From e21d9e4ea7be43334ba838b36dc395e9c759a2ff Mon Sep 17 00:00:00 2001 From: Hillwood Yang Date: Sat, 19 Oct 2024 22:07:11 +0800 Subject: [PATCH] feat: Support Qt 6.8 Log: Fix build on Qt 6.8 --- src/util/private/dbuiltiniconengine.cpp | 24 ++++++++++++++++++++++++ tests/src/ut_builtinengine.cpp | 4 ++++ 2 files changed, 28 insertions(+) diff --git a/src/util/private/dbuiltiniconengine.cpp b/src/util/private/dbuiltiniconengine.cpp index a71d7b20..9c8f5d4a 100644 --- a/src/util/private/dbuiltiniconengine.cpp +++ b/src/util/private/dbuiltiniconengine.cpp @@ -50,7 +50,11 @@ class Q_DECL_HIDDEN ImageEntry : public QIconLoaderEngineEntry } } +#if QT_VERSION >= QT_VERSION_CHECK(6, 8, 0) + QPixmap pixmap(const QSize &size, QIcon::Mode mode, QIcon::State state, qreal scale) override { +#else QPixmap pixmap(const QSize &size, QIcon::Mode mode, QIcon::State state) override { +#endif Q_UNUSED(state) QPixmap pm; @@ -111,7 +115,11 @@ class Q_DECL_HIDDEN DirImageEntry : public ImageEntry return dir.filePath("normal." + suffix); } +#if QT_VERSION >= QT_VERSION_CHECK(6, 8, 0) + QPixmap pixmap(const QSize &size, QIcon::Mode mode, QIcon::State state, qreal scale) override { +#else QPixmap pixmap(const QSize &size, QIcon::Mode mode, QIcon::State state) override { +#endif if (iconFileMap.isEmpty()) { const QString &suffix = QFileInfo(filename).suffix(); QDir dir(filename); @@ -128,7 +136,11 @@ class Q_DECL_HIDDEN DirImageEntry : public ImageEntry reader.setFileName(iconFileMap.value(mode << 8 | state)); +#if QT_VERSION >= QT_VERSION_CHECK(6, 8, 0) + return ImageEntry::pixmap(size, mode, state, scale); +#else return ImageEntry::pixmap(size, mode, state); +#endif } QMap iconFileMap; @@ -192,7 +204,11 @@ QPixmap DBuiltinIconEngine::pixmap(const QSize &size, QIcon::Mode mode, QIconLoaderEngineEntry *entry = QIconLoaderEngine::entryForSize(m_info, size); if (entry) +#if QT_VERSION >= QT_VERSION_CHECK(6, 8, 0) + return entry->pixmap(size, mode, state, 1.0); +#else return entry->pixmap(size, mode, state); +#endif return QPixmap(); } @@ -222,7 +238,11 @@ void DBuiltinIconEngine::paint(QPainter *painter, const QRect &rect, QIcon(bgFileName).paint(painter, rect, Qt::AlignCenter, mode, state); } +#if QT_VERSION >= QT_VERSION_CHECK(6, 8, 0) + QPixmap pm = entry->pixmap(pixmapSize, mode, state, 1.0); +#else QPixmap pm = entry->pixmap(pixmapSize, mode, state); +#endif ImageEntry::Type type = static_cast(entry)->type; if (type == ImageEntry::TextType || (type == ImageEntry::ActionType && mode != QIcon::Normal)) { QPainter pa(&pm); @@ -386,7 +406,11 @@ void DBuiltinIconEngine::virtual_hook(int id, void *data) // QIcon::pixmap() multiplies size by the device pixel ratio. const int integerScale = qCeil(arg.scale); QIconLoaderEngineEntry *entry = QIconLoaderEngine::entryForSize(m_info, arg.size / integerScale, integerScale); +#if QT_VERSION >= QT_VERSION_CHECK(6, 8, 0) + arg.pixmap = entry ? entry->pixmap(arg.size, arg.mode, arg.state, 1.0) : QPixmap(); +#else arg.pixmap = entry ? entry->pixmap(arg.size, arg.mode, arg.state) : QPixmap(); +#endif } break; default: diff --git a/tests/src/ut_builtinengine.cpp b/tests/src/ut_builtinengine.cpp index f729d7c4..c41242f3 100644 --- a/tests/src/ut_builtinengine.cpp +++ b/tests/src/ut_builtinengine.cpp @@ -60,7 +60,11 @@ TEST_F(ut_DBuiltinIconEngine, loadIcon) ASSERT_EQ(entry->dir.path, builtinActionPath); ASSERT_EQ(entry->dir.size, ICONSIZE); ASSERT_EQ(entry->dir.type, QIconDirInfo::Scalable); +#if QT_VERSION >= QT_VERSION_CHECK(6, 8, 0) + ASSERT_FALSE(entry->pixmap(QSize(ICONSIZE, ICONSIZE), QIcon::Normal, QIcon::On, 1.0).isNull()); +#else ASSERT_FALSE(entry->pixmap(QSize(ICONSIZE, ICONSIZE), QIcon::Normal, QIcon::On).isNull()); +#endif #if QT_VERSION < QT_VERSION_CHECK(6, 4, 0) for (auto item : themeInfo.entries) {