2023-02-16 13:51:55 +08:00
|
|
|
|
// Copyright (C) 2022 ~ 2022 Deepin Technology Co., Ltd.
|
|
|
|
|
// SPDX-FileCopyrightText: 2018 - 2023 UnionTech Software Technology Co., Ltd.
|
|
|
|
|
//
|
|
|
|
|
// SPDX-License-Identifier: LGPL-3.0-or-later
|
|
|
|
|
|
2022-05-12 17:09:10 +08:00
|
|
|
|
#include "traymanagerwindow.h"
|
|
|
|
|
#include "quickpluginwindow.h"
|
|
|
|
|
#include "tray_gridview.h"
|
|
|
|
|
#include "tray_delegate.h"
|
|
|
|
|
#include "tray_model.h"
|
|
|
|
|
#include "constants.h"
|
|
|
|
|
#include "systempluginwindow.h"
|
|
|
|
|
#include "datetimedisplayer.h"
|
2022-11-09 11:03:59 +00:00
|
|
|
|
#include "expandiconwidget.h"
|
2022-12-12 10:30:44 +00:00
|
|
|
|
#include "quickdragcore.h"
|
2022-12-12 09:52:52 +00:00
|
|
|
|
#include "utils.h"
|
2023-06-07 14:11:50 +08:00
|
|
|
|
#include "docksettings.h"
|
2022-05-12 17:09:10 +08:00
|
|
|
|
|
|
|
|
|
#include <DGuiApplicationHelper>
|
|
|
|
|
|
|
|
|
|
#include <QDropEvent>
|
|
|
|
|
#include <QBoxLayout>
|
|
|
|
|
#include <QLabel>
|
|
|
|
|
#include <QMimeData>
|
|
|
|
|
#include <QDBusConnection>
|
|
|
|
|
#include <QPainter>
|
2022-05-25 09:42:01 +08:00
|
|
|
|
#include <QPainterPath>
|
2022-05-12 17:09:10 +08:00
|
|
|
|
|
2022-05-25 09:42:01 +08:00
|
|
|
|
#define CRITLCALHEIGHT 42
|
|
|
|
|
#define CONTENTSPACE 7
|
2022-12-12 09:52:52 +00:00
|
|
|
|
#define SINGLEROWSPACE 4
|
2022-05-25 09:42:01 +08:00
|
|
|
|
// 高度小于等于这个值的时候,间距最小值
|
|
|
|
|
#define MINHIGHT 46
|
|
|
|
|
// 最小值与最大值的差值
|
|
|
|
|
#define MINSPACE 4
|
|
|
|
|
// 当前高度与最小高度差值大于这个值的时候,间距使用最大值
|
|
|
|
|
#define MAXDIFF 3
|
2022-05-12 17:09:10 +08:00
|
|
|
|
|
|
|
|
|
TrayManagerWindow::TrayManagerWindow(QWidget *parent)
|
|
|
|
|
: QWidget(parent)
|
2022-05-25 09:42:01 +08:00
|
|
|
|
, m_appPluginDatetimeWidget(new QWidget(this))
|
2023-06-07 14:11:50 +08:00
|
|
|
|
, m_systemPluginWidget(new SystemPluginWindow(this))
|
2022-05-12 17:09:10 +08:00
|
|
|
|
, m_appPluginWidget(new QWidget(m_appPluginDatetimeWidget))
|
2023-01-31 10:55:04 +08:00
|
|
|
|
, m_quickIconWidget(new QuickPluginWindow(Dock::DisplayMode::Fashion, m_appPluginWidget))
|
2022-10-19 03:50:12 +00:00
|
|
|
|
, m_dateTimeWidget(new DateTimeDisplayer(false, m_appPluginDatetimeWidget))
|
2022-05-12 17:09:10 +08:00
|
|
|
|
, m_appPluginLayout(new QBoxLayout(QBoxLayout::Direction::LeftToRight, this))
|
|
|
|
|
, m_mainLayout(new QBoxLayout(QBoxLayout::Direction::LeftToRight, this))
|
2023-08-16 17:03:38 +08:00
|
|
|
|
, m_trayView(TrayGridView::getDockTrayGridView(this))
|
2022-11-02 06:57:46 +00:00
|
|
|
|
, m_model(TrayModel::getDockModel())
|
2023-08-16 17:03:38 +08:00
|
|
|
|
, m_delegate(TrayDelegate::getDockTrayDelegate(m_trayView, m_trayView))
|
2022-08-25 19:31:31 +00:00
|
|
|
|
, m_position(Dock::Position::Bottom)
|
2022-11-02 06:57:46 +00:00
|
|
|
|
, m_displayMode(Dock::DisplayMode::Fashion)
|
2022-05-17 20:57:09 +08:00
|
|
|
|
, m_splitLine(new QLabel(m_appPluginDatetimeWidget))
|
2022-08-25 19:31:31 +00:00
|
|
|
|
, m_singleShow(false)
|
|
|
|
|
, m_borderRadius(0)
|
2023-06-07 14:11:50 +08:00
|
|
|
|
, m_windowFashionSize(DockSettings::instance()->getWindowSizeFashion())
|
2022-05-12 17:09:10 +08:00
|
|
|
|
{
|
|
|
|
|
initUi();
|
|
|
|
|
initConnection();
|
|
|
|
|
|
|
|
|
|
setAcceptDrops(true);
|
|
|
|
|
setMouseTracking(true);
|
2022-08-25 19:31:31 +00:00
|
|
|
|
|
|
|
|
|
QMetaObject::invokeMethod(this, &TrayManagerWindow::updateLayout, Qt::QueuedConnection);
|
2022-05-12 17:09:10 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TrayManagerWindow::~TrayManagerWindow()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-25 19:31:31 +00:00
|
|
|
|
void TrayManagerWindow::updateBorderRadius(int borderRadius)
|
2022-05-27 17:34:02 +08:00
|
|
|
|
{
|
2022-08-25 19:31:31 +00:00
|
|
|
|
m_borderRadius = borderRadius;
|
|
|
|
|
update();
|
2023-01-12 13:55:34 +08:00
|
|
|
|
qApp->setProperty("trayBorderRadius", pathRadius());
|
2022-08-25 19:31:31 +00:00
|
|
|
|
}
|
2022-05-27 17:34:02 +08:00
|
|
|
|
|
2022-08-25 19:31:31 +00:00
|
|
|
|
void TrayManagerWindow::updateLayout()
|
|
|
|
|
{
|
2022-12-12 09:52:52 +00:00
|
|
|
|
if (!isVisible())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
int dockSize = 0;
|
|
|
|
|
if (Utils::isDraging()) {
|
|
|
|
|
if (m_position == Dock::Position::Top || m_position == Dock::Position::Bottom)
|
|
|
|
|
dockSize = topLevelWidget()->height();
|
|
|
|
|
else
|
|
|
|
|
dockSize = topLevelWidget()->width();
|
|
|
|
|
} else {
|
2023-06-07 14:11:50 +08:00
|
|
|
|
dockSize = m_windowFashionSize;
|
2022-12-12 09:52:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-08-25 19:31:31 +00:00
|
|
|
|
bool lastIsSingle = m_singleShow;
|
2022-12-12 09:52:52 +00:00
|
|
|
|
updateItemLayout(dockSize);
|
|
|
|
|
// 当插件区域从单行变成两行或者两行变成单行的时候,发送该信号,通知外部重新调整区域大小
|
|
|
|
|
if (lastIsSingle != m_singleShow)
|
|
|
|
|
Q_EMIT requestUpdate();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TrayManagerWindow::updateItemLayout(int dockSize)
|
|
|
|
|
{
|
|
|
|
|
if (m_position == Dock::Position::Top || m_position == Dock::Position::Bottom) {
|
|
|
|
|
m_singleShow = (dockSize <= CRITLCALHEIGHT);
|
|
|
|
|
} else {
|
2022-08-25 19:31:31 +00:00
|
|
|
|
m_singleShow = true;
|
2022-12-12 09:52:52 +00:00
|
|
|
|
}
|
2022-06-20 15:03:35 +08:00
|
|
|
|
|
2022-08-25 19:31:31 +00:00
|
|
|
|
if (m_singleShow)
|
2022-05-27 17:34:02 +08:00
|
|
|
|
resetSingleDirection();
|
|
|
|
|
else
|
|
|
|
|
resetMultiDirection();
|
|
|
|
|
|
|
|
|
|
resetChildWidgetSize();
|
|
|
|
|
// 当尺寸发生变化的时候,通知托盘区域刷新尺寸,让托盘图标始终保持居中显示
|
|
|
|
|
Q_EMIT m_delegate->sizeHintChanged(m_model->index(0, 0));
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-12 13:55:34 +08:00
|
|
|
|
int TrayManagerWindow::pathRadius() const
|
|
|
|
|
{
|
|
|
|
|
QMargins mainMargin = m_mainLayout->contentsMargins();
|
|
|
|
|
return m_borderRadius - mainMargin.top();
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-12 17:09:10 +08:00
|
|
|
|
void TrayManagerWindow::setPositon(Dock::Position position)
|
|
|
|
|
{
|
2022-08-25 19:31:31 +00:00
|
|
|
|
if (m_position == position)
|
2022-05-12 17:09:10 +08:00
|
|
|
|
return;
|
|
|
|
|
|
2022-08-25 19:31:31 +00:00
|
|
|
|
m_position = position;
|
2022-05-17 20:57:09 +08:00
|
|
|
|
|
2022-05-12 17:09:10 +08:00
|
|
|
|
TrayDelegate *delegate = static_cast<TrayDelegate *>(m_trayView->itemDelegate());
|
|
|
|
|
delegate->setPositon(position);
|
|
|
|
|
|
2022-05-17 20:57:09 +08:00
|
|
|
|
m_trayView->setPosition(position);
|
2022-05-12 17:09:10 +08:00
|
|
|
|
m_quickIconWidget->setPositon(position);
|
|
|
|
|
m_dateTimeWidget->setPositon(position);
|
|
|
|
|
m_systemPluginWidget->setPositon(position);
|
2022-11-22 10:47:20 +00:00
|
|
|
|
m_trayView->onUpdateEditorView();
|
2022-08-25 19:31:31 +00:00
|
|
|
|
updateLayout();
|
2022-05-12 17:09:10 +08:00
|
|
|
|
}
|
|
|
|
|
|
2022-11-02 06:57:46 +00:00
|
|
|
|
void TrayManagerWindow::setDisplayMode(Dock::DisplayMode displayMode)
|
|
|
|
|
{
|
|
|
|
|
m_displayMode = displayMode;
|
2022-11-09 11:03:59 +00:00
|
|
|
|
// 如果当前模式为高效模式,则设置当前的trayView为其计算位置的参照
|
2022-12-12 09:52:52 +00:00
|
|
|
|
if (displayMode == Dock::DisplayMode::Fashion) {
|
2022-11-09 11:03:59 +00:00
|
|
|
|
ExpandIconWidget::popupTrayView()->setReferGridView(m_trayView);
|
2023-06-07 14:11:50 +08:00
|
|
|
|
updateItemLayout(m_windowFashionSize);
|
2023-08-16 17:03:38 +08:00
|
|
|
|
// TODO: reuse QuickPluginWindow, SystemPluginWindow
|
|
|
|
|
m_appPluginLayout->addWidget(TrayGridView::getDockTrayGridView());
|
|
|
|
|
m_appPluginLayout->addWidget(m_quickIconWidget);
|
|
|
|
|
} else {
|
|
|
|
|
m_appPluginLayout->removeWidget(TrayGridView::getDockTrayGridView());
|
|
|
|
|
m_appPluginLayout->removeWidget(m_quickIconWidget);
|
2022-12-12 09:52:52 +00:00
|
|
|
|
}
|
2022-11-02 06:57:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-08-25 19:31:31 +00:00
|
|
|
|
int TrayManagerWindow::appDatetimeSize(const Dock::Position &position) const
|
2022-05-12 17:09:10 +08:00
|
|
|
|
{
|
2022-08-25 19:31:31 +00:00
|
|
|
|
if (position == Dock::Position::Top || position == Dock::Position::Bottom) {
|
|
|
|
|
bool showSingle = m_singleShow;
|
|
|
|
|
// 正在从左右切换到上下(m_position当前显示的位置,还未切换),此时根据托盘区域的尺寸来决定显示一行还是两行
|
|
|
|
|
if (m_position == Dock::Position::Left || m_position == Dock::Position::Right) {
|
2023-06-07 14:11:50 +08:00
|
|
|
|
showSingle = m_windowFashionSize < CRITLCALHEIGHT;
|
2022-08-25 19:31:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 如果是一行或者是在切换位置(从左右切换到上下)
|
|
|
|
|
if (showSingle) {
|
|
|
|
|
return m_trayView->suitableSize(position).width() + m_quickIconWidget->suitableSize(position).width()
|
|
|
|
|
+ m_dateTimeWidget->suitableSize(position).width() + 4;
|
2022-05-17 20:57:09 +08:00
|
|
|
|
}
|
|
|
|
|
//如果是两行
|
2022-08-25 19:31:31 +00:00
|
|
|
|
int topWidth = m_trayView->suitableSize(position).width() + m_quickIconWidget->suitableSize(position).width();
|
|
|
|
|
int bottomWidth = m_dateTimeWidget->suitableSize(position).width();
|
2022-05-17 20:57:09 +08:00
|
|
|
|
return qMax(topWidth, bottomWidth);
|
2022-05-12 17:09:10 +08:00
|
|
|
|
}
|
|
|
|
|
|
2022-08-25 19:31:31 +00:00
|
|
|
|
int trayHeight = m_trayView->suitableSize(position).height();
|
|
|
|
|
int traypluginHeight = trayHeight + m_quickIconWidget->suitableSize(position).height() + m_appPluginLayout->spacing();
|
2023-08-30 16:05:02 +08:00
|
|
|
|
return traypluginHeight + m_dateTimeWidget->suitableSize(position).height() + 2;
|
2022-08-25 19:31:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QSize TrayManagerWindow::suitableSize() const
|
|
|
|
|
{
|
|
|
|
|
return suitableSize(m_position);
|
2022-05-12 17:09:10 +08:00
|
|
|
|
}
|
|
|
|
|
|
2022-08-25 19:31:31 +00:00
|
|
|
|
QSize TrayManagerWindow::suitableSize(const Dock::Position &position) const
|
2022-05-12 17:09:10 +08:00
|
|
|
|
{
|
|
|
|
|
QMargins m = m_mainLayout->contentsMargins();
|
2022-08-25 19:31:31 +00:00
|
|
|
|
if (position == Dock::Position::Top || position == Dock::Position::Bottom) {
|
2022-11-30 11:13:45 +08:00
|
|
|
|
int width = appDatetimeSize(position);
|
|
|
|
|
int systemWidgetWidth = m_systemPluginWidget->suitableSize(position).width();
|
|
|
|
|
if (systemWidgetWidth > 0) {
|
|
|
|
|
width += systemWidgetWidth + m_mainLayout->spacing();
|
|
|
|
|
}
|
|
|
|
|
width += m.left() + m.right();
|
|
|
|
|
return QSize(width, QWIDGETSIZE_MAX);
|
2022-05-12 17:09:10 +08:00
|
|
|
|
}
|
|
|
|
|
|
2022-11-30 11:13:45 +08:00
|
|
|
|
int height = appDatetimeSize(position);
|
|
|
|
|
int systemWidgetHeight = m_systemPluginWidget->suitableSize(position).height();
|
|
|
|
|
if (systemWidgetHeight > 0) {
|
|
|
|
|
height += systemWidgetHeight + m_mainLayout->spacing();
|
|
|
|
|
}
|
|
|
|
|
height += m.top() + m.bottom();
|
|
|
|
|
return QSize(QWIDGETSIZE_MAX, height);
|
2022-05-12 17:09:10 +08:00
|
|
|
|
}
|
|
|
|
|
|
2022-05-25 09:42:01 +08:00
|
|
|
|
// 用于返回需要绘制的圆形区域
|
|
|
|
|
QPainterPath TrayManagerWindow::roundedPaths()
|
|
|
|
|
{
|
|
|
|
|
QMargins mainMargin = m_mainLayout->contentsMargins();
|
2023-01-12 13:55:34 +08:00
|
|
|
|
int radius = pathRadius();
|
2022-05-25 09:42:01 +08:00
|
|
|
|
QPainterPath path;
|
2022-08-25 19:31:31 +00:00
|
|
|
|
if ((m_position == Dock::Position::Top || m_position == Dock::Position::Bottom)
|
|
|
|
|
&& m_singleShow) {
|
2022-05-25 09:42:01 +08:00
|
|
|
|
// 如果是上下方向,且只有一行
|
|
|
|
|
// 计算托盘和快捷插件区域
|
|
|
|
|
QPoint pointPlugin(mainMargin.left(), mainMargin.top());
|
|
|
|
|
QRect rctPlugin(QPoint(mainMargin.left(), mainMargin.top()), m_appPluginWidget->size());
|
|
|
|
|
path.addRoundedRect(rctPlugin, radius, radius);
|
|
|
|
|
|
|
|
|
|
// 计算日期时间区域
|
|
|
|
|
QPoint pointDateTime = m_dateTimeWidget->pos();
|
|
|
|
|
pointDateTime = m_dateTimeWidget->parentWidget()->mapTo(this, pointDateTime);
|
|
|
|
|
QRect rctDatetime(pointDateTime, m_dateTimeWidget->size());
|
|
|
|
|
path.addRoundedRect(rctDatetime, radius, radius);
|
|
|
|
|
// 计算系统插件区域
|
|
|
|
|
path.addRoundedRect(m_systemPluginWidget->geometry(), radius, radius);
|
|
|
|
|
} else {
|
|
|
|
|
// 添加系统插件区域的位置信息
|
|
|
|
|
path.addRoundedRect(m_appPluginDatetimeWidget->geometry(), radius, radius);
|
|
|
|
|
path.addRoundedRect(m_systemPluginWidget->geometry(), radius, radius);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return path;
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-02 06:57:46 +00:00
|
|
|
|
void TrayManagerWindow::onTrayCountChanged()
|
|
|
|
|
{
|
|
|
|
|
resetChildWidgetSize();
|
|
|
|
|
Q_EMIT requestUpdate();
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-09 16:46:07 +08:00
|
|
|
|
void TrayManagerWindow::updateHighlightArea(const QRect &rect)
|
|
|
|
|
{
|
|
|
|
|
do {
|
|
|
|
|
m_highlightArea.clear();
|
|
|
|
|
if (!rect.isValid())
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
auto widget = qobject_cast<QWidget *>(sender());
|
|
|
|
|
Q_ASSERT(widget);
|
|
|
|
|
|
|
|
|
|
QRect tmp = rect;
|
|
|
|
|
tmp.moveTopLeft(widget->mapTo(this, rect.topLeft()));
|
|
|
|
|
|
|
|
|
|
const auto radius = pathRadius();
|
|
|
|
|
m_highlightArea.addRoundedRect(tmp, radius, radius);
|
|
|
|
|
if (widget == m_dateTimeWidget) {
|
|
|
|
|
if (!m_singleShow) {
|
|
|
|
|
QPainterPath path;
|
|
|
|
|
if(m_position == Dock::Position::Top)
|
|
|
|
|
path.addRect(tmp.adjusted(0, radius, 0, 0));
|
|
|
|
|
else
|
|
|
|
|
path.addRect(tmp.adjusted(0, 0, 0, -radius));
|
|
|
|
|
|
|
|
|
|
m_highlightArea += path;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} while (false);
|
|
|
|
|
|
|
|
|
|
update();
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-12 17:09:10 +08:00
|
|
|
|
void TrayManagerWindow::resizeEvent(QResizeEvent *event)
|
|
|
|
|
{
|
|
|
|
|
Q_UNUSED(event);
|
|
|
|
|
|
2022-05-27 17:34:02 +08:00
|
|
|
|
updateLayout();
|
2022-05-12 17:09:10 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TrayManagerWindow::initUi()
|
|
|
|
|
{
|
2022-10-19 03:50:12 +00:00
|
|
|
|
m_systemPluginWidget->setDisplayMode(Dock::DisplayMode::Fashion);
|
2022-05-12 17:09:10 +08:00
|
|
|
|
m_trayView->setModel(m_model);
|
2022-05-17 20:57:09 +08:00
|
|
|
|
m_trayView->setItemDelegate(m_delegate);
|
|
|
|
|
m_trayView->setDragDistance(2);
|
|
|
|
|
|
|
|
|
|
m_splitLine->setFixedHeight(1);
|
|
|
|
|
QPalette pal;
|
|
|
|
|
QColor lineColor(Qt::black);
|
2022-05-25 09:42:01 +08:00
|
|
|
|
lineColor.setAlpha(static_cast<int>(255 * 0.1));
|
2023-03-22 20:11:24 +08:00
|
|
|
|
pal.setColor(QPalette::Window, lineColor);
|
2022-05-17 20:57:09 +08:00
|
|
|
|
m_splitLine->setAutoFillBackground(true);
|
|
|
|
|
m_splitLine->setPalette(pal);
|
2022-05-12 17:09:10 +08:00
|
|
|
|
|
|
|
|
|
// 左侧的区域,包括应用托盘插件和下方的日期时间区域
|
2022-05-17 20:57:09 +08:00
|
|
|
|
m_appPluginLayout->setContentsMargins(0, 0, 0, 0);
|
2022-05-12 17:09:10 +08:00
|
|
|
|
m_appPluginLayout->setSpacing(0);
|
|
|
|
|
m_appPluginWidget->setLayout(m_appPluginLayout);
|
|
|
|
|
m_appPluginLayout->addWidget(m_trayView);
|
|
|
|
|
m_appPluginLayout->addWidget(m_quickIconWidget);
|
|
|
|
|
|
|
|
|
|
setLayout(m_mainLayout);
|
2022-05-25 09:42:01 +08:00
|
|
|
|
// 通用情况下,设置边距和间距都为7
|
|
|
|
|
m_mainLayout->setContentsMargins(CONTENTSPACE, CONTENTSPACE, CONTENTSPACE, CONTENTSPACE);
|
|
|
|
|
m_mainLayout->setSpacing(CONTENTSPACE);
|
2022-05-12 17:09:10 +08:00
|
|
|
|
m_mainLayout->addWidget(m_appPluginDatetimeWidget);
|
|
|
|
|
m_mainLayout->addWidget(m_systemPluginWidget);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TrayManagerWindow::initConnection()
|
|
|
|
|
{
|
2022-11-02 06:57:46 +00:00
|
|
|
|
connect(m_model, &TrayModel::rowCountChanged, this, &TrayManagerWindow::onTrayCountChanged);
|
|
|
|
|
connect(m_model, &TrayModel::rowCountChanged, m_trayView, &TrayGridView::onUpdateEditorView);
|
|
|
|
|
connect(m_model, &TrayModel::requestRefreshEditor, m_trayView, &TrayGridView::onUpdateEditorView);
|
2022-05-12 17:09:10 +08:00
|
|
|
|
connect(m_quickIconWidget, &QuickPluginWindow::itemCountChanged, this, [ this ] {
|
2022-05-17 20:57:09 +08:00
|
|
|
|
// 当插件数量发生变化的时候,需要调整尺寸
|
2022-05-12 17:09:10 +08:00
|
|
|
|
m_quickIconWidget->setFixedSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX);
|
2022-08-25 19:31:31 +00:00
|
|
|
|
if (m_position == Dock::Position::Top || m_position == Dock::Position::Bottom)
|
2022-05-12 17:09:10 +08:00
|
|
|
|
m_quickIconWidget->setFixedWidth(m_quickIconWidget->suitableSize().width());
|
|
|
|
|
else
|
|
|
|
|
m_quickIconWidget->setFixedHeight(m_quickIconWidget->suitableSize().height());
|
|
|
|
|
|
2022-06-20 15:03:35 +08:00
|
|
|
|
Q_EMIT requestUpdate();
|
2022-05-12 17:09:10 +08:00
|
|
|
|
});
|
|
|
|
|
|
2022-06-20 15:03:35 +08:00
|
|
|
|
connect(m_systemPluginWidget, &SystemPluginWindow::itemChanged, this, [ this ] {
|
2022-08-25 19:31:31 +00:00
|
|
|
|
if (m_position == Dock::Position::Top || m_position == Dock::Position::Bottom)
|
2022-05-12 17:09:10 +08:00
|
|
|
|
m_systemPluginWidget->setFixedWidth(m_systemPluginWidget->suitableSize().width());
|
2023-04-18 10:18:55 +08:00
|
|
|
|
else
|
2022-05-12 17:09:10 +08:00
|
|
|
|
m_systemPluginWidget->setFixedHeight(m_systemPluginWidget->suitableSize().height());
|
|
|
|
|
|
2022-06-20 15:03:35 +08:00
|
|
|
|
Q_EMIT requestUpdate();
|
2022-05-12 17:09:10 +08:00
|
|
|
|
});
|
2023-03-09 16:46:07 +08:00
|
|
|
|
connect(m_systemPluginWidget, &SystemPluginWindow::requestDrawBackground, this, &TrayManagerWindow::updateHighlightArea);
|
2022-05-12 17:09:10 +08:00
|
|
|
|
|
2022-05-17 20:57:09 +08:00
|
|
|
|
connect(m_trayView, &TrayGridView::dragLeaved, m_delegate, [ this ]{
|
|
|
|
|
Q_EMIT m_delegate->requestDrag(true);
|
2022-05-12 17:09:10 +08:00
|
|
|
|
});
|
2022-11-09 11:03:59 +00:00
|
|
|
|
connect(m_trayView, &TrayGridView::dragFinished, this, [ this ] {
|
|
|
|
|
// 如果拖拽结束,则隐藏托盘
|
2022-05-17 20:57:09 +08:00
|
|
|
|
Q_EMIT m_delegate->requestDrag(false);
|
2022-05-12 17:09:10 +08:00
|
|
|
|
});
|
2022-11-09 11:03:59 +00:00
|
|
|
|
|
|
|
|
|
connect(m_model, &TrayModel::rowCountChanged, m_trayView, &TrayGridView::onUpdateEditorView);
|
2022-08-16 09:39:43 +00:00
|
|
|
|
connect(m_dateTimeWidget, &DateTimeDisplayer::requestUpdate, this, &TrayManagerWindow::requestUpdate);
|
2023-03-09 16:46:07 +08:00
|
|
|
|
connect(m_dateTimeWidget, &DateTimeDisplayer::requestDrawBackground, this, &TrayManagerWindow::updateHighlightArea);
|
2022-05-12 17:09:10 +08:00
|
|
|
|
|
|
|
|
|
m_trayView->installEventFilter(this);
|
|
|
|
|
m_quickIconWidget->installEventFilter(this);
|
|
|
|
|
installEventFilter(this);
|
2022-06-20 15:03:35 +08:00
|
|
|
|
QMetaObject::invokeMethod(this, &TrayManagerWindow::requestUpdate, Qt::QueuedConnection);
|
2023-06-07 14:11:50 +08:00
|
|
|
|
|
|
|
|
|
connect(DockSettings::instance() ,&DockSettings::windowSizeFashionChanged, this, [=](uint size) {
|
|
|
|
|
m_windowFashionSize = size;
|
|
|
|
|
});
|
2022-05-12 17:09:10 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TrayManagerWindow::resetChildWidgetSize()
|
|
|
|
|
{
|
2022-08-25 19:31:31 +00:00
|
|
|
|
switch (m_position) {
|
2022-05-12 17:09:10 +08:00
|
|
|
|
case Dock::Position::Top:
|
|
|
|
|
case Dock::Position::Bottom: {
|
2022-05-17 20:57:09 +08:00
|
|
|
|
int trayWidth = m_trayView->suitableSize().width();
|
2022-08-25 19:31:31 +00:00
|
|
|
|
int appDateTimeWidth = appDatetimeSize(m_position);
|
2022-05-12 17:09:10 +08:00
|
|
|
|
QMargins m = m_appPluginLayout->contentsMargins();
|
2022-08-25 19:31:31 +00:00
|
|
|
|
if (m_singleShow) {
|
2022-05-12 17:09:10 +08:00
|
|
|
|
// 单行显示
|
|
|
|
|
int trayHeight = m_appPluginDatetimeWidget->height() - m.top() - m.bottom();
|
|
|
|
|
m_trayView->setFixedSize(trayWidth, trayHeight);
|
|
|
|
|
m_quickIconWidget->setFixedSize(m_quickIconWidget->suitableSize().width(), trayHeight);
|
2022-05-17 20:57:09 +08:00
|
|
|
|
m_appPluginWidget->setFixedSize(trayWidth + m_quickIconWidget->suitableSize().width(), trayHeight);
|
2022-05-12 17:09:10 +08:00
|
|
|
|
m_dateTimeWidget->setFixedSize(m_dateTimeWidget->suitableSize().width(), trayHeight);
|
2022-05-19 17:04:02 +08:00
|
|
|
|
// 设置右侧的电源按钮的尺寸
|
2022-05-26 18:07:43 +08:00
|
|
|
|
m_systemPluginWidget->setFixedSize(m_systemPluginWidget->suitableSize());
|
2022-12-12 09:52:52 +00:00
|
|
|
|
m_mainLayout->setContentsMargins(SINGLEROWSPACE, SINGLEROWSPACE, SINGLEROWSPACE, SINGLEROWSPACE);
|
|
|
|
|
m_mainLayout->setSpacing(SINGLEROWSPACE);
|
2022-08-25 19:31:31 +00:00
|
|
|
|
// 单行显示需要重新设置插件和时间日期的位置,不显示分割线
|
|
|
|
|
m_splitLine->setVisible(false);
|
|
|
|
|
m_appPluginWidget->move(0, 0);
|
|
|
|
|
m_dateTimeWidget->move(m_appPluginWidget->x() + m_appPluginWidget->width() + 4, m_appPluginWidget->y());
|
2022-05-12 17:09:10 +08:00
|
|
|
|
} else {
|
|
|
|
|
// 多行显示
|
2022-08-25 19:31:31 +00:00
|
|
|
|
m_quickIconWidget->setFixedSize(m_quickIconWidget->suitableSize());
|
2022-05-26 18:07:43 +08:00
|
|
|
|
int trayHeight = m_appPluginDatetimeWidget->height() / 2 + 4 - m.top() - m.bottom();
|
|
|
|
|
m_trayView->setFixedSize(trayWidth, trayHeight);
|
2022-08-25 19:31:31 +00:00
|
|
|
|
m_appPluginWidget->setFixedSize(trayWidth + m_quickIconWidget->suitableSize().width(), trayHeight);
|
2022-05-17 20:57:09 +08:00
|
|
|
|
// 因为是两行,所以对于时间控件的尺寸,只能设置最小值
|
2022-05-25 09:44:29 +08:00
|
|
|
|
int dateTimeWidth = qMax(m_appPluginWidget->width(), m_dateTimeWidget->suitableSize().width());
|
2022-08-25 19:31:31 +00:00
|
|
|
|
int dateTimeHeight = m_appPluginDatetimeWidget->height() - - m.top() - m.bottom() - trayHeight;
|
|
|
|
|
m_dateTimeWidget->setFixedSize(dateTimeWidth, dateTimeHeight);
|
2022-05-26 18:07:43 +08:00
|
|
|
|
m_systemPluginWidget->setFixedSize(m_systemPluginWidget->suitableSize());
|
2023-06-07 14:11:50 +08:00
|
|
|
|
int contentSpace = qMin(MAXDIFF, qMax(((Utils::isDraging() ? height() : (int)m_windowFashionSize) - MINHIGHT), 0)) + MINSPACE;
|
2022-05-25 09:42:01 +08:00
|
|
|
|
m_mainLayout->setContentsMargins(contentSpace, contentSpace, contentSpace, contentSpace);
|
|
|
|
|
m_mainLayout->setSpacing(contentSpace);
|
2022-08-25 19:31:31 +00:00
|
|
|
|
|
|
|
|
|
// 调整插件和日期窗体的位置显示,这里没有用到布局,是因为在调整任务栏位置的时候,
|
|
|
|
|
// 随着布局方向的改变,显示有很大的问题
|
|
|
|
|
m_splitLine->setFixedWidth(appDateTimeWidth);
|
|
|
|
|
m_splitLine->setVisible(true);
|
|
|
|
|
if (m_position == Dock::Position::Bottom) {
|
|
|
|
|
m_appPluginWidget->move(0, 0);
|
|
|
|
|
m_splitLine->move(0, m_appPluginWidget->y() + m_appPluginWidget->height());
|
|
|
|
|
m_dateTimeWidget->move(0, m_appPluginWidget->y() + m_appPluginWidget->height() + m_splitLine->height());
|
|
|
|
|
} else {
|
|
|
|
|
m_dateTimeWidget->move(0, 0);
|
|
|
|
|
m_splitLine->move(0, m_dateTimeWidget->y() + m_dateTimeWidget->height());
|
|
|
|
|
m_appPluginWidget->move(0, m_dateTimeWidget->y() + m_dateTimeWidget->height() + m_splitLine->height());
|
|
|
|
|
}
|
2022-05-12 17:09:10 +08:00
|
|
|
|
}
|
2022-05-26 18:07:43 +08:00
|
|
|
|
QMargins margin = m_mainLayout->contentsMargins();
|
|
|
|
|
int appDateHeight = height() - margin.top() - margin.bottom();
|
2022-08-25 19:31:31 +00:00
|
|
|
|
m_appPluginDatetimeWidget->setFixedSize(appDateTimeWidth, appDateHeight);
|
2022-05-12 17:09:10 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case Dock::Position::Left:
|
|
|
|
|
case Dock::Position::Right: {
|
2022-05-17 20:57:09 +08:00
|
|
|
|
int trayHeight = m_trayView->suitableSize().height();
|
2022-05-12 17:09:10 +08:00
|
|
|
|
int quickAreaHeight = m_quickIconWidget->suitableSize().height();
|
|
|
|
|
QMargins m = m_appPluginLayout->contentsMargins();
|
2022-05-17 20:57:09 +08:00
|
|
|
|
// 左右方向始终只有一列
|
|
|
|
|
int datetimeHeight = m_dateTimeWidget->suitableSize().height();
|
|
|
|
|
int sizeWidth = m_appPluginDatetimeWidget->width() - m.left() - m.right();
|
|
|
|
|
m_trayView->setFixedSize(sizeWidth, trayHeight);
|
|
|
|
|
m_quickIconWidget->setFixedSize(sizeWidth, quickAreaHeight);
|
|
|
|
|
m_dateTimeWidget->setFixedSize(sizeWidth, datetimeHeight);
|
|
|
|
|
m_appPluginWidget->setFixedSize(sizeWidth, trayHeight + quickAreaHeight);
|
2022-05-26 18:07:43 +08:00
|
|
|
|
m_systemPluginWidget->setFixedSize(m_systemPluginWidget->suitableSize());
|
2022-05-25 09:42:01 +08:00
|
|
|
|
|
2023-06-07 14:11:50 +08:00
|
|
|
|
int contentSpace = (qMin(MAXDIFF, qMax((Utils::isDraging() ? width() : (int)m_windowFashionSize) - MINHIGHT, 0)) + MINSPACE);
|
2022-05-25 09:42:01 +08:00
|
|
|
|
m_mainLayout->setContentsMargins(contentSpace, contentSpace, contentSpace, contentSpace);
|
|
|
|
|
m_mainLayout->setSpacing(contentSpace);
|
2022-05-26 18:07:43 +08:00
|
|
|
|
|
|
|
|
|
int appDateWidth = width() - (contentSpace * 2);
|
2022-08-25 19:31:31 +00:00
|
|
|
|
m_appPluginDatetimeWidget->setFixedSize(appDateWidth, appDatetimeSize(m_position));
|
|
|
|
|
|
|
|
|
|
// 调整各个部件的位置
|
|
|
|
|
m_appPluginWidget->move(0, 0);
|
|
|
|
|
m_splitLine->setFixedWidth(width());
|
|
|
|
|
m_splitLine->setVisible(true);
|
|
|
|
|
m_splitLine->move(0, m_appPluginWidget->y() + m_appPluginWidget->height());
|
|
|
|
|
m_dateTimeWidget->move(0, m_appPluginWidget->y() + m_appPluginWidget->height() + m_splitLine->height());
|
2022-05-12 17:09:10 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TrayManagerWindow::resetSingleDirection()
|
|
|
|
|
{
|
2022-08-25 19:31:31 +00:00
|
|
|
|
switch (m_position) {
|
2022-05-17 20:57:09 +08:00
|
|
|
|
case Dock::Position::Top:
|
2022-05-12 17:09:10 +08:00
|
|
|
|
case Dock::Position::Bottom: {
|
|
|
|
|
m_appPluginLayout->setDirection(QBoxLayout::Direction::LeftToRight);
|
2022-05-17 20:57:09 +08:00
|
|
|
|
// 应用和时间在一行显示
|
2022-05-12 17:09:10 +08:00
|
|
|
|
m_mainLayout->setDirection(QBoxLayout::Direction::LeftToRight);
|
2022-05-25 09:42:01 +08:00
|
|
|
|
m_splitLine->hide();
|
2022-05-12 17:09:10 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
2022-05-17 20:57:09 +08:00
|
|
|
|
case Dock::Position::Left:
|
|
|
|
|
case Dock::Position::Right:{
|
2022-05-12 17:09:10 +08:00
|
|
|
|
m_appPluginLayout->setDirection(QBoxLayout::Direction::TopToBottom);
|
|
|
|
|
m_mainLayout->setDirection(QBoxLayout::Direction::TopToBottom);
|
2022-05-25 09:42:01 +08:00
|
|
|
|
m_splitLine->show();
|
2022-05-12 17:09:10 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-05-20 13:58:51 +08:00
|
|
|
|
m_dateTimeWidget->setOneRow(true);
|
2022-05-12 17:09:10 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TrayManagerWindow::resetMultiDirection()
|
|
|
|
|
{
|
2022-08-25 19:31:31 +00:00
|
|
|
|
switch (m_position) {
|
|
|
|
|
case Dock::Position::Top:
|
2022-05-12 17:09:10 +08:00
|
|
|
|
case Dock::Position::Bottom: {
|
|
|
|
|
m_appPluginLayout->setDirection(QBoxLayout::Direction::LeftToRight);
|
|
|
|
|
m_mainLayout->setDirection(QBoxLayout::Direction::LeftToRight);
|
2022-05-20 13:58:51 +08:00
|
|
|
|
m_splitLine->show();
|
|
|
|
|
m_dateTimeWidget->setOneRow(false);
|
2022-05-12 17:09:10 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
2022-05-17 20:57:09 +08:00
|
|
|
|
case Dock::Position::Left:
|
2022-05-12 17:09:10 +08:00
|
|
|
|
case Dock::Position::Right: {
|
|
|
|
|
m_appPluginLayout->setDirection(QBoxLayout::Direction::TopToBottom);
|
|
|
|
|
m_mainLayout->setDirection(QBoxLayout::Direction::TopToBottom);
|
2022-05-20 13:58:51 +08:00
|
|
|
|
m_splitLine->hide();
|
|
|
|
|
m_dateTimeWidget->setOneRow(true);
|
2022-05-12 17:09:10 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TrayManagerWindow::dragEnterEvent(QDragEnterEvent *e)
|
|
|
|
|
{
|
|
|
|
|
e->setDropAction(Qt::CopyAction);
|
|
|
|
|
e->accept();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TrayManagerWindow::dragMoveEvent(QDragMoveEvent *e)
|
|
|
|
|
{
|
|
|
|
|
e->setDropAction(Qt::CopyAction);
|
|
|
|
|
e->accept();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TrayManagerWindow::dropEvent(QDropEvent *e)
|
|
|
|
|
{
|
2022-07-15 18:14:29 +08:00
|
|
|
|
if (!e || !e->mimeData() || e->source() == this)
|
2022-05-12 17:09:10 +08:00
|
|
|
|
return;
|
|
|
|
|
|
2023-01-05 17:03:02 +08:00
|
|
|
|
if (m_quickIconWidget->isQuickWindow(e->source())) {
|
2022-07-15 18:14:29 +08:00
|
|
|
|
const QuickPluginMimeData *mimeData = qobject_cast<const QuickPluginMimeData *>(e->mimeData());
|
|
|
|
|
if (!mimeData)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
PluginsItemInterface *pluginItem = static_cast<PluginsItemInterface *>(mimeData->pluginItemInterface());
|
|
|
|
|
if (pluginItem)
|
|
|
|
|
m_quickIconWidget->dragPlugin(pluginItem);
|
|
|
|
|
} else if (qobject_cast<TrayGridView *>(e->source())) {
|
|
|
|
|
// 将trayView中的dropEvent扩大到整个区域(this),这样便于随意拖动到这个区域都可以捕获。
|
|
|
|
|
// m_trayView中有e->accept不会导致事件重复处理。
|
|
|
|
|
m_trayView->handleDropEvent(e);
|
|
|
|
|
}
|
2022-05-12 17:09:10 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TrayManagerWindow::dragLeaveEvent(QDragLeaveEvent *event)
|
|
|
|
|
{
|
|
|
|
|
event->accept();
|
|
|
|
|
}
|
2022-05-25 09:42:01 +08:00
|
|
|
|
|
|
|
|
|
void TrayManagerWindow::paintEvent(QPaintEvent *event)
|
|
|
|
|
{
|
|
|
|
|
Q_UNUSED(event);
|
|
|
|
|
QPainterPath path = roundedPaths();
|
|
|
|
|
QPainter painter(this);
|
|
|
|
|
painter.save();
|
|
|
|
|
painter.setRenderHint(QPainter::Antialiasing);
|
|
|
|
|
painter.setClipPath(path);
|
|
|
|
|
painter.fillRect(rect().adjusted(1, 1, -1, -1), maskColor(102));
|
|
|
|
|
painter.setPen(maskColor(110));
|
|
|
|
|
painter.drawPath(path);
|
|
|
|
|
painter.restore();
|
2023-03-09 16:46:07 +08:00
|
|
|
|
|
|
|
|
|
// draw highlight background for special path.
|
|
|
|
|
if (!m_highlightArea.isEmpty()) {
|
|
|
|
|
painter.save();
|
|
|
|
|
QColor backColor = DGuiApplicationHelper::ColorType::DarkType == DGuiApplicationHelper::instance()->themeType() ? QColor(20, 20, 20) : Qt::white;
|
|
|
|
|
backColor.setAlphaF(0.2);
|
|
|
|
|
painter.setPen(Qt::NoPen);
|
|
|
|
|
painter.setBrush(backColor);
|
|
|
|
|
painter.drawPath(m_highlightArea);
|
|
|
|
|
painter.restore();
|
|
|
|
|
}
|
2022-05-25 09:42:01 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QColor TrayManagerWindow::maskColor(uint8_t alpha) const
|
|
|
|
|
{
|
|
|
|
|
QColor color = DGuiApplicationHelper::standardPalette(DGuiApplicationHelper::instance()->themeType()).window().color();
|
|
|
|
|
color.setAlpha(alpha);
|
|
|
|
|
return color;
|
|
|
|
|
}
|