mirror of
https://github.com/linuxdeepin/dde-dock.git
synced 2025-06-04 17:33:05 +00:00
systray plugin adapte to the new interface
This commit is contained in:
parent
3bcfcdd471
commit
089c944ac6
@ -1,6 +1,8 @@
|
||||
#include <QStyle>
|
||||
#include <QDebug>
|
||||
|
||||
#include <dock/dockconstants.h>
|
||||
|
||||
#include "compositetrayitem.h"
|
||||
|
||||
static const int Margins = 4;
|
||||
@ -9,7 +11,9 @@ static const int ColumnWidth = 20;
|
||||
CompositeTrayItem::CompositeTrayItem(QWidget *parent) :
|
||||
QFrame(parent)
|
||||
{
|
||||
m_columnCount = 2;
|
||||
|
||||
setBackground();
|
||||
}
|
||||
|
||||
CompositeTrayItem::~CompositeTrayItem()
|
||||
@ -35,9 +39,8 @@ void CompositeTrayItem::addWidget(QWidget * widget)
|
||||
} else if (childrenCount <= 12) {
|
||||
m_columnCount = 6;
|
||||
}
|
||||
setFixedSize(Margins * 2 + ColumnWidth * m_columnCount, 48);
|
||||
setStyleSheet("QFrame { background-image: url(':/images/darea_container_4.svg') }");
|
||||
style()->polish(this);
|
||||
|
||||
setBackground();
|
||||
|
||||
// move the widget to right position
|
||||
int x = (childrenCount - 1) % m_columnCount * ColumnWidth + Margins + (ColumnWidth - 16) / 2;
|
||||
@ -47,7 +50,7 @@ void CompositeTrayItem::addWidget(QWidget * widget)
|
||||
|
||||
void CompositeTrayItem::removeWidget(QWidget *widget)
|
||||
{
|
||||
widget->setParent(NULL);
|
||||
// widget->setParent(NULL);
|
||||
|
||||
uint childrenCount = children().length();
|
||||
|
||||
@ -63,7 +66,15 @@ void CompositeTrayItem::removeWidget(QWidget *widget)
|
||||
} else if (childrenCount <= 12) {
|
||||
m_columnCount = 6;
|
||||
}
|
||||
setFixedSize(Margins * 2 + ColumnWidth * m_columnCount, 48);
|
||||
setStyleSheet("QFrame { background-image: url(':/images/darea_container_4.svg') }");
|
||||
style()->polish(this);
|
||||
|
||||
setBackground();
|
||||
}
|
||||
|
||||
|
||||
void CompositeTrayItem::setBackground()
|
||||
{
|
||||
resize(Margins * 2 + ColumnWidth * m_columnCount, 48);
|
||||
setStyleSheet("QFrame { background-image: url(':/images/darea_container_4.svg') }");
|
||||
|
||||
qDebug() << "CompositeTrayItem::setBackground()" << this->geometry();
|
||||
}
|
||||
|
@ -14,7 +14,9 @@ public:
|
||||
void removeWidget(QWidget * widget);
|
||||
|
||||
private:
|
||||
uint m_columnCount = 2;
|
||||
uint m_columnCount;
|
||||
|
||||
void setBackground();
|
||||
};
|
||||
|
||||
#endif // COMPOSITETRAYITEM_H
|
||||
|
@ -8,7 +8,6 @@ QT += core gui dbus
|
||||
|
||||
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
|
||||
|
||||
INCLUDEPATH += ../dde-dock/src/
|
||||
CONFIG += plugin c++11
|
||||
|
||||
TARGET = $$qtLibraryTarget(dock-systray-plugin)
|
||||
|
@ -6,14 +6,20 @@
|
||||
|
||||
static const QString CompositeItemKey = "composite_item_key";
|
||||
|
||||
SystrayPlugin::SystrayPlugin()
|
||||
{
|
||||
m_items[CompositeItemKey] = new CompositeTrayItem;
|
||||
}
|
||||
|
||||
SystrayPlugin::~SystrayPlugin()
|
||||
{
|
||||
this->clearItems();
|
||||
}
|
||||
|
||||
void SystrayPlugin::init(DockPluginProxyInterface * proxier)
|
||||
void SystrayPlugin::init(DockPluginProxyInterface * proxy)
|
||||
{
|
||||
m_proxier = proxier;
|
||||
m_proxy = proxy;
|
||||
m_mode = proxy->dockMode();
|
||||
|
||||
if (!m_dbusTrayManager) {
|
||||
m_dbusTrayManager = new com::deepin::dde::TrayManager("com.deepin.dde.TrayManager",
|
||||
@ -27,70 +33,82 @@ void SystrayPlugin::init(DockPluginProxyInterface * proxier)
|
||||
QList<uint> trayIcons = m_dbusTrayManager->trayIcons();
|
||||
qDebug() << "Found trayicons: " << trayIcons;
|
||||
|
||||
if (m_mode == Dock::FashionMode) {
|
||||
m_proxy->itemAddedEvent(CompositeItemKey);
|
||||
}
|
||||
|
||||
foreach (uint trayIcon, trayIcons) {
|
||||
onAdded(trayIcon);
|
||||
}
|
||||
}
|
||||
|
||||
QStringList SystrayPlugin::uuids()
|
||||
{
|
||||
return m_items.keys();
|
||||
}
|
||||
|
||||
QWidget * SystrayPlugin::getItem(QString uuid)
|
||||
{
|
||||
return m_items.value(uuid);
|
||||
}
|
||||
|
||||
QString SystrayPlugin::name()
|
||||
{
|
||||
return QString("System Tray");
|
||||
}
|
||||
|
||||
QStringList SystrayPlugin::uuids()
|
||||
{
|
||||
return m_items.keys();
|
||||
}
|
||||
|
||||
QString SystrayPlugin::getTitle(QString)
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
QWidget * SystrayPlugin::getItem(QString uuid)
|
||||
{
|
||||
return m_items.value(uuid);
|
||||
}
|
||||
|
||||
QWidget * SystrayPlugin::getApplet(QString)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void SystrayPlugin::changeMode(Dock::DockMode newMode, Dock::DockMode oldMode)
|
||||
{
|
||||
m_mode = newMode;
|
||||
|
||||
CompositeTrayItem * compositeItem = NULL;
|
||||
|
||||
QWidget * widget = m_items.value(CompositeItemKey);
|
||||
if (!widget)
|
||||
{
|
||||
compositeItem = new CompositeTrayItem;
|
||||
m_items[CompositeItemKey] = compositeItem;
|
||||
}
|
||||
else
|
||||
compositeItem = qobject_cast<CompositeTrayItem*>(widget);
|
||||
|
||||
compositeItem->resize(Dock::APPLET_FASHION_ITEM_WIDTH,Dock::APPLET_FASHION_ITEM_HEIGHT);
|
||||
CompositeTrayItem * compositeItem = qobject_cast<CompositeTrayItem*>(widget);
|
||||
|
||||
if (oldMode == Dock::FashionMode && newMode != Dock::FashionMode) {
|
||||
|
||||
compositeItem->setParent(NULL);
|
||||
|
||||
qDebug() << "SystrayPlugin change mode to other mode.";
|
||||
foreach (QWidget * widget, m_items) {
|
||||
if (widget != compositeItem) {
|
||||
m_proxy->itemAddedEvent(m_items.key(widget));
|
||||
compositeItem->removeWidget(widget);
|
||||
m_proxier->itemAddedEvent(m_items.key(widget));
|
||||
}
|
||||
}
|
||||
|
||||
m_proxier->itemRemovedEvent(CompositeItemKey);
|
||||
compositeItem->setParent(NULL);
|
||||
m_proxy->itemRemovedEvent(CompositeItemKey);
|
||||
} else if (newMode == Dock::FashionMode && oldMode != Dock::FashionMode) {
|
||||
|
||||
qDebug() << "SystrayPlugin change mode to fashion mode.";
|
||||
foreach (QWidget * widget, m_items) {
|
||||
if (widget != compositeItem) {
|
||||
compositeItem->addWidget(widget);
|
||||
m_proxier->itemRemovedEvent(m_items.key(widget));
|
||||
m_proxy->itemRemovedEvent(m_items.key(widget));
|
||||
}
|
||||
}
|
||||
|
||||
m_proxier->itemAddedEvent(CompositeItemKey);
|
||||
m_proxy->itemAddedEvent(CompositeItemKey);
|
||||
m_proxy->itemSizeChangedEvent(CompositeItemKey);
|
||||
}
|
||||
}
|
||||
|
||||
QString SystrayPlugin::getMenuContent(QString)
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
void SystrayPlugin::invokeMenuItem(QString, QString, bool)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// private methods
|
||||
void SystrayPlugin::clearItems()
|
||||
{
|
||||
@ -107,24 +125,31 @@ void SystrayPlugin::addItem(QString uuid, QWidget * item)
|
||||
if (m_mode == Dock::FashionMode) {
|
||||
CompositeTrayItem * compositeItem = qobject_cast<CompositeTrayItem*>(m_items.value(CompositeItemKey));
|
||||
compositeItem->addWidget(item);
|
||||
|
||||
m_proxy->itemSizeChangedEvent(CompositeItemKey);
|
||||
} else {
|
||||
m_proxier->itemAddedEvent(uuid);
|
||||
m_proxy->itemAddedEvent(uuid);
|
||||
}
|
||||
}
|
||||
|
||||
void SystrayPlugin::removeItem(QString uuid)
|
||||
{
|
||||
QWidget * item = m_items[uuid];
|
||||
QWidget * item = m_items[uuid];
|
||||
|
||||
if (m_mode == Dock::FashionMode) {
|
||||
CompositeTrayItem * compositeItem = qobject_cast<CompositeTrayItem*>(m_items.value(CompositeItemKey));
|
||||
compositeItem->removeWidget(item);
|
||||
|
||||
m_proxy->itemSizeChangedEvent(CompositeItemKey);
|
||||
|
||||
m_items.remove(uuid);
|
||||
item->deleteLater();
|
||||
} else {
|
||||
m_items.remove(uuid);
|
||||
item->deleteLater();
|
||||
|
||||
m_proxy->itemRemovedEvent(uuid);
|
||||
}
|
||||
|
||||
m_items.remove(uuid);
|
||||
item->deleteLater();
|
||||
|
||||
m_proxier->itemRemovedEvent(uuid);
|
||||
}
|
||||
|
||||
// private slots
|
||||
@ -133,11 +158,12 @@ void SystrayPlugin::onAdded(WId winId)
|
||||
QString key = QString::number(winId);
|
||||
|
||||
QWidget *item = new QWidget;
|
||||
item->setFixedSize(16, 16);
|
||||
item->setStyleSheet("QWidget { background-color: green }");
|
||||
item->resize(Dock::APPLET_CLASSIC_ICON_SIZE, Dock::APPLET_CLASSIC_ICON_SIZE);
|
||||
|
||||
QWindow *win = QWindow::fromWinId(winId);
|
||||
QWidget *w = QWidget::createWindowContainer(win, item);
|
||||
w->setFixedSize(item->size());
|
||||
// QWindow * win = QWindow::fromWinId(winId);
|
||||
// QWidget * winItem = QWidget::createWindowContainer(win, item);
|
||||
// winItem->resize(item->size());
|
||||
|
||||
addItem(key, item);
|
||||
}
|
||||
|
@ -6,9 +6,10 @@
|
||||
#include <QWindow>
|
||||
#include <QWidget>
|
||||
|
||||
#include "dockconstants.h"
|
||||
#include "dockplugininterface.h"
|
||||
#include "dockpluginproxyinterface.h"
|
||||
#include <dock/dockconstants.h>
|
||||
#include <dock/dockplugininterface.h>
|
||||
#include <dock/dockpluginproxyinterface.h>
|
||||
|
||||
#include "dbustraymanager.h"
|
||||
|
||||
class SystrayPlugin : public QObject, public DockPluginInterface
|
||||
@ -18,20 +19,25 @@ class SystrayPlugin : public QObject, public DockPluginInterface
|
||||
Q_INTERFACES(DockPluginInterface)
|
||||
|
||||
public:
|
||||
SystrayPlugin();
|
||||
~SystrayPlugin();
|
||||
|
||||
void init(DockPluginProxyInterface * proxier) Q_DECL_OVERRIDE;
|
||||
|
||||
QStringList uuids() Q_DECL_OVERRIDE;
|
||||
QWidget * getItem(QString uuid) Q_DECL_OVERRIDE;
|
||||
QWidget * getContents(QString uuid){return NULL;}
|
||||
void changeMode(Dock::DockMode newMode, Dock::DockMode oldMode);
|
||||
void init(DockPluginProxyInterface * proxy) Q_DECL_OVERRIDE;
|
||||
|
||||
QString name() Q_DECL_OVERRIDE;
|
||||
|
||||
QStringList uuids() Q_DECL_OVERRIDE;
|
||||
QString getTitle(QString uuid) Q_DECL_OVERRIDE;
|
||||
QWidget * getItem(QString uuid) Q_DECL_OVERRIDE;
|
||||
QWidget * getApplet(QString uuid) Q_DECL_OVERRIDE;
|
||||
void changeMode(Dock::DockMode newMode, Dock::DockMode oldMode);
|
||||
|
||||
QString getMenuContent(QString uuid);
|
||||
void invokeMenuItem(QString uuid, QString itemId, bool checked);
|
||||
|
||||
private:
|
||||
QMap<QString, QWidget*> m_items;
|
||||
DockPluginProxyInterface * m_proxier = 0;
|
||||
DockPluginProxyInterface * m_proxy = 0;
|
||||
com::deepin::dde::TrayManager *m_dbusTrayManager = 0;
|
||||
Dock::DockMode m_mode;
|
||||
|
||||
|
@ -303,7 +303,7 @@ int DockLayout::getContentsWidth()
|
||||
tmpWidth += appList.at(i)->width();
|
||||
}
|
||||
|
||||
if (spacingItemIndex() != -1 && tmpAppMap.firstKey())
|
||||
if (spacingItemIndex() != -1 && !tmpAppMap.isEmpty() && tmpAppMap.firstKey())
|
||||
tmpWidth += tmpAppMap.firstKey()->width() + itemSpacing;
|
||||
|
||||
return tmpWidth;
|
||||
|
@ -96,7 +96,7 @@ void AbstractDockItem::showPreview()
|
||||
// TODO: memory management
|
||||
tmpContent = new QLabel(title);
|
||||
tmpContent->setStyleSheet("QLabel { color: white }");
|
||||
tmpContent->setFixedSize(100, 20);
|
||||
tmpContent->adjustSize();
|
||||
}
|
||||
|
||||
m_previewAR->setArrorDirection(ArrowRectangle::ArrowBottom);
|
||||
|
@ -19,7 +19,7 @@ PluginItemWrapper::PluginItemWrapper(DockPluginInterface *plugin,
|
||||
if (item) {
|
||||
item->setParent(this);
|
||||
item->move(0, 0);
|
||||
item->adjustSize();
|
||||
this->adjustSize();
|
||||
|
||||
emit widthChanged();
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user