dde-dock/frame/window/mainwindow.cpp
donghualin 1691e7188c fix: 任务栏代码结构优化解耦
原来的TrayManagerWindow的类是放到MainPanelWindow类里面作为它的一部分,导致窗管在显示的时候有很多问题
修改方案:
1、将左右侧区域拆分成两个窗体,让它们继承自相同的基类MainWindowBase。
2、左右区域公共的部分,例如圆角、展示区域、动画获取等,都在基类中实现或者通过接口返回
3、增加WindowManager类,管理所有的界面,WindowManager类无需知道具体子类的指针,只需要根据相应的接口来获取即可
4、所有的界面类在main.cpp中创建,调用WindowManager对象设置
5、拆分MultiScreenWorker类,使MultiScreenWorker类只关心任务栏相关的逻辑,无需关心窗体或界面

Log: 优化任务栏的显示问题
Influence: 打开任务栏,观察时尚模式下圆角,左右侧区域中间是否连接在一起等
Bug: https://pms.uniontech.com/bug-view-137267.html
Bug: https://pms.uniontech.com/bug-view-140029.html
Bug: https://pms.uniontech.com/bug-view-134527.html
Bug: https://pms.uniontech.com/bug-view-146743.html
Bug: https://pms.uniontech.com/bug-view-150293.html
Change-Id: I4266f6f8c983f61258b92834d93cdacd0221d7de
2022-08-25 19:31:44 +00:00

175 lines
5.5 KiB
C++
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
* Copyright (C) 2011 ~ 2018 Deepin Technology Co., Ltd.
*
* Author: sbw <sbw@sbw.so>
*
* Maintainer: sbw <sbw@sbw.so>
* zhaolong <zhaolong@uniontech.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 "mainwindow.h"
#include "mainpanelcontrol.h"
#include "dockitemmanager.h"
#include "menuworker.h"
#include "proxyplugincontroller.h"
#include "windowmanager.h"
#include "dockscreen.h"
#include "dragwidget.h"
#include "multiscreenworker.h"
#include "constants.h"
#include "displaymanager.h"
#include <DStyle>
#include <DPlatformWindowHandle>
#include <DSysInfo>
#include <DPlatformTheme>
#include <DDBusSender>
#include <QDebug>
#include <QEvent>
#include <QResizeEvent>
#include <QScreen>
#include <QGuiApplication>
#include <QX11Info>
#include <QtConcurrent>
#include <qpa/qplatformwindow.h>
#include <qpa/qplatformscreen.h>
#include <qpa/qplatformnativeinterface.h>
#include <QMenu>
#include <X11/X.h>
#include <X11/Xutil.h>
#define DOCK_SCREEN DockScreen::instance()
#define DIS_INS DisplayManager::instance()
MainWindow::MainWindow(MultiScreenWorker *multiScreenWorker, QWidget *parent)
: MainWindowBase(multiScreenWorker, parent)
, m_mainPanel(new MainPanelControl(multiScreenWorker->dockInter(), this))
, m_multiScreenWorker(multiScreenWorker)
{
m_mainPanel->setDisplayMode(m_multiScreenWorker->displayMode());
initConnections();
for (auto item : DockItemManager::instance()->itemList())
m_mainPanel->insertItem(-1, item);
}
void MainWindow::resizeEvent(QResizeEvent *event)
{
MainWindowBase::resizeEvent(event);
m_mainPanel->updatePluginsLayout();
// 任务栏大小、位置、模式改变都会触发resize发射大小改变信号供依赖项目更新位置
Q_EMIT requestUpdate();
}
void MainWindow::initConnections()
{
connect(DockItemManager::instance(), &DockItemManager::itemInserted, m_mainPanel, &MainPanelControl::insertItem, Qt::DirectConnection);
connect(DockItemManager::instance(), &DockItemManager::itemRemoved, m_mainPanel, &MainPanelControl::removeItem, Qt::DirectConnection);
connect(DockItemManager::instance(), &DockItemManager::itemUpdated, m_mainPanel, &MainPanelControl::itemUpdated, Qt::DirectConnection);
connect(DockItemManager::instance(), &DockItemManager::trayVisableCountChanged, this, &MainWindow::resizeDockIcon, Qt::QueuedConnection);
connect(m_mainPanel, &MainPanelControl::itemMoved, DockItemManager::instance(), &DockItemManager::itemMoved, Qt::DirectConnection);
connect(m_mainPanel, &MainPanelControl::itemAdded, DockItemManager::instance(), &DockItemManager::itemAdded, Qt::DirectConnection);
connect(m_mainPanel, &MainPanelControl::requestUpdate, this, &MainWindow::requestUpdate);
}
/**
* @brief MainWindow::getTrayVisableItemCount
* 重新获取以下当前托盘区域有多少个可见的图标,并更新图标的大小
*/
void MainWindow::resizeDockIcon()
{
m_mainPanel->resizeDockIcon();
}
/**
* @brief MainWindow::setGeometry
* @param rect 设置任务栏的位置和大小重写此函数时为了及时发出panelGeometryChanged信号最终供外部DBus调用方使用
*/
void MainWindow::setGeometry(const QRect &rect)
{
if (rect == this->geometry())
return;
DBlurEffectWidget::setGeometry(rect);
emit requestUpdate();
}
MainWindowBase::DockWindowType MainWindow::windowType() const
{
return DockWindowType::MainWindow;
}
void MainWindow::setPosition(const Position &position)
{
MainWindowBase::setPosition(position);
m_mainPanel->setPositonValue(position);
// 更新鼠标拖拽样式在类内部设置到qApp单例上去
if ((Top == position) || (Bottom == position))
m_mainPanel->setCursor(Qt::SizeVerCursor);
else
m_mainPanel->setCursor(Qt::SizeHorCursor);
}
void MainWindow::setDisplayMode(const Dock::DisplayMode &displayMode)
{
m_mainPanel->setDisplayMode(displayMode);
MainWindowBase::setDisplayMode(displayMode);
}
void MainWindow::updateParentGeometry(const Position &pos, const QRect &rect)
{
setFixedSize(rect.size());
setGeometry(rect);
int panelSize = windowSize();
QRect panelRect = rect;
switch (pos) {
case Position::Top:
m_mainPanel->move(0, rect.height() - panelSize);
panelRect.setHeight(panelSize);
break;
case Position::Left:
m_mainPanel->move(width() - panelSize, 0);
panelRect.setWidth(panelSize);
break;
case Position::Bottom:
m_mainPanel->move(0, 0);
panelRect.setHeight(panelSize);
break;
case Position::Right:
m_mainPanel->move(0, 0);
panelRect.setWidth(panelSize);
break;
}
m_mainPanel->setFixedSize(panelRect.size());
}
QSize MainWindow::suitableSize(const Position &pos, const int &screenSize, const double &deviceRatio) const
{
return m_mainPanel->suitableSize(pos, screenSize, deviceRatio);
}
void MainWindow::resetPanelGeometry()
{
m_mainPanel->setFixedSize(size());
m_mainPanel->move(0, 0);
}