From a8d44db60f530c0c0864912c675b6d634bb07fb0 Mon Sep 17 00:00:00 2001 From: donghualin Date: Fri, 18 Nov 2022 10:29:51 +0000 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E5=BF=AB=E6=8D=B7?= =?UTF-8?q?=E9=9D=A2=E6=9D=BF=E5=BC=B9=E5=87=BA=E4=BD=8D=E7=BD=AE=E4=B8=8D?= =?UTF-8?q?=E5=87=86=E7=A1=AE=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 快捷面板的弹出位置根据当前选中的插件位置来计算 Log: Influence: 从任务栏不同的插件图标点击,观察弹出快捷面板的位置 Bug: https://pms.uniontech.com/bug-view-172213.html Change-Id: Id229e0028221dd5ed10407d0054228aae0066ef0 --- frame/window/quickpluginwindow.cpp | 25 ++++++++++++++++++------- frame/window/quickpluginwindow.h | 2 +- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/frame/window/quickpluginwindow.cpp b/frame/window/quickpluginwindow.cpp index acd2ea090..7dc66c0cd 100644 --- a/frame/window/quickpluginwindow.cpp +++ b/frame/window/quickpluginwindow.cpp @@ -199,8 +199,14 @@ bool QuickPluginWindow::eventFilter(QObject *watched, QEvent *event) if (m_dragInfo->isNull()) break; - if (!m_dragInfo->canDrag(mouseEvent->pos())) { - // 弹出快捷设置面板 + do { + if (m_dragInfo->canDrag(mouseEvent->pos())) + break; + + QuickDockItem *releaseItem = qobject_cast(watched); + if (!releaseItem) + break; + DockPopupWindow *popWindow = QuickSettingContainer::popWindow(); if (Utils::IS_WAYLAND_DISPLAY) { // TODO: 临时解决方案,如果是wayland环境,toolTip没有消失,因此,此处直接调用接口来隐藏 @@ -216,9 +222,10 @@ bool QuickPluginWindow::eventFilter(QObject *watched, QEvent *event) dockItem->hideToolTip(); } } - popWindow->show(popupPoint(), true); - } + popWindow->show(popupPoint(releaseItem), true); + } while (false); m_dragInfo->reset(); + break; } case QEvent::MouseMove: { @@ -296,31 +303,35 @@ void QuickPluginWindow::onRequestUpdate() Q_EMIT itemCountChanged(); } -QPoint QuickPluginWindow::popupPoint() const +QPoint QuickPluginWindow::popupPoint(QWidget *widget) const { - if (!parentWidget()) + if (!widget) return pos(); - QPoint pointCurrent = parentWidget()->mapToGlobal(pos()); + QPoint pointCurrent = widget->mapToGlobal(QPoint(0, 0)); switch (m_position) { case Dock::Position::Bottom: { // 在下方的时候,Y坐标设置在顶层窗口的y值,保证下方对齐 + pointCurrent.setX(pointCurrent.x() + widget->width() / 2); pointCurrent.setY(topLevelWidget()->y()); break; } case Dock::Position::Top: { // 在上面的时候,Y坐标设置为任务栏的下方,保证上方对齐 + pointCurrent.setX(pointCurrent.x() + widget->width() / 2); pointCurrent.setY(topLevelWidget()->y() + topLevelWidget()->height()); break; } case Dock::Position::Left: { // 在左边的时候,X坐标设置在顶层窗口的最右侧,保证左对齐 pointCurrent.setX(topLevelWidget()->x() + topLevelWidget()->width()); + pointCurrent.setY(pointCurrent.y() + widget->height() / 2); break; } case Dock::Position::Right: { // 在右边的时候,X坐标设置在顶层窗口的最左侧,保证右对齐 pointCurrent.setX(topLevelWidget()->x()); + pointCurrent.setY(pointCurrent.y() + widget->height() / 2); } } return pointCurrent; diff --git a/frame/window/quickpluginwindow.h b/frame/window/quickpluginwindow.h index a8c9ba7a4..27fe3c09c 100644 --- a/frame/window/quickpluginwindow.h +++ b/frame/window/quickpluginwindow.h @@ -76,7 +76,7 @@ private: void startDrag(PluginsItemInterface *moveItem); PluginsItemInterface *findQuickSettingItem(const QPoint &mousePoint, const QList &settingItems); int getDropIndex(QPoint point); - QPoint popupPoint() const; + QPoint popupPoint(QWidget *widget) const; QuickDockItem *getDockItemByPlugin(PluginsItemInterface *item); QuickDockItem *getActiveDockItem(QPoint point) const;