[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [kreport] src: Add support for custom page width/height
From:       Adam Pigg <null () kde ! org>
Date:       2017-08-24 8:38:42
Message-ID: E1dknf0-0007gA-3t () code ! kde ! org
[Download RAW message or body]

Git commit d5194fc276c6a37b6d00acf3120375f963bc64d6 by Adam Pigg.
Committed on 24/08/2017 at 08:38.
Pushed by piggz into branch 'master'.

Add support for custom page width/height

Summary: Add support for custom page sizes, specified in user units/points

Test Plan:
Created report with 10x10cm size.  Displays ok in designer and viewer

Printed report from Kexi with custom size to PDF.  Seems to work ok.

Reviewers: staniek

Reviewed By: staniek

Tags: #kreport

Differential Revision: https://phabricator.kde.org/D1263

M  +3    -2    src/common/KReportDocument.cpp
M  +2    -0    src/common/KReportPageSize.cpp
M  +0    -14   src/renderer/KReportPage.cpp
M  +4    -4    src/renderer/KReportPrintRenderer_p.cpp
M  +39   -23   src/wrtembed/KReportDesigner.cpp
M  +7    -4    src/wrtembed/KReportDesignerSection.cpp
M  +1    -1    src/wrtembed/KReportDesignerSection.h

https://commits.kde.org/kreport/d5194fc276c6a37b6d00acf3120375f963bc64d6

diff --git a/src/common/KReportDocument.cpp b/src/common/KReportDocument.cpp
index 61277c8..aa22362 100644
--- a/src/common/KReportDocument.cpp
+++ b/src/common/KReportDocument.cpp
@@ -72,7 +72,7 @@ KReportDocument::KReportDocument(const QDomElement & elemSource, \
QObject *parent  << elemSource.text();
         return;
     }
-
+    
     QDomNodeList sections = elemSource.childNodes();
     for (int nodeCounter = 0; nodeCounter < sections.count(); nodeCounter++) {
         QDomElement elemThis = sections.item(nodeCounter).toElement();
@@ -93,7 +93,8 @@ KReportDocument::KReportDocument(const QDomElement & elemSource, \
                QObject *parent
                 setPageSize(elemThis.attribute(QLatin1String("report:page-size"), \
                QLatin1String("A4")));
                 d->pageLayout.setPageSize(QPageSize(KReportPageSize::pageSize(pageSize())));
  } else if (pagetype == QLatin1String("custom")) {
-                QPageSize \
custom(QSize(elemThis.attribute(QLatin1String("report:custom-page-width"), \
QString()).toFloat() , elemThis.attribute(QLatin1String("report:custom-page-height"), \
QString()).toFloat()), QLatin1String("Custom")); +                kreportDebug() << \
"Setting custom page size in document to " << \
KReportUnit::parseValue(elemThis.attribute(QLatin1String("report:custom-page-width"), \
QLatin1String("5.0cm"))) << \
KReportUnit::parseValue(elemThis.attribute(QLatin1String("report:custom-page-height"), \
QLatin1String("5.0cm"))) ; +                QPageSize \
custom(QSize(KReportUnit::parseValue(elemThis.attribute(QLatin1String("report:custom-page-width"), \
QLatin1String("5.0cm")))  , \
KReportUnit::parseValue(elemThis.attribute(QLatin1String("report:custom-page-height"), \
QLatin1String("5.0cm"))) ), QString(), QPageSize::ExactMatch);  
                 d->pageLayout.setPageSize(custom);
             } else if (pagetype == QLatin1String("label")) {
diff --git a/src/common/KReportPageSize.cpp b/src/common/KReportPageSize.cpp
index 7505af5..46509d0 100644
--- a/src/common/KReportPageSize.cpp
+++ b/src/common/KReportPageSize.cpp
@@ -38,7 +38,9 @@ static const KReportPageSizeInfo pageSizeInfo[] = {
                                   "Usually don't translate literally, use \"US \
Legal\""),  QPageSize::Legal},
     { "Screen",	QT_TRANSLATE_NOOP3("KReportPageFormat", "Screen", ""), \
QPageSize::A4}, +    { "Custom", QT_TRANSLATE_NOOP3("KReportPageFormat", "Custom", \
""), QPageSize::Custom},  { "", {"", ""}, QPageSize::LastPageSize}
+
 };
 
 QStringList KReportPageSize::pageFormatNames()
diff --git a/src/renderer/KReportPage.cpp b/src/renderer/KReportPage.cpp
index 1b4cdba..94d3789 100644
--- a/src/renderer/KReportPage.cpp
+++ b/src/renderer/KReportPage.cpp
@@ -60,23 +60,9 @@ KReportPage::KReportPage(QWidget *parent, ORODocument *document)
     int pageWidth;
     int pageHeight;
 
-    QString pageSize = d->reportDocument->pageLayout().pageSize().name();
-
     pageWidth = d->reportDocument->pageLayout().fullRectPixels(KReportPrivate::dpiX()).width();
                
     pageHeight = d->reportDocument->pageLayout().fullRectPixels(KReportPrivate::dpiX()).height();
  
-//TODO remove after check    
-#if 0    
-    if (pageSize == QLatin1String("Custom")) {
-        // if this is custom sized sheet of paper we will just use those values
-
-    } else {
-        // lookup the correct size information for the specified size paper
-        pageWidth = d->reportDocument->pageOptions().pixelSize().width();
-        pageHeight = d->reportDocument->pageOptions().pixelSize().height();
-    }
-#endif
-
     setRect(0, 0, pageWidth, pageHeight);
     //kreportDebug() << "PAGE IS " << pageWidth << "x" << pageHeight;
     d->pixmap = QPixmap(pageWidth, pageHeight);
diff --git a/src/renderer/KReportPrintRenderer_p.cpp \
b/src/renderer/KReportPrintRenderer_p.cpp index f2821c8..c5d3549 100644
--- a/src/renderer/KReportPrintRenderer_p.cpp
+++ b/src/renderer/KReportPrintRenderer_p.cpp
@@ -47,11 +47,11 @@ bool PrintRenderer::setupPrinter( ORODocument * document, \
                QPrinter * pPrinter)
     pPrinter->setOrientation((document->pageLayout().orientation() == \
QPageLayout::Portrait ? QPrinter::Portrait : QPrinter::Landscape));  \
pPrinter->setPageOrder(QPrinter::FirstPageFirst);  
-    if (!document->pageLayout().pageSize().isValid()) {
-        pPrinter->setPageSize(QPrinter::Custom);
-    } else {
+//    if (!document->pageLayout().pageSize().isValid()) {
+//        pPrinter->setPageSize(QPageSize(QSize(document->pageLayout().getCustomWidth(), \
document->pageLayout().getCustomHeight()), QLatin1String("Custom")); +//    } else {
         pPrinter->setPageSize(QPageSize(document->pageLayout().pageSize()));
