mirror of
https://github.com/linuxdeepin/dde-dock.git
synced 2025-06-02 15:45:21 +00:00
change plugin interface
Change-Id: Ie2e3fd67559cd1af77deec2377c7978ad00364f1
This commit is contained in:
parent
53cea04d4c
commit
2037457bf7
@ -68,7 +68,7 @@ DockItemController::DockItemController(QObject *parent)
|
||||
connect(m_appInter, &DBusDock::EntryAdded, this, &DockItemController::appItemAdded);
|
||||
connect(m_appInter, &DBusDock::EntryRemoved, this, &DockItemController::appItemRemoved);
|
||||
|
||||
connect(m_pluginsInter, &DockPluginsController::pluginsInserted, this, &DockItemController::pluginsItemInserted);
|
||||
connect(m_pluginsInter, &DockPluginsController::pluginItemInserted, this, &DockItemController::pluginsItemInserted);
|
||||
}
|
||||
|
||||
void DockItemController::appItemAdded(const QDBusObjectPath &path, const int index)
|
||||
|
@ -16,10 +16,17 @@ DockPluginsController::~DockPluginsController()
|
||||
{
|
||||
}
|
||||
|
||||
void DockPluginsController::itemAdded(PluginsItemInterface * const itemInter, const QString &itemKey)
|
||||
{
|
||||
PluginsItem *item = new PluginsItem(itemInter, itemKey);
|
||||
|
||||
emit pluginItemInserted(item);
|
||||
}
|
||||
|
||||
void DockPluginsController::loadPlugins()
|
||||
{
|
||||
Q_ASSERT(m_pluginLoaderList.isEmpty());
|
||||
Q_ASSERT(m_pluginsInterfaceList.isEmpty());
|
||||
// Q_ASSERT(m_pluginLoaderList.isEmpty());
|
||||
// Q_ASSERT(m_pluginsInterfaceList.isEmpty());
|
||||
|
||||
#ifdef QT_DEBUG
|
||||
const QDir pluginsDir("plugins");
|
||||
@ -42,7 +49,9 @@ void DockPluginsController::loadPlugins()
|
||||
continue;
|
||||
}
|
||||
|
||||
m_pluginLoaderList.append(pluginLoader);
|
||||
m_pluginsInterfaceList.append(interface);
|
||||
interface->init(this);
|
||||
|
||||
// m_pluginLoaderList.append(pluginLoader);
|
||||
// m_pluginsInterfaceList.append(interface);
|
||||
}
|
||||
}
|
||||
|
@ -2,13 +2,14 @@
|
||||
#define DOCKPLUGINSCONTROLLER_H
|
||||
|
||||
#include "item/pluginsitem.h"
|
||||
#include "pluginproxyinterface.h"
|
||||
|
||||
#include <QPluginLoader>
|
||||
#include <QList>
|
||||
|
||||
class DockItemController;
|
||||
class PluginsItemInterface;
|
||||
class DockPluginsController : public QObject
|
||||
class DockPluginsController : public QObject, PluginProxyInterface
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
@ -16,15 +17,17 @@ public:
|
||||
explicit DockPluginsController(DockItemController *itemControllerInter = 0);
|
||||
~DockPluginsController();
|
||||
|
||||
void itemAdded(PluginsItemInterface * const itemInter, const QString &itemKey);
|
||||
|
||||
signals:
|
||||
void pluginsInserted(PluginsItem *pluginsItem) const;
|
||||
void pluginItemInserted(PluginsItem *pluginsItem) const;
|
||||
|
||||
private slots:
|
||||
void loadPlugins();
|
||||
|
||||
private:
|
||||
QList<PluginsItemInterface *> m_pluginsInterfaceList;
|
||||
QList<QPluginLoader *> m_pluginLoaderList;
|
||||
// QList<PluginsItemInterface *> m_pluginsInterfaceList;
|
||||
// QList<QPluginLoader *> m_pluginLoaderList;
|
||||
DockItemController *m_itemControllerInter;
|
||||
};
|
||||
|
||||
|
@ -5,14 +5,20 @@
|
||||
#include <QPainter>
|
||||
#include <QBoxLayout>
|
||||
|
||||
PluginsItem::PluginsItem(PluginsItemInterface* const inter, QWidget *parent)
|
||||
PluginsItem::PluginsItem(PluginsItemInterface* const pluginInter, const QString &itemKey, QWidget *parent)
|
||||
: DockItem(Plugins, parent),
|
||||
m_inter(inter)
|
||||
m_pluginInter(pluginInter),
|
||||
m_itemKey(itemKey)
|
||||
{
|
||||
m_type = pluginInter->pluginType(itemKey);
|
||||
|
||||
if (m_type == PluginsItemInterface::Simple)
|
||||
return;
|
||||
|
||||
// construct complex widget layout
|
||||
QBoxLayout *layout = new QHBoxLayout;
|
||||
layout->addWidget(m_inter->centeralWidget());
|
||||
layout->addWidget(m_pluginInter->itemWidget(itemKey));
|
||||
layout->setSpacing(0);
|
||||
layout->setMargin(0);
|
||||
|
||||
setLayout(layout);
|
||||
}
|
||||
|
@ -2,17 +2,20 @@
|
||||
#define PLUGINSITEM_H
|
||||
|
||||
#include "dockitem.h"
|
||||
#include "pluginsiteminterface.h"
|
||||
|
||||
class PluginsItemInterface;
|
||||
class PluginsItem : public DockItem
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit PluginsItem(PluginsItemInterface* const inter, QWidget *parent = 0);
|
||||
explicit PluginsItem(PluginsItemInterface* const pluginInter, const QString &itemKey, QWidget *parent = 0);
|
||||
|
||||
private:
|
||||
PluginsItemInterface* const m_inter;
|
||||
PluginsItemInterface * const m_pluginInter;
|
||||
const QString m_itemKey;
|
||||
|
||||
PluginsItemInterface::PluginType m_type;
|
||||
};
|
||||
|
||||
#endif // PLUGINSITEM_H
|
||||
|
@ -1,6 +1,7 @@
|
||||
HEADERS += \
|
||||
$$PWD/pluginsiteminterface.h \
|
||||
$$PWD/constants.h
|
||||
$$PWD/constants.h \
|
||||
$$PWD/pluginproxyinterface.h
|
||||
|
||||
INCLUDEPATH += $$PWD
|
||||
|
||||
|
14
interfaces/pluginproxyinterface.h
Normal file
14
interfaces/pluginproxyinterface.h
Normal file
@ -0,0 +1,14 @@
|
||||
#ifndef PLUGINPROXYINTERFACE_H
|
||||
#define PLUGINPROXYINTERFACE_H
|
||||
|
||||
#include <QtCore>
|
||||
|
||||
class PluginsItemInterface;
|
||||
class PluginProxyInterface
|
||||
{
|
||||
public:
|
||||
virtual void itemAdded(PluginsItemInterface * const itemInter, const QString &itemKey) = 0;
|
||||
|
||||
};
|
||||
|
||||
#endif // PLUGINPROXYINTERFACE_H
|
@ -1,15 +1,37 @@
|
||||
#ifndef PLUGINSITEMINTERFACE_H
|
||||
#define PLUGINSITEMINTERFACE_H
|
||||
|
||||
#include "pluginproxyinterface.h"
|
||||
|
||||
#include <QIcon>
|
||||
#include <QtCore>
|
||||
|
||||
class PluginsItemInterface
|
||||
{
|
||||
public:
|
||||
enum PluginType
|
||||
{
|
||||
Simple,
|
||||
Complex,
|
||||
};
|
||||
|
||||
public:
|
||||
virtual ~PluginsItemInterface() {}
|
||||
|
||||
virtual const QString name() = 0;
|
||||
virtual QWidget *centeralWidget() = 0;
|
||||
// the unique plugin id
|
||||
virtual const QString pluginName() = 0;
|
||||
// plugins type, simple icon or complex widget
|
||||
virtual PluginType pluginType(const QString &itemKey) = 0;
|
||||
// init plugins
|
||||
virtual void init(PluginProxyInterface *proxyInter) = 0;
|
||||
|
||||
// if complex widget mode, only return widget to plugins item
|
||||
virtual QWidget *itemWidget(const QString &itemKey) {Q_UNUSED(itemKey); return nullptr;}
|
||||
// in simple icon mode, plugins need to implements some data source functions
|
||||
virtual const QIcon itemIcon(const QString &itemKey) {Q_UNUSED(itemKey); return QIcon();}
|
||||
|
||||
protected:
|
||||
PluginProxyInterface *m_proxyInter;
|
||||
};
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
@ -24,13 +24,28 @@ DatetimePlugin::~DatetimePlugin()
|
||||
delete m_timeLabel;
|
||||
}
|
||||
|
||||
const QString DatetimePlugin::name()
|
||||
const QString DatetimePlugin::pluginName()
|
||||
{
|
||||
return "datetime";
|
||||
}
|
||||
|
||||
QWidget *DatetimePlugin::centeralWidget()
|
||||
PluginsItemInterface::PluginType DatetimePlugin::pluginType(const QString &itemKey)
|
||||
{
|
||||
Q_UNUSED(itemKey);
|
||||
|
||||
return Complex;
|
||||
}
|
||||
|
||||
void DatetimePlugin::init(PluginProxyInterface *proxyInter)
|
||||
{
|
||||
m_proxyInter = proxyInter;
|
||||
m_proxyInter->itemAdded(this, QString());
|
||||
}
|
||||
|
||||
QWidget *DatetimePlugin::itemWidget(const QString &itemKey)
|
||||
{
|
||||
Q_UNUSED(itemKey);
|
||||
|
||||
return m_timeLabel;
|
||||
}
|
||||
|
||||
|
@ -16,8 +16,12 @@ public:
|
||||
explicit DatetimePlugin(QObject *parent = 0);
|
||||
~DatetimePlugin();
|
||||
|
||||
const QString name();
|
||||
QWidget *centeralWidget();
|
||||
const QString pluginName();
|
||||
PluginType pluginType(const QString &itemKey);
|
||||
void init(PluginProxyInterface *proxyInter);
|
||||
|
||||
QWidget *itemWidget(const QString &itemKey);
|
||||
|
||||
|
||||
private slots:
|
||||
void refershTime();
|
||||
|
Loading…
x
Reference in New Issue
Block a user