2020-08-05 19:46:15 +08:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2018 ~ 2028 Deepin Technology Co., Ltd.
|
|
|
|
*
|
|
|
|
* Author: fanpengcheng <fanpengcheng_cm@deepin.com>
|
|
|
|
*
|
|
|
|
* Maintainer: fanpengcheng <fanpengcheng_cm@deepin.com>
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
#include "menuworker.h"
|
2020-12-16 17:38:41 +08:00
|
|
|
#include "dockitemmanager.h"
|
2021-03-12 13:20:13 +08:00
|
|
|
#include "utils.h"
|
2020-08-05 19:46:15 +08:00
|
|
|
|
|
|
|
#include <QAction>
|
|
|
|
#include <QMenu>
|
|
|
|
#include <QGSettings>
|
|
|
|
|
|
|
|
#include <DApplication>
|
|
|
|
|
|
|
|
MenuWorker::MenuWorker(DBusDock *dockInter,QWidget *parent)
|
|
|
|
: QObject (parent)
|
|
|
|
, m_dockInter(dockInter)
|
|
|
|
, m_autoHide(true)
|
|
|
|
{
|
2021-04-16 11:19:56 +08:00
|
|
|
|
2020-08-05 19:46:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
MenuWorker::~MenuWorker()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2021-03-12 13:20:13 +08:00
|
|
|
QMenu *MenuWorker::createMenu()
|
2020-08-05 19:46:15 +08:00
|
|
|
{
|
2021-03-12 13:20:13 +08:00
|
|
|
QMenu *settingsMenu = new QMenu;
|
|
|
|
settingsMenu->setAccessibleName("settingsmenu");
|
|
|
|
settingsMenu->setTitle("Settings Menu");
|
2020-08-05 19:46:15 +08:00
|
|
|
|
2021-03-11 18:03:12 +08:00
|
|
|
// 模式
|
2021-03-20 12:10:45 +08:00
|
|
|
const QGSettings *menuSettings = Utils::ModuleSettingsPtr("menu");
|
2021-03-12 13:20:13 +08:00
|
|
|
if (!menuSettings || !menuSettings->keys().contains("modeVisible") || menuSettings->get("modeVisible").toBool()) {
|
2021-03-11 18:03:12 +08:00
|
|
|
const DisplayMode displayMode = static_cast<DisplayMode>(m_dockInter->displayMode());
|
2020-08-05 19:46:15 +08:00
|
|
|
|
2021-03-12 13:20:13 +08:00
|
|
|
QMenu *modeSubMenu = new QMenu(settingsMenu);
|
2021-03-11 18:03:12 +08:00
|
|
|
modeSubMenu->setAccessibleName("modesubmenu");
|
2020-08-05 19:46:15 +08:00
|
|
|
|
2021-03-11 18:03:12 +08:00
|
|
|
QAction *fashionModeAct = new QAction(tr("Fashion Mode"), this);
|
|
|
|
QAction *efficientModeAct = new QAction(tr("Efficient Mode"), this);
|
2021-02-19 18:08:06 +08:00
|
|
|
|
2021-03-11 18:03:12 +08:00
|
|
|
fashionModeAct->setCheckable(true);
|
|
|
|
efficientModeAct->setCheckable(true);
|
2021-02-18 15:36:59 +08:00
|
|
|
|
2021-03-11 18:03:12 +08:00
|
|
|
fashionModeAct->setChecked(displayMode == Fashion);
|
|
|
|
efficientModeAct->setChecked(displayMode == Efficient);
|
2021-02-18 15:36:59 +08:00
|
|
|
|
2021-03-11 18:03:12 +08:00
|
|
|
connect(fashionModeAct, &QAction::triggered, this, [ = ]{ m_dockInter->setDisplayMode(DisplayMode::Fashion); });
|
|
|
|
connect(efficientModeAct, &QAction::triggered, this, [ = ]{ m_dockInter->setDisplayMode(DisplayMode::Efficient); });
|
2021-02-18 15:36:59 +08:00
|
|
|
|
2021-03-11 18:03:12 +08:00
|
|
|
modeSubMenu->addAction(fashionModeAct);
|
|
|
|
modeSubMenu->addAction(efficientModeAct);
|
2021-02-18 15:36:59 +08:00
|
|
|
|
2021-03-11 18:03:12 +08:00
|
|
|
QAction *act = new QAction(tr("Mode"), this);
|
|
|
|
act->setMenu(modeSubMenu);
|
2021-02-18 15:36:59 +08:00
|
|
|
|
2021-03-12 13:20:13 +08:00
|
|
|
settingsMenu->addAction(act);
|
2021-03-11 18:03:12 +08:00
|
|
|
}
|
2020-08-05 19:46:15 +08:00
|
|
|
|
2021-03-11 18:03:12 +08:00
|
|
|
// 位置
|
2021-03-12 13:20:13 +08:00
|
|
|
if (!menuSettings || !menuSettings->keys().contains("locationVisible") || menuSettings->get("locationVisible").toBool()) {
|
2021-03-11 18:03:12 +08:00
|
|
|
const Position position = static_cast<Position>(m_dockInter->position());
|
2020-08-05 19:46:15 +08:00
|
|
|
|
2021-03-12 13:20:13 +08:00
|
|
|
QMenu *locationSubMenu = new QMenu(settingsMenu);
|
2021-03-11 18:03:12 +08:00
|
|
|
locationSubMenu->setAccessibleName("locationsubmenu");
|
2020-08-05 19:46:15 +08:00
|
|
|
|
2021-03-11 18:03:12 +08:00
|
|
|
QAction *topPosAct = new QAction(tr("Top"), this);
|
|
|
|
QAction *bottomPosAct = new QAction(tr("Bottom"), this);
|
|
|
|
QAction *leftPosAct = new QAction(tr("Left"), this);
|
|
|
|
QAction *rightPosAct = new QAction(tr("Right"), this);
|
2020-08-05 19:46:15 +08:00
|
|
|
|
2021-03-11 18:03:12 +08:00
|
|
|
topPosAct->setCheckable(true);
|
|
|
|
bottomPosAct->setCheckable(true);
|
|
|
|
leftPosAct->setCheckable(true);
|
|
|
|
rightPosAct->setCheckable(true);
|
2020-08-05 19:46:15 +08:00
|
|
|
|
2021-03-11 18:03:12 +08:00
|
|
|
topPosAct->setChecked(position == Top);
|
|
|
|
bottomPosAct->setChecked(position == Bottom);
|
|
|
|
leftPosAct->setChecked(position == Left);
|
|
|
|
rightPosAct->setChecked(position == Right);
|
2020-08-05 19:46:15 +08:00
|
|
|
|
2021-03-11 18:03:12 +08:00
|
|
|
connect(topPosAct, &QAction::triggered, this, [ = ]{ m_dockInter->setPosition(Top); });
|
|
|
|
connect(bottomPosAct, &QAction::triggered, this, [ = ]{ m_dockInter->setPosition(Bottom); });
|
|
|
|
connect(leftPosAct, &QAction::triggered, this, [ = ]{ m_dockInter->setPosition(Left); });
|
|
|
|
connect(rightPosAct, &QAction::triggered, this, [ = ]{ m_dockInter->setPosition(Right); });
|
2020-08-05 19:46:15 +08:00
|
|
|
|
2021-03-11 18:03:12 +08:00
|
|
|
locationSubMenu->addAction(topPosAct);
|
|
|
|
locationSubMenu->addAction(bottomPosAct);
|
|
|
|
locationSubMenu->addAction(leftPosAct);
|
|
|
|
locationSubMenu->addAction(rightPosAct);
|
2020-08-05 19:46:15 +08:00
|
|
|
|
2021-03-11 18:03:12 +08:00
|
|
|
QAction *act = new QAction(tr("Location"), this);
|
|
|
|
act->setMenu(locationSubMenu);
|
|
|
|
|
2021-03-12 13:20:13 +08:00
|
|
|
settingsMenu->addAction(act);
|
2020-08-05 19:46:15 +08:00
|
|
|
}
|
|
|
|
|
2021-03-11 18:03:12 +08:00
|
|
|
// 状态
|
2021-03-12 13:20:13 +08:00
|
|
|
if (!menuSettings || !menuSettings->keys().contains("statusVisible") || menuSettings->get("statusVisible").toBool()) {
|
2021-03-11 18:03:12 +08:00
|
|
|
const HideMode hideMode = static_cast<HideMode>(m_dockInter->hideMode());
|
2020-08-05 19:46:15 +08:00
|
|
|
|
2021-03-12 13:20:13 +08:00
|
|
|
QMenu *statusSubMenu = new QMenu(settingsMenu);
|
2021-03-11 18:03:12 +08:00
|
|
|
statusSubMenu->setAccessibleName("statussubmenu");
|
2020-08-05 19:46:15 +08:00
|
|
|
|
2021-03-11 18:03:12 +08:00
|
|
|
QAction *keepShownAct = new QAction(tr("Keep Shown"), this);
|
|
|
|
QAction *keepHiddenAct = new QAction(tr("Keep Hidden"), this);
|
|
|
|
QAction *smartHideAct = new QAction(tr("Smart Hide"), this);
|
2020-08-05 19:46:15 +08:00
|
|
|
|
2021-03-11 18:03:12 +08:00
|
|
|
keepShownAct->setCheckable(true);
|
|
|
|
keepHiddenAct->setCheckable(true);
|
|
|
|
smartHideAct->setCheckable(true);
|
2020-08-05 19:46:15 +08:00
|
|
|
|
2021-03-11 18:03:12 +08:00
|
|
|
keepShownAct->setChecked(hideMode == KeepShowing);
|
|
|
|
keepHiddenAct->setChecked(hideMode == KeepHidden);
|
|
|
|
smartHideAct->setChecked(hideMode == SmartHide);
|
2020-08-05 19:46:15 +08:00
|
|
|
|
2021-03-11 18:03:12 +08:00
|
|
|
connect(keepShownAct, &QAction::triggered, this, [ = ]{ m_dockInter->setHideMode(KeepShowing); });
|
|
|
|
connect(keepHiddenAct, &QAction::triggered, this, [ = ]{ m_dockInter->setHideMode(KeepHidden); });
|
|
|
|
connect(smartHideAct, &QAction::triggered, this, [ = ]{ m_dockInter->setHideMode(SmartHide); });
|
2020-08-05 19:46:15 +08:00
|
|
|
|
2021-03-11 18:03:12 +08:00
|
|
|
statusSubMenu->addAction(keepShownAct);
|
|
|
|
statusSubMenu->addAction(keepHiddenAct);
|
|
|
|
statusSubMenu->addAction(smartHideAct);
|
2020-08-05 19:46:15 +08:00
|
|
|
|
2021-03-11 18:03:12 +08:00
|
|
|
QAction *act = new QAction(tr("Status"), this);
|
|
|
|
act->setMenu(statusSubMenu);
|
2020-08-05 19:46:15 +08:00
|
|
|
|
2021-03-12 13:20:13 +08:00
|
|
|
settingsMenu->addAction(act);
|
2020-08-05 19:46:15 +08:00
|
|
|
}
|
|
|
|
|
2021-03-11 18:03:12 +08:00
|
|
|
// 插件
|
2021-03-12 13:20:13 +08:00
|
|
|
if (!menuSettings || !menuSettings->keys().contains("hideVisible") || menuSettings->get("hideVisible").toBool()) {
|
|
|
|
QMenu *hideSubMenu = new QMenu(settingsMenu);
|
2021-03-11 18:03:12 +08:00
|
|
|
hideSubMenu->setAccessibleName("pluginsmenu");
|
|
|
|
|
|
|
|
QAction *hideSubMenuAct = new QAction(tr("Plugins"), this);
|
|
|
|
hideSubMenuAct->setMenu(hideSubMenu);
|
|
|
|
|
|
|
|
// create actions
|
|
|
|
QList<QAction *> actions;
|
|
|
|
for (auto *p : DockItemManager::instance()->pluginList()) {
|
|
|
|
if (!p->pluginIsAllowDisable())
|
|
|
|
continue;
|
|
|
|
|
|
|
|
const bool enable = !p->pluginIsDisable();
|
|
|
|
const QString &name = p->pluginName();
|
|
|
|
const QString &display = p->pluginDisplayName();
|
|
|
|
|
|
|
|
// 模块和菜单均需要响应enable配置的变化
|
2021-03-20 12:10:45 +08:00
|
|
|
const QGSettings *setting = Utils::ModuleSettingsPtr(name);
|
2021-03-11 18:03:12 +08:00
|
|
|
if (setting && setting->keys().contains("enable") && !setting->get("enable").toBool()) {
|
|
|
|
continue;
|
|
|
|
}
|
2021-03-12 13:20:13 +08:00
|
|
|
delete setting;
|
|
|
|
setting = nullptr;
|
2021-03-11 18:03:12 +08:00
|
|
|
|
|
|
|
// 未开启窗口特效时,同样不显示多任务视图插件
|
|
|
|
if (name == "multitasking" && !DWindowManagerHelper::instance()->hasComposite()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (name == "deepin-screen-recorder-plugin") {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
QAction *act = new QAction(display, this);
|
|
|
|
act->setCheckable(true);
|
|
|
|
act->setChecked(enable);
|
|
|
|
act->setData(name);
|
|
|
|
|
|
|
|
connect(act, &QAction::triggered, this, [ p ]{p->pluginStateSwitched();});
|
|
|
|
|
|
|
|
// check plugin hide menu.
|
2021-03-20 12:10:45 +08:00
|
|
|
const QGSettings *pluginSettings = Utils::ModuleSettingsPtr(name);
|
2021-03-12 13:20:13 +08:00
|
|
|
if (pluginSettings && (!pluginSettings->keys().contains("visible") || pluginSettings->get("visible").toBool()))
|
2021-03-11 18:03:12 +08:00
|
|
|
actions << act;
|
|
|
|
}
|
2020-08-05 19:46:15 +08:00
|
|
|
|
2021-03-11 18:03:12 +08:00
|
|
|
// sort by name
|
|
|
|
std::sort(actions.begin(), actions.end(), [](QAction * a, QAction * b) -> bool {
|
|
|
|
return a->data().toString() > b->data().toString();
|
|
|
|
});
|
|
|
|
|
|
|
|
// add plugins actions
|
|
|
|
qDeleteAll(hideSubMenu->actions());
|
|
|
|
for (auto act : actions)
|
|
|
|
hideSubMenu->addAction(act);
|
|
|
|
|
|
|
|
// add plugins menu
|
2021-03-12 13:20:13 +08:00
|
|
|
settingsMenu->addAction(hideSubMenuAct);
|
|
|
|
}
|
|
|
|
|
|
|
|
delete menuSettings;
|
|
|
|
menuSettings = nullptr;
|
|
|
|
|
|
|
|
return settingsMenu;
|
|
|
|
}
|
|
|
|
|
|
|
|
void MenuWorker::showDockSettingsMenu()
|
|
|
|
{
|
|
|
|
// 菜单功能被禁用
|
2021-03-20 12:10:45 +08:00
|
|
|
static const QGSettings *setting = Utils::ModuleSettingsPtr("menu", QByteArray(), this);
|
2021-03-12 13:20:13 +08:00
|
|
|
if (setting && setting->keys().contains("enable") && !setting->get("enable").toBool()) {
|
|
|
|
return;
|
2020-08-05 19:46:15 +08:00
|
|
|
}
|
|
|
|
|
2021-03-12 13:20:13 +08:00
|
|
|
// 菜单将要被打开
|
|
|
|
setAutoHide(false);
|
|
|
|
|
|
|
|
QMenu *menu = createMenu();
|
|
|
|
menu->exec(QCursor::pos());
|
2020-08-05 19:46:15 +08:00
|
|
|
|
2021-03-11 18:03:12 +08:00
|
|
|
// 菜单已经关闭
|
|
|
|
setAutoHide(true);
|
2021-03-12 13:20:13 +08:00
|
|
|
delete menu;
|
|
|
|
menu = nullptr;
|
2020-08-05 19:46:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void MenuWorker::setAutoHide(const bool autoHide)
|
|
|
|
{
|
|
|
|
if (m_autoHide == autoHide)
|
|
|
|
return;
|
|
|
|
|
|
|
|
m_autoHide = autoHide;
|
|
|
|
emit autoHideChanged(m_autoHide);
|
|
|
|
}
|