2019-08-14 15:17:04 +08:00
|
|
|
|
/*
|
|
|
|
|
* Copyright (C) 2019 ~ 2019 Deepin Technology Co., Ltd.
|
|
|
|
|
*
|
|
|
|
|
* Author: xuwenw <xuwenw@xuwenw.so>
|
|
|
|
|
*
|
|
|
|
|
* Maintainer: xuwenw <xuwenw@xuwenw.so>
|
|
|
|
|
*
|
|
|
|
|
* 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 "mainpanelcontrol.h"
|
2019-08-17 18:24:24 +08:00
|
|
|
|
#include "../item/dockitem.h"
|
2019-08-29 20:21:36 +08:00
|
|
|
|
#include "../item/placeholderitem.h"
|
|
|
|
|
#include "../item/components/appdrag.h"
|
|
|
|
|
#include "../item/appitem.h"
|
2019-10-28 14:42:56 +08:00
|
|
|
|
#include "../item/pluginsitem.h"
|
2019-10-31 15:38:56 +08:00
|
|
|
|
#include "../item/traypluginitem.h"
|
2020-03-09 11:06:03 +08:00
|
|
|
|
#include "../controller/dockitemmanager.h"
|
2020-08-18 10:41:14 +08:00
|
|
|
|
#include "util/touchsignalmanager.h"
|
2019-08-14 15:17:04 +08:00
|
|
|
|
|
2019-08-21 12:52:53 +08:00
|
|
|
|
#include <QDrag>
|
2019-08-14 15:17:04 +08:00
|
|
|
|
#include <QTimer>
|
2019-09-09 13:26:27 +08:00
|
|
|
|
#include <QStandardPaths>
|
|
|
|
|
#include <QString>
|
2019-09-24 19:17:51 +08:00
|
|
|
|
#include <QApplication>
|
2020-02-14 23:25:09 +08:00
|
|
|
|
#include <QGSettings>
|
2020-03-09 11:06:03 +08:00
|
|
|
|
#include <QPointer>
|
2019-08-14 15:17:04 +08:00
|
|
|
|
|
2019-09-17 13:14:23 +08:00
|
|
|
|
#include <DGuiApplicationHelper>
|
2019-09-24 10:47:43 +08:00
|
|
|
|
#include <DWindowManagerHelper>
|
2019-09-17 13:14:23 +08:00
|
|
|
|
|
|
|
|
|
#define SPLITER_SIZE 2
|
2019-10-28 14:42:56 +08:00
|
|
|
|
#define TRASH_MARGIN 20
|
2019-10-31 15:38:56 +08:00
|
|
|
|
#define PLUGIN_MAX_SIZE 40
|
|
|
|
|
#define PLUGIN_MIN_SIZE 20
|
2019-12-24 13:09:50 +08:00
|
|
|
|
#define DESKTOP_SIZE 10
|
2019-09-17 13:14:23 +08:00
|
|
|
|
|
2019-08-14 15:17:04 +08:00
|
|
|
|
DWIDGET_USE_NAMESPACE
|
|
|
|
|
|
2020-02-14 23:25:09 +08:00
|
|
|
|
static QGSettings *GSettingsByLaunch()
|
|
|
|
|
{
|
|
|
|
|
static QGSettings settings("com.deepin.dde.dock.module.launcher");
|
|
|
|
|
return &settings;
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-14 15:17:04 +08:00
|
|
|
|
MainPanelControl::MainPanelControl(QWidget *parent)
|
|
|
|
|
: QWidget(parent)
|
|
|
|
|
, m_mainPanelLayout(new QBoxLayout(QBoxLayout::LeftToRight, this))
|
|
|
|
|
, m_fixedAreaWidget(new QWidget(this))
|
2020-10-28 11:30:50 +08:00
|
|
|
|
, m_fixedAreaLayout(new QBoxLayout(QBoxLayout::LeftToRight))
|
|
|
|
|
, m_fixedSpliter(new QLabel(this))
|
2019-08-14 15:17:04 +08:00
|
|
|
|
, m_appAreaWidget(new QWidget(this))
|
2020-10-28 11:30:50 +08:00
|
|
|
|
, m_appAreaSonWidget(new QWidget(this))
|
|
|
|
|
, m_appAreaSonLayout(new QBoxLayout(QBoxLayout::LeftToRight))
|
|
|
|
|
, m_appSpliter(new QLabel(this))
|
2019-08-14 15:17:04 +08:00
|
|
|
|
, m_trayAreaWidget(new QWidget(this))
|
|
|
|
|
, m_trayAreaLayout(new QBoxLayout(QBoxLayout::LeftToRight))
|
2020-10-28 11:30:50 +08:00
|
|
|
|
, m_traySpliter(new QLabel(this))
|
|
|
|
|
, m_pluginAreaWidget(new QWidget(this))
|
2019-08-14 15:17:04 +08:00
|
|
|
|
, m_pluginLayout(new QBoxLayout(QBoxLayout::LeftToRight))
|
2020-10-28 11:30:50 +08:00
|
|
|
|
, m_desktopWidget(new DesktopWidget(this))
|
2019-11-23 10:15:59 +08:00
|
|
|
|
, m_position(Position::Bottom)
|
2019-08-29 20:21:36 +08:00
|
|
|
|
, m_placeholderItem(nullptr)
|
|
|
|
|
, m_appDragWidget(nullptr)
|
2019-08-30 11:41:52 +08:00
|
|
|
|
, m_dislayMode(Efficient)
|
2019-12-23 13:48:11 +08:00
|
|
|
|
, m_isHover(false)
|
2020-07-28 14:42:16 +08:00
|
|
|
|
, m_needRecoveryWin(false)
|
2020-02-14 23:25:09 +08:00
|
|
|
|
, m_isEnableLaunch(true)
|
2019-08-14 15:17:04 +08:00
|
|
|
|
{
|
2020-10-28 11:30:50 +08:00
|
|
|
|
initUi();
|
2019-08-14 15:17:04 +08:00
|
|
|
|
updateMainPanelLayout();
|
2019-08-21 12:52:53 +08:00
|
|
|
|
setAcceptDrops(true);
|
2019-08-30 15:54:19 +08:00
|
|
|
|
setMouseTracking(true);
|
2019-12-23 13:48:11 +08:00
|
|
|
|
m_desktopWidget->setMouseTracking(true);
|
2020-05-08 11:26:09 +08:00
|
|
|
|
m_desktopWidget->setObjectName("showdesktoparea");
|
2019-08-30 11:41:52 +08:00
|
|
|
|
|
2019-09-04 10:31:37 +08:00
|
|
|
|
m_appAreaWidget->installEventFilter(this);
|
2019-09-09 09:58:31 +08:00
|
|
|
|
m_appAreaSonWidget->installEventFilter(this);
|
2019-10-28 14:42:56 +08:00
|
|
|
|
m_trayAreaWidget->installEventFilter(this);
|
2019-12-23 13:48:11 +08:00
|
|
|
|
m_desktopWidget->installEventFilter(this);
|
2020-04-26 18:42:42 +08:00
|
|
|
|
|
|
|
|
|
//在设置每条线大小前,应该设置fixedsize(0,0)
|
|
|
|
|
//应为paintEvent函数会先调用设置背景颜色,大小为随机值
|
|
|
|
|
m_fixedSpliter->setFixedSize(0,0);
|
|
|
|
|
m_appSpliter ->setFixedSize(0,0);
|
|
|
|
|
m_traySpliter->setFixedSize(0,0);
|
2019-08-14 15:17:04 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MainPanelControl::~MainPanelControl()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-28 11:30:50 +08:00
|
|
|
|
void MainPanelControl::initUi()
|
2019-08-14 15:17:04 +08:00
|
|
|
|
{
|
2020-10-28 11:30:50 +08:00
|
|
|
|
/* 固定区域 */
|
|
|
|
|
m_fixedAreaWidget->setObjectName("fixedarea");
|
|
|
|
|
m_fixedAreaWidget->setLayout(m_fixedAreaLayout);
|
|
|
|
|
m_fixedAreaLayout->setSpacing(0);
|
|
|
|
|
m_fixedAreaLayout->setContentsMargins(0, 0, 0, 0);
|
|
|
|
|
m_mainPanelLayout->addWidget(m_fixedAreaWidget);
|
|
|
|
|
|
2020-05-06 17:28:16 +08:00
|
|
|
|
m_fixedSpliter->setObjectName("spliter_fix");
|
2020-12-08 13:45:51 +08:00
|
|
|
|
m_mainPanelLayout->addWidget(m_fixedSpliter);
|
2020-03-13 12:59:02 +08:00
|
|
|
|
|
2020-10-28 11:30:50 +08:00
|
|
|
|
/* 应用程序区域 */
|
2020-05-27 14:24:18 +08:00
|
|
|
|
m_appAreaWidget->setAccessibleName("AppFullArea");
|
2019-09-06 14:44:07 +08:00
|
|
|
|
m_mainPanelLayout->addWidget(m_appAreaWidget);
|
2020-10-28 11:30:50 +08:00
|
|
|
|
m_appAreaSonWidget->setObjectName("apparea");
|
|
|
|
|
m_appAreaSonWidget->setLayout(m_appAreaSonLayout);
|
2019-08-17 18:24:24 +08:00
|
|
|
|
m_appAreaSonLayout->setSpacing(0);
|
2020-10-28 11:30:50 +08:00
|
|
|
|
m_appAreaSonLayout->setContentsMargins(0, 0, 0, 0);
|
2019-09-06 14:44:07 +08:00
|
|
|
|
|
2020-10-28 11:30:50 +08:00
|
|
|
|
m_appSpliter->setObjectName("spliter_app");
|
2020-12-08 13:45:51 +08:00
|
|
|
|
m_mainPanelLayout->addWidget(m_appSpliter);
|
2020-10-28 11:30:50 +08:00
|
|
|
|
|
|
|
|
|
/* 托盘区域 */
|
2020-05-06 17:28:16 +08:00
|
|
|
|
m_trayAreaWidget->setObjectName("trayarea");
|
2020-10-28 11:30:50 +08:00
|
|
|
|
m_trayAreaWidget->setLayout(m_trayAreaLayout);
|
2019-08-17 18:24:24 +08:00
|
|
|
|
m_trayAreaLayout->setSpacing(0);
|
2020-10-28 11:30:50 +08:00
|
|
|
|
m_trayAreaLayout->setContentsMargins(0, 10, 0, 10);
|
|
|
|
|
m_mainPanelLayout->addWidget(m_trayAreaWidget);
|
2019-09-06 14:44:07 +08:00
|
|
|
|
|
2020-10-28 11:30:50 +08:00
|
|
|
|
m_traySpliter->setObjectName("spliter_tray");
|
2020-12-08 13:45:51 +08:00
|
|
|
|
m_mainPanelLayout->addWidget(m_traySpliter);
|
2020-10-28 11:30:50 +08:00
|
|
|
|
|
|
|
|
|
/* 插件区域 */
|
2020-05-06 17:28:16 +08:00
|
|
|
|
m_pluginAreaWidget->setObjectName("pluginarea");
|
2020-10-28 11:30:50 +08:00
|
|
|
|
m_pluginAreaWidget->setLayout(m_pluginLayout);
|
2019-09-05 15:30:14 +08:00
|
|
|
|
m_pluginLayout->setSpacing(10);
|
2020-10-28 11:30:50 +08:00
|
|
|
|
m_pluginLayout->setContentsMargins(0, 0, 0, 0);
|
|
|
|
|
m_mainPanelLayout->addWidget(m_pluginAreaWidget);
|
2019-12-23 13:48:11 +08:00
|
|
|
|
|
2020-10-28 11:30:50 +08:00
|
|
|
|
/* 桌面预览 */
|
2019-12-23 13:48:11 +08:00
|
|
|
|
m_mainPanelLayout->addWidget(m_desktopWidget);
|
|
|
|
|
|
2020-10-28 11:30:50 +08:00
|
|
|
|
m_mainPanelLayout->setSpacing(0);
|
|
|
|
|
m_mainPanelLayout->setContentsMargins(0, 0, 0, 0);
|
2020-12-08 13:45:51 +08:00
|
|
|
|
m_mainPanelLayout->setAlignment(m_fixedSpliter, Qt::AlignCenter);
|
|
|
|
|
m_mainPanelLayout->setAlignment(m_appSpliter, Qt::AlignCenter);
|
|
|
|
|
m_mainPanelLayout->setAlignment(m_traySpliter, Qt::AlignCenter);
|
2020-10-28 11:30:50 +08:00
|
|
|
|
|
2020-02-14 23:25:09 +08:00
|
|
|
|
connect(GSettingsByLaunch(), &QGSettings::changed, this, &MainPanelControl::onGSettingsChanged);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MainPanelControl::onGSettingsChanged(const QString &key)
|
|
|
|
|
{
|
|
|
|
|
if (key != "enable") {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QGSettings *setting = GSettingsByLaunch();
|
|
|
|
|
|
|
|
|
|
if (setting->keys().contains("enable")) {
|
|
|
|
|
const bool isEnable = GSettingsByLaunch()->keys().contains("enable") && GSettingsByLaunch()->get("enable").toBool();
|
2020-03-09 11:06:03 +08:00
|
|
|
|
if (isEnable && setting->get("enable").toBool()) {
|
2020-02-14 23:25:09 +08:00
|
|
|
|
m_fixedAreaWidget->setVisible(true);
|
|
|
|
|
m_fixedSpliter->setVisible(true);
|
|
|
|
|
m_isEnableLaunch = true;
|
|
|
|
|
} else {
|
|
|
|
|
m_fixedAreaWidget->setVisible(false);
|
|
|
|
|
m_fixedSpliter->setVisible(false);
|
|
|
|
|
m_isEnableLaunch = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-08-28 11:37:19 +08:00
|
|
|
|
}
|
2019-08-14 15:17:04 +08:00
|
|
|
|
|
2020-10-28 11:30:50 +08:00
|
|
|
|
void MainPanelControl::setDisplayMode(DisplayMode dislayMode)
|
2019-08-28 11:37:19 +08:00
|
|
|
|
{
|
2020-10-28 11:30:50 +08:00
|
|
|
|
if (dislayMode == m_dislayMode)
|
2019-08-30 11:41:52 +08:00
|
|
|
|
return;
|
2020-10-28 11:30:50 +08:00
|
|
|
|
m_dislayMode = dislayMode;
|
2019-09-09 15:56:29 +08:00
|
|
|
|
updateDisplayMode();
|
2019-08-14 15:17:04 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MainPanelControl::updateMainPanelLayout()
|
|
|
|
|
{
|
|
|
|
|
switch (m_position) {
|
2019-08-30 13:58:58 +08:00
|
|
|
|
case Position::Top:
|
|
|
|
|
case Position::Bottom:
|
2019-08-14 15:17:04 +08:00
|
|
|
|
m_fixedAreaWidget->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding);
|
|
|
|
|
m_appAreaWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
2020-08-25 19:49:13 +08:00
|
|
|
|
m_pluginAreaWidget->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
|
2019-08-14 15:17:04 +08:00
|
|
|
|
m_trayAreaWidget->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding);
|
|
|
|
|
m_mainPanelLayout->setDirection(QBoxLayout::LeftToRight);
|
|
|
|
|
m_fixedAreaLayout->setDirection(QBoxLayout::LeftToRight);
|
|
|
|
|
m_pluginLayout->setDirection(QBoxLayout::LeftToRight);
|
|
|
|
|
m_trayAreaLayout->setDirection(QBoxLayout::LeftToRight);
|
|
|
|
|
m_appAreaSonLayout->setDirection(QBoxLayout::LeftToRight);
|
2019-09-17 13:14:23 +08:00
|
|
|
|
m_trayAreaLayout->setContentsMargins(0, 10, 0, 10);
|
2020-03-12 12:34:09 +08:00
|
|
|
|
m_pluginLayout->setContentsMargins(10, 0, 10, 0);
|
2019-08-14 15:17:04 +08:00
|
|
|
|
break;
|
2019-08-30 13:58:58 +08:00
|
|
|
|
case Position::Right:
|
|
|
|
|
case Position::Left:
|
2019-08-14 15:17:04 +08:00
|
|
|
|
m_fixedAreaWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
|
|
|
|
|
m_appAreaWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
2020-08-25 19:49:13 +08:00
|
|
|
|
m_pluginAreaWidget->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
|
2019-08-14 15:17:04 +08:00
|
|
|
|
m_trayAreaWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
|
|
|
|
|
m_mainPanelLayout->setDirection(QBoxLayout::TopToBottom);
|
|
|
|
|
m_fixedAreaLayout->setDirection(QBoxLayout::TopToBottom);
|
|
|
|
|
m_pluginLayout->setDirection(QBoxLayout::TopToBottom);
|
|
|
|
|
m_trayAreaLayout->setDirection(QBoxLayout::TopToBottom);
|
|
|
|
|
m_appAreaSonLayout->setDirection(QBoxLayout::TopToBottom);
|
2019-09-17 13:14:23 +08:00
|
|
|
|
m_trayAreaLayout->setContentsMargins(10, 0, 10, 0);
|
2020-03-12 12:34:09 +08:00
|
|
|
|
m_pluginLayout->setContentsMargins(0, 10, 0, 10);
|
2019-08-14 15:17:04 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
2020-05-28 14:49:06 +08:00
|
|
|
|
|
|
|
|
|
resizeDesktopWidget();
|
|
|
|
|
resizeDockIcon();
|
2019-08-14 15:17:04 +08:00
|
|
|
|
}
|
|
|
|
|
|
2019-08-30 15:54:19 +08:00
|
|
|
|
void MainPanelControl::addFixedAreaItem(int index, QWidget *wdg)
|
2019-08-14 15:17:04 +08:00
|
|
|
|
{
|
2020-04-26 18:42:42 +08:00
|
|
|
|
if(m_position == Position::Top || m_position == Position::Bottom){
|
|
|
|
|
wdg->setMaximumSize(height(),height());
|
|
|
|
|
} else {
|
|
|
|
|
wdg->setMaximumSize(width(),width());
|
|
|
|
|
}
|
2019-09-02 09:13:02 +08:00
|
|
|
|
m_fixedAreaLayout->insertWidget(index, wdg);
|
2019-08-14 15:17:04 +08:00
|
|
|
|
}
|
|
|
|
|
|
2019-08-30 15:54:19 +08:00
|
|
|
|
void MainPanelControl::addAppAreaItem(int index, QWidget *wdg)
|
2019-08-14 15:17:04 +08:00
|
|
|
|
{
|
2020-04-26 18:42:42 +08:00
|
|
|
|
if(m_position == Position::Top || m_position == Position::Bottom){
|
|
|
|
|
wdg->setMaximumSize(height(),height());
|
|
|
|
|
} else {
|
|
|
|
|
wdg->setMaximumSize(width(),width());
|
|
|
|
|
}
|
2019-09-02 09:13:02 +08:00
|
|
|
|
m_appAreaSonLayout->insertWidget(index, wdg);
|
2019-08-14 15:17:04 +08:00
|
|
|
|
}
|
|
|
|
|
|
2019-08-30 15:54:19 +08:00
|
|
|
|
void MainPanelControl::addTrayAreaItem(int index, QWidget *wdg)
|
2019-08-14 15:17:04 +08:00
|
|
|
|
{
|
2019-10-31 15:38:56 +08:00
|
|
|
|
m_tray = static_cast<TrayPluginItem *>(wdg);
|
2019-09-02 09:13:02 +08:00
|
|
|
|
m_trayAreaLayout->insertWidget(index, wdg);
|
2019-08-14 15:17:04 +08:00
|
|
|
|
}
|
|
|
|
|
|
2019-08-30 15:54:19 +08:00
|
|
|
|
void MainPanelControl::addPluginAreaItem(int index, QWidget *wdg)
|
2019-08-14 15:17:04 +08:00
|
|
|
|
{
|
2020-09-10 15:51:33 +08:00
|
|
|
|
//因为日期时间插件和其他插件的大小有异,为了方便设置边距,在插件区域布局再添加一层布局设置边距
|
|
|
|
|
//因此在处理插件图标时,需要通过两层布局判断是否为需要的插件,例如拖动插件位置等判断
|
|
|
|
|
QBoxLayout * boxLayout = new QBoxLayout(QBoxLayout::LeftToRight);
|
|
|
|
|
boxLayout->addWidget(wdg, 0, Qt::AlignCenter);
|
|
|
|
|
m_pluginLayout->insertLayout(index, boxLayout, 0);
|
2019-08-14 15:17:04 +08:00
|
|
|
|
}
|
|
|
|
|
|
2019-08-17 18:24:24 +08:00
|
|
|
|
void MainPanelControl::removeFixedAreaItem(QWidget *wdg)
|
|
|
|
|
{
|
|
|
|
|
m_fixedAreaLayout->removeWidget(wdg);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MainPanelControl::removeAppAreaItem(QWidget *wdg)
|
|
|
|
|
{
|
|
|
|
|
m_appAreaSonLayout->removeWidget(wdg);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MainPanelControl::removeTrayAreaItem(QWidget *wdg)
|
|
|
|
|
{
|
|
|
|
|
m_trayAreaLayout->removeWidget(wdg);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MainPanelControl::removePluginAreaItem(QWidget *wdg)
|
|
|
|
|
{
|
2020-09-10 15:51:33 +08:00
|
|
|
|
//因为日期时间插件大小和其他插件有异,为了方便设置边距,各插件中增加一层布局
|
|
|
|
|
//因此remove插件图标时,需要从多的一层布局中取widget进行判断是否需要移除的插件
|
|
|
|
|
for (int i = 0; i < m_pluginLayout->count(); ++i) {
|
|
|
|
|
QLayoutItem *layoutItem = m_pluginLayout->itemAt(i);
|
|
|
|
|
QLayout *boxLayout = layoutItem->layout();
|
|
|
|
|
if (boxLayout && boxLayout->itemAt(0)->widget() == wdg) {
|
|
|
|
|
boxLayout->removeWidget(wdg);
|
|
|
|
|
m_pluginLayout->removeItem(layoutItem);
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-08-17 18:24:24 +08:00
|
|
|
|
}
|
|
|
|
|
|
2019-08-14 15:17:04 +08:00
|
|
|
|
void MainPanelControl::resizeEvent(QResizeEvent *event)
|
|
|
|
|
{
|
2020-05-28 14:49:06 +08:00
|
|
|
|
resizeDesktopWidget();
|
2019-10-28 14:42:56 +08:00
|
|
|
|
resizeDockIcon();
|
2019-09-04 10:31:37 +08:00
|
|
|
|
return QWidget::resizeEvent(event);
|
|
|
|
|
}
|
2019-09-02 09:13:02 +08:00
|
|
|
|
|
2019-09-04 10:31:37 +08:00
|
|
|
|
void MainPanelControl::updateAppAreaSonWidgetSize()
|
|
|
|
|
{
|
2019-08-30 13:58:58 +08:00
|
|
|
|
if ((m_position == Position::Top) || (m_position == Position::Bottom)) {
|
2019-09-02 09:13:02 +08:00
|
|
|
|
m_appAreaSonWidget->setMaximumHeight(this->height());
|
2019-09-04 10:31:37 +08:00
|
|
|
|
m_appAreaSonWidget->setMaximumWidth(m_appAreaWidget->width());
|
2019-08-14 15:17:04 +08:00
|
|
|
|
} else {
|
2019-09-02 09:13:02 +08:00
|
|
|
|
m_appAreaSonWidget->setMaximumWidth(this->width());
|
2019-09-04 10:31:37 +08:00
|
|
|
|
m_appAreaSonWidget->setMaximumHeight(m_appAreaWidget->height());
|
2019-08-14 15:17:04 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m_appAreaSonWidget->adjustSize();
|
2019-09-02 09:13:02 +08:00
|
|
|
|
|
2019-09-04 10:31:37 +08:00
|
|
|
|
moveAppSonWidget();
|
2019-08-14 15:17:04 +08:00
|
|
|
|
}
|
|
|
|
|
|
2019-09-03 10:22:27 +08:00
|
|
|
|
void MainPanelControl::setPositonValue(Dock::Position position)
|
2019-08-14 15:17:04 +08:00
|
|
|
|
{
|
2019-08-30 13:58:58 +08:00
|
|
|
|
if (m_position == position)
|
|
|
|
|
return;
|
2019-09-09 17:47:48 +08:00
|
|
|
|
|
2019-08-30 13:58:58 +08:00
|
|
|
|
m_position = position;
|
2020-09-01 20:59:03 +08:00
|
|
|
|
QTimer::singleShot(0, this, [=] {
|
|
|
|
|
updateMainPanelLayout();
|
|
|
|
|
});
|
2019-08-14 15:17:04 +08:00
|
|
|
|
}
|
2019-08-17 18:24:24 +08:00
|
|
|
|
|
2019-08-30 15:54:19 +08:00
|
|
|
|
void MainPanelControl::insertItem(int index, DockItem *item)
|
2019-08-17 18:24:24 +08:00
|
|
|
|
{
|
2019-08-21 12:52:53 +08:00
|
|
|
|
item->installEventFilter(this);
|
|
|
|
|
|
2019-08-17 18:24:24 +08:00
|
|
|
|
switch (item->itemType()) {
|
|
|
|
|
case DockItem::Launcher:
|
2019-12-04 09:27:11 +08:00
|
|
|
|
addFixedAreaItem(0, item);
|
|
|
|
|
break;
|
2019-09-04 13:22:43 +08:00
|
|
|
|
case DockItem::FixedPlugin:
|
2019-08-19 15:17:56 +08:00
|
|
|
|
addFixedAreaItem(index, item);
|
2019-08-17 18:24:24 +08:00
|
|
|
|
break;
|
|
|
|
|
case DockItem::App:
|
2019-08-29 20:21:36 +08:00
|
|
|
|
case DockItem::Placeholder:
|
2019-08-19 15:17:56 +08:00
|
|
|
|
addAppAreaItem(index, item);
|
2019-08-17 18:24:24 +08:00
|
|
|
|
break;
|
|
|
|
|
case DockItem::TrayPlugin:
|
2019-08-19 15:17:56 +08:00
|
|
|
|
addTrayAreaItem(index, item);
|
2019-08-17 18:24:24 +08:00
|
|
|
|
break;
|
|
|
|
|
case DockItem::Plugins:
|
2019-08-19 15:17:56 +08:00
|
|
|
|
addPluginAreaItem(index, item);
|
2019-08-17 18:24:24 +08:00
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
2020-09-28 13:19:09 +08:00
|
|
|
|
resizeDockIcon();
|
2019-08-17 18:24:24 +08:00
|
|
|
|
}
|
|
|
|
|
|
2019-08-19 15:17:56 +08:00
|
|
|
|
void MainPanelControl::removeItem(DockItem *item)
|
2019-08-17 18:24:24 +08:00
|
|
|
|
{
|
|
|
|
|
switch (item->itemType()) {
|
|
|
|
|
case DockItem::Launcher:
|
2019-09-04 13:22:43 +08:00
|
|
|
|
case DockItem::FixedPlugin:
|
2019-08-17 18:24:24 +08:00
|
|
|
|
removeFixedAreaItem(item);
|
|
|
|
|
break;
|
|
|
|
|
case DockItem::App:
|
2019-08-29 20:21:36 +08:00
|
|
|
|
case DockItem::Placeholder:
|
2019-08-17 18:24:24 +08:00
|
|
|
|
removeAppAreaItem(item);
|
|
|
|
|
break;
|
|
|
|
|
case DockItem::TrayPlugin:
|
|
|
|
|
removeTrayAreaItem(item);
|
|
|
|
|
break;
|
|
|
|
|
case DockItem::Plugins:
|
|
|
|
|
removePluginAreaItem(item);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
2020-09-28 13:19:09 +08:00
|
|
|
|
resizeDockIcon();
|
2019-08-17 18:24:24 +08:00
|
|
|
|
}
|
|
|
|
|
|
2019-08-29 20:21:36 +08:00
|
|
|
|
MainPanelDelegate *MainPanelControl::delegate() const
|
|
|
|
|
{
|
|
|
|
|
return m_delegate;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MainPanelControl::setDelegate(MainPanelDelegate *delegate)
|
|
|
|
|
{
|
|
|
|
|
m_delegate = delegate;
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-21 12:52:53 +08:00
|
|
|
|
void MainPanelControl::moveItem(DockItem *sourceItem, DockItem *targetItem)
|
2019-08-19 15:17:56 +08:00
|
|
|
|
{
|
2019-08-21 12:52:53 +08:00
|
|
|
|
// get target index
|
|
|
|
|
int idx = -1;
|
|
|
|
|
if (targetItem->itemType() == DockItem::App)
|
|
|
|
|
idx = m_appAreaSonLayout->indexOf(targetItem);
|
2020-09-10 15:51:33 +08:00
|
|
|
|
else if (targetItem->itemType() == DockItem::Plugins){
|
|
|
|
|
//因为日期时间插件大小和其他插件大小有异,为了设置边距,在各插件中增加了一层布局
|
|
|
|
|
//因此有拖动图标时,需要从多的一层布局中判断是否相同插件而获取插件位置顺序
|
|
|
|
|
for (int i = 0; i < m_pluginLayout->count(); ++i) {
|
|
|
|
|
QLayout *layout = m_pluginLayout->itemAt(i)->layout();
|
|
|
|
|
if (layout && layout->itemAt(0)->widget() == targetItem) {
|
|
|
|
|
idx = i;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else if (targetItem->itemType() == DockItem::FixedPlugin)
|
2019-09-04 13:22:43 +08:00
|
|
|
|
idx = m_fixedAreaLayout->indexOf(targetItem);
|
2019-08-21 12:52:53 +08:00
|
|
|
|
else
|
|
|
|
|
return;
|
|
|
|
|
|
2019-08-19 15:17:56 +08:00
|
|
|
|
// remove old item
|
2019-08-21 12:52:53 +08:00
|
|
|
|
removeItem(sourceItem);
|
|
|
|
|
|
2019-08-19 15:17:56 +08:00
|
|
|
|
// insert new position
|
2019-08-21 12:52:53 +08:00
|
|
|
|
insertItem(idx, sourceItem);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MainPanelControl::dragEnterEvent(QDragEnterEvent *e)
|
|
|
|
|
{
|
2020-09-10 19:52:35 +08:00
|
|
|
|
//拖拽图标到任务栏时,如果拖拽到垃圾箱插件图标widget上,则默认不允许拖拽,其他位置默认为允许拖拽
|
|
|
|
|
QWidget *widget = QApplication::widgetAt(QCursor::pos());
|
|
|
|
|
//"trash-centralwidget"名称是在PluginsItem类中m_centralWidget->setObjectName(pluginInter->pluginName() + "-centralwidget");
|
|
|
|
|
if (widget && widget->objectName() == "trash-centralwidget") {
|
|
|
|
|
return;
|
2020-03-09 11:06:03 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-09-10 19:52:35 +08:00
|
|
|
|
e->accept();
|
2019-08-21 12:52:53 +08:00
|
|
|
|
}
|
|
|
|
|
|
2019-08-29 20:21:36 +08:00
|
|
|
|
void MainPanelControl::dragLeaveEvent(QDragLeaveEvent *e)
|
|
|
|
|
{
|
2019-09-03 10:22:27 +08:00
|
|
|
|
Q_UNUSED(e);
|
2019-08-29 20:21:36 +08:00
|
|
|
|
if (m_placeholderItem) {
|
|
|
|
|
const QRect r(static_cast<QWidget *>(parent())->pos(), size());
|
|
|
|
|
const QPoint p(QCursor::pos());
|
|
|
|
|
|
|
|
|
|
// remove margins to fix a touch screen bug:
|
|
|
|
|
// the mouse point position will stay on this rect's margins after
|
|
|
|
|
// drag move to the edge of screen
|
|
|
|
|
if (r.marginsRemoved(QMargins(1, 10, 1, 1)).contains(p))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
removeAppAreaItem(m_placeholderItem);
|
|
|
|
|
m_placeholderItem->deleteLater();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MainPanelControl::dropEvent(QDropEvent *e)
|
2019-08-21 12:52:53 +08:00
|
|
|
|
{
|
2019-08-29 20:21:36 +08:00
|
|
|
|
if (m_placeholderItem) {
|
|
|
|
|
|
|
|
|
|
emit itemAdded(e->mimeData()->data(m_draggingMimeKey), m_appAreaSonLayout->indexOf(m_placeholderItem));
|
|
|
|
|
|
|
|
|
|
removeAppAreaItem(m_placeholderItem);
|
|
|
|
|
m_placeholderItem->deleteLater();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MainPanelControl::handleDragMove(QDragMoveEvent *e, bool isFilter)
|
|
|
|
|
{
|
|
|
|
|
if (!e->source()) {
|
|
|
|
|
// 应用程序拖到dock上
|
|
|
|
|
e->accept();
|
|
|
|
|
|
|
|
|
|
DockItem *insertPositionItem = dropTargetItem(nullptr, e->pos());
|
|
|
|
|
|
|
|
|
|
if (m_placeholderItem.isNull()) {
|
|
|
|
|
|
|
|
|
|
m_placeholderItem = new PlaceholderItem;
|
|
|
|
|
|
2019-09-03 10:22:27 +08:00
|
|
|
|
if (m_position == Dock::Top || m_position == Dock::Bottom) {
|
2019-08-29 20:21:36 +08:00
|
|
|
|
if (m_appAreaSonWidget->mapFromParent(e->pos()).x() > m_appAreaSonWidget->rect().right()) {
|
|
|
|
|
// 插入到最右侧
|
|
|
|
|
insertPositionItem = nullptr;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
if (m_appAreaSonWidget->mapFromParent(e->pos()).y() > m_appAreaSonWidget->rect().bottom()) {
|
|
|
|
|
// 插入到最下测
|
|
|
|
|
insertPositionItem = nullptr;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
insertItem(m_appAreaSonLayout->indexOf(insertPositionItem), m_placeholderItem);
|
|
|
|
|
|
|
|
|
|
} else if (insertPositionItem && m_placeholderItem != insertPositionItem) {
|
|
|
|
|
moveItem(m_placeholderItem, insertPositionItem);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-21 12:52:53 +08:00
|
|
|
|
DockItem *sourceItem = qobject_cast<DockItem *>(e->source());
|
2019-08-29 20:21:36 +08:00
|
|
|
|
|
2019-08-21 12:52:53 +08:00
|
|
|
|
if (!sourceItem) {
|
|
|
|
|
e->ignore();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-29 20:21:36 +08:00
|
|
|
|
DockItem *targetItem = nullptr;
|
|
|
|
|
|
|
|
|
|
if (isFilter) {
|
|
|
|
|
// appItem调整顺序或者移除驻留
|
|
|
|
|
targetItem = dropTargetItem(sourceItem, mapFromGlobal(m_appDragWidget->mapToGlobal(e->pos())));
|
|
|
|
|
|
|
|
|
|
if (targetItem) {
|
|
|
|
|
m_appDragWidget->setOriginPos((m_appAreaSonWidget->mapToGlobal(targetItem->pos())));
|
|
|
|
|
} else {
|
|
|
|
|
targetItem = sourceItem;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
// other dockItem调整顺序
|
|
|
|
|
targetItem = dropTargetItem(sourceItem, e->pos());
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-21 12:52:53 +08:00
|
|
|
|
if (!targetItem) {
|
|
|
|
|
e->ignore();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
e->accept();
|
|
|
|
|
|
|
|
|
|
if (targetItem == sourceItem)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
moveItem(sourceItem, targetItem);
|
|
|
|
|
emit itemMoved(sourceItem, targetItem);
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-29 20:21:36 +08:00
|
|
|
|
void MainPanelControl::dragMoveEvent(QDragMoveEvent *e)
|
|
|
|
|
{
|
2020-01-14 10:57:50 +08:00
|
|
|
|
DockItem *sourceItem = qobject_cast<DockItem *>(e->source());
|
|
|
|
|
if (sourceItem) {
|
|
|
|
|
handleDragMove(e, false);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 拖app到dock上
|
|
|
|
|
const char *RequestDockKey = "RequestDock";
|
|
|
|
|
const char *RequestDockKeyFallback = "text/plain";
|
|
|
|
|
const char *DesktopMimeType = "application/x-desktop";
|
2020-03-09 11:06:03 +08:00
|
|
|
|
auto DragmineData = e->mimeData();
|
2020-01-14 10:57:50 +08:00
|
|
|
|
|
|
|
|
|
m_draggingMimeKey = DragmineData->formats().contains(RequestDockKey) ? RequestDockKey : RequestDockKeyFallback;
|
|
|
|
|
|
|
|
|
|
// dragging item is NOT a desktop file
|
|
|
|
|
if (QMimeDatabase().mimeTypeForFile(DragmineData->data(m_draggingMimeKey)).name() != DesktopMimeType) {
|
|
|
|
|
m_draggingMimeKey.clear();
|
|
|
|
|
e->setAccepted(false);
|
|
|
|
|
qDebug() << "dragging item is NOT a desktop file";
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//如果当前从桌面拖拽的的app是trash,则不能放入app任务栏中
|
|
|
|
|
QString str = "file://";
|
|
|
|
|
//启动器
|
|
|
|
|
QString str_t = "";
|
|
|
|
|
|
|
|
|
|
str.append(QStandardPaths::locate(QStandardPaths::DesktopLocation, "dde-trash.desktop"));
|
|
|
|
|
str_t.append(QStandardPaths::locate(QStandardPaths::ApplicationsLocation, "dde-trash.desktop"));
|
|
|
|
|
|
|
|
|
|
if ((str == DragmineData->data(m_draggingMimeKey)) || (str_t == DragmineData->data(m_draggingMimeKey))) {
|
|
|
|
|
e->setAccepted(false);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (m_delegate && m_delegate->appIsOnDock(DragmineData->data(m_draggingMimeKey))) {
|
|
|
|
|
e->setAccepted(false);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-29 20:21:36 +08:00
|
|
|
|
handleDragMove(e, false);
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-21 12:52:53 +08:00
|
|
|
|
bool MainPanelControl::eventFilter(QObject *watched, QEvent *event)
|
|
|
|
|
{
|
2019-09-09 09:58:31 +08:00
|
|
|
|
if (watched == m_appAreaSonWidget) {
|
2020-09-17 11:28:47 +08:00
|
|
|
|
switch (event->type()) {
|
|
|
|
|
case QEvent::LayoutRequest:
|
2019-09-09 09:58:31 +08:00
|
|
|
|
m_appAreaSonWidget->adjustSize();
|
2019-10-28 14:42:56 +08:00
|
|
|
|
resizeDockIcon();
|
2020-09-17 11:28:47 +08:00
|
|
|
|
break;
|
2020-09-23 16:52:42 +08:00
|
|
|
|
case QEvent::Resize:
|
2020-09-17 11:28:47 +08:00
|
|
|
|
resizeDockIcon();
|
|
|
|
|
break;
|
|
|
|
|
default:
|
2019-09-09 14:14:25 +08:00
|
|
|
|
moveAppSonWidget();
|
2020-09-17 11:28:47 +08:00
|
|
|
|
break;
|
2019-09-09 14:14:25 +08:00
|
|
|
|
}
|
2019-09-09 09:58:31 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-01-14 10:57:50 +08:00
|
|
|
|
if (watched == m_desktopWidget) {
|
|
|
|
|
if (event->type() == QEvent::Enter) {
|
2020-07-28 14:42:16 +08:00
|
|
|
|
if (checkNeedShowDesktop()) {
|
|
|
|
|
m_needRecoveryWin = true;
|
|
|
|
|
QProcess::startDetached("/usr/lib/deepin-daemon/desktop-toggle");
|
|
|
|
|
}
|
2019-12-23 13:48:11 +08:00
|
|
|
|
m_isHover = true;
|
|
|
|
|
update();
|
2020-01-14 10:57:50 +08:00
|
|
|
|
} else if (event->type() == QEvent::Leave) {
|
2020-07-28 14:42:16 +08:00
|
|
|
|
// 鼠标移入时隐藏了窗口,移出时恢复
|
|
|
|
|
if (m_needRecoveryWin) {
|
|
|
|
|
QProcess::startDetached("/usr/lib/deepin-daemon/desktop-toggle");
|
|
|
|
|
}
|
2019-12-23 13:48:11 +08:00
|
|
|
|
m_isHover = false;
|
|
|
|
|
update();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-04 10:31:37 +08:00
|
|
|
|
if (watched == m_appAreaWidget) {
|
|
|
|
|
if (event->type() == QEvent::Resize)
|
|
|
|
|
updateAppAreaSonWidgetSize();
|
|
|
|
|
|
|
|
|
|
if (event->type() == QEvent::Move)
|
|
|
|
|
moveAppSonWidget();
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-29 20:21:36 +08:00
|
|
|
|
if (m_appDragWidget && watched == static_cast<QGraphicsView *>(m_appDragWidget)->viewport()) {
|
|
|
|
|
QDropEvent *e = static_cast<QDropEvent *>(event);
|
|
|
|
|
bool isContains = rect().contains(mapFromGlobal(m_appDragWidget->mapToGlobal(e->pos())));
|
|
|
|
|
if (isContains) {
|
|
|
|
|
if (event->type() == QEvent::DragMove) {
|
|
|
|
|
handleDragMove(static_cast<QDragMoveEvent *>(event), true);
|
|
|
|
|
} else if (event->type() == QEvent::Drop) {
|
|
|
|
|
m_appDragWidget->hide();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-09-04 10:31:37 +08:00
|
|
|
|
|
2019-08-29 20:21:36 +08:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-21 12:52:53 +08:00
|
|
|
|
if (event->type() != QEvent::MouseMove)
|
|
|
|
|
return false;
|
|
|
|
|
|
2020-07-27 14:32:49 +08:00
|
|
|
|
QMouseEvent *mouseEvent = dynamic_cast<QMouseEvent *>(event);
|
2019-08-21 12:52:53 +08:00
|
|
|
|
if (!mouseEvent || mouseEvent->buttons() != Qt::LeftButton)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
DockItem *item = qobject_cast<DockItem *>(watched);
|
|
|
|
|
if (!item)
|
|
|
|
|
return false;
|
|
|
|
|
|
2019-09-04 13:22:43 +08:00
|
|
|
|
if (item->itemType() != DockItem::App && item->itemType() != DockItem::Plugins && item->itemType() != DockItem::FixedPlugin)
|
2019-08-21 12:52:53 +08:00
|
|
|
|
return false;
|
|
|
|
|
|
2019-09-24 19:17:51 +08:00
|
|
|
|
const QPoint pos = mouseEvent->globalPos();
|
|
|
|
|
const QPoint distance = pos - m_mousePressPos;
|
|
|
|
|
if (distance.manhattanLength() < QApplication::startDragDistance())
|
|
|
|
|
return false;
|
|
|
|
|
|
2020-07-27 14:32:49 +08:00
|
|
|
|
// source为MouseEventSynthesizedByQt时,事件由触屏事件转换而来,触屏没有收到后端的延迟触屏信号时不进行拖动
|
2020-08-18 10:41:14 +08:00
|
|
|
|
if (mouseEvent->source() == Qt::MouseEventSynthesizedByQt && !TouchSignalManager::instance()->isDragIconPress()) {
|
2020-07-27 14:32:49 +08:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-21 12:52:53 +08:00
|
|
|
|
startDrag(item);
|
|
|
|
|
|
2019-09-04 10:31:37 +08:00
|
|
|
|
return QWidget::eventFilter(watched, event);
|
2019-08-19 15:17:56 +08:00
|
|
|
|
}
|
|
|
|
|
|
2019-09-24 19:17:51 +08:00
|
|
|
|
void MainPanelControl::mousePressEvent(QMouseEvent *e)
|
|
|
|
|
{
|
2019-12-23 13:48:11 +08:00
|
|
|
|
if (e->button() == Qt::LeftButton) {
|
2019-09-24 19:17:51 +08:00
|
|
|
|
m_mousePressPos = e->globalPos();
|
|
|
|
|
|
2020-01-14 10:57:50 +08:00
|
|
|
|
QRect rect(m_desktopWidget->pos(), m_desktopWidget->size());
|
2020-07-28 14:42:16 +08:00
|
|
|
|
if (rect.contains(e->pos())) {
|
2020-08-02 15:38:18 +08:00
|
|
|
|
if (m_needRecoveryWin) {
|
|
|
|
|
// 手动点击 显示桌面窗口 后,鼠标移出时不再调用显/隐窗口进程,以手动点击设置为准
|
|
|
|
|
m_needRecoveryWin = false;
|
|
|
|
|
} else {
|
|
|
|
|
// 需求调整,鼠标移入,预览桌面时再点击显示桌面保持显示桌面状态,再点击才切换桌面显、隐状态
|
|
|
|
|
QProcess::startDetached("/usr/lib/deepin-daemon/desktop-toggle");
|
|
|
|
|
}
|
2020-07-28 14:42:16 +08:00
|
|
|
|
}
|
2019-12-23 13:48:11 +08:00
|
|
|
|
}
|
|
|
|
|
|
2019-09-24 19:17:51 +08:00
|
|
|
|
QWidget::mousePressEvent(e);
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-21 12:52:53 +08:00
|
|
|
|
void MainPanelControl::startDrag(DockItem *item)
|
|
|
|
|
{
|
|
|
|
|
const QPixmap pixmap = item->grab();
|
|
|
|
|
|
|
|
|
|
item->setDraging(true);
|
|
|
|
|
item->update();
|
|
|
|
|
|
2019-08-29 20:21:36 +08:00
|
|
|
|
QDrag *drag = nullptr;
|
|
|
|
|
if (item->itemType() == DockItem::App) {
|
|
|
|
|
AppDrag *appDrag = new AppDrag(item);
|
2019-09-24 10:47:43 +08:00
|
|
|
|
|
2019-08-29 20:21:36 +08:00
|
|
|
|
m_appDragWidget = appDrag->appDragWidget();
|
|
|
|
|
|
|
|
|
|
connect(m_appDragWidget, &AppDragWidget::destroyed, this, [ = ] {
|
|
|
|
|
m_appDragWidget = nullptr;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
appDrag->appDragWidget()->setOriginPos((m_appAreaSonWidget->mapToGlobal(item->pos())));
|
2019-09-03 10:22:27 +08:00
|
|
|
|
appDrag->appDragWidget()->setDockInfo(m_position, QRect(mapToGlobal(pos()), size()));
|
2020-08-18 16:41:25 +08:00
|
|
|
|
const QPixmap &dragPix = qobject_cast<AppItem *>(item)->appIcon();
|
2019-09-24 10:47:43 +08:00
|
|
|
|
|
2020-08-18 16:41:25 +08:00
|
|
|
|
appDrag->setPixmap(dragPix);
|
|
|
|
|
m_appDragWidget->show();
|
2019-09-24 10:47:43 +08:00
|
|
|
|
|
2020-08-18 16:41:25 +08:00
|
|
|
|
if (DWindowManagerHelper::instance()->hasComposite()) {
|
2019-09-24 10:47:43 +08:00
|
|
|
|
static_cast<QGraphicsView *>(m_appDragWidget)->viewport()->installEventFilter(this);
|
|
|
|
|
} else {
|
|
|
|
|
appDrag->QDrag::setPixmap(dragPix);
|
2020-08-18 16:41:25 +08:00
|
|
|
|
}
|
2019-08-29 20:21:36 +08:00
|
|
|
|
|
|
|
|
|
drag = appDrag;
|
2020-08-28 18:47:34 +08:00
|
|
|
|
drag->setHotSpot(dragPix.rect().center() / dragPix.devicePixelRatioF());
|
2019-08-29 20:21:36 +08:00
|
|
|
|
} else {
|
|
|
|
|
drag = new QDrag(item);
|
|
|
|
|
drag->setPixmap(pixmap);
|
2020-08-28 18:47:34 +08:00
|
|
|
|
drag->setHotSpot(pixmap.rect().center() / pixmap.devicePixelRatioF());
|
2019-08-29 20:21:36 +08:00
|
|
|
|
}
|
2019-08-21 12:52:53 +08:00
|
|
|
|
drag->setMimeData(new QMimeData);
|
|
|
|
|
drag->exec(Qt::MoveAction);
|
|
|
|
|
|
2019-09-24 10:47:43 +08:00
|
|
|
|
// app关闭特效情况下移除
|
|
|
|
|
if (item->itemType() == DockItem::App && !DWindowManagerHelper::instance()->hasComposite()) {
|
|
|
|
|
if (m_appDragWidget->isRemoveAble())
|
|
|
|
|
qobject_cast<AppItem *>(item)->undock();
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-29 20:21:36 +08:00
|
|
|
|
m_appDragWidget = nullptr;
|
2019-08-21 12:52:53 +08:00
|
|
|
|
item->setDraging(false);
|
|
|
|
|
item->update();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DockItem *MainPanelControl::dropTargetItem(DockItem *sourceItem, QPoint point)
|
|
|
|
|
{
|
2019-08-29 20:21:36 +08:00
|
|
|
|
QWidget *parentWidget = m_appAreaSonWidget;
|
2019-08-21 12:52:53 +08:00
|
|
|
|
|
2019-08-29 20:21:36 +08:00
|
|
|
|
if (sourceItem) {
|
|
|
|
|
switch (sourceItem->itemType()) {
|
|
|
|
|
case DockItem::App:
|
|
|
|
|
parentWidget = m_appAreaSonWidget;
|
|
|
|
|
break;
|
|
|
|
|
case DockItem::Plugins:
|
|
|
|
|
parentWidget = m_pluginAreaWidget;
|
|
|
|
|
break;
|
2019-09-04 13:22:43 +08:00
|
|
|
|
case DockItem::FixedPlugin:
|
|
|
|
|
parentWidget = m_fixedAreaWidget;
|
|
|
|
|
break;
|
2019-08-29 20:21:36 +08:00
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
2019-08-21 12:52:53 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!parentWidget)
|
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
|
|
point = parentWidget->mapFromParent(point);
|
|
|
|
|
QLayout *parentLayout = parentWidget->layout();
|
|
|
|
|
|
|
|
|
|
DockItem *targetItem = nullptr;
|
|
|
|
|
|
|
|
|
|
for (int i = 0 ; i < parentLayout->count(); ++i) {
|
|
|
|
|
QLayoutItem *layoutItem = parentLayout->itemAt(i);
|
|
|
|
|
|
2020-09-10 15:51:33 +08:00
|
|
|
|
DockItem *dockItem = nullptr;
|
|
|
|
|
if (parentWidget == m_pluginAreaWidget) {
|
|
|
|
|
QLayout *layout = layoutItem->layout();
|
|
|
|
|
if (layout) {
|
|
|
|
|
dockItem = qobject_cast<DockItem *>(layout->itemAt(0)->widget());
|
2019-12-04 11:05:31 +08:00
|
|
|
|
}
|
2020-09-10 15:51:33 +08:00
|
|
|
|
} else{
|
|
|
|
|
dockItem = qobject_cast<DockItem *>(layoutItem->widget());
|
2019-12-04 09:27:11 +08:00
|
|
|
|
}
|
2020-09-10 15:51:33 +08:00
|
|
|
|
|
|
|
|
|
if (!dockItem)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
QRect rect(dockItem->pos(), dockItem->size());
|
2019-08-21 12:52:53 +08:00
|
|
|
|
if (rect.contains(point)) {
|
|
|
|
|
targetItem = dockItem;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-29 20:21:36 +08:00
|
|
|
|
if (!targetItem && parentWidget == m_appAreaSonWidget) {
|
|
|
|
|
// appitem调整顺序是,判断是否拖放在两边空白区域
|
|
|
|
|
|
|
|
|
|
if (!m_appAreaSonLayout->count())
|
|
|
|
|
return targetItem;
|
|
|
|
|
|
|
|
|
|
DockItem *first = qobject_cast<DockItem *>(m_appAreaSonLayout->itemAt(0)->widget());
|
|
|
|
|
DockItem *last = qobject_cast<DockItem *>(m_appAreaSonLayout->itemAt(m_appAreaSonLayout->count() - 1)->widget());
|
|
|
|
|
|
2019-09-03 10:22:27 +08:00
|
|
|
|
if (m_position == Dock::Top || m_position == Dock::Bottom) {
|
2019-08-29 20:21:36 +08:00
|
|
|
|
|
|
|
|
|
if (point.x() < 0) {
|
|
|
|
|
targetItem = first;
|
|
|
|
|
} else {
|
|
|
|
|
targetItem = last;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
|
|
if (point.y() < 0) {
|
|
|
|
|
targetItem = first;
|
|
|
|
|
} else {
|
|
|
|
|
targetItem = last;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-09-04 10:31:37 +08:00
|
|
|
|
|
2019-08-21 12:52:53 +08:00
|
|
|
|
return targetItem;
|
|
|
|
|
}
|
2019-08-30 11:41:52 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void MainPanelControl::updateDisplayMode()
|
2019-09-04 10:31:37 +08:00
|
|
|
|
{
|
|
|
|
|
moveAppSonWidget();
|
2020-08-06 21:42:27 +08:00
|
|
|
|
resizeDesktopWidget();
|
2019-09-04 10:31:37 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MainPanelControl::moveAppSonWidget()
|
2019-08-30 11:41:52 +08:00
|
|
|
|
{
|
2019-09-02 09:13:02 +08:00
|
|
|
|
QRect rect(QPoint(0, 0), m_appAreaSonWidget->size());
|
|
|
|
|
if (DisplayMode::Efficient == m_dislayMode) {
|
|
|
|
|
switch (m_position) {
|
|
|
|
|
case Top:
|
|
|
|
|
case Bottom :
|
2019-09-04 10:31:37 +08:00
|
|
|
|
rect.moveTo(m_appAreaWidget->pos());
|
2019-09-02 09:13:02 +08:00
|
|
|
|
break;
|
|
|
|
|
case Right:
|
|
|
|
|
case Left:
|
2019-09-04 10:31:37 +08:00
|
|
|
|
rect.moveTo(m_appAreaWidget->pos());
|
2019-09-02 09:13:02 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
2019-08-30 11:41:52 +08:00
|
|
|
|
} else {
|
2019-09-02 09:13:02 +08:00
|
|
|
|
switch (m_position) {
|
|
|
|
|
case Top:
|
|
|
|
|
case Bottom :
|
|
|
|
|
rect.moveCenter(this->rect().center());
|
2019-09-04 10:31:37 +08:00
|
|
|
|
if (rect.right() > m_appAreaWidget->geometry().right()) {
|
|
|
|
|
rect.moveRight(m_appAreaWidget->geometry().right());
|
2019-09-02 09:13:02 +08:00
|
|
|
|
}
|
2020-08-25 18:56:55 +08:00
|
|
|
|
if (rect.left() < m_appAreaWidget->geometry().left()) {
|
|
|
|
|
rect.moveLeft(m_appAreaWidget->geometry().left());
|
|
|
|
|
}
|
2019-09-02 09:13:02 +08:00
|
|
|
|
break;
|
|
|
|
|
case Right:
|
|
|
|
|
case Left:
|
|
|
|
|
rect.moveCenter(this->rect().center());
|
2019-09-04 10:31:37 +08:00
|
|
|
|
if (rect.bottom() > m_appAreaWidget->geometry().bottom()) {
|
|
|
|
|
rect.moveBottom(m_appAreaWidget->geometry().bottom());
|
2019-09-02 09:13:02 +08:00
|
|
|
|
}
|
2020-08-25 18:56:55 +08:00
|
|
|
|
if (rect.top() < m_appAreaWidget->geometry().top()) {
|
|
|
|
|
rect.moveTop(m_appAreaWidget->geometry().top());
|
|
|
|
|
}
|
2019-09-02 09:13:02 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
2019-08-30 11:41:52 +08:00
|
|
|
|
}
|
2019-09-02 09:13:02 +08:00
|
|
|
|
|
|
|
|
|
m_appAreaSonWidget->move(rect.x(), rect.y());
|
2019-08-30 11:41:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
2019-09-06 14:44:07 +08:00
|
|
|
|
void MainPanelControl::itemUpdated(DockItem *item)
|
|
|
|
|
{
|
|
|
|
|
item->parentWidget()->adjustSize();
|
2020-01-11 11:56:55 +08:00
|
|
|
|
resizeDockIcon();
|
2019-09-06 14:44:07 +08:00
|
|
|
|
}
|
2019-09-17 13:14:23 +08:00
|
|
|
|
|
2020-03-09 11:06:03 +08:00
|
|
|
|
void MainPanelControl::showEvent(QShowEvent *event)
|
|
|
|
|
{
|
|
|
|
|
QTimer::singleShot(0, this, [ = ] {
|
2020-02-14 23:25:09 +08:00
|
|
|
|
onGSettingsChanged("enable");
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return QWidget::showEvent(event);
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-17 13:14:23 +08:00
|
|
|
|
void MainPanelControl::paintEvent(QPaintEvent *event)
|
|
|
|
|
{
|
2020-08-03 15:01:59 +08:00
|
|
|
|
Q_UNUSED(event);
|
|
|
|
|
|
2019-09-17 13:14:23 +08:00
|
|
|
|
QPainter painter(this);
|
|
|
|
|
QColor color;
|
|
|
|
|
if (DGuiApplicationHelper::instance()->themeType() == DGuiApplicationHelper::LightType) {
|
|
|
|
|
color = Qt::black;
|
|
|
|
|
painter.setOpacity(0.5);
|
|
|
|
|
} else {
|
|
|
|
|
color = Qt::white;
|
|
|
|
|
painter.setOpacity(0.1);
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-09 11:06:03 +08:00
|
|
|
|
if (m_isEnableLaunch)
|
2020-02-14 23:25:09 +08:00
|
|
|
|
painter.fillRect(m_fixedSpliter->geometry(), color);
|
2019-09-17 13:14:23 +08:00
|
|
|
|
painter.fillRect(m_appSpliter->geometry(), color);
|
|
|
|
|
painter.fillRect(m_traySpliter->geometry(), color);
|
2019-12-23 13:48:11 +08:00
|
|
|
|
|
|
|
|
|
//描绘桌面区域的颜色
|
|
|
|
|
painter.setOpacity(1);
|
|
|
|
|
QPen pen;
|
|
|
|
|
QColor penColor(0, 0, 0, 25);
|
|
|
|
|
pen.setWidth(2);
|
|
|
|
|
pen.setColor(penColor);
|
|
|
|
|
painter.setPen(pen);
|
|
|
|
|
painter.drawRect(m_desktopWidget->geometry());
|
2020-01-14 10:57:50 +08:00
|
|
|
|
if (m_isHover) {
|
2019-12-23 13:48:11 +08:00
|
|
|
|
painter.fillRect(m_desktopWidget->geometry(), QColor(255, 255, 255, 51));
|
|
|
|
|
return;
|
|
|
|
|
}
|
2020-01-14 10:57:50 +08:00
|
|
|
|
painter.fillRect(m_desktopWidget->geometry(), QColor(255, 255, 255, 25));
|
2019-09-17 13:14:23 +08:00
|
|
|
|
}
|
2019-10-28 14:42:56 +08:00
|
|
|
|
|
|
|
|
|
void MainPanelControl::resizeDockIcon()
|
|
|
|
|
{
|
2019-11-04 17:22:34 +08:00
|
|
|
|
// 插件有点特殊,因为会引入第三方的插件,并不会受dock的缩放影响,我们只能限制我们自己的插件,否则会导致显示错误。
|
|
|
|
|
// 以下是受控制的插件
|
2019-10-31 15:38:56 +08:00
|
|
|
|
PluginsItem *trashPlugin = nullptr;
|
2020-01-09 15:47:09 +08:00
|
|
|
|
PluginsItem *shutdownPlugin = nullptr;
|
|
|
|
|
PluginsItem *keyboardPlugin = nullptr;
|
2020-05-28 16:01:38 +08:00
|
|
|
|
PluginsItem *notificationPlugin = nullptr;
|
2020-09-10 15:51:33 +08:00
|
|
|
|
|
|
|
|
|
//因为日期时间大小和其他插件大小有异,为了设置边距,在各插件中增加了一层布局
|
|
|
|
|
//因此需要通过多一层布局来获取各插件
|
2019-10-28 14:42:56 +08:00
|
|
|
|
for (int i = 0; i < m_pluginLayout->count(); ++ i) {
|
2020-09-10 15:51:33 +08:00
|
|
|
|
QLayout *layout = m_pluginLayout->itemAt(i)->layout();
|
|
|
|
|
if (layout) {
|
|
|
|
|
PluginsItem *w = static_cast<PluginsItem *>(m_pluginLayout->itemAt(i)->widget());
|
|
|
|
|
if (w) {
|
|
|
|
|
if (w->pluginName() == "trash") {
|
|
|
|
|
trashPlugin = w;
|
|
|
|
|
} else if (w->pluginName() == "shutdown") {
|
|
|
|
|
shutdownPlugin = w;
|
|
|
|
|
} else if (w->pluginName() == "onboard") {
|
|
|
|
|
keyboardPlugin = w;
|
|
|
|
|
} else if (w->pluginName() == "notifications") {
|
|
|
|
|
notificationPlugin = w;
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-10-28 14:42:56 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-31 15:38:56 +08:00
|
|
|
|
// 总宽度
|
|
|
|
|
int totalLength = ((m_position == Position::Top) || (m_position == Position::Bottom)) ? width() : height();
|
|
|
|
|
// 减去托盘间隔区域
|
2020-09-10 15:51:33 +08:00
|
|
|
|
if (m_tray) {
|
|
|
|
|
totalLength -= (m_tray->trayVisableItemCount() + 1) * 10;
|
|
|
|
|
}
|
2019-10-31 15:38:56 +08:00
|
|
|
|
// 减去3个分割线的宽度
|
|
|
|
|
totalLength -= 3 * SPLITER_SIZE;
|
|
|
|
|
|
2020-08-03 15:01:59 +08:00
|
|
|
|
// 减去所有插件宽度,加上参与计算的4个插件宽度
|
2019-11-04 17:22:34 +08:00
|
|
|
|
if ((m_position == Position::Top) || (m_position == Position::Bottom)) {
|
|
|
|
|
totalLength -= m_pluginAreaWidget->width();
|
|
|
|
|
if (trashPlugin) totalLength += trashPlugin->width();
|
2020-01-09 15:47:09 +08:00
|
|
|
|
if (shutdownPlugin) totalLength += shutdownPlugin->width();
|
|
|
|
|
if (keyboardPlugin) totalLength += keyboardPlugin->width();
|
2020-06-15 11:38:46 +08:00
|
|
|
|
if (notificationPlugin) totalLength += notificationPlugin->width();
|
2019-12-23 13:48:11 +08:00
|
|
|
|
totalLength -= m_desktopWidget->width();
|
2019-11-04 17:22:34 +08:00
|
|
|
|
} else {
|
|
|
|
|
totalLength -= m_pluginAreaWidget->height();
|
|
|
|
|
if (trashPlugin) totalLength += trashPlugin->height();
|
2020-01-09 15:47:09 +08:00
|
|
|
|
if (shutdownPlugin) totalLength += shutdownPlugin->height();
|
|
|
|
|
if (keyboardPlugin) totalLength += keyboardPlugin->height();
|
2020-06-15 11:38:46 +08:00
|
|
|
|
if (notificationPlugin) totalLength += notificationPlugin->height();
|
2019-12-23 13:48:11 +08:00
|
|
|
|
totalLength -= m_desktopWidget->height();
|
2019-11-04 17:22:34 +08:00
|
|
|
|
}
|
2019-10-31 15:38:56 +08:00
|
|
|
|
|
|
|
|
|
if (totalLength < 0)
|
|
|
|
|
return;
|
|
|
|
|
|
2019-11-04 17:22:34 +08:00
|
|
|
|
// 参与计算的插件的个数(包含托盘和插件,垃圾桶,关机,屏幕键盘)
|
2020-09-10 15:51:33 +08:00
|
|
|
|
int pluginCount = 0;
|
|
|
|
|
if (m_tray) {
|
|
|
|
|
pluginCount = m_tray->trayVisableItemCount() + (trashPlugin ? 1 : 0) + (shutdownPlugin ? 1 : 0) + (keyboardPlugin ? 1 : 0) + (notificationPlugin ? 1 : 0);
|
|
|
|
|
} else {
|
|
|
|
|
pluginCount = (trashPlugin ? 1 : 0) + (shutdownPlugin ? 1 : 0) + (keyboardPlugin ? 1 : 0) + (notificationPlugin ? 1 : 0);
|
|
|
|
|
}
|
2019-10-31 15:38:56 +08:00
|
|
|
|
// icon个数
|
|
|
|
|
int iconCount = m_fixedAreaLayout->count() + m_appAreaSonLayout->count() + pluginCount;
|
|
|
|
|
// 余数
|
|
|
|
|
int yu = (totalLength % iconCount);
|
|
|
|
|
// icon宽度 = (总宽度-余数)/icon个数
|
2020-08-03 15:01:59 +08:00
|
|
|
|
int iconSize = (totalLength - yu) / iconCount;
|
|
|
|
|
//计算插件图标的最大或最小值
|
|
|
|
|
int tray_item_size = qBound(20, iconSize, 40);
|
|
|
|
|
if ((m_position == Position::Top) || (m_position == Position::Bottom)) {
|
|
|
|
|
tray_item_size = qMin(tray_item_size,height());
|
|
|
|
|
tray_item_size = std::min(tray_item_size, height() - 20);
|
|
|
|
|
} else {
|
|
|
|
|
tray_item_size = qMin(tray_item_size,width());
|
|
|
|
|
tray_item_size = std::min(tray_item_size, width() - 20);
|
2019-10-31 15:38:56 +08:00
|
|
|
|
}
|
2020-08-03 15:01:59 +08:00
|
|
|
|
//减去插件图标的大小后重新计算固定图标和应用图标的平均大小
|
|
|
|
|
totalLength -= tray_item_size * pluginCount;
|
|
|
|
|
iconCount -= pluginCount;
|
|
|
|
|
// 余数
|
|
|
|
|
yu = (totalLength % iconCount);
|
|
|
|
|
// icon宽度 = (总宽度-余数)/icon个数
|
|
|
|
|
iconSize = (totalLength - yu) / iconCount;
|
2019-10-28 14:42:56 +08:00
|
|
|
|
|
|
|
|
|
if ((m_position == Position::Top) || (m_position == Position::Bottom)) {
|
|
|
|
|
if (iconSize >= height()) {
|
2020-05-28 16:01:38 +08:00
|
|
|
|
calcuDockIconSize(height(), height(), trashPlugin, shutdownPlugin, keyboardPlugin, notificationPlugin);
|
2019-10-28 14:42:56 +08:00
|
|
|
|
} else {
|
2020-05-28 16:01:38 +08:00
|
|
|
|
calcuDockIconSize(iconSize, height(), trashPlugin, shutdownPlugin, keyboardPlugin, notificationPlugin);
|
2019-10-28 14:42:56 +08:00
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
if (iconSize >= width()) {
|
2020-05-28 16:01:38 +08:00
|
|
|
|
calcuDockIconSize(width(), width(), trashPlugin, shutdownPlugin, keyboardPlugin, notificationPlugin);
|
2019-10-28 14:42:56 +08:00
|
|
|
|
} else {
|
2020-05-28 16:01:38 +08:00
|
|
|
|
calcuDockIconSize(width(), iconSize, trashPlugin, shutdownPlugin, keyboardPlugin, notificationPlugin);
|
2019-10-28 14:42:56 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-28 16:01:38 +08:00
|
|
|
|
void MainPanelControl::calcuDockIconSize(int w, int h, PluginsItem *trashPlugin, PluginsItem *shutdownPlugin, PluginsItem *keyboardPlugin, PluginsItem *notificationPlugin)
|
2019-10-28 14:42:56 +08:00
|
|
|
|
{
|
2020-09-10 15:51:33 +08:00
|
|
|
|
int appItemSize = qMin(w, h);
|
|
|
|
|
|
2020-08-03 15:01:59 +08:00
|
|
|
|
for (int i = 0; i < m_fixedAreaLayout->count(); ++i) {
|
2020-09-10 15:51:33 +08:00
|
|
|
|
m_fixedAreaLayout->itemAt(i)->widget()->setFixedSize(appItemSize, appItemSize);
|
2019-10-28 14:42:56 +08:00
|
|
|
|
}
|
|
|
|
|
|
2019-10-31 15:38:56 +08:00
|
|
|
|
if (m_position == Dock::Position::Top || m_position == Dock::Position::Bottom) {
|
|
|
|
|
m_fixedSpliter->setFixedSize(SPLITER_SIZE, int(w * 0.6));
|
|
|
|
|
m_appSpliter->setFixedSize(SPLITER_SIZE, int(w * 0.6));
|
|
|
|
|
m_traySpliter->setFixedSize(SPLITER_SIZE, int(w * 0.5));
|
|
|
|
|
} else {
|
|
|
|
|
m_fixedSpliter->setFixedSize(int(h * 0.6), SPLITER_SIZE);
|
|
|
|
|
m_appSpliter->setFixedSize(int(h * 0.6), SPLITER_SIZE);
|
|
|
|
|
m_traySpliter->setFixedSize(int(h * 0.5), SPLITER_SIZE);
|
2019-10-28 14:42:56 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-08-03 15:01:59 +08:00
|
|
|
|
for (int i = 0; i < m_appAreaSonLayout->count(); ++i) {
|
2020-09-10 15:51:33 +08:00
|
|
|
|
m_appAreaSonLayout->itemAt(i)->widget()->setFixedSize(appItemSize, appItemSize);
|
2020-08-03 15:01:59 +08:00
|
|
|
|
}
|
2019-10-31 15:38:56 +08:00
|
|
|
|
|
|
|
|
|
// 托盘上每个图标大小
|
|
|
|
|
int tray_item_size = 20;
|
|
|
|
|
|
|
|
|
|
if ((m_position == Position::Top) || (m_position == Position::Bottom)) {
|
|
|
|
|
w = qBound(20, w, 40);
|
|
|
|
|
tray_item_size = std::min(w, h - 20);
|
|
|
|
|
} else {
|
|
|
|
|
h = qBound(20, h, 40);
|
|
|
|
|
tray_item_size = std::min(w - 20, h);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (tray_item_size < 20)
|
|
|
|
|
return;
|
|
|
|
|
|
2020-09-10 15:51:33 +08:00
|
|
|
|
if (m_tray) {
|
|
|
|
|
m_tray->centralWidget()->setProperty("iconSize", tray_item_size);
|
2020-01-09 15:47:09 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-09-10 15:51:33 +08:00
|
|
|
|
//因为日期时间大小和其他插件大小有异,为了设置边距,在各插件中增加了一层布局
|
|
|
|
|
//因此需要通过多一层布局来获取各插件
|
2020-01-09 15:47:09 +08:00
|
|
|
|
if ((m_position == Position::Top) || (m_position == Position::Bottom)) {
|
|
|
|
|
// 三方插件
|
2020-01-06 14:27:22 +08:00
|
|
|
|
for (int i = 0; i < m_pluginLayout->count(); ++ i) {
|
2020-09-10 15:51:33 +08:00
|
|
|
|
QLayout *layout = m_pluginLayout->itemAt(i)->layout();
|
|
|
|
|
if (layout) {
|
|
|
|
|
PluginsItem *pItem = static_cast<PluginsItem *>(layout->itemAt(0)->widget());
|
2020-12-17 09:51:28 +08:00
|
|
|
|
if (pItem) {
|
|
|
|
|
if (pItem->sizeHint().width() == -1) {
|
2020-11-06 15:28:56 +08:00
|
|
|
|
pItem->setFixedSize(tray_item_size, tray_item_size);
|
2020-09-10 15:51:33 +08:00
|
|
|
|
}
|
2020-01-09 15:47:09 +08:00
|
|
|
|
}
|
2020-01-06 14:27:22 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2019-10-28 14:42:56 +08:00
|
|
|
|
} else {
|
2020-01-09 15:47:09 +08:00
|
|
|
|
// 三方插件
|
2020-01-06 14:27:22 +08:00
|
|
|
|
for (int i = 0; i < m_pluginLayout->count(); ++ i) {
|
2020-09-10 15:51:33 +08:00
|
|
|
|
QLayout *layout = m_pluginLayout->itemAt(i)->layout();
|
|
|
|
|
if (layout) {
|
|
|
|
|
PluginsItem *pItem = static_cast<PluginsItem *>(layout->itemAt(0)->widget());
|
2020-12-17 09:51:28 +08:00
|
|
|
|
if (pItem) {
|
|
|
|
|
if (pItem->sizeHint().width() == -1) {
|
2020-11-06 15:28:56 +08:00
|
|
|
|
pItem->setFixedSize(tray_item_size, tray_item_size);
|
2020-09-10 15:51:33 +08:00
|
|
|
|
}
|
2020-01-09 15:47:09 +08:00
|
|
|
|
}
|
2020-01-06 14:27:22 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2019-10-28 14:42:56 +08:00
|
|
|
|
}
|
2020-09-10 15:51:33 +08:00
|
|
|
|
|
|
|
|
|
int appTopAndBottomMargin = 0;
|
|
|
|
|
int appLeftAndRightMargin = 0;
|
|
|
|
|
|
|
|
|
|
int trayTopAndBottomMargin = 0;
|
|
|
|
|
int trayLeftAndRightMargin = 0;
|
|
|
|
|
|
|
|
|
|
if ((m_position == Position::Top) || (m_position == Position::Bottom)) {
|
|
|
|
|
appTopAndBottomMargin = (m_fixedAreaWidget->height() - appItemSize) / 2;
|
|
|
|
|
trayTopAndBottomMargin = (m_trayAreaWidget->height() - tray_item_size) / 2;
|
|
|
|
|
} else {
|
|
|
|
|
appLeftAndRightMargin = (m_fixedAreaWidget->width() - appItemSize) / 2;
|
|
|
|
|
trayLeftAndRightMargin = (m_trayAreaWidget->width() - tray_item_size) / 2;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m_fixedAreaLayout->setContentsMargins(appLeftAndRightMargin, appTopAndBottomMargin, appLeftAndRightMargin, appTopAndBottomMargin);
|
|
|
|
|
m_appAreaSonLayout->setContentsMargins(appLeftAndRightMargin, appTopAndBottomMargin, appLeftAndRightMargin, appTopAndBottomMargin);
|
|
|
|
|
m_trayAreaLayout->setContentsMargins(trayLeftAndRightMargin, trayTopAndBottomMargin, trayLeftAndRightMargin, trayTopAndBottomMargin);
|
|
|
|
|
|
|
|
|
|
//因为日期时间插件大小和其他插件大小有异,需要单独设置各插件的边距
|
|
|
|
|
//而不对日期时间插件设置边距
|
|
|
|
|
for (int i = 0; i < m_pluginLayout->count(); ++ i) {
|
|
|
|
|
QLayout *layout = m_pluginLayout->itemAt(i)->layout();
|
|
|
|
|
if (layout) {
|
|
|
|
|
PluginsItem *pItem = static_cast<PluginsItem *>(layout->itemAt(0)->widget());
|
|
|
|
|
|
|
|
|
|
if (pItem && pItem->pluginName() != "datetime") {
|
|
|
|
|
layout->setContentsMargins(trayLeftAndRightMargin, trayTopAndBottomMargin, trayLeftAndRightMargin, trayTopAndBottomMargin);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-10-28 14:42:56 +08:00
|
|
|
|
}
|
2019-10-31 15:38:56 +08:00
|
|
|
|
|
|
|
|
|
void MainPanelControl::getTrayVisableItemCount()
|
|
|
|
|
{
|
|
|
|
|
if (m_trayAreaLayout->count() > 0) {
|
|
|
|
|
TrayPluginItem *w = static_cast<TrayPluginItem *>(m_trayAreaLayout->itemAt(0)->widget());
|
|
|
|
|
m_trayIconCount = w->trayVisableItemCount();
|
|
|
|
|
} else {
|
|
|
|
|
m_trayIconCount = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
resizeDockIcon();
|
|
|
|
|
}
|
2020-05-28 14:49:06 +08:00
|
|
|
|
|
|
|
|
|
void MainPanelControl::resizeDesktopWidget()
|
|
|
|
|
{
|
|
|
|
|
if (m_position == Position::Right || m_position == Position::Left)
|
|
|
|
|
m_desktopWidget->setFixedSize(width(), DESKTOP_SIZE);
|
|
|
|
|
else
|
|
|
|
|
m_desktopWidget->setFixedSize(DESKTOP_SIZE, height());
|
|
|
|
|
|
|
|
|
|
if (DisplayMode::Fashion == m_dislayMode)
|
|
|
|
|
m_desktopWidget->setFixedSize(0, 0);
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-28 14:42:16 +08:00
|
|
|
|
/**
|
|
|
|
|
* @brief MainPanelControl::checkNeedShowDesktop 根据窗管提供接口(当前是否显示的桌面),提供鼠标
|
|
|
|
|
* 移入 显示桌面窗口 区域时,是否需要显示桌面判断依据
|
|
|
|
|
* @return 窗管返回 当前是桌面 或 窗管接口查询失败 返回false,否则true
|
|
|
|
|
*/
|
|
|
|
|
bool MainPanelControl::checkNeedShowDesktop()
|
|
|
|
|
{
|
|
|
|
|
QDBusInterface wmInter("com.deepin.wm", "/com/deepin/wm", "com.deepin.wm");
|
|
|
|
|
QList<QVariant> argumentList;
|
|
|
|
|
QDBusMessage reply = wmInter.callWithArgumentList(QDBus::Block, QStringLiteral("GetIsShowDesktop"), argumentList);
|
|
|
|
|
if (reply.type() == QDBusMessage::ReplyMessage && reply.arguments().count() == 1) {
|
|
|
|
|
return !reply.arguments().at(0).toBool();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
qDebug() << "wm call GetIsShowDesktop fail, res:" << reply.type();
|
|
|
|
|
return false;
|
|
|
|
|
}
|