From 8a36e7350d66b3e860e6c6a2300c9eec66924536 Mon Sep 17 00:00:00 2001 From: Albert Astals Cid Date: Thu, 27 Jan 2022 19:24:52 +0100 Subject: [PATCH] Make Utils::realDpi work on QWindow not on QWidget Small step towards the goal of okularcore not linking to QWidgets --- core/document.cpp | 3 ++- core/utils.cpp | 4 ++-- core/utils.h | 7 +++---- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/core/document.cpp b/core/document.cpp index ea125537e..cf784fe24 100644 --- a/core/document.cpp +++ b/core/document.cpp @@ -880,7 +880,8 @@ Document::OpenResult DocumentPrivate::openDocumentInternal(const KPluginMetaData QApplication::setOverrideCursor(Qt::WaitCursor); - const QSizeF dpi = Utils::realDpi(m_widget); + const QWindow *window = m_widget && m_widget->window() ? m_widget->window()->windowHandle() : nullptr; + const QSizeF dpi = Utils::realDpi(window); qCDebug(OkularCoreDebug) << "Output DPI:" << dpi; m_generator->setDPI(dpi); diff --git a/core/utils.cpp b/core/utils.cpp index 254a13bf2..d40d9447e 100644 --- a/core/utils.cpp +++ b/core/utils.cpp @@ -44,9 +44,9 @@ QRect Utils::rotateRect(const QRect source, int width, int height, int orientati return ret; } -QSizeF Utils::realDpi(QWidget *widgetOnScreen) +QSizeF Utils::realDpi(const QWindow *windowOnScreen) { - const QScreen *screen = widgetOnScreen && widgetOnScreen->window() && widgetOnScreen->window()->windowHandle() ? widgetOnScreen->window()->windowHandle()->screen() : qGuiApp->primaryScreen(); + const QScreen *screen = windowOnScreen ? windowOnScreen->screen() : qGuiApp->primaryScreen(); if (screen) { const QSizeF res(screen->physicalDotsPerInchX(), screen->physicalDotsPerInchY()); diff --git a/core/utils.h b/core/utils.h index 0691859da..b4e3e5a28 100644 --- a/core/utils.h +++ b/core/utils.h @@ -12,7 +12,6 @@ class QRect; class QImage; -class QWidget; namespace Okular { @@ -31,14 +30,14 @@ public: static QRect rotateRect(const QRect source, int width, int height, int orientation); /** - * Return the real DPI of the display containing given widget + * Return the real DPI of the display containing given window * * On X11, it can indicate the real horizontal DPI value without any Xrdb * setting. Otherwise, returns the same as realDpiX/Y(), * - * @since 0.19 (KDE 4.13) + * @since 22.04 */ - static QSizeF realDpi(QWidget *widgetOnScreen); + static QSizeF realDpi(const QWindow *windowOnScreen); /** * Compute the smallest rectangle that contains all non-white pixels in image),