From 1212175e55cf56d09d9a58660faba621d79a154e Mon Sep 17 00:00:00 2001 From: wangxuwen Date: Mon, 6 Jan 2020 14:27:22 +0800 Subject: [PATCH] feat(dde-dock): change the plugins logic for task 13189 --- frame/panel/mainpanelcontrol.cpp | 72 +++++++++++++++++++------------- frame/panel/mainpanelcontrol.h | 2 +- 2 files changed, 43 insertions(+), 31 deletions(-) diff --git a/frame/panel/mainpanelcontrol.cpp b/frame/panel/mainpanelcontrol.cpp index a9fc39f6f..e521cee95 100755 --- a/frame/panel/mainpanelcontrol.cpp +++ b/frame/panel/mainpanelcontrol.cpp @@ -777,16 +777,18 @@ void MainPanelControl::resizeDockIcon() // 插件有点特殊,因为会引入第三方的插件,并不会受dock的缩放影响,我们只能限制我们自己的插件,否则会导致显示错误。 // 以下是受控制的插件 PluginsItem *trashPlugin = nullptr; - PluginsItem *shutdownPlugin = nullptr; - PluginsItem *keyboardPlugin = nullptr; + int pluginTotalWidth = 0; + int pluginTotalHeight = 0; + int count = 0; //计算除时间和垃圾箱之外的插件个数 for (int i = 0; i < m_pluginLayout->count(); ++ i) { PluginsItem *w = static_cast(m_pluginLayout->itemAt(i)->widget()); if (w->pluginName() == "trash") { trashPlugin = w; - } else if (w->pluginName() == "shutdown") { - shutdownPlugin = w; - } else if (w->pluginName() == "onboard") { - keyboardPlugin = w; + } else if (w->pluginName() == "datetime") { + } else { + pluginTotalWidth += w->width(); + pluginTotalHeight += w->height(); + count++; } } @@ -803,14 +805,12 @@ void MainPanelControl::resizeDockIcon() if ((m_position == Position::Top) || (m_position == Position::Bottom)) { totalLength -= m_pluginAreaWidget->width(); if (trashPlugin) totalLength += trashPlugin->width(); - if (shutdownPlugin) totalLength += shutdownPlugin->width(); - if (keyboardPlugin) totalLength += keyboardPlugin->width(); + totalLength += pluginTotalWidth; totalLength -= m_desktopWidget->width(); } else { totalLength -= m_pluginAreaWidget->height(); if (trashPlugin) totalLength += trashPlugin->height(); - if (shutdownPlugin) totalLength += shutdownPlugin->height(); - if (keyboardPlugin) totalLength += keyboardPlugin->height(); + totalLength += pluginTotalHeight; totalLength -= m_desktopWidget->height(); } @@ -818,7 +818,7 @@ void MainPanelControl::resizeDockIcon() return; // 参与计算的插件的个数(包含托盘和插件,垃圾桶,关机,屏幕键盘) - int pluginCount = m_tray->trayVisableItemCount() + (trashPlugin ? 1 : 0) + (shutdownPlugin ? 1 : 0) + (keyboardPlugin ? 1 : 0); + int pluginCount = m_tray->trayVisableItemCount() + (trashPlugin ? 1 : 0) + count; // icon个数 int iconCount = m_fixedAreaLayout->count() + m_appAreaSonLayout->count() + pluginCount; @@ -848,20 +848,20 @@ void MainPanelControl::resizeDockIcon() if ((m_position == Position::Top) || (m_position == Position::Bottom)) { if (iconSize >= height()) { - calcuDockIconSize(height(), height(), trashPlugin, shutdownPlugin, keyboardPlugin); + calcuDockIconSize(height(), height()); } else { - calcuDockIconSize(iconSize, height(), trashPlugin, shutdownPlugin, keyboardPlugin); + calcuDockIconSize(iconSize, height()); } } else { if (iconSize >= width()) { - calcuDockIconSize(width(), width(), trashPlugin, shutdownPlugin, keyboardPlugin); + calcuDockIconSize(width(), width()); } else { - calcuDockIconSize(width(), iconSize, trashPlugin, shutdownPlugin, keyboardPlugin); + calcuDockIconSize(width(), iconSize); } } } -void MainPanelControl::calcuDockIconSize(int w, int h, PluginsItem *trashPlugin, PluginsItem *shutdownPlugin, PluginsItem *keyboardPlugin) +void MainPanelControl::calcuDockIconSize(int w, int h) { for (int i = 0; i < m_fixedAreaLayout->count(); ++ i) { m_fixedAreaLayout->itemAt(i)->widget()->setFixedSize(w, h); @@ -871,9 +871,14 @@ void MainPanelControl::calcuDockIconSize(int w, int h, PluginsItem *trashPlugin, m_fixedSpliter->setFixedSize(SPLITER_SIZE, int(w * 0.6)); m_appSpliter->setFixedSize(SPLITER_SIZE, int(w * 0.6)); m_traySpliter->setFixedSize(SPLITER_SIZE, int(w * 0.5)); + // 垃圾桶 - if (trashPlugin) - trashPlugin->setFixedSize(std::min(w, h - 20), h - 20); + for (int i = 0; i < m_pluginLayout->count(); ++ i) { + PluginsItem *pluginItem = static_cast(m_pluginLayout->itemAt(i)->widget()); + if (pluginItem->pluginName() == "trash"){ + pluginItem->setFixedSize(std::min(w, h - 20), h - 20); + } + } for (int i = 0; i < m_appAreaSonLayout->count(); ++ i) { m_appAreaSonLayout->itemAt(i)->widget()->setMaximumWidth(h); @@ -884,10 +889,14 @@ void MainPanelControl::calcuDockIconSize(int w, int h, PluginsItem *trashPlugin, m_fixedSpliter->setFixedSize(int(h * 0.6), SPLITER_SIZE); m_appSpliter->setFixedSize(int(h * 0.6), SPLITER_SIZE); m_traySpliter->setFixedSize(int(h * 0.5), SPLITER_SIZE); - // 垃圾桶 - if (trashPlugin) - trashPlugin->setFixedSize(w - 20, std::min(w - 20, h)); + // 垃圾桶 + for (int i = 0; i < m_pluginLayout->count(); ++ i) { + PluginsItem *pluginItem = static_cast(m_pluginLayout->itemAt(i)->widget()); + if (pluginItem->pluginName() == "trash"){ + pluginItem->setFixedSize(w - 20, std::min(w - 20, h)); + } + } for (int i = 0; i < m_appAreaSonLayout->count(); ++ i) { m_appAreaSonLayout->itemAt(i)->widget()->setMaximumHeight(w); @@ -915,17 +924,20 @@ void MainPanelControl::calcuDockIconSize(int w, int h, PluginsItem *trashPlugin, m_tray->centralWidget()->setProperty("iconSize", tray_item_size); // 插件 - if (shutdownPlugin) - shutdownPlugin->setFixedSize(tray_item_size, h - 20); - if (keyboardPlugin) - keyboardPlugin->setFixedSize(tray_item_size, h - 20); + for (int i = 0; i < m_pluginLayout->count(); ++ i) { + PluginsItem *pluginItem = static_cast(m_pluginLayout->itemAt(i)->widget()); + if (pluginItem->pluginName() != "trash" && pluginItem->pluginName() != "datetime"){ + pluginItem->setFixedSize(tray_item_size, h - 20); + } + } } else { m_tray->centralWidget()->setProperty("iconSize", tray_item_size); - - if (shutdownPlugin) - shutdownPlugin->setFixedSize(w - 20, tray_item_size); - if (keyboardPlugin) - keyboardPlugin->setFixedSize(w - 20, tray_item_size); + for (int i = 0; i < m_pluginLayout->count(); ++ i) { + PluginsItem *pluginItem = static_cast(m_pluginLayout->itemAt(i)->widget()); + if (pluginItem->pluginName() != "trash" && pluginItem->pluginName() != "datetime"){ + pluginItem->setFixedSize(w - 20, tray_item_size); + } + } } } diff --git a/frame/panel/mainpanelcontrol.h b/frame/panel/mainpanelcontrol.h index 8e743e71b..a924c2bb6 100755 --- a/frame/panel/mainpanelcontrol.h +++ b/frame/panel/mainpanelcontrol.h @@ -90,7 +90,7 @@ private: void handleDragMove(QDragMoveEvent *e, bool isFilter); void paintEvent(QPaintEvent *event) override; void resizeDockIcon(); - void calcuDockIconSize(const int w, const int h, PluginsItem *trashPlugin, PluginsItem *shutdownPlugin, PluginsItem *keyboardPlugin); + void calcuDockIconSize(const int w, const int h); public slots: void insertItem(const int index, DockItem *item);