From 54bbb1b0bb4ecea249c08db06118e35b727eb935 Mon Sep 17 00:00:00 2001 From: chenjun Date: Mon, 6 Sep 2021 08:43:22 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=B0=83=E6=95=B4=E6=8F=92=E4=BB=B6?= =?UTF-8?q?=E5=9B=BE=E6=A0=87=E5=A4=A7=E5=B0=8F=E8=AE=A1=E7=AE=97=E6=96=B9?= =?UTF-8?q?=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 在计算图标大小时,已经计算过插件图标的大小,然后再计算应用图标的大小,不能再根据图标大小计算插件图标大小,会造成反复计算后插件图标大小不准确,插 件区域尺寸重复调整 Log: 修复任务栏高度快速变化后没有自动调整控件大小的问题 Change-Id: I51d4967f129609c4944080d51e4f06b0077d90c2 Bug: https://pms.uniontech.com/zentao/bug-view-88133.html --- frame/window/mainpanelcontrol.cpp | 50 ++++++++++++++++--------------- frame/window/mainpanelcontrol.h | 2 +- 2 files changed, 27 insertions(+), 25 deletions(-) diff --git a/frame/window/mainpanelcontrol.cpp b/frame/window/mainpanelcontrol.cpp index 7e1496a36..b12a0b1fd 100755 --- a/frame/window/mainpanelcontrol.cpp +++ b/frame/window/mainpanelcontrol.cpp @@ -85,6 +85,7 @@ MainPanelControl::MainPanelControl(QWidget *parent) m_appAreaSonWidget->installEventFilter(this); m_trayAreaWidget->installEventFilter(this); m_desktopWidget->installEventFilter(this); + m_pluginAreaWidget->installEventFilter(this); //在设置每条线大小前,应该设置fixedsize(0,0) //应为paintEvent函数会先调用设置背景颜色,大小为随机值 @@ -632,6 +633,17 @@ bool MainPanelControl::eventFilter(QObject *watched, QEvent *event) } } + // fix:88133 在计算icon大小时m_pluginAreaWidget的数据错误 + if (watched == m_pluginAreaWidget) { + switch (event->type()) { + case QEvent::Resize: + resizeDockIcon(); + break; + default: + break; + } + } + // 高效模式下,鼠标移入移出'显示桌面'区域的处理 if (watched == m_desktopWidget) { if (event->type() == QEvent::Enter) { @@ -1074,6 +1086,10 @@ void MainPanelControl::resizeDockIcon() tray_item_size = qMin(tray_item_size,width()); tray_item_size = std::min(tray_item_size, width() - 20); } + + if (tray_item_size < 20) + tray_item_size = 20; + //减去插件图标的大小后重新计算固定图标和应用图标的平均大小 totalLength -= tray_item_size * pluginCount; iconCount -= pluginCount; @@ -1084,20 +1100,20 @@ void MainPanelControl::resizeDockIcon() if ((m_position == Position::Top) || (m_position == Position::Bottom)) { if (iconSize >= height()) { - calcuDockIconSize(height(), height(), trashPlugin, shutdownPlugin, keyboardPlugin, notificationPlugin); + calcuDockIconSize(height(), height(), tray_item_size, trashPlugin, shutdownPlugin, keyboardPlugin, notificationPlugin); } else { - calcuDockIconSize(iconSize, height(), trashPlugin, shutdownPlugin, keyboardPlugin, notificationPlugin); + calcuDockIconSize(iconSize, height(), tray_item_size, trashPlugin, shutdownPlugin, keyboardPlugin, notificationPlugin); } } else { if (iconSize >= width()) { - calcuDockIconSize(width(), width(), trashPlugin, shutdownPlugin, keyboardPlugin, notificationPlugin); + calcuDockIconSize(width(), width(), tray_item_size, trashPlugin, shutdownPlugin, keyboardPlugin, notificationPlugin); } else { - calcuDockIconSize(width(), iconSize, trashPlugin, shutdownPlugin, keyboardPlugin, notificationPlugin); + calcuDockIconSize(width(), iconSize, tray_item_size, trashPlugin, shutdownPlugin, keyboardPlugin, notificationPlugin); } } } -void MainPanelControl::calcuDockIconSize(int w, int h, PluginsItem *trashPlugin, PluginsItem *shutdownPlugin, PluginsItem *keyboardPlugin, PluginsItem *notificationPlugin) +void MainPanelControl::calcuDockIconSize(int w, int h, int traySize, PluginsItem *trashPlugin, PluginsItem *shutdownPlugin, PluginsItem *keyboardPlugin, PluginsItem *notificationPlugin) { int appItemSize = qMin(w, h); @@ -1119,22 +1135,8 @@ void MainPanelControl::calcuDockIconSize(int w, int h, PluginsItem *trashPlugin, m_appAreaSonLayout->itemAt(i)->widget()->setFixedSize(appItemSize, appItemSize); } - // 托盘上每个图标大小 - 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; - if (m_tray) { - m_tray->centralWidget()->setProperty("iconSize", tray_item_size); + m_tray->centralWidget()->setProperty("iconSize", traySize); } //因为日期时间大小和其他插件大小有异,为了设置边距,在各插件中增加了一层布局 @@ -1147,7 +1149,7 @@ void MainPanelControl::calcuDockIconSize(int w, int h, PluginsItem *trashPlugin, PluginsItem *pItem = static_cast(layout->itemAt(0)->widget()); if (pItem) { if (pItem->sizeHint().height() == -1) { - pItem->setFixedSize(tray_item_size, tray_item_size); + pItem->setFixedSize(traySize, traySize); } else if (pItem->sizeHint().height() > height()) { pItem->resize(pItem->width(), height()); } @@ -1162,7 +1164,7 @@ void MainPanelControl::calcuDockIconSize(int w, int h, PluginsItem *trashPlugin, PluginsItem *pItem = static_cast(layout->itemAt(0)->widget()); if (pItem) { if (pItem->sizeHint().width() == -1) { - pItem->setFixedSize(tray_item_size, tray_item_size); + pItem->setFixedSize(traySize, traySize); } else if (pItem->sizeHint().width() > width()) { pItem->resize(width(), pItem->height()); } @@ -1179,10 +1181,10 @@ void MainPanelControl::calcuDockIconSize(int w, int h, PluginsItem *trashPlugin, if ((m_position == Position::Top) || (m_position == Position::Bottom)) { appTopAndBottomMargin = (m_fixedAreaWidget->height() - appItemSize) / 2; - trayTopAndBottomMargin = (m_trayAreaWidget->height() - tray_item_size) / 2; + trayTopAndBottomMargin = (m_trayAreaWidget->height() - traySize) / 2; } else { appLeftAndRightMargin = (m_fixedAreaWidget->width() - appItemSize) / 2; - trayLeftAndRightMargin = (m_trayAreaWidget->width() - tray_item_size) / 2; + trayLeftAndRightMargin = (m_trayAreaWidget->width() - traySize) / 2; } m_fixedAreaLayout->setContentsMargins(appLeftAndRightMargin, appTopAndBottomMargin, appLeftAndRightMargin, appTopAndBottomMargin); diff --git a/frame/window/mainpanelcontrol.h b/frame/window/mainpanelcontrol.h index 4d485a58a..f02fb314b 100755 --- a/frame/window/mainpanelcontrol.h +++ b/frame/window/mainpanelcontrol.h @@ -100,7 +100,7 @@ private: void handleDragMove(QDragMoveEvent *e, bool isFilter); void paintEvent(QPaintEvent *event) override; void resizeDockIcon(); - void calcuDockIconSize(int w, int h, PluginsItem *trashPlugin, PluginsItem *shutdownPlugin, PluginsItem *keyboardPlugin, PluginsItem *notificationPlugin); + void calcuDockIconSize(int w, int h, int traySize, PluginsItem *trashPlugin, PluginsItem *shutdownPlugin, PluginsItem *keyboardPlugin, PluginsItem *notificationPlugin); void resizeDesktopWidget(); bool checkNeedShowDesktop(); bool appIsOnDock(const QString &appDesktop);