diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -198,6 +198,8 @@ Qt5::Widgets KF5::ConfigGui KF5::WidgetsAddons + PRIVATE + Qt5::PrintSupport ) ecm_setup_version(${PROJECT_VERSION} diff --git a/src/common/KReportUtils_p.h b/src/common/KReportUtils_p.h --- a/src/common/KReportUtils_p.h +++ b/src/common/KReportUtils_p.h @@ -1,5 +1,5 @@ /* This file is part of the KDE project - Copyright (C) 2015-2016 Jarosław Staniek + Copyright (C) 2015-2019 Jarosław Staniek This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public @@ -26,6 +26,8 @@ #include #include +class QPrinter; + const bool DEFAULT_SHOW_GRID = true; const bool DEFAULT_SNAP_TO_GRID = true; const int DEFAULT_GRID_DIVISIONS = 4; @@ -173,6 +175,14 @@ int dpiY(); +/*! + * Returns a high-resolution printer + * + * The QPrinter(QPrinter::HighResolution)) instance is created on first call. + * The global printer helps to optimize access to QPrinter when report items need it. + */ +QPrinter* highResolutionPrinter(); + //! This class is wrapper that fixes a critical QTBUG-47551 bug in default constructor of QPageLayout //! Default constructor of QPageLayout does not initialize units. //! https://bugreports.qt.io/browse/QTBUG-47551 diff --git a/src/common/KReportUtils_p.cpp b/src/common/KReportUtils_p.cpp --- a/src/common/KReportUtils_p.cpp +++ b/src/common/KReportUtils_p.cpp @@ -1,5 +1,5 @@ /* This file is part of the KDE project - Copyright (C) 2015-2016 Jarosław Staniek + Copyright (C) 2015-2019 Jarosław Staniek Copyright (C) 2016 Adam Pigg This library is free software; you can redistribute it and/or @@ -26,13 +26,14 @@ #include #include +#include #include #include +#include +#include #include #include #include -#include -#include #ifdef Q_WS_X11 #include @@ -329,6 +330,13 @@ return s_instance->m_dpiY; } +Q_GLOBAL_STATIC_WITH_ARGS(QPrinter, s_printerInstance, (QPrinter::HighResolution)) + +QPrinter* highResolutionPrinter() +{ + return s_printerInstance; +} + PageLayout::PageLayout() : QPageLayout(QPageSize(QPageSize::A4), QPageLayout::Portrait, QMarginsF(0,0,0,0)) { } diff --git a/src/items/text/KReportItemText.cpp b/src/items/text/KReportItemText.cpp --- a/src/items/text/KReportItemText.cpp +++ b/src/items/text/KReportItemText.cpp @@ -1,5 +1,6 @@ /* This file is part of the KDE project * Copyright (C) 2007-2008 by Adam Pigg (adam@piggz.co.uk) + * Copyright (C) 2019 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 @@ -17,8 +18,9 @@ #include "KReportItemText.h" #include "KReportRenderObjects.h" -#include "kreportplugin_debug.h" #include "KReportUtils.h" +#include "KReportUtils_p.h" +#include "kreportplugin_debug.h" #include #include @@ -217,11 +219,10 @@ int pos = 0; QChar separator; QRegularExpression re(QLatin1String("\\s")); - QPrinter prnt(QPrinter::HighResolution); - QFontMetricsF fm(font(), &prnt); + const QFontMetricsF fm(font(), KReportPrivate::highResolutionPrinter()); - // int intRectWidth = (int)(trf.width() * prnt.resolution()) - 10; - int intRectWidth = (int)((size().width() / 72) * prnt.resolution()); + const int intRectWidth + = (int)((size().width() / 72) * KReportPrivate::highResolutionPrinter()->resolution()); int intLineCounter = 0; qreal intBaseTop = trf.top(); qreal intRectHeight = trf.height();