Changeset View
Changeset View
Standalone View
Standalone View
src/wrtembed/KReportDesigner.cpp
Show First 20 Lines • Show All 145 Lines • ▼ Show 20 Line(s) | 114 | public: | |||
---|---|---|---|---|---|
146 | 146 | | |||
147 | //Properties | 147 | //Properties | ||
148 | KPropertySet set; | 148 | KPropertySet set; | ||
149 | KPropertySet *itemSet; | 149 | KPropertySet *itemSet; | ||
150 | KProperty *title; | 150 | KProperty *title; | ||
151 | KProperty *pageSize; | 151 | KProperty *pageSize; | ||
152 | KProperty *orientation; | 152 | KProperty *orientation; | ||
153 | KProperty *unit; | 153 | KProperty *unit; | ||
154 | KProperty *customHeight; | 154 | KProperty *customPageSize; | ||
155 | KProperty *customWidth; | | |||
156 | KProperty *leftMargin; | 155 | KProperty *leftMargin; | ||
157 | KProperty *rightMargin; | 156 | KProperty *rightMargin; | ||
158 | KProperty *topMargin; | 157 | KProperty *topMargin; | ||
159 | KProperty *bottomMargin; | 158 | KProperty *bottomMargin; | ||
160 | KProperty *showGrid; | 159 | KProperty *showGrid; | ||
161 | KProperty *gridDivisions; | 160 | KProperty *gridDivisions; | ||
162 | KProperty *gridSnap; | 161 | KProperty *gridSnap; | ||
163 | KProperty *labelType; | 162 | KProperty *labelType; | ||
▲ Show 20 Lines • Show All 126 Lines • ▼ Show 20 Line(s) | 282 | #endif | |||
290 | 289 | | |||
291 | //! @todo Load page options | 290 | //! @todo Load page options | ||
292 | else if (n == QLatin1String("report:page-style")) { | 291 | else if (n == QLatin1String("report:page-style")) { | ||
293 | QString pagetype = it.firstChild().nodeValue(); | 292 | QString pagetype = it.firstChild().nodeValue(); | ||
294 | 293 | | |||
295 | if (pagetype == QLatin1String("predefined")) { | 294 | if (pagetype == QLatin1String("predefined")) { | ||
296 | d->pageSize->setValue(it.toElement().attribute(QLatin1String("report:page-size"), QLatin1String("A4"))); | 295 | d->pageSize->setValue(it.toElement().attribute(QLatin1String("report:page-size"), QLatin1String("A4"))); | ||
297 | } else if (pagetype == QLatin1String("custom")) { | 296 | } else if (pagetype == QLatin1String("custom")) { | ||
298 | d->pageSize->setValue(QLatin1String("custom")); | 297 | d->pageSize->setValue(QLatin1String("Custom")); | ||
299 | d->customHeight->setValue(KReportUnit::parseValue(it.toElement().attribute(QLatin1String("report:custom-page-height"), QLatin1String("")))); | 298 | d->customPageSize->setValue(QSizeF(KReportUnit::parseValue(it.toElement().attribute(QLatin1String("report:custom-page-width"), QLatin1String(""))), | ||
300 | d->customWidth->setValue(KReportUnit::parseValue(it.toElement().attribute(QLatin1String("report:custom-page-widtht"), QLatin1String("")))); | 299 | KReportUnit::parseValue(it.toElement().attribute(QLatin1String("report:custom-page-height"), QLatin1String(""))))); | ||
staniek: Line too long | |||||
301 | } else if (pagetype == QLatin1String("label")) { | 300 | } else if (pagetype == QLatin1String("label")) { | ||
302 | //! @todo | 301 | //! @todo | ||
303 | } | 302 | } | ||
304 | 303 | | |||
305 | d->rightMargin->setValue(KReportUnit::parseValue(it.toElement().attribute(QLatin1String("fo:margin-right"), QLatin1String("1.0cm")))); | 304 | d->rightMargin->setValue(KReportUnit::parseValue(it.toElement().attribute(QLatin1String("fo:margin-right"), QLatin1String("1.0cm")))); | ||
306 | d->leftMargin->setValue(KReportUnit::parseValue(it.toElement().attribute(QLatin1String("fo:margin-left"), QLatin1String("1.0cm")))); | 305 | d->leftMargin->setValue(KReportUnit::parseValue(it.toElement().attribute(QLatin1String("fo:margin-left"), QLatin1String("1.0cm")))); | ||
307 | d->topMargin->setValue(KReportUnit::parseValue(it.toElement().attribute(QLatin1String("fo:margin-top"), QLatin1String("1.0cm")))); | 306 | d->topMargin->setValue(KReportUnit::parseValue(it.toElement().attribute(QLatin1String("fo:margin-top"), QLatin1String("1.0cm")))); | ||
308 | d->bottomMargin->setValue(KReportUnit::parseValue(it.toElement().attribute(QLatin1String("fo:margin-bottom"), QLatin1String("1.0cm")))); | 307 | 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) | 378 | #endif | |||
386 | content.appendChild(grd); | 385 | content.appendChild(grd); | ||
387 | 386 | | |||
388 | // pageOptions | 387 | // pageOptions | ||
389 | // -- size | 388 | // -- size | ||
390 | QDomElement pagestyle = doc.createElement(QLatin1String("report:page-style")); | 389 | QDomElement pagestyle = doc.createElement(QLatin1String("report:page-style")); | ||
391 | 390 | | |||
392 | if (d->pageSize->value().toString() == QLatin1String("Custom")) { | 391 | if (d->pageSize->value().toString() == QLatin1String("Custom")) { | ||
393 | pagestyle.appendChild(doc.createTextNode(QLatin1String("custom"))); | 392 | pagestyle.appendChild(doc.createTextNode(QLatin1String("custom"))); | ||
394 | KReportUtils::setAttribute(&pagestyle, QLatin1String("report:custom-page-width"), d->customWidth->value().toDouble()); | 393 | KReportUtils::setAttribute(&pagestyle, QLatin1String("report:custom-page-width"), d->customPageSize->value().toSizeF().width()); | ||
395 | KReportUtils::setAttribute(&pagestyle, QLatin1String("report:custom-page-height"), d->customHeight->value().toDouble()); | 394 | KReportUtils::setAttribute(&pagestyle, QLatin1String("report:custom-page-height"), d->customPageSize->value().toSizeF().height()); | ||
396 | 395 | | |||
397 | } else if (d->pageSize->value().toString() == QLatin1String("Label")) { | 396 | } else if (d->pageSize->value().toString() == QLatin1String("Label")) { | ||
398 | pagestyle.appendChild(doc.createTextNode(QLatin1String("label"))); | 397 | pagestyle.appendChild(doc.createTextNode(QLatin1String("label"))); | ||
399 | pagestyle.setAttribute(QLatin1String("report:page-label-type"), d->labelType->value().toString()); | 398 | pagestyle.setAttribute(QLatin1String("report:page-label-type"), d->labelType->value().toString()); | ||
400 | } else { | 399 | } else { | ||
401 | pagestyle.appendChild(doc.createTextNode(QLatin1String("predefined"))); | 400 | pagestyle.appendChild(doc.createTextNode(QLatin1String("predefined"))); | ||
402 | KReportUtils::addPropertyAsAttribute(&pagestyle, d->pageSize); | 401 | KReportUtils::addPropertyAsAttribute(&pagestyle, d->pageSize); | ||
403 | //pagestyle.setAttribute("report:page-size", d->pageSize->value().toString()); | 402 | //pagestyle.setAttribute("report:page-size", d->pageSize->value().toString()); | ||
▲ Show 20 Lines • Show All 317 Lines • ▼ Show 20 Line(s) | 719 | { | |||
721 | KReportDesigner::addMetaProperties(&d->set, | 720 | KReportDesigner::addMetaProperties(&d->set, | ||
722 | tr("Report", "Main report element"), QLatin1String("kreport-report-element")); | 721 | tr("Report", "Main report element"), QLatin1String("kreport-report-element")); | ||
723 | 722 | | |||
724 | connect(&d->set, SIGNAL(propertyChanged(KPropertySet&,KProperty&)), | 723 | connect(&d->set, SIGNAL(propertyChanged(KPropertySet&,KProperty&)), | ||
725 | this, SLOT(slotPropertyChanged(KPropertySet&,KProperty&))); | 724 | this, SLOT(slotPropertyChanged(KPropertySet&,KProperty&))); | ||
726 | 725 | | |||
727 | d->title = new KProperty("title", QLatin1String("Report"), tr("Title"), tr("Report Title")); | 726 | d->title = new KProperty("title", QLatin1String("Report"), tr("Title"), tr("Report Title")); | ||
728 | 727 | | |||
729 | KPropertyListData *listData = new KPropertyListData(KReportPageSize::pageFormatKeys(), | 728 | 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.. | |||||
730 | KReportPageSize::pageFormatNames()); | 729 | KReportPageSize::pageFormatNames()); | ||
staniek: Let's have custom-page-size property (tr("Custom Page Size")) of type SizeF.
| |||||
731 | QVariant defaultKey = KReportPageSize::pageSizeKey(KReportPageSize::defaultSize()); | 730 | 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. | |||||
732 | d->pageSize = new KProperty("page-size", listData, defaultKey, tr("Page Size")); | 731 | d->pageSize = new KProperty("page-size", listData, defaultKey, tr("Page Size")); | ||
733 | 732 | | |||
733 | d->customPageSize = new KProperty("custom-page-size", QSizeF(KReportUnit(KReportUnit::Type::Centimeter).fromUserValue(10), KReportUnit(KReportUnit::Type::Centimeter).fromUserValue(10)), | ||||
734 | tr("Custom Page Size"), tr("Custom Page Size"), KProperty::SizeF); | ||||
735 | | ||||
staniek: Is it good time to remove this code? | |||||
734 | listData = new KPropertyListData({ QLatin1String("portrait"), QLatin1String("landscape") }, | 736 | listData = new KPropertyListData({ QLatin1String("portrait"), QLatin1String("landscape") }, | ||
735 | QVariantList{ tr("Portrait"), tr("Landscape") }); | 737 | QVariantList{ tr("Portrait"), tr("Landscape") }); | ||
736 | d->orientation = new KProperty("print-orientation", listData, QLatin1String("portrait"), | 738 | d->orientation = new KProperty("print-orientation", listData, QLatin1String("portrait"), | ||
737 | tr("Page Orientation")); | 739 | tr("Page Orientation")); | ||
738 | 740 | | |||
739 | QList<KReportUnit::Type> types(KReportUnit::allTypes()); | 741 | QList<KReportUnit::Type> types(KReportUnit::allTypes()); | ||
740 | types.removeOne(KReportUnit::Type::Pixel); | 742 | types.removeOne(KReportUnit::Type::Pixel); | ||
741 | listData = new KPropertyListData(KReportUnit::symbols(types), KReportUnit::descriptions(types)); | 743 | listData = new KPropertyListData(KReportUnit::symbols(types), KReportUnit::descriptions(types)); | ||
Show All 13 Lines | 756 | d->bottomMargin = new KProperty("margin-bottom", KReportUnit(KReportUnit::Type::Centimeter).fromUserValue(1.0), | |||
755 | tr("Bottom Margin"), tr("Bottom Margin"), KProperty::Double); | 757 | tr("Bottom Margin"), tr("Bottom Margin"), KProperty::Double); | ||
756 | d->leftMargin->setOption("unit", QLatin1String("cm")); | 758 | d->leftMargin->setOption("unit", QLatin1String("cm")); | ||
757 | d->rightMargin->setOption("unit", QLatin1String("cm")); | 759 | d->rightMargin->setOption("unit", QLatin1String("cm")); | ||
758 | d->topMargin->setOption("unit", QLatin1String("cm")); | 760 | d->topMargin->setOption("unit", QLatin1String("cm")); | ||
759 | d->bottomMargin->setOption("unit", QLatin1String("cm")); | 761 | d->bottomMargin->setOption("unit", QLatin1String("cm")); | ||
760 | 762 | | |||
761 | d->set.addProperty(d->title); | 763 | d->set.addProperty(d->title); | ||
762 | d->set.addProperty(d->pageSize); | 764 | d->set.addProperty(d->pageSize); | ||
765 | d->set.addProperty(d->customPageSize); | ||||
763 | d->set.addProperty(d->orientation); | 766 | d->set.addProperty(d->orientation); | ||
764 | d->set.addProperty(d->unit); | 767 | d->set.addProperty(d->unit); | ||
765 | d->set.addProperty(d->gridSnap); | 768 | d->set.addProperty(d->gridSnap); | ||
766 | d->set.addProperty(d->showGrid); | 769 | d->set.addProperty(d->showGrid); | ||
767 | d->set.addProperty(d->gridDivisions); | 770 | d->set.addProperty(d->gridDivisions); | ||
768 | d->set.addProperty(d->leftMargin); | 771 | d->set.addProperty(d->leftMargin); | ||
769 | d->set.addProperty(d->rightMargin); | 772 | d->set.addProperty(d->rightMargin); | ||
770 | d->set.addProperty(d->topMargin); | 773 | d->set.addProperty(d->topMargin); | ||
771 | d->set.addProperty(d->bottomMargin); | 774 | d->set.addProperty(d->bottomMargin); | ||
772 | 775 | | |||
773 | #ifdef KREPORT_SCRIPTING | 776 | #ifdef KREPORT_SCRIPTING | ||
774 | d->script = new KProperty("script", new KPropertyListData, QVariant(), tr("Object Script")); | 777 | d->script = new KProperty("script", new KPropertyListData, QVariant(), tr("Object Script")); | ||
775 | d->set.addProperty(d->script); | 778 | d->set.addProperty(d->script); | ||
776 | #endif | 779 | #endif | ||
777 | 780 | | |||
778 | // KProperty* _customHeight; | | |||
779 | // KProperty* _customWidth; | | |||
780 | | ||||
781 | } | 781 | } | ||
782 | 782 | | |||
783 | /** | 783 | /** | ||
784 | @brief Handle property changes | 784 | @brief Handle property changes | ||
785 | */ | 785 | */ | ||
786 | void KReportDesigner::slotPropertyChanged(KPropertySet &s, KProperty &p) | 786 | 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 | |||||
787 | { | 787 | { | ||
788 | setModified(true); | 788 | setModified(true); | ||
789 | emit pagePropertyChanged(s); | 789 | emit pagePropertyChanged(s); | ||
790 | 790 | | |||
791 | if (p.name() == "page-unit") { | 791 | if (p.name() == "page-unit") { | ||
792 | d->hruler->setUnit(pageUnit()); | 792 | d->hruler->setUnit(pageUnit()); | ||
793 | QString newstr = d->set.property("page-unit").value().toString(); | 793 | QString newstr = d->set.property("page-unit").value().toString(); | ||
794 | 794 | | |||
795 | d->set.property("margin-left").setOption("unit", newstr); | 795 | d->set.property("margin-left").setOption("unit", newstr); | ||
796 | d->set.property("margin-right").setOption("unit", newstr); | 796 | d->set.property("margin-right").setOption("unit", newstr); | ||
797 | d->set.property("margin-top").setOption("unit", newstr); | 797 | d->set.property("margin-top").setOption("unit", newstr); | ||
798 | d->set.property("margin-bottom").setOption("unit", newstr); | 798 | d->set.property("margin-bottom").setOption("unit", newstr); | ||
799 | d->set.property("custom-page-size").setOption("unit", newstr); | ||||
799 | } | 800 | } | ||
800 | } | 801 | } | ||
801 | 802 | | |||
802 | void KReportDesigner::slotPageButton_Pressed() | 803 | void KReportDesigner::slotPageButton_Pressed() | ||
803 | { | 804 | { | ||
804 | #ifdef KREPORT_SCRIPTING | 805 | #ifdef KREPORT_SCRIPTING | ||
805 | if (d->scriptSource) { | 806 | if (d->scriptSource) { | ||
806 | QStringList sl = d->scriptSource->scriptList(); | 807 | QStringList sl = d->scriptSource->scriptList(); | ||
▲ Show 20 Lines • Show All 42 Lines • ▼ Show 20 Line(s) | 816 | { | |||
849 | 850 | | |||
850 | h += d->hruler->height(); | 851 | h += d->hruler->height(); | ||
851 | 852 | | |||
852 | return QSize(w, h); | 853 | return QSize(w, h); | ||
853 | } | 854 | } | ||
854 | 855 | | |||
855 | int KReportDesigner::pageWidthPx() const | 856 | int KReportDesigner::pageWidthPx() const | ||
856 | { | 857 | { | ||
858 | QSize pageSizePx; | ||||
859 | int pageWidth; | ||||
860 | | ||||
861 | if (d->set.property("page-size").value().toString() == QLatin1String("Custom")) { | ||||
862 | KReportUnit unit = pageUnit(); | ||||
863 | | ||||
864 | QSizeF customSize = d->set.property("custom-page-size").value().toSizeF(); | ||||
865 | QPageLayout layout(QPageSize(customSize, QPageSize::Point, QString(), QPageSize::ExactMatch), d->set.property("print-orientation").value().toString() | ||||
866 | == QLatin1String("portrait") ? QPageLayout::Portrait : QPageLayout::Landscape, QMarginsF(0,0,0,0)); | ||||
867 | | ||||
868 | pageSizePx = layout.fullRectPixels(KReportPrivate::dpiX()).size(); | ||||
869 | } else { | ||||
857 | QPageLayout layout = QPageLayout( | 870 | QPageLayout layout = QPageLayout( | ||
858 | QPageSize(KReportPageSize::pageSize(d->set.property("page-size").value().toString())), | 871 | QPageSize(KReportPageSize::pageSize(d->set.property("page-size").value().toString())), | ||
859 | d->set.property("print-orientation").value().toString() | 872 | d->set.property("print-orientation").value().toString() | ||
860 | == QLatin1String("portrait") ? QPageLayout::Portrait : QPageLayout::Landscape, QMarginsF(0,0,0,0)); | 873 | == QLatin1String("portrait") ? QPageLayout::Portrait : QPageLayout::Landscape, QMarginsF(0,0,0,0)); | ||
874 | pageSizePx = layout.fullRectPixels(KReportPrivate::dpiX()).size(); | ||||
875 | } | ||||
861 | 876 | | |||
862 | QSize pageSizePx = layout.fullRectPixels(KReportPrivate::dpiX()).size(); | 877 | pageWidth = pageSizePx.width(); | ||
863 | 878 | | |||
864 | int width = pageSizePx.width(); | 879 | pageWidth = pageWidth - POINT_TO_INCH(d->set.property("margin-left").value().toDouble()) * KReportPrivate::dpiX(); | ||
staniek: remove debug.. | |||||
865 | width = width - POINT_TO_INCH(d->set.property("margin-left").value().toDouble()) * KReportPrivate::dpiX(); | 880 | pageWidth = pageWidth - POINT_TO_INCH(d->set.property("margin-right").value().toDouble()) * KReportPrivate::dpiX(); | ||
866 | width = width - POINT_TO_INCH(d->set.property("margin-right").value().toDouble()) * KReportPrivate::dpiX(); | | |||
867 | 881 | | |||
868 | return width; | 882 | return pageWidth; | ||
869 | } | 883 | } | ||
870 | 884 | | |||
871 | void KReportDesigner::resizeEvent(QResizeEvent * event) | 885 | void KReportDesigner::resizeEvent(QResizeEvent * event) | ||
872 | { | 886 | { | ||
873 | Q_UNUSED(event); | 887 | Q_UNUSED(event); | ||
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 | d->hruler->setRulerLength(pageWidthPx()); | 888 | d->hruler->setRulerLength(pageWidthPx()); | ||
staniek: remove or disable debug here and elsewhere.. | |||||
875 | } | 889 | } | ||
876 | 890 | | |||
877 | void KReportDesigner::setDetail(KReportDesignerSectionDetail *rsd) | 891 | void KReportDesigner::setDetail(KReportDesignerSectionDetail *rsd) | ||
878 | { | 892 | { | ||
879 | if (!d->detail) { | 893 | if (!d->detail) { | ||
880 | int idx = 0; | 894 | int idx = 0; | ||
881 | if (d->pageHeaderFirst) idx++; | 895 | if (d->pageHeaderFirst) idx++; | ||
882 | if (d->pageHeaderOdd) idx++; | 896 | if (d->pageHeaderOdd) idx++; | ||
▲ Show 20 Lines • Show All 150 Lines • ▼ Show 20 Line(s) | |||||
1033 | void KReportDesigner::changeSet(KPropertySet *s) | 1047 | void KReportDesigner::changeSet(KPropertySet *s) | ||
1034 | { | 1048 | { | ||
1035 | //Set the checked state of the report properties button | 1049 | //Set the checked state of the report properties button | ||
1036 | if (s == &d->set) | 1050 | if (s == &d->set) | ||
1037 | d->pageButton->setCheckState(Qt::Checked); | 1051 | d->pageButton->setCheckState(Qt::Checked); | ||
1038 | else | 1052 | else | ||
1039 | d->pageButton->setCheckState(Qt::Unchecked); | 1053 | d->pageButton->setCheckState(Qt::Unchecked); | ||
1040 | 1054 | | |||
1055 | if (d->itemSet != s) { | ||||
1041 | d->itemSet = s; | 1056 | d->itemSet = s; | ||
1042 | emit propertySetChanged(); | 1057 | emit propertySetChanged(); | ||
1043 | } | 1058 | } | ||
1059 | } | ||||
1044 | 1060 | | |||
1045 | // | 1061 | // | ||
1046 | // Actions | 1062 | // Actions | ||
1047 | // | 1063 | // | ||
1048 | 1064 | | |||
1049 | void KReportDesigner::slotItem(const QString &entity) | 1065 | void KReportDesigner::slotItem(const QString &entity) | ||
1050 | { | 1066 | { | ||
1051 | //kreportDebug() << entity; | 1067 | //kreportDebug() << entity; | ||
▲ Show 20 Lines • Show All 486 Lines • Show Last 20 Lines |
Line too long