feat:replace DockItemController to DockItemManager

This commit is contained in:
王少君 2019-08-17 18:01:32 +08:00 committed by 张继德
parent b13a361031
commit 854d8a68a4
3 changed files with 31 additions and 43 deletions

View File

@ -39,6 +39,7 @@ class DockPluginsController : public AbstractPluginsController
Q_OBJECT Q_OBJECT
friend class DockItemController; friend class DockItemController;
friend class DockItemManager;
public: public:
explicit DockPluginsController(QObject *parent = 0); explicit DockPluginsController(QObject *parent = 0);

View File

@ -59,7 +59,7 @@ DockSettings::DockSettings(QWidget *parent)
, m_smartHideAct(tr("Smart Hide"), this) , m_smartHideAct(tr("Smart Hide"), this)
, m_displayInter(new DBusDisplay(this)) , m_displayInter(new DBusDisplay(this))
, m_dockInter(new DBusDock("com.deepin.dde.daemon.Dock", "/com/deepin/dde/daemon/Dock", QDBusConnection::sessionBus(), this)) , m_dockInter(new DBusDock("com.deepin.dde.daemon.Dock", "/com/deepin/dde/daemon/Dock", QDBusConnection::sessionBus(), this))
, m_itemController(DockItemController::instance(this)) , m_itemManager(DockItemManager::instance(this))
{ {
m_primaryRawRect = m_displayInter->primaryRawRect(); m_primaryRawRect = m_displayInter->primaryRawRect();
m_screenRawHeight = m_displayInter->screenRawHeight(); m_screenRawHeight = m_displayInter->screenRawHeight();
@ -136,15 +136,15 @@ DockSettings::DockSettings(QWidget *parent)
connect(m_dockInter, &DBusDock::ServiceRestarted, this, &DockSettings::resetFrontendGeometry); connect(m_dockInter, &DBusDock::ServiceRestarted, this, &DockSettings::resetFrontendGeometry);
connect(m_dockInter, &DBusDock::OpacityChanged, this, &DockSettings::onOpacityChanged); connect(m_dockInter, &DBusDock::OpacityChanged, this, &DockSettings::onOpacityChanged);
connect(m_itemController, &DockItemController::itemInserted, this, &DockSettings::dockItemCountChanged, Qt::QueuedConnection); connect(m_itemManager, &DockItemManager::itemInserted, this, &DockSettings::dockItemCountChanged, Qt::QueuedConnection);
connect(m_itemController, &DockItemController::itemRemoved, this, &DockSettings::dockItemCountChanged, Qt::QueuedConnection); connect(m_itemManager, &DockItemManager::itemRemoved, this, &DockSettings::dockItemCountChanged, Qt::QueuedConnection);
connect(m_itemController, &DockItemController::fashionTraySizeChanged, this, &DockSettings::onFashionTraySizeChanged, Qt::QueuedConnection); connect(m_itemManager, &DockItemManager::fashionTraySizeChanged, this, &DockSettings::onFashionTraySizeChanged, Qt::QueuedConnection);
connect(m_displayInter, &DBusDisplay::PrimaryRectChanged, this, &DockSettings::primaryScreenChanged, Qt::QueuedConnection); connect(m_displayInter, &DBusDisplay::PrimaryRectChanged, this, &DockSettings::primaryScreenChanged, Qt::QueuedConnection);
connect(m_displayInter, &DBusDisplay::ScreenHeightChanged, this, &DockSettings::primaryScreenChanged, Qt::QueuedConnection); connect(m_displayInter, &DBusDisplay::ScreenHeightChanged, this, &DockSettings::primaryScreenChanged, Qt::QueuedConnection);
connect(m_displayInter, &DBusDisplay::ScreenWidthChanged, this, &DockSettings::primaryScreenChanged, Qt::QueuedConnection); connect(m_displayInter, &DBusDisplay::ScreenWidthChanged, this, &DockSettings::primaryScreenChanged, Qt::QueuedConnection);
DApplication *app = qobject_cast<DApplication*>(qApp); DApplication *app = qobject_cast<DApplication *>(qApp);
if (app) { if (app) {
connect(app, &DApplication::iconThemeChanged, this, &DockSettings::gtkIconThemeChanged); connect(app, &DApplication::iconThemeChanged, this, &DockSettings::gtkIconThemeChanged);
} }
@ -153,7 +153,7 @@ DockSettings::DockSettings(QWidget *parent)
updateForbidPostions(); updateForbidPostions();
resetFrontendGeometry(); resetFrontendGeometry();
QTimer::singleShot(0, this, [=] {onOpacityChanged(m_dockInter->opacity());}); QTimer::singleShot(0, this, [ = ] {onOpacityChanged(m_dockInter->opacity());});
} }
DockSettings &DockSettings::Instance() DockSettings &DockSettings::Instance()
@ -181,10 +181,8 @@ const QSize DockSettings::panelSize() const
const QRect DockSettings::windowRect(const Position position, const bool hide) const const QRect DockSettings::windowRect(const Position position, const bool hide) const
{ {
QSize size = m_mainWindowSize; QSize size = m_mainWindowSize;
if (hide) if (hide) {
{ switch (position) {
switch (position)
{
case Top: case Top:
case Bottom: size.setHeight(2); break; case Bottom: size.setHeight(2); break;
case Left: case Left:
@ -197,8 +195,7 @@ const QRect DockSettings::windowRect(const Position position, const bool hide) c
const int offsetY = (primaryRect.height() - size.height()) / 2; const int offsetY = (primaryRect.height() - size.height()) / 2;
QPoint p(0, 0); QPoint p(0, 0);
switch (position) switch (position) {
{
case Top: case Top:
p = QPoint(offsetX, 0); break; p = QPoint(offsetX, 0); break;
case Left: case Left:
@ -207,7 +204,7 @@ const QRect DockSettings::windowRect(const Position position, const bool hide) c
p = QPoint(primaryRect.width() - size.width(), offsetY); break; p = QPoint(primaryRect.width() - size.width(), offsetY); break;
case Bottom: case Bottom:
p = QPoint(offsetX, primaryRect.height() - size.height()); break; p = QPoint(offsetX, primaryRect.height() - size.height()); break;
default:Q_UNREACHABLE(); default: Q_UNREACHABLE();
} }
return QRect(primaryRect.topLeft() + p, size); return QRect(primaryRect.topLeft() + p, size);
@ -219,8 +216,7 @@ void DockSettings::showDockSettingsMenu()
// create actions // create actions
QList<QAction *> actions; QList<QAction *> actions;
for (auto *p : m_itemController->pluginList()) for (auto *p : m_itemManager->pluginList()) {
{
if (!p->pluginIsAllowDisable()) if (!p->pluginIsAllowDisable())
continue; continue;
@ -242,7 +238,7 @@ void DockSettings::showDockSettingsMenu()
} }
// sort by name // sort by name
std::sort(actions.begin(), actions.end(), [] (QAction *a, QAction *b) -> bool { std::sort(actions.begin(), actions.end(), [](QAction * a, QAction * b) -> bool {
return a->data().toString() > b->data().toString(); return a->data().toString() > b->data().toString();
}); });
@ -323,8 +319,7 @@ void DockSettings::menuActionClicked(QAction *action)
const QString &data = action->data().toString(); const QString &data = action->data().toString();
if (data.isEmpty()) if (data.isEmpty())
return; return;
for (auto *p : m_itemController->pluginList()) for (auto *p : m_itemManager->pluginList()) {
{
if (p->pluginName() == data) if (p->pluginName() == data)
return p->pluginStateSwitched(); return p->pluginStateSwitched();
} }
@ -347,7 +342,7 @@ void DockSettings::onPositionChanged()
calculateWindowConfig(); calculateWindowConfig();
m_itemController->refershItemsIcon(); m_itemManager->refershItemsIcon();
}); });
} }
@ -373,7 +368,7 @@ void DockSettings::onDisplayModeChanged()
emit displayModeChanegd(); emit displayModeChanegd();
QTimer::singleShot(1, m_itemController, &DockItemController::sortPluginItems); QTimer::singleShot(1, m_itemManager, &DockItemManager::sortPluginItems);
} }
void DockSettings::hideModeChanged() void DockSettings::hideModeChanged()
@ -435,8 +430,7 @@ void DockSettings::resetFrontendGeometry()
bool DockSettings::test(const Position pos, const QList<QRect> &otherScreens) const bool DockSettings::test(const Position pos, const QList<QRect> &otherScreens) const
{ {
QRect maxStrut(0, 0, m_screenRawWidth, m_screenRawHeight); QRect maxStrut(0, 0, m_screenRawWidth, m_screenRawHeight);
switch (pos) switch (pos) {
{
case Top: case Top:
maxStrut.setBottom(m_primaryRawRect.top() - 1); maxStrut.setBottom(m_primaryRawRect.top() - 1);
maxStrut.setLeft(m_primaryRawRect.left()); maxStrut.setLeft(m_primaryRawRect.left());
@ -480,8 +474,7 @@ void DockSettings::updateForbidPostions()
QSet<Position> forbids; QSet<Position> forbids;
QList<QRect> rawScreenRects; QList<QRect> rawScreenRects;
for (auto *s : screens) for (auto *s : screens) {
{
qInfo() << s->name() << s->geometry(); qInfo() << s->name() << s->geometry();
if (s == qApp->primaryScreen()) if (s == qApp->primaryScreen())
@ -535,10 +528,8 @@ void DockSettings::calculateWindowConfig()
const int defaultHeight = std::round(AppItem::itemBaseHeight() / ratio); const int defaultHeight = std::round(AppItem::itemBaseHeight() / ratio);
const int defaultWidth = std::round(AppItem::itemBaseWidth() / ratio); const int defaultWidth = std::round(AppItem::itemBaseWidth() / ratio);
if (m_displayMode == Dock::Efficient) if (m_displayMode == Dock::Efficient) {
{ switch (m_position) {
switch (m_position)
{
case Top: case Top:
case Bottom: case Bottom:
m_mainWindowSize.setHeight(defaultHeight + PANEL_BORDER); m_mainWindowSize.setHeight(defaultHeight + PANEL_BORDER);
@ -554,15 +545,11 @@ void DockSettings::calculateWindowConfig()
default: default:
Q_ASSERT(false); Q_ASSERT(false);
} }
} } else if (m_displayMode == Dock::Fashion) {
else if (m_displayMode == Dock::Fashion)
{
int visibleItemCount = 0; int visibleItemCount = 0;
const auto &itemList = m_itemController->itemList(); const auto &itemList = m_itemManager->itemList();
for (auto item : itemList) for (auto item : itemList) {
{ switch (item->itemType()) {
switch (item->itemType())
{
case DockItem::Launcher: case DockItem::Launcher:
case DockItem::App: case DockItem::App:
case DockItem::Plugins: case DockItem::Plugins:
@ -580,8 +567,7 @@ void DockSettings::calculateWindowConfig()
const int maxHeight = primaryRect.height() - FASHION_MODE_PADDING * 2; const int maxHeight = primaryRect.height() - FASHION_MODE_PADDING * 2;
const int calcWidth = qMin(maxWidth, perfectWidth); const int calcWidth = qMin(maxWidth, perfectWidth);
const int calcHeight = qMin(maxHeight, perfectHeight); const int calcHeight = qMin(maxHeight, perfectHeight);
switch (m_position) switch (m_position) {
{
case Top: case Top:
case Bottom: { case Bottom: {
m_mainWindowSize.setHeight(defaultHeight + PANEL_BORDER); m_mainWindowSize.setHeight(defaultHeight + PANEL_BORDER);
@ -612,7 +598,7 @@ void DockSettings::calculateWindowConfig()
void DockSettings::gtkIconThemeChanged() void DockSettings::gtkIconThemeChanged()
{ {
qDebug() << Q_FUNC_INFO; qDebug() << Q_FUNC_INFO;
m_itemController->refershItemsIcon(); m_itemManager->refershItemsIcon();
} }
qreal DockSettings::dockRatio() const qreal DockSettings::dockRatio() const

View File

@ -25,7 +25,7 @@
#include "constants.h" #include "constants.h"
#include "dbus/dbusmenumanager.h" #include "dbus/dbusmenumanager.h"
#include "dbus/dbusdisplay.h" #include "dbus/dbusdisplay.h"
#include "controller/dockitemcontroller.h" #include "controller/dockitemmanager.h"
#include <com_deepin_dde_daemon_dock.h> #include <com_deepin_dde_daemon_dock.h>
@ -46,7 +46,8 @@ class WhiteMenu : public QMenu
{ {
Q_OBJECT Q_OBJECT
public: public:
WhiteMenu(QWidget * parent = nullptr) : QMenu(parent) { WhiteMenu(QWidget *parent = nullptr) : QMenu(parent)
{
QStyle *style = QStyleFactory::create("dlight"); QStyle *style = QStyleFactory::create("dlight");
if (style) setStyle(style); if (style) setStyle(style);
} }
@ -59,7 +60,7 @@ class DockSettings : public QObject
Q_OBJECT Q_OBJECT
public: public:
static DockSettings& Instance(); static DockSettings &Instance();
inline DisplayMode displayMode() const { return m_displayMode; } inline DisplayMode displayMode() const { return m_displayMode; }
inline HideMode hideMode() const { return m_hideMode; } inline HideMode hideMode() const { return m_hideMode; }
@ -155,7 +156,7 @@ private:
DBusDisplay *m_displayInter; DBusDisplay *m_displayInter;
DBusDock *m_dockInter; DBusDock *m_dockInter;
DockItemController *m_itemController; DockItemManager *m_itemManager;
}; };
#endif // DOCKSETTINGS_H #endif // DOCKSETTINGS_H