From 1bf372f2d04b76af3954bcca99036c60040cb399 Mon Sep 17 00:00:00 2001 From: donghualin Date: Wed, 16 Nov 2022 05:36:56 +0000 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E5=8F=B3=E9=94=AE?= =?UTF-8?q?=E6=8F=92=E4=BB=B6=E5=8C=BA=E5=9F=9F=E5=86=8D=E5=8D=95=E5=87=BB?= =?UTF-8?q?=E5=BC=B9=E5=87=BA=E8=8F=9C=E5=8D=95=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-171559.html Change-Id: I6fd4c974c10b89e4921c15e8bf0bb8aecef3eeca --- frame/window/quickpluginwindow.cpp | 59 +++++++++++++++--------------- 1 file changed, 30 insertions(+), 29 deletions(-) diff --git a/frame/window/quickpluginwindow.cpp b/frame/window/quickpluginwindow.cpp index ee3a12331..f7fd313e7 100644 --- a/frame/window/quickpluginwindow.cpp +++ b/frame/window/quickpluginwindow.cpp @@ -179,20 +179,26 @@ bool QuickPluginWindow::eventFilter(QObject *watched, QEvent *event) { switch (event->type()) { case QEvent::MouseButtonPress: { + QMouseEvent *mouseEvent = static_cast(event); + if (mouseEvent->button() != Qt::LeftButton) + break; + QuickDockItem *dockItem = qobject_cast(watched); if (!dockItem) break; - QMouseEvent *mouseEvent = static_cast(event); m_dragInfo->dockItem = dockItem; m_dragInfo->dragPoint = mouseEvent->pos(); break; } case QEvent::MouseButtonRelease: { + QMouseEvent *mouseEvent = static_cast(event); + if (mouseEvent->button() != Qt::LeftButton) + break; + if (m_dragInfo->isNull()) break; - QMouseEvent *mouseEvent = static_cast(event); if (!m_dragInfo->canDrag(mouseEvent->pos())) { // 弹出快捷设置面板 DockPopupWindow *popWindow = QuickSettingContainer::popWindow(); @@ -541,38 +547,33 @@ void QuickDockItem::paintEvent(QPaintEvent *event) void QuickDockItem::mousePressEvent(QMouseEvent *event) { - switch (event->button()) { - case Qt::RightButton: { - if (m_contextMenu->actions().isEmpty()) { - const QString menuJson = m_pluginItem->itemContextMenu(m_itemKey); - if (menuJson.isEmpty()) - return; + if (event->button() != Qt::RightButton) + return QWidget::mousePressEvent(event); - QJsonDocument jsonDocument = QJsonDocument::fromJson(menuJson.toLocal8Bit().data()); - if (jsonDocument.isNull()) - return; + if (m_contextMenu->actions().isEmpty()) { + const QString menuJson = m_pluginItem->itemContextMenu(m_itemKey); + if (menuJson.isEmpty()) + return; - QJsonObject jsonMenu = jsonDocument.object(); + QJsonDocument jsonDocument = QJsonDocument::fromJson(menuJson.toLocal8Bit().data()); + if (jsonDocument.isNull()) + return; - QJsonArray jsonMenuItems = jsonMenu.value("items").toArray(); - for (auto item : jsonMenuItems) { - QJsonObject itemObj = item.toObject(); - QAction *action = new QAction(itemObj.value("itemText").toString()); - action->setCheckable(itemObj.value("isCheckable").toBool()); - action->setChecked(itemObj.value("checked").toBool()); - action->setData(itemObj.value("itemId").toString()); - action->setEnabled(itemObj.value("isActive").toBool()); - m_contextMenu->addAction(action); - } + QJsonObject jsonMenu = jsonDocument.object(); + + QJsonArray jsonMenuItems = jsonMenu.value("items").toArray(); + for (auto item : jsonMenuItems) { + QJsonObject itemObj = item.toObject(); + QAction *action = new QAction(itemObj.value("itemText").toString()); + action->setCheckable(itemObj.value("isCheckable").toBool()); + action->setChecked(itemObj.value("checked").toBool()); + action->setData(itemObj.value("itemId").toString()); + action->setEnabled(itemObj.value("isActive").toBool()); + m_contextMenu->addAction(action); } + } - m_contextMenu->exec(QCursor::pos()); - break; - } - default: - break; - } - QWidget::mousePressEvent(event); + m_contextMenu->exec(QCursor::pos()); } void QuickDockItem::enterEvent(QEvent *event)