diff --git a/autotests/format/FormatTest.cpp b/autotests/format/FormatTest.cpp index fb4f9279..c5e4abe0 100644 --- a/autotests/format/FormatTest.cpp +++ b/autotests/format/FormatTest.cpp @@ -1,222 +1,221 @@ /* This file is part of the KDE project * Copyright (C) 2012 Dag Andersen * Copyright (C) 2015 Jarosław Staniek * * QFUZZYCOMPARE() from marble/tests/TestUtils.h: * Copyright (C) 2013 Dennis Nienhüser * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . */ #include "FormatTest.h" #include "KReportTestUtils.h" #include "KReportPreRenderer.h" #include "KReportDesigner.h" #include "KReportLabelElement.h" #include "KReportDocument.h" -#include "KReportPageOptions.h" #include "KReportDesignerSectionDetail.h" #include "KReportSection.h" #include "KReportPosition.h" #include "KReportSize.h" #include "KReportDesignerItemLine.h" #include "KReportItemLine.h" #include "KReportDesignerItemRectBase.h" #include "KReportUnit.h" #include #include #include #include #include #include #include #include #include QTEST_MAIN(FormatTest) static bool openDesignFile(KReportDesign *design, QString *errorMessage) { const QString dir(QFile::decodeName(FILES_DATA_DIR)); const QString fname(QLatin1String(QTest::currentTestFunction()) + QLatin1String(".kreport")); QFile file(dir + QDir::separator() + fname); bool ok = file.open(QFile::ReadOnly | QFile::Text); if (!ok) { *errorMessage = QString::fromLatin1("Could not open file %1: ").arg(file.fileName()) + file.errorString(); return false; } QString content = file.readAll(); if (file.error() != QFileDevice::NoError) { *errorMessage = QString::fromLatin1("Error reading file %1: ").arg(file.fileName()) + file.errorString(); return false; } KReportDesignReadingStatus status; if (!design->setContent(content, &status)) { QString message; QDebug(&message) << status; *errorMessage = QLatin1String("Failed to load content. ") + message; return false; } errorMessage->clear(); return true; } void FormatTest::testPageLayout() { KReportDesign design; QString errorMessage; if (!openDesignFile(&design, &errorMessage)) { QFAIL(qPrintable(errorMessage)); } const QPageLayout pageLayout = design.pageLayout(); QVERIFY(pageLayout.isValid()); QCOMPARE(pageLayout.pageSize().id(), QPageSize::A5); QCOMPARE(pageLayout.pageSize().sizePoints(), QPageSize(QPageSize::A5).sizePoints()); QCOMPARE(pageLayout.orientation(), QPageLayout::Portrait); QCOMPARE(pageLayout.margins(QPageLayout::Millimeter), QMarginsF(30.0, 20.0, 40.0, 15.0)); //! @todo move this renderer test to a separate place #if 0 KReportDesigner designer; QCOMPARE(designer.propertySet()->property("page-size").value().toString(), QLatin1String("A5")); QCOMPARE(designer.propertySet()->property("margin-bottom").value().toDouble(), KReportUnit::parseValue("1.5cm")); QCOMPARE(designer.propertySet()->property("margin-top").value().toDouble(), KReportUnit::parseValue("2.0cm")); QCOMPARE(designer.propertySet()->property("margin-left").value().toDouble(), KReportUnit::parseValue("3.0cm")); QCOMPARE(designer.propertySet()->property("margin-right").value().toDouble(), KReportUnit::parseValue("4.0cm")); KReportPreRenderer renderer( designer.document() ); renderer.generate(); ReportPageOptions opt = renderer.reportData()->pageOptions(); QCOMPARE(opt.getPageSize(), QString("A5")); QScreen *srn = QApplication::screens().at(0); const qreal dpiY = srn->logicalDotsPerInchY(); qDebug() << opt.getMarginBottom() << INCH_TO_POINT(opt.getMarginBottom()) << KReportDpi::dpiY() << dpiY << KReportUnit::parseValue("1.5cm"); QFUZZYCOMPARE(INCH_TO_POINT(opt.getMarginBottom()) / KReportDpi::dpiY(), KReportUnit::parseValue("1.5cm"), 0.2); QFUZZYCOMPARE(INCH_TO_POINT(opt.getMarginTop()) / KReportDpi::dpiY(), KReportUnit::parseValue("2.0cm"), 0.2); QFUZZYCOMPARE(INCH_TO_POINT(opt.getMarginLeft()) / KReportDpi::dpiX(), KReportUnit::parseValue("3.0cm"), 0.2); QFUZZYCOMPARE(INCH_TO_POINT(opt.getMarginRight()) / KReportDpi::dpiX(), KReportUnit::parseValue("4.0cm"), 0.3); #endif } void FormatTest::testLineElement() { #if 0 // todo KReportDesign design; QString errorMessage; if (!openDesignFile(&design, &errorMessage)) { QFAIL(qPrintable(errorMessage)); } #endif //! @todo move this renderer test to a separate place #if 0 KReportDesigner designer; ReportSectionDetail *ds = designer.detailSection(); ReportSection *sec = ds->detailSection(); KReportItemLine *l = dynamic_cast(sec->items().first()); QVERIFY(l != 0); QCOMPARE(l->Z, 1.5); KReportPosition start = l->startPosition(); KReportPosition end = l->endPosition(); QCOMPARE(start.toPoint(), QPointF(KReportUnit::parseValue("1.5cm"), KReportUnit::parseValue("0.5cm"))); QCOMPARE(end.toPoint(), QPointF(KReportUnit::parseValue("4.5cm"), KReportUnit::parseValue("2.5cm"))); KReportPreRenderer renderer( designer.document() ); renderer.generate(); l = dynamic_cast(renderer.reportData()->object("line1")); QVERIFY(l != 0); QCOMPARE(l->Z, 1.5); start = l->startPosition(); end = l->endPosition(); QCOMPARE(start.toPoint(), QPointF(KReportUnit::parseValue("1.5cm"), KReportUnit::parseValue("0.5cm"))); QCOMPARE(end.toPoint(), QPointF(KReportUnit::parseValue("4.5cm"), KReportUnit::parseValue("2.5cm"))); #endif } void FormatTest::testLabelElement() { KReportDesign design; QString errorMessage; if (!openDesignFile(&design, &errorMessage)) { QFAIL(qPrintable(errorMessage)); } QCOMPARE(design.title(), QLatin1String("Label Element Test Report")); QVERIFY(design.hasSection(KReportSection::Detail)); KReportSection detailSection = design.section(KReportSection::Detail); QCOMPARE(detailSection.type(), KReportSection::Detail); QCOMPARE(detailSection.height(), CM_TO_POINT(5.0)); QCOMPARE(detailSection.backgroundColor(), QColor("#eeeeee")); QList elements = detailSection.elements(); QCOMPARE(elements.count(), 1); KReportElement element = elements.first(); QCOMPARE(element.name(), QLatin1String("label1")); KReportLabelElement label1(elements.first()); QCOMPARE(label1.text(), "Label"); QCOMPARE(label1.z(), 2.5); const QRectF rect(CM_TO_POINT(1.5), CM_TO_POINT(0.5), CM_TO_POINT(4.5), CM_TO_POINT(0.75)); QCOMPARE(label1.rect(), rect); QCOMPARE(label1.backgroundColor(), QColor("#dddddd")); QCOMPARE(label1.foregroundColor(), QColor("#101010")); QCOMPARE(label1.backgroundOpacity(), 0.9); QCOMPARE(label1.alignment(), Qt::AlignRight | Qt::AlignBottom); QCOMPARE(label1.font().capitalization(), QFont::AllLowercase); QCOMPARE(label1.font().bold(), true); QCOMPARE(label1.font().weight(), 99); QCOMPARE(label1.font().italic(), true); QCOMPARE(label1.font().fixedPitch(), true); QCOMPARE(label1.font().family(), "Ubuntu"); QCOMPARE(label1.font().kerning(), true); QCOMPARE(label1.font().underline(), true); QCOMPARE(label1.font().strikeOut(), true); QCOMPARE(label1.font().pointSizeF(), 9.0); QCOMPARE(label1.font().letterSpacing(), 110.0); QCOMPARE(label1.font().letterSpacingType(), QFont::PercentageSpacing); QCOMPARE(label1.borderStyle().width(), 1.0); QCOMPARE(label1.borderStyle().color(), QColor("#400000")); QCOMPARE(label1.borderStyle().penStyle(), Qt::DashLine); //! @todo move this renderer test to a separate place #if 0 KReportDesigner designer;//, doc.documentElement()); ReportSectionDetail *ds = designer.detailSection(); ReportSection *sec = ds->detailSection(); QVERIFY(sec->items().count() == 1); KReportDesignerItemRectBase *rect = dynamic_cast(sec->items().first()); QVERIFY(rect != 0); QRectF expected( QPointF(KReportUnit::parseValue("1.5cm"), KReportUnit::parseValue("0.5cm")), QSizeF(KReportUnit::parseValue("4.5cm"), KReportUnit::parseValue("0.75cm"))); QCOMPARE(rect->pointRect(), expected); KReportPreRenderer renderer( designer.document() ); renderer.generate(); KReportItemBase *item = dynamic_cast(renderer.reportData()->object("label1")); QVERIFY(item != 0); KReportPosition pos = item->position(); KReportSize size = item->size(); QCOMPARE(pos.toPoint().x(), KReportUnit::parseValue("1.5cm")); QCOMPARE(pos.toPoint().y(), KReportUnit::parseValue("0.5cm")); QCOMPARE(size.toPoint(), QSizeF(KReportUnit::parseValue("4.5cm"), KReportUnit::parseValue("0.75cm"))); QCOMPARE(size.toPoint(), QSizeF(KReportUnit::parseValue("4.5cm"), KReportUnit::parseValue("0.75cm"))); #endif } diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 32794d94..234f5b90 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,339 +1,337 @@ # Options simple_option(KREPORT_SCRIPTING "Scripting support using JavaScript language" ON) if(KREPORT_SCRIPTING) find_package(Qt5Qml REQUIRED) set(SCRIPTING_LIBS Qt5::Qml) endif() set(kreport_LIB_SRCS common/kreport_debug.cpp common/kreportplugin_debug.cpp common/KReportPosition.cpp common/KReportSize.cpp common/KReportItemBase.cpp common/KReportAsyncItemBase.cpp common/KReportSectionData.cpp common/KReportLabelSizeInfo.cpp - common/KReportPageOptions.cpp common/KReportDocument.cpp common/KReportDetailSectionData.cpp common/KReportPluginInterface.cpp common/KReportItemLine.cpp common/KReportRenderObjects.cpp common/KReportPluginManager.cpp common/KReportJsonTrader_p.cpp common/KReportPluginMetaData.cpp common/KReportData.cpp common/KReportUtils.cpp common/KReportPageSize.cpp common/KReportUnit.cpp common/KReportDesign.cpp common/KReportDesign_p.cpp common/KReportLineStyle.cpp common/KReportElement.cpp ${PROJECT_BINARY_DIR}/src/KReportElement_sdc.cpp common/KReportSection.cpp renderer/KReportPrintRenderer_p.cpp renderer/KReportPreRenderer.cpp renderer/KReportAsyncItemManager_p.cpp renderer/KReportScreenRenderer_p.cpp renderer/KReportHTMLTableRenderer_p.cpp renderer/KReportHTMLCSSRenderer_p.cpp #TODO renderer/KReportKSpreadRenderer.cpp #TODO renderer/KReportODTRenderer.cpp #TODO renderer/KOdtFrameReportRenderer.cpp renderer/KReportRendererBase.cpp renderer/KReportPage.cpp renderer/KReportView.cpp renderer/KReportOneRecordData_p.cpp wrtembed/KReportDetailGroupSectionDialog.cpp wrtembed/KReportDesignerItemBase.cpp wrtembed/KReportDesignerItemRectBase.cpp wrtembed/KReportDesignerItemLine.cpp wrtembed/KReportDesignerSection.cpp wrtembed/KReportDesignerSectionDetailGroup.cpp wrtembed/KReportDesignerSectionDetail.cpp wrtembed/KReportDesignerSectionScene.cpp wrtembed/KReportDesignerSectionView.cpp wrtembed/KReportDesigner.cpp wrtembed/KReportPropertiesButton.cpp wrtembed/KReportSectionEditor.cpp wrtembed/KReportDpi.cpp wrtembed/KReportRuler.cpp wrtembed/KReportZoomHandler.cpp wrtembed/KReportZoomMode.cpp items/label/KReportItemLabel.cpp items/label/KReportDesignerItemLabel.cpp items/label/KReportLabelPlugin.cpp items/label/KReportBoundedTextItem.cpp items/label/KReportLabelElement.cpp items/label/label.json items/check/KReportItemCheck.cpp items/check/KReportDesignerItemCheckBox.cpp items/check/KReportCheckBoxPlugin.cpp items/check/check.json items/field/KReportItemField.cpp items/field/KReportDesignerItemField.cpp items/field/KReportFieldPlugin.cpp items/field/field.json items/image/KReportItemImage.cpp items/image/KReportDesignerItemImage.cpp items/image/KReportImagePlugin.cpp items/image/image.json items/text/KReportItemText.cpp items/text/KReportDesignerItemText.cpp items/text/KReportTextPlugin.cpp items/text/text.json # non-source: Mainpage.dox Messages.sh ) set(kreport_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/common ${CMAKE_CURRENT_SOURCE_DIR}/wrtembed ${CMAKE_CURRENT_SOURCE_DIR}/renderer ) set(kreport_TARGET_INCLUDE_DIRS common renderer wrtembed ) if(KREPORT_SCRIPTING) list(APPEND kreport_LIB_SRCS renderer/scripting/KReportScriptHandler.cpp renderer/scripting/KReportScriptConstants.cpp renderer/scripting/KReportScriptDebug.cpp renderer/scripting/KReportScriptDraw.cpp renderer/scripting/KReportScriptReport.cpp renderer/scripting/KReportScriptSection.cpp renderer/scripting/KReportScriptLine.cpp #renderer/odtframe/KoOdtFrameReportDocument.cpp #renderer/odtframe/KoOdtFrameReportCheckBox.cpp #renderer/odtframe/KoOdtFrameReportImage.cpp #renderer/odtframe/KoOdtFrameReportTextBox.cpp #renderer/odtframe/KoOdtFrameReportLine.cpp #renderer/odtframe/KoOdtFrameReportPicture.cpp #renderer/odtframe/KoOdtFrameReportPrimitive.cpp #renderer/ods/KoSimpleOdsDocument.cpp #renderer/ods/KoSimpleOdsSheet.cpp #renderer/ods/KoSimpleOdsCell.cpp items/label/KReportScriptLabel.cpp items/check/KReportScriptCheck.cpp items/field/KReportScriptField.cpp items/image/KReportScriptImage.cpp items/text/KReportScriptText.cpp ) qt_wrap_cpp(KReport kreport_LIB_SRCS renderer/scripting/KReportGroupTracker.h ) list(APPEND kreport_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/renderer/scripting ) list(APPEND kreport_TARGET_INCLUDE_DIRS renderer/scripting ) endif() qt5_wrap_ui(kreport_LIB_SRCS wrtembed/KReportDetailGroupSectionDialog.ui wrtembed/KReportSectionEditor.ui ) ecm_create_qm_loader(kreport_LIB_SRCS kreport_qt) add_library(KReport SHARED ${kreport_LIB_SRCS}) set_coinstallable_lib_version(KReport) kdb_create_shared_data_classes( kreport_GENERATED_SHARED_DATA_CLASS_HEADERS # output variable with list of headers NO_PREFIX # subdirectory in which the headers should be generated common/KReportLineStyle.shared.h common/KReportElement.shared.h common/KReportSection.shared.h items/label/KReportLabelElement.shared.h ) kdb_remove_extensions( kreport_GENERATED_SHARED_DATA_CLASS_BASENAMES ${kreport_GENERATED_SHARED_DATA_CLASS_HEADERS} ) generate_export_header(KReport) #qt5_use_modules(KReport Widgets Xml PrintSupport) target_include_directories(KReport PUBLIC "$" INTERFACE "$" PRIVATE ${kreport_TARGET_INCLUDE_DIRS} ) target_link_libraries(KReport PUBLIC Qt5::PrintSupport Qt5::Xml KF5::CoreAddons KPropertyWidgets PRIVATE KF5::WidgetsAddons KF5::ConfigGui # KStandardShortcut ${SCRIPTING_LIBS} #KF5::KIOCore #KF5::KIOFileWidgets #KF5::KIOWidgets #KF5::KIONTLM ) ecm_setup_version(${PROJECT_VERSION} VARIABLE_PREFIX KREPORT VERSION_HEADER "${CMAKE_CURRENT_BINARY_DIR}/kreport_version.h" PACKAGE_VERSION_FILE "${CMAKE_CURRENT_BINARY_DIR}/KReportConfigVersion.cmake" ) install(TARGETS KReport EXPORT KReportTargets ${KDE_INSTALL_TARGETS_DEFAULT_ARGS}) # Create a Config.cmake and a ConfigVersion.cmake file and install them set(CMAKECONFIG_INSTALL_DIR "${CMAKECONFIG_INSTALL_PREFIX}/${KREPORT_BASE_NAME}") # A place for KReport plugins set(KREPORT_PLUGIN_INSTALL_DIR ${PLUGIN_INSTALL_DIR}/kreport${PROJECT_STABLE_VERSION_MAJOR}) ecm_configure_package_config_file( "${CMAKE_CURRENT_SOURCE_DIR}/KReportConfig.cmake.in" "${CMAKE_CURRENT_BINARY_DIR}/KReportConfig.cmake" INSTALL_DESTINATION "${CMAKECONFIG_INSTALL_DIR}" ) install(FILES "${CMAKE_CURRENT_BINARY_DIR}/KReportConfig.cmake" "${CMAKE_CURRENT_BINARY_DIR}/KReportConfigVersion.cmake" DESTINATION "${CMAKECONFIG_INSTALL_DIR}" COMPONENT Devel) install(EXPORT KReportTargets DESTINATION "${CMAKECONFIG_INSTALL_DIR}" FILE KReportTargets.cmake) ecm_generate_pri_file( BASE_NAME ${KREPORT_BASE_NAME} LIB_NAME ${KREPORT_BASE_NAME} DEPS "widgets" FILENAME_VAR PRI_FILENAME INCLUDE_INSTALL_DIR ${KREPORT_INCLUDE_INSTALL_DIR} ) install(FILES ${PRI_FILENAME} DESTINATION ${ECM_MKSPECS_INSTALL_DIR}) install(FILES kreport_elementplugin.desktop DESTINATION ${SERVICETYPES_INSTALL_DIR}) ecm_generate_headers(kreport_FORWARDING_HEADERS REQUIRED_HEADERS kreport_HEADERS ORIGINAL CAMELCASE RELATIVE common HEADER_NAMES KReportPageSize KReportData KReportItemBase KReportItemLine KReportPluginMetaData KReportPluginManager KReportPluginInterface KReportUnit KReportUtils KReportDesign KReportSize KReportPosition KReportDocument KReportSectionData - KReportPageOptions KReportRenderObjects KReportAsyncItemBase ) ecm_generate_headers(kreport_FORWARDING_HEADERS REQUIRED_HEADERS kreport_HEADERS ORIGINAL CAMELCASE RELATIVE renderer HEADER_NAMES KReportPage KReportRendererBase KReportPreRenderer KReportView ) if(KREPORT_SCRIPTING) ecm_generate_headers(kreport_FORWARDING_HEADERS REQUIRED_HEADERS kreport_HEADERS ORIGINAL CAMELCASE RELATIVE renderer/scripting HEADER_NAMES KReportScriptHandler KReportScriptDraw KReportScriptConstants KReportGroupTracker ) endif() ecm_generate_headers(kreport_FORWARDING_HEADERS REQUIRED_HEADERS kreport_HEADERS ORIGINAL CAMELCASE RELATIVE wrtembed HEADER_NAMES KReportZoomMode KReportDesignerSectionDetail KReportDesignerSection KReportDpi KReportZoomHandler KReportDesignerItemBase KReportDesignerSectionDetailGroup KReportDesignerItemRectBase KReportDesigner ) ecm_generate_headers(kreport_FORWARDING_HEADERS_FROM_BUILDDIR REQUIRED_HEADERS kreport_HEADERS_FROM_BUILDDIR ORIGINAL CAMELCASE SOURCE_DIR ${PROJECT_BINARY_DIR}/src HEADER_NAMES ${kreport_GENERATED_SHARED_DATA_CLASS_BASENAMES} ) list(APPEND kreport_HEADERS ${CMAKE_CURRENT_BINARY_DIR}/kreport_version.h) install( FILES ${kreport_HEADERS} ${kreport_HEADERS_FROM_BUILDDIR} ${kreport_FORWARDING_HEADERS} ${kreport_FORWARDING_HEADERS_FROM_BUILDDIR} ${PROJECT_BINARY_DIR}/src/kreport_export.h ${PROJECT_BINARY_DIR}/src/config-kreport.h DESTINATION ${KREPORT_INCLUDE_INSTALL_DIR} COMPONENT Devel ) add_subdirectory(plugins) add_subdirectory(pics) enable_testing() configure_file(config-kreport.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config-kreport.h) diff --git a/src/common/KReportDocument.cpp b/src/common/KReportDocument.cpp index 7dec1f1d..d8fc3dd7 100644 --- a/src/common/KReportDocument.cpp +++ b/src/common/KReportDocument.cpp @@ -1,361 +1,388 @@ /* This file is part of the KDE project * Copyright (C) 2007-2008 by Adam Pigg (adam@piggz.co.uk) * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . */ #include "KReportDocument.h" #include "KReportUnit.h" #include "KReportDetailSectionData.h" #include "KReportItemBase.h" #include "KReportDpi.h" +#include "KReportPageSize.h" #include #include #include "kreport_debug.h" class Q_DECL_HIDDEN KReportDocument::Private { public: bool valid; QString title; QString name; QString query; #ifdef KREPORT_SCRIPTING QString script; QString interpreter; #endif bool externalData; - KReportPageOptions page; + QPageLayout page; + QString pageSize; + QString labelType; }; void KReportDocument::init() { m_pageHeaderFirst = m_pageHeaderOdd = m_pageHeaderEven = m_pageHeaderLast = m_pageHeaderAny = 0; m_pageFooterFirst = m_pageFooterOdd = m_pageFooterEven = m_pageFooterLast = m_pageFooterAny = 0; m_reportHeader = m_reportFooter = 0; } KReportDocument::KReportDocument(QObject *parent) : QObject(parent), m_detailSection(0), d(new Private()) { init(); d->valid = true; } KReportDocument::KReportDocument(const QDomElement & elemSource, QObject *parent) : QObject(parent), m_detailSection(0), d(new Private()) { d->valid = false; init(); //kreportDebug(); if (elemSource.tagName() != QLatin1String("report:content")) { kreportWarning() << "QDomElement is not tag" << elemSource.text(); return; } const qreal dpiX = KReportDpi::dpiX(); const qreal dpiY = KReportDpi::dpiY(); QDomNodeList sections = elemSource.childNodes(); for (int nodeCounter = 0; nodeCounter < sections.count(); nodeCounter++) { QDomElement elemThis = sections.item(nodeCounter).toElement(); if (elemThis.tagName() == QLatin1String("report:title")) { d->title = elemThis.text(); #ifdef KREPORT_SCRIPTING } else if (elemThis.tagName() == QLatin1String("report:script")) { d->script = elemThis.text(); d->interpreter = elemThis.attribute(QLatin1String("report:script-interpreter")); #endif - } else if (elemThis.tagName() == QLatin1String("report:page-style")) { + } else if (elemThis.tagName() == QLatin1String("report:page-style")) { QString pagetype = elemThis.firstChild().nodeValue(); + //Full page mode is required to allow margins to be set to whatever the user has specified + d->page.setMode(QPageLayout::FullPageMode); + if (pagetype == QLatin1String("predefined")) { - d->page.setPageSize(elemThis.attribute(QLatin1String("report:page-size"), QLatin1String("A4"))); + setPageSize(elemThis.attribute(QLatin1String("report:page-size"), QLatin1String("A4"))); + d->page.setPageSize(QPageSize(KReportPageSize::pageSize(pageSize()))); } else if (pagetype == QLatin1String("custom")) { - d->page.setCustomWidth(POINT_TO_INCH(KReportUnit::parseValue(elemThis.attribute(QLatin1String("report:custom-page-width"), QString()))) * dpiX); - d->page.setCustomHeight(POINT_TO_INCH(KReportUnit::parseValue(elemThis.attribute(QLatin1String("report:custom-page-height"), QString()))) * dpiY); - d->page.setPageSize(QLatin1String("Custom")); + QPageSize custom(QSize(elemThis.attribute(QLatin1String("report:custom-page-width"), QString()).toFloat() , elemThis.attribute(QLatin1String("report:custom-page-height"), QString()).toFloat()), QLatin1String("Custom")); + + d->page.setPageSize(custom); } else if (pagetype == QLatin1String("label")) { - d->page.setLabelType(elemThis.firstChild().nodeValue()); + setLabelType(elemThis.firstChild().nodeValue()); } //! @todo add config for default margins or add within templates support - d->page.setMarginBottom(POINT_TO_INCH(KReportUnit::parseValue(elemThis.attribute(QLatin1String("fo:margin-bottom"), QLatin1String("1.0cm")))) * dpiY); - d->page.setMarginTop(POINT_TO_INCH(KReportUnit::parseValue(elemThis.attribute(QLatin1String("fo:margin-top"), QLatin1String("1.0cm")))) * dpiY); - d->page.setMarginLeft(POINT_TO_INCH(KReportUnit::parseValue(elemThis.attribute(QLatin1String("fo:margin-left"), QLatin1String("1.0cm")))) * dpiX); - d->page.setMarginRight(POINT_TO_INCH(KReportUnit::parseValue(elemThis.attribute(QLatin1String("fo:margin-right"), QLatin1String("1.0cm")))) * dpiX); - - d->page.setPortrait(elemThis.attribute(QLatin1String("report:print-orientation"), QLatin1String("portrait")) == QLatin1String("portrait")); - + d->page.setUnits(QPageLayout::Point); + d->page.setLeftMargin(KReportUnit::parseValue(elemThis.attribute(QLatin1String("fo:margin-left"), QLatin1String("1.0cm")))); + d->page.setRightMargin(KReportUnit::parseValue(elemThis.attribute(QLatin1String("fo:margin-right"), QLatin1String("1.0cm")))); + d->page.setTopMargin(KReportUnit::parseValue(elemThis.attribute(QLatin1String("fo:margin-top"), QLatin1String("1.0cm")))); + d->page.setBottomMargin(KReportUnit::parseValue(elemThis.attribute(QLatin1String("fo:margin-bottom"), QLatin1String("1.0cm")))); + d->page.setOrientation(elemThis.attribute(QLatin1String("report:print-orientation"), QLatin1String("portrait")) == QLatin1String("portrait") ? QPageLayout::Portrait : QPageLayout::Landscape); } else if (elemThis.tagName() == QLatin1String("report:body")) { QDomNodeList sectionlist = elemThis.childNodes(); QDomNode sec; for (int s = 0; s < sectionlist.count(); ++s) { sec = sectionlist.item(s); if (sec.isElement()) { QString sn = sec.nodeName().toLower(); //kreportDebug() << sn; if (sn == QLatin1String("report:section")) { KReportSectionData * sd = new KReportSectionData(sec.toElement(), this); if (!sd->isValid()) { kreportDebug() << "Invalid section"; delete sd; } else { //kreportDebug() << "Adding section of type " << sd->type(); switch (sd->type()) { case KReportSectionData::PageHeaderFirst: m_pageHeaderFirst = sd; break; case KReportSectionData::PageHeaderOdd: m_pageHeaderOdd = sd; break; case KReportSectionData::PageHeaderEven: m_pageHeaderEven = sd; break; case KReportSectionData::PageHeaderLast: m_pageHeaderLast = sd; break; case KReportSectionData::PageHeaderAny: m_pageHeaderAny = sd; break; case KReportSectionData::ReportHeader: m_reportHeader = sd; break; case KReportSectionData::ReportFooter: m_reportFooter = sd; break; case KReportSectionData::PageFooterFirst: m_pageFooterFirst = sd; break; case KReportSectionData::PageFooterOdd: m_pageFooterOdd = sd; break; case KReportSectionData::PageFooterEven: m_pageFooterEven = sd; break; case KReportSectionData::PageFooterLast: m_pageFooterLast = sd; break; case KReportSectionData::PageFooterAny: m_pageFooterAny = sd; break; default: ; } } } else if (sn == QLatin1String("report:detail")) { KReportDetailSectionData * dsd = new KReportDetailSectionData(sec.toElement(), this); if (dsd->isValid()) { m_detailSection = dsd; } else { kreportDebug() << "Invalid detail section"; delete dsd; } } } else { kreportWarning() << "Encountered an unknown Element: " << elemThis.tagName(); } } } d->valid = true; } } KReportDocument::~KReportDocument() { delete d; } QList KReportDocument::objects() const { QList obs; for (int i = 1; i <= KReportSectionData::PageFooterAny; i++) { KReportSectionData *sec = section((KReportSectionData::Section)i); if (sec) { obs << sec->objects(); } } if (m_detailSection) { //kreportDebug() << "Number of groups: " << m_detailSection->m_groupList.count(); foreach(KReportDetailGroupSectionData* g, m_detailSection->m_groupList) { if (g->m_groupHeader) { obs << g->m_groupHeader->objects(); } if (g->m_groupFooter) { obs << g->m_groupFooter->objects(); } } if (m_detailSection->m_detailSection) obs << m_detailSection->m_detailSection->objects(); } /*kreportDebug() << "Object List:"; foreach(KReportItemBase* o, obs) { kreportDebug() << o->entityName(); }*/ return obs; } KReportItemBase* KReportDocument::object(const QString& n) const { QList obs = objects(); foreach(KReportItemBase* o, obs) { if (o->entityName() == n) { return o; } } return 0; } QList KReportDocument::sections() const { QList secs; for (int i = 0; i < 12 ; ++i) { KReportSectionData *sec = section((KReportSectionData::Section)(i + 1)); if (sec) { secs << sec; } } if (m_detailSection) { //kreportDebug() << "Number of groups: " << m_detailSection->m_groupList.count(); foreach(KReportDetailGroupSectionData* g, m_detailSection->m_groupList) { if (g->m_groupHeader) { secs << g->m_groupHeader; } if (g->m_groupFooter) { secs << g->m_groupFooter; } } if (m_detailSection->m_detailSection) secs << m_detailSection->m_detailSection; } return secs; } KReportSectionData* KReportDocument::section(const QString& sn) const { QList secs = sections(); foreach(KReportSectionData *sec, secs) { if (sec->name() == sn) { return sec; } } return 0; } KReportSectionData* KReportDocument::section(KReportSectionData::Section s) const { KReportSectionData *sec; switch (s) { case KReportSectionData::PageHeaderAny: sec = m_pageHeaderAny; break; case KReportSectionData::PageHeaderEven: sec = m_pageHeaderEven; break; case KReportSectionData::PageHeaderOdd: sec = m_pageHeaderOdd; break; case KReportSectionData::PageHeaderFirst: sec = m_pageHeaderFirst; break; case KReportSectionData::PageHeaderLast: sec = m_pageHeaderLast; break; case KReportSectionData::PageFooterAny: sec = m_pageFooterAny; break; case KReportSectionData::PageFooterEven: sec = m_pageFooterEven; break; case KReportSectionData::PageFooterOdd: sec = m_pageFooterOdd; break; case KReportSectionData::PageFooterFirst: sec = m_pageFooterFirst; break; case KReportSectionData::PageFooterLast: sec = m_pageFooterLast; break; case KReportSectionData::ReportHeader: sec = m_reportHeader; break; case KReportSectionData::ReportFooter: sec = m_reportFooter; break; default: sec = 0; } return sec; } -KReportPageOptions KReportDocument::pageOptions() const +QPageLayout KReportDocument::pageLayout() const { return d->page; } bool KReportDocument::isValid() const { return d->valid; } QString KReportDocument::title() const { return d->title; } bool KReportDocument::externalData() const { return d->externalData; } QString KReportDocument::interpreter() const { return d->interpreter; } QString KReportDocument::name() const { return d->name; } void KReportDocument::setName(const QString& n) { d->name = n; } QString KReportDocument::query() const { return d->query; } QString KReportDocument::script() const { return d->script; } + +QString KReportDocument::pageSize() +{ + return d->pageSize; +} + +void KReportDocument::setPageSize(const QString& size) +{ + d->pageSize = size; +} + +QString KReportDocument::labelType() const +{ + return d->labelType; +} + +void KReportDocument::setLabelType(const QString& label) +{ + d->labelType = label; +} + diff --git a/src/common/KReportDocument.h b/src/common/KReportDocument.h index cf93cb17..04892c60 100644 --- a/src/common/KReportDocument.h +++ b/src/common/KReportDocument.h @@ -1,126 +1,136 @@ /* This file is part of the KDE project * Copyright (C) 2001-2007 by OpenMFG, LLC (info@openmfg.com) * Copyright (C) 2007-2008 by Adam Pigg (adam@piggz.co.uk) * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . */ -#ifndef KREPORTSCHEMADATA_H -#define KREPORTSCHEMADATA_H +#ifndef KREPORTDOCUMENT_H +#define KREPORTDOCUMENT_H #include "config-kreport.h" #include "kreport_export.h" #include "KReportSectionData.h" -#include "KReportPageOptions.h" + +#include class KReportDetailSectionData; #ifdef KREPORT_SCRIPTING namespace Scripting { class Report; } #endif /** */ class KREPORT_EXPORT KReportDocument : public QObject { Q_OBJECT public: explicit KReportDocument(const QDomElement & elemSource, QObject *parent = 0); explicit KReportDocument(QObject *parent = 0); ~KReportDocument(); bool isValid() const; /** \return a list of all objects in the report */ QList objects() const; /** \return a report object given its name */ KReportItemBase* object(const QString&) const; /** \return all the sections, including groups and detail */ QList sections() const; /** \return a sectiondata given a section enum */ KReportSectionData* section(KReportSectionData::Section) const; /** \return a sectiondata given its name */ KReportSectionData* section(const QString&) const; QString query() const; #ifdef KREPORT_SCRIPTING QString script() const; QString interpreter() const; #endif bool externalData() const; KReportDetailSectionData* detail() const { return m_detailSection; } void setName(const QString&n); QString name() const; QString title() const; - KReportPageOptions pageOptions() const; + QPageLayout pageLayout() const; + + QString pageSize(); + void setPageSize(const QString &size); + protected: KReportSectionData * m_pageHeaderFirst; KReportSectionData * m_pageHeaderOdd; KReportSectionData * m_pageHeaderEven; KReportSectionData * m_pageHeaderLast; KReportSectionData * m_pageHeaderAny; KReportSectionData * m_reportHeader; KReportSectionData * m_reportFooter; KReportSectionData * m_pageFooterFirst; KReportSectionData * m_pageFooterOdd; KReportSectionData * m_pageFooterEven; KReportSectionData * m_pageFooterLast; KReportSectionData * m_pageFooterAny; KReportDetailSectionData* m_detailSection; private: void init(); friend class KReportPreRendererPrivate; friend class KReportPreRenderer; #ifdef KREPORT_SCRIPTING friend class KReportScriptHandler; friend class Scripting::Report; #endif + + //! TODO add support for labels + QString labelType() const; + void setLabelType(const QString &label); + class Private; Private * const d; }; #endif diff --git a/src/common/KReportPageOptions.cpp b/src/common/KReportPageOptions.cpp deleted file mode 100644 index 9cb37f9b..00000000 --- a/src/common/KReportPageOptions.cpp +++ /dev/null @@ -1,218 +0,0 @@ -/* This file is part of the KDE project - * Copyright (C) 2001-2007 by OpenMFG, LLC (info@openmfg.com) - * Copyright (C) 2007-2008 by Adam Pigg (adam@piggz.co.uk) - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library. If not, see . - */ - -#include "KReportPageOptions.h" -#include "KReportUnit.h" -#include "KReportPageSize.h" -#include "KReportDpi.h" - -#include - -KReportPageOptions::KReportPageOptions() - : QObject(), m_pageSize(QLatin1String("Letter")) -{ - m_marginTop = m_marginBottom = 1.0; - m_marginLeft = m_marginRight = 1.0; - - m_orientation = Portrait; - - m_customWidth = 8.5; - m_customHeight = 11.0; -} - -KReportPageOptions::KReportPageOptions(const KReportPageOptions & rpo) - : QObject() -{ - m_marginTop = rpo.m_marginTop; - m_marginBottom = rpo.m_marginBottom; - m_marginLeft = rpo.m_marginLeft; - m_marginRight = rpo.m_marginRight; - - m_pageSize = rpo.m_pageSize; - m_customWidth = rpo.m_customWidth; - m_customHeight = rpo.m_customHeight; - - m_orientation = rpo.m_orientation; - - m_labelType = rpo.m_labelType; -} - -KReportPageOptions & KReportPageOptions::operator=(const KReportPageOptions & rpo) -{ - m_marginTop = rpo.m_marginTop; - m_marginBottom = rpo.m_marginBottom; - m_marginLeft = rpo.m_marginLeft; - m_marginRight = rpo.m_marginRight; - - m_pageSize = rpo.m_pageSize; - m_customWidth = rpo.m_customWidth; - m_customHeight = rpo.m_customHeight; - - m_orientation = rpo.m_orientation; - - m_labelType = rpo.m_labelType; - - return *this; -} - -qreal KReportPageOptions::getMarginTop() const -{ - return m_marginTop; -} - -void KReportPageOptions::setMarginTop(qreal v) -{ - if (m_marginTop == v) - return; - - m_marginTop = v; - emit pageOptionsChanged(); -} - -qreal KReportPageOptions::getMarginBottom() const -{ - return m_marginBottom; -} - -void KReportPageOptions::setMarginBottom(qreal v) -{ - if (m_marginBottom == v) - return; - - m_marginBottom = v; - emit pageOptionsChanged(); -} - -qreal KReportPageOptions::getMarginLeft() const -{ - return m_marginLeft; -} - -void KReportPageOptions::setMarginLeft(qreal v) -{ - if (m_marginLeft == v) - return; - - m_marginLeft = v; - emit pageOptionsChanged(); -} - -qreal KReportPageOptions::getMarginRight() const -{ - return m_marginRight; -} - -void KReportPageOptions::setMarginRight(qreal v) -{ - if (m_marginRight == v) - return; - - m_marginRight = v; - emit pageOptionsChanged(); -} - -const QString & KReportPageOptions::getPageSize() const -{ - return m_pageSize; -} - -void KReportPageOptions::setPageSize(const QString & s) -{ - if (m_pageSize == s) - return; - - m_pageSize = s; - emit pageOptionsChanged(); -} -qreal KReportPageOptions::getCustomWidth() const -{ - return m_customWidth; -} -void KReportPageOptions::setCustomWidth(qreal v) -{ - if (m_customWidth == v) - return; - - m_customWidth = v; - emit pageOptionsChanged(); -} - -qreal KReportPageOptions::getCustomHeight() const -{ - return m_customHeight; -} - -void KReportPageOptions::setCustomHeight(qreal v) -{ - if (m_customHeight == v) - return; - - m_customHeight = v; - emit pageOptionsChanged(); -} - -KReportPageOptions::PageOrientation KReportPageOptions::getOrientation() const -{ - return m_orientation; -} - -bool KReportPageOptions::isPortrait() const -{ - return (m_orientation == Portrait); -} - -void KReportPageOptions::setOrientation(PageOrientation o) -{ - if (m_orientation == o) - return; - - m_orientation = o; - emit pageOptionsChanged(); -} - -void KReportPageOptions::setPortrait(bool yes) -{ - setOrientation((yes ? Portrait : Landscape)); -} - -const QString & KReportPageOptions::getLabelType() const -{ - return m_labelType; -} - -void KReportPageOptions::setLabelType(const QString & type) -{ - if (m_labelType == type) - return; - - m_labelType = type; - emit pageOptionsChanged(); -} - -//Convenience functions that return the page width/height in pixels based on the DPI -QSizeF KReportPageOptions::pixelSize() const -{ - QSizeF xDpiSize = QPageSize(KReportPageSize::pageSize(getPageSize())).sizePixels(KReportDpi::dpiX()); - QSizeF yDpiSize = QPageSize(KReportPageSize::pageSize(getPageSize())).sizePixels(KReportDpi::dpiY()); - - if (isPortrait()){ - return QSizeF(xDpiSize.width(), yDpiSize.height()); - } else { - return QSizeF(xDpiSize.height(), yDpiSize.width()); - } -} diff --git a/src/common/KReportPageOptions.h b/src/common/KReportPageOptions.h deleted file mode 100644 index 6e86308c..00000000 --- a/src/common/KReportPageOptions.h +++ /dev/null @@ -1,85 +0,0 @@ -/* This file is part of the KDE project - * Copyright (C) 2001-2007 by OpenMFG, LLC (info@openmfg.com) - * Copyright (C) 2007-2008 by Adam Pigg (adam@piggz.co.uk) - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library. If not, see . - */ - -#ifndef KREPORTPAGEOPTIONS_H -#define KREPORTPAGEOPTIONS_H - -#include -#include - -#include "kreport_export.h" - -class KREPORT_EXPORT KReportPageOptions : public QObject -{ - Q_OBJECT -public: - KReportPageOptions(); - KReportPageOptions(const KReportPageOptions &); - - KReportPageOptions & operator=(const KReportPageOptions &); - - enum PageOrientation { - Landscape = 0, // essentially false - Portrait = 1 // and true - }; - - qreal getMarginTop() const; - void setMarginTop(qreal v); - qreal getMarginBottom() const; - void setMarginBottom(qreal v); - qreal getMarginLeft() const; - void setMarginLeft(qreal v); - qreal getMarginRight() const; - void setMarginRight(qreal v); - - QSizeF pixelSize() const; - - const QString & getPageSize() const; - void setPageSize(const QString & s); - qreal getCustomWidth() const; - void setCustomWidth(qreal v); - qreal getCustomHeight() const; - void setCustomHeight(qreal v); - - PageOrientation getOrientation() const; - bool isPortrait() const; - void setOrientation(PageOrientation o); - void setPortrait(bool yes); - - void setLabelType(const QString &); - const QString & getLabelType() const; - -Q_SIGNALS: - void pageOptionsChanged(); - -private: - qreal m_marginTop; - qreal m_marginBottom; - qreal m_marginLeft; - qreal m_marginRight; - - QString m_pageSize; - qreal m_customWidth; - qreal m_customHeight; - - PageOrientation m_orientation; - - QString m_labelType; -}; - -#endif diff --git a/src/common/KReportRenderObjects.cpp b/src/common/KReportRenderObjects.cpp index c8f765eb..4fc96b26 100644 --- a/src/common/KReportRenderObjects.cpp +++ b/src/common/KReportRenderObjects.cpp @@ -1,516 +1,516 @@ /* This file is part of the KDE project * Copyright (C) 2001-2007 by OpenMFG, LLC (info@openmfg.com) * Copyright (C) 2007-2008 by Adam Pigg (adam@piggz.co.uk) * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . */ #include "KReportRenderObjects.h" #include "kreport_debug.h" // // ORODocument // ORODocument::ORODocument(const QString & pTitle) : m_title(pTitle) { } ORODocument::~ORODocument() { qDeleteAll(m_pages); m_pages.clear(); qDeleteAll(m_sections); m_sections.clear(); } void ORODocument::setTitle(const QString & pTitle) { m_title = pTitle; } OROPage* ORODocument::page(int pnum) { if (pnum >= 0 && pnum < m_pages.count()) { return m_pages.at(pnum); } return Q_NULLPTR; } void ORODocument::addPage(OROPage* p) { if (p == 0) return; // check that this page is not already in another document p->m_document = this; m_pages.append(p); } OROSection* ORODocument::section(int pnum) { return m_sections.at(pnum); } void ORODocument::addSection(OROSection* s) { if (s == 0) return; // check that this page is not already in another document s->m_document = this; m_sections.append(s); } -void ORODocument::setPageOptions(const KReportPageOptions & options) +void ORODocument::setPageLayout(const QPageLayout & options) { - m_pageOptions = options; + m_pageLayout = options; } void ORODocument::notifyChange(int pageNo) { emit(updated(pageNo)); } // // OROPage // OROPage::OROPage(ORODocument * pDocument) : m_document(pDocument) { } OROPage::~OROPage() { if (m_document) { m_document->m_pages.removeOne(this); m_document = 0; } qDeleteAll(m_primitives); m_primitives.clear(); } int OROPage::page() const { if (m_document) { for (int i = 0; i < m_document->m_pages.size(); i++) { if (m_document->m_pages.at(i) == this) return i; } } return -1; } OROPrimitive* OROPage::primitive(int idx) { return m_primitives.at(idx); } void OROPage::addPrimitive(OROPrimitive* p, bool atBeginning, bool notify) { //kreportDebug() << "Adding primitive" << p->type() << "to page" << page(); if (p == 0) return; // check that this primitve is not already in another page p->m_page = this; if (atBeginning) { m_primitives.prepend(p); } else { m_primitives.append(p); } if (notify) { if (m_document) { m_document->notifyChange(page()); } } } // // OROSection // OROSection::OROSection(ORODocument * pDocument) : m_document(pDocument) { m_height = 0; m_backgroundColor = Qt::white; } OROSection::~OROSection() { if (m_document) { m_document->m_sections.removeOne(this); m_document = 0; } qDeleteAll(m_primitives); m_primitives.clear(); } OROPrimitive* OROSection::primitive(int idx) { return m_primitives.at(idx); } void OROSection::addPrimitive(OROPrimitive* p) { if (p == 0) return; m_primitives.append(p); } void OROSection::setHeight(int h) { m_height = h; } int OROSection::height() { return m_height; } void OROSection::setBackgroundColor(const QColor &c) { m_backgroundColor = c; } QColor OROSection::backgroundColor() { return m_backgroundColor; } void OROSection::sortPrimatives(Sort s) { if (s == SortX) { qSort(m_primitives.begin(), m_primitives.end(), xLessThan); } } bool OROSection::xLessThan(OROPrimitive* s1, OROPrimitive* s2) { return s1->position().x() < s2->position().x(); } // // OROPrimitive // OROPrimitive::OROPrimitive(int pType) : m_type(pType) { m_page = 0; } OROPrimitive::~OROPrimitive() { if (m_page) { m_page->m_primitives.removeAt(m_page->m_primitives.indexOf(this)); m_page = 0; } } void OROPrimitive::setPosition(const QPointF & p) { m_position = p; } void OROPrimitive::setSize(const QSizeF & s) { m_size = s; } // // OROTextBox // const int OROTextBox::TextBox = 1; OROTextBox::OROTextBox() : OROPrimitive(OROTextBox::TextBox) { m_flags = 0; m_lineStyle.setColor(Qt::black); m_lineStyle.setWidth(0); m_lineStyle.setPenStyle(Qt::NoPen); m_requiresPostProcessing = false; m_wordWrap = false; m_canGrow = false; } OROTextBox::~OROTextBox() { } void OROTextBox::setText(const QString & s) { m_text = s; } void OROTextBox::setTextStyle(const KRTextStyleData & ts) { m_textStyle = ts; } void OROTextBox::setLineStyle(const KReportLineStyle & ls) { m_lineStyle = ls; } void OROTextBox::setFont(const QFont & f) { m_textStyle.font = f; } void OROTextBox::setFlags(int f) { m_flags = f; } OROPrimitive* OROTextBox::clone() { OROTextBox *theClone = new OROTextBox(); theClone->setSize(m_size); theClone->setPosition(m_position); theClone->setText(m_text); theClone->setTextStyle(m_textStyle); theClone->setLineStyle(m_lineStyle); theClone->setFlags(m_alignment); return theClone; } // // OROLine // const int OROLine::Line = 2; OROLine::OROLine() : OROPrimitive(OROLine::Line) { } OROLine::~OROLine() { } void OROLine::setStartPoint(const QPointF & p) { setPosition(p); } void OROLine::setEndPoint(const QPointF & p) { m_endPoint = p; } void OROLine::setLineStyle(const KReportLineStyle& ls) { m_lineStyle = ls; } OROPrimitive* OROLine::clone() { OROLine *theClone = new OROLine(); theClone->setStartPoint(m_position); theClone->setEndPoint(m_endPoint); theClone->setLineStyle(m_lineStyle); return theClone; } // // OROImage // const int OROImage::Image = 3; OROImage::OROImage() : OROPrimitive(OROImage::Image) { m_scaled = false; m_transformFlags = Qt::FastTransformation; m_aspectFlags = Qt::IgnoreAspectRatio; } OROImage::~OROImage() { } void OROImage::setImage(const QImage & img) { m_image = img; } void OROImage::setScaled(bool b) { m_scaled = b; } void OROImage::setTransformationMode(int tm) { m_transformFlags = tm; } void OROImage::setAspectRatioMode(int arm) { m_aspectFlags = arm; } OROPrimitive* OROImage::clone() { OROImage *theClone = new OROImage(); theClone->setSize(m_size); theClone->setPosition(m_position); theClone->setImage(m_image); theClone->setScaled(m_scaled); theClone->setTransformationMode(m_transformFlags); theClone->setAspectRatioMode(m_aspectFlags); return theClone; } // // OROPicture // const int OROPicture::Picture = 6; OROPicture::OROPicture() : OROPrimitive(OROPicture::Picture) { } OROPicture::~OROPicture() { } OROPrimitive* OROPicture::clone() { OROPicture *theClone = new OROPicture(); theClone->setSize(m_size); theClone->setPosition(m_position); theClone->setPicture(m_picture); return theClone; } // // ORORect // const int ORORect::Rect = 4; ORORect::ORORect() : OROPrimitive(ORORect::Rect) { } ORORect::~ORORect() { } void ORORect::setRect(const QRectF & r) { setPosition(r.topLeft()); setSize(r.size()); } void ORORect::setPen(const QPen & p) { m_pen = p; } void ORORect::setBrush(const QBrush & b) { m_brush = b; } OROPrimitive* ORORect::clone() { ORORect *theClone = new ORORect(); theClone->setSize(m_size); theClone->setPosition(m_position); theClone->setPen(m_pen); theClone->setBrush(m_brush); return theClone; } // // OROEllipse // const int OROEllipse::Ellipse = 5; OROEllipse::OROEllipse() : OROPrimitive(OROEllipse::Ellipse) { } OROEllipse::~OROEllipse() { } void OROEllipse::setRect(const QRectF & r) { setPosition(r.topLeft()); setSize(r.size()); } void OROEllipse::setPen(const QPen & p) { m_pen = p; } void OROEllipse::setBrush(const QBrush & b) { m_brush = b; } OROPrimitive* OROEllipse::clone() { OROEllipse *theClone = new OROEllipse(); theClone->setSize(m_size); theClone->setPosition(m_position); theClone->setPen(m_pen); theClone->setBrush(m_brush); return theClone; } const int OROCheck::Check = 7; OROCheck::OROCheck() : OROPrimitive(OROCheck::Check) , m_value(false) { } OROCheck::~OROCheck() { } OROPrimitive* OROCheck::clone() { OROCheck *theClone = new OROCheck(); theClone->setSize(m_size); theClone->setPosition(m_position); theClone->setLineStyle(m_lineStyle); theClone->setForegroundColor(m_fgColor); theClone->setValue(m_value); return theClone; } diff --git a/src/common/KReportRenderObjects.h b/src/common/KReportRenderObjects.h index 2966219a..bed2b9e6 100644 --- a/src/common/KReportRenderObjects.h +++ b/src/common/KReportRenderObjects.h @@ -1,487 +1,487 @@ /* This file is part of the KDE project * Copyright (C) 2001-2007 by OpenMFG, LLC (info@openmfg.com) * Copyright (C) 2007-2008 by Adam Pigg (adam@piggz.co.uk) * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . */ #ifndef KREPORTRENDEROBJECTS_H #define KREPORTRENDEROBJECTS_H #include #include #include #include #include #include #include #include #include +#include -#include "KReportPageOptions.h" #include "KReportData.h" #include "KReportItemBase.h" #include "KReportSectionData.h" #include "KReportLineStyle.h" class ORODocument; class OROPage; class OROPrimitive; class OROTextBox; class OROLine; class OROImage; class OROSection; // // ORODocument // This object is a single document containing one or more OROPage elements // class KREPORT_EXPORT ORODocument : public QObject { Q_OBJECT friend class OROPage; friend class OROSection; public: explicit ORODocument(const QString & = QString()); ~ORODocument(); QString title() const { return m_title; }; void setTitle(const QString &); int pages() const { return m_pages.count(); }; OROPage* page(int); void addPage(OROPage*); int sections() const { return m_sections.count(); }; OROSection* section(int); void addSection(OROSection*); - void setPageOptions(const KReportPageOptions &); - KReportPageOptions pageOptions() const { - return m_pageOptions; + void setPageLayout(const QPageLayout &); + QPageLayout pageLayout() const { + return m_pageLayout; }; void notifyChange(int pageNo); protected: QString m_title; QList m_pages; QList m_sections; - KReportPageOptions m_pageOptions; + QPageLayout m_pageLayout; Q_SIGNALS: void updated(int pageNo); }; // // OROPage // This object is a single page in a document and may contain zero or more // OROPrimitive objects all of which represent some form of mark to made on // a page. // class KREPORT_EXPORT OROPage { friend class ORODocument; friend class OROPrimitive; public: explicit OROPage(ORODocument * = 0); ~OROPage(); ORODocument* document() const { return m_document; }; int page() const; // returns this pages current page number int primitives() const { return m_primitives.count(); }; OROPrimitive* primitive(int); void addPrimitive(OROPrimitive*, bool atBeginning = false, bool notify = false); protected: ORODocument * m_document; QList m_primitives; }; // // OROSection // This object is a single row in a document and may contain zero or more // OROPrimitives // class KREPORT_EXPORT OROSection { friend class ORODocument; friend class OROPrimitive; public: enum Sort { SortX = 1, SortY, SortZ }; explicit OROSection(ORODocument * = 0); ~OROSection(); void setHeight(int); int height(); void setBackgroundColor(const QColor&L); QColor backgroundColor(); ORODocument* document() const { return m_document; }; void setType(KReportSectionData::Section t) { m_type = t; } KReportSectionData::Section type() { return m_type; } int primitives() const { return m_primitives.count(); }; OROPrimitive* primitive(int); void addPrimitive(OROPrimitive*); void sortPrimatives(Sort); protected: ORODocument * m_document; QList m_primitives; long m_row; int m_height; KReportSectionData::Section m_type; QColor m_backgroundColor; private: static bool xLessThan(OROPrimitive* s1, OROPrimitive* s2); }; // // OROPrimitive // This object represents the basic primitive with a position and type. // Other primitives are subclasses with a defined type and any additional // information they require to define that primitive. // class KREPORT_EXPORT OROPrimitive { friend class OROPage; public: virtual ~OROPrimitive(); // Returns the type of the primitive which should be // set by the subclass int type() const { return m_type; }; OROPage * page() const { return m_page; }; QPointF position() const { return m_position; }; void setPosition(const QPointF &); QSizeF size() const { return m_size; } void setSize(const QSizeF &s); virtual OROPrimitive* clone() = 0; protected: OROPrimitive(int); OROPage * m_page; int m_type; QPointF m_position; QSizeF m_size; }; // // OROTextBox // This is a text box primitive it defines a box region and text that will // be rendered inside that region. It also contains information for font // and positioning of the text. // class KREPORT_EXPORT OROTextBox : public OROPrimitive { public: OROTextBox(); virtual ~OROTextBox(); QString text() const { return m_text; }; void setText(const QString &); KRTextStyleData textStyle() const { return m_textStyle; } void setTextStyle(const KRTextStyleData&); KReportLineStyle lineStyle() const { return m_lineStyle; } void setLineStyle(const KReportLineStyle&); void setFont(const QFont &); int flags() const { return m_flags; }; void setFlags(int); static const int TextBox; virtual OROPrimitive* clone(); bool requiresPostProcessing(){return m_requiresPostProcessing;} void setRequiresPostProcessing(bool pp = true){m_requiresPostProcessing = pp;} bool wordWrap() const {return m_wordWrap;} void setWordWrap(bool ww){m_wordWrap = ww;} bool canGrow() const {return m_canGrow;} void setCanGrow(bool cg){m_canGrow = cg;} protected: QString m_text; KRTextStyleData m_textStyle; KReportLineStyle m_lineStyle; Qt::Alignment m_alignment; int m_flags; // Qt::AlignmentFlag and Qt::TextFlag OR'd bool m_wordWrap; bool m_canGrow; bool m_requiresPostProcessing; }; // // OROLine // This primitive defines a line with a width/weight. // class KREPORT_EXPORT OROLine : public OROPrimitive { public: OROLine(); virtual ~OROLine(); QPointF startPoint() const { return position(); }; void setStartPoint(const QPointF &); QPointF endPoint() const { return m_endPoint; }; void setEndPoint(const QPointF &); KReportLineStyle lineStyle() const { return m_lineStyle; }; void setLineStyle(const KReportLineStyle&); static const int Line; virtual OROPrimitive* clone(); protected: QPointF m_endPoint; KReportLineStyle m_lineStyle; }; // // OROImage // This primitive defines an image // class KREPORT_EXPORT OROImage: public OROPrimitive { public: OROImage(); virtual ~OROImage(); QImage image() const { return m_image; }; void setImage(const QImage &); bool scaled() const { return m_scaled; }; void setScaled(bool); int transformationMode() const { return m_transformFlags; }; void setTransformationMode(int); int aspectRatioMode() const { return m_aspectFlags; }; void setAspectRatioMode(int); static const int Image; virtual OROPrimitive* clone(); protected: QImage m_image; bool m_scaled; int m_transformFlags; int m_aspectFlags; }; class KREPORT_EXPORT OROPicture: public OROPrimitive { public: OROPicture(); virtual ~OROPicture(); void setPicture(const QPicture& p) { m_picture = p; } QPicture* picture() { return &m_picture; }; static const int Picture; virtual OROPrimitive* clone(); protected: QPicture m_picture; }; // // ORORect // This primitive defines a drawn rectangle // class KREPORT_EXPORT ORORect: public OROPrimitive { public: ORORect(); virtual ~ORORect(); QRectF rect() const { return QRectF(m_position, m_size); }; void setRect(const QRectF &); QPen pen() const { return m_pen; }; void setPen(const QPen &); QBrush brush() const { return m_brush; }; void setBrush(const QBrush &); static const int Rect; virtual OROPrimitive* clone(); protected: QPen m_pen; QBrush m_brush; }; // // ORORect // This primitive defines a drawn rectangle // class KREPORT_EXPORT OROEllipse: public OROPrimitive { public: OROEllipse(); virtual ~OROEllipse(); QRectF rect() const { return QRectF(m_position, m_size); }; void setRect(const QRectF &); QPen pen() const { return m_pen; }; void setPen(const QPen &); QBrush brush() const { return m_brush; }; void setBrush(const QBrush &); static const int Ellipse; virtual OROPrimitive* clone(); protected: QSizeF m_size; QPen m_pen; QBrush m_brush; }; class KREPORT_EXPORT OROCheck : public OROPrimitive { public: OROCheck(); virtual ~OROCheck(); virtual OROPrimitive* clone(); static const int Check; void setCheckType(const QString& t) { if (t == QLatin1String("Cross") || t == QLatin1String("Tick") || t == QLatin1String("Dot")) { m_checkType = t; } else { m_checkType = QLatin1String("Cross"); } } QString checkType() const { return m_checkType; }; void setValue(bool v) { m_value = v; } bool value() const { return m_value; } void setLineStyle(const KReportLineStyle& ls) { m_lineStyle = ls; } KReportLineStyle lineStyle() const { return m_lineStyle; } void setForegroundColor(const QColor& fg) { m_fgColor = fg; } QColor foregroundColor() const { return m_fgColor; } protected: QSizeF m_size; QString m_checkType; bool m_value; KReportLineStyle m_lineStyle; QColor m_fgColor; }; #endif // __RENDEROBJECTS_H__ diff --git a/src/renderer/KReportPage.cpp b/src/renderer/KReportPage.cpp index e6aadc86..42f4782e 100644 --- a/src/renderer/KReportPage.cpp +++ b/src/renderer/KReportPage.cpp @@ -1,125 +1,131 @@ /* This file is part of the KDE project * Copyright (C) 2007-2008 by Adam Pigg (adam@piggz.co.uk) * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . */ #include "KReportPage.h" #include "KReportRendererBase.h" #include "KReportUnit.h" #include "KReportRenderObjects.h" +#include "KReportDpi.h" #include "kreport_debug.h" #include #include #include #include //! @internal class Q_DECL_HIDDEN KReportPage::Private { public: explicit Private(ORODocument *document) : reportDocument(document) , page(0) {} ~Private() { delete renderer; } ORODocument *reportDocument; int page; QPixmap pixmap; KReportRendererFactory factory; KReportRendererBase *renderer; QTimer renderTimer; }; KReportPage::KReportPage(QWidget *parent, ORODocument *document) : QObject(parent), QGraphicsRectItem() , d(new Private(document)) { Q_ASSERT(document); int pageWidth; int pageHeight; - QString pageSize = d->reportDocument->pageOptions().getPageSize(); + QString pageSize = d->reportDocument->pageLayout().pageSize().name(); + pageWidth = d->reportDocument->pageLayout().fullRectPixels(KReportDpi::dpiX()).width(); + pageHeight = d->reportDocument->pageLayout().fullRectPixels(KReportDpi::dpiX()).height(); + +//TODO remove after check +#if 0 if (pageSize == QLatin1String("Custom")) { // if this is custom sized sheet of paper we will just use those values - pageWidth = (int)(d->reportDocument->pageOptions().getCustomWidth()); - pageHeight = (int)(d->reportDocument->pageOptions().getCustomHeight()); + } else { // lookup the correct size information for the specified size paper pageWidth = d->reportDocument->pageOptions().pixelSize().width(); pageHeight = d->reportDocument->pageOptions().pixelSize().height(); } - +#endif + setRect(0, 0, pageWidth, pageHeight); //kreportDebug() << "PAGE IS " << pageWidth << "x" << pageHeight; d->pixmap = QPixmap(pageWidth, pageHeight); d->renderer = d->factory.createInstance(QLatin1String("screen")); connect(d->reportDocument, SIGNAL(updated(int)), this, SLOT(pageUpdated(int))); d->renderTimer.setSingleShot(true); connect(&d->renderTimer, SIGNAL(timeout()), this, SLOT(renderCurrentPage())); renderPage(1); } KReportPage::~KReportPage() { delete d; } void KReportPage::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) { Q_UNUSED(option); Q_UNUSED(widget); painter->drawPixmap(QPoint(0, 0), d->pixmap); } void KReportPage::renderPage(int page) { d->page = page - 1; d->pixmap.fill(); QPainter qp(&d->pixmap); if (d->reportDocument) { KReportRendererContext cxt; cxt.painter = &qp; d->renderer->render(cxt, d->reportDocument, d->page); } update(); } void KReportPage::pageUpdated(int pageNo) { //kreportDebug() << pageNo << d->page; //Refresh this page if it changes if (pageNo == d->page) { //kreportDebug() << "Current page updated"; d->renderTimer.start(100); } } void KReportPage::renderCurrentPage() { renderPage(d->page + 1); } diff --git a/src/renderer/KReportPreRenderer.cpp b/src/renderer/KReportPreRenderer.cpp index 3c74ab9e..6a23217e 100644 --- a/src/renderer/KReportPreRenderer.cpp +++ b/src/renderer/KReportPreRenderer.cpp @@ -1,700 +1,698 @@ /* This file is part of the KDE project * Copyright (C) 2001-2007 by OpenMFG, LLC (info@openmfg.com) * Copyright (C) 2007-2008 by Adam Pigg (adam@piggz.co.uk) * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . */ #include "KReportPreRenderer.h" #include "KReportPreRenderer_p.h" #include "KReportAsyncItemManager_p.h" #include "KReportOneRecordData_p.h" #include "KReportRenderObjects.h" #include "KReportData.h" #include "KReportItemBase.h" #include "KReportDocument.h" #include "KReportDetailSectionData.h" #include "KReportLabelSizeInfo.h" #include "KReportPageSize.h" #include "KReportDpi.h" #ifdef KREPORT_SCRIPTING #include "scripting/KReportScriptHandler.h" #include "scripting/KReportGroupTracker.h" #endif #include #include #include "kreport_debug.h" KReportPreRendererPrivate::KReportPreRendererPrivate(KReportPreRenderer *preRenderer) : m_preRenderer(preRenderer) { m_valid = false; m_document = 0; m_reportDocument = 0; m_page = 0; m_yOffset = 0.0; m_topMargin = m_bottomMargin = 0.0; m_leftMargin = m_rightMargin = 0.0; m_pageCounter = 0; m_maxHeight = m_maxWidth = 0.0; m_oneRecord = new KReportPrivate::OneRecordData(); m_kodata = 0; #ifdef KREPORT_SCRIPTING m_scriptHandler = 0; #endif asyncManager = new KReportPrivate::AsyncItemManager(this); connect(asyncManager, SIGNAL(finished()), this, SLOT(asyncItemsFinished())); } KReportPreRendererPrivate::~KReportPreRendererPrivate() { delete m_reportDocument; delete m_document; delete m_oneRecord; m_postProcText.clear(); } void KReportPreRendererPrivate::createNewPage() { //kreportDebug(); if (m_pageCounter > 0) finishCurPage(); m_pageCounter++; #ifdef KREPORT_SCRIPTING //Update the page count script value m_scriptHandler->setPageNumber(m_pageCounter); m_scriptHandler->newPage(); #endif m_page = new OROPage(0); m_document->addPage(m_page); //! @todo calculate past page bool lastPage = false; m_yOffset = m_topMargin; if (m_pageCounter == 1 && m_reportDocument->m_pageHeaderFirst) renderSection(*(m_reportDocument->m_pageHeaderFirst)); else if (lastPage == true && m_reportDocument->m_pageHeaderLast) renderSection(*(m_reportDocument->m_pageHeaderLast)); else if ((m_pageCounter % 2) == 1 && m_reportDocument->m_pageHeaderOdd) renderSection(*(m_reportDocument->m_pageHeaderOdd)); else if ((m_pageCounter % 2) == 0 && m_reportDocument->m_pageHeaderAny) renderSection(*(m_reportDocument->m_pageHeaderAny)); else if (m_reportDocument->m_pageHeaderAny) renderSection(*(m_reportDocument->m_pageHeaderAny)); } qreal KReportPreRendererPrivate::finishCurPageSize(bool lastPage) { qreal retval = 0.0; if (lastPage && m_reportDocument->m_pageFooterLast) retval = renderSectionSize(* (m_reportDocument->m_pageFooterLast)); else if (m_pageCounter == 1 && m_reportDocument->m_pageFooterFirst) retval = renderSectionSize(* (m_reportDocument->m_pageFooterFirst)); else if ((m_pageCounter % 2) == 1 && m_reportDocument->m_pageFooterOdd) retval = renderSectionSize(* (m_reportDocument->m_pageFooterOdd)); else if ((m_pageCounter % 2) == 0 && m_reportDocument->m_pageFooterEven) retval = renderSectionSize(* (m_reportDocument->m_pageFooterEven)); else if (m_reportDocument->m_pageFooterAny) retval = renderSectionSize(* (m_reportDocument->m_pageFooterAny)); //kreportDebug() << retval; return retval; } qreal KReportPreRendererPrivate::finishCurPage(bool lastPage) { qreal offset = m_maxHeight - m_bottomMargin; qreal retval = 0.0; //kreportDebug() << offset; if (lastPage && m_reportDocument->m_pageFooterLast) { //kreportDebug() << "Last Footer"; m_yOffset = offset - renderSectionSize(* (m_reportDocument->m_pageFooterLast)); retval = renderSection(* (m_reportDocument->m_pageFooterLast)); } else if (m_pageCounter == 1 && m_reportDocument->m_pageFooterFirst) { //kreportDebug() << "First Footer"; m_yOffset = offset - renderSectionSize(* (m_reportDocument->m_pageFooterFirst)); retval = renderSection(* (m_reportDocument->m_pageFooterFirst)); } else if ((m_pageCounter % 2) == 1 && m_reportDocument->m_pageFooterOdd) { //kreportDebug() << "Odd Footer"; m_yOffset = offset - renderSectionSize(* (m_reportDocument->m_pageFooterOdd)); retval = renderSection(* (m_reportDocument->m_pageFooterOdd)); } else if ((m_pageCounter % 2) == 0 && m_reportDocument->m_pageFooterEven) { //kreportDebug() << "Even Footer"; m_yOffset = offset - renderSectionSize(* (m_reportDocument->m_pageFooterEven)); retval = renderSection(* (m_reportDocument->m_pageFooterEven)); } else if (m_reportDocument->m_pageFooterAny) { //kreportDebug() << "Any Footer"; m_yOffset = offset - renderSectionSize(* (m_reportDocument->m_pageFooterAny)); retval = renderSection(* (m_reportDocument->m_pageFooterAny)); } return retval; } void KReportPreRendererPrivate::renderDetailSection(KReportDetailSectionData *detailData) { if (detailData->m_detailSection) { if (m_kodata/* && !curs->eof()*/) { QStringList keys; QStringList keyValues; QList shownGroups; KReportDetailGroupSectionData * grp = 0; bool status = m_kodata->moveFirst(); int recordCount = m_kodata->recordCount(); //kreportDebug() << "Record Count:" << recordCount; for (int i = 0; i < (int) detailData->m_groupList.count(); ++i) { grp = detailData->m_groupList[i]; //If the group has a header or footer, then emit a change of group value if(grp->m_groupFooter || grp->m_groupHeader) { // we get here only if group is *shown* shownGroups << i; keys.append(grp->m_column); if (!keys.last().isEmpty()) keyValues.append(m_kodata->value(m_kodata->fieldNumber(keys.last())).toString()); else keyValues.append(QString()); //Tell interested parties we're about to render a header emit(enteredGroup(keys.last(), keyValues.last())); } if (grp->m_groupHeader) renderSection(*(grp->m_groupHeader)); } while (status) { const qint64 pos = m_kodata->at(); //kreportDebug() << "At:" << l << "Y:" << m_yOffset << "Max Height:" << m_maxHeight; if ((renderSectionSize(*detailData->m_detailSection) + finishCurPageSize((pos + 1 == recordCount)) + m_bottomMargin + m_yOffset) >= m_maxHeight) { //kreportDebug() << "Next section is too big for this page"; if (pos > 0) { m_kodata->movePrevious(); createNewPage(); m_kodata->moveNext(); } } renderSection(*(detailData->m_detailSection)); if (m_kodata) status = m_kodata->moveNext(); if (status == true && keys.count() > 0) { // check to see where it is we need to start int pos = -1; // if it's still -1 by the time we are done then no keyValues changed for (int i = 0; i < keys.count(); ++i) { if (keyValues[i] != m_kodata->value(m_kodata->fieldNumber(keys[i])).toString()) { pos = i; break; } } // don't bother if nothing has changed if (pos != -1) { // roll back the query and go ahead if all is good status = m_kodata->movePrevious(); if (status == true) { // print the footers as needed // any changes made in this for loop need to be duplicated // below where the footers are finished. bool do_break = false; for (int i = shownGroups.count() - 1; i >= 0; i--) { if (do_break) createNewPage(); do_break = false; grp = detailData->m_groupList[shownGroups.at(i)]; if (grp->m_groupFooter) { if (renderSectionSize(*(grp->m_groupFooter)) + finishCurPageSize() + m_bottomMargin + m_yOffset >= m_maxHeight) createNewPage(); renderSection(*(grp->m_groupFooter)); } if (KReportDetailGroupSectionData::BreakAfterGroupFooter == grp->m_pagebreak) do_break = true; } // step ahead to where we should be and print the needed headers // if all is good status = m_kodata->moveNext(); if (do_break) createNewPage(); if (status == true) { for (int i = 0; i < shownGroups.count(); ++i) { grp = detailData->m_groupList[shownGroups.at(i)]; if (grp->m_groupHeader) { if (renderSectionSize(*(grp->m_groupHeader)) + finishCurPageSize() + m_bottomMargin + m_yOffset >= m_maxHeight) { m_kodata->movePrevious(); createNewPage(); m_kodata->moveNext(); } if (!keys[i].isEmpty()) keyValues[i] = m_kodata->value(m_kodata->fieldNumber(keys[i])).toString(); //Tell interested parties thak key values changed renderSection(*(grp->m_groupHeader)); } } } } } } } if (keys.size() > 0 && m_kodata->movePrevious()) { // finish footers // duplicated changes from above here for (int i = shownGroups.count() - 1; i >= 0; i--) { grp = detailData->m_groupList[shownGroups.at(i)]; if (grp->m_groupFooter) { if (renderSectionSize(*(grp->m_groupFooter)) + finishCurPageSize() + m_bottomMargin + m_yOffset >= m_maxHeight) createNewPage(); renderSection(*(grp->m_groupFooter)); emit(exitedGroup(keys[i], keyValues[i])); } } } } if (KReportDetailSectionData::BreakAtEnd == detailData->m_pageBreak) createNewPage(); } } qreal KReportPreRendererPrivate::renderSectionSize(const KReportSectionData & sectionData) { qreal intHeight = POINT_TO_INCH(sectionData.height()) * KReportDpi::dpiX(); int itemHeight = 0; if (sectionData.objects().count() == 0) return intHeight; QList objects = sectionData.objects(); foreach(KReportItemBase *ob, objects) { QPointF offset(m_leftMargin, m_yOffset); QVariant itemData = m_kodata->value(ob->itemDataSource()); //ASync objects cannot alter the section height KReportAsyncItemBase *async_ob = qobject_cast(ob); if (!async_ob) { itemHeight = ob->renderSimpleData(0, 0, offset, itemData, m_scriptHandler); if (itemHeight > intHeight) { intHeight = itemHeight; } } } return intHeight; } qreal KReportPreRendererPrivate::renderSection(const KReportSectionData & sectionData) { qreal sectionHeight = POINT_TO_INCH(sectionData.height()) * KReportDpi::dpiX(); int itemHeight = 0; //kreportDebug() << "Name: " << sectionData.name() << " Height: " << sectionHeight // << "Objects: " << sectionData.objects().count(); emit(renderingSection(const_cast(§ionData), m_page, QPointF(m_leftMargin, m_yOffset))); //Create a pre-rendered section for this section and add it to the document OROSection *sec = new OROSection(m_document); sec->setHeight(sectionData.height()); sec->setBackgroundColor(sectionData.backgroundColor()); sec->setType(sectionData.type()); m_document->addSection(sec); //Render section background ORORect* bg = new ORORect(); bg->setPen(QPen(Qt::NoPen)); bg->setBrush(sectionData.backgroundColor()); - qreal w = m_page->document()->pageOptions().pixelSize().width() - m_page->document()->pageOptions().getMarginRight() - m_leftMargin; + qreal w = m_page->document()->pageLayout().fullRectPixels(KReportDpi::dpiX()).width() - m_page->document()->pageLayout().marginsPixels(KReportDpi::dpiX()).right() - m_leftMargin; bg->setRect(QRectF(m_leftMargin, m_yOffset, w, sectionHeight)); m_page->addPrimitive(bg, true); QList objects = sectionData.objects(); foreach(KReportItemBase *ob, objects) { QPointF offset(m_leftMargin, m_yOffset); QVariant itemData = m_kodata->value(ob->itemDataSource()); if (ob->supportsSubQuery()) { itemHeight = ob->renderReportData(m_page, sec, offset, m_kodata, m_scriptHandler); } else { KReportAsyncItemBase *async_ob = qobject_cast(ob); if (async_ob){ //kreportDebug() << "async object"; asyncManager->addItem(async_ob, m_page, sec, offset, itemData, m_scriptHandler); } else { //kreportDebug() << "sync object"; itemHeight = ob->renderSimpleData(m_page, sec, offset, itemData, m_scriptHandler); } } if (itemHeight > sectionHeight) { sectionHeight = itemHeight; } } for (int i = 0; i < m_page->primitives(); ++i) { OROPrimitive *prim = m_page->primitive(i); if (prim->type() == OROTextBox::TextBox) { OROTextBox *text = static_cast(prim); if (text->requiresPostProcessing()) { m_postProcText.append(text); } } } m_yOffset += sectionHeight; return sectionHeight; } #ifdef KREPORT_SCRIPTING void KReportPreRendererPrivate::initEngine() { delete m_scriptHandler; m_scriptHandler = new KReportScriptHandler(m_kodata, m_reportDocument); connect(this, SIGNAL(enteredGroup(QString,QVariant)), m_scriptHandler, SLOT(slotEnteredGroup(QString,QVariant))); connect(this, SIGNAL(exitedGroup(QString,QVariant)), m_scriptHandler, SLOT(slotExitedGroup(QString,QVariant))); connect(this, SIGNAL(renderingSection(KReportSectionData*,OROPage*,QPointF)), m_scriptHandler, SLOT(slotEnteredSection(KReportSectionData*,OROPage*,QPointF))); } #endif void KReportPreRendererPrivate::asyncItemsFinished() { //kreportDebug() << "Finished rendering async items"; asyncManager->deleteLater(); emit finishedAllASyncItems(); } bool KReportPreRendererPrivate::generateDocument() { if (!m_kodata) { m_kodata = m_oneRecord; } if (!m_valid || !m_reportDocument) { return false; } // Do this check now so we don't have to undo a lot of work later if it fails KReportLabelSizeInfo label; - if (m_reportDocument->pageOptions().getPageSize() == QLatin1String("Labels")) { - label = KReportLabelSizeInfo::find(m_reportDocument->pageOptions().getLabelType()); + if (m_reportDocument->pageSize() == QLatin1String("Labels")) { + label = KReportLabelSizeInfo::find(m_reportDocument->labelType()); if (label.isNull()) { return false; } } - //kreportDebug() << "Creating Document"; m_document = new ORODocument(m_reportDocument->title()); m_pageCounter = 0; m_yOffset = 0.0; //kreportDebug() << "Calculating Margins"; if (!label.isNull()) { - if (m_reportDocument->pageOptions().isPortrait()) { + if (m_reportDocument->pageLayout().orientation() == QPageLayout::Portrait) { m_topMargin = (label.startY() / 100.0); m_bottomMargin = 0; m_rightMargin = 0; m_leftMargin = (label.startX() / 100.0); } else { m_topMargin = (label.startX() / 100.0); m_bottomMargin = 0; m_rightMargin = 0; m_leftMargin = (label.startY() / 100.0); } } else { - m_topMargin = m_reportDocument->pageOptions().getMarginTop(); - m_bottomMargin = m_reportDocument->pageOptions().getMarginBottom(); - m_rightMargin = m_reportDocument->pageOptions().getMarginRight(); - m_leftMargin = m_reportDocument->pageOptions().getMarginLeft(); + + m_topMargin = m_reportDocument->pageLayout().marginsPoints().top(); + m_bottomMargin = m_reportDocument->pageLayout().marginsPoints().bottom(); + m_rightMargin = m_reportDocument->pageLayout().marginsPoints().right(); + m_leftMargin = m_reportDocument->pageLayout().marginsPoints().left(); //kreportDebug() << "Margins:" << m_topMargin << m_bottomMargin << m_rightMargin << m_leftMargin; - } + } //kreportDebug() << "Calculating Page Size"; - KReportPageOptions rpo(m_reportDocument->pageOptions()); + QPageLayout layout = m_reportDocument->pageLayout(); // This should reflect the information of the report page size - if (m_reportDocument->pageOptions().getPageSize() == QLatin1String("Custom")) { - m_maxWidth = m_reportDocument->pageOptions().getCustomWidth(); - m_maxHeight = m_reportDocument->pageOptions().getCustomHeight(); + if (m_reportDocument->pageSize() == QLatin1String("Custom")) { + m_maxWidth = m_reportDocument->pageLayout().fullRectPoints().width(); + m_maxHeight = m_reportDocument->pageLayout().fullRectPoints().height(); } else { if (!label.isNull()) { m_maxWidth = label.width(); m_maxHeight = label.height(); - rpo.setPageSize(label.paper()); + m_reportDocument->pageLayout().setPageSize(QPageSize(KReportPageSize::pageSize(label.paper()))); } else { // lookup the correct size information for the specified size paper - QSizeF pageSizePx = m_reportDocument->pageOptions().pixelSize(); + QSizeF pageSizePx = m_reportDocument->pageLayout().fullRectPixels(KReportDpi::dpiX()).size(); m_maxWidth = pageSizePx.width(); m_maxHeight = pageSizePx.height(); } } - if (!m_reportDocument->pageOptions().isPortrait()) { + if (m_reportDocument->pageLayout().orientation() == QPageLayout::Landscape) { qreal tmp = m_maxWidth; m_maxWidth = m_maxHeight; m_maxHeight = tmp; } //kreportDebug() << "Page Size:" << m_maxWidth << m_maxHeight; - m_document->setPageOptions(rpo); + m_document->setPageLayout(m_reportDocument->pageLayout()); m_kodata->setSorting(m_reportDocument->m_detailSection->m_sortedFields); if (!m_kodata->open()) { return false; } #ifdef KREPORT_SCRIPTING initEngine(); connect(m_scriptHandler, SIGNAL(groupChanged(QMap)), m_preRenderer, SIGNAL(groupChanged(QMap))); //Loop through all abjects that have been registered, and register them with the script handler if (m_scriptHandler) { QMapIterator i(m_scriptObjects); while (i.hasNext()) { i.next(); m_scriptHandler->registerScriptObject(i.value(), i.key()); } //execute the script, if it fails, abort and return the empty document if (!m_scriptHandler->trigger()) { m_scriptHandler->displayErrors(); return m_document; } } #endif createNewPage(); if (!label.isNull()) { // Label Print Run // remember the initial margin setting as we will be modifying // the value and restoring it as we move around qreal margin = m_leftMargin; m_yOffset = m_topMargin; qreal w = (label.width() / 100.0); qreal wg = (label.xGap() / 100.0); qreal h = (label.height() / 100.0); qreal hg = (label.yGap() / 100.0); int numCols = label.columns(); int numRows = label.rows(); qreal tmp; // flip the value around if we are printing landscape - if (!m_reportDocument->pageOptions().isPortrait()) { + if (!m_reportDocument->pageLayout().orientation() == QPageLayout::Portrait) { w = (label.height() / 100.0); wg = (label.yGap() / 100.0); h = (label.width() / 100.0); hg = (label.xGap() / 100.0); numCols = label.rows(); numRows = label.columns(); } KReportDetailSectionData * detailData = m_reportDocument->m_detailSection; if (detailData->m_detailSection) { KReportData *mydata = m_kodata; if (mydata && mydata->recordCount() > 0) { /* && !((query = orqThis->getQuery())->eof()))*/ if (!mydata->moveFirst()) { return false; } int row = 0; int col = 0; do { tmp = m_yOffset; // store the value as renderSection changes it renderSection(*(detailData->m_detailSection)); m_yOffset = tmp; // restore the value that renderSection modified col++; m_leftMargin += w + wg; if (col >= numCols) { m_leftMargin = margin; // reset back to original value col = 0; row++; m_yOffset += h + hg; if (row >= numRows) { m_yOffset = m_topMargin; row = 0; createNewPage(); } } } while (mydata->moveNext()); } } } else { // Normal Print Run if (m_reportDocument->m_reportHeader) { renderSection(*(m_reportDocument->m_reportHeader)); } if (m_reportDocument->m_detailSection) { renderDetailSection(m_reportDocument->m_detailSection); } if (m_reportDocument->m_reportFooter) { if (renderSectionSize(*(m_reportDocument->m_reportFooter)) + finishCurPageSize(true) + m_bottomMargin + m_yOffset >= m_maxHeight) { createNewPage(); } renderSection(*(m_reportDocument->m_reportFooter)); } } finishCurPage(true); #ifdef KREPORT_SCRIPTING // _postProcText contains those text boxes that need to be updated // with information that wasn't available at the time it was added to the document m_scriptHandler->setPageTotal(m_document->pages()); for (int i = 0; i < m_postProcText.size(); i++) { OROTextBox * tb = m_postProcText.at(i); m_scriptHandler->setPageNumber(tb->page()->page() + 1); tb->setText(m_scriptHandler->evaluate(tb->text()).toString()); } #endif asyncManager->startRendering(); #ifdef KREPORT_SCRIPTING m_scriptHandler->displayErrors(); #endif if (!m_kodata->close()) { return false; } #ifdef KREPORT_SCRIPTING delete m_scriptHandler; m_scriptHandler = 0; #endif if (m_kodata != m_oneRecord) { delete m_kodata; m_kodata = 0; } m_postProcText.clear(); return true; } //===========================KReportPreRenderer=============================== -KReportPreRenderer::KReportPreRenderer(const QDomElement & document) - : d(new KReportPreRendererPrivate(this)) +KReportPreRenderer::KReportPreRenderer(const QDomElement &document) : d(new KReportPreRendererPrivate(this)) { setDocument(document); connect(d, &KReportPreRendererPrivate::finishedAllASyncItems, this, &KReportPreRenderer::finishedAllASyncItems); - } KReportPreRenderer::~KReportPreRenderer() { delete d; } void KReportPreRenderer::setName(const QString &n) { d->m_reportDocument->setName(n); } bool KReportPreRenderer::isValid() const { if (d && d->m_valid) return true; return false; } ORODocument* KReportPreRenderer::document() { return d->m_document; } bool KReportPreRenderer::generateDocument() { // delete d->m_document; if (!d->generateDocument()) { delete d->m_document; d->m_document = 0; } return d->m_document; } void KReportPreRenderer::setSourceData(KReportData *data) { if (d && data != d->m_kodata) { delete d->m_kodata; d->m_kodata = data; } } bool KReportPreRenderer::setDocument(const QDomElement &document) { delete d->m_document; d->m_valid = false; if (document.tagName() != QLatin1String("report:content")) { kreportWarning() << "report schema is invalid"; return false; } d->m_reportDocument = new KReportDocument(document); d->m_valid = d->m_reportDocument->isValid(); return isValid(); } #ifdef KREPORT_SCRIPTING void KReportPreRenderer::registerScriptObject(QObject* obj, const QString& name) { //kreportDebug() << name; d->m_scriptObjects[name] = obj; } KReportScriptHandler *KReportPreRenderer::scriptHandler() { return d->m_scriptHandler; } #endif const KReportDocument* KReportPreRenderer::reportData() const { return d->m_reportDocument; } diff --git a/src/renderer/KReportPrintRenderer_p.cpp b/src/renderer/KReportPrintRenderer_p.cpp index dc6b6d61..e1f33368 100644 --- a/src/renderer/KReportPrintRenderer_p.cpp +++ b/src/renderer/KReportPrintRenderer_p.cpp @@ -1,261 +1,261 @@ /* This file is part of the KDE project * Copyright (C) 2001-2007 by OpenMFG, LLC (info@openmfg.com) * Copyright (C) 2007-2008 by Adam Pigg (adam@piggz.co.uk) * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . */ #include "KReportPrintRenderer_p.h" #include "kreport_debug.h" #include "KReportRenderObjects.h" #include "KReportPageSize.h" #include "KReportDpi.h" #include #include #include namespace KReportPrivate { PrintRenderer::PrintRenderer() { } PrintRenderer::~PrintRenderer() { } bool PrintRenderer::setupPrinter( ORODocument * document, QPrinter * pPrinter) { if (document == 0 || pPrinter == 0) return false; pPrinter->setCreator(QLatin1String("KReport Print Renderer")); pPrinter->setDocName(document->title()); pPrinter->setFullPage(true); - pPrinter->setOrientation((document->pageOptions().isPortrait() ? QPrinter::Portrait : QPrinter::Landscape)); + pPrinter->setOrientation((document->pageLayout().orientation() == QPageLayout::Portrait ? QPrinter::Portrait : QPrinter::Landscape)); pPrinter->setPageOrder(QPrinter::FirstPageFirst); - if (document->pageOptions().getPageSize().isEmpty()) { + if (!document->pageLayout().pageSize().isValid()) { pPrinter->setPageSize(QPrinter::Custom); } else { - pPrinter->setPageSize(QPageSize(KReportPageSize::pageSize(document->pageOptions().getPageSize()))); + pPrinter->setPageSize(QPageSize(document->pageLayout().pageSize())); } return true; } bool PrintRenderer::render(const KReportRendererContext &context, ORODocument *document, int page) { Q_UNUSED(page); if (document == 0 || context.printer == 0 || context.painter == 0) return false; setupPrinter(document, context.printer); bool endWhenComplete = false; if (!context.painter->isActive()) { endWhenComplete = true; if (!context.painter->begin(context.printer)) return false; } int fromPage = context.printer->fromPage(); if (fromPage > 0) fromPage -= 1; int toPage = context.printer->toPage(); if (toPage == 0 || toPage > document->pages()) toPage = document->pages(); qreal scaleX = context.printer->resolution() / qreal(KReportDpi::dpiX()); qreal scaleY = context.printer->resolution() / qreal(KReportDpi::dpiY()); for (int copy = 0; copy < context.printer->numCopies(); copy++) { for (int page = fromPage; page < toPage; page++) { if (page > fromPage) context.printer->newPage(); OROPage * p = document->page(page); if (context.printer->pageOrder() == QPrinter::LastPageFirst) p = document->page(toPage - 1 - page); // Render Page Objects for (int i = 0; i < p->primitives(); i++) { OROPrimitive * prim = p->primitive(i); prim->setPosition(QPointF(prim->position().x() * scaleX, prim->position().y() * scaleY)); prim->setSize(QSizeF(prim->size().width() * scaleX, prim->size().height() * scaleY)); //kreportDebug() << "Rendering object" << i << "type" << prim->type(); if (prim->type() == OROTextBox::TextBox) { //kreportDebug() << "Text Box"; OROTextBox * tb = (OROTextBox*) prim; QPointF ps = tb->position(); QSizeF sz = tb->size(); QRectF rc = QRectF(ps.x(), ps.y(), sz.width(), sz.height()); context.painter->save(); //Background QColor bg = tb->textStyle().backgroundColor; bg.setAlphaF(0.01 * tb->textStyle().backgroundOpacity); //_painter->setBackgroundMode(Qt::OpaqueMode); context.painter->fillRect(rc, bg); //Text context.painter->setBackgroundMode(Qt::TransparentMode); context.painter->setFont(tb->textStyle().font); context.painter->setPen(tb->textStyle().foregroundColor); context.painter->drawText(rc, tb->flags(), tb->text()); //outer line context.painter->setPen(QPen(tb->lineStyle().color(), tb->lineStyle().width() * scaleX, tb->lineStyle().penStyle())); context.painter->drawRect(rc); //Reset back to defaults for next element context.painter->restore(); } else if (prim->type() == OROLine::Line) { //kreportDebug() << "Line"; OROLine * ln = (OROLine*) prim; QPointF s = ln->startPoint(); QPointF e(ln->endPoint().x() * scaleX, ln->endPoint().y() * scaleY); //QPen pen ( _painter->pen() ); QPen pen(ln->lineStyle().color(), ln->lineStyle().width() * scaleX, ln->lineStyle().penStyle()); context.painter->save(); context.painter->setRenderHint(QPainter::Antialiasing, true); context.painter->setPen(pen); context.painter->drawLine(QLineF(s.x(), s.y(), e.x(), e.y())); context.painter->setRenderHint(QPainter::Antialiasing, false); context.painter->restore(); } else if (prim->type() == OROImage::Image) { //kreportDebug() << "Image"; OROImage * im = (OROImage*) prim; QPointF ps = im->position(); QSizeF sz = im->size(); QRectF rc = QRectF(ps.x(), ps.y(), sz.width(), sz.height()); QImage img = im->image(); if (im->scaled()) img = img.scaled(rc.size().toSize(), (Qt::AspectRatioMode) im->aspectRatioMode(), (Qt::TransformationMode) im->transformationMode()); QRectF sr = QRectF(QPointF(0.0, 0.0), rc.size().boundedTo(img.size())); context.painter->drawImage(rc.topLeft(), img, sr); } else if (prim->type() == ORORect::Rect) { //kreportDebug() << "Rect"; ORORect * re = (ORORect*) prim; QPointF ps = re->position(); QSizeF sz = re->size(); QRectF rc = QRectF(ps.x(), ps.y(), sz.width(), sz.height()); context.painter->save(); context.painter->setPen(re->pen()); context.painter->setBrush(re->brush()); context.painter->drawRect(rc); context.painter->restore(); } else if (prim->type() == OROEllipse::Ellipse) { OROEllipse * re = (OROEllipse*) prim; QPointF ps = re->position(); QSizeF sz = re->size(); QRectF rc = QRectF(ps.x(), ps.y(), sz.width(), sz.height()); context.painter->save(); context.painter->setPen(re->pen()); context.painter->setBrush(re->brush()); context.painter->drawEllipse(rc); context.painter->restore(); } else if (prim->type() == OROPicture::Picture) { OROPicture * im = (OROPicture*) prim; QPointF ps = im->position(); QSizeF sz = im->size(); QRectF rc = QRectF(ps.x(), ps.y(), sz.width(), sz.height()); context.painter->drawPicture(rc.topLeft(), *(im->picture())); } else if (prim->type() == OROCheck::Check) { OROCheck * chk = (OROCheck*) prim; QPointF ps = chk->position(); QSizeF sz = chk->size(); QRectF rc = QRectF(ps.x(), ps.y(), sz.width(), sz.height()); context.painter->save(); context.painter->setBackgroundMode(Qt::OpaqueMode); context.painter->setRenderHint(QPainter::Antialiasing); context.painter->setPen(chk->foregroundColor()); if (chk->lineStyle().penStyle() == Qt::NoPen || chk->lineStyle().width() <= 0) { context.painter->setPen(QPen(Qt::lightGray)); } else { context.painter->setPen(QPen(chk->lineStyle().color(), chk->lineStyle().width() * scaleX, chk->lineStyle().penStyle())); } qreal ox = sz.width() / 5; qreal oy = sz.height() / 5; //Checkbox Style if (chk->checkType() == QLatin1String("Cross")) { context.painter->drawRoundedRect(rc, sz.width() / 10 , sz.height() / 10); if (chk->value()) { QPen lp; lp.setColor(chk->foregroundColor()); lp.setWidth(ox > oy ? oy : ox); context.painter->setPen(lp); context.painter->drawLine(QPointF(ox, oy) + ps, QPointF(sz.width() - ox, sz.height() - oy) + ps); context.painter->drawLine(QPointF(ox, sz.height() - oy) + ps, QPoint(sz.width() - ox, oy) + ps); } } else if (chk->checkType() == QLatin1String("Dot")) { //Radio Style context.painter->drawEllipse(rc); if (chk->value()) { QBrush lb(chk->foregroundColor()); context.painter->setBrush(lb); context.painter->setPen(Qt::NoPen); context.painter->drawEllipse(rc.center(), sz.width() / 2 - ox, sz.height() / 2 - oy); } } else { //Tickbox Style context.painter->drawRoundedRect(rc, sz.width() / 10 , sz.height() / 10); if (chk->value()) { QPen lp; lp.setColor(chk->foregroundColor()); lp.setWidth(ox > oy ? oy : ox); context.painter->setPen(lp); context.painter->drawLine(QPointF(ox, sz.height() / 2) + ps, QPointF(sz.width() / 2, sz.height() - oy) + ps); context.painter->drawLine(QPointF(sz.width() / 2, sz.height() - oy) + ps, QPointF(sz.width() - ox, oy) + ps); } } context.painter->restore(); } } } } if (endWhenComplete) context.painter->end(); return true; } } diff --git a/src/wrtembed/KReportDesigner.cpp b/src/wrtembed/KReportDesigner.cpp index 5885e8a3..84d8cf3c 100644 --- a/src/wrtembed/KReportDesigner.cpp +++ b/src/wrtembed/KReportDesigner.cpp @@ -1,1553 +1,1553 @@ /* This file is part of the KDE project * Copyright (C) 2001-2007 by OpenMFG, LLC * Copyright (C) 2007-2010 by Adam Pigg * Copyright (C) 2011 Jarosław Staniek * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . */ #include "KReportDesigner.h" #include "KReportDesignerSection.h" #include "KReportDesignerSectionScene.h" #include "KReportDesignerSectionView.h" #include "KReportDesignerSectionDetailGroup.h" #include "KReportPropertiesButton.h" #include "KReportSectionEditor.h" #include "KReportDesignerSectionDetail.h" #include "KReportDesignerItemLine.h" #include "KReportRuler_p.h" #include "KReportZoomHandler.h" #include "KReportPageSize.h" #include "KReportDpi.h" #include "KReportUtils.h" #include "KReportPluginInterface.h" #include "KReportPluginManager.h" #include "KReportSection.h" #include "KReportPluginMetaData.h" #include "kreport_debug.h" #include #include #include #include #include #include #include #include #include #include #include #include #include //! Also add public method for runtime? const char ns[] = "http://kexi-project.org/report/2.0"; static QDomElement propertyToElement(QDomDocument* d, KProperty* p) { QDomElement e = d->createElement(QLatin1String("report:" + p->name().toLower())); e.appendChild(d->createTextNode(p->value().toString())); return e; } // // define and implement the ReportWriterSectionData class // a simple class to hold/hide data in the ReportHandler class // class ReportWriterSectionData { public: ReportWriterSectionData() { selected_x_offset = 0; selected_y_offset = 0; mouseAction = ReportWriterSectionData::MA_None; } virtual ~ReportWriterSectionData() { } enum MouseAction { MA_None = 0, MA_Insert = 1, MA_Grab = 2, MA_MoveStartPoint, MA_MoveEndPoint, MA_ResizeNW = 8, MA_ResizeN, MA_ResizeNE, MA_ResizeE, MA_ResizeSE, MA_ResizeS, MA_ResizeSW, MA_ResizeW }; int selected_x_offset; int selected_y_offset; MouseAction mouseAction; QString insertItem; QList copy_list; QList cut_list; }; //! @internal class Q_DECL_HIDDEN KReportDesigner::Private { public: Private() : activeScene(0) , reportHeader(0) , pageHeaderFirst(0) , pageHeaderOdd(0) , pageHeaderEven(0) , pageHeaderLast(0) , pageHeaderAny(0) , pageFooterFirst(0) , pageFooterOdd(0) , pageFooterEven(0) , pageFooterLast(0) , pageFooterAny(0) , reportFooter(0) , detail(0) , pressX(-1) , pressY(-1) , releaseX(-1) , releaseY(-1) , modified(false) , kordata(0) {} ~Private() { delete zoom; delete sectionData; delete set; delete kordata; } QGridLayout *grid; KReportRuler *hruler; KReportZoomHandler *zoom; QVBoxLayout *vboxlayout; KReportPropertiesButton *pageButton; QGraphicsScene *activeScene; ReportWriterSectionData *sectionData; KReportDesignerSection *reportHeader; KReportDesignerSection *pageHeaderFirst; KReportDesignerSection *pageHeaderOdd; KReportDesignerSection *pageHeaderEven; KReportDesignerSection *pageHeaderLast; KReportDesignerSection *pageHeaderAny; KReportDesignerSection *pageFooterFirst; KReportDesignerSection *pageFooterOdd; KReportDesignerSection *pageFooterEven; KReportDesignerSection *pageFooterLast; KReportDesignerSection *pageFooterAny; KReportDesignerSection *reportFooter; KReportDesignerSectionDetail *detail; //Properties KPropertySet *set; KPropertySet *itmset; KProperty *title; KProperty *pageSize; KProperty *orientation; KProperty *unit; KProperty *customHeight; KProperty *customWidth; KProperty *leftMargin; KProperty *rightMargin; KProperty *topMargin; KProperty *bottomMargin; KProperty *showGrid; KProperty *gridDivisions; KProperty *gridSnap; KProperty *labelType; #ifdef KREPORT_SCRIPTING KProperty *script; #endif //Actions QAction *editCutAction; QAction *editCopyAction; QAction *editPasteAction; QAction *editDeleteAction; QAction *sectionEdit; QAction *parameterEdit; QAction *itemRaiseAction; QAction *itemLowerAction; qreal pressX; qreal pressY; qreal releaseX; qreal releaseY; bool modified; // true if this document has been modified, false otherwise QString originalInterpreter; //Value of the script interpreter at load time QString originalScript; //Value of the script at load time KReportData *kordata; }; KReportDesigner::KReportDesigner(QWidget * parent) : QWidget(parent), d(new Private()) { init(); } void KReportDesigner::init() { KReportPluginManager::self(); // this loads icons early enough d->sectionData = new ReportWriterSectionData(); createProperties(); createActions(); d->grid = new QGridLayout(this); d->grid->setSpacing(0); d->grid->setMargin(0); d->grid->setColumnStretch(1, 1); d->grid->setRowStretch(1, 1); d->grid->setSizeConstraint(QLayout::SetFixedSize); d->vboxlayout = new QVBoxLayout(); d->vboxlayout->setSpacing(0); d->vboxlayout->setMargin(0); d->vboxlayout->setSizeConstraint(QLayout::SetFixedSize); //Create nice rulers d->zoom = new KReportZoomHandler(); d->hruler = new KReportRuler(this, Qt::Horizontal, d->zoom); d->pageButton = new KReportPropertiesButton(this); d->hruler->setUnit(KReportUnit(KReportUnit::Centimeter)); d->grid->addWidget(d->pageButton, 0, 0); d->grid->addWidget(d->hruler, 0, 1); d->grid->addLayout(d->vboxlayout, 1, 0, 1, 2); d->pageButton->setMaximumSize(QSize(19, 22)); d->pageButton->setMinimumSize(QSize(19, 22)); d->detail = new KReportDesignerSectionDetail(this); d->vboxlayout->insertWidget(0, d->detail); setLayout(d->grid); connect(d->pageButton, SIGNAL(released()), this, SLOT(slotPageButton_Pressed())); emit pagePropertyChanged(*d->set); connect(d->set, SIGNAL(propertyChanged(KPropertySet&,KProperty&)), this, SLOT(slotPropertyChanged(KPropertySet&,KProperty&))); changeSet(d->set); } KReportDesigner::~KReportDesigner() { delete d; } ///The loading Code KReportDesigner::KReportDesigner(QWidget *parent, const QDomElement &data) : QWidget(parent), d(new Private()) { init(); if (data.tagName() != QLatin1String("report:content")) { // arg we got an xml file but not one i know of kreportWarning() << "root element was not "; } //kreportDebug() << data.text(); deleteDetail(); QDomNodeList nlist = data.childNodes(); QDomNode it; for (int i = 0; i < nlist.count(); ++i) { it = nlist.item(i); // at this level all the children we get should be Elements if (it.isElement()) { QString n = it.nodeName().toLower(); //kreportDebug() << n; if (n == QLatin1String("report:title")) { setReportTitle(it.firstChild().nodeValue()); #ifdef KREPORT_SCRIPTING } else if (n == QLatin1String("report:script")) { d->originalInterpreter = it.toElement().attribute(QLatin1String("report:script-interpreter")); d->originalScript = it.firstChild().nodeValue(); d->script->setValue(d->originalScript); if (d->originalInterpreter != QLatin1String("javascript") && d->originalInterpreter != QLatin1String("qtscript")) { QString msg = tr("This report contains scripts of type \"%1\". " "Only scripts written in JavaScript language are " "supported. To prevent losing the scripts, their type " "and content will not be changed unless you change these scripts." ).arg(d->originalInterpreter); QMessageBox::warning(this, tr("Unsupported Script Type"), msg); } #endif } else if (n == QLatin1String("report:grid")) { d->showGrid->setValue(it.toElement().attribute(QLatin1String("report:grid-visible"), QString::number(1)).toInt() != 0); d->gridSnap->setValue(it.toElement().attribute(QLatin1String("report:grid-snap"), QString::number(1)).toInt() != 0); d->gridDivisions->setValue(it.toElement().attribute(QLatin1String("report:grid-divisions"), QString::number(4)).toInt()); d->unit->setValue(it.toElement().attribute(QLatin1String("report:page-unit"), QLatin1String("cm"))); } //! @todo Load page options else if (n == QLatin1String("report:page-style")) { QString pagetype = it.firstChild().nodeValue(); if (pagetype == QLatin1String("predefined")) { d->pageSize->setValue(it.toElement().attribute(QLatin1String("report:page-size"), QLatin1String("A4"))); } else if (pagetype == QLatin1String("custom")) { d->pageSize->setValue(QLatin1String("custom")); d->customHeight->setValue(KReportUnit::parseValue(it.toElement().attribute(QLatin1String("report:custom-page-height"), QLatin1String("")))); d->customWidth->setValue(KReportUnit::parseValue(it.toElement().attribute(QLatin1String("report:custom-page-widtht"), QLatin1String("")))); } else if (pagetype == QLatin1String("label")) { //! @todo } d->rightMargin->setValue(KReportUnit::parseValue(it.toElement().attribute(QLatin1String("fo:margin-right"), QLatin1String("1.0cm")))); d->leftMargin->setValue(KReportUnit::parseValue(it.toElement().attribute(QLatin1String("fo:margin-left"), QLatin1String("1.0cm")))); d->topMargin->setValue(KReportUnit::parseValue(it.toElement().attribute(QLatin1String("fo:margin-top"), QLatin1String("1.0cm")))); d->bottomMargin->setValue(KReportUnit::parseValue(it.toElement().attribute(QLatin1String("fo:margin-bottom"), QLatin1String("1.0cm")))); d->orientation->setValue(it.toElement().attribute(QLatin1String("report:print-orientation"), QLatin1String("portrait"))); } else if (n == QLatin1String("report:body")) { QDomNodeList sectionlist = it.childNodes(); QDomNode sec; for (int s = 0; s < sectionlist.count(); ++s) { sec = sectionlist.item(s); if (sec.isElement()) { QString sn = sec.nodeName().toLower(); //kreportDebug() << sn; if (sn == QLatin1String("report:section")) { QString sectiontype = sec.toElement().attribute(QLatin1String("report:section-type")); if (section(KReportSectionData::sectionTypeFromString(sectiontype)) == 0) { insertSection(KReportSectionData::sectionTypeFromString(sectiontype)); section(KReportSectionData::sectionTypeFromString(sectiontype))->initFromXML(sec); } } else if (sn == QLatin1String("report:detail")) { KReportDesignerSectionDetail * rsd = new KReportDesignerSectionDetail(this); rsd->initFromXML(&sec); setDetail(rsd); } } else { kreportWarning() << "Encountered an unknown Element: " << n; } } } } else { kreportWarning() << "Encountered a child node of root that is not an Element"; } } this->slotPageButton_Pressed(); emit reportDataChanged(); slotPropertyChanged(*d->set, *d->unit); // set unit for all items setModified(false); } ///The saving code QDomElement KReportDesigner::document() const { QDomDocument doc; QString saveInterpreter; QDomElement content = doc.createElement(QLatin1String("report:content")); content.setAttribute(QLatin1String("xmlns:report"), QLatin1String(ns)); content.setAttribute(QLatin1String("xmlns:fo"), QLatin1String("urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0")); content.setAttribute(QLatin1String("xmlns:svg"), QLatin1String("urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0")); doc.appendChild(content); //title content.appendChild(propertyToElement(&doc, d->title)); #ifdef KREPORT_SCRIPTING if (!d->script->value().toString().isEmpty()) { if (d->script->value().toString() != d->originalScript || d->originalInterpreter == QLatin1String("qtscript")) { //The script has changed so force interpreter to 'javascript'. Also set if was using qtscript saveInterpreter = QLatin1String("javascript"); } else { saveInterpreter = d->originalInterpreter; } QDomElement scr = propertyToElement(&doc, d->script); scr.setAttribute(QLatin1String("report:script-interpreter"), saveInterpreter); content.appendChild(scr); } #endif QDomElement grd = doc.createElement(QLatin1String("report:grid")); KReportUtils::addPropertyAsAttribute(&grd, d->showGrid); KReportUtils::addPropertyAsAttribute(&grd, d->gridDivisions); KReportUtils::addPropertyAsAttribute(&grd, d->gridSnap); KReportUtils::addPropertyAsAttribute(&grd, d->unit); content.appendChild(grd); // pageOptions // -- size QDomElement pagestyle = doc.createElement(QLatin1String("report:page-style")); if (d->pageSize->value().toString() == QLatin1String("Custom")) { pagestyle.appendChild(doc.createTextNode(QLatin1String("custom"))); KReportUtils::setAttribute(&pagestyle, QLatin1String("report:custom-page-width"), d->customWidth->value().toDouble()); KReportUtils::setAttribute(&pagestyle, QLatin1String("report:custom-page-height"), d->customHeight->value().toDouble()); } else if (d->pageSize->value().toString() == QLatin1String("Label")) { pagestyle.appendChild(doc.createTextNode(QLatin1String("label"))); pagestyle.setAttribute(QLatin1String("report:page-label-type"), d->labelType->value().toString()); } else { pagestyle.appendChild(doc.createTextNode(QLatin1String("predefined"))); KReportUtils::addPropertyAsAttribute(&pagestyle, d->pageSize); //pagestyle.setAttribute("report:page-size", d->pageSize->value().toString()); } // -- orientation KReportUtils::addPropertyAsAttribute(&pagestyle, d->orientation); // -- margins: save as points, and not localized KReportUtils::setAttribute(&pagestyle, QLatin1String("fo:margin-top"), d->topMargin->value().toDouble()); KReportUtils::setAttribute(&pagestyle, QLatin1String("fo:margin-bottom"), d->bottomMargin->value().toDouble()); KReportUtils::setAttribute(&pagestyle, QLatin1String("fo:margin-right"), d->rightMargin->value().toDouble()); KReportUtils::setAttribute(&pagestyle, QLatin1String("fo:margin-left"), d->leftMargin->value().toDouble()); content.appendChild(pagestyle); QDomElement body = doc.createElement(QLatin1String("report:body")); QDomElement domsection; for (int i = KReportSectionData::PageHeaderFirst; i <= KReportSectionData::PageFooterAny; ++i) { KReportDesignerSection *sec = section((KReportSectionData::Section)i); if (sec) { domsection = doc.createElement(QLatin1String("report:section")); domsection.setAttribute(QLatin1String("report:section-type"), KReportSectionData::sectionTypeString(KReportSectionData::Section(i))); sec->buildXML(&doc, &domsection); body.appendChild(domsection); } } QDomElement detail = doc.createElement(QLatin1String("report:detail")); d->detail->buildXML(&doc, &detail); body.appendChild(detail); content.appendChild(body); return content; } void KReportDesigner::slotSectionEditor() { KReportSectionEditor se(this); (void)se.exec(); } void KReportDesigner::setReportData(KReportData* kodata) { if (d->kordata == kodata) { return; } delete d->kordata; d->kordata = kodata; slotPageButton_Pressed(); setModified(true); emit reportDataChanged(); } KReportDesignerSection * KReportDesigner::section(KReportSectionData::Section s) const { KReportDesignerSection *sec; switch (s) { case KReportSectionData::PageHeaderAny: sec = d->pageHeaderAny; break; case KReportSectionData::PageHeaderEven: sec = d->pageHeaderEven; break; case KReportSectionData::PageHeaderOdd: sec = d->pageHeaderOdd; break; case KReportSectionData::PageHeaderFirst: sec = d->pageHeaderFirst; break; case KReportSectionData::PageHeaderLast: sec = d->pageHeaderLast; break; case KReportSectionData::PageFooterAny: sec = d->pageFooterAny; break; case KReportSectionData::PageFooterEven: sec = d->pageFooterEven; break; case KReportSectionData::PageFooterOdd: sec = d->pageFooterOdd; break; case KReportSectionData::PageFooterFirst: sec = d->pageFooterFirst; break; case KReportSectionData::PageFooterLast: sec = d->pageFooterLast; break; case KReportSectionData::ReportHeader: sec = d->reportHeader; break; case KReportSectionData::ReportFooter: sec = d->reportFooter; break; default: sec = 0; } return sec; } void KReportDesigner::removeSection(KReportSectionData::Section s) { KReportDesignerSection* sec = section(s); if (sec) { delete sec; switch (s) { case KReportSectionData::PageHeaderAny: d->pageHeaderAny = 0; break; case KReportSectionData::PageHeaderEven: sec = d->pageHeaderEven = 0; break; case KReportSectionData::PageHeaderOdd: d->pageHeaderOdd = 0; break; case KReportSectionData::PageHeaderFirst: d->pageHeaderFirst = 0; break; case KReportSectionData::PageHeaderLast: d->pageHeaderLast = 0; break; case KReportSectionData::PageFooterAny: d->pageFooterAny = 0; break; case KReportSectionData::PageFooterEven: d->pageFooterEven = 0; break; case KReportSectionData::PageFooterOdd: d->pageFooterOdd = 0; break; case KReportSectionData::PageFooterFirst: d->pageFooterFirst = 0; break; case KReportSectionData::PageFooterLast: d->pageFooterLast = 0; break; case KReportSectionData::ReportHeader: d->reportHeader = 0; break; case KReportSectionData::ReportFooter: d->reportFooter = 0; break; default: sec = 0; } setModified(true); adjustSize(); } } void KReportDesigner::insertSection(KReportSectionData::Section s) { KReportDesignerSection* sec = section(s); if (!sec) { int idx = 0; for (int i = 1; i <= s; ++i) { if (section((KReportSectionData::Section)i)) idx++; } if (s > KReportSectionData::ReportHeader) idx++; //kreportDebug() << idx; KReportDesignerSection *rs = new KReportDesignerSection(this); d->vboxlayout->insertWidget(idx, rs); switch (s) { case KReportSectionData::PageHeaderAny: rs->setTitle(tr("Page Header (Any)")); d->pageHeaderAny = rs; break; case KReportSectionData::PageHeaderEven: rs->setTitle(tr("Page Header (Even)")); d->pageHeaderEven = rs; break; case KReportSectionData::PageHeaderOdd: rs->setTitle(tr("Page Header (Odd)")); d->pageHeaderOdd = rs; break; case KReportSectionData::PageHeaderFirst: rs->setTitle(tr("Page Header (First)")); d->pageHeaderFirst = rs; break; case KReportSectionData::PageHeaderLast: rs->setTitle(tr("Page Header (Last)")); d->pageHeaderLast = rs; break; case KReportSectionData::PageFooterAny: rs->setTitle(tr("Page Footer (Any)")); d->pageFooterAny = rs; break; case KReportSectionData::PageFooterEven: rs->setTitle(tr("Page Footer (Even)")); d->pageFooterEven = rs; break; case KReportSectionData::PageFooterOdd: rs->setTitle(tr("Page Footer (Odd)")); d->pageFooterOdd = rs; break; case KReportSectionData::PageFooterFirst: rs->setTitle(tr("Page Footer (First)")); d->pageFooterFirst = rs; break; case KReportSectionData::PageFooterLast: rs->setTitle(tr("Page Footer (Last)")); d->pageFooterLast = rs; break; case KReportSectionData::ReportHeader: rs->setTitle(tr("Report Header")); d->reportHeader = rs; break; case KReportSectionData::ReportFooter: rs->setTitle(tr("Report Footer")); d->reportFooter = rs; break; //These sections cannot be inserted this way case KReportSectionData::None: case KReportSectionData::GroupHeader: case KReportSectionData::GroupFooter: case KReportSectionData::Detail: break; } rs->show(); setModified(true); adjustSize(); emit pagePropertyChanged(*d->set); } } void KReportDesigner::setReportTitle(const QString & str) { if (reportTitle() != str) { d->title->setValue(str); setModified(true); } } KPropertySet * KReportDesigner::propertySet() const { return d->set; } KPropertySet* KReportDesigner::itemPropertySet() const { return d->itmset; } KReportData *KReportDesigner::reportData() const { return d->kordata; } KReportDesignerSectionDetail * KReportDesigner::detailSection() const { return d->detail; } QString KReportDesigner::reportTitle() const { return d->title->value().toString(); } bool KReportDesigner::isModified() const { return d->modified; } void KReportDesigner::setModified(bool mod) { d->modified = mod; if (d->modified) { emit dirty(); } } QStringList KReportDesigner::fieldNames() const { QStringList qs; qs << QString(); if (d->kordata) qs << d->kordata->fieldNames(); return qs; } QStringList KReportDesigner::fieldKeys() const { QStringList qs; qs << QString(); if (d->kordata) qs << d->kordata->fieldKeys(); return qs; } void KReportDesigner::createProperties() { QStringList keys, strings; d->set = new KPropertySet; KReportDesigner::addMetaProperties(d->set, tr("Report", "Main report element"), QLatin1String("kreport-report-element")); connect(d->set, SIGNAL(propertyChanged(KPropertySet&,KProperty&)), this, SLOT(slotPropertyChanged(KPropertySet&,KProperty&))); d->title = new KProperty("title", QLatin1String("Report"), tr("Title"), tr("Report Title")); keys.clear(); keys = KReportPageSize::pageFormatKeys(); strings = KReportPageSize::pageFormatNames(); QString defaultKey = KReportPageSize::pageSizeKey(KReportPageSize::defaultSize()); d->pageSize = new KProperty("page-size", keys, strings, defaultKey, tr("Page Size")); keys.clear(); strings.clear(); keys << QLatin1String("portrait") << QLatin1String("landscape"); strings << tr("Portrait") << tr("Landscape"); d->orientation = new KProperty("print-orientation", keys, strings, QLatin1String("portrait"), tr("Page Orientation")); keys.clear(); strings.clear(); strings = KReportUnit::listOfUnitNameForUi(KReportUnit::HidePixel); QString unit; foreach(const QString &un, strings) { unit = un.mid(un.indexOf(QLatin1String("(")) + 1, 2); keys << unit; } d->unit = new KProperty("page-unit", keys, strings, QLatin1String("cm"), tr("Page Unit")); d->showGrid = new KProperty("grid-visible", true, tr("Show Grid")); d->gridSnap = new KProperty("grid-snap", true, tr("Snap to Grid")); d->gridDivisions = new KProperty("grid-divisions", 4, tr("Grid Divisions")); d->leftMargin = new KProperty("margin-left", KReportUnit(KReportUnit::Centimeter).fromUserValue(1.0), tr("Left Margin"), tr("Left Margin"), KProperty::Double); d->rightMargin = new KProperty("margin-right", KReportUnit(KReportUnit::Centimeter).fromUserValue(1.0), tr("Right Margin"), tr("Right Margin"), KProperty::Double); d->topMargin = new KProperty("margin-top", KReportUnit(KReportUnit::Centimeter).fromUserValue(1.0), tr("Top Margin"), tr("Top Margin"), KProperty::Double); d->bottomMargin = new KProperty("margin-bottom", KReportUnit(KReportUnit::Centimeter).fromUserValue(1.0), tr("Bottom Margin"), tr("Bottom Margin"), KProperty::Double); d->leftMargin->setOption("unit", QLatin1String("cm")); d->rightMargin->setOption("unit", QLatin1String("cm")); d->topMargin->setOption("unit", QLatin1String("cm")); d->bottomMargin->setOption("unit", QLatin1String("cm")); d->set->addProperty(d->title); d->set->addProperty(d->pageSize); d->set->addProperty(d->orientation); d->set->addProperty(d->unit); d->set->addProperty(d->gridSnap); d->set->addProperty(d->showGrid); d->set->addProperty(d->gridDivisions); d->set->addProperty(d->leftMargin); d->set->addProperty(d->rightMargin); d->set->addProperty(d->topMargin); d->set->addProperty(d->bottomMargin); #ifdef KREPORT_SCRIPTING d->script = new KProperty("script", QStringList(), QStringList(), QString(), tr("Object Script")); d->set->addProperty(d->script); #endif // KProperty* _customHeight; // KProperty* _customWidth; } /** @brief Handle property changes */ void KReportDesigner::slotPropertyChanged(KPropertySet &s, KProperty &p) { setModified(true); emit pagePropertyChanged(s); if (p.name() == "page-unit") { d->hruler->setUnit(pageUnit()); QString newstr = d->set->property("page-unit").value().toString(); d->set->property("margin-left").setOption("unit", newstr); d->set->property("margin-right").setOption("unit", newstr); d->set->property("margin-top").setOption("unit", newstr); d->set->property("margin-bottom").setOption("unit", newstr); } } void KReportDesigner::slotPageButton_Pressed() { #ifdef KREPORT_SCRIPTING if (d->kordata) { QStringList sl = d->kordata->scriptList(); sl.prepend(QLatin1String("")); d->script->setListData(sl, sl); } changeSet(d->set); #endif } QSize KReportDesigner::sizeHint() const { int w = 0; int h = 0; if (d->pageFooterAny) h += d->pageFooterAny->sizeHint().height(); if (d->pageFooterEven) h += d->pageFooterEven->sizeHint().height(); if (d->pageFooterFirst) h += d->pageFooterFirst->sizeHint().height(); if (d->pageFooterLast) h += d->pageFooterLast->sizeHint().height(); if (d->pageFooterOdd) h += d->pageFooterOdd->sizeHint().height(); if (d->pageHeaderAny) h += d->pageHeaderAny->sizeHint().height(); if (d->pageHeaderEven) h += d->pageHeaderEven->sizeHint().height(); if (d->pageHeaderFirst) h += d->pageHeaderFirst->sizeHint().height(); if (d->pageHeaderLast) h += d->pageHeaderLast->sizeHint().height(); if (d->pageHeaderOdd) h += d->pageHeaderOdd->sizeHint().height(); if (d->reportHeader) h += d->reportHeader->sizeHint().height(); if (d->reportFooter) { h += d->reportFooter->sizeHint().height(); } if (d->detail) { h += d->detail->sizeHint().height(); w += d->detail->sizeHint().width(); } h += d->hruler->height(); return QSize(w, h); } int KReportDesigner::pageWidthPx() const { - KReportPageOptions po; - po.setPageSize(d->set->property("page-size").value().toString()); - po.setPortrait(d->set->property("print-orientation").value().toString() == QLatin1String("portrait")); - QSizeF pageSizePx = po.pixelSize(); + QPageLayout layout; + layout.setPageSize(QPageSize(KReportPageSize::pageSize(d->set->property("page-size").value().toString()))); + layout.setOrientation(d->set->property("print-orientation").value().toString() == QLatin1String("portrait") ? QPageLayout::Portrait : QPageLayout::Landscape); + QSize pageSizePx = layout.fullRectPixels(KReportDpi::dpiX()).size(); int width = pageSizePx.width(); width = width - POINT_TO_INCH(d->set->property("margin-left").value().toDouble()) * KReportDpi::dpiX(); width = width - POINT_TO_INCH(d->set->property("margin-right").value().toDouble()) * KReportDpi::dpiX(); return width; } void KReportDesigner::resizeEvent(QResizeEvent * event) { Q_UNUSED(event); d->hruler->setRulerLength(pageWidthPx()); } void KReportDesigner::setDetail(KReportDesignerSectionDetail *rsd) { if (!d->detail) { int idx = 0; if (d->pageHeaderFirst) idx++; if (d->pageHeaderOdd) idx++; if (d->pageHeaderEven) idx++; if (d->pageHeaderLast) idx++; if (d->pageHeaderAny) idx++; if (d->reportHeader) idx++; d->detail = rsd; d->vboxlayout->insertWidget(idx, d->detail); } } void KReportDesigner::deleteDetail() { delete d->detail; d->detail = 0; } KReportUnit KReportDesigner::pageUnit() const { QString u; bool found; u = d->unit->value().toString(); KReportUnit unit = KReportUnit::fromSymbol(u, &found); if (!found) { unit = KReportUnit(KReportUnit::Centimeter); } return unit; } void KReportDesigner::setGridOptions(bool vis, int div) { d->showGrid->setValue(QVariant(vis)); d->gridDivisions->setValue(div); } // // methods for the sectionMouse*Event() // void KReportDesigner::sectionContextMenuEvent(KReportDesignerSectionScene * s, QGraphicsSceneContextMenuEvent * e) { Q_UNUSED(s); QMenu pop; bool itemsSelected = selectionCount() > 0; if (itemsSelected) { //! @todo KF5 use KStandardAction QAction *a = new QAction(QIcon::fromTheme(QLatin1String("edit-cut")), tr("Cut"), this); connect(a, SIGNAL(triggered()), this, SLOT(slotEditCut())); pop.addAction(a); //! @todo KF5 use KStandardAction a = new QAction(QIcon::fromTheme(QLatin1String("edit-copy")), tr("Copy"), this); connect(a, SIGNAL(triggered()), this, SLOT(slotEditCopy())); pop.addAction(a); } if (!d->sectionData->copy_list.isEmpty()) { QAction *a = new QAction(QIcon::fromTheme(QLatin1String("edit-paste")), tr("Paste"), this); connect(a, SIGNAL(triggered()), this, SLOT(slotEditPaste())); pop.addAction(a); } if (itemsSelected) { pop.addSeparator(); //! @todo KF5 use KStandard* //const KGuiItem del = KStandardGuiItem::del(); //a->setToolTip(del.toolTip()); //a->setShortcut(QKeySequence(QKeySequence::Delete)); QAction *a = new QAction(QIcon::fromTheme(QLatin1String("edit-delete")), tr("Delete"), this); connect(a, SIGNAL(triggered()), SLOT(slotEditDelete())); pop.addAction(a); } if (!pop.actions().isEmpty()) { pop.exec(e->screenPos()); } } void KReportDesigner::sectionMousePressEvent(KReportDesignerSectionView * v, QMouseEvent * e) { Q_UNUSED(v); d->pressX = e->pos().x(); d->pressY = e->pos().y(); } void KReportDesigner::sectionMouseReleaseEvent(KReportDesignerSectionView * v, QMouseEvent * e) { e->accept(); d->releaseX = e->pos().x(); d->releaseY = e->pos().y(); if (e->button() == Qt::LeftButton) { QPointF pos(d->pressX, d->pressY); QPointF end(d->releaseX, d->releaseY); if (d->releaseY >= v->scene()->height()) { d->releaseY = v->scene()->height(); end.setY(v->scene()->height()); } if (d->releaseX >= v->scene()->width()) { d->releaseX = v->scene()->width(); end.setX(v->scene()->width()); } if (d->sectionData->mouseAction == ReportWriterSectionData::MA_Insert) { QGraphicsItem * item = 0; QString classString; QString iconName; if (d->sectionData->insertItem == QLatin1String("org.kde.kreport.line")) { item = new KReportDesignerItemLine(v->designer(), v->scene(), pos, end); classString = tr("Line", "Report line element"); iconName = QLatin1String("kreport-line-element"); } else { KReportPluginManager* pluginManager = KReportPluginManager::self(); KReportPluginInterface *plug = pluginManager->plugin(d->sectionData->insertItem); if (plug) { QObject *obj = plug->createDesignerInstance(v->designer(), v->scene(), pos); if (obj) { item = dynamic_cast(obj); classString = plug->metaData()->name(); iconName = plug->metaData()->iconName(); } } else { kreportWarning() << "attempted to insert an unknown item"; } } if (item) { item->setVisible(true); item->setSelected(true); KReportItemBase* baseReportItem = dynamic_cast(item); if (baseReportItem) { baseReportItem->setUnit(pageUnit()); KPropertySet *set = baseReportItem->propertySet(); KReportDesigner::addMetaProperties(set, classString, iconName); changeSet(set); if (v && v->designer()) { v->designer()->setModified(true); } emit itemInserted(d->sectionData->insertItem); } } d->sectionData->mouseAction = ReportWriterSectionData::MA_None; d->sectionData->insertItem.clear(); unsetSectionCursor(); } } } unsigned int KReportDesigner::selectionCount() const { if (activeScene()) return activeScene()->selectedItems().count(); else return 0; } void KReportDesigner::changeSet(KPropertySet *s) { //Set the checked state of the report properties button if (s == d->set) d->pageButton->setCheckState(Qt::Checked); else d->pageButton->setCheckState(Qt::Unchecked); d->itmset = s; emit propertySetChanged(); } // // Actions // void KReportDesigner::slotItem(const QString &entity) { //kreportDebug() << entity; d->sectionData->mouseAction = ReportWriterSectionData::MA_Insert; d->sectionData->insertItem = entity; setSectionCursor(QCursor(Qt::CrossCursor)); } void KReportDesigner::slotEditDelete() { QGraphicsItem * item = 0; bool modified = false; while (selectionCount() > 0) { item = activeScene()->selectedItems().value(0); if (item) { QGraphicsScene * scene = item->scene(); delete item; scene->update(); d->sectionData->mouseAction = ReportWriterSectionData::MA_None; modified = true; } } activeScene()->selectedItems().clear(); /*! @todo temporary: clears cut and copy lists to make sure we do not crash if weve deleted something in the list should really check if an item is in the list first and remove it. */ d->sectionData->cut_list.clear(); d->sectionData->copy_list.clear(); if (modified) { setModified(true); } } void KReportDesigner::slotEditCut() { if (selectionCount() > 0) { //First delete any items that are curerntly in the list //so as not to leak memory qDeleteAll(d->sectionData->cut_list); d->sectionData->cut_list.clear(); QGraphicsItem * item = activeScene()->selectedItems().first(); bool modified = false; if (item) { d->sectionData->copy_list.clear(); foreach(QGraphicsItem *item, activeScene()->selectedItems()) { d->sectionData->cut_list.append(dynamic_cast(item)); d->sectionData->copy_list.append(dynamic_cast(item)); } foreach(QGraphicsItem *item, activeScene()->selectedItems()) { activeScene()->removeItem(item); activeScene()->update(); modified = true; } d->sectionData->selected_x_offset = 10; d->sectionData->selected_y_offset = 10; } if (modified) { setModified(true); } } } void KReportDesigner::slotEditCopy() { if (selectionCount() < 1) return; QGraphicsItem * item = activeScene()->selectedItems().first(); if (item) { d->sectionData->copy_list.clear(); foreach(QGraphicsItem *item, activeScene()->selectedItems()) { d->sectionData->copy_list.append(dynamic_cast(item)); } d->sectionData->selected_x_offset = 10; d->sectionData->selected_y_offset = 10; } } void KReportDesigner::slotEditPaste() { // call the editPaste function passing it a reportsection slotEditPaste(activeScene()); } void KReportDesigner::slotEditPaste(QGraphicsScene * canvas) { // paste a new item of the copy we have in the specified location if (!d->sectionData->copy_list.isEmpty()) { QList activeItems = canvas->selectedItems(); QGraphicsItem *activeItem = 0; if (activeItems.count() == 1) { activeItem = activeItems.first(); } canvas->clearSelection(); d->sectionData->mouseAction = ReportWriterSectionData::MA_None; //! @todo this code sucks :) //! The setPos calls only work AFTER the name has been set ?!?!? foreach(KReportDesignerItemBase *item, d->sectionData->copy_list) { KReportItemBase *obj = dynamic_cast(item); const QString type = obj ? obj->typeName() : QLatin1String("object"); //kreportDebug() << type; KReportDesignerItemBase *ent = item->clone(); KReportItemBase *new_obj = dynamic_cast(ent); new_obj->setEntityName(suggestEntityName(type)); if (activeItem) { new_obj->setPosition(KReportItemBase::positionFromScene(QPointF(activeItem->x() + 10, activeItem->y() + 10))); } else { new_obj->setPosition(KReportItemBase::positionFromScene(QPointF(0, 0))); } changeSet(new_obj->propertySet()); QGraphicsItem *pasted_ent = dynamic_cast(ent); if (pasted_ent) { pasted_ent->setSelected(true); canvas->addItem(pasted_ent); pasted_ent->show(); d->sectionData->mouseAction = ReportWriterSectionData::MA_Grab; setModified(true); } } } } void KReportDesigner::slotRaiseSelected() { dynamic_cast(activeScene())->raiseSelected(); } void KReportDesigner::slotLowerSelected() { dynamic_cast(activeScene())->lowerSelected(); } QGraphicsScene* KReportDesigner::activeScene() const { return d->activeScene; } void KReportDesigner::setActiveScene(QGraphicsScene* a) { if (d->activeScene && d->activeScene != a) d->activeScene->clearSelection(); d->activeScene = a; //Trigger an update so that the last scene redraws its title; update(); } KReportZoomHandler* KReportDesigner::zoomHandler() const { return d->zoom; } QString KReportDesigner::suggestEntityName(const QString &n) const { KReportDesignerSection *sec; int itemCount = 0; //Count items in the main sections for (int i = 1; i <= KReportSectionData::PageFooterAny; i++) { sec = section((KReportSectionData::Section) i); if (sec) { const QGraphicsItemList l = sec->items(); itemCount += l.count(); } } if (d->detail) { //Count items in the group headers/footers for (int i = 0; i < d->detail->groupSectionCount(); i++) { sec = d->detail->groupSection(i)->groupHeader(); if (sec) { const QGraphicsItemList l = sec->items(); itemCount += l.count(); } sec = d->detail->groupSection(i)->groupFooter(); if (sec) { const QGraphicsItemList l = sec->items(); itemCount += l.count(); } } sec = d->detail->detailSection(); if (sec) { const QGraphicsItemList l = sec->items(); itemCount += l.count(); } } while (!isEntityNameUnique(n + QString::number(itemCount))) { itemCount++; } return n + QString::number(itemCount); } bool KReportDesigner::isEntityNameUnique(const QString &n, KReportItemBase* ignore) const { KReportDesignerSection *sec; bool unique = true; //Check items in the main sections for (int i = 1; i <= KReportSectionData::PageFooterAny; i++) { sec = section((KReportSectionData::Section)i); if (sec) { const QGraphicsItemList l = sec->items(); for (QGraphicsItemList::const_iterator it = l.constBegin(); it != l.constEnd(); ++it) { KReportItemBase* itm = dynamic_cast(*it); if (itm && itm->entityName() == n && itm != ignore) { unique = false; break; } } if (!unique) break; } } //Count items in the group headers/footers if (unique && d->detail) { for (int i = 0; i < d->detail->groupSectionCount(); ++i) { sec = d->detail->groupSection(i)->groupHeader(); if (sec) { const QGraphicsItemList l = sec->items(); for (QGraphicsItemList::const_iterator it = l.constBegin(); it != l.constEnd(); ++it) { KReportItemBase* itm = dynamic_cast(*it); if (itm && itm->entityName() == n && itm != ignore) { unique = false; break; } } } sec = d->detail->groupSection(i)->groupFooter(); if (unique && sec) { const QGraphicsItemList l = sec->items(); for (QGraphicsItemList::const_iterator it = l.constBegin(); it != l.constEnd(); ++it) { KReportItemBase* itm = dynamic_cast(*it); if (itm && itm->entityName() == n && itm != ignore) { unique = false; break; } } } } } if (unique && d->detail) { sec = d->detail->detailSection(); if (sec) { const QGraphicsItemList l = sec->items(); for (QGraphicsItemList::const_iterator it = l.constBegin(); it != l.constEnd(); ++it) { KReportItemBase* itm = dynamic_cast(*it); if (itm && itm->entityName() == n && itm != ignore) { unique = false; break; } } } } return unique; } static bool actionPriortyLessThan(QAction* act1, QAction* act2) { if (act1->data().toInt() > 0 && act2->data().toInt() > 0) { return act1->data().toInt() < act2->data().toInt(); } return false; } QList KReportDesigner::itemActions(QActionGroup* group) { KReportPluginManager* manager = KReportPluginManager::self(); QList actList = manager->createActions(group); //! @todo make line a real plugin so this isn't needed: QAction *act = new QAction(QIcon::fromTheme(QLatin1String("kreport-line-element")), tr("Line"), group); act->setObjectName(QLatin1String("org.kde.kreport.line")); act->setData(9); act->setCheckable(true); actList << act; qSort(actList.begin(), actList.end(), actionPriortyLessThan); int i = 0; /*! @todo maybe this is a bit hackish It finds the first plugin based on the priority in userdata The lowest oriority a plugin can have is 10 And inserts a separator before it. */ bool sepInserted = false; foreach(QAction *a, actList) { ++i; if (!sepInserted && a->data().toInt() >= 10) { QAction *sep = new QAction(QLatin1String("separator"), group); sep->setSeparator(true); actList.insert(i-1, sep); sepInserted = true; } if (group) { group->addAction(a); } } return actList; } QList< QAction* > KReportDesigner::designerActions() { QList al; QAction *sep = new QAction(QString(), this); sep->setSeparator(true); al << d->editCutAction << d->editCopyAction << d->editPasteAction << d->editDeleteAction << sep << d->sectionEdit << sep << d->itemLowerAction << d->itemRaiseAction; return al; } void KReportDesigner::createActions() { d->editCutAction = new QAction(QIcon::fromTheme(QLatin1String("edit-cut")), tr("Cu&t"), this); d->editCutAction->setObjectName(QLatin1String("edit_cut")); d->editCutAction->setToolTip(tr("Cut selection to clipboard")); d->editCutAction->setShortcuts(KStandardShortcut::cut()); d->editCutAction->setProperty("iconOnly", true); d->editCopyAction = new QAction(QIcon::fromTheme(QLatin1String("edit-copy")), tr("&Copy"), this); d->editCopyAction->setObjectName(QLatin1String("edit_copy")); d->editCopyAction->setToolTip(tr("Copy selection to clipboard")); d->editCopyAction->setShortcuts(KStandardShortcut::copy()); d->editCopyAction->setProperty("iconOnly", true); d->editPasteAction = new QAction(QIcon::fromTheme(QLatin1String("edit-paste")), tr("&Paste"), this); d->editPasteAction->setObjectName(QLatin1String("edit_paste")); d->editPasteAction->setToolTip(tr("Paste clipboard content")); d->editPasteAction->setShortcuts(KStandardShortcut::paste()); d->editPasteAction->setProperty("iconOnly", true); const KGuiItem del = KStandardGuiItem::del(); d->editDeleteAction = new QAction(del.icon(), del.text(), this); d->editDeleteAction->setObjectName(QLatin1String("edit_delete")); d->editDeleteAction->setToolTip(del.toolTip()); d->editDeleteAction->setWhatsThis(del.whatsThis()); d->editDeleteAction->setProperty("iconOnly", true); d->sectionEdit = new QAction(tr("Edit Sections"), this); d->sectionEdit->setObjectName(QLatin1String("section_edit")); d->itemRaiseAction = new QAction(QIcon::fromTheme(QLatin1String("arrow-up")), tr("Raise"), this); d->itemRaiseAction->setObjectName(QLatin1String("item_raise")); d->itemLowerAction = new QAction(QIcon::fromTheme(QLatin1String("arrow-down")), tr("Lower"), this); d->itemLowerAction->setObjectName(QLatin1String("item_lower")); //Edit Actions connect(d->editCutAction, SIGNAL(triggered(bool)), this, SLOT(slotEditCut())); connect(d->editCopyAction, SIGNAL(triggered(bool)), this, SLOT(slotEditCopy())); connect(d->editPasteAction, SIGNAL(triggered(bool)), this, SLOT(slotEditPaste())); connect(d->editDeleteAction, SIGNAL(triggered(bool)), this, SLOT(slotEditDelete())); connect(d->sectionEdit, SIGNAL(triggered(bool)), this, SLOT(slotSectionEditor())); //Raise/Lower connect(d->itemRaiseAction, SIGNAL(triggered(bool)), this, SLOT(slotRaiseSelected())); connect(d->itemLowerAction, SIGNAL(triggered(bool)), this, SLOT(slotLowerSelected())); } void KReportDesigner::setSectionCursor(const QCursor& c) { if (d->pageFooterAny) d->pageFooterAny->setSectionCursor(c); if (d->pageFooterEven) d->pageFooterEven->setSectionCursor(c); if (d->pageFooterFirst) d->pageFooterFirst->setSectionCursor(c); if (d->pageFooterLast) d->pageFooterLast->setSectionCursor(c); if (d->pageFooterOdd) d->pageFooterOdd->setSectionCursor(c); if (d->pageHeaderAny) d->pageHeaderAny->setSectionCursor(c); if (d->pageHeaderEven) d->pageHeaderEven->setSectionCursor(c); if (d->pageHeaderFirst) d->pageHeaderFirst->setSectionCursor(c); if (d->pageHeaderLast) d->pageHeaderLast->setSectionCursor(c); if (d->pageHeaderOdd) d->pageHeaderOdd->setSectionCursor(c); if (d->detail) d->detail->setSectionCursor(c); } void KReportDesigner::unsetSectionCursor() { if (d->pageFooterAny) d->pageFooterAny->unsetSectionCursor(); if (d->pageFooterEven) d->pageFooterEven->unsetSectionCursor(); if (d->pageFooterFirst) d->pageFooterFirst->unsetSectionCursor(); if (d->pageFooterLast) d->pageFooterLast->unsetSectionCursor(); if (d->pageFooterOdd) d->pageFooterOdd->unsetSectionCursor(); if (d->pageHeaderAny) d->pageHeaderAny->unsetSectionCursor(); if (d->pageHeaderEven) d->pageHeaderEven->unsetSectionCursor(); if (d->pageHeaderFirst) d->pageHeaderFirst->unsetSectionCursor(); if (d->pageHeaderLast) d->pageHeaderLast->unsetSectionCursor(); if (d->pageHeaderOdd) d->pageHeaderOdd->unsetSectionCursor(); if (d->detail) d->detail->unsetSectionCursor(); } qreal KReportDesigner::countSelectionHeight() const { if (d->releaseY == -1 || d->pressY == -1) { return -1; } return qAbs(d->releaseY - d->pressY); } qreal KReportDesigner::countSelectionWidth() const { if (d->releaseX == -1 || d->pressX == -1) { return -1; } return qAbs(d->releaseX - d->pressX); } qreal KReportDesigner::getSelectionPressX() const { return d->pressX; } qreal KReportDesigner::getSelectionPressY() const { return d->pressY; } QPointF KReportDesigner::getPressPoint() const { return QPointF(d->pressX, d->pressY); } QPointF KReportDesigner::getReleasePoint() const { return QPointF(d->releaseX, d->releaseY); } void KReportDesigner::plugItemActions(const QList &actList) { foreach(QAction *a, actList) { connect(a, SIGNAL(triggered(bool)), this, SLOT(slotItemTriggered(bool))); } } void KReportDesigner::slotItemTriggered(bool checked) { if (!checked) { return; } QObject *theSender = sender(); if (!theSender) { return; } slotItem(theSender->objectName()); } void KReportDesigner::addMetaProperties(KPropertySet* set, const QString &classString, const QString &iconName) { Q_ASSERT(set); KProperty *prop; set->addProperty(prop = new KProperty("this:classString", classString)); prop->setVisible(false); set->addProperty(prop = new KProperty("this:iconName", iconName)); prop->setVisible(false); } diff --git a/src/wrtembed/KReportDesignerSectionScene.cpp b/src/wrtembed/KReportDesignerSectionScene.cpp index 905071fb..95def202 100644 --- a/src/wrtembed/KReportDesignerSectionScene.cpp +++ b/src/wrtembed/KReportDesignerSectionScene.cpp @@ -1,261 +1,260 @@ /* This file is part of the KDE project * Copyright (C) 2001-2007 by OpenMFG, LLC (info@openmfg.com) * Copyright (C) 2007-2008 by Adam Pigg (adam@piggz.co.uk) * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . */ #include "KReportDesignerSectionScene.h" -#include "KReportPageOptions.h" #include "KReportDesignerItemRectBase.h" #include "KReportDesigner.h" #include "KReportLabelSizeInfo.h" #include "KReportDpi.h" #include "kreport_debug.h" #include #include #include #include KReportDesignerSectionScene::KReportDesignerSectionScene(qreal w, qreal h, KReportDesigner *rd) : QGraphicsScene(0, 0, w, h, rd) { m_rd = rd; m_minorSteps = 0; m_dpiX = KReportDpi::dpiX(); m_dpiY = KReportDpi::dpiY(); if (m_unit.type() != m_rd->pageUnit().type()) { m_unit = m_rd->pageUnit(); if (m_unit.type() == KReportUnit::Cicero || m_unit.type() == KReportUnit::Pica || m_unit.type() == KReportUnit::Millimeter) { m_majorX = POINT_TO_INCH(m_unit.fromUserValue(10)) * m_dpiX; m_majorY = POINT_TO_INCH(m_unit.fromUserValue(10)) * m_dpiY; } else if (m_unit.type() == KReportUnit::Point) { m_majorX = POINT_TO_INCH(m_unit.fromUserValue(100)) * m_dpiX; m_majorY = POINT_TO_INCH(m_unit.fromUserValue(100)) * m_dpiY; } else { m_majorX = POINT_TO_INCH(m_unit.fromUserValue(1)) * m_dpiX; m_majorY = POINT_TO_INCH(m_unit.fromUserValue(1)) * m_dpiY; } } } KReportDesignerSectionScene::~KReportDesignerSectionScene() { // Qt should be handling everything for us } void KReportDesignerSectionScene::drawBackground(QPainter* painter, const QRectF & clip) { //Draw the default background colour QGraphicsScene::drawBackground(painter, clip); painter->setRenderHint(QPainter::Antialiasing, false); if (m_rd->propertySet()->property("grid-visible").value().toBool()) { if (m_unit.type() != m_rd->pageUnit().type()) { m_unit = m_rd->pageUnit(); if (m_unit.type() == KReportUnit::Cicero || m_unit.type() == KReportUnit::Pica || m_unit.type() == KReportUnit::Millimeter) { m_majorX = POINT_TO_INCH(m_unit.fromUserValue(10)) * m_dpiX; m_majorY = POINT_TO_INCH(m_unit.fromUserValue(10)) * m_dpiY; } else if (m_unit.type() == KReportUnit::Point) { m_majorX = POINT_TO_INCH(m_unit.fromUserValue(100)) * m_dpiX; m_majorY = POINT_TO_INCH(m_unit.fromUserValue(100)) * m_dpiY; } else { m_majorX = POINT_TO_INCH(m_unit.fromUserValue(1)) * m_dpiX; m_majorY = POINT_TO_INCH(m_unit.fromUserValue(1)) * m_dpiY; } } m_minorSteps = m_rd->propertySet()->property("grid-divisions").value().toInt(); m_pixelIncrementX = (m_majorX / m_minorSteps); m_pixelIncrementY = (m_majorY / m_minorSteps); QPen pen = painter->pen(); painter->setPen(Qt::lightGray); //kreportDebug() << "dpix" << KReportDpi::dpiX() << "dpiy" << KReportDpi::dpiY() << "mayorx:" << majorx << "majory" << majory << "pix:" << pixel_incrementx << "piy:" << pixel_incrementy; QVector lines; QVector points; if (m_pixelIncrementX > 2) { // do not bother painting points if increments are so small int wpoints = qRound(sceneRect().width() / m_pixelIncrementX); int hpoints = qRound(sceneRect().height() / m_pixelIncrementY); for (int i = 0; i < wpoints; ++i) { for (int j = 0; j < hpoints; ++j) { //if (clip.contains(i * pixel_incrementx, j * pixel_incrementy)){ if (i % m_minorSteps == 0 && j % m_minorSteps == 0) { lines << QLine(QPoint(i * m_pixelIncrementX, j * m_pixelIncrementY), QPoint(i * m_pixelIncrementX, j * m_pixelIncrementY + m_majorX)); //painter->drawLine(); lines << QLine(QPoint(i * m_pixelIncrementX, j * m_pixelIncrementY), QPoint(i * m_pixelIncrementX + m_majorY, j * m_pixelIncrementY)); //painter->drawLine(); } else { points << QPoint(i * m_pixelIncrementX, j * m_pixelIncrementY); //painter->drawPoint(); } //} } } painter->drawPoints(points); painter->drawLines(lines); } pen.setWidth(1); //update ( clip ); } } void KReportDesignerSectionScene::mousePressEvent(QGraphicsSceneMouseEvent * e) { // clear the selection if Shift Key has not been pressed and it's a left mouse button and // if the right mouse button has been pressed over an item which is not part of selected items if (((e->modifiers() & Qt::ShiftModifier) == 0 && e->button() == Qt::LeftButton) || (!(selectedItems().contains(itemAt(e->scenePos(), QTransform()))) && e->button() == Qt::RightButton)) clearSelection(); //This will be caught by the section to display its properties, if an item is under the cursor then they will display their properties QGraphicsItem* itemUnderCursor = itemAt(e->scenePos(), QTransform()); emit clicked(); KReportDesignerItemRectBase *rectUnderCursor = qgraphicsitem_cast< KReportDesignerItemRectBase* >(itemUnderCursor); if (itemUnderCursor && !rectUnderCursor) { rectUnderCursor = qgraphicsitem_cast< KReportDesignerItemRectBase* >(itemUnderCursor->parentItem()); } exitInlineEditingModeInItems(rectUnderCursor); QGraphicsScene::mousePressEvent(e); } void KReportDesignerSectionScene::contextMenuEvent(QGraphicsSceneContextMenuEvent * e) { m_rd->sectionContextMenuEvent(this, e); } QPointF KReportDesignerSectionScene::gridPoint(const QPointF& p) { if (!m_rd->propertySet()->property("grid-snap").value().toBool()) { return p; } if (m_unit.type() != m_rd->pageUnit().type()) { m_unit = m_rd->pageUnit(); //! @todo Again? Copy&Paste error? if (m_unit.type() != m_rd->pageUnit().type()) { m_unit = m_rd->pageUnit(); if (m_unit.type() == KReportUnit::Cicero || m_unit.type() == KReportUnit::Pica || m_unit.type() == KReportUnit::Millimeter) { m_majorX = POINT_TO_INCH(m_unit.fromUserValue(10)) * m_dpiX; m_majorY = POINT_TO_INCH(m_unit.fromUserValue(10)) * m_dpiY; } else if (m_unit.type() == KReportUnit::Point) { m_majorX = POINT_TO_INCH(m_unit.fromUserValue(100)) * m_dpiX; m_majorY = POINT_TO_INCH(m_unit.fromUserValue(100)) * m_dpiY; } else { m_majorX = POINT_TO_INCH(m_unit.fromUserValue(1)) * m_dpiX; m_majorY = POINT_TO_INCH(m_unit.fromUserValue(1)) * m_dpiY; } } } m_minorSteps = m_rd->propertySet()->property("grid-divisions").value().toInt(); m_pixelIncrementX = (m_majorX / m_minorSteps); m_pixelIncrementY = (m_majorY / m_minorSteps); return QPointF(qRound((p.x() / m_pixelIncrementX)) * m_pixelIncrementX, qRound((p.y() / m_pixelIncrementY)) * m_pixelIncrementY); } void KReportDesignerSectionScene::focusOutEvent(QFocusEvent * focusEvent) { exitInlineEditingModeInItems(0); emit lostFocus(); QGraphicsScene::focusOutEvent(focusEvent); } qreal KReportDesignerSectionScene::lowestZValue() { qreal z; qreal zz; z = 0; QGraphicsItemList list = items(); for (QGraphicsItemList::iterator it = list.begin(); it != list.end(); ++it) { zz = (*it)->zValue(); if (zz < z) { z = zz; } } return z; } qreal KReportDesignerSectionScene::highestZValue() { qreal z; qreal zz; z = 0; QGraphicsItemList list = items(); for (QGraphicsItemList::iterator it = list.begin(); it != list.end(); ++it) { zz = (*it)->zValue(); if (zz > z) { z = zz; } } return z; } void KReportDesignerSectionScene::lowerSelected() { QGraphicsItemList list = selectedItems(); for (QGraphicsItemList::iterator it = list.begin(); it != list.end(); ++it) { (*it)->setZValue(lowestZValue() - 1); } } void KReportDesignerSectionScene::raiseSelected() { QGraphicsItemList list = selectedItems(); for (QGraphicsItemList::iterator it = list.begin(); it != list.end(); ++it) { (*it)->setZValue(highestZValue() + 1); } } QGraphicsItemList KReportDesignerSectionScene::itemsOrdered() const { QGraphicsItemList r; QGraphicsItemList list = items(); for (QGraphicsItemList::iterator it = list.begin(); it != list.end(); ++it) { for (QGraphicsItemList::iterator rit = r.begin(); rit != r.end(); ++rit) { } } return r; } void KReportDesignerSectionScene::exitInlineEditingModeInItems(KReportDesignerItemRectBase *rectUnderCursor) { foreach(QGraphicsItem *it, items()) { KReportDesignerItemRectBase *itm = qgraphicsitem_cast< KReportDesignerItemRectBase* >(it); if (itm && itm != rectUnderCursor) { itm->exitInlineEditingMode(); } } }