mirror of
https://github.com/linuxdeepin/dde-dock.git
synced 2025-06-04 17:33:05 +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)
|
include(../interfaces/interfaces.pri)
|
||||||
|
|
||||||
QT += core gui widgets dbus x11extras svg
|
QT += core gui widgets dbus x11extras svg concurrent
|
||||||
|
|
||||||
TARGET = dde-dock
|
TARGET = dde-dock
|
||||||
DESTDIR = $$_PRO_FILE_PWD_/../
|
DESTDIR = $$_PRO_FILE_PWD_/../
|
||||||
|
@ -15,6 +15,9 @@
|
|||||||
#include <QGraphicsScene>
|
#include <QGraphicsScene>
|
||||||
#include <QGraphicsItemAnimation>
|
#include <QGraphicsItemAnimation>
|
||||||
#include <QTimeLine>
|
#include <QTimeLine>
|
||||||
|
#include <QFuture>
|
||||||
|
#include <QFutureWatcher>
|
||||||
|
#include <QtConcurrent>
|
||||||
|
|
||||||
#define APP_DRAG_THRESHOLD 20
|
#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::requestHidePreview, this, &AppItem::hidePopup, Qt::QueuedConnection);
|
||||||
connect(m_appPreviewTips, &_PreviewContainer::requestCheckWindows, m_itemEntry, &DBusDockEntry::Check);
|
connect(m_appPreviewTips, &_PreviewContainer::requestCheckWindows, m_itemEntry, &DBusDockEntry::Check);
|
||||||
|
|
||||||
updateTitle();
|
QTimer::singleShot(1, this, [=] {
|
||||||
refershIcon();
|
updateTitle();
|
||||||
|
refershIcon();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
AppItem::~AppItem()
|
AppItem::~AppItem()
|
||||||
@ -474,16 +479,24 @@ void AppItem::refershIcon()
|
|||||||
const QString icon = m_itemEntry->icon();
|
const QString icon = m_itemEntry->icon();
|
||||||
const int iconSize = qMin(width(), height());
|
const int iconSize = qMin(width(), height());
|
||||||
|
|
||||||
|
QFutureWatcher<QPixmap> *smallWatcher = new QFutureWatcher<QPixmap>(this);
|
||||||
|
QFutureWatcher<QPixmap> *largeWatcher = new QFutureWatcher<QPixmap>(this);
|
||||||
|
|
||||||
if (DockDisplayMode == Efficient)
|
if (DockDisplayMode == Efficient)
|
||||||
{
|
{
|
||||||
m_smallIcon = ThemeAppIcon::getIcon(icon, iconSize * 0.7);
|
// m_smallIcon = ThemeAppIcon::getIcon(icon, iconSize * 0.7);
|
||||||
m_largeIcon = ThemeAppIcon::getIcon(icon, iconSize * 0.9);
|
// 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 {
|
} else {
|
||||||
m_smallIcon = ThemeAppIcon::getIcon(icon, iconSize * 0.6);
|
// m_smallIcon = ThemeAppIcon::getIcon(icon, iconSize * 0.6);
|
||||||
m_largeIcon = ThemeAppIcon::getIcon(icon, iconSize * 0.8);
|
// 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();
|
m_updateIconGeometryTimer->start();
|
||||||
}
|
}
|
||||||
@ -517,3 +530,27 @@ void AppItem::showPreview()
|
|||||||
|
|
||||||
showPopupWindow(m_appPreviewTips, true);
|
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 <QGraphicsView>
|
||||||
#include <QGraphicsItem>
|
#include <QGraphicsItem>
|
||||||
|
#include <QFuture>
|
||||||
|
|
||||||
class AppItem : public DockItem
|
class AppItem : public DockItem
|
||||||
{
|
{
|
||||||
@ -56,6 +57,9 @@ private slots:
|
|||||||
void activeChanged();
|
void activeChanged();
|
||||||
void showPreview();
|
void showPreview();
|
||||||
|
|
||||||
|
void gotSmallIcon();
|
||||||
|
void gotLargeIcon();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QLabel *m_appNameTips;
|
QLabel *m_appNameTips;
|
||||||
_PreviewContainer *m_appPreviewTips;
|
_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;
|
const int s = size & ~1;
|
||||||
|
|
||||||
|
@ -10,7 +10,7 @@ public:
|
|||||||
explicit ThemeAppIcon(QObject *parent = 0);
|
explicit ThemeAppIcon(QObject *parent = 0);
|
||||||
~ThemeAppIcon();
|
~ThemeAppIcon();
|
||||||
|
|
||||||
static const QPixmap getIcon(const QString iconName, const int size);
|
static QPixmap getIcon(const QString iconName, const int size);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // THEMEAPPICON_H
|
#endif // THEMEAPPICON_H
|
||||||
|
Loading…
x
Reference in New Issue
Block a user