From d325a98a2b1eca02f190d27d1dc9a2b65b8739d7 Mon Sep 17 00:00:00 2001 From: wangxuwen Date: Mon, 28 Oct 2019 14:42:56 +0800 Subject: [PATCH] =?UTF-8?q?feat(dock):=20change=20the=20lohic=20for=20dock?= =?UTF-8?q?=20icon=E2=80=98s=20size?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frame/item/pluginsitem.cpp | 1 - frame/panel/mainpanelcontrol.cpp | 158 +++++++++++--------- frame/panel/mainpanelcontrol.h | 3 + plugins/multitasking/multitaskingwidget.cpp | 21 --- plugins/multitasking/multitaskingwidget.h | 2 - plugins/show-desktop/showdesktopwidget.cpp | 21 --- plugins/show-desktop/showdesktopwidget.h | 2 - plugins/trash/trashwidget.cpp | 28 +--- plugins/trash/trashwidget.h | 2 - 9 files changed, 95 insertions(+), 143 deletions(-) diff --git a/frame/item/pluginsitem.cpp b/frame/item/pluginsitem.cpp index 936fed1ac..f95bf66e2 100644 --- a/frame/item/pluginsitem.cpp +++ b/frame/item/pluginsitem.cpp @@ -361,7 +361,6 @@ bool PluginsItem::checkGSettingsControl() const void PluginsItem::resizeEvent(QResizeEvent *event) { - setMinimumSize(m_centralWidget->minimumSize()); setMaximumSize(m_centralWidget->maximumSize()); return DockItem::resizeEvent(event); } diff --git a/frame/panel/mainpanelcontrol.cpp b/frame/panel/mainpanelcontrol.cpp index ce3d52d3f..30aeec63c 100644 --- a/frame/panel/mainpanelcontrol.cpp +++ b/frame/panel/mainpanelcontrol.cpp @@ -25,6 +25,7 @@ #include "../item/placeholderitem.h" #include "../item/components/appdrag.h" #include "../item/appitem.h" +#include "../item/pluginsitem.h" #include #include @@ -36,6 +37,7 @@ #include #define SPLITER_SIZE 2 +#define TRASH_MARGIN 20 DWIDGET_USE_NAMESPACE @@ -66,6 +68,7 @@ MainPanelControl::MainPanelControl(QWidget *parent) m_appAreaWidget->installEventFilter(this); m_appAreaSonWidget->installEventFilter(this); + m_trayAreaWidget->installEventFilter(this); } MainPanelControl::~MainPanelControl() @@ -153,41 +156,31 @@ void MainPanelControl::updateMainPanelLayout() m_trayAreaLayout->setContentsMargins(10, 0, 10, 0); break; } - } void MainPanelControl::addFixedAreaItem(int index, QWidget *wdg) { m_fixedAreaLayout->insertWidget(index, wdg); - - if ((m_position == Position::Top) || (m_position == Position::Bottom)) { - wdg->setMaximumSize(height(), height()); - } else { - wdg->setMaximumSize(width(), width()); - } + resizeDockIcon(); } void MainPanelControl::addAppAreaItem(int index, QWidget *wdg) { m_appAreaSonLayout->insertWidget(index, wdg); - - if ((m_position == Position::Top) || (m_position == Position::Bottom)) { - wdg->setMaximumSize(height(), height()); - } else { - wdg->setMaximumSize(width(), width()); - } + resizeDockIcon(); } void MainPanelControl::addTrayAreaItem(int index, QWidget *wdg) { m_trayAreaLayout->insertWidget(index, wdg); + resizeDockIcon(); } void MainPanelControl::addPluginAreaItem(int index, QWidget *wdg) { m_pluginLayout->insertWidget(index, wdg); + resizeDockIcon(); QTimer::singleShot(50, this, [ = ] {m_pluginAreaWidget->adjustSize();}); - } void MainPanelControl::removeFixedAreaItem(QWidget *wdg) @@ -212,28 +205,7 @@ void MainPanelControl::removePluginAreaItem(QWidget *wdg) void MainPanelControl::resizeEvent(QResizeEvent *event) { - for (int i = 0; i < m_appAreaSonLayout->count(); ++i) { - QWidget *w = m_appAreaSonLayout->itemAt(i)->widget(); - if (w) { - if ((m_position == Position::Top) || (m_position == Position::Bottom)) { - w->setMaximumSize(height(), height()); - } else { - w->setMaximumSize(width(), width()); - } - } - } - - for (int i = 0; i < m_fixedAreaLayout->count(); ++i) { - QWidget *w = m_fixedAreaLayout->itemAt(i)->widget(); - if (w) { - if ((m_position == Position::Top) || (m_position == Position::Bottom)) { - w->setMaximumSize(height(), height()); - } else { - w->setMaximumSize(width(), width()); - } - } - } - + resizeDockIcon(); return QWidget::resizeEvent(event); } @@ -481,38 +453,8 @@ bool MainPanelControl::eventFilter(QObject *watched, QEvent *event) if (watched == m_appAreaSonWidget) { if (event->type() == QEvent::LayoutRequest) { m_appAreaSonWidget->adjustSize(); + resizeDockIcon(); - if (m_position == Dock::Position::Top || m_position == Dock::Position::Bottom) { - m_fixedSpliter->setFixedSize(SPLITER_SIZE, height() * 0.6); - m_appSpliter->setFixedSize(SPLITER_SIZE, height() * 0.6); - m_traySpliter->setFixedSize(SPLITER_SIZE, height() * 0.5); - } else { - m_fixedSpliter->setFixedSize(width() * 0.6, SPLITER_SIZE); - m_appSpliter->setFixedSize(width() * 0.6, SPLITER_SIZE); - m_traySpliter->setFixedSize(width() * 0.5, SPLITER_SIZE); - } - - for (int i = 0; i < m_appAreaSonLayout->count(); ++i) { - QWidget *w = m_appAreaSonLayout->itemAt(i)->widget(); - if (w) { - if ((m_position == Position::Top) || (m_position == Position::Bottom)) { - w->setMaximumSize(height(), height()); - } else { - w->setMaximumSize(width(), width()); - } - } - } - - for (int i = 0; i < m_fixedAreaLayout->count(); ++i) { - QWidget *w = m_fixedAreaLayout->itemAt(i)->widget(); - if (w) { - if ((m_position == Position::Top) || (m_position == Position::Bottom)) { - w->setMaximumSize(height(), height()); - } else { - w->setMaximumSize(width(), width()); - } - } - } } else { moveAppSonWidget(); } @@ -530,6 +472,16 @@ bool MainPanelControl::eventFilter(QObject *watched, QEvent *event) moveAppSonWidget(); } + if (watched == m_trayAreaWidget) { + if (event->type() == QEvent::Resize) { + resizeDockIcon(); + } + } + + if (watched == m_trayAreaWidget) { + if (event->type() == QEvent::Resize) { + } + } if (m_appDragWidget && watched == static_cast(m_appDragWidget)->viewport()) { QDropEvent *e = static_cast(event); bool isContains = rect().contains(mapFromGlobal(m_appDragWidget->mapToGlobal(e->pos()))); @@ -767,3 +719,75 @@ void MainPanelControl::paintEvent(QPaintEvent *event) painter.fillRect(m_appSpliter->geometry(), color); painter.fillRect(m_traySpliter->geometry(), color); } + +void MainPanelControl::resizeDockIcon() +{ + //计算插件区域的垃圾箱大小 + int trashWidth = 0; + int trashHeight = 0; + for (int i = 0; i < m_pluginLayout->count(); ++ i) { + PluginsItem *w = static_cast(m_pluginLayout->itemAt(i)->widget()); + if (w->pluginName() == "trash") { + trashWidth = w->width(); + trashHeight = w->height(); + break; + } + } + //计算luancher 和 APP 区域大小 + int iconWidgetwidth = 0; + if ((m_position == Position::Top) || (m_position == Position::Bottom)) { + iconWidgetwidth = this->width() - m_trayAreaWidget->width() - (m_pluginAreaWidget->width() - trashHeight); + } else { + iconWidgetwidth = this->height() - m_trayAreaWidget->height() - (m_pluginAreaWidget->height() - trashWidth); + } + + //计算每一个icon的大小 + float iconSize = (iconWidgetwidth) / (m_fixedAreaLayout->count() + m_appAreaSonLayout->count() + 1) - 1; + + if ((m_position == Position::Top) || (m_position == Position::Bottom)) { + if (iconSize >= height()) { + calcuDockIconSize(height(), height()); + } else { + calcuDockIconSize(iconSize, height()); + } + } else { + if (iconSize >= width()) { + calcuDockIconSize(width(), width()); + } else { + calcuDockIconSize(width(), iconSize); + } + } +} + +void MainPanelControl::calcuDockIconSize(int w, int h) +{ + for (int i = 0; i < m_fixedAreaLayout->count(); ++ i) { + m_fixedAreaLayout->itemAt(i)->widget()->setFixedSize(w, h); + } + + for (int i = 0; i < m_appAreaSonLayout->count(); ++ i) { + m_appAreaSonLayout->itemAt(i)->widget()->setFixedSize(w, h); + } + + for (int i = 0; i < m_pluginLayout->count(); ++ i) { + PluginsItem *p = static_cast(m_pluginLayout->itemAt(i)->widget()); + if (p->pluginName() == "trash") { + if ((m_position == Position::Top) || (m_position == Position::Bottom)) { + p->setFixedSize(w, h - TRASH_MARGIN); + } else { + p->setFixedSize(w - TRASH_MARGIN, h); + } + break; + } + } + + if (m_position == Dock::Position::Top || m_position == Dock::Position::Bottom) { + m_fixedSpliter->setFixedSize(SPLITER_SIZE, w * 0.6); + m_appSpliter->setFixedSize(SPLITER_SIZE, w * 0.6); + m_traySpliter->setFixedSize(SPLITER_SIZE, w * 0.5); + } else { + m_fixedSpliter->setFixedSize(h * 0.6, SPLITER_SIZE); + m_appSpliter->setFixedSize(h * 0.6, SPLITER_SIZE); + m_traySpliter->setFixedSize(h * 0.5, SPLITER_SIZE); + } +} diff --git a/frame/panel/mainpanelcontrol.h b/frame/panel/mainpanelcontrol.h index 7d5a9355d..70698661d 100644 --- a/frame/panel/mainpanelcontrol.h +++ b/frame/panel/mainpanelcontrol.h @@ -85,6 +85,8 @@ private: void moveItem(DockItem *sourceItem, DockItem *targetItem); void handleDragMove(QDragMoveEvent *e, bool isFilter); void paintEvent(QPaintEvent *event) override; + void resizeDockIcon(); + void calcuDockIconSize(int w,int h); public slots: void insertItem(const int index, DockItem *item); @@ -102,6 +104,7 @@ private: QBoxLayout *m_pluginLayout; QWidget *m_appAreaSonWidget; QBoxLayout *m_appAreaSonLayout; + QBoxLayout *m_appAreaLayout; Position m_position; QPointer m_placeholderItem; MainPanelDelegate *m_delegate; diff --git a/plugins/multitasking/multitaskingwidget.cpp b/plugins/multitasking/multitaskingwidget.cpp index 171e0a7ce..2eb23b23f 100644 --- a/plugins/multitasking/multitaskingwidget.cpp +++ b/plugins/multitasking/multitaskingwidget.cpp @@ -29,7 +29,6 @@ MultitaskingWidget::MultitaskingWidget(QWidget *parent) : QWidget(parent) { - setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); m_icon = QIcon::fromTheme(":/icons/deepin-multitasking-view.svg"); } @@ -38,11 +37,6 @@ void MultitaskingWidget::refreshIcon() update(); } -QSize MultitaskingWidget::sizeHint() const -{ - return QSize(16, 16); -} - void MultitaskingWidget::paintEvent(QPaintEvent *e) { Q_UNUSED(e); @@ -63,18 +57,3 @@ void MultitaskingWidget::paintEvent(QPaintEvent *e) const QRectF &rfp = QRectF(icon.rect()); painter.drawPixmap(rf.center() - rfp.center() / ratio, icon); } - -void MultitaskingWidget::resizeEvent(QResizeEvent *event) -{ - const Dock::Position position = qApp->property(PROP_POSITION).value(); - // 保持横纵比 - if (position == Dock::Bottom || position == Dock::Top) { - setMinimumWidth(height()); - setMinimumHeight(PLUGIN_ICON_MIN_SIZE); - } else { - setMinimumWidth(PLUGIN_ICON_MIN_SIZE); - setMinimumHeight(width()); - } - - QWidget::resizeEvent(event); -} diff --git a/plugins/multitasking/multitaskingwidget.h b/plugins/multitasking/multitaskingwidget.h index a3d277b31..63c5770fe 100644 --- a/plugins/multitasking/multitaskingwidget.h +++ b/plugins/multitasking/multitaskingwidget.h @@ -34,14 +34,12 @@ class MultitaskingWidget : public QWidget public: explicit MultitaskingWidget(QWidget *parent = 0); void refreshIcon(); - QSize sizeHint() const override; signals: void requestContextMenu(const QString &itemKey) const; protected: void paintEvent(QPaintEvent *e) override; - void resizeEvent(QResizeEvent *event) override; QIcon m_icon; }; diff --git a/plugins/show-desktop/showdesktopwidget.cpp b/plugins/show-desktop/showdesktopwidget.cpp index 1be23d9bd..37f8bf3b1 100644 --- a/plugins/show-desktop/showdesktopwidget.cpp +++ b/plugins/show-desktop/showdesktopwidget.cpp @@ -29,7 +29,6 @@ ShowDesktopWidget::ShowDesktopWidget(QWidget *parent) : QWidget(parent) { - setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); } void ShowDesktopWidget::refreshIcon() @@ -37,11 +36,6 @@ void ShowDesktopWidget::refreshIcon() update(); } -QSize ShowDesktopWidget::sizeHint() const -{ - return QSize(16, 16); -} - void ShowDesktopWidget::paintEvent(QPaintEvent *e) { Q_UNUSED(e); @@ -62,18 +56,3 @@ void ShowDesktopWidget::paintEvent(QPaintEvent *e) const QRectF &rfp = QRectF(icon.rect()); painter.drawPixmap(rf.center() - rfp.center() / ratio, icon); } - -void ShowDesktopWidget::resizeEvent(QResizeEvent *event) -{ - const Dock::Position position = qApp->property(PROP_POSITION).value(); - // 保持横纵比 - if (position == Dock::Bottom || position == Dock::Top) { - setMinimumWidth(height()); - setMinimumHeight(PLUGIN_ICON_MIN_SIZE); - } else { - setMinimumWidth(PLUGIN_ICON_MIN_SIZE); - setMinimumHeight(width()); - } - - QWidget::resizeEvent(event); -} diff --git a/plugins/show-desktop/showdesktopwidget.h b/plugins/show-desktop/showdesktopwidget.h index 4409cea85..4bd5175ca 100644 --- a/plugins/show-desktop/showdesktopwidget.h +++ b/plugins/show-desktop/showdesktopwidget.h @@ -31,14 +31,12 @@ class ShowDesktopWidget : public QWidget public: explicit ShowDesktopWidget(QWidget *parent = 0); void refreshIcon(); - QSize sizeHint() const override; signals: void requestContextMenu(const QString &itemKey) const; protected: void paintEvent(QPaintEvent *e) override; - void resizeEvent(QResizeEvent *event) override; }; #endif // SHOWDESKTOPWIDGET_H diff --git a/plugins/trash/trashwidget.cpp b/plugins/trash/trashwidget.cpp index c3304a1f3..d647a10e5 100644 --- a/plugins/trash/trashwidget.cpp +++ b/plugins/trash/trashwidget.cpp @@ -44,8 +44,6 @@ TrashWidget::TrashWidget(QWidget *parent) setAcceptDrops(true); - setMinimumSize(PLUGIN_ICON_MIN_SIZE, PLUGIN_ICON_MIN_SIZE); - m_defaulticon = QIcon::fromTheme(":/icons/user-trash.svg"); } @@ -54,14 +52,6 @@ QWidget *TrashWidget::popupApplet() return m_popupApplet; } -QSize TrashWidget::sizeHint() const -{ - int w = std::min(width(), DOCK_MAX_SIZE); - int h = std::min(height(), DOCK_MAX_SIZE); - int size = std::max(w, h); - return QSize(size, size); -} - const QString TrashWidget::contextMenu() const { QList items; @@ -177,21 +167,6 @@ void TrashWidget::paintEvent(QPaintEvent *e) painter.drawPixmap(rf.center() - rfp.center() / devicePixelRatioF(), m_icon); } -void TrashWidget::resizeEvent(QResizeEvent *e) -{ - const Dock::Position position = qApp->property(PROP_POSITION).value(); - // 保持横纵比 - if (position == Dock::Bottom || position == Dock::Top) { - setMaximumWidth(height()); - setMaximumHeight(QWIDGETSIZE_MAX); - } else { - setMaximumHeight(width()); - setMaximumWidth(QWIDGETSIZE_MAX); - } - - QWidget::resizeEvent(e); -} - void TrashWidget::updateIcon() { // Dock::DisplayMode displayMode = qApp->property(PROP_DISPLAY_MODE).value(); @@ -203,11 +178,10 @@ void TrashWidget::updateIcon() if (displayMode == Dock::Efficient) iconString.append("-symbolic"); - const int size = std::min(width(), height()) ; + const int size = std::min(width(), height()) * ((Dock::Fashion == qApp->property(PROP_DISPLAY_MODE).value()) ? 0.8 : 0.7); QIcon icon = QIcon::fromTheme(iconString, m_defaulticon); const auto ratio = devicePixelRatioF(); - m_icon = icon.pixmap(size * ratio, size * ratio); m_icon.setDevicePixelRatio(ratio); } diff --git a/plugins/trash/trashwidget.h b/plugins/trash/trashwidget.h index d246ac273..38f133bf4 100644 --- a/plugins/trash/trashwidget.h +++ b/plugins/trash/trashwidget.h @@ -44,7 +44,6 @@ public: QWidget *popupApplet(); - QSize sizeHint() const Q_DECL_OVERRIDE; const QString contextMenu() const; int trashItemCount() const; void invokeMenuItem(const QString &menuId, const bool checked); @@ -59,7 +58,6 @@ protected: void dragMoveEvent(QDragMoveEvent *e) Q_DECL_OVERRIDE; void dropEvent(QDropEvent *e) Q_DECL_OVERRIDE; void paintEvent(QPaintEvent *e) Q_DECL_OVERRIDE; - void resizeEvent(QResizeEvent *e) Q_DECL_OVERRIDE; private slots: void removeApp(const QString &appKey);