mirror of
https://github.com/linuxdeepin/dde-dock.git
synced 2025-06-04 17:33:05 +00:00
dock plugin supporting menu
This commit is contained in:
parent
28f218f6a6
commit
4952571605
@ -1,9 +1,14 @@
|
||||
#include <QWidget>
|
||||
#include <QFrame>
|
||||
#include <QLabel>
|
||||
#include "Widgets/arrowrectangle.h"
|
||||
#include <QtDBus>
|
||||
#include <QJsonObject>
|
||||
#include <QJsonValue>
|
||||
|
||||
#include "abstractdockitem.h"
|
||||
#include "Widgets/arrowrectangle.h"
|
||||
#include "DBus/dbusmenu.h"
|
||||
#include "DBus/dbusmenumanager.h"
|
||||
|
||||
AbstractDockItem::AbstractDockItem(QWidget * parent) :
|
||||
QFrame(parent)
|
||||
@ -114,3 +119,43 @@ void AbstractDockItem::resizePreview()
|
||||
m_previewAR->resizeWithContent();
|
||||
m_previewAR->showAtBottom(globalX() + width() / 2,globalY() - 5);
|
||||
}
|
||||
|
||||
void AbstractDockItem::showMenu()
|
||||
{
|
||||
if (m_dbusMenuManager == NULL) {
|
||||
m_dbusMenuManager = new DBusMenuManager(this);
|
||||
}
|
||||
|
||||
QDBusPendingReply<QDBusObjectPath> pr = m_dbusMenuManager->RegisterMenu();
|
||||
pr.waitForFinished();
|
||||
|
||||
if (pr.isValid()) {
|
||||
QDBusObjectPath op = pr.value();
|
||||
|
||||
if (m_dbusMenu != NULL) {
|
||||
m_dbusMenu->deleteLater();
|
||||
}
|
||||
|
||||
m_dbusMenu = new DBusMenu(op.path(), this);
|
||||
|
||||
connect(m_dbusMenu, &DBusMenu::ItemInvoked, this, &AbstractDockItem::invokeMenuItem);
|
||||
|
||||
QJsonObject targetObj;
|
||||
targetObj.insert("x", QJsonValue(globalX() + width() / 2));
|
||||
targetObj.insert("y", QJsonValue(globalY() - 5));
|
||||
targetObj.insert("isDockMenu", QJsonValue(true));
|
||||
targetObj.insert("menuJsonContent", QJsonValue(getMenuContent()));
|
||||
|
||||
m_dbusMenu->ShowMenu(QString(QJsonDocument(targetObj).toJson()));
|
||||
}
|
||||
}
|
||||
|
||||
QString AbstractDockItem::getMenuContent()
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
void AbstractDockItem::invokeMenuItem(QString, bool)
|
||||
{
|
||||
|
||||
}
|
||||
|
@ -3,6 +3,8 @@
|
||||
|
||||
#include "Widgets/arrowrectangle.h"
|
||||
|
||||
class DBusMenu;
|
||||
class DBusMenuManager;
|
||||
class AbstractDockItem : public QFrame
|
||||
{
|
||||
Q_OBJECT
|
||||
@ -32,6 +34,10 @@ public:
|
||||
void cancelHide();
|
||||
void resizePreview();
|
||||
|
||||
void showMenu();
|
||||
virtual QString getMenuContent();
|
||||
virtual void invokeMenuItem(QString itemId, bool checked);
|
||||
|
||||
signals:
|
||||
void dragStart();
|
||||
void dragEntered(QDragEnterEvent * event);
|
||||
@ -51,6 +57,9 @@ protected:
|
||||
ArrowRectangle *m_previewAR = new ArrowRectangle();
|
||||
|
||||
QPoint m_itemNextPos;
|
||||
|
||||
DBusMenu * m_dbusMenu = NULL;
|
||||
DBusMenuManager * m_dbusMenuManager = NULL;
|
||||
};
|
||||
|
||||
#endif // ABSTRACTDOCKITEM_H
|
||||
|
@ -20,6 +20,9 @@ public:
|
||||
virtual QWidget * getItem(QString uuid) = 0;
|
||||
virtual QWidget * getApplet(QString uuid) = 0;
|
||||
virtual void changeMode(Dock::DockMode newMode, Dock::DockMode oldMode) = 0;
|
||||
|
||||
virtual QString getMenuContent(QString uuid) = 0;
|
||||
virtual void invokeMenuItem(QString uuid, QString itemId, bool checked) = 0;
|
||||
};
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
@ -1,3 +1,5 @@
|
||||
#include <QMouseEvent>
|
||||
|
||||
#include "pluginitemwrapper.h"
|
||||
|
||||
PluginItemWrapper::PluginItemWrapper(DockPluginInterface *plugin,
|
||||
@ -24,6 +26,12 @@ PluginItemWrapper::PluginItemWrapper(DockPluginInterface *plugin,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
PluginItemWrapper::~PluginItemWrapper()
|
||||
{
|
||||
qDebug() << "PluginItemWrapper destroyed " << m_plugin->name() << m_uuid;
|
||||
}
|
||||
|
||||
QString PluginItemWrapper::getTitle()
|
||||
{
|
||||
return m_plugin->getTitle(m_uuid);
|
||||
@ -34,25 +42,39 @@ QWidget * PluginItemWrapper::getApplet()
|
||||
return m_plugin->getApplet(m_uuid);
|
||||
}
|
||||
|
||||
QString PluginItemWrapper::uuid() const
|
||||
{
|
||||
return m_uuid;
|
||||
}
|
||||
|
||||
void PluginItemWrapper::enterEvent(QEvent *)
|
||||
{
|
||||
emit mouseEntered();
|
||||
|
||||
showPreview();
|
||||
}
|
||||
|
||||
void PluginItemWrapper::leaveEvent(QEvent *)
|
||||
{
|
||||
emit mouseExited();
|
||||
|
||||
hidePreview();
|
||||
}
|
||||
|
||||
PluginItemWrapper::~PluginItemWrapper()
|
||||
|
||||
void PluginItemWrapper::mousePressEvent(QMouseEvent * event)
|
||||
{
|
||||
qDebug() << "PluginItemWrapper destroyed " << m_plugin->name() << m_uuid;
|
||||
if (event->button() == Qt::RightButton) {
|
||||
this->showMenu();
|
||||
}
|
||||
}
|
||||
|
||||
QString PluginItemWrapper::uuid() const
|
||||
QString PluginItemWrapper::getMenuContent()
|
||||
{
|
||||
return m_uuid;
|
||||
return m_plugin->getMenuContent(m_uuid);
|
||||
}
|
||||
|
||||
void PluginItemWrapper::invokeMenuItem(QString itemId, bool checked)
|
||||
{
|
||||
m_plugin->invokeMenuItem(m_uuid, itemId, checked);
|
||||
}
|
||||
|
@ -4,6 +4,7 @@
|
||||
#include "abstractdockitem.h"
|
||||
#include "dockplugininterface.h"
|
||||
|
||||
class QMouseEvent;
|
||||
class PluginItemWrapper : public AbstractDockItem
|
||||
{
|
||||
Q_OBJECT
|
||||
@ -13,12 +14,17 @@ public:
|
||||
|
||||
QString uuid() const;
|
||||
|
||||
QString getTitle();
|
||||
QWidget * getApplet();
|
||||
QString getTitle() Q_DECL_OVERRIDE;
|
||||
QWidget * getApplet() Q_DECL_OVERRIDE;
|
||||
|
||||
QString getMenuContent() Q_DECL_OVERRIDE;
|
||||
void invokeMenuItem(QString itemId, bool checked) Q_DECL_OVERRIDE;
|
||||
|
||||
protected:
|
||||
void enterEvent(QEvent * event);
|
||||
void leaveEvent(QEvent * event);
|
||||
void enterEvent(QEvent * event) Q_DECL_OVERRIDE;
|
||||
void leaveEvent(QEvent * event) Q_DECL_OVERRIDE;
|
||||
void mousePressEvent(QMouseEvent * event) Q_DECL_OVERRIDE;
|
||||
// void mouseReleaseEvent(QMouseEvent * event) Q_DECL_OVERRIDE;
|
||||
|
||||
private:
|
||||
QWidget *m_pluginItemContents = NULL;
|
||||
|
Loading…
x
Reference in New Issue
Block a user