2016-06-03 16:06:11 +08:00
|
|
|
#include "appitem.h"
|
|
|
|
|
|
|
|
#include <QPainter>
|
|
|
|
|
2016-06-06 14:28:28 +08:00
|
|
|
#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"
|
|
|
|
|
2016-06-06 14:57:07 +08:00
|
|
|
DBusClientManager *AppItem::ClientInter = nullptr;
|
|
|
|
uint AppItem::ActiveWindowId = 0;
|
|
|
|
|
2016-06-03 16:06:11 +08:00
|
|
|
AppItem::AppItem(const QDBusObjectPath &entry, QWidget *parent)
|
2016-06-06 11:37:09 +08:00
|
|
|
: DockItem(App, parent),
|
2016-06-03 16:06:11 +08:00
|
|
|
m_itemEntry(new DBusDockEntry(entry.path(), this))
|
|
|
|
{
|
2016-06-06 14:57:07 +08:00
|
|
|
initClientManager();
|
2016-06-06 14:28:28 +08:00
|
|
|
|
|
|
|
m_data = m_itemEntry->data();
|
|
|
|
|
|
|
|
connect(m_itemEntry, static_cast<void (DBusDockEntry::*)(const QString&, const QString&)>(&DBusDockEntry::DataChanged), this, &AppItem::entryDataChanged);
|
2016-06-03 16:06:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void AppItem::paintEvent(QPaintEvent *e)
|
|
|
|
{
|
|
|
|
DockItem::paintEvent(e);
|
|
|
|
|
2016-06-06 10:59:29 +08:00
|
|
|
const QRect itemRect = rect();
|
|
|
|
const int iconSize = std::min(itemRect.width(), itemRect.height());
|
|
|
|
|
|
|
|
QRect iconRect;
|
|
|
|
iconRect.setWidth(iconSize);
|
|
|
|
iconRect.setHeight(iconSize);
|
|
|
|
iconRect.moveTopLeft(itemRect.center() - iconRect.center());
|
|
|
|
|
2016-06-03 16:06:11 +08:00
|
|
|
QPainter painter(this);
|
2016-06-06 14:28:28 +08:00
|
|
|
|
2016-06-06 14:57:07 +08:00
|
|
|
// draw current active background
|
|
|
|
if (m_windows.contains(ActiveWindowId))
|
|
|
|
{
|
|
|
|
painter.fillRect(rect(), Qt::blue);
|
|
|
|
} else if (m_data[APP_STATUS_KEY] == APP_ACTIVE_STATUS)
|
2016-06-06 14:28:28 +08:00
|
|
|
{
|
2016-06-06 14:57:07 +08:00
|
|
|
// draw active background
|
2016-06-06 14:28:28 +08:00
|
|
|
painter.fillRect(rect(), Qt::cyan);
|
|
|
|
} else {
|
2016-06-06 14:57:07 +08:00
|
|
|
// draw normal background
|
2016-06-06 14:28:28 +08:00
|
|
|
painter.fillRect(rect(), Qt::gray);
|
|
|
|
}
|
|
|
|
|
|
|
|
// draw icon
|
2016-06-06 10:59:29 +08:00
|
|
|
painter.fillRect(iconRect, Qt::yellow);
|
2016-06-06 14:28:28 +08:00
|
|
|
|
|
|
|
// draw text
|
2016-06-03 16:06:11 +08:00
|
|
|
painter.drawText(rect(), m_itemEntry->id());
|
|
|
|
}
|
2016-06-06 14:28:28 +08:00
|
|
|
|
|
|
|
void AppItem::mouseReleaseEvent(QMouseEvent *e)
|
|
|
|
{
|
|
|
|
Q_UNUSED(e);
|
|
|
|
|
|
|
|
// TODO: dbus signature changed
|
|
|
|
m_itemEntry->Activate();
|
|
|
|
}
|
|
|
|
|
2016-06-06 14:57:07 +08:00
|
|
|
void AppItem::initClientManager()
|
|
|
|
{
|
|
|
|
if (ClientInter)
|
|
|
|
return;
|
|
|
|
|
|
|
|
ClientInter = new DBusClientManager(this);
|
|
|
|
connect(ClientInter, &DBusClientManager::ActiveWindowChanged, [&] (const uint wid) {
|
|
|
|
ActiveWindowId = wid;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2016-06-06 14:28:28 +08:00
|
|
|
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();
|
|
|
|
}
|