dde-dock/frame/window/traymainwindow.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

164 lines
4.8 KiB
C++
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) 2022 ~ 2022 Deepin Technology Co., Ltd.
*
* Author: donghualin <donghualin@uniontech.com>
*
* Maintainer: donghualin <donghualin@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 "traymainwindow.h"
#include "traymanagerwindow.h"
#include "dragwidget.h"
#include "dockscreen.h"
#include "displaymanager.h"
#include <DSysInfo>
#include <DPlatformTheme>
#include <DStyleHelper>
#include <QBitmap>
#include <QBoxLayout>
#include <QX11Info>
#include <qpa/qplatformwindow.h>
#include <qpa/qplatformscreen.h>
#include <qpa/qplatformnativeinterface.h>
#define DOCK_SCREEN DockScreen::instance()
#define DIS_INS DisplayManager::instance()
TrayMainWindow::TrayMainWindow(MultiScreenWorker *multiScreenWorker, QWidget *parent)
: MainWindowBase(multiScreenWorker, parent)
, m_trayManager(new TrayManagerWindow(this))
, m_multiScreenWorker(multiScreenWorker)
{
initUI();
initConnection();
}
void TrayMainWindow::setPosition(const Dock::Position &position)
{
MainWindowBase::setPosition(position);
m_trayManager->setPositon(position);
}
TrayManagerWindow *TrayMainWindow::trayManagerWindow() const
{
return m_trayManager;
}
void TrayMainWindow::setDisplayMode(const Dock::DisplayMode &displayMode)
{
// 只有在时尚模式下才显示
setVisible(displayMode == Dock::DisplayMode::Fashion);
MainWindowBase::setDisplayMode(displayMode);
}
MainWindowBase::DockWindowType TrayMainWindow::windowType() const
{
return DockWindowType::TrayWindow;
}
void TrayMainWindow::updateParentGeometry(const Dock::Position &position, const QRect &rect)
{
QSize trayPanelSize = m_trayManager->suitableSize(position);
// 设置trayManagerWindow的大小和位置
if (position == Dock::Position::Top || position == Dock::Position::Bottom) {
setFixedSize(trayPanelSize.width(), rect.height());
move(rect.topLeft());
} else {
setFixedSize(rect.width(), trayPanelSize.height());
move(rect.topLeft());
}
int panelSize = windowSize();
QRect panelRect = rect;
switch(position) {
case Dock::Position::Left:
m_trayManager->move(width() - panelSize, 0);
panelRect.setWidth(panelSize);
panelRect.setHeight(trayPanelSize.height());
break;
case Dock::Position::Top:
m_trayManager->move(0, height() - panelSize);
panelRect.setWidth(trayPanelSize.width());
panelRect.setHeight(panelSize);
break;
case Dock::Position::Right: {
m_trayManager->move(0, 0);
panelRect.setWidth(panelSize);
panelRect.setHeight(trayPanelSize.height());
break;
}
case Dock::Position::Bottom: {
m_trayManager->move(0, 0);
panelRect.setWidth(trayPanelSize.width());
panelRect.setHeight(panelSize);
break;
}
}
// 在从高效模式切换到时尚模式的时候,需要调用该函数来设置托盘区域的尺寸,在设置尺寸的时候会触发
// 托盘区域的requestUpdate信号WindowManager接收到requestUpdate会依次对每个顶层界面设置尺寸此时又会触发该函数
// 引起无限循环,因此,在设置尺寸的时候阻塞信号,防止进入死循环
m_trayManager->blockSignals(true);
m_trayManager->setFixedSize(panelRect.size());
m_trayManager->blockSignals(false);
}
QSize TrayMainWindow::suitableSize() const
{
return m_trayManager->suitableSize();
}
void TrayMainWindow::resetPanelGeometry()
{
m_trayManager->setFixedSize(size());
m_trayManager->move(0, 0);
}
int TrayMainWindow::dockSpace() const
{
return 0;
}
void TrayMainWindow::updateRadius(int borderRadius)
{
m_trayManager->updateBorderRadius(borderRadius);
}
QSize TrayMainWindow::suitableSize(const Dock::Position &pos, const int &, const double &) const
{
return m_trayManager->suitableSize(pos);
}
void TrayMainWindow::initUI()
{
m_trayManager->move(0, 0);
}
void TrayMainWindow::initConnection()
{
connect(m_trayManager, &TrayManagerWindow::requestUpdate, this, &TrayMainWindow::onRequestUpdate);
}
void TrayMainWindow::onRequestUpdate()
{
// 如果当前是高效模式,则无需发送信号
if (displayMode() == Dock::DisplayMode::Efficient)
return;
Q_EMIT requestUpdate();
}