From 41882bba9aa82c1f7ca079c700cf96643d6bdaf0 Mon Sep 17 00:00:00 2001 From: yeshanshan Date: Fri, 17 Oct 2025 14:25:50 +0800 Subject: [PATCH 1/2] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8DDTK=E6=90=9C?= =?UTF-8?q?=E7=B4=A2=E6=A1=86=E5=9B=BE=E6=A0=87=E9=A2=9C=E8=89=B2=E4=B8=8D?= =?UTF-8?q?=E8=B7=9F=E9=9A=8F=E4=B8=BB=E9=A2=98=E5=8F=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit from gerrit/develop/eagle in qt5integration. 466143d3a4cf40b0e95d4d1adf988a8b9c44eddd 9d60ce5c90cc7a7131434adb0a2bcc048f4e9515 2d88e02dfefcfc0b9e112e528d7586656923ba37 fix: 修复DTK搜索框图标颜色不跟随主题变化 图标引擎修改,在绘制pixmap前先填充颜色 Log: 修复DTK搜索框图标颜色不跟随主题变化 Bug: https://pms.uniontech.com/bug-view-200405.html https://pms.uniontech.com/bug-view-231425.html Influence: DTK内置图标绘制 Change-Id: Ib6869cdb331005794661dbd076c60cd5ae0f41df --- src/util/private/dbuiltiniconengine.cpp | 35 ++++++++++++++++++------- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/src/util/private/dbuiltiniconengine.cpp b/src/util/private/dbuiltiniconengine.cpp index d85cec42..3a138379 100644 --- a/src/util/private/dbuiltiniconengine.cpp +++ b/src/util/private/dbuiltiniconengine.cpp @@ -101,6 +101,23 @@ class Q_DECL_HIDDEN ImageEntry : public QIconLoaderEngineEntry QImageReader reader; }; +static QPixmap compositedPixmap(QIcon::Mode mode, QPixmap &pm, QIconLoaderEngineEntry *entry, QPainter *painter = nullptr) { + ImageEntry::Type type = static_cast(entry)->type; + if (type == ImageEntry::TextType || (type == ImageEntry::ActionType && mode != QIcon::Normal)) { + QPainter pa(&pm); + QColor color; + pa.setCompositionMode(QPainter::CompositionMode_SourceIn); + if (painter) { + color = painter->pen().brush().color(); + } else { + auto palette = qApp->palette(); + color = (mode == QIcon::Selected) ? palette.highlightedText().color() : palette.windowText().color(); + } + pa.fillRect(pm.rect(), color); + } + return pm; +} + class Q_DECL_HIDDEN DirImageEntry : public ImageEntry { public: @@ -219,12 +236,14 @@ QPixmap DBuiltinIconEngine::pixmap(const QSize &size, QIcon::Mode mode, ensureLoaded(); QIconLoaderEngineEntry *entry = QIconLoaderEngine::entryForSize(m_info, size); - if (entry) + if (entry) { #if QT_VERSION >= QT_VERSION_CHECK(6, 8, 0) - return entry->pixmap(size, mode, state, devicePixelRatio(nullptr)); + auto pm = entry->pixmap(size, mode, state, devicePixelRatio(nullptr)); #else - return entry->pixmap(size, mode, state); + auto pm = entry->pixmap(size, mode, state); #endif + return compositedPixmap(mode, pm, entry); + } return QPixmap(); } @@ -253,12 +272,7 @@ void DBuiltinIconEngine::paint(QPainter *painter, const QRect &rect, #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); - pa.setCompositionMode(QPainter::CompositionMode_SourceIn); - pa.fillRect(pm.rect(), painter->pen().brush()); - } + pm = compositedPixmap(mode, pm, entry, painter); pm.setDevicePixelRatio(scale); painter->drawPixmap(rect, pm); @@ -442,6 +456,9 @@ void DBuiltinIconEngine::virtual_hook(int id, void *data) arg.pixmap = entry ? entry->pixmap(arg.size, arg.mode, arg.state, arg.scale) : QPixmap(); #else arg.pixmap = entry ? entry->pixmap(arg.size, arg.mode, arg.state) : QPixmap(); + if (!arg.pixmap.isNull()) { + arg.pixmap = compositedPixmap(arg.mode, arg.pixmap, entry); + } #endif } break; From 0ab3a1a9842e16f12820e241ac371b5715cbc9b6 Mon Sep 17 00:00:00 2001 From: yeshanshan Date: Fri, 17 Oct 2025 14:33:40 +0800 Subject: [PATCH 2/2] =?UTF-8?q?fix:=20=E6=B2=A1=E6=9C=89=E5=8C=B9=E9=85=8D?= =?UTF-8?q?=E6=9C=80=E4=BD=B3=E5=B0=BA=E5=AF=B8=E7=9A=84=E5=9B=BE=E6=A0=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 3b5ab7a: fix: 没有匹配最佳尺寸的图标 原因:存在同名不同尺寸svg图标时,Scalable类型的图标会使用maxSize和minSize去找合适的图标 ,找到的不一定是最佳尺寸,绘图的时候会进行缩放,导致图标线条变粗/变细 解决方案:在使用entryForSize查找图标之前,先找一下是否有尺寸完全匹配的图标 Log: Influence: dtk内建图标(所有使用dtk内建图标的都会有影响) Change-Id: I158283516b067cc0a81654dee8c6657f54b9a56f --- src/util/private/dbuiltiniconengine.cpp | 26 ++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/src/util/private/dbuiltiniconengine.cpp b/src/util/private/dbuiltiniconengine.cpp index 3a138379..e84e090c 100644 --- a/src/util/private/dbuiltiniconengine.cpp +++ b/src/util/private/dbuiltiniconengine.cpp @@ -248,6 +248,22 @@ QPixmap DBuiltinIconEngine::pixmap(const QSize &size, QIcon::Mode mode, return QPixmap(); } +static QIconLoaderEngineEntry *perfectEntryForSize(const QThemeIconInfo &info, const QSize &size, qreal scale = 1) +{ + const int numEntries = info.entries.size(); + const int iconsize = qMin(size.width(), size.height()); + for (int i = 0; i < numEntries; ++i) { + const auto &entry = info.entries.at(i); + if (static_cast(entry->dir.size * scale) == iconsize) +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + return entry.get(); +#else + return info.entries.at(i); +#endif + } + return nullptr; +} + void DBuiltinIconEngine::paint(QPainter *painter, const QRect &rect, QIcon::Mode mode, QIcon::State state) { @@ -256,9 +272,13 @@ void DBuiltinIconEngine::paint(QPainter *painter, const QRect &rect, const qreal scale = devicePixelRatio(painter); QSize pixmapSize = rect.size() * scale; - QIconLoaderEngineEntry *entry = QIconLoaderEngine::entryForSize(m_info, pixmapSize); - if (!entry) - return; + // Search perfect entry first + QIconLoaderEngineEntry *entry = perfectEntryForSize(m_info, pixmapSize, scale); + if (!entry) { + entry = QIconLoaderEngine::entryForSize(m_info, pixmapSize); + if (!entry) + return; + } // 如果有 background 则绘制背景图先 QString bgFileName = entry->filename + QStringLiteral(".background");