[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: [kreport] src: Port from KReportPageFormat to new KReportPageSize
From: Adam Pigg <adam () piggz ! co ! uk>
Date: 2016-01-14 19:58:17
Message-ID: E1aJo2D-0000jG-Ra () scm ! kde ! org
[Download RAW message or body]
Git commit fcc16e59f586a400c4d9ef4fa2abac088f475da7 by Adam Pigg.
Committed on 14/01/2016 at 19:58.
Pushed by piggz into branch 'master'.
Port from KReportPageFormat to new KReportPageSize
Summary:
API is simpler as uses QPageSize instead of custom defined sizes
Only ported a few of the page sizes in this version but more are easily added
Removed usage of QScreen to get DPI, and use KReportDpi everywhere, and
made KReportDpi return same for X and Y, as QPageSize uses a single resolution
to get px width/height.
Reviewers: staniek
Reviewed By: staniek
Differential Revision: https://phabricator.kde.org/D547
M +2 -2 src/CMakeLists.txt
M +3 -4 src/common/KReportDocument.cpp
D +0 -189 src/common/KReportPageFormat.cpp
D +0 -142 src/common/KReportPageFormat.h
M +25 -44 src/common/KReportPageOptions.cpp
M +11 -12 src/common/KReportPageOptions.h
A +86 -0 src/common/KReportPageSize.cpp [License: LGPL (v2.1+)]
A +67 -0 src/common/KReportPageSize.h [License: LGPL (v2.1+)]
M +5 -9 src/common/KReportPosition.cpp
M +5 -8 src/common/KReportSize.cpp
M +2 -3 src/renderer/KReportPage.cpp
M +9 -17 src/renderer/KReportPreRenderer.cpp
M +14 -13 src/renderer/KReportPrintRenderer_p.cpp
M +0 -1 src/renderer/KReportScreenRenderer_p.cpp
M +12 -19 src/wrtembed/KReportDesigner.cpp
M +3 -5 src/wrtembed/KReportDesignerItemRectBase.cpp
M +3 -3 src/wrtembed/KReportDesignerSection.cpp
M +3 -7 src/wrtembed/KReportDesignerSectionScene.cpp
http://commits.kde.org/kreport/fcc16e59f586a400c4d9ef4fa2abac088f475da7
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 4f49ebb..0463c46 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -30,7 +30,7 @@ set(kreport_LIB_SRCS
common/KReportPluginMetaData.cpp
common/KReportData.cpp
common/KReportUtils.cpp
- common/KReportPageFormat.cpp
+ common/KReportPageSize.cpp
common/KReportUnit.cpp
common/KReportDesign.cpp
common/KReportDesign_p.cpp
@@ -246,7 +246,7 @@ ecm_generate_headers(kreport_FORWARDING_HEADERS
ORIGINAL CAMELCASE
RELATIVE common
HEADER_NAMES
- KReportPageFormat
+ KReportPageSize
KReportData
KReportItemBase
KReportItemLine
diff --git a/src/common/KReportDocument.cpp b/src/common/KReportDocument.cpp
index af97903..8cb46fa 100644
--- a/src/common/KReportDocument.cpp
+++ b/src/common/KReportDocument.cpp
@@ -19,10 +19,10 @@
#include "KReportUnit.h"
#include "KReportDetailSectionData.h"
#include "KReportItemBase.h"
+#include "KReportDpi.h"
#include <QDomElement>
#include <QApplication>
-#include <QScreen>
#include "kreport_debug.h"
void KReportDocument::init()
@@ -52,10 +52,9 @@ KReportDocument::KReportDocument(const QDomElement & elemSource, \
QObject *parent << elemSource.text();
return;
}
- QScreen *srn = QApplication::screens().at(0);
- const qreal dpiX = srn->logicalDotsPerInchX();
- const qreal dpiY = srn->logicalDotsPerInchY();
+ const qreal dpiX = KReportDpi::dpiX();
+ const qreal dpiY = KReportDpi::dpiY();
QDomNodeList sections = elemSource.childNodes();
diff --git a/src/common/KReportPageFormat.cpp b/src/common/KReportPageFormat.cpp
deleted file mode 100644
index 22c9d50..0000000
--- a/src/common/KReportPageFormat.cpp
+++ /dev/null
@@ -1,189 +0,0 @@
-/* This file is part of the KDE project
- Copyright (C) 1998, 1999 Torben Weis <weis@kde.org>
- Copyright 2002, 2003 David Faure <faure@kde.org>
- Copyright 2003 Nicolas GOUTTE <goutte@kde.org>
- Copyright 2007 Thomas Zander <zander@kde.org>
-
- This library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Library General Public
- License as published by the Free Software Foundation; either
- version 2 of the License, or (at your option) any later version.
-
- This library is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Library General Public License for more details.
-
- You should have received a copy of the GNU Library General Public License
- along with this library; see the file COPYING.LIB. If not, write to
- the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301, USA.
-*/
-
-#include "KReportPageFormat.h"
-
-#include "kreport_debug.h"
-#include <QPageSize>
-#include <QPrinterInfo>
-#include <QCoreApplication>
-
-// paper formats ( mm )
-#define PG_A3_WIDTH 297.0
-#define PG_A3_HEIGHT 420.0
-#define PG_A4_WIDTH 210.0
-#define PG_A4_HEIGHT 297.0
-#define PG_A5_WIDTH 148.0
-#define PG_A5_HEIGHT 210.0
-#define PG_B5_WIDTH 182.0
-#define PG_B5_HEIGHT 257.0
-#define PG_US_LETTER_WIDTH 216.0
-#define PG_US_LETTER_HEIGHT 279.0
-#define PG_US_LEGAL_WIDTH 216.0
-#define PG_US_LEGAL_HEIGHT 356.0
-#define PG_US_EXECUTIVE_WIDTH 191.0
-#define PG_US_EXECUTIVE_HEIGHT 254.0
-
-// To ignore the clang warning we get because we have a
-// for (int i = 0; pageFormatInfo[i].format != -1 ;i++)
-// construct and pageFormatInfo has (KReportPageFormat::Format) - 1
-#if defined(__clang__)
-#pragma GCC diagnostic ignored "-Wtautological-constant-out-of-range-compare"
-#endif
-
-struct PageFormatInfo {
- KReportPageFormat::Format format;
- QPrinter::PageSize qprinter;
- const char* shortName; // Short name
- const char* descriptiveName; // Full name, which will be translated
- qreal width; // in mm
- qreal height; // in mm
-};
-
-// NOTES:
-// - the width and height of non-ISO formats are rounded
-// http://en.wikipedia.org/wiki/Paper_size can help
-// - the comments "should be..." indicates the exact values if the inch sizes would \
be multiplied by 25.4 mm/inch
-
-const PageFormatInfo pageFormatInfo[] = {
- { KReportPageFormat::IsoA3Size, QPrinter::A3, "A3", \
QT_TRANSLATE_NOOP("KReportPageFormat", "ISO A3"), 297.0, 420.0 \
},
- { KReportPageFormat::IsoA4Size, QPrinter::A4, "A4", \
QT_TRANSLATE_NOOP("KReportPageFormat", "ISO A4"), 210.0, 297.0 \
},
- { KReportPageFormat::IsoA5Size, QPrinter::A5, "A5", \
QT_TRANSLATE_NOOP("KReportPageFormat", "ISO A5"), 148.0, 210.0 \
},
- { KReportPageFormat::UsLetterSize, QPrinter::Letter, "Letter", \
QT_TRANSLATE_NOOP("KReportPageFormat", "US Letter"), 215.9, 279.4 \
},
- { KReportPageFormat::UsLegalSize, QPrinter::Legal, "Legal", \
QT_TRANSLATE_NOOP("KReportPageFormat", "US Legal"), 215.9, 355.6 \
},
- { KReportPageFormat::ScreenSize, QPrinter::A4, "Screen", \
QT_TRANSLATE_NOOP("KReportPageFormat", "Screen"), PG_A4_HEIGHT, PG_A4_WIDTH }, // \
Custom, so fall back to A4
- { KReportPageFormat::CustomSize, QPrinter::A4, "Custom", \
QT_TRANSLATE_NOOP("KReportPageFormat", "Custom"), PG_A4_WIDTH, PG_A4_HEIGHT }, // \
Custom, so fall back to A4
- { KReportPageFormat::IsoB5Size, QPrinter::B5, "B5", \
QT_TRANSLATE_NOOP("KReportPageFormat", "ISO B5"), 182.0, 257.0 \
},
- { KReportPageFormat::UsExecutiveSize, QPrinter::Executive, "Executive", \
QT_TRANSLATE_NOOP("KReportPageFormat", "US Executive"), 191.0, 254.0 }, // should be \
190.5 mm x 254.0 mm
- { KReportPageFormat::IsoA0Size, QPrinter::A0, "A0", \
QT_TRANSLATE_NOOP("KReportPageFormat", "ISO A0"), 841.0, 1189.0 \
},
- { KReportPageFormat::IsoA1Size, QPrinter::A1, "A1", \
QT_TRANSLATE_NOOP("KReportPageFormat", "ISO A1"), 594.0, 841.0 \
},
- { KReportPageFormat::IsoA2Size, QPrinter::A2, "A2", \
QT_TRANSLATE_NOOP("KReportPageFormat", "ISO A2"), 420.0, 594.0 \
},
- { KReportPageFormat::IsoA6Size, QPrinter::A6, "A6", \
QT_TRANSLATE_NOOP("KReportPageFormat", "ISO A6"), 105.0, 148.0 \
},
- { KReportPageFormat::IsoA7Size, QPrinter::A7, "A7", \
QT_TRANSLATE_NOOP("KReportPageFormat", "ISO A7"), 74.0, 105.0 \
},
- { KReportPageFormat::IsoA8Size, QPrinter::A8, "A8", \
QT_TRANSLATE_NOOP("KReportPageFormat", "ISO A8"), 52.0, 74.0 \
},
- { KReportPageFormat::IsoA9Size, QPrinter::A9, "A9", \
QT_TRANSLATE_NOOP("KReportPageFormat", "ISO A9"), 37.0, 52.0 \
},
- { KReportPageFormat::IsoB0Size, QPrinter::B0, "B0", \
QT_TRANSLATE_NOOP("KReportPageFormat", "ISO B0"), 1030.0, 1456.0 \
},
- { KReportPageFormat::IsoB1Size, QPrinter::B1, "B1", \
QT_TRANSLATE_NOOP("KReportPageFormat", "ISO B1"), 728.0, 1030.0 \
},
- { KReportPageFormat::IsoB10Size, QPrinter::B10, "B10", \
QT_TRANSLATE_NOOP("KReportPageFormat", "ISO B10"), 32.0, 45.0 \
},
- { KReportPageFormat::IsoB2Size, QPrinter::B2, "B2", \
QT_TRANSLATE_NOOP("KReportPageFormat", "ISO B2"), 515.0, 728.0 \
},
- { KReportPageFormat::IsoB3Size, QPrinter::B3, "B3", \
QT_TRANSLATE_NOOP("KReportPageFormat", "ISO B3"), 364.0, 515.0 \
},
- { KReportPageFormat::IsoB4Size, QPrinter::B4, "B4", \
QT_TRANSLATE_NOOP("KReportPageFormat", "ISO B4"), 257.0, 364.0 \
},
- { KReportPageFormat::IsoB6Size, QPrinter::B6, "B6", \
QT_TRANSLATE_NOOP("KReportPageFormat", "ISO B6"), 128.0, 182.0 \
},
- { KReportPageFormat::IsoC5Size, QPrinter::C5E, "C5", \
QT_TRANSLATE_NOOP("KReportPageFormat", "ISO C5"), 163.0, 229.0 }, // Some \
sources tells: 162 mm x 228 mm
- { KReportPageFormat::UsComm10Size, QPrinter::Comm10E, "Comm10", \
QT_TRANSLATE_NOOP("KReportPageFormat", "US Common 10"), 105.0, 241.0 }, // should be \
104.775 mm x 241.3 mm
- { KReportPageFormat::IsoDLSize, QPrinter::DLE, "DL", \
QT_TRANSLATE_NOOP("KReportPageFormat", "ISO DL"), 110.0, 220.0 \
},
- { KReportPageFormat::UsFolioSize, QPrinter::Folio, "Folio", \
QT_TRANSLATE_NOOP("KReportPageFormat", "US Folio"), 210.0, 330.0 }, // should be \
209.54 mm x 330.2 mm
- { KReportPageFormat::UsLedgerSize, QPrinter::Ledger, "Ledger", \
QT_TRANSLATE_NOOP("KReportPageFormat", "US Ledger"), 432.0, 279.0 }, // should be \
431.8 mm x 297.4 mm
- { KReportPageFormat::UsTabloidSize, QPrinter::Tabloid, "Tabloid", \
QT_TRANSLATE_NOOP("KReportPageFormat", "US Tabloid"), 279.0, 432.0 }, // should \
be 297.4 mm x 431.8 mm
- {(KReportPageFormat::Format) - 1, (QPrinter::PageSize) - 1, "", "", -1, \
-1 }
-};
-
-QPrinter::PageSize KReportPageFormat::printerPageSize(KReportPageFormat::Format \
format)
-{
- if (format == ScreenSize) {
- kreportWarning() << "You use the page layout SCREEN. Printing in ISO A4 \
Landscape.";
- return QPrinter::A4;
- }
- if (format == CustomSize) {
- kreportWarning() << "The used page layout (Custom) is not supported by \
KQPrinter. Printing in A4.";
- return QPrinter::A4;
- }
- return pageFormatInfo[ format ].qprinter;
-}
-
-qreal KReportPageFormat::width(Format format, Orientation orientation)
-{
- if (orientation == Landscape)
- return height(format, Portrait);
- return pageFormatInfo[ format ].width;
-}
-
-qreal KReportPageFormat::height(Format format, Orientation orientation)
-{
- if (orientation == Landscape)
- return width(format, Portrait);
- return pageFormatInfo[ format ].height;
-}
-
-KReportPageFormat::Format KReportPageFormat::guessFormat(qreal width, qreal height)
-{
- for (int i = 0; pageFormatInfo[i].format != -1 ;i++) {
- // We have some tolerance. 1pt is a third of a mm, this is
- // barely noticeable for a page size.
- if (qAbs(width - pageFormatInfo[i].width) < 1.0 && qAbs(height - \
pageFormatInfo[i].height) < 1.0)
- return pageFormatInfo[i].format;
- }
- return CustomSize;
-}
-
-QString KReportPageFormat::formatString(Format format)
-{
- return QString::fromLatin1(pageFormatInfo[ format ].shortName);
-}
-
-KReportPageFormat::Format KReportPageFormat::formatFromString(const QString & \
string)
-{
- for (int i = 0; pageFormatInfo[i].format != -1 ;i++) {
- if (string == QString::fromLatin1(pageFormatInfo[ i ].shortName))
- return pageFormatInfo[ i ].format;
- }
- // We do not know the format name, so we have a custom format
- return CustomSize;
-}
-
-KReportPageFormat::Format KReportPageFormat::defaultFormat()
-{
- QPrinterInfo printerInfo = QPrinterInfo::defaultPrinter();
- QPageSize size = printerInfo.defaultPageSize();
- if (size.isValid()) {
- const QPageSize::PageSizeId qprinter = size.id();
- for (int i = 0; pageFormatInfo[i].format != -1 ;i++) {
- if (pageFormatInfo[ i ].qprinter == \
static_cast<QPrinter::PageSize>(qprinter)){
- return static_cast<Format>(i);
- }
- }
- }
- return IsoA4Size;
-}
-
-QString KReportPageFormat::name(Format format)
-{
- return QCoreApplication::translate("KReportPageFormat", pageFormatInfo[ format \
].descriptiveName);
-}
-
-QStringList KReportPageFormat::localizedPageFormatNames()
-{
- QStringList lst;
- for (int i = 0; pageFormatInfo[i].format != -1 ;i++) {
- lst << QCoreApplication::translate("KReportPageFormat", pageFormatInfo[ i \
].descriptiveName);
- }
- return lst;
-}
-
-QStringList KReportPageFormat::pageFormatNames()
-{
- QStringList lst;
- for (int i = 0; pageFormatInfo[i].format != -1 ;i++) {
- lst << QLatin1String(pageFormatInfo[ i ].shortName);
- }
- return lst;
-}
diff --git a/src/common/KReportPageFormat.h b/src/common/KReportPageFormat.h
deleted file mode 100644
index cdcabee..0000000
--- a/src/common/KReportPageFormat.h
+++ /dev/null
@@ -1,142 +0,0 @@
-/* This file is part of the KDE project
- Copyright (C) 1998, 1999 Torben Weis <weis@kde.org>
- Copyright 2002, 2003 David Faure <faure@kde.org>
- Copyright 2003 Nicolas GOUTTE <goutte@kde.org>
- Copyright 2007 Thomas Zander <zander@kde.org>
-
- This library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Library General Public
- License as published by the Free Software Foundation; either
- version 2 of the License, or (at your option) any later version.
-
- This library is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Library General Public License for more details.
-
- You should have received a copy of the GNU Library General Public License
- along with this library; see the file COPYING.LIB. If not, write to
- the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301, USA.
-*/
-
-#ifndef KREPORTPAGEFORMAT_H
-#define KREPORTPAGEFORMAT_H
-
-#include <QPrinter>
-
-#include "kreport_export.h"
-
-/// The page formats KReport supports
-namespace KReportPageFormat
-{
-/**
- * @brief Represents the paper format a document shall be printed on.
- *
- * For compatibility reasons, and because of screen and custom,
- * this enum doesn't map to QPrinter::PageSize but \
KReportPageFormat::printerPageSize
- * does the conversion.
- */
-enum Format {
- IsoA3Size,
- IsoA4Size,
- IsoA5Size,
- UsLetterSize,
- UsLegalSize,
- ScreenSize,
- CustomSize,
- IsoB5Size,
- UsExecutiveSize,
- IsoA0Size,
- IsoA1Size,
- IsoA2Size,
- IsoA6Size,
- IsoA7Size,
- IsoA8Size,
- IsoA9Size,
- IsoB0Size,
- IsoB1Size,
- IsoB10Size,
- IsoB2Size,
- IsoB3Size,
- IsoB4Size,
- IsoB6Size,
- IsoC5Size,
- UsComm10Size,
- IsoDLSize,
- UsFolioSize,
- UsLedgerSize,
- UsTabloidSize
-};
-
-/**
- * Represents the orientation of a printed document.
- */
-enum Orientation {
- Portrait,
- Landscape
-};
-
-/**
- * @brief Convert a Format into a KPrinter::PageSize.
- *
- * If format is 'screen' it will use A4 landscape.
- * If format is 'custom' it will use A4 portrait.
- * (you may want to take care of those cases separately).
- * Usually passed to KPrinter::setPageSize().
- */
-KREPORT_EXPORT QPrinter::PageSize printerPageSize(Format format);
-
-/**
- * Returns the width (in mm) for a given page format and orientation
- * 'Custom' isn't supported by this function, obviously.
- */
-KREPORT_EXPORT qreal width(Format format, Orientation orientation = Landscape);
-
-/**
- * Returns the height (in mm) for a given page format and orientation
- * 'Custom' isn't supported by this function, obviously.
- */
-KREPORT_EXPORT qreal height(Format format, Orientation orientation = Landscape);
-
-/**
- * Returns the internal name of the given page format.
- * Use for saving.
- */
-KREPORT_EXPORT QString formatString(Format format);
-
-/**
- * Convert a format string (internal name) to a page format value.
- * Use for loading.
- */
-KREPORT_EXPORT Format formatFromString(const QString &string);
-
-/**
- * Returns the default format (based on the KControl settings)
- */
-KREPORT_EXPORT Format defaultFormat();
-
-/**
- * Returns the translated name of the given page format.
- * Use for showing the user.
- */
-KREPORT_EXPORT QString name(Format format);
-
-/**
- * Lists the translated names of all the available formats
- */
-KREPORT_EXPORT QStringList localizedPageFormatNames();
-
-/**
- * Lists the non-translated names of all the available formats
- */
-KREPORT_EXPORT QStringList pageFormatNames();
-
-/**
- * Try to find the paper format for the given width and height (in mm).
- * Useful to some import filters.
- */
-KREPORT_EXPORT Format guessFormat(qreal width, qreal height);
-}
-
-#endif
diff --git a/src/common/KReportPageOptions.cpp b/src/common/KReportPageOptions.cpp
index bc8d098..9cb37f9 100644
--- a/src/common/KReportPageOptions.cpp
+++ b/src/common/KReportPageOptions.cpp
@@ -17,10 +17,11 @@
*/
#include "KReportPageOptions.h"
-#include "KReportPageFormat.h"
#include "KReportUnit.h"
+#include "KReportPageSize.h"
+#include "KReportDpi.h"
+
#include <QApplication>
-#include <QScreen>
KReportPageOptions::KReportPageOptions()
: QObject(), m_pageSize(QLatin1String("Letter"))
@@ -69,7 +70,7 @@ KReportPageOptions & KReportPageOptions::operator=(const \
KReportPageOptions & rp return *this;
}
-qreal KReportPageOptions::getMarginTop()
+qreal KReportPageOptions::getMarginTop() const
{
return m_marginTop;
}
@@ -83,7 +84,7 @@ void KReportPageOptions::setMarginTop(qreal v)
emit pageOptionsChanged();
}
-qreal KReportPageOptions::getMarginBottom()
+qreal KReportPageOptions::getMarginBottom() const
{
return m_marginBottom;
}
@@ -97,7 +98,7 @@ void KReportPageOptions::setMarginBottom(qreal v)
emit pageOptionsChanged();
}
-qreal KReportPageOptions::getMarginLeft()
+qreal KReportPageOptions::getMarginLeft() const
{
return m_marginLeft;
}
@@ -111,7 +112,7 @@ void KReportPageOptions::setMarginLeft(qreal v)
emit pageOptionsChanged();
}
-qreal KReportPageOptions::getMarginRight()
+qreal KReportPageOptions::getMarginRight() const
{
return m_marginRight;
}
@@ -125,10 +126,11 @@ void KReportPageOptions::setMarginRight(qreal v)
emit pageOptionsChanged();
}
-const QString & KReportPageOptions::getPageSize()
+const QString & KReportPageOptions::getPageSize() const
{
return m_pageSize;
}
+
void KReportPageOptions::setPageSize(const QString & s)
{
if (m_pageSize == s)
@@ -137,7 +139,7 @@ void KReportPageOptions::setPageSize(const QString & s)
m_pageSize = s;
emit pageOptionsChanged();
}
-qreal KReportPageOptions::getCustomWidth()
+qreal KReportPageOptions::getCustomWidth() const
{
return m_customWidth;
}
@@ -149,10 +151,12 @@ void KReportPageOptions::setCustomWidth(qreal v)
m_customWidth = v;
emit pageOptionsChanged();
}
-qreal KReportPageOptions::getCustomHeight()
+
+qreal KReportPageOptions::getCustomHeight() const
{
return m_customHeight;
}
+
void KReportPageOptions::setCustomHeight(qreal v)
{
if (m_customHeight == v)
@@ -162,12 +166,12 @@ void KReportPageOptions::setCustomHeight(qreal v)
emit pageOptionsChanged();
}
-KReportPageOptions::PageOrientation KReportPageOptions::getOrientation()
+KReportPageOptions::PageOrientation KReportPageOptions::getOrientation() const
{
return m_orientation;
}
-bool KReportPageOptions::isPortrait()
+bool KReportPageOptions::isPortrait() const
{
return (m_orientation == Portrait);
}
@@ -180,15 +184,17 @@ void KReportPageOptions::setOrientation(PageOrientation o)
m_orientation = o;
emit pageOptionsChanged();
}
+
void KReportPageOptions::setPortrait(bool yes)
{
setOrientation((yes ? Portrait : Landscape));
}
-const QString & KReportPageOptions::getLabelType()
+const QString & KReportPageOptions::getLabelType() const
{
return m_labelType;
}
+
void KReportPageOptions::setLabelType(const QString & type)
{
if (m_labelType == type)
@@ -199,39 +205,14 @@ void KReportPageOptions::setLabelType(const QString & type)
}
//Convenience functions that return the page width/height in pixels based on the DPI
-qreal KReportPageOptions::widthPx()
-{
- int pageWidth;
-
- if (isPortrait()) {
- pageWidth = \
KReportPageFormat::width(KReportPageFormat::formatFromString(getPageSize()), \
KReportPageFormat::Portrait);
- } else {
- pageWidth = \
KReportPageFormat::width(KReportPageFormat::formatFromString(getPageSize()), \
KReportPageFormat::Landscape);
- }
-
- KReportUnit pageUnit(KReportUnit::Millimeter);
- QScreen *srn = QApplication::screens().at(0);
-
- pageWidth = KReportUnit::toInch(pageUnit.fromUserValue(pageWidth)) * \
srn->logicalDotsPerInchX();
-
- return pageWidth;
-}
-
-qreal KReportPageOptions::heightPx()
+QSizeF KReportPageOptions::pixelSize() const
{
- int pageHeight;
-
- if (isPortrait()) {
- pageHeight = \
KReportPageFormat::height(KReportPageFormat::formatFromString(getPageSize()), \
KReportPageFormat::Portrait); + QSizeF xDpiSize = \
QPageSize(KReportPageSize::pageSize(getPageSize())).sizePixels(KReportDpi::dpiX()); + \
QSizeF yDpiSize = QPageSize(KReportPageSize::pageSize(getPageSize())).sizePixels(KReportDpi::dpiY());
+
+ if (isPortrait()){
+ return QSizeF(xDpiSize.width(), yDpiSize.height());
} else {
- pageHeight = \
KReportPageFormat::height(KReportPageFormat::formatFromString(getPageSize()), \
KReportPageFormat::Landscape); + return QSizeF(xDpiSize.height(), yDpiSize.width());
}
-
- KReportUnit pageUnit(KReportUnit::Millimeter);
- QScreen *srn = QApplication::screens().at(0);
-
- pageHeight = KReportUnit::toInch(pageUnit.fromUserValue(pageHeight)) * \
srn->logicalDotsPerInchY();
-
- return pageHeight;
}
-
diff --git a/src/common/KReportPageOptions.h b/src/common/KReportPageOptions.h
index 79e2c68..6e86308 100644
--- a/src/common/KReportPageOptions.h
+++ b/src/common/KReportPageOptions.h
@@ -38,32 +38,31 @@ public:
Portrait = 1 // and true
};
- qreal getMarginTop();
+ qreal getMarginTop() const;
void setMarginTop(qreal v);
- qreal getMarginBottom();
+ qreal getMarginBottom() const;
void setMarginBottom(qreal v);
- qreal getMarginLeft();
+ qreal getMarginLeft() const;
void setMarginLeft(qreal v);
- qreal getMarginRight();
+ qreal getMarginRight() const;
void setMarginRight(qreal v);
- qreal widthPx();
- qreal heightPx();
+ QSizeF pixelSize() const;
- const QString & getPageSize();
+ const QString & getPageSize() const;
void setPageSize(const QString & s);
- qreal getCustomWidth();
+ qreal getCustomWidth() const;
void setCustomWidth(qreal v);
- qreal getCustomHeight();
+ qreal getCustomHeight() const;
void setCustomHeight(qreal v);
- PageOrientation getOrientation();
- bool isPortrait();
+ PageOrientation getOrientation() const;
+ bool isPortrait() const;
void setOrientation(PageOrientation o);
void setPortrait(bool yes);
void setLabelType(const QString &);
- const QString & getLabelType();
+ const QString & getLabelType() const;
Q_SIGNALS:
void pageOptionsChanged();
diff --git a/src/common/KReportPageSize.cpp b/src/common/KReportPageSize.cpp
new file mode 100644
index 0000000..0e2c34a
--- /dev/null
+++ b/src/common/KReportPageSize.cpp
@@ -0,0 +1,86 @@
+ /* This file is part of the KDE project
+ Copyright (C) 2015 by Adam Pigg <adam@piggz.co.uk>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#include "KReportPageSize.h"
+#include <QCoreApplication>
+#include <QPrinterInfo>
+
+struct KReportPageSizeInfo {
+ char *name;
+ char *description;
+ QPageSize::PageSizeId pageSize;
+};
+
+const KReportPageSizeInfo pageSizeInfo[] = {
+ { "A3", QT_TRANSLATE_NOOP("KReportPageFormat", "A3"), QPageSize::A3},
+ { "A4", QT_TRANSLATE_NOOP("KReportPageFormat", "A4"), QPageSize::A4},
+ { "A5", QT_TRANSLATE_NOOP("KReportPageFormat", "A5"), QPageSize::A5},
+ { "Letter", QT_TRANSLATE_NOOP("KReportPageFormat", "US Letter"), \
QPageSize::Letter}, + { "Legal", QT_TRANSLATE_NOOP("KReportPageFormat", "US \
Legal"), QPageSize::Legal}, + { "Screen", QT_TRANSLATE_NOOP("KReportPageFormat", \
"Screen"), QPageSize::A4}, + { "", "", QPageSize::LastPageSize}
+};
+
+QStringList KReportPageSize::pageFormatNames()
+{
+ QStringList lst;
+ for (int i = 0; pageSizeInfo[i].pageSize != QPageSize::LastPageSize ;i++) {
+ lst << QCoreApplication::translate("KReportPageFormat", pageSizeInfo[ i \
].description); + }
+ return lst;
+}
+
+QStringList KReportPageSize::pageFormatKeys()
+{
+ QStringList lst;
+ for (int i = 0; pageSizeInfo[i].pageSize != QPageSize::LastPageSize ;i++) {
+ lst << QLatin1String(pageSizeInfo[ i ].name);
+ }
+ return lst;
+}
+
+QPageSize::PageSizeId KReportPageSize::defaultSize()
+{
+ QPrinterInfo printerInfo = QPrinterInfo::defaultPrinter();
+ QPageSize size = printerInfo.defaultPageSize();
+ if (size.isValid()) {
+ return size.id();
+ }
+ return QPageSize::A4;
+}
+
+QString KReportPageSize::pageSizeKey(QPageSize::PageSizeId id)
+{
+ for (int i = 0; pageSizeInfo[i].pageSize != QPageSize::LastPageSize ;i++) {
+ if (pageSizeInfo[i].pageSize == id) {
+ return QLatin1String(pageSizeInfo[i].name);
+ }
+ }
+ return QString();
+}
+
+QPageSize::PageSizeId KReportPageSize::pageSize(const QString &size)
+{
+ for (int i = 0; pageSizeInfo[i].pageSize != QPageSize::LastPageSize ;i++) {
+ if (QLatin1String(pageSizeInfo[i].name) == size) {
+ return pageSizeInfo[i].pageSize;
+ }
+ }
+ return defaultSize();
+}
diff --git a/src/common/KReportPageSize.h b/src/common/KReportPageSize.h
new file mode 100644
index 0000000..ae55280
--- /dev/null
+++ b/src/common/KReportPageSize.h
@@ -0,0 +1,67 @@
+/* This file is part of the KDE project
+ Copyright (C) 2015 by Adam Pigg <adam@piggz.co.uk>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#ifndef KREPORTPAGESIZE_H
+#define KREPORTPAGESIZE_H
+#include <QPageSize>
+#include "kreport_export.h"
+
+/**
+ * @brief Handle the page sizes we support in reports
+ *
+ * A group of helper functions and definitions of the page sizes
+ * we support in KReport.
+ *
+ * We don't support all the sizes supported by Qt, so here we provide a list
+ * of supported sizes and translatable descriptions, with helper functions to
+ * switch between QString and QPageSizeId
+ *
+ */
+namespace KReportPageSize
+{
+
+/**
+ * @return list of translated names of all the available formats
+ */
+KREPORT_EXPORT QStringList pageFormatNames();
+
+/**
+ * @return list of non-translated names of all the available formats
+ */
+KREPORT_EXPORT QStringList pageFormatKeys();
+
+/**
+ * @return the default format (based on the default printer)
+ */
+KREPORT_EXPORT QPageSize::PageSizeId defaultSize();
+
+/**
+ * @return the page size Id for the given key
+ */
+KREPORT_EXPORT QPageSize::PageSizeId pageSize(const QString& key);
+
+/**
+ * @return the page size string for the given Id
+ */
+KREPORT_EXPORT QString pageSizeKey(QPageSize::PageSizeId id);
+
+
+}
+
+#endif // KREPORTPAGESIZE_H
diff --git a/src/common/KReportPosition.cpp b/src/common/KReportPosition.cpp
index 4056a88..16ece89 100644
--- a/src/common/KReportPosition.cpp
+++ b/src/common/KReportPosition.cpp
@@ -17,10 +17,10 @@
*/
#include "KReportPosition.h"
+#include "KReportDpi.h"
#include <KProperty>
-#include <QScreen>
#include <QApplication>
KReportPosition::KReportPosition(const KReportUnit& unit)
@@ -41,10 +41,8 @@ KReportPosition::~KReportPosition()
void KReportPosition::setScenePos(const QPointF& pos, UpdatePropertyFlag update)
{
- QScreen *srn = QApplication::screens().at(0);
-
- const qreal x = INCH_TO_POINT(pos.x() / srn->logicalDotsPerInchX());
- const qreal y = INCH_TO_POINT(pos.y() / srn->logicalDotsPerInchY());
+ const qreal x = INCH_TO_POINT(pos.x() / KReportDpi::dpiX());
+ const qreal y = INCH_TO_POINT(pos.y() / KReportDpi::dpiY());
m_pointPos.setX(x);
m_pointPos.setY(y);
@@ -87,10 +85,8 @@ QPointF KReportPosition::toPoint() const
QPointF KReportPosition::toScene() const
{
- QScreen *srn = QApplication::screens().at(0);
-
- const qreal x = POINT_TO_INCH(m_pointPos.x()) * srn->logicalDotsPerInchX();
- const qreal y = POINT_TO_INCH(m_pointPos.y()) * srn->logicalDotsPerInchY();
+ const qreal x = POINT_TO_INCH(m_pointPos.x()) * KReportDpi::dpiX();
+ const qreal y = POINT_TO_INCH(m_pointPos.y()) * KReportDpi::dpiY();
return QPointF(x, y);
}
diff --git a/src/common/KReportSize.cpp b/src/common/KReportSize.cpp
index db0b3cc..0c8b6f2 100644
--- a/src/common/KReportSize.cpp
+++ b/src/common/KReportSize.cpp
@@ -16,10 +16,10 @@
*/
#include "KReportSize.h"
+#include "KReportDpi.h"
#include <KProperty>
-#include <QScreen>
#include <QApplication>
KReportSize::KReportSize(const KReportUnit& unit)
@@ -37,10 +37,8 @@ void KReportSize::setSceneSize(const QSizeF& s, UpdatePropertyFlag \
update) {
qreal w, h;
- QScreen *srn = QApplication::screens().at(0);
-
- w = INCH_TO_POINT(s.width() / srn->logicalDotsPerInchX());
- h = INCH_TO_POINT(s.height() / srn->logicalDotsPerInchY());
+ w = INCH_TO_POINT(s.width() / KReportDpi::dpiX());
+ h = INCH_TO_POINT(s.height() / KReportDpi::dpiY());
m_pointSize.setWidth(w);
m_pointSize.setHeight(h);
@@ -83,9 +81,8 @@ QSizeF KReportSize::toPoint() const
QSizeF KReportSize::toScene() const
{
qreal w, h;
- QScreen *srn = QApplication::screens().at(0);
- w = POINT_TO_INCH(m_pointSize.width()) * srn->logicalDotsPerInchX();
- h = POINT_TO_INCH(m_pointSize.height()) * srn->logicalDotsPerInchY();
+ w = POINT_TO_INCH(m_pointSize.width()) * KReportDpi::dpiX();
+ h = POINT_TO_INCH(m_pointSize.height()) * KReportDpi::dpiY();
return QSizeF(w, h);
}
diff --git a/src/renderer/KReportPage.cpp b/src/renderer/KReportPage.cpp
index 1ffe4a4..8bcfed7 100644
--- a/src/renderer/KReportPage.cpp
+++ b/src/renderer/KReportPage.cpp
@@ -18,7 +18,6 @@
#include "KReportPage.h"
#include "KReportRendererBase.h"
-#include "KReportPageFormat.h"
#include "KReportUnit.h"
#include "KReportRenderObjects.h"
#include "kreport_debug.h"
@@ -71,8 +70,8 @@ KReportPage::KReportPage(QWidget *parent, ORODocument *document)
pageHeight = (int)(d->reportDocument->pageOptions().getCustomHeight());
} else {
// lookup the correct size information for the specified size paper
- pageWidth = d->reportDocument->pageOptions().widthPx();
- pageHeight = d->reportDocument->pageOptions().heightPx();
+ pageWidth = d->reportDocument->pageOptions().pixelSize().width();
+ pageHeight = d->reportDocument->pageOptions().pixelSize().height();
}
}
setRect(0,0,pageWidth, pageHeight);
diff --git a/src/renderer/KReportPreRenderer.cpp \
b/src/renderer/KReportPreRenderer.cpp index 707182b..477c5a6 100644
--- a/src/renderer/KReportPreRenderer.cpp
+++ b/src/renderer/KReportPreRenderer.cpp
@@ -27,7 +27,8 @@
#include "KReportDocument.h"
#include "KReportDetailSectionData.h"
#include "KReportLabelSizeInfo.h"
-#include "KReportPageFormat.h"
+#include "KReportPageSize.h"
+#include "KReportDpi.h"
#ifdef KREPORT_SCRIPTING
#include "scripting/KReportScriptHandler.h"
@@ -35,7 +36,6 @@
#endif
#include <QDomElement>
-#include <QScreen>
#include <QApplication>
#include "kreport_debug.h"
@@ -288,8 +288,7 @@ void \
KReportPreRendererPrivate::renderDetailSection(KReportDetailSectionData *de
qreal KReportPreRendererPrivate::renderSectionSize(const KReportSectionData & \
sectionData) {
- QScreen *srn = QApplication::screens().at(0);
- qreal intHeight = POINT_TO_INCH(sectionData.height()) * \
srn->logicalDotsPerInchX(); + qreal intHeight = \
POINT_TO_INCH(sectionData.height()) * KReportDpi::dpiX();
int itemHeight = 0;
@@ -318,8 +317,7 @@ qreal KReportPreRendererPrivate::renderSectionSize(const \
KReportSectionData & se
qreal KReportPreRendererPrivate::renderSection(const KReportSectionData & \
sectionData) {
- QScreen *srn = QApplication::screens().at(0);
- qreal sectionHeight = POINT_TO_INCH(sectionData.height()) * \
srn->logicalDotsPerInchX(); + qreal sectionHeight = \
POINT_TO_INCH(sectionData.height()) * KReportDpi::dpiX();
int itemHeight = 0;
//kreportDebug() << "Name: " << sectionData.name() << " Height: " << \
sectionHeight @@ -337,7 +335,7 @@ qreal \
KReportPreRendererPrivate::renderSection(const KReportSectionData & sectio ORORect* \
bg = new ORORect(); bg->setPen(QPen(Qt::NoPen));
bg->setBrush(sectionData.backgroundColor());
- qreal w = m_page->document()->pageOptions().widthPx() - \
m_page->document()->pageOptions().getMarginRight() - m_leftMargin; + qreal w = \
m_page->document()->pageOptions().pixelSize().width() - \
m_page->document()->pageOptions().getMarginRight() - m_leftMargin;
bg->setRect(QRectF(m_leftMargin, m_yOffset, w, sectionHeight));
m_page->addPrimitive(bg, true);
@@ -419,10 +417,6 @@ void KReportPreRenderer::setName(const QString &n)
ORODocument* KReportPreRenderer::generate()
{
- QScreen *srn = QApplication::screens().at(0);
- int dpiX = srn->logicalDotsPerInchX();
- int dpiY = srn->logicalDotsPerInchY();
-
if (d == 0 || !d->m_valid || d->m_reportDocument == 0 || d->m_kodata == 0)
return 0;
@@ -442,7 +436,7 @@ ORODocument* KReportPreRenderer::generate()
//kreportDebug() << "Calculating Margins";
if (!label.isNull()) {
- if (d->m_reportDocument ->page.isPortrait()) {
+ if (d->m_reportDocument->page.isPortrait()) {
d->m_topMargin = (label.startY() / 100.0);
d->m_bottomMargin = 0;
d->m_rightMargin = 0;
@@ -474,12 +468,10 @@ ORODocument* KReportPreRenderer::generate()
rpo.setPageSize(label.paper());
} else {
// lookup the correct size information for the specified size paper
- d->m_maxWidth = \
KReportPageFormat::width(KReportPageFormat::formatFromString(d->m_reportDocument->page.getPageSize()), \
KReportPageFormat::Portrait);
- d->m_maxHeight = \
KReportPageFormat::height(KReportPageFormat::formatFromString(d->m_reportDocument->page.getPageSize()), \
KReportPageFormat::Portrait); + QSizeF pageSizePx = \
d->m_reportDocument->page.pixelSize();
- KReportUnit pageUnit(KReportUnit::Millimeter);
- d->m_maxWidth = \
KReportUnit::toInch(pageUnit.fromUserValue(d->m_maxWidth)) * dpiX;
- d->m_maxHeight = \
KReportUnit::toInch(pageUnit.fromUserValue(d->m_maxHeight)) * dpiY; + \
d->m_maxWidth = pageSizePx.width(); + d->m_maxHeight = pageSizePx.height();
}
}
diff --git a/src/renderer/KReportPrintRenderer_p.cpp \
b/src/renderer/KReportPrintRenderer_p.cpp index 1292fb0..dc6b6d6 100644
--- a/src/renderer/KReportPrintRenderer_p.cpp
+++ b/src/renderer/KReportPrintRenderer_p.cpp
@@ -19,9 +19,9 @@
#include "KReportPrintRenderer_p.h"
#include "kreport_debug.h"
#include "KReportRenderObjects.h"
-#include "KReportPageFormat.h"
+#include "KReportPageSize.h"
+#include "KReportDpi.h"
-#include <QScreen>
#include <QApplication>
#include <QPainter>
#include <QPrinter>
@@ -47,10 +47,11 @@ bool PrintRenderer::setupPrinter( ORODocument * document, \
QPrinter * pPrinter)
pPrinter->setOrientation((document->pageOptions().isPortrait() ? \
QPrinter::Portrait : QPrinter::Landscape)); \
pPrinter->setPageOrder(QPrinter::FirstPageFirst);
- if (document->pageOptions().getPageSize().isEmpty())
+ if (document->pageOptions().getPageSize().isEmpty()) {
pPrinter->setPageSize(QPrinter::Custom);
- else
- pPrinter->setPageSize(KReportPageFormat::printerPageSize(KReportPageFormat::formatFromString(document->pageOptions().getPageSize())));
+ } else {
+ pPrinter->setPageSize(QPageSize(KReportPageSize::pageSize(document->pageOptions().getPageSize())));
+ }
return true;
}
@@ -79,9 +80,9 @@ bool PrintRenderer::render(const KReportRendererContext &context, \
ORODocument *d if (toPage == 0 || toPage > document->pages())
toPage = document->pages();
- QScreen *srn = QApplication::screens().at(0);
+ qreal scaleX = context.printer->resolution() / qreal(KReportDpi::dpiX());
+ qreal scaleY = context.printer->resolution() / qreal(KReportDpi::dpiY());
- qreal scale = context.printer->resolution() / qreal(srn->logicalDotsPerInchX());
for (int copy = 0; copy < context.printer->numCopies(); copy++) {
for (int page = fromPage; page < toPage; page++) {
@@ -97,8 +98,8 @@ bool PrintRenderer::render(const KReportRendererContext &context, \
ORODocument *d OROPrimitive * prim = p->primitive(i);
- prim->setPosition(prim->position() * scale);
- prim->setSize(prim->size() * scale);
+ prim->setPosition(QPointF(prim->position().x() * scaleX, \
prim->position().y() * scaleY)); + \
prim->setSize(QSizeF(prim->size().width() * scaleX, \
prim->size().height() * scaleY));
//kreportDebug() << "Rendering object" << i << "type" << \
prim->type(); if (prim->type() == OROTextBox::TextBox) {
//kreportDebug() << "Text Box";
@@ -124,7 +125,7 @@ bool PrintRenderer::render(const KReportRendererContext &context, \
ORODocument *d
context.painter->drawText(rc, tb->flags(), tb->text());
//outer line
- context.painter->setPen(QPen(tb->lineStyle().color(), \
tb->lineStyle().width() * scale, tb->lineStyle().penStyle())); + \
context.painter->setPen(QPen(tb->lineStyle().color(), tb->lineStyle().width() * \
scaleX, tb->lineStyle().penStyle())); context.painter->drawRect(rc);
//Reset back to defaults for next element
@@ -134,9 +135,9 @@ bool PrintRenderer::render(const KReportRendererContext &context, \
ORODocument *d //kreportDebug() << "Line";
OROLine * ln = (OROLine*) prim;
QPointF s = ln->startPoint();
- QPointF e = ln->endPoint() * scale;
+ QPointF e(ln->endPoint().x() * scaleX, ln->endPoint().y() * \
scaleY); //QPen pen ( _painter->pen() );
- QPen pen(ln->lineStyle().color(), ln->lineStyle().width() * \
scale, ln->lineStyle().penStyle()); + QPen \
pen(ln->lineStyle().color(), ln->lineStyle().width() * scaleX, \
ln->lineStyle().penStyle());
context.painter->save();
context.painter->setRenderHint(QPainter::Antialiasing, true);
@@ -204,7 +205,7 @@ bool PrintRenderer::render(const KReportRendererContext &context, \
ORODocument *d
if (chk->lineStyle().penStyle() == Qt::NoPen || \
chk->lineStyle().width() <= 0) { context.painter->setPen(QPen(Qt::lightGray));
} else {
- context.painter->setPen(QPen(chk->lineStyle().color(), \
chk->lineStyle().width() * scale, chk->lineStyle().penStyle())); + \
context.painter->setPen(QPen(chk->lineStyle().color(), chk->lineStyle().width() * \
scaleX, chk->lineStyle().penStyle())); }
qreal ox = sz.width() / 5;
diff --git a/src/renderer/KReportScreenRenderer_p.cpp \
b/src/renderer/KReportScreenRenderer_p.cpp index 5520ac1..8a1338f 100644
--- a/src/renderer/KReportScreenRenderer_p.cpp
+++ b/src/renderer/KReportScreenRenderer_p.cpp
@@ -18,7 +18,6 @@
#include "KReportScreenRenderer_p.h"
#include "KReportRenderObjects.h"
-#include "KReportPageFormat.h"
#include "KReportUnit.h"
#include "kreport_debug.h"
diff --git a/src/wrtembed/KReportDesigner.cpp b/src/wrtembed/KReportDesigner.cpp
index 7b3c62e..70e1d2a 100644
--- a/src/wrtembed/KReportDesigner.cpp
+++ b/src/wrtembed/KReportDesigner.cpp
@@ -28,7 +28,7 @@
#include "KReportDesignerItemLine.h"
#include "KReportRuler_p.h"
#include "KReportZoomHandler.h"
-#include "KReportPageFormat.h"
+#include "KReportPageSize.h"
#include "KReportDpi.h"
#include "KReportUtils.h"
#include "KReportPluginInterface.h"
@@ -725,9 +725,9 @@ void KReportDesigner::createProperties()
d->title = new KProperty("title", QLatin1String("Report"), tr("Title"), \
tr("Report Title"));
keys.clear();
- keys = KReportPageFormat::pageFormatNames();
- strings = KReportPageFormat::localizedPageFormatNames();
- QString defaultKey = \
KReportPageFormat::formatString(KReportPageFormat::defaultFormat()); + keys = \
KReportPageSize::pageFormatKeys(); + strings = KReportPageSize::pageFormatKeys();
+ QString defaultKey = \
KReportPageSize::pageSizeKey(KReportPageSize::defaultSize());
d->pageSize = new KProperty("page-size", keys, strings, defaultKey, tr("Page \
Size"));
keys.clear(); strings.clear();
@@ -858,29 +858,22 @@ QSize KReportDesigner::sizeHint() const
}
int KReportDesigner::pageWidthPx() const
-{
- int cw = 0;
- int ch = 0;
- int width = 0;
-
- KReportPageFormat::Format pf = \
KReportPageFormat::formatFromString(d->set->property("page-size").value().toString());
-
- cw = POINT_TO_INCH(MM_TO_POINT(KReportPageFormat::width(pf, \
KReportPageFormat::Portrait))) * KReportDpi::dpiX();
-
- ch = POINT_TO_INCH(MM_TO_POINT(KReportPageFormat::height(pf, \
KReportPageFormat::Portrait))) * KReportDpi::dpiY();
-
- width = (d->set->property("print-orientation").value().toString() == \
QLatin1String("portrait") ? cw : ch); +{
+ KReportPageOptions po;
+ po.setPageSize(d->set->property("page-size").value().toString());
+ po.setPortrait(d->set->property("print-orientation").value().toString() == \
QLatin1String("portrait")); + QSizeF pageSizePx = po.pixelSize();
+ int width = pageSizePx.width();
width = width - \
POINT_TO_INCH(d->set->property("margin-left").value().toDouble()) * \
KReportDpi::dpiX();
width = width - \
POINT_TO_INCH(d->set->property("margin-right").value().toDouble()) * \
KReportDpi::dpiX();
-
- return width;
+
+ return width;
}
void KReportDesigner::resizeEvent(QResizeEvent * event)
{
Q_UNUSED(event);
- //hruler->setRulerLength ( vboxlayout->geometry().width() );
d->hruler->setRulerLength(pageWidthPx());
}
diff --git a/src/wrtembed/KReportDesignerItemRectBase.cpp \
b/src/wrtembed/KReportDesignerItemRectBase.cpp index bf42be2..9633de0 100644
--- a/src/wrtembed/KReportDesignerItemRectBase.cpp
+++ b/src/wrtembed/KReportDesignerItemRectBase.cpp
@@ -22,19 +22,17 @@
#include "KReportPosition.h"
#include "KReportSize.h"
#include "KReportDesignerSectionScene.h"
+#include "KReportDpi.h"
#include <KPropertySet>
#include <QGraphicsSceneMouseEvent>
-#include <QScreen>
#include <QApplication>
KReportDesignerItemRectBase::KReportDesignerItemRectBase(KReportDesigner *r)
: QGraphicsRectItem(), KReportDesignerItemBase(r)
{
- QScreen *srn = QApplication::screens().at(0);
-
- m_dpiX = srn->logicalDotsPerInchX();
- m_dpiY = srn->logicalDotsPerInchY();
+ m_dpiX = KReportDpi::dpiX();
+ m_dpiY = KReportDpi::dpiY();
m_ppos = 0;
m_psize = 0;
diff --git a/src/wrtembed/KReportDesignerSection.cpp \
b/src/wrtembed/KReportDesignerSection.cpp index a4ef9f7..0fbf89e 100644
--- a/src/wrtembed/KReportDesignerSection.cpp
+++ b/src/wrtembed/KReportDesignerSection.cpp
@@ -30,6 +30,7 @@
#include "KReportDesignerItemLine.h"
#include "KReportRuler_p.h"
#include "KReportZoomHandler.h"
+#include "KReportDpi.h"
#include "kreport_debug.h"
#include <QLabel>
@@ -39,7 +40,6 @@
#include <QGridLayout>
#include <QMouseEvent>
#include <QApplication>
-#include <QScreen>
#include <QApplication>
#include <QIcon>
@@ -103,8 +103,8 @@ KReportDesignerSection::KReportDesignerSection(KReportDesigner * \
rptdes) d->sectionData = new KReportSectionData(this);
connect(d->sectionData->propertySet(), \
SIGNAL(propertyChanged(KPropertySet&,KProperty&)), this, \
SLOT(slotPropertyChanged(KPropertySet&,KProperty&)));
- QScreen *srn = QApplication::screens().at(0);
- d->dpiY = srn->logicalDotsPerInchY();
+
+ d->dpiY = KReportDpi::dpiY();
d->reportDesigner = rptdes;
setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
diff --git a/src/wrtembed/KReportDesignerSectionScene.cpp \
b/src/wrtembed/KReportDesignerSectionScene.cpp index 8dea81f..6bb5001 100644
--- a/src/wrtembed/KReportDesignerSectionScene.cpp
+++ b/src/wrtembed/KReportDesignerSectionScene.cpp
@@ -21,11 +21,10 @@
#include "KReportDesignerItemRectBase.h"
#include "KReportDesigner.h"
#include "KReportLabelSizeInfo.h"
-#include "KReportPageFormat.h"
+#include "KReportDpi.h"
#include "kreport_debug.h"
#include <QPainter>
-#include <QScreen>
#include <QApplication>
#include <QGraphicsItem>
#include <QGraphicsSceneMouseEvent>
@@ -35,11 +34,8 @@ KReportDesignerSectionScene::KReportDesignerSectionScene(qreal w, \
qreal h, KRepo {
m_rd = rd;
m_minorSteps = 0;
-
- QScreen *srn = QApplication::screens().at(0);
-
- m_dpiX = srn->logicalDotsPerInchX();
- m_dpiY = srn->logicalDotsPerInchY();
+ m_dpiX = KReportDpi::dpiX();
+ m_dpiY = KReportDpi::dpiY();
if (m_unit.type() != m_rd->pageUnit().type()) {
m_unit = m_rd->pageUnit();
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic