diff --git a/frame/util/multiscreenworker.cpp b/frame/util/multiscreenworker.cpp index 526bf25d7..cce24dea7 100644 --- a/frame/util/multiscreenworker.cpp +++ b/frame/util/multiscreenworker.cpp @@ -935,7 +935,7 @@ void MultiScreenWorker::initConnection() connect(qApp, &QApplication::primaryScreenChanged, this, &MultiScreenWorker::primaryScreenChanged); connect(DIS_INS, &DisplayManager::primaryScreenChanged, this, &MultiScreenWorker::primaryScreenChanged); connect(DIS_INS, &DisplayManager::screenInfoChanged, this, &MultiScreenWorker::requestUpdateMonitorInfo); - connect(parent()->panel(), &MainPanelControl::sizeChanged, this, &MultiScreenWorker::onChildSizeChanged); + connect(parent()->panel(), &MainPanelControl::requestUpdate, this, &MultiScreenWorker::onChildSizeChanged); connect(m_launcherInter, static_cast(&DBusLuncher::VisibleChanged), this, [ = ](bool value) { setStates(LauncherDisplay, value); }); diff --git a/frame/window/mainpanelcontrol.cpp b/frame/window/mainpanelcontrol.cpp index 68e72bd63..04c3d4415 100755 --- a/frame/window/mainpanelcontrol.cpp +++ b/frame/window/mainpanelcontrol.cpp @@ -96,6 +96,7 @@ MainPanelControl::MainPanelControl(QWidget *parent) , m_dockScreen(nullptr) { initUI(); + initConnection(); updateMainPanelLayout(); updateModeChange(); setAcceptDrops(true); @@ -153,20 +154,9 @@ void MainPanelControl::initUI() m_pluginLayout->setContentsMargins(0, 0, 0, 0); m_mainPanelLayout->addWidget(m_pluginAreaWidget, 0, Qt::AlignCenter); - m_mainPanelLayout->addSpacing(15); m_mainPanelLayout->addWidget(m_trayManagerWidget); - connect(m_trayManagerWidget, &TrayManagerWindow::sizeChanged, this, [ this ] { - QSize suitableSize = m_trayManagerWidget->suitableSize(); - if (m_position == Position::Right || m_position == Position::Left) - m_trayManagerWidget->setFixedSize(width(), suitableSize.height()); - else - m_trayManagerWidget->setFixedSize(suitableSize.width(), height()); - - Q_EMIT sizeChanged(); - }); - /* 桌面预览 */ m_desktopWidget->setObjectName("showdesktoparea"); m_mainPanelLayout->addWidget(m_desktopWidget); @@ -178,6 +168,11 @@ void MainPanelControl::initUI() m_mainPanelLayout->setAlignment(m_traySpliter, Qt::AlignCenter); } +void MainPanelControl::initConnection() +{ + connect(m_trayManagerWidget, &TrayManagerWindow::requestUpdate, this, &MainPanelControl::onRequestUpdate); +} + /** * @brief MainPanelControl::setDisplayMode 根据任务栏显示模式更新界面显示,如果是时尚模式,没有‘显示桌面'区域,否则就有 * @param dislayMode 任务栏显示模式 @@ -249,7 +244,7 @@ void MainPanelControl::addFixedAreaItem(int index, QWidget *wdg) wdg->setMaximumSize(width(),width()); } m_fixedAreaLayout->insertWidget(index, wdg); - Q_EMIT sizeChanged(); + Q_EMIT requestUpdate(); } /**往应用区域添加应用 @@ -265,7 +260,7 @@ void MainPanelControl::addAppAreaItem(int index, QWidget *wdg) wdg->setMaximumSize(width(),width()); } m_appAreaSonLayout->insertWidget(index, wdg); - Q_EMIT sizeChanged(); + Q_EMIT requestUpdate(); } /**往托盘插件区域添加应用 @@ -307,7 +302,7 @@ void MainPanelControl::addPluginAreaItem(int index, QWidget *wdg) void MainPanelControl::removeFixedAreaItem(QWidget *wdg) { m_fixedAreaLayout->removeWidget(wdg); - Q_EMIT sizeChanged(); + Q_EMIT requestUpdate(); } /**移除应用区域某一应用 @@ -317,7 +312,7 @@ void MainPanelControl::removeFixedAreaItem(QWidget *wdg) void MainPanelControl::removeAppAreaItem(QWidget *wdg) { m_appAreaSonLayout->removeWidget(wdg); - Q_EMIT sizeChanged(); + Q_EMIT requestUpdate(); } /**移除托盘插件区域某一应用 @@ -1054,19 +1049,24 @@ QSize MainPanelControl::suitableSize(int screenSize, double deviceRatio) const return QSize(width(), static_cast((traySuitableSize.height() + 20) / ratio)); } - int yu = (totalLength % iconCount); + int redundantLength = (totalLength % iconCount); // icon宽度 = (总宽度-余数)/icon个数 - int iconSize = (totalLength - yu) / iconCount; + int iconSize = (totalLength - redundantLength) / iconCount; if (m_position == Position::Top || m_position == Position::Bottom) { iconSize = iconSize < height() ? iconSize : height(); - return QSize(iconSize * iconCount + static_cast((m_fixedSpliter->width() + traySuitableSize.width() + 20) / ratio), - static_cast(height() / ratio)); + int panelWidth = qMin(iconSize * iconCount + static_cast((m_fixedSpliter->width() + traySuitableSize.width() + 20) / ratio), + static_cast(screenSize / deviceRatio)); + + return QSize(panelWidth, static_cast(height() / ratio)); } iconSize = iconSize < width() ? iconSize : width(); - return QSize(width(), iconSize * iconCount + static_cast((m_fixedSpliter->height() + traySuitableSize.height() + 20) / ratio)); + int panelHeight = qMin(iconSize * iconCount + static_cast((m_fixedSpliter->height() + traySuitableSize.height() + 20) / ratio), + static_cast(screenSize / deviceRatio)); + + return QSize(width(), panelHeight); } void MainPanelControl::itemUpdated(DockItem *item) @@ -1128,8 +1128,9 @@ void MainPanelControl::resizeDockIcon() // 总宽度 if (m_dislayMode == DisplayMode::Fashion) { int totalLength = getScreenSize(); + QSize trayManagerSize = m_trayManagerWidget->suitableSize(); // 减去右侧托盘和插件区域的宽度 - totalLength -= ((m_position == Position::Top) || (m_position == Position::Bottom)) ? m_trayManagerWidget->width() : m_trayManagerWidget->height(); + totalLength -= ((m_position == Position::Top) || (m_position == Position::Bottom)) ? trayManagerSize.width() : trayManagerSize.height(); iconCount = m_fixedAreaLayout->count() + m_appAreaSonLayout->count(); @@ -1140,7 +1141,6 @@ void MainPanelControl::resizeDockIcon() int yu = (totalLength % iconCount); // icon宽度 = (总宽度-余数)/icon个数 iconSize = (totalLength - yu) / iconCount; - // 计算插件图标的最大或最小值 tray_item_size = qBound(20, iconSize, 40); if ((m_position == Position::Top) || (m_position == Position::Bottom)) { @@ -1344,6 +1344,14 @@ void MainPanelControl::calcuDockIconSize(int w, int h, int traySize) } } +void MainPanelControl::onRequestUpdate() +{ + resizeDesktopWidget(); + // 在插件区域界面发生变化后(新增插件、删除插件、时间长度变化,新增托盘等),会触发当前的信号,此时当前类 + // 的尺寸还未变化,因此在此处发送requestUpdate信号,通知外面来调整任务栏右侧的大小,同时计算整个任务栏的大小 + Q_EMIT requestUpdate(); +} + /**时尚模式没有‘显示桌面’区域 * @brief MainPanelControl::resizeDesktopWidget */ diff --git a/frame/window/mainpanelcontrol.h b/frame/window/mainpanelcontrol.h index 3e06cb6dc..a525ab008 100755 --- a/frame/window/mainpanelcontrol.h +++ b/frame/window/mainpanelcontrol.h @@ -64,10 +64,11 @@ public slots: signals: void itemMoved(DockItem *sourceItem, DockItem *targetItem); void itemAdded(const QString &appDesktop, int idx); - void sizeChanged(); + void requestUpdate(); private: void initUI(); + void initConnection(); void updateAppAreaSonWidgetSize(); void updateMainPanelLayout(); void updateDisplayMode(); @@ -95,6 +96,9 @@ private: bool appIsOnDock(const QString &appDesktop); void resetRadius(); +private Q_SLOTS: + void onRequestUpdate(); + protected: void dragMoveEvent(QDragMoveEvent *e) override; void dragEnterEvent(QDragEnterEvent *e) override; diff --git a/frame/window/mainwindow.cpp b/frame/window/mainwindow.cpp index 21453c119..9b2f764a3 100755 --- a/frame/window/mainwindow.cpp +++ b/frame/window/mainwindow.cpp @@ -317,7 +317,7 @@ void MainWindow::initConnections() connect(m_wmHelper, &DWindowManagerHelper::hasCompositeChanged, m_shadowMaskOptimizeTimer, static_cast(&QTimer::start)); connect(&m_platformWindowHandle, &DPlatformWindowHandle::frameMarginsChanged, m_shadowMaskOptimizeTimer, static_cast(&QTimer::start)); connect(&m_platformWindowHandle, &DPlatformWindowHandle::windowRadiusChanged, m_shadowMaskOptimizeTimer, static_cast(&QTimer::start)); - connect(m_mainPanel, &MainPanelControl::sizeChanged, m_shadowMaskOptimizeTimer, static_cast(&QTimer::start)); + connect(m_mainPanel, &MainPanelControl::requestUpdate, m_shadowMaskOptimizeTimer, static_cast(&QTimer::start)); connect(m_dbusDaemonInterface, &QDBusConnectionInterface::serviceOwnerChanged, this, &MainWindow::onDbusNameOwnerChanged); diff --git a/frame/window/systempluginwindow.cpp b/frame/window/systempluginwindow.cpp index 1a368fcc1..3128375ba 100644 --- a/frame/window/systempluginwindow.cpp +++ b/frame/window/systempluginwindow.cpp @@ -116,7 +116,7 @@ void SystemPluginWindow::onPluginItemAdded(StretchPluginsItem *pluginItem) pluginItem->setParent(this); pluginItem->show(); m_mainLayout->addWidget(pluginItem); - Q_EMIT sizeChanged(); + Q_EMIT itemChanged(); } void SystemPluginWindow::onPluginItemRemoved(StretchPluginsItem *pluginItem) @@ -127,7 +127,7 @@ void SystemPluginWindow::onPluginItemRemoved(StretchPluginsItem *pluginItem) pluginItem->setParent(nullptr); pluginItem->hide(); m_mainLayout->removeWidget(pluginItem); - Q_EMIT sizeChanged(); + Q_EMIT itemChanged(); } void SystemPluginWindow::onPluginItemUpdated(StretchPluginsItem *pluginItem) diff --git a/frame/window/systempluginwindow.h b/frame/window/systempluginwindow.h index 15d814d36..184b1f46f 100644 --- a/frame/window/systempluginwindow.h +++ b/frame/window/systempluginwindow.h @@ -45,7 +45,7 @@ public: QSize suitableSize(); Q_SIGNALS: - void sizeChanged(); + void itemChanged(); private: void initUi(); diff --git a/frame/window/traymanagerwindow.cpp b/frame/window/traymanagerwindow.cpp index fa14c1d9c..74753e397 100644 --- a/frame/window/traymanagerwindow.cpp +++ b/frame/window/traymanagerwindow.cpp @@ -82,6 +82,8 @@ void TrayManagerWindow::updateLayout() if (m_postion == Dock::Position::Top || m_postion == Dock::Position::Bottom) showSingle = (topLevelWidget()->height() <= CRITLCALHEIGHT); + QBoxLayout::Direction lastDirection = m_appDatetimeLayout->direction(); + if (showSingle) resetSingleDirection(); else @@ -90,6 +92,10 @@ void TrayManagerWindow::updateLayout() resetChildWidgetSize(); // 当尺寸发生变化的时候,通知托盘区域刷新尺寸,让托盘图标始终保持居中显示 Q_EMIT m_delegate->sizeHintChanged(m_model->index(0, 0)); + + // 当插件区域从单行变成两行或者两行变成单行的时候,发送该信号,通知外部重新调整区域大小 + if (lastDirection != m_appDatetimeLayout->direction()) + Q_EMIT requestUpdate(); } void TrayManagerWindow::setPositon(Dock::Position position) @@ -237,11 +243,11 @@ void TrayManagerWindow::initConnection() // 在加载界面的时候,会出现快捷设置区域的图标和左侧的托盘图标挤在一起(具体原因未知),此时需要延时50毫秒重新刷新界面来保证界面布局正常(临时解决方案) QTimer::singleShot(50, this, [ this ] { resetChildWidgetSize(); - Q_EMIT sizeChanged(); + Q_EMIT requestUpdate(); }); } else { resetChildWidgetSize(); - Q_EMIT sizeChanged(); + Q_EMIT requestUpdate(); } }); connect(m_quickIconWidget, &QuickPluginWindow::itemCountChanged, this, [ this ] { @@ -252,10 +258,10 @@ void TrayManagerWindow::initConnection() else m_quickIconWidget->setFixedHeight(m_quickIconWidget->suitableSize().height()); - Q_EMIT sizeChanged(); + Q_EMIT requestUpdate(); }); - connect(m_systemPluginWidget, &SystemPluginWindow::sizeChanged, this, [ this ] { + connect(m_systemPluginWidget, &SystemPluginWindow::itemChanged, this, [ this ] { // 当系统插件发生变化的时候,同样需要调整尺寸 m_systemPluginWidget->setFixedSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX); if (m_postion == Dock::Position::Top || m_postion == Dock::Position::Bottom) @@ -263,13 +269,13 @@ void TrayManagerWindow::initConnection() else m_systemPluginWidget->setFixedHeight(m_systemPluginWidget->suitableSize().height()); - Q_EMIT sizeChanged(); + Q_EMIT requestUpdate(); }); connect(m_delegate, &TrayDelegate::visibleChanged, this, [ this ](const QModelIndex &index, bool visible) { m_trayView->setRowHidden(index.row(), !visible); resetChildWidgetSize(); - Q_EMIT sizeChanged(); + Q_EMIT requestUpdate(); }); connect(m_trayView, &TrayGridView::dragLeaved, m_delegate, [ this ]{ @@ -288,12 +294,12 @@ void TrayManagerWindow::initConnection() } } }); - connect(m_dateTimeWidget, &DateTimeDisplayer::sizeChanged, this, &TrayManagerWindow::sizeChanged); + connect(m_dateTimeWidget, &DateTimeDisplayer::sizeChanged, this, &TrayManagerWindow::requestUpdate); m_trayView->installEventFilter(this); m_quickIconWidget->installEventFilter(this); installEventFilter(this); - QMetaObject::invokeMethod(this, &TrayManagerWindow::sizeChanged, Qt::QueuedConnection); + QMetaObject::invokeMethod(this, &TrayManagerWindow::requestUpdate, Qt::QueuedConnection); } void TrayManagerWindow::resetChildWidgetSize() diff --git a/frame/window/traymanagerwindow.h b/frame/window/traymanagerwindow.h index 554acd4f7..20650a3ed 100644 --- a/frame/window/traymanagerwindow.h +++ b/frame/window/traymanagerwindow.h @@ -57,7 +57,7 @@ public: QSize suitableSize(); Q_SIGNALS: - void sizeChanged(); + void requestUpdate(); protected: void resizeEvent(QResizeEvent *event) override;