Changeset View
Standalone View
src/wrtembed/KReportDesigner.cpp
Show First 20 Lines • Show All 100 Lines • ▼ Show 20 Line(s) | 70 | public: | |||
---|---|---|---|---|---|
101 | QList<KReportDesignerItemBase*> copy_list; | 101 | QList<KReportDesignerItemBase*> copy_list; | ||
102 | QList<KReportDesignerItemBase*> cut_list; | 102 | QList<KReportDesignerItemBase*> cut_list; | ||
103 | }; | 103 | }; | ||
104 | 104 | | |||
105 | //! @internal | 105 | //! @internal | ||
106 | class Q_DECL_HIDDEN KReportDesigner::Private | 106 | class Q_DECL_HIDDEN KReportDesigner::Private | ||
107 | { | 107 | { | ||
108 | public: | 108 | public: | ||
109 | Private(){} | 109 | Private() : currentUnit(DEFAULT_UNIT_TYPE) {} | ||
110 | 110 | | |||
111 | ~Private() | 111 | ~Private() | ||
112 | { | 112 | { | ||
113 | delete dataSource; | 113 | delete dataSource; | ||
114 | } | 114 | } | ||
115 | 115 | | |||
116 | void updateCurrentUnit() { | ||||
117 | QString u = unit->value().toString(); | ||||
118 | bool found; | ||||
119 | KReportUnit newUnit = KReportUnit::fromSymbol(u, &found); | ||||
120 | if (found) { | ||||
121 | currentUnit = newUnit; | ||||
122 | } else { | ||||
123 | currentUnit = DEFAULT_UNIT; | ||||
124 | } | ||||
125 | } | ||||
126 | | ||||
116 | QGridLayout *grid; | 127 | QGridLayout *grid; | ||
117 | KReportRuler *hruler; | 128 | KReportRuler *hruler; | ||
118 | KReportZoomHandler zoomHandler; | 129 | KReportZoomHandler zoomHandler; | ||
119 | QVBoxLayout *vboxlayout; | 130 | QVBoxLayout *vboxlayout; | ||
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. | |||||
120 | KReportPropertiesButton *pageButton; | 131 | KReportPropertiesButton *pageButton; | ||
121 | 132 | | |||
122 | QGraphicsScene *activeScene = nullptr; | 133 | QGraphicsScene *activeScene = nullptr; | ||
123 | 134 | | |||
124 | ReportWriterSectionData sectionData; | 135 | ReportWriterSectionData sectionData; | ||
125 | 136 | | |||
126 | KReportDesignerSection *reportHeader = nullptr; | 137 | KReportDesignerSection *reportHeader = nullptr; | ||
127 | KReportDesignerSection *pageHeaderFirst = nullptr; | 138 | KReportDesignerSection *pageHeaderFirst = nullptr; | ||
Show All 12 Lines | |||||
140 | 151 | | |||
141 | //Properties | 152 | //Properties | ||
142 | KPropertySet set; | 153 | KPropertySet set; | ||
143 | KPropertySet *itemSet; | 154 | KPropertySet *itemSet; | ||
144 | KProperty *title; | 155 | KProperty *title; | ||
145 | KProperty *pageSize; | 156 | KProperty *pageSize; | ||
146 | KProperty *orientation; | 157 | KProperty *orientation; | ||
147 | KProperty *unit; | 158 | KProperty *unit; | ||
159 | KReportUnit currentUnit; | ||||
148 | KProperty *customHeight; | 160 | KProperty *customHeight; | ||
149 | KProperty *customWidth; | 161 | KProperty *customWidth; | ||
150 | KProperty *leftMargin; | 162 | KProperty *leftMargin; | ||
151 | KProperty *rightMargin; | 163 | KProperty *rightMargin; | ||
152 | KProperty *topMargin; | 164 | KProperty *topMargin; | ||
153 | KProperty *bottomMargin; | 165 | KProperty *bottomMargin; | ||
154 | KProperty *showGrid; | 166 | KProperty *showGrid; | ||
155 | KProperty *gridDivisions; | 167 | KProperty *gridDivisions; | ||
▲ Show 20 Lines • Show All 46 Lines • ▼ Show 20 Line(s) | 199 | { | |||
202 | d->vboxlayout->setMargin(0); | 214 | d->vboxlayout->setMargin(0); | ||
203 | d->vboxlayout->setSizeConstraint(QLayout::SetFixedSize); | 215 | d->vboxlayout->setSizeConstraint(QLayout::SetFixedSize); | ||
204 | 216 | | |||
205 | //Create nice rulers | 217 | //Create nice rulers | ||
206 | d->hruler = new KReportRuler(this, Qt::Horizontal, d->zoomHandler); | 218 | d->hruler = new KReportRuler(this, Qt::Horizontal, d->zoomHandler); | ||
207 | 219 | | |||
208 | d->pageButton = new KReportPropertiesButton(this); | 220 | d->pageButton = new KReportPropertiesButton(this); | ||
209 | 221 | | |||
210 | d->hruler->setUnit(KReportUnit(KReportUnit::Centimeter)); | 222 | d->hruler->setUnit(DEFAULT_UNIT); | ||
211 | 223 | | |||
212 | d->grid->addWidget(d->pageButton, 0, 0); | 224 | d->grid->addWidget(d->pageButton, 0, 0); | ||
213 | d->grid->addWidget(d->hruler, 0, 1); | 225 | d->grid->addWidget(d->hruler, 0, 1); | ||
214 | d->grid->addLayout(d->vboxlayout, 1, 0, 1, 2); | 226 | d->grid->addLayout(d->vboxlayout, 1, 0, 1, 2); | ||
215 | 227 | | |||
216 | d->pageButton->setMaximumSize(QSize(19, 22)); | 228 | d->pageButton->setMaximumSize(QSize(19, 22)); | ||
217 | d->pageButton->setMinimumSize(QSize(19, 22)); | 229 | d->pageButton->setMinimumSize(QSize(19, 22)); | ||
218 | 230 | | |||
▲ Show 20 Lines • Show All 46 Lines • ▼ Show 20 Line(s) | 273 | QString msg = tr("This report contains scripts of type \"%1\". " | |||
265 | ).arg(d->originalInterpreter); | 277 | ).arg(d->originalInterpreter); | ||
266 | QMessageBox::warning(this, tr("Unsupported Script Type"), msg); | 278 | QMessageBox::warning(this, tr("Unsupported Script Type"), msg); | ||
267 | } | 279 | } | ||
268 | #endif | 280 | #endif | ||
269 | } else if (n == QLatin1String("report:grid")) { | 281 | } else if (n == QLatin1String("report:grid")) { | ||
270 | d->showGrid->setValue(it.toElement().attribute(QLatin1String("report:grid-visible"), QString::number(1)).toInt() != 0); | 282 | d->showGrid->setValue(it.toElement().attribute(QLatin1String("report:grid-visible"), QString::number(1)).toInt() != 0); | ||
271 | d->gridSnap->setValue(it.toElement().attribute(QLatin1String("report:grid-snap"), QString::number(1)).toInt() != 0); | 283 | d->gridSnap->setValue(it.toElement().attribute(QLatin1String("report:grid-snap"), QString::number(1)).toInt() != 0); | ||
272 | d->gridDivisions->setValue(it.toElement().attribute(QLatin1String("report:grid-divisions"), QString::number(4)).toInt()); | 284 | d->gridDivisions->setValue(it.toElement().attribute(QLatin1String("report:grid-divisions"), QString::number(4)).toInt()); | ||
273 | d->unit->setValue(it.toElement().attribute(QLatin1String("report:page-unit"), QLatin1String("cm"))); | 285 | d->unit->setValue(it.toElement().attribute( | ||
286 | QLatin1String("report:page-unit"), DEFAULT_UNIT_STRING)); | ||||
287 | d->updateCurrentUnit(); | ||||
274 | } | 288 | } | ||
275 | 289 | | |||
276 | //! @todo Load page options | 290 | //! @todo Load page options | ||
277 | else if (n == QLatin1String("report:page-style")) { | 291 | else if (n == QLatin1String("report:page-style")) { | ||
278 | QString pagetype = it.firstChild().nodeValue(); | 292 | QString pagetype = it.firstChild().nodeValue(); | ||
279 | 293 | | |||
280 | if (pagetype == QLatin1String("predefined")) { | 294 | if (pagetype == QLatin1String("predefined")) { | ||
281 | 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"))); | ||
282 | } else if (pagetype == QLatin1String("custom")) { | 296 | } else if (pagetype == QLatin1String("custom")) { | ||
283 | d->pageSize->setValue(QLatin1String("custom")); | 297 | d->pageSize->setValue(QLatin1String("custom")); | ||
284 | d->customHeight->setValue(KReportUnit::parseValue(it.toElement().attribute(QLatin1String("report:custom-page-height"), QLatin1String("")))); | 298 | //! @todo | ||
285 | d->customWidth->setValue(KReportUnit::parseValue(it.toElement().attribute(QLatin1String("report:custom-page-widtht"), QLatin1String("")))); | 299 | d->customHeight->setValue(pageUnit().convertFromPoint( | ||
300 | KReportUnit::parseValue(it.toElement().attribute( | ||||
301 | QLatin1String("report:custom-page-height"), QString())))); | ||||
302 | d->customWidth->setValue(pageUnit().convertFromPoint( | ||||
303 | KReportUnit::parseValue(it.toElement().attribute( | ||||
304 | QLatin1String("report:custom-page-width"), QString())))); | ||||
286 | } else if (pagetype == QLatin1String("label")) { | 305 | } else if (pagetype == QLatin1String("label")) { | ||
287 | //! @todo | 306 | //! @todo | ||
288 | } | 307 | } | ||
289 | 308 | | |||
290 | d->rightMargin->setValue(KReportUnit::parseValue(it.toElement().attribute(QLatin1String("fo:margin-right"), QLatin1String("1.0cm")))); | 309 | d->rightMargin->setValue(pageUnit().convertFromPoint( | ||
291 | d->leftMargin->setValue(KReportUnit::parseValue(it.toElement().attribute(QLatin1String("fo:margin-left"), QLatin1String("1.0cm")))); | 310 | KReportUnit::parseValue(it.toElement().attribute( | ||
292 | d->topMargin->setValue(KReportUnit::parseValue(it.toElement().attribute(QLatin1String("fo:margin-top"), QLatin1String("1.0cm")))); | 311 | QLatin1String("fo:margin-right"), DEFAULT_PAGE_MARGIN_STRING)))); | ||
293 | d->bottomMargin->setValue(KReportUnit::parseValue(it.toElement().attribute(QLatin1String("fo:margin-bottom"), QLatin1String("1.0cm")))); | 312 | d->leftMargin->setValue(pageUnit().convertFromPoint( | ||
294 | 313 | KReportUnit::parseValue(it.toElement().attribute( | |||
295 | d->orientation->setValue(it.toElement().attribute(QLatin1String("report:print-orientation"), QLatin1String("portrait"))); | 314 | QLatin1String("fo:margin-left"), DEFAULT_PAGE_MARGIN_STRING)))); | ||
296 | 315 | d->topMargin->setValue(pageUnit().convertFromPoint( | |||
316 | KReportUnit::parseValue(it.toElement().attribute( | ||||
317 | QLatin1String("fo:margin-top"), DEFAULT_PAGE_MARGIN_STRING)))); | ||||
318 | d->bottomMargin->setValue(pageUnit().convertFromPoint( | ||||
319 | KReportUnit::parseValue(it.toElement().attribute( | ||||
320 | QLatin1String("fo:margin-bottom"), DEFAULT_PAGE_MARGIN_STRING)))); | ||||
321 | d->orientation->setValue( | ||||
322 | it.toElement().attribute(QLatin1String("report:print-orientation"), | ||||
323 | QLatin1String("portrait"))); | ||||
297 | } else if (n == QLatin1String("report:body")) { | 324 | } else if (n == QLatin1String("report:body")) { | ||
298 | QDomNodeList sectionlist = it.childNodes(); | 325 | QDomNodeList sectionlist = it.childNodes(); | ||
299 | QDomNode sec; | 326 | QDomNode sec; | ||
300 | 327 | | |||
301 | for (int s = 0; s < sectionlist.count(); ++s) { | 328 | for (int s = 0; s < sectionlist.count(); ++s) { | ||
302 | sec = sectionlist.item(s); | 329 | sec = sectionlist.item(s); | ||
303 | if (sec.isElement()) { | 330 | if (sec.isElement()) { | ||
304 | QString sn = sec.nodeName().toLower(); | 331 | QString sn = sec.nodeName().toLower(); | ||
305 | //kreportDebug() << sn; | 332 | //kreportDebug() << sn; | ||
306 | if (sn == QLatin1String("report:section")) { | 333 | if (sn == QLatin1String("report:section")) { | ||
307 | QString sectiontype = sec.toElement().attribute(QLatin1String("report:section-type")); | 334 | const QString sectiontype = KReportUtils::readSectionTypeNameAttribute(sec.toElement()); | ||
308 | if (section(KReportSectionData::sectionTypeFromString(sectiontype)) == 0) { | 335 | if (section(KReportSectionData::sectionTypeFromString(sectiontype)) == 0) { | ||
309 | insertSection(KReportSectionData::sectionTypeFromString(sectiontype)); | 336 | insertSection(KReportSectionData::sectionTypeFromString(sectiontype)); | ||
310 | section(KReportSectionData::sectionTypeFromString(sectiontype))->initFromXML(sec); | 337 | section(KReportSectionData::sectionTypeFromString(sectiontype))->initFromXML(sec); | ||
311 | } | 338 | } | ||
312 | } else if (sn == QLatin1String("report:detail")) { | 339 | } else if (sn == QLatin1String("report:detail")) { | ||
313 | KReportDesignerSectionDetail * rsd = new KReportDesignerSectionDetail(this); | 340 | KReportDesignerSectionDetail * rsd = new KReportDesignerSectionDetail(this); | ||
314 | rsd->initFromXML(&sec); | 341 | rsd->initFromXML(&sec); | ||
315 | setDetail(rsd); | 342 | setDetail(rsd); | ||
316 | } | 343 | } | ||
317 | } else { | 344 | } else { | ||
318 | kreportWarning() << "Encountered an unknown Element: " << n; | 345 | kreportWarning() << "Encountered an unknown Element: " << n; | ||
319 | } | 346 | } | ||
320 | } | 347 | } | ||
321 | } | 348 | } | ||
322 | } else { | 349 | } else { | ||
323 | kreportWarning() << "Encountered a child node of root that is not an Element"; | 350 | kreportWarning() << "Encountered a child node of root that is not an Element"; | ||
324 | } | 351 | } | ||
325 | } | 352 | } | ||
326 | this->slotPageButton_Pressed(); | 353 | this->slotPageButton_Pressed(); | ||
327 | emit reportDataChanged(); | 354 | emit reportDataChanged(); | ||
328 | slotPropertyChanged(d->set, *d->unit); // set unit for all items | 355 | slotPropertyChanged(d->set, *d->unit); // set unit for all items | ||
329 | setModified(false); | 356 | setModified(false); | ||
330 | } | 357 | } | ||
331 | 358 | | |||
359 | KReportDesigner::~KReportDesigner() | ||||
360 | { | ||||
361 | delete d; | ||||
362 | } | ||||
363 | | ||||
332 | ///The saving code | 364 | ///The saving code | ||
333 | QDomElement KReportDesigner::document() const | 365 | QDomElement KReportDesigner::document() const | ||
334 | { | 366 | { | ||
335 | QDomDocument doc; | 367 | QDomDocument doc; | ||
336 | QString saveInterpreter; | 368 | QString saveInterpreter; | ||
337 | 369 | | |||
338 | QDomElement content = doc.createElement(QLatin1String("report:content")); | 370 | QDomElement content = doc.createElement(QLatin1String("report:content")); | ||
339 | content.setAttribute(QLatin1String("xmlns:report"), QLatin1String(ns)); | 371 | content.setAttribute(QLatin1String("xmlns:report"), QLatin1String(ns)); | ||
Show All 28 Lines | 393 | #endif | |||
368 | content.appendChild(grd); | 400 | content.appendChild(grd); | ||
369 | 401 | | |||
370 | // pageOptions | 402 | // pageOptions | ||
371 | // -- size | 403 | // -- size | ||
372 | QDomElement pagestyle = doc.createElement(QLatin1String("report:page-style")); | 404 | QDomElement pagestyle = doc.createElement(QLatin1String("report:page-style")); | ||
373 | 405 | | |||
374 | if (d->pageSize->value().toString() == QLatin1String("Custom")) { | 406 | if (d->pageSize->value().toString() == QLatin1String("Custom")) { | ||
375 | pagestyle.appendChild(doc.createTextNode(QLatin1String("custom"))); | 407 | pagestyle.appendChild(doc.createTextNode(QLatin1String("custom"))); | ||
376 | KReportUtils::setAttribute(&pagestyle, QLatin1String("report:custom-page-width"), d->customWidth->value().toDouble()); | 408 | KReportUtils::setAttribute( | ||
377 | KReportUtils::setAttribute(&pagestyle, QLatin1String("report:custom-page-height"), d->customHeight->value().toDouble()); | 409 | &pagestyle, QLatin1String("report:custom-page-width"), | ||
378 | 410 | d->currentUnit.convertToPoint(d->customWidth->value().toDouble())); | |||
411 | KReportUtils::setAttribute( | ||||
412 | &pagestyle, QLatin1String("report:custom-page-height"), | ||||
413 | d->currentUnit.convertToPoint(d->customHeight->value().toDouble())); | ||||
379 | } else if (d->pageSize->value().toString() == QLatin1String("Label")) { | 414 | } else if (d->pageSize->value().toString() == QLatin1String("Label")) { | ||
380 | pagestyle.appendChild(doc.createTextNode(QLatin1String("label"))); | 415 | pagestyle.appendChild(doc.createTextNode(QLatin1String("label"))); | ||
381 | pagestyle.setAttribute(QLatin1String("report:page-label-type"), d->labelType->value().toString()); | 416 | pagestyle.setAttribute(QLatin1String("report:page-label-type"), d->labelType->value().toString()); | ||
382 | } else { | 417 | } else { | ||
383 | pagestyle.appendChild(doc.createTextNode(QLatin1String("predefined"))); | 418 | pagestyle.appendChild(doc.createTextNode(QLatin1String("predefined"))); | ||
384 | KReportUtils::addPropertyAsAttribute(&pagestyle, d->pageSize); | 419 | KReportUtils::addPropertyAsAttribute(&pagestyle, d->pageSize); | ||
385 | //pagestyle.setAttribute("report:page-size", d->pageSize->value().toString()); | 420 | //pagestyle.setAttribute("report:page-size", d->pageSize->value().toString()); | ||
386 | } | 421 | } | ||
387 | 422 | | |||
388 | // -- orientation | 423 | // -- orientation | ||
389 | KReportUtils::addPropertyAsAttribute(&pagestyle, d->orientation); | 424 | KReportUtils::addPropertyAsAttribute(&pagestyle, d->orientation); | ||
390 | 425 | | |||
391 | // -- margins: save as points, and not localized | 426 | // -- margins: save as points, and not localized | ||
392 | KReportUtils::setAttribute(&pagestyle, QLatin1String("fo:margin-top"), d->topMargin->value().toDouble()); | 427 | KReportUtils::setAttribute( | ||
393 | KReportUtils::setAttribute(&pagestyle, QLatin1String("fo:margin-bottom"), d->bottomMargin->value().toDouble()); | 428 | &pagestyle, QLatin1String("fo:margin-top"), | ||
394 | KReportUtils::setAttribute(&pagestyle, QLatin1String("fo:margin-right"), d->rightMargin->value().toDouble()); | 429 | d->currentUnit.convertToPoint(d->topMargin->value().toDouble())); | ||
395 | KReportUtils::setAttribute(&pagestyle, QLatin1String("fo:margin-left"), d->leftMargin->value().toDouble()); | 430 | KReportUtils::setAttribute( | ||
431 | &pagestyle, QLatin1String("fo:margin-bottom"), | ||||
432 | d->currentUnit.convertToPoint(d->bottomMargin->value().toDouble())); | ||||
433 | KReportUtils::setAttribute( | ||||
434 | &pagestyle, QLatin1String("fo:margin-right"), | ||||
435 | d->currentUnit.convertToPoint(d->rightMargin->value().toDouble())); | ||||
436 | KReportUtils::setAttribute( | ||||
437 | &pagestyle, QLatin1String("fo:margin-left"), | ||||
438 | d->currentUnit.convertToPoint(d->leftMargin->value().toDouble())); | ||||
396 | 439 | | |||
397 | content.appendChild(pagestyle); | 440 | content.appendChild(pagestyle); | ||
398 | 441 | | |||
399 | QDomElement body = doc.createElement(QLatin1String("report:body")); | 442 | QDomElement body = doc.createElement(QLatin1String("report:body")); | ||
400 | QDomElement domsection; | 443 | QDomElement domsection; | ||
401 | 444 | | |||
402 | for (int i = KReportSectionData::PageHeaderFirst; i <= KReportSectionData::PageFooterAny; ++i) { | 445 | for (int i = KReportSectionData::PageHeaderFirst; i <= KReportSectionData::PageFooterAny; ++i) { | ||
403 | KReportDesignerSection *sec = section((KReportSectionData::Section)i); | 446 | KReportDesignerSection *sec = section((KReportSectionData::Section)i); | ||
▲ Show 20 Lines • Show All 287 Lines • ▼ Show 20 Line(s) | 732 | { | |||
691 | KReportDesigner::addMetaProperties(&d->set, | 734 | KReportDesigner::addMetaProperties(&d->set, | ||
692 | tr("Report", "Main report element"), QLatin1String("kreport-report-element")); | 735 | tr("Report", "Main report element"), QLatin1String("kreport-report-element")); | ||
693 | 736 | | |||
694 | connect(&d->set, SIGNAL(propertyChanged(KPropertySet&,KProperty&)), | 737 | connect(&d->set, SIGNAL(propertyChanged(KPropertySet&,KProperty&)), | ||
695 | this, SLOT(slotPropertyChanged(KPropertySet&,KProperty&))); | 738 | this, SLOT(slotPropertyChanged(KPropertySet&,KProperty&))); | ||
696 | 739 | | |||
697 | d->title = new KProperty("title", QLatin1String("Report"), tr("Title"), tr("Report Title")); | 740 | d->title = new KProperty("title", QLatin1String("Report"), tr("Title"), tr("Report Title")); | ||
698 | 741 | | |||
742 | strings = KReportUnit::listOfUnitNameForUi(KReportUnit::HidePixel); | ||||
743 | QString unit; | ||||
744 | foreach(const QString &un, strings) { | ||||
745 | unit = un.mid(un.indexOf(QLatin1String("(")) + 1, 2); | ||||
746 | keys << unit; | ||||
747 | } | ||||
748 | d->unit = new KProperty("page-unit", keys, strings, DEFAULT_UNIT_STRING, tr("Page Unit")); | ||||
749 | | ||||
699 | keys.clear(); | 750 | keys.clear(); | ||
700 | keys = KReportPageSize::pageFormatKeys(); | 751 | keys = KReportPageSize::pageFormatKeys(); | ||
701 | strings = KReportPageSize::pageFormatNames(); | 752 | strings = KReportPageSize::pageFormatNames(); | ||
702 | QString defaultKey = KReportPageSize::pageSizeKey(KReportPageSize::defaultSize()); | 753 | QString defaultKey = KReportPageSize::pageSizeKey(KReportPageSize::defaultSize()); | ||
703 | d->pageSize = new KProperty("page-size", keys, strings, defaultKey, tr("Page Size")); | 754 | d->pageSize = new KProperty("page-size", keys, strings, defaultKey, tr("Page Size")); | ||
704 | 755 | | |||
705 | keys.clear(); strings.clear(); | 756 | keys.clear(); | ||
757 | strings.clear(); | ||||
706 | keys << QLatin1String("portrait") << QLatin1String("landscape"); | 758 | keys << QLatin1String("portrait") << QLatin1String("landscape"); | ||
707 | strings << tr("Portrait") << tr("Landscape"); | 759 | strings << tr("Portrait") << tr("Landscape"); | ||
708 | d->orientation = new KProperty("print-orientation", keys, strings, QLatin1String("portrait"), tr("Page Orientation")); | 760 | d->orientation = new KProperty("print-orientation", keys, strings, QLatin1String("portrait"), tr("Page Orientation")); | ||
709 | | ||||
710 | keys.clear(); strings.clear(); | | |||
711 | | ||||
712 | strings = KReportUnit::listOfUnitNameForUi(KReportUnit::HidePixel); | | |||
713 | QString unit; | | |||
714 | foreach(const QString &un, strings) { | | |||
715 | unit = un.mid(un.indexOf(QLatin1String("(")) + 1, 2); | | |||
716 | keys << unit; | | |||
717 | } | | |||
718 | | ||||
719 | d->unit = new KProperty("page-unit", keys, strings, QLatin1String("cm"), tr("Page Unit")); | | |||
720 | | ||||
721 | d->showGrid = new KProperty("grid-visible", true, tr("Show Grid")); | 761 | d->showGrid = new KProperty("grid-visible", true, tr("Show Grid")); | ||
722 | d->gridSnap = new KProperty("grid-snap", true, tr("Snap to Grid")); | 762 | d->gridSnap = new KProperty("grid-snap", true, tr("Snap to Grid")); | ||
723 | d->gridDivisions = new KProperty("grid-divisions", 4, tr("Grid Divisions")); | 763 | d->gridDivisions = new KProperty("grid-divisions", 4, tr("Grid Divisions")); | ||
724 | 764 | | |||
725 | d->leftMargin = new KProperty("margin-left", KReportUnit(KReportUnit::Centimeter).fromUserValue(1.0), | 765 | d->leftMargin | ||
726 | tr("Left Margin"), tr("Left Margin"), KProperty::Double); | 766 | = new KProperty("margin-left", DEFAULT_PAGE_MARGIN_PT, tr("Left Margin"), | ||
727 | d->rightMargin = new KProperty("margin-right", KReportUnit(KReportUnit::Centimeter).fromUserValue(1.0), | 767 | tr("Left Margin"), KProperty::Double); | ||
728 | tr("Right Margin"), tr("Right Margin"), KProperty::Double); | 768 | d->rightMargin | ||
729 | d->topMargin = new KProperty("margin-top", KReportUnit(KReportUnit::Centimeter).fromUserValue(1.0), | 769 | = new KProperty("margin-right", DEFAULT_PAGE_MARGIN_PT, tr("Right Margin"), | ||
730 | tr("Top Margin"), tr("Top Margin"), KProperty::Double); | 770 | tr("Right Margin"), KProperty::Double); | ||
731 | d->bottomMargin = new KProperty("margin-bottom", KReportUnit(KReportUnit::Centimeter).fromUserValue(1.0), | 771 | d->topMargin = new KProperty("margin-top", DEFAULT_PAGE_MARGIN_PT, tr("Top Margin"), | ||
732 | tr("Bottom Margin"), tr("Bottom Margin"), KProperty::Double); | 772 | tr("Top Margin"), KProperty::Double); | ||
733 | d->leftMargin->setOption("unit", QLatin1String("cm")); | 773 | d->bottomMargin | ||
734 | d->rightMargin->setOption("unit", QLatin1String("cm")); | 774 | = new KProperty("margin-bottom", DEFAULT_PAGE_MARGIN_PT, tr("Bottom Margin"), | ||
735 | d->topMargin->setOption("unit", QLatin1String("cm")); | 775 | tr("Bottom Margin"), KProperty::Double); | ||
736 | d->bottomMargin->setOption("unit", QLatin1String("cm")); | 776 | d->leftMargin->setOption("suffix", d->currentUnit.symbol()); | ||
777 | d->rightMargin->setOption("suffix", d->currentUnit.symbol()); | ||||
778 | d->topMargin->setOption("suffix", d->currentUnit.symbol()); | ||||
779 | d->bottomMargin->setOption("suffix", d->currentUnit.symbol()); | ||||
737 | 780 | | |||
738 | d->set.addProperty(d->title); | 781 | d->set.addProperty(d->title); | ||
739 | d->set.addProperty(d->pageSize); | 782 | d->set.addProperty(d->pageSize); | ||
740 | d->set.addProperty(d->orientation); | 783 | d->set.addProperty(d->orientation); | ||
741 | d->set.addProperty(d->unit); | 784 | d->set.addProperty(d->unit); | ||
742 | d->set.addProperty(d->gridSnap); | 785 | d->set.addProperty(d->gridSnap); | ||
743 | d->set.addProperty(d->showGrid); | 786 | d->set.addProperty(d->showGrid); | ||
744 | d->set.addProperty(d->gridDivisions); | 787 | d->set.addProperty(d->gridDivisions); | ||
Show All 16 Lines | |||||
761 | @brief Handle property changes | 804 | @brief Handle property changes | ||
762 | */ | 805 | */ | ||
763 | void KReportDesigner::slotPropertyChanged(KPropertySet &s, KProperty &p) | 806 | void KReportDesigner::slotPropertyChanged(KPropertySet &s, KProperty &p) | ||
764 | { | 807 | { | ||
765 | setModified(true); | 808 | setModified(true); | ||
766 | emit pagePropertyChanged(s); | 809 | emit pagePropertyChanged(s); | ||
767 | 810 | | |||
768 | if (p.name() == "page-unit") { | 811 | if (p.name() == "page-unit") { | ||
812 | const KReportUnit oldUnit = d->currentUnit; | ||||
813 | d->updateCurrentUnit(); | ||||
769 | d->hruler->setUnit(pageUnit()); | 814 | d->hruler->setUnit(pageUnit()); | ||
770 | QString newstr = d->set.property("page-unit").value().toString(); | | |||
771 | 815 | | |||
772 | d->set.property("margin-left").setOption("unit", newstr); | 816 | // convert values | ||
773 | d->set.property("margin-right").setOption("unit", newstr); | 817 | d->leftMargin->setValue( | ||
774 | d->set.property("margin-top").setOption("unit", newstr); | 818 | KReportUnit::convertFromUnitToUnit(d->leftMargin->value().toPointF(), oldUnit, | ||
775 | d->set.property("margin-bottom").setOption("unit", newstr); | 819 | d->currentUnit), | ||
820 | KProperty::DefaultValueOptions | ||||
821 | & ~KProperty::ValueOptions(KProperty::ValueOption::RememberOld)); | ||||
822 | d->rightMargin->setValue( | ||||
823 | KReportUnit::convertFromUnitToUnit(d->rightMargin->value().toPointF(), oldUnit, | ||||
824 | d->currentUnit), | ||||
825 | KProperty::DefaultValueOptions | ||||
826 | & ~KProperty::ValueOptions(KProperty::ValueOption::RememberOld)); | ||||
827 | d->topMargin->setValue( | ||||
828 | KReportUnit::convertFromUnitToUnit(d->topMargin->value().toPointF(), oldUnit, | ||||
829 | d->currentUnit), | ||||
830 | KProperty::DefaultValueOptions | ||||
831 | & ~KProperty::ValueOptions(KProperty::ValueOption::RememberOld)); | ||||
832 | d->bottomMargin->setValue( | ||||
833 | KReportUnit::convertFromUnitToUnit(d->bottomMargin->value().toPointF(), oldUnit, | ||||
834 | d->currentUnit), | ||||
835 | KProperty::DefaultValueOptions | ||||
836 | & ~KProperty::ValueOptions(KProperty::ValueOption::RememberOld)); | ||||
837 | //! @todo convert custom sizes | ||||
838 | | ||||
839 | d->leftMargin->setOption("suffix", d->currentUnit.symbol()); | ||||
840 | d->rightMargin->setOption("suffix", d->currentUnit.symbol()); | ||||
841 | d->topMargin->setOption("suffix", d->currentUnit.symbol()); | ||||
842 | d->bottomMargin->setOption("suffix", d->currentUnit.symbol()); | ||||
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… | |||||
843 | //TODO d->customWidth->setOption("suffix", newUnit); | ||||
844 | //TODO d->customHeight->setOption("suffix", newUnit); | ||||
776 | } | 845 | } | ||
777 | } | 846 | } | ||
778 | 847 | | |||
779 | void KReportDesigner::slotPageButton_Pressed() | 848 | void KReportDesigner::slotPageButton_Pressed() | ||
780 | { | 849 | { | ||
781 | #ifdef KREPORT_SCRIPTING | 850 | #ifdef KREPORT_SCRIPTING | ||
782 | if (d->dataSource) { | 851 | if (d->dataSource) { | ||
783 | QStringList sl = d->dataSource->scriptList(); | 852 | QStringList sl = d->dataSource->scriptList(); | ||
▲ Show 20 Lines • Show All 84 Lines • ▼ Show 20 Line(s) | |||||
868 | void KReportDesigner::deleteDetail() | 937 | void KReportDesigner::deleteDetail() | ||
869 | { | 938 | { | ||
870 | delete d->detail; | 939 | delete d->detail; | ||
871 | d->detail = 0; | 940 | d->detail = 0; | ||
872 | } | 941 | } | ||
873 | 942 | | |||
874 | KReportUnit KReportDesigner::pageUnit() const | 943 | KReportUnit KReportDesigner::pageUnit() const | ||
875 | { | 944 | { | ||
876 | QString u; | 945 | return d->currentUnit; | ||
877 | bool found; | | |||
878 | | ||||
879 | u = d->unit->value().toString(); | | |||
880 | | ||||
881 | KReportUnit unit = KReportUnit::fromSymbol(u, &found); | | |||
882 | if (!found) { | | |||
883 | unit = KReportUnit(KReportUnit::Centimeter); | | |||
884 | } | | |||
885 | | ||||
886 | return unit; | | |||
887 | } | 946 | } | ||
888 | 947 | | |||
889 | void KReportDesigner::setGridOptions(bool vis, int div) | 948 | void KReportDesigner::setGridOptions(bool vis, int div) | ||
890 | { | 949 | { | ||
891 | d->showGrid->setValue(QVariant(vis)); | 950 | d->showGrid->setValue(QVariant(vis)); | ||
892 | d->gridDivisions->setValue(div); | 951 | d->gridDivisions->setValue(div); | ||
893 | } | 952 | } | ||
894 | 953 | | |||
▲ Show 20 Lines • Show All 89 Lines • ▼ Show 20 Line(s) | 1042 | else { | |||
984 | kreportWarning() << "attempted to insert an unknown item"; | 1043 | kreportWarning() << "attempted to insert an unknown item"; | ||
985 | } | 1044 | } | ||
986 | } | 1045 | } | ||
987 | if (item) { | 1046 | if (item) { | ||
988 | item->setVisible(true); | 1047 | item->setVisible(true); | ||
989 | item->setSelected(true); | 1048 | item->setSelected(true); | ||
990 | KReportItemBase* baseReportItem = dynamic_cast<KReportItemBase*>(item); | 1049 | KReportItemBase* baseReportItem = dynamic_cast<KReportItemBase*>(item); | ||
991 | if (baseReportItem) { | 1050 | if (baseReportItem) { | ||
992 | baseReportItem->setUnit(pageUnit()); | | |||
993 | KPropertySet *set = baseReportItem->propertySet(); | 1051 | KPropertySet *set = baseReportItem->propertySet(); | ||
994 | KReportDesigner::addMetaProperties(set, classString, iconName); | 1052 | KReportDesigner::addMetaProperties(set, classString, iconName); | ||
995 | changeSet(set); | 1053 | changeSet(set); | ||
996 | if (v && v->designer()) { | 1054 | if (v && v->designer()) { | ||
997 | v->designer()->setModified(true); | 1055 | v->designer()->setModified(true); | ||
998 | } | 1056 | } | ||
999 | emit itemInserted(d->sectionData.itemToInsert); | 1057 | emit itemInserted(d->sectionData.itemToInsert); | ||
1000 | } | 1058 | } | ||
▲ Show 20 Lines • Show All 509 Lines • ▼ Show 20 Line(s) | 1567 | void KReportDesigner::addMetaProperties(KPropertySet* set, const QString &classString, | |||
1510 | const QString &iconName) | 1568 | const QString &iconName) | ||
1511 | { | 1569 | { | ||
1512 | Q_ASSERT(set); | 1570 | Q_ASSERT(set); | ||
1513 | KProperty *prop; | 1571 | KProperty *prop; | ||
1514 | set->addProperty(prop = new KProperty("this:classString", classString)); | 1572 | set->addProperty(prop = new KProperty("this:classString", classString)); | ||
1515 | prop->setVisible(false); | 1573 | prop->setVisible(false); | ||
1516 | set->addProperty(prop = new KProperty("this:iconName", iconName)); | 1574 | set->addProperty(prop = new KProperty("this:iconName", iconName)); | ||
1517 | prop->setVisible(false); | 1575 | prop->setVisible(false); | ||
1518 | } | 1576 | } | ||
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)