mirror of
https://github.com/linuxdeepin/dde-dock.git
synced 2025-06-03 00:15:21 +00:00
fix: 修复任务栏概率性获取不到图标的问题
采用qtxdg-iconfinder命令查找图标的文件,然后直接读取文件 Log: 修复任务栏安装应用后图标小概率显示为齿轮的问题 Bug: https://pms.uniontech.com/zentao/bug-view-80456.html Change-Id: Ibd534c42d8991a8f8918fe31c73ed00c871cc285
This commit is contained in:
parent
331cf7c749
commit
07b6a455eb
3
debian/control
vendored
3
debian/control
vendored
@ -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),
|
||||
|
@ -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))
|
||||
|
@ -32,6 +32,7 @@
|
||||
#include <QDate>
|
||||
#include <QPainter>
|
||||
#include <QStandardPaths>
|
||||
#include <QProcess>
|
||||
|
||||
#include <private/qguiapplication_p.h>
|
||||
#include <private/qiconloader_p.h>
|
||||
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user