-    }
+//    }
 
     return true;
 }
diff --git a/src/wrtembed/KReportDesigner.cpp b/src/wrtembed/KReportDesigner.cpp
index e584665..b374544 100644
--- a/src/wrtembed/KReportDesigner.cpp
+++ b/src/wrtembed/KReportDesigner.cpp
@@ -151,8 +151,7 @@ public:
     KProperty *pageSize;
     KProperty *orientation;
     KProperty *unit;
-    KProperty *customHeight;
-    KProperty *customWidth;
+    KProperty *customPageSize;
     KProperty *leftMargin;
     KProperty *rightMargin;
     KProperty *topMargin;
@@ -295,9 +294,9 @@ KReportDesigner::KReportDesigner(QWidget *parent, const \
QDomElement &data)  if (pagetype == QLatin1String("predefined")) {
                     \
d->pageSize->setValue(it.toElement().attribute(QLatin1String("report:page-size"), \
QLatin1String("A4")));  } else if (pagetype == QLatin1String("custom")) {
-                    d->pageSize->setValue(QLatin1String("custom"));
-                    \
d->customHeight->setValue(KReportUnit::parseValue(it.toElement().attribute(QLatin1String("report:custom-page-height"), \
                QLatin1String(""))));
-                    \
d->customWidth->setValue(KReportUnit::parseValue(it.toElement().attribute(QLatin1String("report:custom-page-widtht"), \
QLatin1String("")))); +                    \
d->pageSize->setValue(QLatin1String("Custom")); +                    \
d->customPageSize->setValue(QSizeF(KReportUnit::parseValue(it.toElement().attribute(QLatin1String("report:custom-page-width"), \
QLatin1String(""))), +                        \
KReportUnit::parseValue(it.toElement().attribute(QLatin1String("report:custom-page-height"), \
QLatin1String("")))));  } else if (pagetype == QLatin1String("label")) {
                     //! @todo
                 }
