From 3cc3ccb5a3c251d52da3dc698fdd653060e87a0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=9F=B3=E5=8D=9A=E6=96=87?= Date: Thu, 22 Feb 2018 14:19:52 +0800 Subject: [PATCH] support attention Change-Id: I5caf72dc3575294205e60bdb77897bf18500a7f5 --- frame/item/appitem.cpp | 26 ++++++++++++++++------ frame/item/appitem.h | 3 ++- frame/item/components/appsnapshot.cpp | 18 ++++++++++----- frame/item/components/appsnapshot.h | 8 +++++-- frame/item/components/previewcontainer.cpp | 2 +- 5 files changed, 41 insertions(+), 16 deletions(-) diff --git a/frame/item/appitem.cpp b/frame/item/appitem.cpp index e6e7b3645..5cbeaa863 100644 --- a/frame/item/appitem.cpp +++ b/frame/item/appitem.cpp @@ -158,6 +158,7 @@ AppItem::AppItem(const QDBusObjectPath &entry, QWidget *parent) m_updateIconGeometryTimer->setSingleShot(true); m_appPreviewTips->setVisible(false); + m_itemEntryInter->setSync(false); connect(m_itemEntryInter, &DockEntryInter::IsActiveChanged, this, &AppItem::activeChanged); connect(m_itemEntryInter, &DockEntryInter::IsActiveChanged, this, static_cast(&AppItem::update)); @@ -171,7 +172,7 @@ AppItem::AppItem(const QDBusObjectPath &entry, QWidget *parent) connect(m_appPreviewTips, &PreviewContainer::requestCancelAndHidePreview, this, &AppItem::cancelAndHidePreview); connect(m_appPreviewTips, &PreviewContainer::requestCheckWindows, m_itemEntryInter, &DockEntryInter::Check); - updateWindowInfos(); + updateWindowInfos(m_itemEntryInter->windowInfos()); refershIcon(); } @@ -283,9 +284,12 @@ void AppItem::paintEvent(QPaintEvent *e) painter.fillRect(activeRect, QColor(44, 167, 248, 255)); } else if (!m_windowInfos.isEmpty()) - painter.fillRect(backgroundRect, QColor(255, 255, 255, 255 * 0.2)); - // else - // painter.fillRect(backgroundRect, Qt::gray); + { + if (hasAttention()) + painter.fillRect(backgroundRect, QColor(241, 138, 46, 255 * .8)); + else + painter.fillRect(backgroundRect, QColor(255, 255, 255, 255 * 0.2)); + } } else { @@ -524,7 +528,7 @@ QWidget *AppItem::popupTips() { const quint32 currentWindow = m_itemEntryInter->currentWindow(); Q_ASSERT(m_windowInfos.contains(currentWindow)); - m_appNameTips->setText(m_windowInfos[currentWindow].m_windowTitle); + m_appNameTips->setText(m_windowInfos[currentWindow].title); } else { m_appNameTips->setText(m_itemEntryInter->name()); } @@ -557,9 +561,17 @@ void AppItem::startDrag() update(); } -void AppItem::updateWindowInfos() +bool AppItem::hasAttention() const { - m_windowInfos = m_itemEntryInter->windowInfos(); + for (const auto &info : m_windowInfos) + if (info.attention) + return true; + return false; +} + +void AppItem::updateWindowInfos(const WindowInfoMap &info) +{ + m_windowInfos = info; m_appPreviewTips->setWindowInfos(m_windowInfos); m_updateIconGeometryTimer->start(); diff --git a/frame/item/appitem.h b/frame/item/appitem.h index 536ad788a..30fefa063 100644 --- a/frame/item/appitem.h +++ b/frame/item/appitem.h @@ -74,9 +74,10 @@ private: QWidget *popupTips(); void startDrag(); + bool hasAttention() const; private slots: - void updateWindowInfos(); + void updateWindowInfos(const WindowInfoMap &info); void refershIcon(); void activeChanged(); void showPreview(); diff --git a/frame/item/components/appsnapshot.cpp b/frame/item/components/appsnapshot.cpp index ad337e21e..f1f6e6a16 100644 --- a/frame/item/components/appsnapshot.cpp +++ b/frame/item/components/appsnapshot.cpp @@ -87,12 +87,13 @@ void AppSnapshot::compositeChanged() const const bool composite = m_wmHelper->hasComposite(); m_title->setVisible(!composite); -// m_closeBtn->setVisible(!composite); } -void AppSnapshot::setWindowTitle(const QString &title) +void AppSnapshot::setWindowInfo(const WindowInfo &info) { - m_title->setText(title); + m_windowInfo = info; + + m_title->setText(m_windowInfo.title); } void AppSnapshot::dragEnterEvent(QDragEnterEvent *e) @@ -181,6 +182,7 @@ void AppSnapshot::paintEvent(QPaintEvent *e) QWidget::paintEvent(e); QPainter painter(this); + painter.setRenderHint(QPainter::Antialiasing); if (!m_wmHelper->hasComposite()) { @@ -195,9 +197,15 @@ void AppSnapshot::paintEvent(QPaintEvent *e) const QRect r = rect().marginsRemoved(QMargins(8, 8, 8, 8)); const auto ratio = devicePixelRatioF(); + // draw attention background + if (m_windowInfo.attention) + { + painter.setBrush(QColor(241, 138, 46, 255 * .8)); + painter.setPen(Qt::NoPen); + painter.drawRoundedRect(rect(), 5, 5); + } + // draw image -// QImage im = m_snapshot.scaled(r.size() * ratio, Qt::KeepAspectRatio, Qt::SmoothTransformation); -// im.setDevicePixelRatio(ratio); const QImage &im = m_snapshot; const QRect ir = im.rect(); diff --git a/frame/item/components/appsnapshot.h b/frame/item/components/appsnapshot.h index 36a3ecedc..d82a21204 100644 --- a/frame/item/components/appsnapshot.h +++ b/frame/item/components/appsnapshot.h @@ -30,6 +30,8 @@ #include #include +#include + DWIDGET_USE_NAMESPACE #define SNAP_WIDTH 200 @@ -43,8 +45,9 @@ public: explicit AppSnapshot(const WId wid, QWidget *parent = 0); WId wid() const { return m_wid; } + bool attentioned() const { return m_windowInfo.attention; } const QImage snapshot() const { return m_snapshot; } - const QString title() const { return m_title->text(); } + const QString title() const { return m_windowInfo.title; } signals: void entered(const WId wid) const; @@ -55,7 +58,7 @@ public slots: void fetchSnapshot(); void closeWindow() const; void compositeChanged() const; - void setWindowTitle(const QString &title); + void setWindowInfo(const WindowInfo &info); private: void dragEnterEvent(QDragEnterEvent *e); @@ -67,6 +70,7 @@ private: private: const WId m_wid; + WindowInfo m_windowInfo; QImage m_snapshot; QLabel *m_title; DImageButton *m_closeBtn; diff --git a/frame/item/components/previewcontainer.cpp b/frame/item/components/previewcontainer.cpp index caf9ed0f4..3b0256016 100644 --- a/frame/item/components/previewcontainer.cpp +++ b/frame/item/components/previewcontainer.cpp @@ -74,7 +74,7 @@ void PreviewContainer::setWindowInfos(const WindowInfoMap &infos) { if (!m_snapshots.contains(it.key())) appendSnapWidget(it.key()); - m_snapshots[it.key()]->setWindowTitle(it.value().m_windowTitle); + m_snapshots[it.key()]->setWindowInfo(it.value()); } if (m_snapshots.isEmpty())