2020-08-05 19:46:15 +08:00
|
|
|
/*
|
2021-06-18 17:36:06 +08:00
|
|
|
* Copyright (C) 2018 ~ 2020 Deepin Technology Co., Ltd.
|
2020-08-05 19:46:15 +08:00
|
|
|
*
|
|
|
|
* 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"
|
2021-08-23 11:39:52 +08:00
|
|
|
#include "displaymanager.h"
|
2020-08-05 19:46:15 +08:00
|
|
|
|
|
|
|
#include <QAction>
|
|
|
|
#include <QMenu>
|
|
|
|
#include <QGSettings>
|
|
|
|
|
|
|
|
#include <DApplication>
|
2021-09-28 15:59:06 +08:00
|
|
|
#include <DDBusSender>
|
2020-08-05 19:46:15 +08:00
|
|
|
|
2021-08-23 11:39:52 +08:00
|
|
|
#define DIS_INS DisplayManager::instance()
|
|
|
|
|
2022-06-22 11:18:29 +08:00
|
|
|
MenuWorker::MenuWorker(DockInter *dockInter,QWidget *parent)
|
|
|
|
: QObject(parent)
|
2020-08-05 19:46:15 +08:00
|
|
|
, m_dockInter(dockInter)
|
|
|
|
, m_autoHide(true)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-01-06 10:53:18 +08:00
|
|
|
QMenu *MenuWorker::createMenu(QMenu *settingsMenu)
|
2020-08-05 19:46:15 +08:00
|
|
|
{
|
2021-03-12 13:20:13 +08:00
|
|
|
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-09-28 15:59:06 +08:00
|
|
|
// 任务栏配置
|
|
|
|
if (!menuSettings || !menuSettings->keys().contains("settingVisible") || menuSettings->get("settingVisible").toBool()) {
|
2021-10-13 11:27:50 +08:00
|
|
|
QAction *act = new QAction(tr("Dock settings"), this);
|
2021-09-28 15:59:06 +08:00
|
|
|
connect(act, &QAction::triggered, this, &MenuWorker::onDockSettingsTriggered);
|
2021-08-23 11:39:52 +08:00
|
|
|
settingsMenu->addAction(act);
|
|
|
|
}
|
|
|
|
|
2021-03-12 13:20:13 +08:00
|
|
|
delete menuSettings;
|
|
|
|
menuSettings = nullptr;
|
|
|
|
return settingsMenu;
|
|
|
|
}
|
|
|
|
|
2021-09-28 15:59:06 +08:00
|
|
|
void MenuWorker::onDockSettingsTriggered()
|
|
|
|
{
|
2022-07-22 02:27:43 +00:00
|
|
|
DDBusSender().service("org.deepin.dde.ControlCenter")
|
|
|
|
.path("/org/deepin/dde/ControlCenter")
|
|
|
|
.interface("org.deepin.dde.ControlCenter")
|
2021-09-28 15:59:06 +08:00
|
|
|
.method("ShowPage")
|
2022-05-27 20:41:09 +08:00
|
|
|
.arg(QString("personalization/dock"))
|
2021-09-28 15:59:06 +08:00
|
|
|
.call();
|
|
|
|
}
|
|
|
|
|
2022-01-06 10:53:18 +08:00
|
|
|
void MenuWorker::showDockSettingsMenu(QMenu *menu)
|
2021-03-12 13:20:13 +08:00
|
|
|
{
|
|
|
|
// 菜单功能被禁用
|
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);
|
|
|
|
|
2022-01-06 10:53:18 +08:00
|
|
|
menu = createMenu(menu);
|
2021-03-12 13:20:13 +08:00
|
|
|
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);
|
|
|
|
}
|