Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sync: from linuxdeepin/dtkgui #10

Merged
merged 1 commit into from
Dec 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/util/private/diconproxyengine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#include <QDir>

#include <private/qiconloader_p.h>
#if XDG_ICON_VERSION_MAR >= 3
#if (XDG_ICON_VERSION_MAR >= 3)
#define private public
#include <private/xdgiconloader/xdgiconloader_p.h>
#undef private
Expand Down
10 changes: 9 additions & 1 deletion src/util/private/xdgiconproxyengine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -299,7 +302,12 @@ void XdgIconProxyEngine::virtual_hook(int id, void *data)
QIconEngine::ScaledPixmapArgument &arg = *reinterpret_cast<QIconEngine::ScaledPixmapArgument *>(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);
Expand Down
4 changes: 3 additions & 1 deletion src/util/private/xdgiconproxyengine_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#define XDGICONPROXYENGINE_H

#include <dtkgui_global.h>
#include <QHash>

#if XDG_ICON_VERSION_MAR >= 3
#include <QIconEngine>
Expand All @@ -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:
Expand Down
9 changes: 4 additions & 5 deletions src/util/util.cmake
Original file line number Diff line number Diff line change
@@ -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
Expand Down
5 changes: 4 additions & 1 deletion tests/src/ut_xdgiconproxyengine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down