Skip to content

Commit

Permalink
refactor: construct FashionTrayItem using TrayPlugin
Browse files Browse the repository at this point in the history
Change-Id: I6df84d6b5a81cb72e55de1c60aa57317cfa32e20
  • Loading branch information
listenerri committed Nov 21, 2018
1 parent 6e88353 commit 7207bbf
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 10 deletions.
11 changes: 6 additions & 5 deletions plugins/tray/fashiontrayitem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,17 @@
int FashionTrayItem::TrayWidgetWidth = TrayWidgetWidthMin;
int FashionTrayItem::TrayWidgetHeight = TrayWidgetHeightMin;

FashionTrayItem::FashionTrayItem(Dock::Position pos, QWidget *parent)
FashionTrayItem::FashionTrayItem(TrayPlugin *trayPlugin, QWidget *parent)
: QWidget(parent),
m_mainBoxLayout(new QBoxLayout(QBoxLayout::Direction::LeftToRight)),
m_trayBoxLayout(new QBoxLayout(QBoxLayout::Direction::LeftToRight)),
m_leftSpliter(new QLabel),
m_rightSpliter(new QLabel),
m_controlWidget(new FashionTrayControlWidget(pos)),
m_currentAttentionTray(nullptr),
m_attentionDelayTimer(new QTimer(this)),
m_dockPosistion(pos)
m_dockPosistion(trayPlugin->dockPosition()),
m_trayPlugin(trayPlugin),
m_controlWidget(new FashionTrayControlWidget(m_dockPosistion)),
m_currentAttentionTray(nullptr)
{
m_leftSpliter->setStyleSheet("background-color: rgba(255, 255, 255, 0.1);");
m_rightSpliter->setStyleSheet("background-color: rgba(255, 255, 255, 0.1);");
Expand Down Expand Up @@ -74,7 +75,7 @@ FashionTrayItem::FashionTrayItem(Dock::Position pos, QWidget *parent)
m_attentionDelayTimer->setInterval(3000);
m_attentionDelayTimer->setSingleShot(true);

setDockPostion(pos);
setDockPostion(m_dockPosistion);
onTrayListExpandChanged(m_controlWidget->expanded());

connect(m_controlWidget, &FashionTrayControlWidget::expandChanged, this, &FashionTrayItem::onTrayListExpandChanged);
Expand Down
12 changes: 8 additions & 4 deletions plugins/tray/fashiontrayitem.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#define FASHIONTRAYITEM_H

#include "constants.h"
#include "trayplugin.h"
#include "fashiontraywidgetwrapper.h"
#include "fashiontraycontrolwidget.h"

Expand All @@ -38,7 +39,7 @@ class FashionTrayItem : public QWidget
Q_OBJECT

public:
explicit FashionTrayItem(Dock::Position pos, QWidget *parent = 0);
explicit FashionTrayItem(TrayPlugin *trayPlugin, QWidget *parent = 0);

void setTrayWidgets(const QMap<QString, AbstractTrayWidget *> &itemTrayMap);
void trayWidgetAdded(const QString &itemKey, AbstractTrayWidget *trayWidget);
Expand Down Expand Up @@ -75,17 +76,20 @@ private Q_SLOTS:
void refreshTraysVisible();

private:
QList<QPointer<FashionTrayWidgetWrapper>> m_wrapperList;
QBoxLayout *m_mainBoxLayout;
QBoxLayout *m_trayBoxLayout;
QLabel *m_leftSpliter;
QLabel *m_rightSpliter;
FashionTrayControlWidget *m_controlWidget;
FashionTrayWidgetWrapper *m_currentAttentionTray;
QTimer *m_attentionDelayTimer;

Dock::Position m_dockPosistion;

TrayPlugin *m_trayPlugin;
FashionTrayControlWidget *m_controlWidget;
FashionTrayWidgetWrapper *m_currentAttentionTray;

QList<QPointer<FashionTrayWidgetWrapper>> m_wrapperList;

static int TrayWidgetWidth;
static int TrayWidgetHeight;
};
Expand Down
7 changes: 6 additions & 1 deletion plugins/tray/trayplugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ TrayPlugin::TrayPlugin(QObject *parent)
m_systemTraysController(new SystemTraysController(this)),
m_tipsLabel(new TipsWidget)
{
m_fashionItem = new FashionTrayItem(position());
m_fashionItem = new FashionTrayItem(this);

m_tipsLabel->setObjectName("tray");
m_tipsLabel->setText(tr("System Tray"));
Expand Down Expand Up @@ -175,6 +175,11 @@ void TrayPlugin::setItemIsInContainer(const QString &itemKey, const bool contain
m_proxyInter->saveValue(this, widKey.isEmpty() ? itemKey : widKey, container);
}

Dock::Position TrayPlugin::dockPosition() const
{
return position();
}

const QString TrayPlugin::getWindowClass(quint32 winId)
{
auto *connection = QX11Info::connection();
Expand Down
2 changes: 2 additions & 0 deletions plugins/tray/trayplugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ class TrayPlugin : public QObject, PluginsItemInterface
void setSortKey(const QString &itemKey, const int order) Q_DECL_OVERRIDE;
void setItemIsInContainer(const QString &itemKey, const bool container) Q_DECL_OVERRIDE;

Dock::Position dockPosition() const;

private:
void loadIndicator();
const QString getWindowClass(quint32 winId);
Expand Down

0 comments on commit 7207bbf

Please sign in to comment.