From bcfca76bbc4308e398ecaed82baea72a22255628 Mon Sep 17 00:00:00 2001 From: deepin-ci-robot Date: Wed, 13 Dec 2023 08:02:02 +0000 Subject: [PATCH] sync: from linuxdeepin/dtkgui Synchronize source files from linuxdeepin/dtkgui. Source-pull-request: https://github.com/linuxdeepin/dtkgui/pull/211 --- src/util/private/diconproxyengine.cpp | 2 +- src/util/private/xdgiconproxyengine.cpp | 10 +++++++++- src/util/private/xdgiconproxyengine_p.h | 4 +++- src/util/util.cmake | 9 ++++----- tests/src/ut_xdgiconproxyengine.cpp | 5 ++++- 5 files changed, 21 insertions(+), 9 deletions(-) diff --git a/src/util/private/diconproxyengine.cpp b/src/util/private/diconproxyengine.cpp index 2ca63dd..2406c5c 100644 --- a/src/util/private/diconproxyengine.cpp +++ b/src/util/private/diconproxyengine.cpp @@ -18,7 +18,7 @@ #include #include -#if XDG_ICON_VERSION_MAR >= 3 +#if (XDG_ICON_VERSION_MAR >= 3) #define private public #include #undef private diff --git a/src/util/private/xdgiconproxyengine.cpp b/src/util/private/xdgiconproxyengine.cpp index 9b296cb..534fafc 100644 --- a/src/util/private/xdgiconproxyengine.cpp +++ b/src/util/private/xdgiconproxyengine.cpp @@ -243,8 +243,11 @@ void XdgIconProxyEngine::paint(QPainter *painter, const QRect &rect, QIcon::Mode QPixmap XdgIconProxyEngine::pixmap(const QSize &size, QIcon::Mode mode, QIcon::State state) { engine->ensureLoaded(); - +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) QIconLoaderEngineEntry *entry = engine->entryForSize(size); +#else + QIconLoaderEngineEntry *entry = engine->entryForSize(engine->m_info ,size); +#endif if (!entry) { DEEPIN_XDG_THEME::colorScheme.setLocalData(DEEPIN_XDG_THEME::PALETTE_MAP()); @@ -299,7 +302,12 @@ void XdgIconProxyEngine::virtual_hook(int id, void *data) QIconEngine::ScaledPixmapArgument &arg = *reinterpret_cast(data); // QIcon::pixmap() multiplies size by the device pixel ratio. const int integerScale = qCeil(arg.scale); + +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) QIconLoaderEngineEntry *entry = engine->entryForSize(arg.size / integerScale, integerScale); +#else + QIconLoaderEngineEntry *entry = engine->entryForSize(engine->m_info, arg.size / integerScale, integerScale); +#endif // 先禁用缩放,因为此size是已经缩放过的 bool useHighDpiPixmap = qGuiApp->testAttribute(Qt::AA_UseHighDpiPixmaps); qGuiApp->setAttribute(Qt::AA_UseHighDpiPixmaps, false); diff --git a/src/util/private/xdgiconproxyengine_p.h b/src/util/private/xdgiconproxyengine_p.h index d00f184..30a340b 100644 --- a/src/util/private/xdgiconproxyengine_p.h +++ b/src/util/private/xdgiconproxyengine_p.h @@ -6,6 +6,7 @@ #define XDGICONPROXYENGINE_H #include +#include #if XDG_ICON_VERSION_MAR >= 3 #include @@ -25,7 +26,8 @@ struct ScalableEntry; class QIconLoaderEngineEntry; class XdgIconLoaderEngine; DGUI_BEGIN_NAMESPACE -#if XDG_ICON_VERSION_MAR >= 3 + +#if (XDG_ICON_VERSION_MAR >= 3) class Q_DECL_HIDDEN XdgIconProxyEngine : public QIconEngine { public: diff --git a/src/util/util.cmake b/src/util/util.cmake index 4c62960..cfaa7fc 100644 --- a/src/util/util.cmake +++ b/src/util/util.cmake @@ -1,10 +1,9 @@ if(NOT DTK_DISABLE_LIBXDG) message("Enable libxdg!") -# find_package(qt${QT_VERSION_MAJOR}xdgiconloader) -if (Qt5_FOUND) - find_package(qt5xdgiconloader) - add_definitions(-DXDG_ICON_VERSION_MAR=${qt5xdgiconloader_VERSION_MAJOR}) -endif() + find_package(qt${QT_VERSION_MAJOR}xdgiconloader) + + add_definitions(-DXDG_ICON_VERSION_MAR=${qt${QT_VERSION_MAJOR}xdgiconloader_VERSION_MAJOR}) + set(UTIL_PRIVATE ${CMAKE_CURRENT_LIST_DIR}/private/xdgiconproxyengine_p.h ${CMAKE_CURRENT_LIST_DIR}/private/xdgiconproxyengine.cpp diff --git a/tests/src/ut_xdgiconproxyengine.cpp b/tests/src/ut_xdgiconproxyengine.cpp index 92c2e92..5bc1585 100644 --- a/tests/src/ut_xdgiconproxyengine.cpp +++ b/tests/src/ut_xdgiconproxyengine.cpp @@ -89,8 +89,11 @@ TEST_F(ut_XdgIconProxyEngine, pixmapByEntry) QPalette pa = qApp->palette(); // ensureLoaded EXPECT_EQ(s64, mIconEngine->actualSize(s64, QIcon::Normal, QIcon::On)); - +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) QIconLoaderEngineEntry *entry = mIconEngine->engine->entryForSize(s64); +#else + QIconLoaderEngineEntry *entry = mIconEngine->engine->entryForSize(mIconEngine->engine->m_info, s64); +#endif ASSERT_TRUE(entry); QPixmap normalPix = mIconEngine->pixmapByEntry(entry, s64, QIcon::Normal, QIcon::On);