From b24569cee1786aed35b7f9193e3ab73d5a3d5e8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=9F=B3=E5=8D=9A=E6=96=87?= Date: Tue, 21 Jun 2016 14:02:51 +0800 Subject: [PATCH] add panel settings menu Change-Id: I8cca172b7c07d427447f8c5cd45bda1e6d7ef610 --- frame/item/placeholderitem.cpp | 5 ++ frame/item/placeholderitem.h | 3 + frame/util/docksettings.cpp | 110 +++++++++++++++++++++++++++++++++ frame/util/docksettings.h | 26 ++++++++ frame/window/mainwindow.cpp | 8 +++ frame/window/mainwindow.h | 1 + 6 files changed, 153 insertions(+) diff --git a/frame/item/placeholderitem.cpp b/frame/item/placeholderitem.cpp index 28f75680a..6b98c3763 100644 --- a/frame/item/placeholderitem.cpp +++ b/frame/item/placeholderitem.cpp @@ -5,3 +5,8 @@ PlaceholderItem::PlaceholderItem(QWidget *parent) { setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); } + +void PlaceholderItem::mousePressEvent(QMouseEvent *e) +{ + QWidget::mousePressEvent(e); +} diff --git a/frame/item/placeholderitem.h b/frame/item/placeholderitem.h index ada516ceb..8573e5b32 100644 --- a/frame/item/placeholderitem.h +++ b/frame/item/placeholderitem.h @@ -9,6 +9,9 @@ class PlaceholderItem : public DockItem public: explicit PlaceholderItem(QWidget *parent = 0); + +private: + void mousePressEvent(QMouseEvent *e); }; #endif // PLACEHOLDERITEM_H diff --git a/frame/util/docksettings.cpp b/frame/util/docksettings.cpp index 31bc8105c..6c5bd3052 100644 --- a/frame/util/docksettings.cpp +++ b/frame/util/docksettings.cpp @@ -2,12 +2,80 @@ #include +#define ICON_SIZE_LARGE 48 +#define ICON_SIZE_MEDIUM 36 +#define ICON_SIZE_SMALL 24 + DockSettings::DockSettings(QObject *parent) : QObject(parent), + + m_settingsMenu(this), + m_fashionModeAct(tr("Fashion Mode"), this), + m_efficientModeAct(tr("Efficient Mode"), this), + m_topPosAct(tr("Top"), this), + m_bottomPosAct(tr("Bottom"), this), + m_leftPosAct(tr("Left"), this), + m_rightPosAct(tr("Right"), this), + m_largeSizeAct(tr("Large"), this), + m_mediumSizeAct(tr("Medium"), this), + m_smallSizeAct(tr("Small"), this), + m_keepShownAct(tr("Keep Shown"), this), + m_keepHiddenAct(tr("Keep Hidden"), this), + m_smartHideAct(tr("Smart Hide"), this), + m_dockInter(new DBusDock(this)), m_itemController(DockItemController::instance(this)) { m_position = Dock::Position(m_dockInter->position()); + m_displayMode = Dock::DisplayMode(m_dockInter->displayMode()); + + m_fashionModeAct.setCheckable(true); + m_efficientModeAct.setCheckable(true); + m_topPosAct.setCheckable(true); + m_bottomPosAct.setCheckable(true); + m_leftPosAct.setCheckable(true); + m_rightPosAct.setCheckable(true); + m_largeSizeAct.setCheckable(true); + m_mediumSizeAct.setCheckable(true); + m_smallSizeAct.setCheckable(true); + m_keepShownAct.setCheckable(true); + m_keepHiddenAct.setCheckable(true); + m_smartHideAct.setCheckable(true); + + DMenu *modeSubMenu = new DMenu(&m_settingsMenu); + modeSubMenu->addAction(&m_fashionModeAct); + modeSubMenu->addAction(&m_efficientModeAct); + DAction *modeSubMenuAct = new DAction(tr("Mode"), this); + modeSubMenuAct->setMenu(modeSubMenu); + + DMenu *locationSubMenu = new DMenu(&m_settingsMenu); + locationSubMenu->addAction(&m_topPosAct); + locationSubMenu->addAction(&m_bottomPosAct); + locationSubMenu->addAction(&m_leftPosAct); + locationSubMenu->addAction(&m_rightPosAct); + DAction *locationSubMenuAct = new DAction(tr("Location"), this); + locationSubMenuAct->setMenu(locationSubMenu); + + DMenu *sizeSubMenu = new DMenu(&m_settingsMenu); + sizeSubMenu->addAction(&m_largeSizeAct); + sizeSubMenu->addAction(&m_mediumSizeAct); + sizeSubMenu->addAction(&m_smallSizeAct); + DAction *sizeSubMenuAct = new DAction(tr("Size"), this); + sizeSubMenuAct->setMenu(sizeSubMenu); + + DMenu *statusSubMenu = new DMenu(&m_settingsMenu); + statusSubMenu->addAction(&m_keepShownAct); + statusSubMenu->addAction(&m_keepHiddenAct); + statusSubMenu->addAction(&m_smartHideAct); + DAction *statusSubMenuAct = new DAction(tr("Status"), this); + statusSubMenuAct->setMenu(statusSubMenu); + + m_settingsMenu.addAction(modeSubMenuAct); + m_settingsMenu.addAction(locationSubMenuAct); + m_settingsMenu.addAction(sizeSubMenuAct); + m_settingsMenu.addAction(statusSubMenuAct); + + connect(&m_settingsMenu, &DMenu::triggered, this, &DockSettings::menuActionClicked); } Position DockSettings::position() const @@ -20,7 +88,49 @@ const QSize DockSettings::mainWindowSize() const return m_mainWindowSize; } +void DockSettings::showDockSettingsMenu() +{ + m_fashionModeAct.setChecked(m_displayMode == Fashion); + m_efficientModeAct.setChecked(m_displayMode == Efficient); + m_topPosAct.setChecked(m_position == Top); + m_bottomPosAct.setChecked(m_position == Bottom); + m_leftPosAct.setChecked(m_position == Left); + m_rightPosAct.setChecked(m_position == Right); + m_largeSizeAct.setChecked(m_iconSize == ICON_SIZE_LARGE); + m_mediumSizeAct.setChecked(m_iconSize == ICON_SIZE_MEDIUM); + m_smallSizeAct.setChecked(m_iconSize == ICON_SIZE_SMALL); + m_keepShownAct.setChecked(m_hideMode == KeepShowing); + m_keepHiddenAct.setChecked(m_hideMode == KeepHidden); + m_smartHideAct.setChecked(m_hideMode == SmartHide); + + m_settingsMenu.exec(); +} + void DockSettings::updateGeometry() { } + +void DockSettings::menuActionClicked(DAction *action) +{ + Q_ASSERT(action); + + if (action == &m_fashionModeAct) + return m_dockInter->setDisplayMode(Fashion); + if (action == &m_efficientModeAct) + return m_dockInter->setDisplayMode(Efficient); + if (action == &m_topPosAct) + return m_dockInter->setPosition(Top); + if (action == &m_bottomPosAct) + return m_dockInter->setPosition(Bottom); + if (action == &m_leftPosAct) + return m_dockInter->setPosition(Left); + if (action == &m_rightPosAct) + return m_dockInter->setPosition(Right); + if (action == &m_keepShownAct) + return m_dockInter->setHideMode(KeepShowing); + if (action == &m_keepHiddenAct) + return m_dockInter->setHideMode(KeepHidden); + if (action == &m_smartHideAct) + return m_dockInter->setHideMode(SmartHide); +} diff --git a/frame/util/docksettings.h b/frame/util/docksettings.h index 55253c986..cd8749320 100644 --- a/frame/util/docksettings.h +++ b/frame/util/docksettings.h @@ -3,11 +3,17 @@ #include "constants.h" #include "dbus/dbusdock.h" +#include "dbus/dbusmenumanager.h" #include "controller/dockitemcontroller.h" +#include +#include + #include #include +DWIDGET_USE_NAMESPACE + using namespace Dock; class DockSettings : public QObject @@ -20,6 +26,8 @@ public: Position position() const; const QSize mainWindowSize() const; + void showDockSettingsMenu(); + signals: void dataChanged() const; @@ -27,11 +35,29 @@ public slots: void updateGeometry(); private slots: + void menuActionClicked(DAction *action); private: + int m_iconSize; Position m_position; + HideMode m_hideMode; + DisplayMode m_displayMode; QSize m_mainWindowSize; + DMenu m_settingsMenu; + DAction m_fashionModeAct; + DAction m_efficientModeAct; + DAction m_topPosAct; + DAction m_bottomPosAct; + DAction m_leftPosAct; + DAction m_rightPosAct; + DAction m_largeSizeAct; + DAction m_mediumSizeAct; + DAction m_smallSizeAct; + DAction m_keepShownAct; + DAction m_keepHiddenAct; + DAction m_smartHideAct; + DBusDock *m_dockInter; DockItemController *m_itemController; }; diff --git a/frame/window/mainwindow.cpp b/frame/window/mainwindow.cpp index 02a6f6009..5667ed3fc 100644 --- a/frame/window/mainwindow.cpp +++ b/frame/window/mainwindow.cpp @@ -36,6 +36,14 @@ void MainWindow::resizeEvent(QResizeEvent *e) m_mainPanel->setFixedSize(e->size()); } +void MainWindow::mousePressEvent(QMouseEvent *e) +{ + e->ignore(); + + if (e->button() == Qt::RightButton) + m_settings->showDockSettingsMenu(); +} + void MainWindow::keyPressEvent(QKeyEvent *e) { switch (e->key()) diff --git a/frame/window/mainwindow.h b/frame/window/mainwindow.h index 73b249663..a6aa6acdc 100644 --- a/frame/window/mainwindow.h +++ b/frame/window/mainwindow.h @@ -19,6 +19,7 @@ public: private: void resizeEvent(QResizeEvent *e); + void mousePressEvent(QMouseEvent *e); void keyPressEvent(QKeyEvent *e); void initComponents(); void initConnections();