diff --git a/autotests/format/FormatTest.cpp b/autotests/format/FormatTest.cpp --- a/autotests/format/FormatTest.cpp +++ b/autotests/format/FormatTest.cpp @@ -31,7 +31,6 @@ #include "KReportItemLine.h" #include "KReportDesignerItemRectBase.h" #include "KReportUnit.h" -#include #include #include @@ -103,11 +102,11 @@ 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); + qDebug() << opt.getMarginBottom() << INCH_TO_POINT(opt.getMarginBottom()) << KReportPrivate::dpiY() << dpiY << KReportUnit::parseValue("1.5cm"); + QFUZZYCOMPARE(INCH_TO_POINT(opt.getMarginBottom()) / KReportPrivate::dpiY(), KReportUnit::parseValue("1.5cm"), 0.2); + QFUZZYCOMPARE(INCH_TO_POINT(opt.getMarginTop()) / KReportPrivate::dpiY(), KReportUnit::parseValue("2.0cm"), 0.2); + QFUZZYCOMPARE(INCH_TO_POINT(opt.getMarginLeft()) / KReportPrivate::dpiX(), KReportUnit::parseValue("3.0cm"), 0.2); + QFUZZYCOMPARE(INCH_TO_POINT(opt.getMarginRight()) / KReportPrivate::dpiX(), KReportUnit::parseValue("4.0cm"), 0.3); #endif } diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -16,4 +16,4 @@ KReportExampleData.cpp ) add_executable(kreportexample ${kreportexample_SRCS}) -target_link_libraries(kreportexample KF5::ConfigGui KReport) +target_link_libraries(kreportexample KF5::ConfigGui KReport KReportUtilsPrivate) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -58,7 +58,6 @@ wrtembed/KReportDesigner.cpp wrtembed/KReportPropertiesButton.cpp wrtembed/KReportSectionEditor.cpp - wrtembed/KReportDpi.cpp wrtembed/KReportRuler.cpp wrtembed/KReportZoomHandler.cpp wrtembed/KReportZoomMode.cpp @@ -94,7 +93,7 @@ Mainpage.dox Messages.sh ) - + set(kreport_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/common ${CMAKE_CURRENT_SOURCE_DIR}/wrtembed @@ -157,6 +156,10 @@ add_library(KReport SHARED ${kreport_LIB_SRCS}) set_coinstallable_lib_version(KReport) +add_library(KReportUtilsPrivate STATIC + common/KReportUtils_p.cpp +) + 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 @@ -188,15 +191,18 @@ KF5::CoreAddons KPropertyWidgets PRIVATE - KF5::WidgetsAddons - KF5::ConfigGui # KStandardShortcut ${SCRIPTING_LIBS} - #KF5::KIOCore - #KF5::KIOFileWidgets - #KF5::KIOWidgets - #KF5::KIONTLM + KReportUtilsPrivate ) +target_link_libraries(KReportUtilsPrivate + PUBLIC + Qt5::Widgets + PRIVATE + KF5::WidgetsAddons + KF5::ConfigGui + ) + ecm_setup_version(${PROJECT_VERSION} VARIABLE_PREFIX KREPORT VERSION_HEADER "${CMAKE_CURRENT_BINARY_DIR}/kreport_version.h" @@ -295,7 +301,6 @@ KReportZoomMode KReportDesignerSectionDetail KReportDesignerSection - KReportDpi KReportZoomHandler KReportDesignerItemBase KReportDesignerSectionDetailGroup diff --git a/src/common/KReportDocument.cpp b/src/common/KReportDocument.cpp --- a/src/common/KReportDocument.cpp +++ b/src/common/KReportDocument.cpp @@ -19,7 +19,7 @@ #include "KReportUnit.h" #include "KReportDetailSectionData.h" #include "KReportItemBase.h" -#include "KReportDpi.h" +#include "KReportUtils_p.h" #include "KReportPageSize.h" #include @@ -73,8 +73,8 @@ return; } - const qreal dpiX = KReportDpi::dpiX(); - const qreal dpiY = KReportDpi::dpiY(); + const qreal dpiX = KReportPrivate::dpiX(); + const qreal dpiY = KReportPrivate::dpiY(); QDomNodeList sections = elemSource.childNodes(); diff --git a/src/common/KReportItemBase.h b/src/common/KReportItemBase.h --- a/src/common/KReportItemBase.h +++ b/src/common/KReportItemBase.h @@ -20,7 +20,6 @@ #include "config-kreport.h" #include "kreport_export.h" -#include "KReportDpi.h" #include "KReportUnit.h" #include diff --git a/src/common/KReportItemBase.cpp b/src/common/KReportItemBase.cpp --- a/src/common/KReportItemBase.cpp +++ b/src/common/KReportItemBase.cpp @@ -18,6 +18,8 @@ #include "KReportItemBase.h" #include "KReportUtils.h" +#include "KReportUtils_p.h" + #include #include #include @@ -183,15 +185,15 @@ QPointF KReportItemBase::scenePosition(const QPointF &pos) { - const qreal x = POINT_TO_INCH(pos.x()) * KReportDpi::dpiX(); - const qreal y = POINT_TO_INCH(pos.y()) * KReportDpi::dpiY(); + const qreal x = POINT_TO_INCH(pos.x()) * KReportPrivate::dpiX(); + const qreal y = POINT_TO_INCH(pos.y()) * KReportPrivate::dpiY(); return QPointF(x, y); } QSizeF KReportItemBase::sceneSize(const QSizeF &size) { - const qreal w = POINT_TO_INCH(size.width()) * KReportDpi::dpiX(); - const qreal h = POINT_TO_INCH(size.height()) * KReportDpi::dpiY(); + const qreal w = POINT_TO_INCH(size.width()) * KReportPrivate::dpiX(); + const qreal h = POINT_TO_INCH(size.height()) * KReportPrivate::dpiY(); return QSizeF(w, h); } @@ -217,15 +219,15 @@ QPointF KReportItemBase::positionFromScene(const QPointF& pos) { - const qreal x = INCH_TO_POINT(pos.x() / KReportDpi::dpiX()); - const qreal y = INCH_TO_POINT(pos.y() / KReportDpi::dpiY()); + const qreal x = INCH_TO_POINT(pos.x() / KReportPrivate::dpiX()); + const qreal y = INCH_TO_POINT(pos.y() / KReportPrivate::dpiY()); return QPointF(x, y); } QSizeF KReportItemBase::sizeFromScene(const QSizeF& size) { - qreal w = INCH_TO_POINT(size.width() / KReportDpi::dpiX()); - qreal h = INCH_TO_POINT(size.height() / KReportDpi::dpiY()); + qreal w = INCH_TO_POINT(size.width() / KReportPrivate::dpiX()); + qreal h = INCH_TO_POINT(size.height() / KReportPrivate::dpiY()); return QSizeF(w, h); } 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 @@ -19,7 +19,6 @@ #ifndef KREPORTUTILS_P_H #define KREPORTUTILS_P_H - #include #include @@ -33,6 +32,14 @@ #include #include #include +#include + +#ifdef Q_WS_X11 +#include +#else +#include +#endif + // This is a private code made inline for use in the lib and examples. //! @todo Move to a shared lib to use in other Kexi libraries as well. @@ -43,41 +50,16 @@ const QString supportedIconTheme = QLatin1String("breeze"); //! @brief @return true if @a path is readable -bool fileReadable(const QString &path) -{ - return !path.isEmpty() && QFileInfo(path).isReadable(); -} +bool fileReadable(const QString &path); //! @brief Used for a workaround: locations for QStandardPaths::AppDataLocation end with app name. //! If this is not an expected app but for example a test app, replace //! the subdir name with app name so we can find resource file(s). QStringList correctStandardLocations(const QString &privateName, QStandardPaths::StandardLocation location, - const QString &extraLocation) -{ - QStringList result; - if (!privateName.isEmpty()) { - QRegularExpression re(QLatin1Char('/') + QCoreApplication::applicationName() + QLatin1Char('$')); - QStringList standardLocations(QStandardPaths::standardLocations(location)); - if (!extraLocation.isEmpty()) { - standardLocations.append(extraLocation); - } - for(const QString &dir : standardLocations) { - if (dir.indexOf(re) != -1) { - QString realDir(dir); - realDir.replace(re, QLatin1Char('/') + privateName); - result.append(realDir); - } - } - } - return result; -} + const QString &extraLocation); + -#ifdef Q_OS_WIN -#define KPATH_SEPARATOR ';' -#else -#define KPATH_SEPARATOR ':' -#endif /*! @brief Locates a file path for specified parameters * @param privateName Name to be used instead of application name for resource lookup @@ -88,38 +70,7 @@ */ QString locateFile(const QString &privateName, const QString& path, QStandardPaths::StandardLocation location, - const QString &extraLocation) -{ - // let QStandardPaths handle this, it will look for app local stuff - QString fullPath = QFileInfo( - QStandardPaths::locate(location, path)).canonicalFilePath(); - if (fileReadable(fullPath)) { - return fullPath; - } - - // Try extra location - fullPath = QFileInfo(extraLocation + QLatin1Char('/') + path).canonicalFilePath(); - if (fileReadable(fullPath)) { - return fullPath; - } - // Try in PATH subdirs, useful for running apps from the build dir, without installing - for(const QByteArray &pathDir : qgetenv("PATH").split(KPATH_SEPARATOR)) { - const QString dataDirFromPath = QFileInfo(QFile::decodeName(pathDir) + QStringLiteral("/data/") - + path).canonicalFilePath(); - if (fileReadable(dataDirFromPath)) { - return dataDirFromPath; - } - } - - const QStringList correctedStandardLocations(correctStandardLocations(privateName, location, extraLocation)); - for(const QString &dir : correctedStandardLocations) { - fullPath = QFileInfo(dir + QLatin1Char('/') + path).canonicalFilePath(); - if (fileReadable(fullPath)) { - return fullPath; - } - } - return QString(); -} + const QString &extraLocation); /*! @brief Registers icons resource file * @param privateName Name to be used instead of application name for resource lookup @@ -133,37 +84,7 @@ bool registerIconsResource(const QString &privateName, const QString& path, QStandardPaths::StandardLocation location, const QString &resourceRoot, const QString &extraLocation, - QString *errorMessage, QString *detailedErrorMessage) -{ - const QString fullPath = locateFile(privateName, path, location, extraLocation); - if (fullPath.isEmpty() || !QFileInfo(fullPath).isReadable() - || !QResource::registerResource(fullPath, resourceRoot)) - { - QStringList triedLocations(QStandardPaths::standardLocations(location)); - if (!extraLocation.isEmpty()) { - triedLocations.append(extraLocation); - } - triedLocations.append(correctStandardLocations(privateName, location, extraLocation)); - const QString triedLocationsString = QLocale().createSeparatedList(triedLocations); -#ifdef QT_ONLY - *errorMessage = QString("Could not open icon resource file %1.").arg(path); - *detailedErrorMessage = QString("Tried to find in %1.").arg(triedLocationsString); -#else - //! @todo 3.1 Re-add translation - *errorMessage = /*QObject::tr*/ QString::fromLatin1( - "Could not open icon resource file \"%1\". " - "Application will not start. " - "Please check if it is properly installed.") - .arg(QFileInfo(path).fileName()); - //! @todo 3.1 Re-add translation - *detailedErrorMessage = QString::fromLatin1("Tried to find in %1.").arg(triedLocationsString); -#endif - return false; - } - *errorMessage = QString(); - *detailedErrorMessage = QString(); - return true; -} + QString *errorMessage, QString *detailedErrorMessage); /*! @brief Registers a global icon resource file * @param themeName A name of icon theme to use. @@ -173,49 +94,16 @@ */ bool registerGlobalIconsResource(const QString &themeName, QString *errorMessage, - QString *detailedErrorMessage) -{ - QString extraLocation; -#ifdef CMAKE_INSTALL_FULL_ICONDIR - extraLocation = QDir::fromNativeSeparators(QFile::decodeName(CMAKE_INSTALL_FULL_ICONDIR)); - if (extraLocation.endsWith("/icons")) { - extraLocation.chop(QLatin1String("/icons").size()); - } -#elif defined(Q_OS_WIN) - extraLocation = QCoreApplication::applicationDirPath() + QStringLiteral("/data"); -#endif - return registerIconsResource(QString(), QString::fromLatin1("icons/%1/%1-icons.rcc").arg(themeName), - QStandardPaths::GenericDataLocation, - QStringLiteral("/icons/") + themeName, - extraLocation, errorMessage, - detailedErrorMessage); -} + QString *detailedErrorMessage); /*! @brief Registers a global icon resource file * @param themeName A name of icon theme to use. */ -bool registerGlobalIconsResource(const QString &themeName) -{ - QString errorMessage; - QString detailedErrorMessage; - if (!registerGlobalIconsResource(themeName, &errorMessage, &detailedErrorMessage)) { - if (detailedErrorMessage.isEmpty()) { - KMessageBox::error(nullptr, errorMessage); - } else { - KMessageBox::detailedError(nullptr, errorMessage, detailedErrorMessage); - } - qWarning() << qPrintable(errorMessage); - return false; - } - return true; -} +bool registerGlobalIconsResource(const QString &themeName); /*! @brief Registers a global icon resource file for default theme name. */ -bool registerGlobalIconsResource() -{ - return registerGlobalIconsResource(supportedIconTheme); -} +bool registerGlobalIconsResource(); /*! @brief Sets up a private icon resource file * @return @c false on failure and sets error message. Does not warn or exit on failure. @@ -231,34 +119,7 @@ bool setupPrivateIconsResource(const QString &privateName, const QString& path, const QString &themeName, QString *errorMessage, QString *detailedErrorMessage, - const QString &prefix = QLatin1String(":/icons")) -{ - // Register application's resource first to have priority over the theme. - // Some icons may exists in both resources. - if (!registerIconsResource(privateName, path, - QStandardPaths::AppDataLocation, - QString(), QString(), errorMessage, detailedErrorMessage)) - { - return false; - } - bool changeTheme = false; -#ifdef QT_GUI_LIB - QIcon::setThemeSearchPaths(QStringList() << prefix << QIcon::themeSearchPaths()); - changeTheme = 0 != QIcon::themeName().compare(themeName, Qt::CaseInsensitive); - if (changeTheme) { - QIcon::setThemeName(themeName); - } -#endif - - KConfigGroup cg(KSharedConfig::openConfig(), "Icons"); - changeTheme = changeTheme || 0 != cg.readEntry("Theme", QString()).compare(themeName, Qt::CaseInsensitive); - // tell KIconLoader an co. about the theme - if (changeTheme) { - cg.writeEntry("Theme", themeName); - cg.sync(); - } - return true; -} + const QString &prefix = QLatin1String(":/icons")); /*! @brief Sets up a private icon resource file * @return @c false on failure and sets error message. @@ -274,20 +135,7 @@ bool setupPrivateIconsResourceWithMessage(const QString &privateName, const QString& path, const QString &themeName, QString *errorMessage, QString *detailedErrorMessage, - const QString &prefix = QLatin1String(":/icons")) -{ - if (!setupPrivateIconsResource(privateName, path, themeName, - errorMessage, detailedErrorMessage, prefix)) - { - if (detailedErrorMessage->isEmpty()) { - KMessageBox::error(nullptr, *errorMessage); - } else { - KMessageBox::detailedError(nullptr, *errorMessage, *detailedErrorMessage); - } - return false; - } - return true; -} + const QString &prefix = QLatin1String(":/icons")); /*! @overload setupPrivateIconsResourceWithMessage(QString &privateName, const QString& path, const QString &themeName, @@ -297,11 +145,7 @@ */ bool setupPrivateIconsResourceWithMessage(const QString &privateName, const QString& path, QString *errorMessage, QString *detailedErrorMessage, - const QString &prefix = QLatin1String(":/icons")) -{ - return setupPrivateIconsResourceWithMessage(privateName, path, supportedIconTheme, - errorMessage, detailedErrorMessage, prefix); -} + const QString &prefix = QLatin1String(":/icons")); /*! @brief Sets up a private icon resource file * Warns on failure and returns @c false. @@ -314,46 +158,15 @@ */ bool setupPrivateIconsResourceWithMessage(const QString &privateName, const QString& path, QtMsgType messageType, - const QString &prefix = QLatin1String(":/icons")) -{ - QString errorMessage; - QString detailedErrorMessage; - if (!setupPrivateIconsResourceWithMessage(privateName, path, - &errorMessage, &detailedErrorMessage, prefix)) { - if (messageType == QtFatalMsg) { - qFatal("%s %s", qPrintable(errorMessage), qPrintable(detailedErrorMessage)); - } else { - qWarning() << qPrintable(errorMessage) << qPrintable(detailedErrorMessage); - } - return false; - } - return true; -} + const QString &prefix = QLatin1String(":/icons")); //! Sets up a global icon theme if it is different from supported. //! Warns on failure and returns @c false. -bool setupGlobalIconTheme() -{ - if (0 != QIcon::themeName().compare(supportedIconTheme, Qt::CaseInsensitive)) { - const QString message = QString::fromLatin1( - "\"%1\" supports only \"%2\" icon theme but current system theme is \"%3\". " - "Application's icon theme will be changed to \"%2\". " - "Please consider adding support for other themes to %4.") - .arg(QLatin1String(KREPORT_BASE_NAME)).arg(supportedIconTheme).arg(QIcon::themeName()) - .arg(QCoreApplication::applicationName()); - qDebug() << qPrintable(message); - if (!registerGlobalIconsResource()) { - // don't fail, just warn - const QString message = QString::fromLatin1( - "Failed to set icon theme to \"%1\". Icons in the application will be inconsistent. " - "Please install .rcc file(s) for the system theme.") - .arg(supportedIconTheme); - qDebug() << qPrintable(message); - return false; - } - } - return true; -} +bool setupGlobalIconTheme(); + +int dpiX(); + +int dpiY(); } // KReportPrivate diff --git a/src/common/KReportUtils_p.h b/src/common/KReportUtils_p.cpp copy from src/common/KReportUtils_p.h copy to src/common/KReportUtils_p.cpp --- a/src/common/KReportUtils_p.h +++ 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) 2016 Adam Pigg This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public @@ -17,44 +17,60 @@ Boston, MA 02110-1301, USA. */ -#ifndef KREPORTUTILS_P_H -#define KREPORTUTILS_P_H +#include "KReportUtils_p.h" +#include "config-kreport.h" -#include +#ifdef Q_OS_WIN +#define KPATH_SEPARATOR ';' +#else +#define KPATH_SEPARATOR ':' +#endif -#include -#include -#include +class KReportDpiSingleton +{ +public: + KReportDpiSingleton(); -#include -#include -#include -#include -#include -#include -#include + int m_dpiX; + int m_dpiY; +}; -// This is a private code made inline for use in the lib and examples. -//! @todo Move to a shared lib to use in other Kexi libraries as well. +KReportDpiSingleton::KReportDpiSingleton() +{ + // Another way to get the DPI of the display would be QPaintDeviceMetrics, + // but we have no widget here (and moving this to KoView wouldn't allow + // using this from the document easily). +#ifdef Q_WS_X11 + m_dpiX = QX11Info::appDpiX(); + m_dpiY = QX11Info::appDpiY(); +#else + QDesktopWidget *w = QApplication::desktop(); + if (w) { + m_dpiX = w->logicalDpiX(); + m_dpiY = w->logicalDpiY(); + } else { + m_dpiX = 75; + m_dpiY = 75; + } +#endif +} + +Q_GLOBAL_STATIC(KReportDpiSingleton, s_instance) -namespace KReportPrivate { -//! @todo Support other themes -const QString supportedIconTheme = QLatin1String("breeze"); -//! @brief @return true if @a path is readable +namespace KReportPrivate +{ + bool fileReadable(const QString &path) { return !path.isEmpty() && QFileInfo(path).isReadable(); } -//! @brief Used for a workaround: locations for QStandardPaths::AppDataLocation end with app name. -//! If this is not an expected app but for example a test app, replace -//! the subdir name with app name so we can find resource file(s). QStringList correctStandardLocations(const QString &privateName, QStandardPaths::StandardLocation location, const QString &extraLocation) -{ + { QStringList result; if (!privateName.isEmpty()) { QRegularExpression re(QLatin1Char('/') + QCoreApplication::applicationName() + QLatin1Char('$')); @@ -73,19 +89,6 @@ return result; } -#ifdef Q_OS_WIN -#define KPATH_SEPARATOR ';' -#else -#define KPATH_SEPARATOR ':' -#endif - -/*! @brief Locates a file path for specified parameters - * @param privateName Name to be used instead of application name for resource lookup - * @param path Relative path to the resource file - * @param location Standard file location to use for file lookup - * @param extraLocation Extra directory path for file lookup - * @return Empty string on failure - */ QString locateFile(const QString &privateName, const QString& path, QStandardPaths::StandardLocation location, const QString &extraLocation) @@ -121,15 +124,6 @@ return QString(); } -/*! @brief Registers icons resource file - * @param privateName Name to be used instead of application name for resource lookup - * @param path Relative path to the resource file - * @param location Standard file location to use for file lookup - * @param resourceRoot A resource root for QResource::registerResource() - * @param errorMessage On failure it is set to a brief error message. - * @param errorDescription On failure it is set to a detailed error message. - * other for warning - */ bool registerIconsResource(const QString &privateName, const QString& path, QStandardPaths::StandardLocation location, const QString &resourceRoot, const QString &extraLocation, @@ -165,12 +159,6 @@ return true; } -/*! @brief Registers a global icon resource file - * @param themeName A name of icon theme to use. - * @param errorMessage On failure it is set to a brief error message. - * @param errorDescription On failure it is set to a detailed error message. - * other for warning - */ bool registerGlobalIconsResource(const QString &themeName, QString *errorMessage, QString *detailedErrorMessage) @@ -191,9 +179,6 @@ detailedErrorMessage); } -/*! @brief Registers a global icon resource file - * @param themeName A name of icon theme to use. - */ bool registerGlobalIconsResource(const QString &themeName) { QString errorMessage; @@ -210,28 +195,15 @@ return true; } -/*! @brief Registers a global icon resource file for default theme name. - */ bool registerGlobalIconsResource() { return registerGlobalIconsResource(supportedIconTheme); } -/*! @brief Sets up a private icon resource file - * @return @c false on failure and sets error message. Does not warn or exit on failure. - * @param privateName Name to be used instead of application name for resource lookup - * @param path Relative path to the resource file - * @param themeName Icon theme to use. It affects filename. - * @param errorMessage On failure it is set to a brief error message - * @param errorDescription On failure it is set to a detailed error message - * other for warning - * @param prefix Resource path prefix. The default is useful for library-global resource, - * other values is useful for plugins. - */ bool setupPrivateIconsResource(const QString &privateName, const QString& path, const QString &themeName, QString *errorMessage, QString *detailedErrorMessage, - const QString &prefix = QLatin1String(":/icons")) + const QString &prefix) { // Register application's resource first to have priority over the theme. // Some icons may exists in both resources. @@ -260,21 +232,10 @@ return true; } -/*! @brief Sets up a private icon resource file - * @return @c false on failure and sets error message. - * @param privateName Name to be used instead of application name for resource lookup - * @param path Relative path to the resource file - * @param themeName Icon theme to use. It affects filename. - * @param errorMessage On failure it is set to a brief error message. - * @param errorDescription On failure it is set to a detailed error message. - * other for warning - * @param prefix Resource path prefix. The default is useful for library-global resource, - * other values is useful for plugins. - */ bool setupPrivateIconsResourceWithMessage(const QString &privateName, const QString& path, const QString &themeName, QString *errorMessage, QString *detailedErrorMessage, - const QString &prefix = QLatin1String(":/icons")) + const QString &prefix) { if (!setupPrivateIconsResource(privateName, path, themeName, errorMessage, detailedErrorMessage, prefix)) @@ -289,32 +250,17 @@ return true; } -/*! @overload setupPrivateIconsResourceWithMessage(QString &privateName, const QString& path, - const QString &themeName, - QString *errorMessage, QString *detailedErrorMessage, - const QString &prefix = QLatin1String(":/icons")) - Uses default theme name. - */ bool setupPrivateIconsResourceWithMessage(const QString &privateName, const QString& path, QString *errorMessage, QString *detailedErrorMessage, - const QString &prefix = QLatin1String(":/icons")) + const QString &prefix) { return setupPrivateIconsResourceWithMessage(privateName, path, supportedIconTheme, errorMessage, detailedErrorMessage, prefix); } -/*! @brief Sets up a private icon resource file - * Warns on failure and returns @c false. - * @param privateName Name to be used instead of application name for resource lookup - * @param path Relative path to the resource file - * @param messageType Type of message to use on error, QtFatalMsg for fatal exit and any - * other for warning - * @param prefix Resource path prefix. The default is useful for library-global resource, - * other values is useful for plugins. - */ bool setupPrivateIconsResourceWithMessage(const QString &privateName, const QString& path, QtMsgType messageType, - const QString &prefix = QLatin1String(":/icons")) + const QString &prefix) { QString errorMessage; QString detailedErrorMessage; @@ -330,8 +276,6 @@ return true; } -//! Sets up a global icon theme if it is different from supported. -//! Warns on failure and returns @c false. bool setupGlobalIconTheme() { if (0 != QIcon::themeName().compare(supportedIconTheme, Qt::CaseInsensitive)) { @@ -355,6 +299,14 @@ return true; } -} // KReportPrivate +int dpiX() +{ + return s_instance->m_dpiX; +} -#endif +int dpiY() +{ + return s_instance->m_dpiY; +} + +} diff --git a/src/renderer/KReportPage.cpp b/src/renderer/KReportPage.cpp --- a/src/renderer/KReportPage.cpp +++ b/src/renderer/KReportPage.cpp @@ -20,7 +20,7 @@ #include "KReportRendererBase.h" #include "KReportUnit.h" #include "KReportRenderObjects.h" -#include "KReportDpi.h" +#include "KReportUtils_p.h" #include "kreport_debug.h" #include @@ -63,8 +63,8 @@ QString pageSize = d->reportDocument->pageLayout().pageSize().name(); - pageWidth = d->reportDocument->pageLayout().fullRectPixels(KReportDpi::dpiX()).width(); - pageHeight = d->reportDocument->pageLayout().fullRectPixels(KReportDpi::dpiX()).height(); + pageWidth = d->reportDocument->pageLayout().fullRectPixels(KReportPrivate::dpiX()).width(); + pageHeight = d->reportDocument->pageLayout().fullRectPixels(KReportPrivate::dpiX()).height(); //TODO remove after check #if 0 diff --git a/src/renderer/KReportPreRenderer.cpp b/src/renderer/KReportPreRenderer.cpp --- a/src/renderer/KReportPreRenderer.cpp +++ b/src/renderer/KReportPreRenderer.cpp @@ -28,7 +28,7 @@ #include "KReportDetailSectionData.h" #include "KReportLabelSizeInfo.h" #include "KReportPageSize.h" -#include "KReportDpi.h" +#include "KReportUtils_p.h" #ifdef KREPORT_SCRIPTING #include "scripting/KReportScriptHandler.h" @@ -292,7 +292,7 @@ qreal KReportPreRendererPrivate::renderSectionSize(const KReportSectionData & sectionData) { - qreal intHeight = POINT_TO_INCH(sectionData.height()) * KReportDpi::dpiX(); + qreal intHeight = POINT_TO_INCH(sectionData.height()) * KReportPrivate::dpiX(); int itemHeight = 0; @@ -321,7 +321,7 @@ qreal KReportPreRendererPrivate::renderSection(const KReportSectionData & sectionData) { - qreal sectionHeight = POINT_TO_INCH(sectionData.height()) * KReportDpi::dpiX(); + qreal sectionHeight = POINT_TO_INCH(sectionData.height()) * KReportPrivate::dpiX(); int itemHeight = 0; //kreportDebug() << "Name: " << sectionData.name() << " Height: " << sectionHeight @@ -339,7 +339,7 @@ ORORect* bg = new ORORect(); bg->setPen(QPen(Qt::NoPen)); bg->setBrush(sectionData.backgroundColor()); - qreal w = m_page->document()->pageLayout().fullRectPixels(KReportDpi::dpiX()).width() - m_page->document()->pageLayout().marginsPixels(KReportDpi::dpiX()).right() - m_leftMargin; + qreal w = m_page->document()->pageLayout().fullRectPixels(KReportPrivate::dpiX()).width() - m_page->document()->pageLayout().marginsPixels(KReportPrivate::dpiX()).right() - m_leftMargin; bg->setRect(QRectF(m_leftMargin, m_yOffset, w, sectionHeight)); m_page->insertPrimitive(bg, true); @@ -460,7 +460,7 @@ m_reportDocument->pageLayout().setPageSize(QPageSize(KReportPageSize::pageSize(label.paper()))); } else { // lookup the correct size information for the specified size paper - QSizeF pageSizePx = m_reportDocument->pageLayout().fullRectPixels(KReportDpi::dpiX()).size(); + QSizeF pageSizePx = m_reportDocument->pageLayout().fullRectPixels(KReportPrivate::dpiX()).size(); m_maxWidth = pageSizePx.width(); m_maxHeight = pageSizePx.height(); diff --git a/src/renderer/KReportPrintRenderer_p.cpp b/src/renderer/KReportPrintRenderer_p.cpp --- a/src/renderer/KReportPrintRenderer_p.cpp +++ b/src/renderer/KReportPrintRenderer_p.cpp @@ -20,7 +20,7 @@ #include "kreport_debug.h" #include "KReportRenderObjects.h" #include "KReportPageSize.h" -#include "KReportDpi.h" +#include "KReportUtils_p.h" #include #include @@ -80,8 +80,8 @@ if (toPage == 0 || toPage > document->pageCount()) toPage = document->pageCount(); - qreal scaleX = context.printer()->resolution() / qreal(KReportDpi::dpiX()); - qreal scaleY = context.printer()->resolution() / qreal(KReportDpi::dpiY()); + qreal scaleX = context.printer()->resolution() / qreal(KReportPrivate::dpiX()); + qreal scaleY = context.printer()->resolution() / qreal(KReportPrivate::dpiY()); for (int copy = 0; copy < context.printer()->numCopies(); copy++) { diff --git a/src/renderer/odtframe/KoOdtFrameReportDocument.cpp b/src/renderer/odtframe/KoOdtFrameReportDocument.cpp --- a/src/renderer/odtframe/KoOdtFrameReportDocument.cpp +++ b/src/renderer/odtframe/KoOdtFrameReportDocument.cpp @@ -99,12 +99,12 @@ void KoOdtFrameReportDocument::createStyles(KoGenStyles *coll) { // convert to inches - qreal pw = m_pageOptions.widthPx() / KReportDpi::dpiX(); - qreal ph = m_pageOptions.heightPx() / KReportDpi::dpiY(); - qreal topMargin = m_pageOptions.getMarginTop() / KReportDpi::dpiY(); - qreal bottomMargin = m_pageOptions.getMarginBottom() / KReportDpi::dpiY(); - qreal leftMargin = m_pageOptions.getMarginLeft() / KReportDpi::dpiX(); - qreal rightMargin = m_pageOptions.getMarginRight() / KReportDpi::dpiX(); + qreal pw = m_pageOptions.widthPx() / KReportPrivate::dpiX(); + qreal ph = m_pageOptions.heightPx() / KReportPrivate::dpiY(); + qreal topMargin = m_pageOptions.getMarginTop() / KReportPrivate::dpiY(); + qreal bottomMargin = m_pageOptions.getMarginBottom() / KReportPrivate::dpiY(); + qreal leftMargin = m_pageOptions.getMarginLeft() / KReportPrivate::dpiX(); + qreal rightMargin = m_pageOptions.getMarginRight() / KReportPrivate::dpiX(); QString orientation = m_pageOptions.isPortrait() ? "portrait" : "landscape"; //kreportDebug()<<"Page:"<startPoint().x() / KReportDpi::dpiX()); - qreal sy = INCH_TO_POINT(line()->startPoint().y() / KReportDpi::dpiY()); - qreal ex = INCH_TO_POINT(line()->endPoint().x() / KReportDpi::dpiX()); - qreal ey = INCH_TO_POINT(line()->endPoint().y() / KReportDpi::dpiY()); + qreal sx = INCH_TO_POINT(line()->startPoint().x() / KReportPrivate::dpiX()); + qreal sy = INCH_TO_POINT(line()->startPoint().y() / KReportPrivate::dpiY()); + qreal ex = INCH_TO_POINT(line()->endPoint().x() / KReportPrivate::dpiX()); + qreal ey = INCH_TO_POINT(line()->endPoint().y() / KReportPrivate::dpiY()); qreal width = ex - sx; qreal height = ey - sy; diff --git a/src/renderer/odtframe/KoOdtFrameReportPrimitive.cpp b/src/renderer/odtframe/KoOdtFrameReportPrimitive.cpp --- a/src/renderer/odtframe/KoOdtFrameReportPrimitive.cpp +++ b/src/renderer/odtframe/KoOdtFrameReportPrimitive.cpp @@ -88,10 +88,10 @@ void KoOdtFrameReportPrimitive::commonAttributes(KoXmlWriter *bodyWriter) const { // convert to inches - qreal x = m_primitive->position().x() / KReportDpi::dpiX(); - qreal y = m_primitive->position().y() / KReportDpi::dpiX(); - qreal w = m_primitive->size().width() / KReportDpi::dpiX(); - qreal h = m_primitive->size().height() / KReportDpi::dpiY(); + qreal x = m_primitive->position().x() / KReportPrivate::dpiX(); + qreal y = m_primitive->position().y() / KReportPrivate::dpiX(); + qreal w = m_primitive->size().width() / KReportPrivate::dpiX(); + qreal h = m_primitive->size().height() / KReportPrivate::dpiY(); bodyWriter->addAttribute("svg:x", QString("%1in").arg(x)); bodyWriter->addAttribute("svg:y", QString("%1in").arg(y)); diff --git a/src/wrtembed/KReportDesigner.cpp b/src/wrtembed/KReportDesigner.cpp --- a/src/wrtembed/KReportDesigner.cpp +++ b/src/wrtembed/KReportDesigner.cpp @@ -29,7 +29,7 @@ #include "KReportRuler_p.h" #include "KReportZoomHandler.h" #include "KReportPageSize.h" -#include "KReportDpi.h" +#include "KReportUtils_p.h" #include "KReportUtils.h" #include "KReportPluginInterface.h" #include "KReportPluginManager.h" @@ -868,11 +868,11 @@ 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(); + QSize pageSizePx = layout.fullRectPixels(KReportPrivate::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(); + width = width - POINT_TO_INCH(d->set->property("margin-left").value().toDouble()) * KReportPrivate::dpiX(); + width = width - POINT_TO_INCH(d->set->property("margin-right").value().toDouble()) * KReportPrivate::dpiX(); return width; } diff --git a/src/wrtembed/KReportDesignerItemRectBase.cpp b/src/wrtembed/KReportDesignerItemRectBase.cpp --- a/src/wrtembed/KReportDesignerItemRectBase.cpp +++ b/src/wrtembed/KReportDesignerItemRectBase.cpp @@ -20,7 +20,7 @@ #include "KReportDesignerSectionView.h" #include "KReportDesigner.h" #include "KReportDesignerSectionScene.h" -#include "KReportDpi.h" +#include "KReportUtils_p.h" #include #include @@ -46,8 +46,8 @@ KReportDesignerItemRectBase::KReportDesignerItemRectBase(KReportDesigner *r, KReportItemBase *b) : QGraphicsRectItem(), KReportDesignerItemBase(r, b), d(new KReportDesignerItemRectBase::Private) { - m_dpiX = KReportDpi::dpiX(); - m_dpiY = KReportDpi::dpiY(); + m_dpiX = KReportPrivate::dpiX(); + m_dpiY = KReportPrivate::dpiY(); d->grabAction = 0; setAcceptHoverEvents(true); diff --git a/src/wrtembed/KReportDesignerSection.cpp b/src/wrtembed/KReportDesignerSection.cpp --- a/src/wrtembed/KReportDesignerSection.cpp +++ b/src/wrtembed/KReportDesignerSection.cpp @@ -30,7 +30,7 @@ #include "KReportDesignerItemLine.h" #include "KReportRuler_p.h" #include "KReportZoomHandler.h" -#include "KReportDpi.h" +#include "KReportUtils_p.h" #include "KReportPluginMetaData.h" #include "kreport_debug.h" @@ -106,7 +106,7 @@ connect(d->sectionData->propertySet(), SIGNAL(propertyChanged(KPropertySet&,KProperty&)), this, SLOT(slotPropertyChanged(KPropertySet&,KProperty&))); - d->dpiY = KReportDpi::dpiY(); + d->dpiY = KReportPrivate::dpiY(); d->reportDesigner = rptdes; setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); diff --git a/src/wrtembed/KReportDesignerSectionScene.cpp b/src/wrtembed/KReportDesignerSectionScene.cpp --- a/src/wrtembed/KReportDesignerSectionScene.cpp +++ b/src/wrtembed/KReportDesignerSectionScene.cpp @@ -20,7 +20,7 @@ #include "KReportDesignerItemRectBase.h" #include "KReportDesigner.h" #include "KReportLabelSizeInfo.h" -#include "KReportDpi.h" +#include "KReportUtils_p.h" #include "kreport_debug.h" #include @@ -33,8 +33,8 @@ { m_rd = rd; m_minorSteps = 0; - m_dpiX = KReportDpi::dpiX(); - m_dpiY = KReportDpi::dpiY(); + m_dpiX = KReportPrivate::dpiX(); + m_dpiY = KReportPrivate::dpiY(); if (m_unit.type() != m_rd->pageUnit().type()) { m_unit = m_rd->pageUnit(); @@ -87,7 +87,7 @@ 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; + //kreportDebug() << "dpix" << KReportPrivate::dpiX() << "dpiy" << KReportPrivate::dpiY() << "mayorx:" << majorx << "majory" << majory << "pix:" << pixel_incrementx << "piy:" << pixel_incrementy; QVector lines; QVector points; diff --git a/src/wrtembed/KReportDpi.h b/src/wrtembed/KReportDpi.h deleted file mode 100644 --- a/src/wrtembed/KReportDpi.h +++ /dev/null @@ -1,41 +0,0 @@ -/* This file is part of the KDE project - Copyright (C) 1998, 1999 Torben Weis - Copyright 2002, 2003 David Faure - Copyright 2003 Nicolas GOUTTE - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. -*/ - -#ifndef KREPORT_DPI_h -#define KREPORT_DPI_h - - -#include "kreport_export.h" - -/** - * Singleton to store user-overwritten DPI information. - */ -namespace KReportDpi -{ - KREPORT_EXPORT int dpiX(); - - KREPORT_EXPORT int dpiY(); - - /// @internal, for KoApplication - KREPORT_EXPORT void setDpi(int x, int y); -} - -#endif // KREPORT_DPI_h diff --git a/src/wrtembed/KReportDpi.cpp b/src/wrtembed/KReportDpi.cpp deleted file mode 100644 --- a/src/wrtembed/KReportDpi.cpp +++ /dev/null @@ -1,83 +0,0 @@ -/* This file is part of the KDE project - Copyright (C) 2001 David Faure - Copyright 2003 Nicolas GOUTTE - Copyright 2009 Thomas Zander - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. -*/ - -#include "KReportDpi.h" - -#ifdef Q_WS_X11 -#include -#else -#include -#include -#endif -#include - - -class KReportDpiSingleton -{ -public: - KReportDpiSingleton(); - - int m_dpiX; - int m_dpiY; -}; - -KReportDpiSingleton::KReportDpiSingleton() -{ - // Another way to get the DPI of the display would be QPaintDeviceMetrics, - // but we have no widget here (and moving this to KoView wouldn't allow - // using this from the document easily). -#ifdef Q_WS_X11 - m_dpiX = QX11Info::appDpiX(); - m_dpiY = QX11Info::appDpiY(); -#else - QDesktopWidget *w = QApplication::desktop(); - if (w) { - m_dpiX = w->logicalDpiX(); - m_dpiY = w->logicalDpiY(); - } else { - m_dpiX = 75; - m_dpiY = 75; - } -#endif -} - -Q_GLOBAL_STATIC(KReportDpiSingleton, s_instance) - -namespace KReportDpi -{ - -int dpiX() -{ - return s_instance->m_dpiX; -} - -int dpiY() -{ - return s_instance->m_dpiY; -} - -void setDpi(int x, int y) -{ - s_instance->m_dpiX = x; - s_instance->m_dpiY = y; -} - -} diff --git a/src/wrtembed/KReportZoomHandler.cpp b/src/wrtembed/KReportZoomHandler.cpp --- a/src/wrtembed/KReportZoomHandler.cpp +++ b/src/wrtembed/KReportZoomHandler.cpp @@ -21,7 +21,7 @@ #include "KReportZoomHandler.h" #include "KReportUnit.h" // for POINT_TO_INCH -#include "KReportDpi.h" +#include "KReportUtils_p.h" #include #include @@ -36,16 +36,16 @@ { setZoom(1.0); setZoomMode( KReportZoomMode::ZOOM_CONSTANT ); - setDpi(KReportDpi::dpiX(), KReportDpi::dpiY()); + setDpi(KReportPrivate::dpiX(), KReportPrivate::dpiY()); } KReportZoomHandler::~KReportZoomHandler() { } void KReportZoomHandler::setResolutionToStandard() { - setDpi(KReportDpi::dpiX(), KReportDpi::dpiY()); + setDpi(KReportPrivate::dpiX(), KReportPrivate::dpiY()); } void KReportZoomHandler::setDpi(int dpiX, int dpiY)