From 687336c4b89452199922efb7f420e7b4c4f65035 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=9F=B3=E5=8D=9A=E6=96=87?= Date: Mon, 6 Jun 2016 14:28:28 +0800 Subject: [PATCH] add active state Change-Id: Id2f96995b4ed8143ae5fbb639daeecfd8b0b4ce7 --- item/appitem.cpp | 44 +++++++++++++++++++++++++++++++++++++++++++- item/appitem.h | 6 ++++++ 2 files changed, 49 insertions(+), 1 deletion(-) diff --git a/item/appitem.cpp b/item/appitem.cpp index 362b87b1f..1c1bd4d6e 100644 --- a/item/appitem.cpp +++ b/item/appitem.cpp @@ -2,11 +2,23 @@ #include +#define APP_STATUS_KEY "app-status" +#define APP_ICON_KEY "icon" +#define APP_MENU_KEY "menu" +#define APP_XIDS_KEY "app-xids" + +#define APP_ACTIVE_STATUS "active" +#define APP_NORMAL_STATUS "normal" + AppItem::AppItem(const QDBusObjectPath &entry, QWidget *parent) : DockItem(App, parent), m_itemEntry(new DBusDockEntry(entry.path(), this)) { qDebug() << m_itemEntry->data(); + + m_data = m_itemEntry->data(); + + connect(m_itemEntry, static_cast(&DBusDockEntry::DataChanged), this, &AppItem::entryDataChanged); } void AppItem::paintEvent(QPaintEvent *e) @@ -22,7 +34,37 @@ void AppItem::paintEvent(QPaintEvent *e) iconRect.moveTopLeft(itemRect.center() - iconRect.center()); QPainter painter(this); - painter.fillRect(rect(), Qt::cyan); + + // draw active background + if (m_data[APP_STATUS_KEY] == APP_ACTIVE_STATUS) + { + painter.fillRect(rect(), Qt::cyan); + } else { + painter.fillRect(rect(), Qt::gray); + } + + // draw icon painter.fillRect(iconRect, Qt::yellow); + + // draw text painter.drawText(rect(), m_itemEntry->id()); } + +void AppItem::mouseReleaseEvent(QMouseEvent *e) +{ + Q_UNUSED(e); + + // TODO: dbus signature changed + m_itemEntry->Activate(); +} + +void AppItem::entryDataChanged(const QString &key, const QString &value) +{ + // update data + m_data[key] = value; + + qDebug() << m_data; + + if (key == APP_STATUS_KEY) + return update(); +} diff --git a/item/appitem.h b/item/appitem.h index 38dda3c69..cdac0452c 100644 --- a/item/appitem.h +++ b/item/appitem.h @@ -13,9 +13,15 @@ public: private: void paintEvent(QPaintEvent *e); + void mouseReleaseEvent(QMouseEvent *e); + + void entryDataChanged(const QString &key, const QString &value); private: DBusDockEntry *m_itemEntry; + + QMap m_data; +// QMap m_windows; }; #endif // APPITEM_H