diff options
author | Michael Weghorn <m.weghorn@posteo.de> | 2024-07-24 08:59:36 +0200 |
---|---|---|
committer | Michael Weghorn <m.weghorn@posteo.de> | 2024-07-24 10:10:34 +0200 |
commit | 52f2edaa596159828b95313e55d8df3bb289aaee (patch) | |
tree | 72d5d955262ca869f2eb4d059d93448335de6319 /vcl | |
parent | 7de061883ddd185e5f36fe39cab0326d8a73b947 (diff) |
qt: Move resolution calc to static helper method
Instead of duplicating the same code in both,
`QtGraphics::GetResolution` and
`QtSvpGraphics::GetResolution`, create a static
helper method `QtGraphicsBase::ImplGetResolution`
in their base class and call that.
While at it, also move `QtGraphics::GetResolution`
to the source file where all of the other
`QtGraphics` methods are implemented.
Change-Id: I721459e8b65756f214fee77ac4d3cb8e500f0b57
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/170930
Tested-by: Jenkins
Reviewed-by: Michael Weghorn <m.weghorn@posteo.de>
Diffstat (limited to 'vcl')
-rw-r--r-- | vcl/Library_vclplug_qt5.mk | 1 | ||||
-rw-r--r-- | vcl/Library_vclplug_qt6.mk | 1 | ||||
-rw-r--r-- | vcl/inc/qt5/QtGraphicsBase.hxx | 7 | ||||
-rw-r--r-- | vcl/qt5/QtGraphics.cxx | 5 | ||||
-rw-r--r-- | vcl/qt5/QtGraphicsBase.cxx | 33 | ||||
-rw-r--r-- | vcl/qt5/QtGraphics_GDI.cxx | 20 | ||||
-rw-r--r-- | vcl/qt5/QtSvpGraphics.cxx | 16 | ||||
-rw-r--r-- | vcl/qt6/QtGraphicsBase.cxx | 12 |
8 files changed, 60 insertions, 35 deletions
diff --git a/vcl/Library_vclplug_qt5.mk b/vcl/Library_vclplug_qt5.mk index f29090d9dd9d..14782ca89dc3 100644 --- a/vcl/Library_vclplug_qt5.mk +++ b/vcl/Library_vclplug_qt5.mk @@ -87,6 +87,7 @@ $(eval $(call gb_Library_add_exception_objects,vclplug_qt5,\ vcl/qt5/QtFontFace \ vcl/qt5/QtFrame \ vcl/qt5/QtGraphics \ + vcl/qt5/QtGraphicsBase \ vcl/qt5/QtGraphics_Controls \ vcl/qt5/QtGraphics_GDI \ vcl/qt5/QtGraphics_Text \ diff --git a/vcl/Library_vclplug_qt6.mk b/vcl/Library_vclplug_qt6.mk index f8a2c38bb836..bf5c05eac189 100644 --- a/vcl/Library_vclplug_qt6.mk +++ b/vcl/Library_vclplug_qt6.mk @@ -86,6 +86,7 @@ $(eval $(call gb_Library_add_exception_objects,vclplug_qt6,\ vcl/qt6/QtFontFace \ vcl/qt6/QtFrame \ vcl/qt6/QtGraphics \ + vcl/qt6/QtGraphicsBase \ vcl/qt6/QtGraphics_Controls \ vcl/qt6/QtGraphics_GDI \ vcl/qt6/QtGraphics_Text \ diff --git a/vcl/inc/qt5/QtGraphicsBase.hxx b/vcl/inc/qt5/QtGraphicsBase.hxx index 73c39fb5ba80..573f086439e3 100644 --- a/vcl/inc/qt5/QtGraphicsBase.hxx +++ b/vcl/inc/qt5/QtGraphicsBase.hxx @@ -9,8 +9,12 @@ #pragma once +#include "QtFrame.hxx" + #include <QtWidgets/QApplication> +#include <sal/types.h> + class QtGraphicsBase { qreal m_fDPR; @@ -24,6 +28,9 @@ public: void setDevicePixelRatioF(qreal fDPR) { m_fDPR = fDPR; } qreal devicePixelRatioF() const { return m_fDPR; } + +protected: + static void ImplGetResolution(QtFrame* pFrame, sal_Int32& rDPIX, sal_Int32& rDPIY); }; /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/qt5/QtGraphics.cxx b/vcl/qt5/QtGraphics.cxx index d809556ce219..5e2d3d38f46f 100644 --- a/vcl/qt5/QtGraphics.cxx +++ b/vcl/qt5/QtGraphics.cxx @@ -103,4 +103,9 @@ void QtGraphics::handleDamage(const tools::Rectangle& rDamagedRegion) aPainter.update(toQRect(rDamagedRegion)); } +void QtGraphics::GetResolution(sal_Int32& rDPIX, sal_Int32& rDPIY) +{ + QtGraphicsBase::ImplGetResolution(m_pFrame, rDPIX, rDPIY); +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/qt5/QtGraphicsBase.cxx b/vcl/qt5/QtGraphicsBase.cxx new file mode 100644 index 000000000000..dcaf84fe2eb9 --- /dev/null +++ b/vcl/qt5/QtGraphicsBase.cxx @@ -0,0 +1,33 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include <QtGraphicsBase.hxx> + +#include <QtGui/QScreen> + +#include <o3tl/string_view.hxx> + +void QtGraphicsBase::ImplGetResolution(QtFrame* pFrame, sal_Int32& rDPIX, sal_Int32& rDPIY) +{ + char* pForceDpi; + if ((pForceDpi = getenv("SAL_FORCEDPI"))) + { + rDPIX = rDPIY = o3tl::toInt32(std::string_view(pForceDpi)); + return; + } + + if (!pFrame) + return; + + QScreen* pScreen = pFrame->GetQWidget()->screen(); + rDPIX = pScreen->logicalDotsPerInchX() * pScreen->devicePixelRatio() + 0.5; + rDPIY = pScreen->logicalDotsPerInchY() * pScreen->devicePixelRatio() + 0.5; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/qt5/QtGraphics_GDI.cxx b/vcl/qt5/QtGraphics_GDI.cxx index 87c7fb85725b..bbfde8e1f22e 100644 --- a/vcl/qt5/QtGraphics_GDI.cxx +++ b/vcl/qt5/QtGraphics_GDI.cxx @@ -25,9 +25,6 @@ #include <sal/log.hxx> #include <QtGui/QPainter> -#include <QtGui/QScreen> -#include <QtGui/QWindow> -#include <QtWidgets/QWidget> #include <numeric> #include <basegfx/polygon/b2dpolygontools.hxx> @@ -690,21 +687,4 @@ bool QtGraphicsBackend::supportsOperation(OutDevSupportType eType) const } } -void QtGraphics::GetResolution(sal_Int32& rDPIX, sal_Int32& rDPIY) -{ - char* pForceDpi; - if ((pForceDpi = getenv("SAL_FORCEDPI"))) - { - rDPIX = rDPIY = o3tl::toInt32(std::string_view(pForceDpi)); - return; - } - - if (!m_pFrame) - return; - - QScreen* pScreen = m_pFrame->GetQWidget()->screen(); - rDPIX = pScreen->logicalDotsPerInchX() * pScreen->devicePixelRatio() + 0.5; - rDPIY = pScreen->logicalDotsPerInchY() * pScreen->devicePixelRatio() + 0.5; -} - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/qt5/QtSvpGraphics.cxx b/vcl/qt5/QtSvpGraphics.cxx index 7d0715be33c5..f84763105a74 100644 --- a/vcl/qt5/QtSvpGraphics.cxx +++ b/vcl/qt5/QtSvpGraphics.cxx @@ -21,8 +21,6 @@ #include <QtSvpSurface.hxx> #include <QtTools.hxx> -#include <QtGui/QScreen> -#include <QtGui/QWindow> #include <QtWidgets/QWidget> QtSvpGraphics::QtSvpGraphics(QtFrame* pFrame) @@ -96,19 +94,7 @@ void QtSvpGraphics::handleDamage(const tools::Rectangle& rDamagedRegion) void QtSvpGraphics::GetResolution(sal_Int32& rDPIX, sal_Int32& rDPIY) { - char* pForceDpi; - if ((pForceDpi = getenv("SAL_FORCEDPI"))) - { - rDPIX = rDPIY = o3tl::toInt32(std::string_view(pForceDpi)); - return; - } - - if (!m_pFrame) - return; - - QScreen* pScreen = m_pFrame->GetQWidget()->screen(); - rDPIX = pScreen->logicalDotsPerInchX() * pScreen->devicePixelRatio() + 0.5; - rDPIY = pScreen->logicalDotsPerInchY() * pScreen->devicePixelRatio() + 0.5; + QtGraphicsBase::ImplGetResolution(m_pFrame, rDPIX, rDPIY); } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/qt6/QtGraphicsBase.cxx b/vcl/qt6/QtGraphicsBase.cxx new file mode 100644 index 000000000000..c7d2d873ff85 --- /dev/null +++ b/vcl/qt6/QtGraphicsBase.cxx @@ -0,0 +1,12 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include "../qt5/QtGraphicsBase.cxx" + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |