From 07b6a455ebb9ea9be23fe1f247d1a7c0e0d96284 Mon Sep 17 00:00:00 2001 From: FanPengCheng Date: Wed, 26 May 2021 10:50:43 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E4=BB=BB=E5=8A=A1?= =?UTF-8?q?=E6=A0=8F=E6=A6=82=E7=8E=87=E6=80=A7=E8=8E=B7=E5=8F=96=E4=B8=8D?= =?UTF-8?q?=E5=88=B0=E5=9B=BE=E6=A0=87=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 采用qtxdg-iconfinder命令查找图标的文件,然后直接读取文件 Log: 修复任务栏安装应用后图标小概率显示为齿轮的问题 Bug: https://pms.uniontech.com/zentao/bug-view-80456.html Change-Id: Ibd534c42d8991a8f8918fe31c73ed00c871cc285 --- debian/control | 3 ++- frame/item/appitem.cpp | 2 +- frame/util/themeappicon.cpp | 35 ++++++++++++++++++++++++++++------- 3 files changed, 31 insertions(+), 9 deletions(-) diff --git a/debian/control b/debian/control index b026ccaf6..882aab70e 100644 --- a/debian/control +++ b/debian/control @@ -38,7 +38,8 @@ Depends: ${shlibs:Depends}, ${misc:Depends}, dde-qt5xcb-plugin (>=5.0.19), dde-daemon (>=5.12.0.31), startdde (>=5.6.0.34), - lastore-daemon (>=5.1.0.21) + lastore-daemon (>=5.1.0.21), + qtxdg-dev-tools Recommends: dde-disk-mount-plugin, dde-dock-onboard-plugin Conflicts: dde-workspace (<< 2.90.5), diff --git a/frame/item/appitem.cpp b/frame/item/appitem.cpp index b9ce7e238..c1b4818ab 100644 --- a/frame/item/appitem.cpp +++ b/frame/item/appitem.cpp @@ -60,7 +60,7 @@ AppItem::AppItem(const QGSettings *appSettings, const QGSettings *activeAppSetti , m_drag(nullptr) , m_dragging(false) , m_retryTimes(0) - , m_iconValid(false) + , m_iconValid(true) , m_lastclickTimes(0) , m_appIcon(QPixmap()) , m_updateIconGeometryTimer(new QTimer(this)) diff --git a/frame/util/themeappicon.cpp b/frame/util/themeappicon.cpp index 1a06f1214..7f026afb9 100644 --- a/frame/util/themeappicon.cpp +++ b/frame/util/themeappicon.cpp @@ -32,6 +32,7 @@ #include #include #include +#include #include #include @@ -182,18 +183,38 @@ ThemeAppIcon::~ThemeAppIcon() * @brief ThemeAppIcon::getIcon 根据传入的\a name 参数重新从系统主题中获取一次图标 * @param name 图标名 * @return 获取到的图标 - * @note 之所以不使用QIcon::fromTheme是因为这个函数中有缓存机制,获取系统主题中的图标的时候,第一次获取不到,下一次也是获取不到 + * @note 只有在正常查找图标失败时,才走这个逻辑,如果直接使用QIcon::fromTheme可以获取到图标,是没必要的 */ QIcon ThemeAppIcon::getIcon(const QString &name) { - QPlatformTheme * const platformTheme = QGuiApplicationPrivate::platformTheme(); - bool hasUserTheme = QIconLoader::instance()->hasUserTheme(); + //TODO 这里找图标会耗时,界面轻微卡顿,后面有时间可以放到AppItem里面,单独开启线程去查找 + auto getIconList = [ = ] (const QString &iconName) { + QProcess process; + process.start("qtxdg-iconfinder", QStringList() << iconName); + process.closeWriteChannel(); + process.waitForFinished(); - if (!platformTheme || hasUserTheme) - return QIcon::fromTheme(name); + int exitCode = process.exitCode(); + QString outputTxt = process.readAllStandardOutput(); - QIconEngine * const engine = platformTheme->createIconEngine(name); - return QIcon(engine); + auto list = outputTxt.split("\n"); + + if (exitCode != 0 || list.size() <= 3) + return QStringList() << ""; + + // 去掉无用数据 + list.removeFirst(); + list.removeLast(); + list.removeLast(); + + for (auto &s : list) { + s = s.simplified(); + } + + return list; + }; + + return QIcon::fromTheme(getIconList(name).first()); } bool ThemeAppIcon::getIcon(QPixmap &pix, const QString iconName, const int size, bool reObtain)