From 88d52e28d1e6cc27c4496db44ce0d42755a42ee9 Mon Sep 17 00:00:00 2001 From: chenjun Date: Thu, 10 Sep 2020 15:51:33 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=B8=BA=E4=BA=86=E5=B0=86maintain/5.1?= =?UTF-8?q?=E5=88=86=E6=94=AF=E5=90=88=E5=85=A5uos,=E9=87=8D=E6=96=B0?= =?UTF-8?q?=E5=AF=B9=E4=BB=BB=E5=8A=A1=E6=A0=8F=E5=9B=BE=E6=A0=87=E7=82=B9?= =?UTF-8?q?=E5=87=BB=E3=80=81=E7=A7=BB=E5=8A=A8=E3=80=81=E6=8B=96=E5=8A=A8?= =?UTF-8?q?=E8=8C=83=E5=9B=B4=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 由原来的提交的用鼠标当前坐标是否在图标范围内的判断方式修改为设置图标布局的边距的方式。以便于将maintain/5.1分支合入uos而不影响其他 功能 Log: 重新对任务栏图标可点击、移动或拖动范围进行处理 Change-Id: Icf6df593f468c247c6d4fc5c2ba0936d5135626b Reviewed-on: http://gerrit.uniontech.com/c/dde-dock/+/4271 Reviewed-by: Reviewed-by: fanpengcheng Tested-by: --- frame/item/dockitem.cpp | 39 +--- frame/item/dockitem.h | 1 - frame/item/pluginsitem.cpp | 12 - frame/panel/mainpanelcontrol.cpp | 206 +++++++++++------- plugins/onboard/onboarditem.cpp | 26 +-- plugins/onboard/onboarditem.h | 1 - plugins/shutdown/shutdownwidget.cpp | 26 +-- plugins/shutdown/shutdownwidget.h | 1 - plugins/tray/abstracttraywidget.cpp | 14 -- plugins/tray/abstracttraywidget.h | 1 - .../containers/abstractcontainer.cpp | 5 - .../fashiontray/fashiontraycontrolwidget.cpp | 44 +--- .../fashiontray/fashiontraycontrolwidget.h | 2 - .../fashiontray/fashiontraywidgetwrapper.cpp | 36 +-- .../fashiontray/fashiontraywidgetwrapper.h | 1 - plugins/tray/snitraywidget.cpp | 19 +- plugins/tray/snitraywidget.h | 1 - plugins/tray/system-trays/systemtrayitem.cpp | 19 +- plugins/tray/system-trays/systemtrayitem.h | 1 - plugins/tray/xembedtraywidget.cpp | 6 +- 20 files changed, 151 insertions(+), 310 deletions(-) diff --git a/frame/item/dockitem.cpp b/frame/item/dockitem.cpp index 43dd8daf7..00e78c638 100644 --- a/frame/item/dockitem.cpp +++ b/frame/item/dockitem.cpp @@ -179,15 +179,9 @@ void DockItem::enterEvent(QEvent *e) return; } - if (containCursorPos()) { - m_hover = true; - m_hoverEffect->setHighlighting(true); - m_popupTipsDelayTimer->start(); - } else { - m_hover = false; - m_hoverEffect->setHighlighting(false); - m_popupTipsDelayTimer->stop(); - } + m_hover = true; + m_hoverEffect->setHighlighting(true); + m_popupTipsDelayTimer->start(); update(); @@ -213,16 +207,9 @@ void DockItem::leaveEvent(QEvent *e) void DockItem::mouseMoveEvent(QMouseEvent *e) { - if (containCursorPos()) { - m_hover = true; - m_hoverEffect->setHighlighting(true); - m_popupTipsDelayTimer->start(); - } else { - m_hover = false; - m_hoverEffect->setHighlighting(false); - m_popupTipsDelayTimer->stop(); - hidePopup(); - } + m_hover = true; + m_hoverEffect->setHighlighting(true); + m_popupTipsDelayTimer->start(); update(); @@ -291,20 +278,6 @@ void DockItem::onContextMenuAccepted() emit requestWindowAutoHide(true); } -bool DockItem::containCursorPos() -{ - QPoint cursorPos = this->mapFromGlobal(QCursor::pos()); - QRect rect(this->rect()); - - int iconSize = qMin(rect.width(), rect.height()); - int w = (rect.width() - iconSize) / 2; - int h = (rect.height() - iconSize) / 2; - - rect = rect.adjusted(w, h, -w, -h); - - return rect.contains(cursorPos); -} - void DockItem::showHoverTips() { // another model popup window already exists diff --git a/frame/item/dockitem.h b/frame/item/dockitem.h index f4899fe50..7d0a46a60 100644 --- a/frame/item/dockitem.h +++ b/frame/item/dockitem.h @@ -60,7 +60,6 @@ public: QSize sizeHint() const override; virtual QString accessibleName(); - bool containCursorPos(); public slots: virtual void refershIcon() {} diff --git a/frame/item/pluginsitem.cpp b/frame/item/pluginsitem.cpp index 7b7a833f6..fe0d7f769 100644 --- a/frame/item/pluginsitem.cpp +++ b/frame/item/pluginsitem.cpp @@ -140,10 +140,6 @@ void PluginsItem::mousePressEvent(QMouseEvent *e) return; } - if (!containCursorPos()) { - return; - } - update(); if (PopupWindow->isVisible()) @@ -164,10 +160,6 @@ void PluginsItem::mouseMoveEvent(QMouseEvent *e) DockItem::mouseMoveEvent(e); - if (!containCursorPos()) { - return; - } - e->accept(); const QPoint distance = e->pos() - MousePressPoint; @@ -191,10 +183,6 @@ void PluginsItem::mouseReleaseEvent(QMouseEvent *e) e->accept(); - if (!containCursorPos()) { - return; - } - const QPoint distance = e->pos() - MousePressPoint; if (distance.manhattanLength() < PLUGIN_ITEM_DRAG_THRESHOLD) mouseClicked(); diff --git a/frame/panel/mainpanelcontrol.cpp b/frame/panel/mainpanelcontrol.cpp index 8e8f09778..d76560638 100755 --- a/frame/panel/mainpanelcontrol.cpp +++ b/frame/panel/mainpanelcontrol.cpp @@ -255,8 +255,12 @@ void MainPanelControl::addTrayAreaItem(int index, QWidget *wdg) void MainPanelControl::addPluginAreaItem(int index, QWidget *wdg) { - m_pluginLayout->insertWidget(index, wdg, 0, Qt::AlignCenter); - resizeDockIcon(); + //因为日期时间插件和其他插件的大小有异,为了方便设置边距,在插件区域布局再添加一层布局设置边距 + //因此在处理插件图标时,需要通过两层布局判断是否为需要的插件,例如拖动插件位置等判断 + QBoxLayout * boxLayout = new QBoxLayout(QBoxLayout::LeftToRight); + boxLayout->addWidget(wdg, 0, Qt::AlignCenter); + m_pluginLayout->insertLayout(index, boxLayout, 0); + resizeDockIcon();; m_pluginAreaWidget->adjustSize(); } @@ -277,7 +281,16 @@ void MainPanelControl::removeTrayAreaItem(QWidget *wdg) void MainPanelControl::removePluginAreaItem(QWidget *wdg) { - m_pluginLayout->removeWidget(wdg); + //因为日期时间插件大小和其他插件有异,为了方便设置边距,各插件中增加一层布局 + //因此remove插件图标时,需要从多的一层布局中取widget进行判断是否需要移除的插件 + for (int i = 0; i < m_pluginLayout->count(); ++i) { + QLayoutItem *layoutItem = m_pluginLayout->itemAt(i); + QLayout *boxLayout = layoutItem->layout(); + if (boxLayout && boxLayout->itemAt(0)->widget() == wdg) { + boxLayout->removeWidget(wdg); + m_pluginLayout->removeItem(layoutItem); + } + } } void MainPanelControl::resizeEvent(QResizeEvent *event) @@ -375,9 +388,17 @@ void MainPanelControl::moveItem(DockItem *sourceItem, DockItem *targetItem) int idx = -1; if (targetItem->itemType() == DockItem::App) idx = m_appAreaSonLayout->indexOf(targetItem); - else if (targetItem->itemType() == DockItem::Plugins) - idx = m_pluginLayout->indexOf(targetItem); - else if (targetItem->itemType() == DockItem::FixedPlugin) + else if (targetItem->itemType() == DockItem::Plugins){ + //因为日期时间插件大小和其他插件大小有异,为了设置边距,在各插件中增加了一层布局 + //因此有拖动图标时,需要从多的一层布局中判断是否相同插件而获取插件位置顺序 + for (int i = 0; i < m_pluginLayout->count(); ++i) { + QLayout *layout = m_pluginLayout->itemAt(i)->layout(); + if (layout && layout->itemAt(0)->widget() == targetItem) { + idx = i; + break; + } + } + } else if (targetItem->itemType() == DockItem::FixedPlugin) idx = m_fixedAreaLayout->indexOf(targetItem); else return; @@ -611,10 +632,6 @@ bool MainPanelControl::eventFilter(QObject *watched, QEvent *event) if (item->itemType() != DockItem::App && item->itemType() != DockItem::Plugins && item->itemType() != DockItem::FixedPlugin) return false; - if (!item->containCursorPos()) { - return false; - } - const QPoint pos = mouseEvent->globalPos(); const QPoint distance = pos - m_mousePressPos; if (distance.manhattanLength() < QApplication::startDragDistance()) @@ -720,22 +737,21 @@ DockItem *MainPanelControl::dropTargetItem(DockItem *sourceItem, QPoint point) for (int i = 0 ; i < parentLayout->count(); ++i) { QLayoutItem *layoutItem = parentLayout->itemAt(i); - DockItem *dockItem = qobject_cast(layoutItem->widget()); + + DockItem *dockItem = nullptr; + if (parentWidget == m_pluginAreaWidget) { + QLayout *layout = layoutItem->layout(); + if (layout) { + dockItem = qobject_cast(layout->itemAt(0)->widget()); + } + } else{ + dockItem = qobject_cast(layoutItem->widget()); + } + if (!dockItem) continue; - QRect rect; - - rect.setTopLeft(dockItem->pos()); - if (dockItem->itemType() == DockItem::Plugins) { - if ((m_position == Position::Top) || (m_position == Position::Bottom)) { - rect.setSize(QSize(PLUGIN_MAX_SIZE, height())); - } else { - rect.setSize(QSize(width(), PLUGIN_MAX_SIZE)); - } - } else { - rect.setSize(dockItem->size()); - } + QRect rect(dockItem->pos(), dockItem->size()); if (rect.contains(point)) { targetItem = dockItem; break; @@ -866,31 +882,39 @@ void MainPanelControl::paintEvent(QPaintEvent *event) void MainPanelControl::resizeDockIcon() { - if (!m_tray) - return; // 插件有点特殊,因为会引入第三方的插件,并不会受dock的缩放影响,我们只能限制我们自己的插件,否则会导致显示错误。 // 以下是受控制的插件 PluginsItem *trashPlugin = nullptr; PluginsItem *shutdownPlugin = nullptr; PluginsItem *keyboardPlugin = nullptr; PluginsItem *notificationPlugin = nullptr; + + //因为日期时间大小和其他插件大小有异,为了设置边距,在各插件中增加了一层布局 + //因此需要通过多一层布局来获取各插件 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() == "notifications") { - notificationPlugin = w; + QLayout *layout = m_pluginLayout->itemAt(i)->layout(); + if (layout) { + PluginsItem *w = static_cast(m_pluginLayout->itemAt(i)->widget()); + if (w) { + if (w->pluginName() == "trash") { + trashPlugin = w; + } else if (w->pluginName() == "shutdown") { + shutdownPlugin = w; + } else if (w->pluginName() == "onboard") { + keyboardPlugin = w; + } else if (w->pluginName() == "notifications") { + notificationPlugin = w; + } + } } } // 总宽度 int totalLength = ((m_position == Position::Top) || (m_position == Position::Bottom)) ? width() : height(); // 减去托盘间隔区域 - totalLength -= (m_tray->trayVisableItemCount() + 1) * 10; + if (m_tray) { + totalLength -= (m_tray->trayVisableItemCount() + 1) * 10; + } // 减去3个分割线的宽度 totalLength -= 3 * SPLITER_SIZE; @@ -915,7 +939,12 @@ void MainPanelControl::resizeDockIcon() return; // 参与计算的插件的个数(包含托盘和插件,垃圾桶,关机,屏幕键盘) - int pluginCount = m_tray->trayVisableItemCount() + (trashPlugin ? 1 : 0) + (shutdownPlugin ? 1 : 0) + (keyboardPlugin ? 1 : 0) + (notificationPlugin ? 1 : 0); + int pluginCount = 0; + if (m_tray) { + pluginCount = m_tray->trayVisableItemCount() + (trashPlugin ? 1 : 0) + (shutdownPlugin ? 1 : 0) + (keyboardPlugin ? 1 : 0) + (notificationPlugin ? 1 : 0); + } else { + pluginCount = (trashPlugin ? 1 : 0) + (shutdownPlugin ? 1 : 0) + (keyboardPlugin ? 1 : 0) + (notificationPlugin ? 1 : 0); + } // icon个数 int iconCount = m_fixedAreaLayout->count() + m_appAreaSonLayout->count() + pluginCount; // 余数 @@ -956,8 +985,10 @@ void MainPanelControl::resizeDockIcon() void MainPanelControl::calcuDockIconSize(int w, int h, PluginsItem *trashPlugin, PluginsItem *shutdownPlugin, PluginsItem *keyboardPlugin, PluginsItem *notificationPlugin) { + int appItemSize = qMin(w, h); + for (int i = 0; i < m_fixedAreaLayout->count(); ++i) { - m_fixedAreaLayout->itemAt(i)->widget()->setFixedSize(w, h); + m_fixedAreaLayout->itemAt(i)->widget()->setFixedSize(appItemSize, appItemSize); } if (m_position == Dock::Position::Top || m_position == Dock::Position::Bottom) { @@ -971,7 +1002,7 @@ void MainPanelControl::calcuDockIconSize(int w, int h, PluginsItem *trashPlugin, } for (int i = 0; i < m_appAreaSonLayout->count(); ++i) { - m_appAreaSonLayout->itemAt(i)->widget()->setFixedSize(w, h); + m_appAreaSonLayout->itemAt(i)->widget()->setFixedSize(appItemSize, appItemSize); } // 托盘上每个图标大小 @@ -988,58 +1019,83 @@ void MainPanelControl::calcuDockIconSize(int w, int h, PluginsItem *trashPlugin, if (tray_item_size < 20) return; - m_tray->centralWidget()->setProperty("iconSize", tray_item_size); - - // 插件 - if ((m_position == Position::Top) || (m_position == Position::Bottom)) { - if (shutdownPlugin) - shutdownPlugin->setFixedSize(tray_item_size, h - 20); - if (keyboardPlugin) - keyboardPlugin->setFixedSize(tray_item_size, h - 20); - if (notificationPlugin) - notificationPlugin->setFixedSize(tray_item_size, h - 20); - if (trashPlugin) - trashPlugin->setFixedSize(tray_item_size, h - 20); - } else { - if (shutdownPlugin) - shutdownPlugin->setFixedSize(w - 20, tray_item_size); - if (keyboardPlugin) - keyboardPlugin->setFixedSize(w - 20, tray_item_size); - if (notificationPlugin) - notificationPlugin->setFixedSize(w - 20, tray_item_size); - if (trashPlugin) - trashPlugin->setFixedSize(w - 20, tray_item_size); + if (m_tray) { + m_tray->centralWidget()->setProperty("iconSize", tray_item_size); } + if (shutdownPlugin) + shutdownPlugin->setFixedSize(tray_item_size, tray_item_size); + if (keyboardPlugin) + keyboardPlugin->setFixedSize(tray_item_size, tray_item_size); + if (notificationPlugin) + notificationPlugin->setFixedSize(tray_item_size, tray_item_size); + if (trashPlugin) + trashPlugin->setFixedSize(tray_item_size, tray_item_size); + + //因为日期时间大小和其他插件大小有异,为了设置边距,在各插件中增加了一层布局 + //因此需要通过多一层布局来获取各插件 if ((m_position == Position::Top) || (m_position == Position::Bottom)) { // 三方插件 for (int i = 0; i < m_pluginLayout->count(); ++ i) { - PluginsItem *pItem = static_cast(m_pluginLayout->itemAt(i)->widget()); - if (pItem != trashPlugin && pItem != shutdownPlugin && pItem != keyboardPlugin && pItem !=notificationPlugin) { - if (pItem->pluginName() == "datetime"){ - pItem->setFixedSize(pItem->sizeHint().width(), h); - } else if (pItem->pluginName() == "AiAssistant"){ - pItem->setFixedSize(tray_item_size, h - 20); - } else { - pItem->setFixedSize(pItem->sizeHint().width(), h - 20); + QLayout *layout = m_pluginLayout->itemAt(i)->layout(); + if (layout) { + PluginsItem *pItem = static_cast(layout->itemAt(0)->widget()); + if (pItem && pItem != trashPlugin && pItem != shutdownPlugin && pItem != keyboardPlugin && pItem !=notificationPlugin) { + if (pItem->pluginName() == "datetime") { + pItem->setFixedSize(pItem->sizeHint().width(), h); + } else { + pItem->setFixedSize(tray_item_size, tray_item_size); + } } } } } else { // 三方插件 for (int i = 0; i < m_pluginLayout->count(); ++ i) { - PluginsItem *pItem = static_cast(m_pluginLayout->itemAt(i)->widget()); - if (pItem != trashPlugin && pItem != shutdownPlugin && pItem != keyboardPlugin && pItem !=notificationPlugin) { - if (pItem->pluginName() == "datetime"){ - pItem->setFixedSize(w, pItem->sizeHint().height()); - } else if (pItem->pluginName() == "AiAssistant"){ - pItem->setFixedSize(w - 20, tray_item_size); - } else { - pItem->setFixedSize(w - 20, pItem->sizeHint().height()); + QLayout *layout = m_pluginLayout->itemAt(i)->layout(); + if (layout) { + PluginsItem *pItem = static_cast(layout->itemAt(0)->widget()); + if (pItem && pItem != trashPlugin && pItem != shutdownPlugin && pItem != keyboardPlugin && pItem !=notificationPlugin) { + if (pItem->pluginName() == "datetime") { + pItem->setFixedSize(w, pItem->sizeHint().height()); + } else { + pItem->setFixedSize(tray_item_size, tray_item_size); + } } } } } + + int appTopAndBottomMargin = 0; + int appLeftAndRightMargin = 0; + + int trayTopAndBottomMargin = 0; + int trayLeftAndRightMargin = 0; + + if ((m_position == Position::Top) || (m_position == Position::Bottom)) { + appTopAndBottomMargin = (m_fixedAreaWidget->height() - appItemSize) / 2; + trayTopAndBottomMargin = (m_trayAreaWidget->height() - tray_item_size) / 2; + } else { + appLeftAndRightMargin = (m_fixedAreaWidget->width() - appItemSize) / 2; + trayLeftAndRightMargin = (m_trayAreaWidget->width() - tray_item_size) / 2; + } + + m_fixedAreaLayout->setContentsMargins(appLeftAndRightMargin, appTopAndBottomMargin, appLeftAndRightMargin, appTopAndBottomMargin); + m_appAreaSonLayout->setContentsMargins(appLeftAndRightMargin, appTopAndBottomMargin, appLeftAndRightMargin, appTopAndBottomMargin); + m_trayAreaLayout->setContentsMargins(trayLeftAndRightMargin, trayTopAndBottomMargin, trayLeftAndRightMargin, trayTopAndBottomMargin); + + //因为日期时间插件大小和其他插件大小有异,需要单独设置各插件的边距 + //而不对日期时间插件设置边距 + for (int i = 0; i < m_pluginLayout->count(); ++ i) { + QLayout *layout = m_pluginLayout->itemAt(i)->layout(); + if (layout) { + PluginsItem *pItem = static_cast(layout->itemAt(0)->widget()); + + if (pItem && pItem->pluginName() != "datetime") { + layout->setContentsMargins(trayLeftAndRightMargin, trayTopAndBottomMargin, trayLeftAndRightMargin, trayTopAndBottomMargin); + } + } + } } void MainPanelControl::getTrayVisableItemCount() diff --git a/plugins/onboard/onboarditem.cpp b/plugins/onboard/onboarditem.cpp index d52924fb6..e552db10d 100644 --- a/plugins/onboard/onboarditem.cpp +++ b/plugins/onboard/onboarditem.cpp @@ -121,11 +121,7 @@ const QPixmap OnboardItem::loadSvg(const QString &fileName, const QSize &size) c void OnboardItem::mousePressEvent(QMouseEvent *event) { - if (containCursorPos()) { - m_pressed = true; - } else { - m_pressed = false; - } + m_pressed = true; update(); @@ -143,11 +139,7 @@ void OnboardItem::mouseReleaseEvent(QMouseEvent *event) void OnboardItem::mouseMoveEvent(QMouseEvent *event) { - if (containCursorPos()) { - m_hover = true; - } else { - m_hover = false; - } + m_hover = true; update(); @@ -167,17 +159,3 @@ void OnboardItem::resizeEvent(QResizeEvent *event) { QWidget::resizeEvent(event); } - -bool OnboardItem::containCursorPos() -{ - QPoint cursorPos = this->mapFromGlobal(QCursor::pos()); - QRect rect(this->rect()); - - int iconSize = qMin(rect.width(), rect.height()); - int w = (rect.width() - iconSize) / 2; - int h = (rect.height() - iconSize) / 2; - - rect = rect.adjusted(w, h, -w, -h); - - return rect.contains(cursorPos); -} diff --git a/plugins/onboard/onboarditem.h b/plugins/onboard/onboarditem.h index 29b776f05..f2186a039 100644 --- a/plugins/onboard/onboarditem.h +++ b/plugins/onboard/onboarditem.h @@ -44,7 +44,6 @@ private: void mouseMoveEvent(QMouseEvent *event) override; void leaveEvent(QEvent *event) override; void resizeEvent(QResizeEvent *event) override; - bool containCursorPos(); private: Dock::DisplayMode m_displayMode; diff --git a/plugins/shutdown/shutdownwidget.cpp b/plugins/shutdown/shutdownwidget.cpp index 7a06ec0bb..958d4a27e 100644 --- a/plugins/shutdown/shutdownwidget.cpp +++ b/plugins/shutdown/shutdownwidget.cpp @@ -122,27 +122,9 @@ const QPixmap ShutdownWidget::loadSvg(const QString &fileName, const QSize &size return pixmap; } -bool ShutdownWidget::containCursorPos() -{ - QPoint cursorPos = this->mapFromGlobal(QCursor::pos()); - QRect rect(this->rect()); - - int iconSize = qMin(rect.width(), rect.height()); - int w = (rect.width() - iconSize) / 2; - int h = (rect.height() - iconSize) / 2; - - rect = rect.adjusted(w, h, -w, -h); - - return rect.contains(cursorPos); -} - void ShutdownWidget::mousePressEvent(QMouseEvent *event) { - if (containCursorPos()) { - m_pressed = true; - } else { - m_pressed = false; - } + m_pressed = true; update(); @@ -160,11 +142,7 @@ void ShutdownWidget::mouseReleaseEvent(QMouseEvent *event) void ShutdownWidget::mouseMoveEvent(QMouseEvent *event) { - if (containCursorPos()) { - m_hover = true; - } else { - m_hover = false; - } + m_hover = true; update(); diff --git a/plugins/shutdown/shutdownwidget.h b/plugins/shutdown/shutdownwidget.h index f0179ed81..414ffe5b4 100644 --- a/plugins/shutdown/shutdownwidget.h +++ b/plugins/shutdown/shutdownwidget.h @@ -43,7 +43,6 @@ protected: private: const QPixmap loadSvg(const QString &fileName, const QSize &size) const; - bool containCursorPos(); private: Dock::DisplayMode m_displayMode; diff --git a/plugins/tray/abstracttraywidget.cpp b/plugins/tray/abstracttraywidget.cpp index 190f43b6b..52ef6f3a0 100644 --- a/plugins/tray/abstracttraywidget.cpp +++ b/plugins/tray/abstracttraywidget.cpp @@ -134,17 +134,3 @@ void AbstractTrayWidget::resizeEvent(QResizeEvent *event) setMaximumWidth(QWIDGETSIZE_MAX); } } - -bool AbstractTrayWidget::containCursorPos() -{ - QPoint cursorPos = this->mapFromGlobal(QCursor::pos()); - QRect rect(this->rect()); - - int iconSize = qMin(rect.width(), rect.height()); - int w = (rect.width() - iconSize) / 2; - int h = (rect.height() - iconSize) / 2; - - rect = rect.adjusted(w, h, -w, -h); - - return rect.contains(cursorPos); -} diff --git a/plugins/tray/abstracttraywidget.h b/plugins/tray/abstracttraywidget.h index bae05bfea..8e450f5c9 100644 --- a/plugins/tray/abstracttraywidget.h +++ b/plugins/tray/abstracttraywidget.h @@ -60,7 +60,6 @@ protected: void handleMouseRelease(); const QRect perfectIconRect() const; void resizeEvent(QResizeEvent *event) override; - bool containCursorPos(); private: QTimer *m_handleMouseReleaseTimer; diff --git a/plugins/tray/fashiontray/containers/abstractcontainer.cpp b/plugins/tray/fashiontray/containers/abstractcontainer.cpp index a07996198..54c245d2f 100644 --- a/plugins/tray/fashiontray/containers/abstractcontainer.cpp +++ b/plugins/tray/fashiontray/containers/abstractcontainer.cpp @@ -149,11 +149,6 @@ void AbstractContainer::setExpand(const bool expand) refreshVisible(); } -//QSize AbstractContainer::sizeHint() const -//{ -// return totalSize(); -//} - void AbstractContainer::setItemSize(int itemSize) { m_itemSize = itemSize; diff --git a/plugins/tray/fashiontray/fashiontraycontrolwidget.cpp b/plugins/tray/fashiontray/fashiontraycontrolwidget.cpp index c27e91066..d9799f47d 100644 --- a/plugins/tray/fashiontray/fashiontraycontrolwidget.cpp +++ b/plugins/tray/fashiontray/fashiontraycontrolwidget.cpp @@ -149,9 +149,8 @@ void FashionTrayControlWidget::mouseReleaseEvent(QMouseEvent *event) if (event->button() == Qt::LeftButton) { event->accept(); - if (containCursorPos()) { - setExpanded(!m_expanded); - } + setExpanded(!m_expanded); + return; } @@ -165,11 +164,7 @@ void FashionTrayControlWidget::mousePressEvent(QMouseEvent *event) return QWidget::mousePressEvent(event); } - if (containCursorPos()) { - m_pressed = true; - } else { - m_pressed = false; - } + m_pressed = true; update(); @@ -178,11 +173,7 @@ void FashionTrayControlWidget::mousePressEvent(QMouseEvent *event) void FashionTrayControlWidget::enterEvent(QEvent *event) { - if (containCursorPos()) { - m_hover = true; - } else { - m_hover = false; - } + m_hover = true; update(); @@ -203,19 +194,6 @@ void FashionTrayControlWidget::resizeEvent(QResizeEvent *event) QWidget::resizeEvent(event); } -void FashionTrayControlWidget::mouseMoveEvent(QMouseEvent *event) -{ - if (containCursorPos()) { - m_hover = true; - } else { - m_hover = false; - } - - update(); - - QWidget::mouseMoveEvent(event); -} - void FashionTrayControlWidget::refreshArrowPixmap() { QString iconPath; @@ -238,17 +216,3 @@ void FashionTrayControlWidget::refreshArrowPixmap() const auto ratio = devicePixelRatioF(); m_arrowPix = ImageUtil::loadSvg(iconPath, ":/icons/resources/", PLUGIN_ICON_MAX_SIZE, ratio); } - -bool FashionTrayControlWidget::containCursorPos() -{ - QPoint cursorPos = this->mapFromGlobal(QCursor::pos()); - QRect rect(this->rect()); - - int iconSize = qMin(rect.width(), rect.height()); - int w = (rect.width() - iconSize) / 2; - int h = (rect.height() - iconSize) / 2; - - rect = rect.adjusted(w, h, -w, -h); - - return rect.contains(cursorPos); -} diff --git a/plugins/tray/fashiontray/fashiontraycontrolwidget.h b/plugins/tray/fashiontray/fashiontraycontrolwidget.h index 1d5564afd..c3b3c9262 100644 --- a/plugins/tray/fashiontray/fashiontraycontrolwidget.h +++ b/plugins/tray/fashiontray/fashiontraycontrolwidget.h @@ -48,11 +48,9 @@ protected: void enterEvent(QEvent *event) override; void leaveEvent(QEvent *event) override; void resizeEvent(QResizeEvent *event) override; - void mouseMoveEvent(QMouseEvent *event) override; private: void refreshArrowPixmap(); - bool containCursorPos(); private: QTimer *m_expandDelayTimer; diff --git a/plugins/tray/fashiontray/fashiontraywidgetwrapper.cpp b/plugins/tray/fashiontray/fashiontraywidgetwrapper.cpp index e49ed8373..6b8d5601f 100644 --- a/plugins/tray/fashiontray/fashiontraywidgetwrapper.cpp +++ b/plugins/tray/fashiontray/fashiontraywidgetwrapper.cpp @@ -141,11 +141,7 @@ void FashionTrayWidgetWrapper::mousePressEvent(QMouseEvent *event) MousePressPoint = event->pos(); } - if (containCursorPos()) { - m_pressed = true; - } else { - m_pressed = false; - } + m_pressed = true; update(); @@ -179,11 +175,7 @@ void FashionTrayWidgetWrapper::dragEnterEvent(QDragEnterEvent *event) void FashionTrayWidgetWrapper::enterEvent(QEvent *event) { - if (containCursorPos()) { - m_hover = true; - } else { - m_hover = false; - } + m_hover = true; update(); @@ -228,11 +220,7 @@ void FashionTrayWidgetWrapper::handleMouseMove(QMouseEvent *event) if(m_absTrayWidget.isNull()) return; - if (containCursorPos()) { - m_hover = true; - } else { - m_hover = false; - } + m_hover = true; update(); @@ -244,10 +232,6 @@ void FashionTrayWidgetWrapper::handleMouseMove(QMouseEvent *event) return; } - if (!containCursorPos()) { - return; - } - event->accept(); QDrag drag(this); @@ -283,20 +267,6 @@ void FashionTrayWidgetWrapper::onTrayWidgetClicked() setAttention(false); } -bool FashionTrayWidgetWrapper::containCursorPos() -{ - QPoint cursorPos = this->mapFromGlobal(QCursor::pos()); - QRect rect(this->rect()); - - int iconSize = qMin(rect.width(), rect.height()); - int w = (rect.width() - iconSize) / 2; - int h = (rect.height() - iconSize) / 2; - - rect = rect.adjusted(w, h, -w, -h); - - return rect.contains(cursorPos); -} - bool FashionTrayWidgetWrapper::attention() const { return m_attention; diff --git a/plugins/tray/fashiontray/fashiontraywidgetwrapper.h b/plugins/tray/fashiontray/fashiontraywidgetwrapper.h index 226331ca6..2ad938c23 100644 --- a/plugins/tray/fashiontray/fashiontraywidgetwrapper.h +++ b/plugins/tray/fashiontray/fashiontraywidgetwrapper.h @@ -64,7 +64,6 @@ private: void handleMouseMove(QMouseEvent *event); void onTrayWidgetNeedAttention(); void onTrayWidgetClicked(); - bool containCursorPos(); private: QPointer m_absTrayWidget; diff --git a/plugins/tray/snitraywidget.cpp b/plugins/tray/snitraywidget.cpp index 92e38a99e..039484067 100644 --- a/plugins/tray/snitraywidget.cpp +++ b/plugins/tray/snitraywidget.cpp @@ -560,12 +560,7 @@ QPixmap SNITrayWidget::newIconPixmap(IconType iconType) void SNITrayWidget::enterEvent(QEvent *event) { - if (containCursorPos()) { - m_popupTipsDelayTimer->start(); - } else { - m_popupTipsDelayTimer->stop(); - hidePopup(); - } + m_popupTipsDelayTimer->start(); AbstractTrayWidget::enterEvent(event); } @@ -581,18 +576,6 @@ void SNITrayWidget::leaveEvent(QEvent *event) AbstractTrayWidget::leaveEvent(event); } -void SNITrayWidget::mouseMoveEvent(QMouseEvent *event) -{ - if (containCursorPos()) { - m_popupTipsDelayTimer->start(); - } else { - m_popupTipsDelayTimer->stop(); - hidePopup(); - } - - AbstractTrayWidget::mouseMoveEvent(event); -} - void SNITrayWidget::showHoverTips() { if (PopupWindow->model()) diff --git a/plugins/tray/snitraywidget.h b/plugins/tray/snitraywidget.h index 1e70d4220..2857c2169 100644 --- a/plugins/tray/snitraywidget.h +++ b/plugins/tray/snitraywidget.h @@ -101,7 +101,6 @@ private Q_SLOTS: void popupWindowAccept(); void enterEvent(QEvent *event) override; void leaveEvent(QEvent *event) override; - void mouseMoveEvent(QMouseEvent *event) override; private: void paintEvent(QPaintEvent *e) override; diff --git a/plugins/tray/system-trays/systemtrayitem.cpp b/plugins/tray/system-trays/systemtrayitem.cpp index 05442722a..34e4ab411 100644 --- a/plugins/tray/system-trays/systemtrayitem.cpp +++ b/plugins/tray/system-trays/systemtrayitem.cpp @@ -203,12 +203,7 @@ void SystemTrayItem::enterEvent(QEvent *event) return; } - if (containCursorPos()) { - m_popupTipsDelayTimer->start(); - } else { - m_popupTipsDelayTimer->stop(); - hidePopup(); - } + m_popupTipsDelayTimer->start(); update(); @@ -294,18 +289,6 @@ void SystemTrayItem::showEvent(QShowEvent *event) return AbstractTrayWidget::showEvent(event); } -void SystemTrayItem::mouseMoveEvent(QMouseEvent *event) -{ - if (containCursorPos()) { - m_popupTipsDelayTimer->start(); - } else { - m_popupTipsDelayTimer->stop(); - hidePopup(); - } - - AbstractTrayWidget::mouseMoveEvent(event); -} - const QPoint SystemTrayItem::popupMarkPoint() const { QPoint p(topleftPoint()); diff --git a/plugins/tray/system-trays/systemtrayitem.h b/plugins/tray/system-trays/systemtrayitem.h index 36117750f..00607e082 100644 --- a/plugins/tray/system-trays/systemtrayitem.h +++ b/plugins/tray/system-trays/systemtrayitem.h @@ -72,7 +72,6 @@ protected: void mousePressEvent(QMouseEvent *event) override; void mouseReleaseEvent(QMouseEvent *event) override; void showEvent(QShowEvent* event) override; - void mouseMoveEvent(QMouseEvent* event) override; protected: const QPoint popupMarkPoint() const; diff --git a/plugins/tray/xembedtraywidget.cpp b/plugins/tray/xembedtraywidget.cpp index 35374ac13..9c0700bd3 100644 --- a/plugins/tray/xembedtraywidget.cpp +++ b/plugins/tray/xembedtraywidget.cpp @@ -147,11 +147,7 @@ void XEmbedTrayWidget::mouseMoveEvent(QMouseEvent *e) return; } - if (containCursorPos()) { - m_sendHoverEvent->start();; - } else { - m_sendHoverEvent->stop(); - } + m_sendHoverEvent->start(); } void XEmbedTrayWidget::configContainerPosition()