mirror of
https://github.com/linuxdeepin/dde-dock.git
synced 2025-06-03 00:15:21 +00:00
appitem: make fetch icon asynchronous
Change-Id: I89c32ccddc7529df75c24ddc4beef83a89037fe5
This commit is contained in:
parent
9715df2428
commit
a5b044e585
Notes:
Deepin Code Review
2017-06-15 18:47:43 +08:00
Verified+1: Anonymous Coward #1000004 Code-Review+2: 石博文 <sbw@sbw.so> Submitted-by: 石博文 <sbw@sbw.so> Submitted-at: Thu, 15 Jun 2017 18:47:41 +0800 Reviewed-on: https://cr.deepin.io/23862 Project: dde/dde-dock Branch: refs/heads/master
@ -1,7 +1,7 @@
|
||||
|
||||
include(../interfaces/interfaces.pri)
|
||||
|
||||
QT += core gui widgets dbus x11extras svg
|
||||
QT += core gui widgets dbus x11extras svg concurrent
|
||||
|
||||
TARGET = dde-dock
|
||||
DESTDIR = $$_PRO_FILE_PWD_/../
|
||||
|
@ -15,6 +15,9 @@
|
||||
#include <QGraphicsScene>
|
||||
#include <QGraphicsItemAnimation>
|
||||
#include <QTimeLine>
|
||||
#include <QFuture>
|
||||
#include <QFutureWatcher>
|
||||
#include <QtConcurrent>
|
||||
|
||||
#define APP_DRAG_THRESHOLD 20
|
||||
|
||||
@ -86,8 +89,10 @@ 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);
|
||||
|
||||
updateTitle();
|
||||
refershIcon();
|
||||
QTimer::singleShot(1, this, [=] {
|
||||
updateTitle();
|
||||
refershIcon();
|
||||
});
|
||||
}
|
||||
|
||||
AppItem::~AppItem()
|
||||
@ -474,16 +479,24 @@ void AppItem::refershIcon()
|
||||
const QString icon = m_itemEntry->icon();
|
||||
const int iconSize = qMin(width(), height());
|
||||
|
||||
QFutureWatcher<QPixmap> *smallWatcher = new QFutureWatcher<QPixmap>(this);
|
||||
QFutureWatcher<QPixmap> *largeWatcher = new QFutureWatcher<QPixmap>(this);
|
||||
|
||||
if (DockDisplayMode == Efficient)
|
||||
{
|
||||
m_smallIcon = ThemeAppIcon::getIcon(icon, iconSize * 0.7);
|
||||
m_largeIcon = ThemeAppIcon::getIcon(icon, iconSize * 0.9);
|
||||
// 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));
|
||||
} else {
|
||||
m_smallIcon = ThemeAppIcon::getIcon(icon, iconSize * 0.6);
|
||||
m_largeIcon = ThemeAppIcon::getIcon(icon, iconSize * 0.8);
|
||||
// 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));
|
||||
}
|
||||
|
||||
update();
|
||||
connect(smallWatcher, &QFutureWatcher<QPixmap>::finished, this, &AppItem::gotSmallIcon);
|
||||
connect(largeWatcher, &QFutureWatcher<QPixmap>::finished, this, &AppItem::gotLargeIcon);
|
||||
|
||||
m_updateIconGeometryTimer->start();
|
||||
}
|
||||
@ -517,3 +530,27 @@ void AppItem::showPreview()
|
||||
|
||||
showPopupWindow(m_appPreviewTips, true);
|
||||
}
|
||||
|
||||
void AppItem::gotSmallIcon()
|
||||
{
|
||||
QFutureWatcher<QPixmap> *fw = dynamic_cast<QFutureWatcher<QPixmap> *>(sender());
|
||||
Q_ASSERT(fw);
|
||||
|
||||
m_smallIcon = fw->result();
|
||||
|
||||
fw->deleteLater();
|
||||
|
||||
update();
|
||||
}
|
||||
|
||||
void AppItem::gotLargeIcon()
|
||||
{
|
||||
QFutureWatcher<QPixmap> *fw = dynamic_cast<QFutureWatcher<QPixmap> *>(sender());
|
||||
Q_ASSERT(fw);
|
||||
|
||||
m_largeIcon = fw->result();
|
||||
|
||||
fw->deleteLater();
|
||||
|
||||
update();
|
||||
}
|
||||
|
@ -8,6 +8,7 @@
|
||||
|
||||
#include <QGraphicsView>
|
||||
#include <QGraphicsItem>
|
||||
#include <QFuture>
|
||||
|
||||
class AppItem : public DockItem
|
||||
{
|
||||
@ -56,6 +57,9 @@ private slots:
|
||||
void activeChanged();
|
||||
void showPreview();
|
||||
|
||||
void gotSmallIcon();
|
||||
void gotLargeIcon();
|
||||
|
||||
private:
|
||||
QLabel *m_appNameTips;
|
||||
_PreviewContainer *m_appPreviewTips;
|
||||
|
@ -14,7 +14,7 @@ ThemeAppIcon::~ThemeAppIcon()
|
||||
|
||||
}
|
||||
|
||||
const QPixmap ThemeAppIcon::getIcon(const QString iconName, const int size)
|
||||
QPixmap ThemeAppIcon::getIcon(const QString iconName, const int size)
|
||||
{
|
||||
const int s = size & ~1;
|
||||
|
||||
|
@ -10,7 +10,7 @@ public:
|
||||
explicit ThemeAppIcon(QObject *parent = 0);
|
||||
~ThemeAppIcon();
|
||||
|
||||
static const QPixmap getIcon(const QString iconName, const int size);
|
||||
static QPixmap getIcon(const QString iconName, const int size);
|
||||
};
|
||||
|
||||
#endif // THEMEAPPICON_H
|
||||
|
Loading…
x
Reference in New Issue
Block a user