Changeset View
Standalone View
src/wrtembed/KReportDesigner.cpp
Show First 20 Lines • Show All 106 Lines • ▼ Show 20 Line(s) | 76 | public: | |||
---|---|---|---|---|---|
107 | QList<KReportDesignerItemBase*> copy_list; | 107 | QList<KReportDesignerItemBase*> copy_list; | ||
108 | QList<KReportDesignerItemBase*> cut_list; | 108 | QList<KReportDesignerItemBase*> cut_list; | ||
109 | }; | 109 | }; | ||
110 | 110 | | |||
111 | //! @internal | 111 | //! @internal | ||
112 | class Q_DECL_HIDDEN KReportDesigner::Private | 112 | class Q_DECL_HIDDEN KReportDesigner::Private | ||
113 | { | 113 | { | ||
114 | public: | 114 | public: | ||
115 | Private(){} | 115 | Private() : currentUnit(DEFAULT_UNIT_TYPE) {} | ||
116 | 116 | | |||
117 | ~Private() | 117 | ~Private() | ||
118 | { | 118 | { | ||
119 | delete dataSource; | 119 | delete dataSource; | ||
120 | } | 120 | } | ||
121 | 121 | | |||
122 | void updateCurrentUnit() { | ||||
123 | QString u = unit->value().toString(); | ||||
124 | KReportUnit newUnit = KReportUnit(KReportUnit::symbolToType(u)); | ||||
125 | if (newUnit.isValid()) { | ||||
126 | currentUnit = newUnit; | ||||
127 | } else { | ||||
128 | currentUnit = DEFAULT_UNIT; | ||||
129 | } | ||||
130 | } | ||||
131 | | ||||
122 | QGridLayout *grid; | 132 | QGridLayout *grid; | ||
123 | KReportRuler *hruler; | 133 | KReportRuler *hruler; | ||
124 | KReportZoomHandler zoomHandler; | 134 | KReportZoomHandler zoomHandler; | ||
125 | QVBoxLayout *vboxlayout; | 135 | QVBoxLayout *vboxlayout; | ||
126 | KReportPropertiesButton *pageButton; | 136 | KReportPropertiesButton *pageButton; | ||
staniek: `setValue(10, KProperty::DefaultValueOptions & KProperty::ValueOptions(KProperty::ValueOption… | |||||
I've rebased master changes into this code: if you have unpublished fixes please do the same. Since kproperty 3.0.91 we're no longer using this complex math but instead: setValue(..., KProperty::ValueOption::IgnoreOld). staniek: I've rebased master changes into this code: if you have unpublished fixes please do the same. | |||||
127 | 137 | | |||
128 | QGraphicsScene *activeScene = nullptr; | 138 | QGraphicsScene *activeScene = nullptr; | ||
129 | 139 | | |||
130 | ReportWriterSectionData sectionData; | 140 | ReportWriterSectionData sectionData; | ||
131 | 141 | | |||
132 | KReportDesignerSection *reportHeader = nullptr; | 142 | KReportDesignerSection *reportHeader = nullptr; | ||
133 | KReportDesignerSection *pageHeaderFirst = nullptr; | 143 | KReportDesignerSection *pageHeaderFirst = nullptr; | ||
134 | KReportDesignerSection *pageHeaderOdd = nullptr; | 144 | KReportDesignerSection *pageHeaderOdd = nullptr; | ||
Show All 24 Lines | |||||
159 | KProperty *showGrid; | 169 | KProperty *showGrid; | ||
160 | KProperty *gridDivisions; | 170 | KProperty *gridDivisions; | ||
161 | KProperty *gridSnap; | 171 | KProperty *gridSnap; | ||
162 | KProperty *labelType; | 172 | KProperty *labelType; | ||
163 | #ifdef KREPORT_SCRIPTING | 173 | #ifdef KREPORT_SCRIPTING | ||
164 | KProperty *script; | 174 | KProperty *script; | ||
165 | #endif | 175 | #endif | ||
166 | 176 | | |||
177 | KReportUnit currentUnit; | ||||
178 | | ||||
167 | //Actions | 179 | //Actions | ||
168 | QAction *editCutAction; | 180 | QAction *editCutAction; | ||
169 | QAction *editCopyAction; | 181 | QAction *editCopyAction; | ||
170 | QAction *editPasteAction; | 182 | QAction *editPasteAction; | ||
171 | QAction *editDeleteAction; | 183 | QAction *editDeleteAction; | ||
172 | QAction *sectionEdit; | 184 | QAction *sectionEdit; | ||
173 | QAction *parameterEdit; | 185 | QAction *parameterEdit; | ||
174 | QAction *itemRaiseAction; | 186 | QAction *itemRaiseAction; | ||
Show All 35 Lines | 207 | { | |||
210 | d->vboxlayout->setMargin(0); | 222 | d->vboxlayout->setMargin(0); | ||
211 | d->vboxlayout->setSizeConstraint(QLayout::SetFixedSize); | 223 | d->vboxlayout->setSizeConstraint(QLayout::SetFixedSize); | ||
212 | 224 | | |||
213 | //Create nice rulers | 225 | //Create nice rulers | ||
214 | d->hruler = new KReportRuler(this, Qt::Horizontal, d->zoomHandler); | 226 | d->hruler = new KReportRuler(this, Qt::Horizontal, d->zoomHandler); | ||
215 | 227 | | |||
216 | d->pageButton = new KReportPropertiesButton(this); | 228 | d->pageButton = new KReportPropertiesButton(this); | ||
217 | 229 | | |||
230 | d->hruler->setUnit(DEFAULT_UNIT); | ||||
231 | | ||||
218 | d->grid->addWidget(d->pageButton, 0, 0); | 232 | d->grid->addWidget(d->pageButton, 0, 0); | ||
219 | d->grid->addWidget(d->hruler, 0, 1); | 233 | d->grid->addWidget(d->hruler, 0, 1); | ||
220 | d->grid->addLayout(d->vboxlayout, 1, 0, 1, 2); | 234 | d->grid->addLayout(d->vboxlayout, 1, 0, 1, 2); | ||
221 | 235 | | |||
222 | d->pageButton->setMaximumSize(QSize(19, 22)); | 236 | d->pageButton->setMaximumSize(QSize(19, 22)); | ||
223 | d->pageButton->setMinimumSize(QSize(19, 22)); | 237 | d->pageButton->setMinimumSize(QSize(19, 22)); | ||
224 | 238 | | |||
225 | d->detail = new KReportDesignerSectionDetail(this); | 239 | d->detail = new KReportDesignerSectionDetail(this); | ||
▲ Show 20 Lines • Show All 53 Lines • ▼ Show 20 Line(s) | 289 | QString msg = tr("This report contains scripts of type \"%1\". " | |||
279 | ).arg(d->originalInterpreter); | 293 | ).arg(d->originalInterpreter); | ||
280 | QMessageBox::warning(this, tr("Unsupported Script Type"), msg); | 294 | QMessageBox::warning(this, tr("Unsupported Script Type"), msg); | ||
281 | } | 295 | } | ||
282 | #endif | 296 | #endif | ||
283 | } else if (n == QLatin1String("report:grid")) { | 297 | } else if (n == QLatin1String("report:grid")) { | ||
284 | d->showGrid->setValue(it.toElement().attribute(QLatin1String("report:grid-visible"), QString::number(1)).toInt() != 0); | 298 | d->showGrid->setValue(it.toElement().attribute(QLatin1String("report:grid-visible"), QString::number(1)).toInt() != 0); | ||
285 | d->gridSnap->setValue(it.toElement().attribute(QLatin1String("report:grid-snap"), QString::number(1)).toInt() != 0); | 299 | d->gridSnap->setValue(it.toElement().attribute(QLatin1String("report:grid-snap"), QString::number(1)).toInt() != 0); | ||
286 | d->gridDivisions->setValue(it.toElement().attribute(QLatin1String("report:grid-divisions"), QString::number(4)).toInt()); | 300 | d->gridDivisions->setValue(it.toElement().attribute(QLatin1String("report:grid-divisions"), QString::number(4)).toInt()); | ||
287 | d->unit->setValue(it.toElement().attribute(QLatin1String("report:page-unit"), QLatin1String("cm"))); | 301 | d->unit->setValue(it.toElement().attribute( | ||
302 | QLatin1String("report:page-unit"), DEFAULT_UNIT_STRING)); | ||||
303 | d->updateCurrentUnit(); | ||||
288 | } | 304 | } | ||
289 | 305 | | |||
290 | //! @todo Load page options | 306 | //! @todo Load page options | ||
291 | else if (n == QLatin1String("report:page-style")) { | 307 | else if (n == QLatin1String("report:page-style")) { | ||
292 | QString pagetype = it.firstChild().nodeValue(); | 308 | QString pagetype = it.firstChild().nodeValue(); | ||
293 | 309 | | |||
294 | if (pagetype == QLatin1String("predefined")) { | 310 | if (pagetype == QLatin1String("predefined")) { | ||
295 | d->pageSize->setValue(it.toElement().attribute(QLatin1String("report:page-size"), QLatin1String("A4"))); | 311 | d->pageSize->setValue(it.toElement().attribute(QLatin1String("report:page-size"), QLatin1String("A4"))); | ||
296 | } else if (pagetype == QLatin1String("custom")) { | 312 | } else if (pagetype == QLatin1String("custom")) { | ||
297 | d->pageSize->setValue(QLatin1String("Custom")); | 313 | d->pageSize->setValue(QLatin1String("Custom")); | ||
298 | d->customPageSize->setValue(QSizeF(KReportUnit::parseValue(it.toElement().attribute(QLatin1String("report:custom-page-width"), QLatin1String(""))), | 314 | d->customPageSize->setValue(QSizeF(KReportUnit::parseValue(it.toElement().attribute(QLatin1String("report:custom-page-width"), QLatin1String(""))), | ||
299 | KReportUnit::parseValue(it.toElement().attribute(QLatin1String("report:custom-page-height"), QLatin1String(""))))); | 315 | KReportUnit::parseValue(it.toElement().attribute(QLatin1String("report:custom-page-height"), QLatin1String(""))))); | ||
300 | } else if (pagetype == QLatin1String("label")) { | 316 | } else if (pagetype == QLatin1String("label")) { | ||
301 | //! @todo | 317 | //! @todo | ||
302 | } | 318 | } | ||
303 | 319 | | |||
304 | d->rightMargin->setValue(KReportUnit::parseValue(it.toElement().attribute(QLatin1String("fo:margin-right"), QLatin1String("1.0cm")))); | 320 | d->rightMargin->setValue(pageUnit().convertFromPoint( | ||
305 | d->leftMargin->setValue(KReportUnit::parseValue(it.toElement().attribute(QLatin1String("fo:margin-left"), QLatin1String("1.0cm")))); | 321 | KReportUnit::parseValue(it.toElement().attribute( | ||
306 | d->topMargin->setValue(KReportUnit::parseValue(it.toElement().attribute(QLatin1String("fo:margin-top"), QLatin1String("1.0cm")))); | 322 | QLatin1String("fo:margin-right"), DEFAULT_PAGE_MARGIN_STRING)))); | ||
307 | d->bottomMargin->setValue(KReportUnit::parseValue(it.toElement().attribute(QLatin1String("fo:margin-bottom"), QLatin1String("1.0cm")))); | 323 | d->leftMargin->setValue(pageUnit().convertFromPoint( | ||
308 | 324 | KReportUnit::parseValue(it.toElement().attribute( | |||
309 | d->orientation->setValue(it.toElement().attribute(QLatin1String("report:print-orientation"), QLatin1String("portrait"))); | 325 | QLatin1String("fo:margin-left"), DEFAULT_PAGE_MARGIN_STRING)))); | ||
310 | 326 | d->topMargin->setValue(pageUnit().convertFromPoint( | |||
327 | KReportUnit::parseValue(it.toElement().attribute( | ||||
328 | QLatin1String("fo:margin-top"), DEFAULT_PAGE_MARGIN_STRING)))); | ||||
329 | d->bottomMargin->setValue(pageUnit().convertFromPoint( | ||||
330 | KReportUnit::parseValue(it.toElement().attribute( | ||||
331 | QLatin1String("fo:margin-bottom"), DEFAULT_PAGE_MARGIN_STRING)))); | ||||
332 | d->orientation->setValue( | ||||
333 | it.toElement().attribute(QLatin1String("report:print-orientation"), | ||||
334 | QLatin1String("portrait"))); | ||||
311 | } else if (n == QLatin1String("report:body")) { | 335 | } else if (n == QLatin1String("report:body")) { | ||
312 | QDomNodeList sectionlist = it.childNodes(); | 336 | QDomNodeList sectionlist = it.childNodes(); | ||
313 | QDomNode sec; | 337 | QDomNode sec; | ||
314 | 338 | | |||
315 | for (int s = 0; s < sectionlist.count(); ++s) { | 339 | for (int s = 0; s < sectionlist.count(); ++s) { | ||
316 | sec = sectionlist.item(s); | 340 | sec = sectionlist.item(s); | ||
317 | if (sec.isElement()) { | 341 | if (sec.isElement()) { | ||
318 | QString sn = sec.nodeName().toLower(); | 342 | QString sn = sec.nodeName().toLower(); | ||
319 | //kreportDebug() << sn; | 343 | //kreportDebug() << sn; | ||
320 | if (sn == QLatin1String("report:section")) { | 344 | if (sn == QLatin1String("report:section")) { | ||
321 | QString sectiontype = sec.toElement().attribute(QLatin1String("report:section-type")); | 345 | const QString sectiontype = KReportUtils::readSectionTypeNameAttribute(sec.toElement()); | ||
322 | if (section(KReportSectionData::sectionTypeFromString(sectiontype)) == nullptr) { | 346 | if (section(KReportSectionData::sectionTypeFromString(sectiontype)) == nullptr) { | ||
323 | insertSection(KReportSectionData::sectionTypeFromString(sectiontype)); | 347 | insertSection(KReportSectionData::sectionTypeFromString(sectiontype)); | ||
324 | section(KReportSectionData::sectionTypeFromString(sectiontype))->initFromXML(sec); | 348 | section(KReportSectionData::sectionTypeFromString(sectiontype))->initFromXML(sec); | ||
325 | } | 349 | } | ||
326 | } else if (sn == QLatin1String("report:detail")) { | 350 | } else if (sn == QLatin1String("report:detail")) { | ||
327 | KReportDesignerSectionDetail * rsd = new KReportDesignerSectionDetail(this); | 351 | KReportDesignerSectionDetail * rsd = new KReportDesignerSectionDetail(this); | ||
328 | rsd->initFromXML(&sec); | 352 | rsd->initFromXML(&sec); | ||
329 | setDetail(rsd); | 353 | setDetail(rsd); | ||
▲ Show 20 Lines • Show All 55 Lines • ▼ Show 20 Line(s) | 402 | #endif | |||
385 | content.appendChild(grd); | 409 | content.appendChild(grd); | ||
386 | 410 | | |||
387 | // pageOptions | 411 | // pageOptions | ||
388 | // -- size | 412 | // -- size | ||
389 | QDomElement pagestyle = doc.createElement(QLatin1String("report:page-style")); | 413 | QDomElement pagestyle = doc.createElement(QLatin1String("report:page-style")); | ||
390 | 414 | | |||
391 | if (d->pageSize->value().toString() == QLatin1String("Custom")) { | 415 | if (d->pageSize->value().toString() == QLatin1String("Custom")) { | ||
392 | pagestyle.appendChild(doc.createTextNode(QLatin1String("custom"))); | 416 | pagestyle.appendChild(doc.createTextNode(QLatin1String("custom"))); | ||
393 | KReportUtils::setAttribute(&pagestyle, QLatin1String("report:custom-page-width"), d->customPageSize->value().toSizeF().width()); | | |||
394 | KReportUtils::setAttribute(&pagestyle, QLatin1String("report:custom-page-height"), d->customPageSize->value().toSizeF().height()); | | |||
395 | 417 | | |||
418 | KReportUtils::setAttribute( | ||||
419 | &pagestyle, QLatin1String("report:custom-page-width"), | ||||
420 | d->currentUnit.convertToPoint(d->customPageSize->value().toSizeF().width())); | ||||
421 | KReportUtils::setAttribute( | ||||
422 | &pagestyle, QLatin1String("report:custom-page-height"), | ||||
423 | d->currentUnit.convertToPoint(d->customPageSize->value().toSizeF().height())); | ||||
396 | } else if (d->pageSize->value().toString() == QLatin1String("Label")) { | 424 | } else if (d->pageSize->value().toString() == QLatin1String("Label")) { | ||
397 | pagestyle.appendChild(doc.createTextNode(QLatin1String("label"))); | 425 | pagestyle.appendChild(doc.createTextNode(QLatin1String("label"))); | ||
398 | pagestyle.setAttribute(QLatin1String("report:page-label-type"), d->labelType->value().toString()); | 426 | pagestyle.setAttribute(QLatin1String("report:page-label-type"), d->labelType->value().toString()); | ||
399 | } else { | 427 | } else { | ||
400 | pagestyle.appendChild(doc.createTextNode(QLatin1String("predefined"))); | 428 | pagestyle.appendChild(doc.createTextNode(QLatin1String("predefined"))); | ||
401 | KReportUtils::addPropertyAsAttribute(&pagestyle, d->pageSize); | 429 | KReportUtils::addPropertyAsAttribute(&pagestyle, d->pageSize); | ||
402 | //pagestyle.setAttribute("report:page-size", d->pageSize->value().toString()); | 430 | //pagestyle.setAttribute("report:page-size", d->pageSize->value().toString()); | ||
403 | } | 431 | } | ||
404 | 432 | | |||
405 | // -- orientation | 433 | // -- orientation | ||
406 | KReportUtils::addPropertyAsAttribute(&pagestyle, d->orientation); | 434 | KReportUtils::addPropertyAsAttribute(&pagestyle, d->orientation); | ||
407 | 435 | | |||
408 | // -- margins: save as points, and not localized | 436 | // -- margins: save as points, and not localized | ||
409 | KReportUtils::setAttribute(&pagestyle, QLatin1String("fo:margin-top"), d->topMargin->value().toDouble()); | 437 | KReportUtils::setAttribute( | ||
410 | KReportUtils::setAttribute(&pagestyle, QLatin1String("fo:margin-bottom"), d->bottomMargin->value().toDouble()); | 438 | &pagestyle, QLatin1String("fo:margin-top"), | ||
411 | KReportUtils::setAttribute(&pagestyle, QLatin1String("fo:margin-right"), d->rightMargin->value().toDouble()); | 439 | d->currentUnit.convertToPoint(d->topMargin->value().toDouble())); | ||
412 | KReportUtils::setAttribute(&pagestyle, QLatin1String("fo:margin-left"), d->leftMargin->value().toDouble()); | 440 | KReportUtils::setAttribute( | ||
441 | &pagestyle, QLatin1String("fo:margin-bottom"), | ||||
442 | d->currentUnit.convertToPoint(d->bottomMargin->value().toDouble())); | ||||
443 | KReportUtils::setAttribute( | ||||
444 | &pagestyle, QLatin1String("fo:margin-right"), | ||||
445 | d->currentUnit.convertToPoint(d->rightMargin->value().toDouble())); | ||||
446 | KReportUtils::setAttribute( | ||||
447 | &pagestyle, QLatin1String("fo:margin-left"), | ||||
448 | d->currentUnit.convertToPoint(d->leftMargin->value().toDouble())); | ||||
413 | 449 | | |||
414 | content.appendChild(pagestyle); | 450 | content.appendChild(pagestyle); | ||
415 | 451 | | |||
416 | QDomElement body = doc.createElement(QLatin1String("report:body")); | 452 | QDomElement body = doc.createElement(QLatin1String("report:body")); | ||
417 | QDomElement domsection; | 453 | QDomElement domsection; | ||
418 | 454 | | |||
419 | for (int i = static_cast<int>(KReportSectionData::Type::PageHeaderFirst); | 455 | for (int i = static_cast<int>(KReportSectionData::Type::PageHeaderFirst); | ||
420 | i <= static_cast<int>(KReportSectionData::Type::PageFooterAny); ++i) | 456 | i <= static_cast<int>(KReportSectionData::Type::PageFooterAny); ++i) | ||
▲ Show 20 Lines • Show All 304 Lines • ▼ Show 20 Line(s) | 755 | { | |||
725 | 761 | | |||
726 | d->title = new KProperty("title", QLatin1String("Report"), tr("Title"), tr("Report Title")); | 762 | d->title = new KProperty("title", QLatin1String("Report"), tr("Title"), tr("Report Title")); | ||
727 | 763 | | |||
728 | KPropertyListData *listData = new KPropertyListData(KReportPageSize::pageFormatKeys(), | 764 | KPropertyListData *listData = new KPropertyListData(KReportPageSize::pageFormatKeys(), | ||
729 | KReportPageSize::pageFormatNames()); | 765 | KReportPageSize::pageFormatNames()); | ||
730 | QVariant defaultKey = KReportPageSize::pageSizeKey(KReportPageSize::defaultSize()); | 766 | QVariant defaultKey = KReportPageSize::pageSizeKey(KReportPageSize::defaultSize()); | ||
731 | d->pageSize = new KProperty("page-size", listData, defaultKey, tr("Page Size")); | 767 | d->pageSize = new KProperty("page-size", listData, defaultKey, tr("Page Size")); | ||
732 | 768 | | |||
733 | d->customPageSize = new KProperty("custom-page-size", QSizeF(KReportUnit(KReportUnit::Type::Centimeter).fromUserValue(10), KReportUnit(KReportUnit::Type::Centimeter).fromUserValue(10)), | 769 | d->customPageSize = new KProperty("custom-page-size", DEFAULT_CUSTOM_PAGE_SIZE, | ||
734 | tr("Custom Page Size"), tr("Custom Page Size"), KProperty::SizeF); | 770 | tr("Custom Page Size"), tr("Custom Page Size"), KProperty::SizeF); | ||
771 | d->customPageSize->setOption("suffix", d->currentUnit.symbol()); | ||||
772 | | ||||
735 | 773 | | |||
736 | listData = new KPropertyListData({ QLatin1String("portrait"), QLatin1String("landscape") }, | 774 | listData = new KPropertyListData({ QLatin1String("portrait"), QLatin1String("landscape") }, | ||
737 | QVariantList{ tr("Portrait"), tr("Landscape") }); | 775 | QVariantList{ tr("Portrait"), tr("Landscape") }); | ||
738 | d->orientation = new KProperty("print-orientation", listData, QLatin1String("portrait"), | 776 | d->orientation = new KProperty("print-orientation", listData, QLatin1String("portrait"), | ||
739 | tr("Page Orientation")); | 777 | tr("Page Orientation")); | ||
740 | 778 | | |||
741 | QList<KReportUnit::Type> types(KReportUnit::allTypes()); | 779 | QList<KReportUnit::Type> types(KReportUnit::allTypes()); | ||
742 | types.removeOne(KReportUnit::Type::Pixel); | 780 | types.removeOne(KReportUnit::Type::Pixel); | ||
743 | listData = new KPropertyListData(KReportUnit::symbols(types), KReportUnit::descriptions(types)); | 781 | listData = new KPropertyListData(KReportUnit::symbols(types), KReportUnit::descriptions(types)); | ||
744 | d->unit = new KProperty("page-unit", listData, QLatin1String("cm"), tr("Page Unit")); | 782 | d->unit = new KProperty("page-unit", listData, DEFAULT_UNIT_STRING, tr("Page Unit")); | ||
745 | | ||||
746 | d->showGrid = new KProperty("grid-visible", true, tr("Show Grid")); | 783 | d->showGrid = new KProperty("grid-visible", true, tr("Show Grid")); | ||
747 | d->gridSnap = new KProperty("grid-snap", true, tr("Snap to Grid")); | 784 | d->gridSnap = new KProperty("grid-snap", true, tr("Snap to Grid")); | ||
748 | d->gridDivisions = new KProperty("grid-divisions", 4, tr("Grid Divisions")); | 785 | d->gridDivisions = new KProperty("grid-divisions", 4, tr("Grid Divisions")); | ||
749 | 786 | | |||
750 | d->leftMargin = new KProperty("margin-left", KReportUnit(KReportUnit::Type::Centimeter).fromUserValue(1.0), | 787 | d->leftMargin = new KProperty("margin-left", pageUnit().convertFromPoint(KReportUnit::parseValue(DEFAULT_PAGE_MARGIN_STRING)), | ||
751 | tr("Left Margin"), tr("Left Margin"), KProperty::Double); | 788 | tr("Left Margin"), tr("Left Margin"), KProperty::Double); | ||
752 | d->rightMargin = new KProperty("margin-right", KReportUnit(KReportUnit::Type::Centimeter).fromUserValue(1.0), | 789 | d->rightMargin = new KProperty("margin-right", pageUnit().convertFromPoint(KReportUnit::parseValue(DEFAULT_PAGE_MARGIN_STRING)), | ||
753 | tr("Right Margin"), tr("Right Margin"), KProperty::Double); | 790 | tr("Right Margin"), tr("Right Margin"), KProperty::Double); | ||
754 | d->topMargin = new KProperty("margin-top", KReportUnit(KReportUnit::Type::Centimeter).fromUserValue(1.0), | 791 | d->topMargin = new KProperty("margin-top", pageUnit().convertFromPoint(KReportUnit::parseValue(DEFAULT_PAGE_MARGIN_STRING)), | ||
755 | tr("Top Margin"), tr("Top Margin"), KProperty::Double); | 792 | tr("Top Margin"), tr("Top Margin"), KProperty::Double); | ||
756 | d->bottomMargin = new KProperty("margin-bottom", KReportUnit(KReportUnit::Type::Centimeter).fromUserValue(1.0), | 793 | d->bottomMargin = new KProperty("margin-bottom", pageUnit().convertFromPoint(KReportUnit::parseValue(DEFAULT_PAGE_MARGIN_STRING)), | ||
757 | tr("Bottom Margin"), tr("Bottom Margin"), KProperty::Double); | 794 | tr("Bottom Margin"), tr("Bottom Margin"), KProperty::Double); | ||
758 | d->leftMargin->setOption("unit", QLatin1String("cm")); | 795 | d->leftMargin->setOption("suffix", d->currentUnit.symbol()); | ||
759 | d->rightMargin->setOption("unit", QLatin1String("cm")); | 796 | d->rightMargin->setOption("suffix", d->currentUnit.symbol()); | ||
760 | d->topMargin->setOption("unit", QLatin1String("cm")); | 797 | d->topMargin->setOption("suffix", d->currentUnit.symbol()); | ||
761 | d->bottomMargin->setOption("unit", QLatin1String("cm")); | 798 | d->bottomMargin->setOption("suffix", d->currentUnit.symbol()); | ||
762 | 799 | | |||
763 | d->set.addProperty(d->title); | 800 | d->set.addProperty(d->title); | ||
764 | d->set.addProperty(d->pageSize); | 801 | d->set.addProperty(d->pageSize); | ||
765 | d->set.addProperty(d->customPageSize); | 802 | d->set.addProperty(d->customPageSize); | ||
766 | d->set.addProperty(d->orientation); | 803 | d->set.addProperty(d->orientation); | ||
767 | d->set.addProperty(d->unit); | 804 | d->set.addProperty(d->unit); | ||
768 | d->set.addProperty(d->gridSnap); | 805 | d->set.addProperty(d->gridSnap); | ||
769 | d->set.addProperty(d->showGrid); | 806 | d->set.addProperty(d->showGrid); | ||
Show All 10 Lines | |||||
780 | 817 | | |||
781 | } | 818 | } | ||
782 | 819 | | |||
783 | /** | 820 | /** | ||
784 | @brief Handle property changes | 821 | @brief Handle property changes | ||
785 | */ | 822 | */ | ||
786 | void KReportDesigner::slotPropertyChanged(KPropertySet &s, KProperty &p) | 823 | void KReportDesigner::slotPropertyChanged(KPropertySet &s, KProperty &p) | ||
787 | { | 824 | { | ||
825 | const QSignalBlocker blocker(s); | ||||
788 | setModified(true); | 826 | setModified(true); | ||
789 | emit pagePropertyChanged(s); | | |||
790 | 827 | | |||
791 | if (p.name() == "page-unit") { | 828 | if (p.name() == "page-unit") { | ||
829 | const KReportUnit oldUnit = d->currentUnit; | ||||
830 | d->updateCurrentUnit(); | ||||
792 | d->hruler->setUnit(pageUnit()); | 831 | d->hruler->setUnit(pageUnit()); | ||
793 | QString newstr = d->set.property("page-unit").value().toString(); | | |||
794 | 832 | | |||
795 | d->set.property("margin-left").setOption("unit", newstr); | 833 | // convert values | ||
796 | d->set.property("margin-right").setOption("unit", newstr); | 834 | d->leftMargin->setValue( | ||
797 | d->set.property("margin-top").setOption("unit", newstr); | 835 | KReportUnit::convertFromUnitToUnit(d->leftMargin->value().toDouble(), oldUnit, d->currentUnit), | ||
798 | d->set.property("margin-bottom").setOption("unit", newstr); | 836 | KProperty::DefaultValueOptions & ~KProperty::ValueOptions(KProperty::ValueOption::RememberOld)); | ||
799 | d->set.property("custom-page-size").setOption("unit", newstr); | 837 | | ||
838 | d->rightMargin->setValue( | ||||
839 | KReportUnit::convertFromUnitToUnit(d->rightMargin->value().toDouble(), oldUnit, d->currentUnit), | ||||
840 | KProperty::DefaultValueOptions & ~KProperty::ValueOptions(KProperty::ValueOption::RememberOld)); | ||||
841 | | ||||
842 | d->topMargin->setValue( | ||||
843 | KReportUnit::convertFromUnitToUnit(d->topMargin->value().toDouble(), oldUnit, d->currentUnit), | ||||
844 | KProperty::DefaultValueOptions & ~KProperty::ValueOptions(KProperty::ValueOption::RememberOld)); | ||||
845 | | ||||
846 | d->bottomMargin->setValue( | ||||
847 | KReportUnit::convertFromUnitToUnit(d->bottomMargin->value().toDouble(), oldUnit, d->currentUnit), | ||||
848 | KProperty::DefaultValueOptions & ~KProperty::ValueOptions(KProperty::ValueOption::RememberOld)); | ||||
849 | | ||||
850 | d->customPageSize->setValue( | ||||
851 | KReportUnit::convertFromUnitToUnit(d->customPageSize->value().toSizeF(), oldUnit, d->currentUnit), | ||||
852 | KProperty::DefaultValueOptions & ~KProperty::ValueOptions(KProperty::ValueOption::RememberOld)); | ||||
853 | | ||||
854 | d->leftMargin->setOption("suffix", d->currentUnit.symbol()); | ||||
855 | d->rightMargin->setOption("suffix", d->currentUnit.symbol()); | ||||
856 | d->topMargin->setOption("suffix", d->currentUnit.symbol()); | ||||
857 | d->bottomMargin->setOption("suffix", d->currentUnit.symbol()); | ||||
858 | d->customPageSize->setOption("suffix", d->currentUnit.symbol()); | ||||
800 | } | 859 | } | ||
propertyName.startsWith("margin-") is not future-proof. What if we ever have properties like margin-background for example? ;) staniek: `propertyName.startsWith("margin-")` is not future-proof. What if we ever have properties like… | |||||
860 | emit pagePropertyChanged(s); | ||||
861 | | ||||
801 | } | 862 | } | ||
802 | 863 | | |||
803 | void KReportDesigner::slotPageButton_Pressed() | 864 | void KReportDesigner::slotPageButton_Pressed() | ||
804 | { | 865 | { | ||
805 | #ifdef KREPORT_SCRIPTING | 866 | #ifdef KREPORT_SCRIPTING | ||
806 | if (d->scriptSource) { | 867 | if (d->scriptSource) { | ||
807 | QStringList sl = d->scriptSource->scriptList(); | 868 | QStringList sl = d->scriptSource->scriptList(); | ||
808 | sl.prepend(QString()); | 869 | sl.prepend(QString()); | ||
▲ Show 20 Lines • Show All 47 Lines • ▼ Show 20 Line(s) | |||||
856 | int KReportDesigner::pageWidthPx() const | 917 | int KReportDesigner::pageWidthPx() const | ||
857 | { | 918 | { | ||
858 | QSize pageSizePx; | 919 | QSize pageSizePx; | ||
859 | int pageWidth; | 920 | int pageWidth; | ||
860 | 921 | | |||
861 | if (d->set.property("page-size").value().toString() == QLatin1String("Custom")) { | 922 | if (d->set.property("page-size").value().toString() == QLatin1String("Custom")) { | ||
862 | KReportUnit unit = pageUnit(); | 923 | KReportUnit unit = pageUnit(); | ||
863 | 924 | | |||
864 | QSizeF customSize = d->set.property("custom-page-size").value().toSizeF(); | 925 | QSizeF customSize = d->currentUnit.convertToPoint(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() | 926 | 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)); | 927 | == QLatin1String("portrait") ? QPageLayout::Portrait : QPageLayout::Landscape, QMarginsF(0,0,0,0)); | ||
867 | 928 | | |||
868 | pageSizePx = layout.fullRectPixels(KReportPrivate::dpiX()).size(); | 929 | pageSizePx = layout.fullRectPixels(KReportPrivate::dpiX()).size(); | ||
869 | } else { | 930 | } else { | ||
870 | QPageLayout layout = QPageLayout( | 931 | QPageLayout layout = QPageLayout( | ||
871 | QPageSize(KReportPageSize::pageSize(d->set.property("page-size").value().toString())), | 932 | QPageSize(KReportPageSize::pageSize(d->set.property("page-size").value().toString())), | ||
872 | d->set.property("print-orientation").value().toString() | 933 | d->set.property("print-orientation").value().toString() | ||
873 | == QLatin1String("portrait") ? QPageLayout::Portrait : QPageLayout::Landscape, QMarginsF(0,0,0,0)); | 934 | == QLatin1String("portrait") ? QPageLayout::Portrait : QPageLayout::Landscape, QMarginsF(0,0,0,0)); | ||
874 | pageSizePx = layout.fullRectPixels(KReportPrivate::dpiX()).size(); | 935 | pageSizePx = layout.fullRectPixels(KReportPrivate::dpiX()).size(); | ||
875 | } | 936 | } | ||
876 | 937 | | |||
877 | pageWidth = pageSizePx.width(); | 938 | pageWidth = pageSizePx.width(); | ||
878 | 939 | | |||
879 | pageWidth = pageWidth - POINT_TO_INCH(d->set.property("margin-left").value().toDouble()) * KReportPrivate::dpiX(); | 940 | pageWidth = pageWidth - KReportUnit::convertFromUnitToUnit(d->set.property("margin-left").value().toDouble(), pageUnit(), KReportUnit(KReportUnit::Type::Inch)) * KReportPrivate::dpiX(); | ||
880 | pageWidth = pageWidth - POINT_TO_INCH(d->set.property("margin-right").value().toDouble()) * KReportPrivate::dpiX(); | 941 | pageWidth = pageWidth - KReportUnit::convertFromUnitToUnit(d->set.property("margin-right").value().toDouble(), pageUnit(), KReportUnit(KReportUnit::Type::Inch)) * KReportPrivate::dpiX(); | ||
881 | 942 | | |||
882 | return pageWidth; | 943 | return pageWidth; | ||
883 | } | 944 | } | ||
884 | 945 | | |||
885 | void KReportDesigner::resizeEvent(QResizeEvent * event) | 946 | void KReportDesigner::resizeEvent(QResizeEvent * event) | ||
886 | { | 947 | { | ||
887 | Q_UNUSED(event); | 948 | Q_UNUSED(event); | ||
888 | d->hruler->setRulerLength(pageWidthPx()); | 949 | d->hruler->setRulerLength(pageWidthPx()); | ||
Show All 16 Lines | |||||
905 | void KReportDesigner::deleteDetail() | 966 | void KReportDesigner::deleteDetail() | ||
906 | { | 967 | { | ||
907 | delete d->detail; | 968 | delete d->detail; | ||
908 | d->detail = nullptr; | 969 | d->detail = nullptr; | ||
909 | } | 970 | } | ||
910 | 971 | | |||
911 | KReportUnit KReportDesigner::pageUnit() const | 972 | KReportUnit KReportDesigner::pageUnit() const | ||
912 | { | 973 | { | ||
913 | const QString symbol = d->unit->value().toString(); | 974 | return d->currentUnit; | ||
914 | KReportUnit unit(KReportUnit::symbolToType(symbol)); | | |||
915 | return unit.isValid() ? unit : DEFAULT_UNIT; | | |||
916 | } | 975 | } | ||
917 | 976 | | |||
918 | void KReportDesigner::setGridOptions(bool vis, int div) | 977 | void KReportDesigner::setGridOptions(bool vis, int div) | ||
919 | { | 978 | { | ||
920 | d->showGrid->setValue(QVariant(vis)); | 979 | d->showGrid->setValue(QVariant(vis)); | ||
921 | d->gridDivisions->setValue(div); | 980 | d->gridDivisions->setValue(div); | ||
922 | } | 981 | } | ||
923 | 982 | | |||
▲ Show 20 Lines • Show All 89 Lines • ▼ Show 20 Line(s) | 1071 | else { | |||
1013 | kreportWarning() << "attempted to insert an unknown item"; | 1072 | kreportWarning() << "attempted to insert an unknown item"; | ||
1014 | } | 1073 | } | ||
1015 | } | 1074 | } | ||
1016 | if (item) { | 1075 | if (item) { | ||
1017 | item->setVisible(true); | 1076 | item->setVisible(true); | ||
1018 | item->setSelected(true); | 1077 | item->setSelected(true); | ||
1019 | KReportItemBase* baseReportItem = dynamic_cast<KReportItemBase*>(item); | 1078 | KReportItemBase* baseReportItem = dynamic_cast<KReportItemBase*>(item); | ||
1020 | if (baseReportItem) { | 1079 | if (baseReportItem) { | ||
1021 | baseReportItem->setUnit(pageUnit()); | | |||
1022 | KPropertySet *set = baseReportItem->propertySet(); | 1080 | KPropertySet *set = baseReportItem->propertySet(); | ||
1023 | KReportDesigner::addMetaProperties(set, classString, iconName); | 1081 | KReportDesigner::addMetaProperties(set, classString, iconName); | ||
1024 | changeSet(set); | 1082 | changeSet(set); | ||
1025 | if (v && v->designer()) { | 1083 | if (v && v->designer()) { | ||
1026 | v->designer()->setModified(true); | 1084 | v->designer()->setModified(true); | ||
1027 | } | 1085 | } | ||
1028 | emit itemInserted(d->sectionData.itemToInsert); | 1086 | emit itemInserted(d->sectionData.itemToInsert); | ||
1029 | } | 1087 | } | ||
▲ Show 20 Lines • Show All 515 Lines • ▼ Show 20 Line(s) | 1602 | void KReportDesigner::addMetaProperties(KPropertySet* set, const QString &classString, | |||
1545 | const QString &iconName) | 1603 | const QString &iconName) | ||
1546 | { | 1604 | { | ||
1547 | Q_ASSERT(set); | 1605 | Q_ASSERT(set); | ||
1548 | KProperty *prop; | 1606 | KProperty *prop; | ||
1549 | set->addProperty(prop = new KProperty("this:classString", classString)); | 1607 | set->addProperty(prop = new KProperty("this:classString", classString)); | ||
1550 | prop->setVisible(false); | 1608 | prop->setVisible(false); | ||
1551 | set->addProperty(prop = new KProperty("this:iconName", iconName)); | 1609 | set->addProperty(prop = new KProperty("this:iconName", iconName)); | ||
1552 | prop->setVisible(false); | 1610 | prop->setVisible(false); | ||
1553 | } | 1611 | } | ||
This is effectively a fix but usability of this a bit low: user needs to locate the longer margin first and reduce it, then increase the desired margin (left-right, top-bottom). It is a bit frustrating when "keyboard does not work" because of the the max limits. How about setting max for left/right margins to page.width-smallest_page_size and max of top/bottom margins to page.height-smallest_page_size (e.g. for portrait A4: 205 and 205)? Then proceed with fixups from 5.3.[1-4]. For this solution we will need a KProperty parameter in this method so we know what property was changed and what property should be fixed. Please look that we never fix up value of property that is currently changed by the user, rather the other property. staniek: This is effectively a fix but usability of this a bit low: user needs to locate the longer… |
setValue(10, KProperty::DefaultValueOptions & KProperty::ValueOptions(KProperty::ValueOption::RememberOld)