diff --git a/src/common/KReportDocument.cpp b/src/common/KReportDocument.cpp --- a/src/common/KReportDocument.cpp +++ b/src/common/KReportDocument.cpp @@ -72,7 +72,7 @@ << 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 @@ 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 --- a/src/common/KReportPageSize.cpp +++ b/src/common/KReportPageSize.cpp @@ -38,7 +38,9 @@ "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 --- a/src/renderer/KReportPage.cpp +++ b/src/renderer/KReportPage.cpp @@ -60,23 +60,9 @@ 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 --- a/src/renderer/KReportPrintRenderer_p.cpp +++ b/src/renderer/KReportPrintRenderer_p.cpp @@ -47,11 +47,11 @@ 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 --- a/src/wrtembed/KReportDesigner.cpp +++ b/src/wrtembed/KReportDesigner.cpp @@ -151,8 +151,7 @@ KProperty *pageSize; KProperty *orientation; KProperty *unit; - KProperty *customHeight; - KProperty *customWidth; + KProperty *customPageSize; KProperty *leftMargin; KProperty *rightMargin; KProperty *topMargin; @@ -295,9 +294,9 @@ 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 @@ 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 @@ 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 @@ 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 @@ d->set.addProperty(d->script); #endif -// KProperty* _customHeight; -// KProperty* _customWidth; - } /** @@ -796,6 +796,7 @@ 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 @@ 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 @@ 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.h b/src/wrtembed/KReportDesignerSection.h --- a/src/wrtembed/KReportDesignerSection.h +++ b/src/wrtembed/KReportDesignerSection.h @@ -68,7 +68,7 @@ void unsetSectionCursor(); protected Q_SLOTS: - void slotResizeBarDragged(int delta); + void slotResizeBarDragged(int delta, bool changeSet = true); protected: explicit KReportDesignerSection(KReportDesigner * rptdes, diff --git a/src/wrtembed/KReportDesignerSection.cpp b/src/wrtembed/KReportDesignerSection.cpp --- a/src/wrtembed/KReportDesignerSection.cpp +++ b/src/wrtembed/KReportDesignerSection.cpp @@ -162,13 +162,16 @@ 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 @@ d->reportDesigner->adjustSize(); d->reportDesigner->repaint(); - slotResizeBarDragged(0); + slotResizeBarDragged(0, false); } void KReportDesignerSection::slotSceneClicked()