Changeset View
Changeset View
Standalone View
Standalone View
src/wrtembed/KReportDesigner.cpp
Show First 20 Lines • Show All 144 Lines • ▼ Show 20 Line(s) | 113 | public: | |||
---|---|---|---|---|---|
145 | 145 | | |||
146 | //Properties | 146 | //Properties | ||
147 | KPropertySet set; | 147 | KPropertySet set; | ||
148 | KPropertySet *itemSet; | 148 | KPropertySet *itemSet; | ||
149 | KProperty *title; | 149 | KProperty *title; | ||
150 | KProperty *pageSize; | 150 | KProperty *pageSize; | ||
151 | KProperty *orientation; | 151 | KProperty *orientation; | ||
152 | KProperty *unit; | 152 | KProperty *unit; | ||
153 | KProperty *customHeight; | 153 | KProperty *customPageSize; | ||
154 | KProperty *customWidth; | | |||
155 | KProperty *leftMargin; | 154 | KProperty *leftMargin; | ||
156 | KProperty *rightMargin; | 155 | KProperty *rightMargin; | ||
157 | KProperty *topMargin; | 156 | KProperty *topMargin; | ||
158 | KProperty *bottomMargin; | 157 | KProperty *bottomMargin; | ||
159 | KProperty *showGrid; | 158 | KProperty *showGrid; | ||
160 | KProperty *gridDivisions; | 159 | KProperty *gridDivisions; | ||
161 | KProperty *gridSnap; | 160 | KProperty *gridSnap; | ||
162 | KProperty *labelType; | 161 | KProperty *labelType; | ||
▲ Show 20 Lines • Show All 128 Lines • ▼ Show 20 Line(s) | 283 | #endif | |||
291 | 290 | | |||
292 | //! @todo Load page options | 291 | //! @todo Load page options | ||
293 | else if (n == QLatin1String("report:page-style")) { | 292 | else if (n == QLatin1String("report:page-style")) { | ||
294 | QString pagetype = it.firstChild().nodeValue(); | 293 | QString pagetype = it.firstChild().nodeValue(); | ||
295 | 294 | | |||
296 | if (pagetype == QLatin1String("predefined")) { | 295 | if (pagetype == QLatin1String("predefined")) { | ||
297 | d->pageSize->setValue(it.toElement().attribute(QLatin1String("report:page-size"), QLatin1String("A4"))); | 296 | d->pageSize->setValue(it.toElement().attribute(QLatin1String("report:page-size"), QLatin1String("A4"))); | ||
298 | } else if (pagetype == QLatin1String("custom")) { | 297 | } else if (pagetype == QLatin1String("custom")) { | ||
299 | d->pageSize->setValue(QLatin1String("custom")); | 298 | d->pageSize->setValue(QLatin1String("Custom")); | ||
300 | d->customHeight->setValue(KReportUnit::parseValue(it.toElement().attribute(QLatin1String("report:custom-page-height"), QLatin1String("")))); | 299 | d->customPageSize->setValue(QSizeF(KReportUnit::parseValue(it.toElement().attribute(QLatin1String("report:custom-page-width"), QLatin1String(""))), | ||
301 | d->customWidth->setValue(KReportUnit::parseValue(it.toElement().attribute(QLatin1String("report:custom-page-widtht"), QLatin1String("")))); | 300 | KReportUnit::parseValue(it.toElement().attribute(QLatin1String("report:custom-page-height"), QLatin1String(""))))); | ||
staniek: Line too long | |||||
302 | } else if (pagetype == QLatin1String("label")) { | 301 | } else if (pagetype == QLatin1String("label")) { | ||
303 | //! @todo | 302 | //! @todo | ||
304 | } | 303 | } | ||
305 | 304 | | |||
306 | d->rightMargin->setValue(KReportUnit::parseValue(it.toElement().attribute(QLatin1String("fo:margin-right"), QLatin1String("1.0cm")))); | 305 | d->rightMargin->setValue(KReportUnit::parseValue(it.toElement().attribute(QLatin1String("fo:margin-right"), QLatin1String("1.0cm")))); | ||
307 | d->leftMargin->setValue(KReportUnit::parseValue(it.toElement().attribute(QLatin1String("fo:margin-left"), QLatin1String("1.0cm")))); | 306 | d->leftMargin->setValue(KReportUnit::parseValue(it.toElement().attribute(QLatin1String("fo:margin-left"), QLatin1String("1.0cm")))); | ||
308 | d->topMargin->setValue(KReportUnit::parseValue(it.toElement().attribute(QLatin1String("fo:margin-top"), QLatin1String("1.0cm")))); | 307 | d->topMargin->setValue(KReportUnit::parseValue(it.toElement().attribute(QLatin1String("fo:margin-top"), QLatin1String("1.0cm")))); | ||
309 | d->bottomMargin->setValue(KReportUnit::parseValue(it.toElement().attribute(QLatin1String("fo:margin-bottom"), QLatin1String("1.0cm")))); | 308 | d->bottomMargin->setValue(KReportUnit::parseValue(it.toElement().attribute(QLatin1String("fo:margin-bottom"), QLatin1String("1.0cm")))); | ||
▲ Show 20 Lines • Show All 77 Lines • ▼ Show 20 Line(s) | 379 | #endif | |||
387 | content.appendChild(grd); | 386 | content.appendChild(grd); | ||
388 | 387 | | |||
389 | // pageOptions | 388 | // pageOptions | ||
390 | // -- size | 389 | // -- size | ||
391 | QDomElement pagestyle = doc.createElement(QLatin1String("report:page-style")); | 390 | QDomElement pagestyle = doc.createElement(QLatin1String("report:page-style")); | ||
392 | 391 | | |||
393 | if (d->pageSize->value().toString() == QLatin1String("Custom")) { | 392 | if (d->pageSize->value().toString() == QLatin1String("Custom")) { | ||
394 | pagestyle.appendChild(doc.createTextNode(QLatin1String("custom"))); | 393 | pagestyle.appendChild(doc.createTextNode(QLatin1String("custom"))); | ||
395 | KReportUtils::setAttribute(&pagestyle, QLatin1String("report:custom-page-width"), d->customWidth->value().toDouble()); | 394 | KReportUtils::setAttribute(&pagestyle, QLatin1String("report:custom-page-width"), d->customPageSize->value().toSizeF().width()); | ||
396 | KReportUtils::setAttribute(&pagestyle, QLatin1String("report:custom-page-height"), d->customHeight->value().toDouble()); | 395 | KReportUtils::setAttribute(&pagestyle, QLatin1String("report:custom-page-height"), d->customPageSize->value().toSizeF().height()); | ||
397 | 396 | | |||
398 | } else if (d->pageSize->value().toString() == QLatin1String("Label")) { | 397 | } else if (d->pageSize->value().toString() == QLatin1String("Label")) { | ||
399 | pagestyle.appendChild(doc.createTextNode(QLatin1String("label"))); | 398 | pagestyle.appendChild(doc.createTextNode(QLatin1String("label"))); | ||
400 | pagestyle.setAttribute(QLatin1String("report:page-label-type"), d->labelType->value().toString()); | 399 | pagestyle.setAttribute(QLatin1String("report:page-label-type"), d->labelType->value().toString()); | ||
401 | } else { | 400 | } else { | ||
402 | pagestyle.appendChild(doc.createTextNode(QLatin1String("predefined"))); | 401 | pagestyle.appendChild(doc.createTextNode(QLatin1String("predefined"))); | ||
403 | KReportUtils::addPropertyAsAttribute(&pagestyle, d->pageSize); | 402 | KReportUtils::addPropertyAsAttribute(&pagestyle, d->pageSize); | ||
404 | //pagestyle.setAttribute("report:page-size", d->pageSize->value().toString()); | 403 | //pagestyle.setAttribute("report:page-size", d->pageSize->value().toString()); | ||
▲ Show 20 Lines • Show All 317 Lines • ▼ Show 20 Line(s) | 720 | { | |||
722 | KReportDesigner::addMetaProperties(&d->set, | 721 | KReportDesigner::addMetaProperties(&d->set, | ||
723 | tr("Report", "Main report element"), QLatin1String("kreport-report-element")); | 722 | tr("Report", "Main report element"), QLatin1String("kreport-report-element")); | ||
724 | 723 | | |||
725 | connect(&d->set, SIGNAL(propertyChanged(KPropertySet&,KProperty&)), | 724 | connect(&d->set, SIGNAL(propertyChanged(KPropertySet&,KProperty&)), | ||
726 | this, SLOT(slotPropertyChanged(KPropertySet&,KProperty&))); | 725 | this, SLOT(slotPropertyChanged(KPropertySet&,KProperty&))); | ||
727 | 726 | | |||
728 | d->title = new KProperty("title", QLatin1String("Report"), tr("Title"), tr("Report Title")); | 727 | d->title = new KProperty("title", QLatin1String("Report"), tr("Title"), tr("Report Title")); | ||
729 | 728 | | |||
730 | KPropertyListData *listData = new KPropertyListData(KReportPageSize::pageFormatKeys(), | 729 | KPropertyListData *listData = new KPropertyListData(KReportPageSize::pageFormatKeys(), | ||
Let's use QPrinterInfo::defaultPrinter().defaultPageSize() as the default. staniek: Let's use QPrinterInfo::defaultPrinter().defaultPageSize() as the default. | |||||
piggz: at least on my system, defaultPageSize() returns an invalid size; | |||||
staniek: Lines too long.. | |||||
731 | KReportPageSize::pageFormatNames()); | 730 | KReportPageSize::pageFormatNames()); | ||
staniek: Let's have custom-page-size property (tr("Custom Page Size")) of type SizeF.
| |||||
732 | QVariant defaultKey = KReportPageSize::pageSizeKey(KReportPageSize::defaultSize()); | 731 | QVariant defaultKey = KReportPageSize::pageSizeKey(KReportPageSize::defaultSize()); | ||
TODO: later let's have this default unit defined somewhere in a single place. staniek: TODO: later let's have this default unit defined somewhere in a single place. | |||||
733 | d->pageSize = new KProperty("page-size", listData, defaultKey, tr("Page Size")); | 732 | d->pageSize = new KProperty("page-size", listData, defaultKey, tr("Page Size")); | ||
734 | 733 | | |||
734 | d->customPageSize = new KProperty("custom-page-size", QSizeF(KReportUnit(KReportUnit::Centimeter).fromUserValue(10), KReportUnit(KReportUnit::Centimeter).fromUserValue(10)), | ||||
735 | tr("Custom Page Size"), tr("Custom Page Size"), KProperty::SizeF); | ||||
736 | | ||||
staniek: Is it good time to remove this code? | |||||
735 | listData = new KPropertyListData({ QLatin1String("portrait"), QLatin1String("landscape") }, | 737 | listData = new KPropertyListData({ QLatin1String("portrait"), QLatin1String("landscape") }, | ||
736 | QVariantList{ tr("Portrait"), tr("Landscape") }); | 738 | QVariantList{ tr("Portrait"), tr("Landscape") }); | ||
737 | d->orientation = new KProperty("print-orientation", listData, QLatin1String("portrait"), | 739 | d->orientation = new KProperty("print-orientation", listData, QLatin1String("portrait"), | ||
738 | tr("Page Orientation")); | 740 | tr("Page Orientation")); | ||
739 | 741 | | |||
740 | QStringList keys; | 742 | QStringList keys; | ||
741 | QStringList strings = KReportUnit::listOfUnitNameForUi(KReportUnit::HidePixel); | 743 | QStringList strings = KReportUnit::listOfUnitNameForUi(KReportUnit::HidePixel); | ||
742 | QString unit; | 744 | QString unit; | ||
Show All 19 Lines | 763 | d->bottomMargin = new KProperty("margin-bottom", KReportUnit(KReportUnit::Centimeter).fromUserValue(1.0), | |||
762 | tr("Bottom Margin"), tr("Bottom Margin"), KProperty::Double); | 764 | tr("Bottom Margin"), tr("Bottom Margin"), KProperty::Double); | ||
763 | d->leftMargin->setOption("unit", QLatin1String("cm")); | 765 | d->leftMargin->setOption("unit", QLatin1String("cm")); | ||
764 | d->rightMargin->setOption("unit", QLatin1String("cm")); | 766 | d->rightMargin->setOption("unit", QLatin1String("cm")); | ||
765 | d->topMargin->setOption("unit", QLatin1String("cm")); | 767 | d->topMargin->setOption("unit", QLatin1String("cm")); | ||
766 | d->bottomMargin->setOption("unit", QLatin1String("cm")); | 768 | d->bottomMargin->setOption("unit", QLatin1String("cm")); | ||
767 | 769 | | |||
768 | d->set.addProperty(d->title); | 770 | d->set.addProperty(d->title); | ||
769 | d->set.addProperty(d->pageSize); | 771 | d->set.addProperty(d->pageSize); | ||
772 | d->set.addProperty(d->customPageSize); | ||||
770 | d->set.addProperty(d->orientation); | 773 | d->set.addProperty(d->orientation); | ||
771 | d->set.addProperty(d->unit); | 774 | d->set.addProperty(d->unit); | ||
772 | d->set.addProperty(d->gridSnap); | 775 | d->set.addProperty(d->gridSnap); | ||
773 | d->set.addProperty(d->showGrid); | 776 | d->set.addProperty(d->showGrid); | ||
774 | d->set.addProperty(d->gridDivisions); | 777 | d->set.addProperty(d->gridDivisions); | ||
775 | d->set.addProperty(d->leftMargin); | 778 | d->set.addProperty(d->leftMargin); | ||
776 | d->set.addProperty(d->rightMargin); | 779 | d->set.addProperty(d->rightMargin); | ||
777 | d->set.addProperty(d->topMargin); | 780 | d->set.addProperty(d->topMargin); | ||
778 | d->set.addProperty(d->bottomMargin); | 781 | d->set.addProperty(d->bottomMargin); | ||
779 | 782 | | |||
780 | #ifdef KREPORT_SCRIPTING | 783 | #ifdef KREPORT_SCRIPTING | ||
781 | d->script = new KProperty("script", new KPropertyListData, QVariant(), tr("Object Script")); | 784 | d->script = new KProperty("script", new KPropertyListData, QVariant(), tr("Object Script")); | ||
782 | d->set.addProperty(d->script); | 785 | d->set.addProperty(d->script); | ||
783 | #endif | 786 | #endif | ||
784 | 787 | | |||
785 | // KProperty* _customHeight; | | |||
786 | // KProperty* _customWidth; | | |||
787 | | ||||
788 | } | 788 | } | ||
789 | 789 | | |||
790 | /** | 790 | /** | ||
791 | @brief Handle property changes | 791 | @brief Handle property changes | ||
792 | */ | 792 | */ | ||
793 | void KReportDesigner::slotPropertyChanged(KPropertySet &s, KProperty &p) | 793 | void KReportDesigner::slotPropertyChanged(KPropertySet &s, KProperty &p) | ||
staniek: TODO future idea: If `p` is page size or custom page size or margin, and the margin is too big… | |||||
Moved to T6557 staniek: Moved to T6557 | |||||
794 | { | 794 | { | ||
795 | setModified(true); | 795 | setModified(true); | ||
796 | emit pagePropertyChanged(s); | 796 | emit pagePropertyChanged(s); | ||
797 | 797 | | |||
798 | if (p.name() == "page-unit") { | 798 | if (p.name() == "page-unit") { | ||
799 | d->hruler->setUnit(pageUnit()); | 799 | d->hruler->setUnit(pageUnit()); | ||
800 | QString newstr = d->set.property("page-unit").value().toString(); | 800 | QString newstr = d->set.property("page-unit").value().toString(); | ||
801 | 801 | | |||
802 | d->set.property("margin-left").setOption("unit", newstr); | 802 | d->set.property("margin-left").setOption("unit", newstr); | ||
803 | d->set.property("margin-right").setOption("unit", newstr); | 803 | d->set.property("margin-right").setOption("unit", newstr); | ||
804 | d->set.property("margin-top").setOption("unit", newstr); | 804 | d->set.property("margin-top").setOption("unit", newstr); | ||
805 | d->set.property("margin-bottom").setOption("unit", newstr); | 805 | d->set.property("margin-bottom").setOption("unit", newstr); | ||
806 | d->set.property("custom-page-size").setOption("unit", newstr); | ||||
806 | } | 807 | } | ||
807 | } | 808 | } | ||
808 | 809 | | |||
809 | void KReportDesigner::slotPageButton_Pressed() | 810 | void KReportDesigner::slotPageButton_Pressed() | ||
810 | { | 811 | { | ||
811 | #ifdef KREPORT_SCRIPTING | 812 | #ifdef KREPORT_SCRIPTING | ||
812 | if (d->scriptSource) { | 813 | if (d->scriptSource) { | ||
813 | QStringList sl = d->scriptSource->scriptList(); | 814 | QStringList sl = d->scriptSource->scriptList(); | ||
▲ Show 20 Lines • Show All 42 Lines • ▼ Show 20 Line(s) | 823 | { | |||
856 | 857 | | |||
857 | h += d->hruler->height(); | 858 | h += d->hruler->height(); | ||
858 | 859 | | |||
859 | return QSize(w, h); | 860 | return QSize(w, h); | ||
860 | } | 861 | } | ||
861 | 862 | | |||
862 | int KReportDesigner::pageWidthPx() const | 863 | int KReportDesigner::pageWidthPx() const | ||
863 | { | 864 | { | ||
865 | QSize pageSizePx; | ||||
staniek: remove debug.. | |||||
866 | int pageWidth; | ||||
867 | int pageHeight; | ||||
868 | | ||||
869 | if (d->set.property("page-size").value().toString() == QLatin1String("Custom")) { | ||||
870 | KReportUnit unit = pageUnit(); | ||||
871 | | ||||
872 | QSizeF customSize = d->set.property("custom-page-size").value().toSizeF(); | ||||
873 | QPageLayout layout(QPageSize(customSize.toSize(), QString(), QPageSize::ExactMatch), d->set.property("print-orientation").value().toString() | ||||
staniek: Do we need toSize() here? QSizeF is accepted in the ctor. | |||||
QSize is used to gice size in POints .. QSizeF is used when units are specified. The ctors are different. piggz: QSize is used to gice size in POints .. QSizeF is used when units are specified. The ctors are… | |||||
I am looking at accuracy here. Do you think QPageSize(customSize, staniek: I am looking at accuracy here. Do you think QPageSize(customSize,
QPageSize::Point, ...) is… | |||||
874 | == QLatin1String("portrait") ? QPageLayout::Portrait : QPageLayout::Landscape, QMarginsF(0,0,0,0)); | ||||
staniek: remove or disable debug here and elsewhere.. | |||||
875 | | ||||
876 | pageSizePx = layout.fullRectPixels(KReportPrivate::dpiX()).size(); | ||||
877 | } else { | ||||
864 | QPageLayout layout = QPageLayout( | 878 | QPageLayout layout = QPageLayout( | ||
865 | QPageSize(KReportPageSize::pageSize(d->set.property("page-size").value().toString())), | 879 | QPageSize(KReportPageSize::pageSize(d->set.property("page-size").value().toString())), | ||
866 | d->set.property("print-orientation").value().toString() | 880 | d->set.property("print-orientation").value().toString() | ||
867 | == QLatin1String("portrait") ? QPageLayout::Portrait : QPageLayout::Landscape, QMarginsF(0,0,0,0)); | 881 | == QLatin1String("portrait") ? QPageLayout::Portrait : QPageLayout::Landscape, QMarginsF(0,0,0,0)); | ||
882 | pageSizePx = layout.fullRectPixels(KReportPrivate::dpiX()).size(); | ||||
883 | } | ||||
868 | 884 | | |||
869 | QSize pageSizePx = layout.fullRectPixels(KReportPrivate::dpiX()).size(); | 885 | pageWidth = pageSizePx.width(); | ||
886 | pageHeight = pageSizePx.height(); | ||||
870 | 887 | | |||
871 | int width = pageSizePx.width(); | 888 | if ((d->set.property("print-orientation").value().toString() == QLatin1String("portrait") && (pageWidth > pageHeight)) || | ||
872 | width = width - POINT_TO_INCH(d->set.property("margin-left").value().toDouble()) * KReportPrivate::dpiX(); | 889 | (d->set.property("print-orientation").value().toString() == QLatin1String("landscape") && (pageWidth < pageHeight))) { | ||
873 | width = width - POINT_TO_INCH(d->set.property("margin-right").value().toDouble()) * KReportPrivate::dpiX(); | 890 | pageWidth = pageHeight; | ||
891 | } | ||||
874 | 892 | | |||
875 | return width; | 893 | pageWidth = pageWidth - POINT_TO_INCH(d->set.property("margin-left").value().toDouble()) * KReportPrivate::dpiX(); | ||
894 | pageWidth = pageWidth - POINT_TO_INCH(d->set.property("margin-right").value().toDouble()) * KReportPrivate::dpiX(); | ||||
895 | | ||||
896 | return pageWidth; | ||||
876 | } | 897 | } | ||
877 | 898 | | |||
878 | void KReportDesigner::resizeEvent(QResizeEvent * event) | 899 | void KReportDesigner::resizeEvent(QResizeEvent * event) | ||
879 | { | 900 | { | ||
880 | Q_UNUSED(event); | 901 | Q_UNUSED(event); | ||
881 | d->hruler->setRulerLength(pageWidthPx()); | 902 | d->hruler->setRulerLength(pageWidthPx()); | ||
882 | } | 903 | } | ||
883 | 904 | | |||
▲ Show 20 Lines • Show All 164 Lines • ▼ Show 20 Line(s) | |||||
1048 | void KReportDesigner::changeSet(KPropertySet *s) | 1069 | void KReportDesigner::changeSet(KPropertySet *s) | ||
1049 | { | 1070 | { | ||
1050 | //Set the checked state of the report properties button | 1071 | //Set the checked state of the report properties button | ||
1051 | if (s == &d->set) | 1072 | if (s == &d->set) | ||
1052 | d->pageButton->setCheckState(Qt::Checked); | 1073 | d->pageButton->setCheckState(Qt::Checked); | ||
1053 | else | 1074 | else | ||
1054 | d->pageButton->setCheckState(Qt::Unchecked); | 1075 | d->pageButton->setCheckState(Qt::Unchecked); | ||
1055 | 1076 | | |||
1077 | if (d->itemSet != s) { | ||||
1056 | d->itemSet = s; | 1078 | d->itemSet = s; | ||
1057 | emit propertySetChanged(); | 1079 | emit propertySetChanged(); | ||
1058 | } | 1080 | } | ||
1081 | } | ||||
1059 | 1082 | | |||
1060 | // | 1083 | // | ||
1061 | // Actions | 1084 | // Actions | ||
1062 | // | 1085 | // | ||
1063 | 1086 | | |||
1064 | void KReportDesigner::slotItem(const QString &entity) | 1087 | void KReportDesigner::slotItem(const QString &entity) | ||
1065 | { | 1088 | { | ||
1066 | //kreportDebug() << entity; | 1089 | //kreportDebug() << entity; | ||
▲ Show 20 Lines • Show All 486 Lines • Show Last 20 Lines |
Line too long