@@ -391,8 +390,8 @@ QDomElement KReportDesigner::document() const
 
     if (d->pageSize->value().toString() == QLatin1String("Custom")) {
         pagestyle.appendChild(doc.createTextNode(QLatin1String("custom")));
-        KReportUtils::setAttribute(&pagestyle, \
                QLatin1String("report:custom-page-width"), \
                d->customWidth->value().toDouble());
-        KReportUtils::setAttribute(&pagestyle, \
QLatin1String("report:custom-page-height"), d->customHeight->value().toDouble()); +   \
KReportUtils::setAttribute(&pagestyle, QLatin1String("report:custom-page-width"), \
d->customPageSize->value().toSizeF().width()); +        \
KReportUtils::setAttribute(&pagestyle, QLatin1String("report:custom-page-height"), \
d->customPageSize->value().toSizeF().height());  
     } else if (d->pageSize->value().toString() == QLatin1String("Label")) {
         pagestyle.appendChild(doc.createTextNode(QLatin1String("label")));
@@ -729,7 +728,10 @@ void KReportDesigner::createProperties()
     KPropertyListData *listData = new \
                KPropertyListData(KReportPageSize::pageFormatKeys(),
                                                         \
                KReportPageSize::pageFormatNames());
     QVariant defaultKey = \
                KReportPageSize::pageSizeKey(KReportPageSize::defaultSize());
-    d->pageSize = new KProperty("page-size", listData, defaultKey, tr("Page Size"));
+    d->pageSize = new KProperty("page-size", listData, defaultKey, tr("Page Size")); \
 +    
+    d->customPageSize = new KProperty("custom-page-size", \
QSizeF(KReportUnit(KReportUnit::Type::Centimeter).fromUserValue(10), \
KReportUnit(KReportUnit::Type::Centimeter).fromUserValue(10)), +        tr("Custom \
Page Size"), tr("Custom Page Size"), KProperty::SizeF);  
     listData = new KPropertyListData({ QLatin1String("portrait"), \
                QLatin1String("landscape") },
                                      QVariantList{ tr("Portrait"), tr("Landscape") \
}); @@ -760,6 +762,7 @@ void KReportDesigner::createProperties()
 
     d->set.addProperty(d->title);
     d->set.addProperty(d->pageSize);
+    d->set.addProperty(d->customPageSize);
     d->set.addProperty(d->orientation);
     d->set.addProperty(d->unit);
     d->set.addProperty(d->gridSnap);
@@ -775,9 +778,6 @@ void KReportDesigner::createProperties()
     d->set.addProperty(d->script);
 #endif
 
-//    KProperty* _customHeight;
-//    KProperty* _customWidth;
-
 }
 
 /**
@@ -796,6 +796,7 @@ void KReportDesigner::slotPropertyChanged(KPropertySet &s, \
KProperty &p)  d->set.property("margin-right").setOption("unit", newstr);
         d->set.property("margin-top").setOption("unit", newstr);
         d->set.property("margin-bottom").setOption("unit", newstr);
+        d->set.property("custom-page-size").setOption("unit", newstr);
     }
 }
 
@@ -854,18 +855,31 @@ QSize KReportDesigner::sizeHint() const
 
 int KReportDesigner::pageWidthPx() const
 {
-    QPageLayout layout = QPageLayout(
-        QPageSize(KReportPageSize::pageSize(d->set.property("page-size").value().toString())),
                
-        d->set.property("print-orientation").value().toString()
-                == QLatin1String("portrait") ? QPageLayout::Portrait : \
                QPageLayout::Landscape, QMarginsF(0,0,0,0));
-
-    QSize pageSizePx = layout.fullRectPixels(KReportPrivate::dpiX()).size();
+    QSize pageSizePx;
+    int pageWidth;
+    
+    if (d->set.property("page-size").value().toString() == QLatin1String("Custom")) \
{ +        KReportUnit unit = pageUnit();
+        
+        QSizeF customSize = d->set.property("custom-page-size").value().toSizeF();
+        QPageLayout layout(QPageSize(customSize, QPageSize::Point, QString(), \
QPageSize::ExactMatch), d->set.property("print-orientation").value().toString() +     \
== QLatin1String("portrait") ? QPageLayout::Portrait : QPageLayout::Landscape, \
QMarginsF(0,0,0,0)); +        
+        pageSizePx = layout.fullRectPixels(KReportPrivate::dpiX()).size();
+    } else {
+        QPageLayout layout = QPageLayout(
+            QPageSize(KReportPageSize::pageSize(d->set.property("page-size").value().toString())),
 +            d->set.property("print-orientation").value().toString()
+                    == QLatin1String("portrait") ? QPageLayout::Portrait : \
QPageLayout::Landscape, QMarginsF(0,0,0,0)); +        pageSizePx = \
layout.fullRectPixels(KReportPrivate::dpiX()).size(); +    }
+    
+    pageWidth = pageSizePx.width();
 
-    int width = pageSizePx.width();
-    width = width - POINT_TO_INCH(d->set.property("margin-left").value().toDouble()) \
                * KReportPrivate::dpiX();
-    width = width - \
POINT_TO_INCH(d->set.property("margin-right").value().toDouble()) * \
KReportPrivate::dpiX(); +    pageWidth = pageWidth - \
POINT_TO_INCH(d->set.property("margin-left").value().toDouble()) * \
KReportPrivate::dpiX(); +    pageWidth = pageWidth - \
POINT_TO_INCH(d->set.property("margin-right").value().toDouble()) * \
KReportPrivate::dpiX();  
-    return width;
+    return pageWidth;
 }
 
 void KReportDesigner::resizeEvent(QResizeEvent * event)
@@ -1038,8 +1052,10 @@ void KReportDesigner::changeSet(KPropertySet *s)
     else
         d->pageButton->setCheckState(Qt::Unchecked);
 
-    d->itemSet = s;
-    emit propertySetChanged();
+    if (d->itemSet != s) {
+        d->itemSet = s;
+        emit propertySetChanged();
+    }
 }
 
 //
diff --git a/src/wrtembed/KReportDesignerSection.cpp \
b/src/wrtembed/KReportDesignerSection.cpp index 62360b1..8310d79 100644
--- a/src/wrtembed/KReportDesignerSection.cpp
+++ b/src/wrtembed/KReportDesignerSection.cpp
@@ -162,13 +162,16 @@ void KReportDesignerSection::setTitle(const QString & s)
     d->title->setText(s);
 }
 
-void KReportDesignerSection::slotResizeBarDragged(int delta)
+void KReportDesignerSection::slotResizeBarDragged(int delta, bool changeSet)
 {
     if (d->sceneView->designer() && \
d->sceneView->designer()->propertySet()->property("page-size").value().toString() == \
                QLatin1String("Labels")) {
         return; // we don't want to allow this on reports that are for labels
     }
-    slotSceneClicked(); // switches property set to this section
-
+    
+    if (changeSet) {
+      slotSceneClicked(); // switches property set to this section
+    }
+    
     qreal h = d->scene->height() + delta;
 
     if (h < 1) h = 1;
@@ -279,7 +282,7 @@ void KReportDesignerSection::slotPageOptionsChanged(KPropertySet \
&set)  d->reportDesigner->adjustSize();
     d->reportDesigner->repaint();
 
-    slotResizeBarDragged(0);
+    slotResizeBarDragged(0, false);
 }
 
 void KReportDesignerSection::slotSceneClicked()
diff --git a/src/wrtembed/KReportDesignerSection.h \
b/src/wrtembed/KReportDesignerSection.h index 45ab813..924f404 100644
--- a/src/wrtembed/KReportDesignerSection.h
+++ b/src/wrtembed/KReportDesignerSection.h
@@ -68,7 +68,7 @@ public:
     void unsetSectionCursor();
 
 protected Q_SLOTS:
-    void slotResizeBarDragged(int delta);
+    void slotResizeBarDragged(int delta, bool changeSet = true);
 
 protected:
     explicit KReportDesignerSection(KReportDesigner * rptdes,


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic