fix: 修复快捷面板弹出位置不准确的问题

快捷面板的弹出位置根据当前选中的插件位置来计算

Log:
Influence: 从任务栏不同的插件图标点击,观察弹出快捷面板的位置
Bug: https://pms.uniontech.com/bug-view-172213.html
Change-Id: Id229e0028221dd5ed10407d0054228aae0066ef0
This commit is contained in:
donghualin 2022-11-18 10:29:51 +00:00
parent b3a989b070
commit a8d44db60f
2 changed files with 19 additions and 8 deletions

View File

@ -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<QuickDockItem *>(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;

View File

@ -76,7 +76,7 @@ private:
void startDrag(PluginsItemInterface *moveItem);
PluginsItemInterface *findQuickSettingItem(const QPoint &mousePoint, const QList<PluginsItemInterface *> &settingItems);
int getDropIndex(QPoint point);
QPoint popupPoint() const;
QPoint popupPoint(QWidget *widget) const;
QuickDockItem *getDockItemByPlugin(PluginsItemInterface *item);
QuickDockItem *getActiveDockItem(QPoint point) const;