mirror of
https://github.com/linuxdeepin/dde-dock.git
synced 2025-06-03 00:15:21 +00:00
add item add and item remove signals
Change-Id: I17ac28e44c908543fc22c6fccdec4c1d316b7576
This commit is contained in:
parent
107574fd72
commit
dc07ffba04
@ -39,10 +39,29 @@ DockItemController::DockItemController(QObject *parent)
|
||||
|
||||
void DockItemController::appItemAdded(const QDBusObjectPath &path)
|
||||
{
|
||||
qDebug() << path.path();
|
||||
qDebug() << "entry add: " << path.path();
|
||||
|
||||
AppItem *item = new AppItem(path);
|
||||
|
||||
m_itemList.append(item);
|
||||
emit itemInserted(0, item);
|
||||
}
|
||||
|
||||
void DockItemController::appItemRemoved(const QString &itemId)
|
||||
void DockItemController::appItemRemoved(const QString &appId)
|
||||
{
|
||||
qDebug() << itemId;
|
||||
for (int i(0); i != m_itemList.size(); ++i)
|
||||
{
|
||||
if (m_itemList[i]->itemType() != DockItem::App)
|
||||
continue;
|
||||
|
||||
AppItem *app = static_cast<AppItem *>(m_itemList[i]);
|
||||
if (app->appId() != appId)
|
||||
continue;
|
||||
|
||||
emit itemRemoved(m_itemList[i]);
|
||||
m_itemList[i]->deleteLater();
|
||||
m_itemList.removeAt(i);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -17,12 +17,13 @@ public:
|
||||
const QList<DockItem *> itemList() const;
|
||||
|
||||
signals:
|
||||
void dockItemCountChanged(const int count) const;
|
||||
void itemInserted(const int index, DockItem *item);
|
||||
void itemRemoved(DockItem *item);
|
||||
|
||||
private:
|
||||
explicit DockItemController(QObject *parent = 0);
|
||||
void appItemAdded(const QDBusObjectPath &path);
|
||||
void appItemRemoved(const QString &itemId);
|
||||
void appItemRemoved(const QString &appId);
|
||||
|
||||
private:
|
||||
QList<DockItem *> m_itemList;
|
||||
|
@ -18,8 +18,8 @@
|
||||
DBusDockEntry::DBusDockEntry(const QString &path, QObject *parent)
|
||||
: QDBusAbstractInterface("com.deepin.dde.daemon.Dock", path, staticInterfaceName(), QDBusConnection::sessionBus(), parent)
|
||||
{
|
||||
qRegisterMetaType<Dict>("Dict");
|
||||
qDBusRegisterMetaType<Dict>();
|
||||
qRegisterMetaType<WindowDict>("WindowDict");
|
||||
qDBusRegisterMetaType<WindowDict>();
|
||||
|
||||
QDBusConnection::sessionBus().connect(this->service(), this->path(), "org.freedesktop.DBus.Properties", "PropertiesChanged","sa{sv}as", this, SLOT(__propertyChanged__(QDBusMessage)));
|
||||
}
|
||||
|
@ -20,7 +20,7 @@
|
||||
#include <QtCore/QVariant>
|
||||
#include <QtDBus/QtDBus>
|
||||
|
||||
typedef QMap<QString, QString> Dict;
|
||||
typedef QMap<quint32, QString> WindowDict;
|
||||
|
||||
/*
|
||||
* Proxy class for interface dde.dock.Entry
|
||||
@ -57,17 +57,21 @@ public:
|
||||
|
||||
~DBusDockEntry();
|
||||
|
||||
Q_PROPERTY(Dict Data READ data NOTIFY DataChanged)
|
||||
inline Dict data() const
|
||||
{ return qvariant_cast< Dict >(property("Data")); }
|
||||
Q_PROPERTY(bool IsActive READ active NOTIFY ActiveChanged)
|
||||
inline bool active() const
|
||||
{ return qvariant_cast< bool >(property("IsActive")); }
|
||||
|
||||
Q_PROPERTY(WindowDict WindowTitles READ titles NOTIFY TitlesChanged)
|
||||
inline WindowDict titles() const
|
||||
{ return qvariant_cast< WindowDict >(property("WindowTitles")); }
|
||||
|
||||
Q_PROPERTY(QString Id READ id NOTIFY IdChanged)
|
||||
inline QString id() const
|
||||
{ return qvariant_cast< QString >(property("Id")); }
|
||||
|
||||
Q_PROPERTY(QString Type READ type NOTIFY TypeChanged)
|
||||
inline QString type() const
|
||||
{ return qvariant_cast< QString >(property("Type")); }
|
||||
Q_PROPERTY(QString Title READ title NOTIFY TitleChanged)
|
||||
inline QString title() const
|
||||
{ return qvariant_cast< QString >(property("Title")); }
|
||||
|
||||
public Q_SLOTS: // METHODS
|
||||
inline QDBusPendingReply<> Activate()
|
||||
@ -76,12 +80,20 @@ public Q_SLOTS: // METHODS
|
||||
return asyncCallWithArgumentList(QStringLiteral("Activate"), argumentList);
|
||||
}
|
||||
|
||||
inline QDBusPendingReply<> Activate1()
|
||||
{
|
||||
QList<QVariant> argumentList;
|
||||
argumentList << QVariant::fromValue(qint32(0)) << QVariant::fromValue(qint32(0)) << QVariant::fromValue(quint32(0));
|
||||
return asyncCallWithArgumentList(QStringLiteral("Activate"), argumentList);
|
||||
}
|
||||
|
||||
Q_SIGNALS: // SIGNALS
|
||||
void DataChanged(const QString &in0, const QString &in1);
|
||||
void TitlesChanged(const quint32 xid, const QString &title);
|
||||
// begin property changed signals
|
||||
void ActiveChanged();
|
||||
void DataChanged();
|
||||
void IdChanged();
|
||||
void TypeChanged();
|
||||
void TitleChanged();
|
||||
};
|
||||
|
||||
namespace dde {
|
||||
|
35
dbus/dbusmenu.cpp
Normal file
35
dbus/dbusmenu.cpp
Normal file
@ -0,0 +1,35 @@
|
||||
/**
|
||||
* Copyright (C) 2015 Deepin Technology Co., Ltd.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
**/
|
||||
|
||||
/*
|
||||
* This file was generated by qdbusxml2cpp version 0.8
|
||||
* Command line was: qdbusxml2cpp -c DBusMenuManager -p dbusmenumanager com.deepin.menu.Manager.xml
|
||||
*
|
||||
* qdbusxml2cpp is Copyright (C) 2015 Digia Plc and/or its subsidiary(-ies).
|
||||
*
|
||||
* This is an auto-generated file.
|
||||
* This file may have been hand-edited. Look for HAND-EDIT comments
|
||||
* before re-generating it.
|
||||
*/
|
||||
|
||||
#include "dbusmenu.h"
|
||||
|
||||
/*
|
||||
* Implementation of interface class DBusMenuManager
|
||||
*/
|
||||
|
||||
DBusMenuManager::DBusMenuManager(QObject *parent)
|
||||
: QDBusAbstractInterface(staticServerPath(), staticInterfacePath(), staticInterfaceName(), QDBusConnection::sessionBus(), parent)
|
||||
{
|
||||
}
|
||||
|
||||
DBusMenuManager::~DBusMenuManager()
|
||||
{
|
||||
}
|
||||
|
75
dbus/dbusmenu.h
Normal file
75
dbus/dbusmenu.h
Normal file
@ -0,0 +1,75 @@
|
||||
/**
|
||||
* Copyright (C) 2015 Deepin Technology Co., Ltd.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
**/
|
||||
|
||||
/*
|
||||
* This file was generated by qdbusxml2cpp version 0.8
|
||||
* Command line was: qdbusxml2cpp -c DBusMenuManager -p dbusmenumanager com.deepin.menu.Manager.xml
|
||||
*
|
||||
* qdbusxml2cpp is Copyright (C) 2015 Digia Plc and/or its subsidiary(-ies).
|
||||
*
|
||||
* This is an auto-generated file.
|
||||
* Do not edit! All changes made to it will be lost.
|
||||
*/
|
||||
|
||||
#ifndef DBUSMENUMANAGER_H_1436158928
|
||||
#define DBUSMENUMANAGER_H_1436158928
|
||||
|
||||
#include <QtCore/QObject>
|
||||
#include <QtCore/QByteArray>
|
||||
#include <QtCore/QList>
|
||||
#include <QtCore/QMap>
|
||||
#include <QtCore/QString>
|
||||
#include <QtCore/QStringList>
|
||||
#include <QtCore/QVariant>
|
||||
#include <QtDBus/QtDBus>
|
||||
|
||||
/*
|
||||
* Proxy class for interface com.deepin.menu.Manager
|
||||
*/
|
||||
class DBusMenuManager: public QDBusAbstractInterface
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
static inline const char *staticServerPath()
|
||||
{ return "com.deepin.menu"; }
|
||||
static inline const char *staticInterfacePath()
|
||||
{ return "/com/deepin/menu"; }
|
||||
static inline const char *staticInterfaceName()
|
||||
{ return "com.deepin.menu.Manager"; }
|
||||
|
||||
public:
|
||||
explicit DBusMenuManager(QObject *parent = 0);
|
||||
|
||||
~DBusMenuManager();
|
||||
|
||||
public Q_SLOTS: // METHODS
|
||||
inline QDBusPendingReply<QDBusObjectPath> RegisterMenu()
|
||||
{
|
||||
QList<QVariant> argumentList;
|
||||
return asyncCallWithArgumentList(QStringLiteral("RegisterMenu"), argumentList);
|
||||
}
|
||||
|
||||
inline QDBusPendingReply<> UnregisterMenu(const QString &menuObjectPath)
|
||||
{
|
||||
QList<QVariant> argumentList;
|
||||
argumentList << QVariant::fromValue(menuObjectPath);
|
||||
return asyncCallWithArgumentList(QStringLiteral("UnregisterMenu"), argumentList);
|
||||
}
|
||||
|
||||
Q_SIGNALS: // SIGNALS
|
||||
};
|
||||
|
||||
namespace com {
|
||||
namespace deepin {
|
||||
namespace menu {
|
||||
typedef ::DBusMenuManager Manager;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
@ -18,7 +18,8 @@ SOURCES += main.cpp \
|
||||
util/docksettings.cpp \
|
||||
item/placeholderitem.cpp \
|
||||
dbus/dbusclientmanager.cpp \
|
||||
dbus/dbusdock.cpp
|
||||
dbus/dbusdock.cpp \
|
||||
dbus/dbusmenu.cpp
|
||||
|
||||
HEADERS += \
|
||||
window/mainwindow.h \
|
||||
@ -32,4 +33,5 @@ HEADERS += \
|
||||
util/docksettings.h \
|
||||
item/placeholderitem.h \
|
||||
dbus/dbusclientmanager.h \
|
||||
dbus/dbusdock.h
|
||||
dbus/dbusdock.h \
|
||||
dbus/dbusmenu.h
|
||||
|
@ -11,7 +11,7 @@
|
||||
#define APP_DRAG_THRESHOLD 20
|
||||
|
||||
DBusClientManager *AppItem::ClientInter = nullptr;
|
||||
uint AppItem::ActiveWindowId = 0;
|
||||
//uint AppItem::ActiveWindowId = 0;
|
||||
|
||||
AppItem::AppItem(const QDBusObjectPath &entry, QWidget *parent)
|
||||
: DockItem(App, parent),
|
||||
@ -20,9 +20,17 @@ AppItem::AppItem(const QDBusObjectPath &entry, QWidget *parent)
|
||||
{
|
||||
initClientManager();
|
||||
|
||||
m_data = m_itemEntry->data();
|
||||
m_titles = m_itemEntry->titles();
|
||||
m_id = m_itemEntry->id();
|
||||
qDebug() << m_titles;
|
||||
|
||||
connect(m_itemEntry, static_cast<void (DBusDockEntry::*)(const QString&, const QString&)>(&DBusDockEntry::DataChanged), this, &AppItem::entryDataChanged);
|
||||
connect(m_itemEntry,&DBusDockEntry::TitlesChanged, this, &AppItem::entryDataChanged);
|
||||
connect(m_itemEntry, &DBusDockEntry::ActiveChanged, this, static_cast<void (AppItem::*)()>(&AppItem::update));
|
||||
}
|
||||
|
||||
const QString AppItem::appId() const
|
||||
{
|
||||
return m_id;
|
||||
}
|
||||
|
||||
void AppItem::paintEvent(QPaintEvent *e)
|
||||
@ -42,6 +50,13 @@ void AppItem::paintEvent(QPaintEvent *e)
|
||||
|
||||
QPainter painter(this);
|
||||
|
||||
if (m_itemEntry->active())
|
||||
{
|
||||
painter.fillRect(rect(), Qt::blue);
|
||||
} else {
|
||||
painter.fillRect(rect(), Qt::gray);
|
||||
}
|
||||
|
||||
// // draw current active background
|
||||
// if (m_windows.contains(ActiveWindowId))
|
||||
// {
|
||||
@ -59,7 +74,8 @@ void AppItem::paintEvent(QPaintEvent *e)
|
||||
painter.fillRect(iconRect, Qt::yellow);
|
||||
|
||||
// draw text
|
||||
painter.drawText(rect(), m_itemEntry->id());
|
||||
painter.setPen(Qt::red);
|
||||
painter.drawText(rect(), m_itemEntry->title());
|
||||
}
|
||||
|
||||
void AppItem::mouseReleaseEvent(QMouseEvent *e)
|
||||
@ -67,7 +83,7 @@ void AppItem::mouseReleaseEvent(QMouseEvent *e)
|
||||
// activate
|
||||
// TODO: dbus signature changed
|
||||
if (e->button() == Qt::LeftButton)
|
||||
m_itemEntry->Activate();
|
||||
m_itemEntry->Activate1();
|
||||
}
|
||||
|
||||
void AppItem::mousePressEvent(QMouseEvent *e)
|
||||
@ -103,7 +119,7 @@ void AppItem::startDrag()
|
||||
|
||||
const Qt::DropAction result = drag->exec(Qt::MoveAction);
|
||||
|
||||
qDebug() << result;
|
||||
qDebug() << "dnd result: " << result;
|
||||
|
||||
m_draging = false;
|
||||
update();
|
||||
@ -115,18 +131,12 @@ void AppItem::initClientManager()
|
||||
return;
|
||||
|
||||
ClientInter = new DBusClientManager(this);
|
||||
connect(ClientInter, &DBusClientManager::ActiveWindowChanged, [&] (const uint wid) {
|
||||
ActiveWindowId = wid;
|
||||
});
|
||||
// connect(ClientInter, &DBusClientManager::ActiveWindowChanged, [&] (const uint wid) {
|
||||
// ActiveWindowId = wid;
|
||||
// });
|
||||
}
|
||||
|
||||
void AppItem::entryDataChanged(const QString &key, const QString &value)
|
||||
void AppItem::entryDataChanged(const quint32 xid, const QString &title)
|
||||
{
|
||||
qDebug() << "data chanegd" << key << value;
|
||||
|
||||
// update data
|
||||
m_data[key] = value;
|
||||
|
||||
// if (key == APP_STATUS_KEY)
|
||||
return update();
|
||||
qDebug() << "title changed: " << xid << title;
|
||||
}
|
||||
|
@ -12,6 +12,8 @@ class AppItem : public DockItem
|
||||
public:
|
||||
explicit AppItem(const QDBusObjectPath &entry, QWidget *parent = nullptr);
|
||||
|
||||
const QString appId() const;
|
||||
|
||||
private:
|
||||
void paintEvent(QPaintEvent *e);
|
||||
void mouseReleaseEvent(QMouseEvent *e);
|
||||
@ -20,20 +22,20 @@ private:
|
||||
|
||||
void startDrag();
|
||||
void initClientManager();
|
||||
void entryDataChanged(const QString &key, const QString &value);
|
||||
void entryDataChanged(const quint32 xid, const QString &title);
|
||||
|
||||
private:
|
||||
DBusDockEntry *m_itemEntry;
|
||||
|
||||
bool m_draging;
|
||||
|
||||
QMap<QString, QString> m_data;
|
||||
QMap<uint, QString> m_windows;
|
||||
WindowDict m_titles;
|
||||
QString m_id;
|
||||
|
||||
QPoint m_mousePressPos;
|
||||
|
||||
static DBusClientManager *ClientInter;
|
||||
static uint ActiveWindowId;
|
||||
// static uint ActiveWindowId;
|
||||
};
|
||||
|
||||
#endif // APPITEM_H
|
||||
|
@ -5,7 +5,6 @@ DockItem::DockItem(const ItemType type, QWidget *parent)
|
||||
m_side(DockSettings::Top),
|
||||
m_type(type)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void DockItem::setDockSide(const DockSettings::DockSide side)
|
||||
|
@ -13,10 +13,13 @@ MainPanel::MainPanel(QWidget *parent)
|
||||
setObjectName("MainPanel");
|
||||
setStyleSheet("QWidget #MainPanel {"
|
||||
"border:none;"
|
||||
"background-color:red;"
|
||||
"background-color:green;"
|
||||
"border-radius:5px 5px 5px 5px;"
|
||||
"}");
|
||||
|
||||
connect(m_itemController, &DockItemController::itemInserted, this, &MainPanel::itemInserted);
|
||||
connect(m_itemController, &DockItemController::itemRemoved, this, &MainPanel::itemRemoved);
|
||||
|
||||
const QList<DockItem *> itemList = m_itemController->itemList();
|
||||
for (auto item : itemList)
|
||||
m_itemLayout->addWidget(item);
|
||||
@ -69,4 +72,20 @@ void MainPanel::adjustItemSize()
|
||||
default:;
|
||||
}
|
||||
}
|
||||
|
||||
updateGeometry();
|
||||
}
|
||||
|
||||
void MainPanel::itemInserted(const int index, DockItem *item)
|
||||
{
|
||||
m_itemLayout->insertWidget(index, item);
|
||||
|
||||
item->setFixedWidth(80);
|
||||
|
||||
adjustSize();
|
||||
}
|
||||
|
||||
void MainPanel::itemRemoved(DockItem *item)
|
||||
{
|
||||
m_itemLayout->removeWidget(item);
|
||||
}
|
||||
|
@ -23,6 +23,8 @@ private:
|
||||
void dropEvent(QDropEvent *e);
|
||||
|
||||
void adjustItemSize();
|
||||
void itemInserted(const int index, DockItem *item);
|
||||
void itemRemoved(DockItem *item);
|
||||
|
||||
private:
|
||||
QBoxLayout *m_itemLayout;
|
||||
|
Loading…
x
Reference in New Issue
Block a user