diff --git a/frame/item/appitem.cpp b/frame/item/appitem.cpp index fc7c39a95..c492c6bd5 100644 --- a/frame/item/appitem.cpp +++ b/frame/item/appitem.cpp @@ -44,7 +44,10 @@ AppItem::AppItem(const QDBusObjectPath &entry, QWidget *parent) m_verticalIndicator(QPixmap(":/indicator/resources/indicator_ver.png")), m_activeHorizontalIndicator(QPixmap(":/indicator/resources/indicator_active.png")), m_activeVerticalIndicator(QPixmap(":/indicator/resources/indicator_active_ver.png")), - m_updateIconGeometryTimer(new QTimer(this)) + m_updateIconGeometryTimer(new QTimer(this)), + + m_smallWatcher(new QFutureWatcher(this)), + m_largeWatcher(new QFutureWatcher(this)) { QHBoxLayout *centralLayout = new QHBoxLayout; centralLayout->addWidget(m_itemView); @@ -93,6 +96,9 @@ AppItem::AppItem(const QDBusObjectPath &entry, QWidget *parent) connect(m_appPreviewTips, &_PreviewContainer::requestHidePreview, this, &AppItem::hidePopup, Qt::QueuedConnection); connect(m_appPreviewTips, &_PreviewContainer::requestCheckWindows, m_itemEntry, &DBusDockEntry::Check); + connect(m_smallWatcher, &QFutureWatcher::finished, this, &AppItem::gotSmallIcon); + connect(m_largeWatcher, &QFutureWatcher::finished, this, &AppItem::gotLargeIcon); + QTimer::singleShot(1, this, [=] { updateTitle(); refershIcon(); @@ -486,25 +492,22 @@ void AppItem::refershIcon() const QString icon = m_itemEntry->icon(); const int iconSize = qMin(width(), height()); - QFutureWatcher *smallWatcher = new QFutureWatcher(this); - QFutureWatcher *largeWatcher = new QFutureWatcher(this); + m_smallWatcher->cancel(); + m_largeWatcher->cancel(); if (DockDisplayMode == Efficient) { // m_smallIcon = ThemeAppIcon::getIcon(icon, iconSize * 0.7); // m_largeIcon = ThemeAppIcon::getIcon(icon, iconSize * 0.9); - smallWatcher->setFuture(QtConcurrent::run(ThemeAppIcon::getIcon, icon, iconSize * 0.7)); - largeWatcher->setFuture(QtConcurrent::run(ThemeAppIcon::getIcon, icon, iconSize * 0.9)); + m_smallWatcher->setFuture(QtConcurrent::run(ThemeAppIcon::getIcon, icon, iconSize * 0.7)); + m_largeWatcher->setFuture(QtConcurrent::run(ThemeAppIcon::getIcon, icon, iconSize * 0.9)); } else { // m_smallIcon = ThemeAppIcon::getIcon(icon, iconSize * 0.6); // m_largeIcon = ThemeAppIcon::getIcon(icon, iconSize * 0.8); - smallWatcher->setFuture(QtConcurrent::run(ThemeAppIcon::getIcon, icon, iconSize * 0.6)); - largeWatcher->setFuture(QtConcurrent::run(ThemeAppIcon::getIcon, icon, iconSize * 0.8)); + m_smallWatcher->setFuture(QtConcurrent::run(ThemeAppIcon::getIcon, icon, iconSize * 0.6)); + m_largeWatcher->setFuture(QtConcurrent::run(ThemeAppIcon::getIcon, icon, iconSize * 0.8)); } - connect(smallWatcher, &QFutureWatcher::finished, this, &AppItem::gotSmallIcon); - connect(largeWatcher, &QFutureWatcher::finished, this, &AppItem::gotLargeIcon); - m_updateIconGeometryTimer->start(); } @@ -540,24 +543,14 @@ void AppItem::showPreview() void AppItem::gotSmallIcon() { - QFutureWatcher *fw = dynamic_cast *>(sender()); - Q_ASSERT(fw); - - m_smallIcon = fw->result(); - - fw->deleteLater(); + m_smallIcon = m_smallWatcher->result(); update(); } void AppItem::gotLargeIcon() { - QFutureWatcher *fw = dynamic_cast *>(sender()); - Q_ASSERT(fw); - - m_largeIcon = fw->result(); - - fw->deleteLater(); + m_largeIcon = m_largeWatcher->result(); update(); } diff --git a/frame/item/appitem.h b/frame/item/appitem.h index 97b5e75e6..59aaf9353 100644 --- a/frame/item/appitem.h +++ b/frame/item/appitem.h @@ -81,6 +81,9 @@ private: QTimer *m_updateIconGeometryTimer; + QFutureWatcher *m_smallWatcher; + QFutureWatcher *m_largeWatcher; + static int IconBaseSize; static QPoint MousePressPos; };