mirror of
https://github.com/linuxdeepin/dde-dock.git
synced 2025-06-04 09:23:03 +00:00
fix: 修复展开托盘无法通过菜单移除U盘的问题
原因:在鼠标点击托盘内右键菜单的时候,会隐藏托盘,导致菜单跟着隐藏,结果是菜单的相关功能不生效 解决方案:在点击托盘区域的时候,判断鼠标位置是否在托盘区域内,包括菜单区域,如果在托盘区域内,则不关闭托盘,等菜单点击完成后再关闭 Log: 修复托盘U盘图标右键不生效的问题 Influence: 插入U盘,打开托盘区,右键菜单,点击,观察功能是否生效 Bug: https://pms.uniontech.com/bug-view-182299.html Change-Id: I7ba5cc65e2509d4a9dab6e21d73906e8894df0b8
This commit is contained in:
parent
81edbf0000
commit
46f01047a2
@ -112,7 +112,9 @@ QWidget *TrayDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem
|
|||||||
PluginsItemInterface *pluginInter = (PluginsItemInterface *)(index.data(TrayModel::PluginInterfaceRole).toULongLong());
|
PluginsItemInterface *pluginInter = (PluginsItemInterface *)(index.data(TrayModel::PluginInterfaceRole).toULongLong());
|
||||||
if (pluginInter) {
|
if (pluginInter) {
|
||||||
const QString itemKey = QuickSettingController::instance()->itemKey(pluginInter);
|
const QString itemKey = QuickSettingController::instance()->itemKey(pluginInter);
|
||||||
trayWidget = new SystemPluginItem(pluginInter, itemKey, parent);
|
SystemPluginItem *trayItem = new SystemPluginItem(pluginInter, itemKey, parent);
|
||||||
|
connect(trayItem, &SystemPluginItem::execActionFinished, this, &TrayDelegate::requestHide);
|
||||||
|
trayWidget = trayItem;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -45,6 +45,7 @@ public:
|
|||||||
Q_SIGNALS:
|
Q_SIGNALS:
|
||||||
void removeRow(const QModelIndex &) const;
|
void removeRow(const QModelIndex &) const;
|
||||||
void requestDrag(bool) const;
|
void requestDrag(bool) const;
|
||||||
|
void requestHide();
|
||||||
|
|
||||||
private Q_SLOTS:
|
private Q_SLOTS:
|
||||||
void onUpdateExpand(bool on);
|
void onUpdateExpand(bool on);
|
||||||
|
@ -54,6 +54,7 @@ Q_SIGNALS:
|
|||||||
void dragLeaved();
|
void dragLeaved();
|
||||||
void dragEntered();
|
void dragEntered();
|
||||||
void dragFinished();
|
void dragFinished();
|
||||||
|
void requestHide();
|
||||||
|
|
||||||
private Q_SLOTS:
|
private Q_SLOTS:
|
||||||
void clearDragModelIndex();
|
void clearDragModelIndex();
|
||||||
|
@ -24,6 +24,7 @@
|
|||||||
#include "tray_delegate.h"
|
#include "tray_delegate.h"
|
||||||
#include "dockpopupwindow.h"
|
#include "dockpopupwindow.h"
|
||||||
#include "imageutil.h"
|
#include "imageutil.h"
|
||||||
|
#include "systempluginitem.h"
|
||||||
|
|
||||||
#include <DGuiApplicationHelper>
|
#include <DGuiApplicationHelper>
|
||||||
#include <DRegionMonitor>
|
#include <DRegionMonitor>
|
||||||
@ -170,6 +171,7 @@ TrayGridWidget *ExpandIconWidget::popupTrayView()
|
|||||||
connect(trayModel, &TrayModel::rowCountChanged, gridParentView, rowCountChanged);
|
connect(trayModel, &TrayModel::rowCountChanged, gridParentView, rowCountChanged);
|
||||||
connect(trayModel, &TrayModel::requestRefreshEditor, trayView, &TrayGridView::onUpdateEditorView);
|
connect(trayModel, &TrayModel::requestRefreshEditor, trayView, &TrayGridView::onUpdateEditorView);
|
||||||
|
|
||||||
|
connect(trayDelegate, &TrayDelegate::requestHide, trayView, &TrayGridView::requestHide);
|
||||||
connect(trayDelegate, &TrayDelegate::removeRow, trayView, [ = ](const QModelIndex &index) {
|
connect(trayDelegate, &TrayDelegate::removeRow, trayView, [ = ](const QModelIndex &index) {
|
||||||
trayView->model()->removeRow(index.row(),index.parent());
|
trayView->model()->removeRow(index.row(),index.parent());
|
||||||
});
|
});
|
||||||
@ -208,6 +210,7 @@ void TrayGridWidget::setPosition(const Dock::Position &position)
|
|||||||
void TrayGridWidget::setTrayGridView(TrayGridView *trayView)
|
void TrayGridWidget::setTrayGridView(TrayGridView *trayView)
|
||||||
{
|
{
|
||||||
m_trayGridView = trayView;
|
m_trayGridView = trayView;
|
||||||
|
connect(m_trayGridView, &TrayGridView::requestHide, this, &TrayGridWidget::hide);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TrayGridWidget::setReferGridView(TrayGridView *trayView)
|
void TrayGridWidget::setReferGridView(TrayGridView *trayView)
|
||||||
@ -315,6 +318,16 @@ void TrayGridWidget::initMember()
|
|||||||
if (rctView.contains(mousePos))
|
if (rctView.contains(mousePos))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
// 查看是否存在SystemPluginItem插件,在此处判断的原因是因为当弹出右键菜单的时候,如果鼠标在菜单上点击
|
||||||
|
// 刚好把托盘区域给隐藏了,导致菜单也跟着隐藏,导致点击菜单的时候不生效
|
||||||
|
QAbstractItemModel *dataModel = m_trayGridView->model();
|
||||||
|
for (int i = 0; i < dataModel->rowCount(); i++) {
|
||||||
|
QModelIndex index = dataModel->index(i, 0);
|
||||||
|
SystemPluginItem *widget = qobject_cast<SystemPluginItem *>(m_trayGridView->indexWidget(index));
|
||||||
|
if (widget && widget->containsPoint(mousePos))
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
hide();
|
hide();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -37,7 +37,7 @@ SystemPluginItem::SystemPluginItem(PluginsItemInterface *const pluginInter, cons
|
|||||||
: BaseTrayWidget(parent)
|
: BaseTrayWidget(parent)
|
||||||
, m_popupShown(false)
|
, m_popupShown(false)
|
||||||
, m_tapAndHold(false)
|
, m_tapAndHold(false)
|
||||||
, m_contextMenu(new QMenu(this))
|
, m_contextMenu(new QMenu)
|
||||||
, m_pluginInter(pluginInter)
|
, m_pluginInter(pluginInter)
|
||||||
, m_centralWidget(m_pluginInter->itemWidget(itemKey))
|
, m_centralWidget(m_pluginInter->itemWidget(itemKey))
|
||||||
, m_popupTipsDelayTimer(new QTimer(this))
|
, m_popupTipsDelayTimer(new QTimer(this))
|
||||||
@ -81,6 +81,11 @@ SystemPluginItem::SystemPluginItem(PluginsItemInterface *const pluginInter, cons
|
|||||||
connect(qApp, &QApplication::aboutToQuit, PopupWindow, &DockPopupWindow::deleteLater);
|
connect(qApp, &QApplication::aboutToQuit, PopupWindow, &DockPopupWindow::deleteLater);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (Utils::IS_WAYLAND_DISPLAY) {
|
||||||
|
Qt::WindowFlags flags = m_contextMenu->windowFlags() | Qt::FramelessWindowHint;
|
||||||
|
m_contextMenu->setWindowFlags(flags);
|
||||||
|
}
|
||||||
|
|
||||||
// 必须初始化父窗口,否则当主题切换之后再设置父窗口的时候palette会更改为主题切换前的palette
|
// 必须初始化父窗口,否则当主题切换之后再设置父窗口的时候palette会更改为主题切换前的palette
|
||||||
if (QWidget *w = m_pluginInter->itemPopupApplet(m_itemKey)) {
|
if (QWidget *w = m_pluginInter->itemPopupApplet(m_itemKey)) {
|
||||||
w->setParent(PopupWindow.data());
|
w->setParent(PopupWindow.data());
|
||||||
@ -109,6 +114,7 @@ SystemPluginItem::~SystemPluginItem()
|
|||||||
{
|
{
|
||||||
if (m_popupShown)
|
if (m_popupShown)
|
||||||
popupWindowAccept();
|
popupWindowAccept();
|
||||||
|
m_contextMenu->deleteLater();
|
||||||
}
|
}
|
||||||
|
|
||||||
QString SystemPluginItem::itemKeyForConfig()
|
QString SystemPluginItem::itemKeyForConfig()
|
||||||
@ -379,6 +385,21 @@ void SystemPluginItem::hidePopup()
|
|||||||
emit requestWindowAutoHide(true);
|
emit requestWindowAutoHide(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool SystemPluginItem::containsPoint(QPoint pos)
|
||||||
|
{
|
||||||
|
QPoint ptGlobal = mapToGlobal(QPoint(0, 0));
|
||||||
|
QRect rectGlobal(ptGlobal, this->size());
|
||||||
|
if (rectGlobal.contains(pos))
|
||||||
|
return true;
|
||||||
|
|
||||||
|
// 如果菜单列表隐藏,则认为不在区域内
|
||||||
|
if (!m_contextMenu->isVisible())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
// 判断鼠标是否在菜单区域
|
||||||
|
return m_contextMenu->geometry().contains(pos);
|
||||||
|
}
|
||||||
|
|
||||||
void SystemPluginItem::hideNonModel()
|
void SystemPluginItem::hideNonModel()
|
||||||
{
|
{
|
||||||
// auto hide if popup is not model window
|
// auto hide if popup is not model window
|
||||||
@ -501,7 +522,7 @@ void SystemPluginItem::showContextMenu()
|
|||||||
QJsonArray jsonMenuItems = jsonMenu.value("items").toArray();
|
QJsonArray jsonMenuItems = jsonMenu.value("items").toArray();
|
||||||
for (auto item : jsonMenuItems) {
|
for (auto item : jsonMenuItems) {
|
||||||
QJsonObject itemObj = item.toObject();
|
QJsonObject itemObj = item.toObject();
|
||||||
QAction *action = new QAction(itemObj.value("itemText").toString());
|
QAction *action = new QAction(itemObj.value("itemText").toString(), m_contextMenu);
|
||||||
action->setCheckable(itemObj.value("isCheckable").toBool());
|
action->setCheckable(itemObj.value("isCheckable").toBool());
|
||||||
action->setChecked(itemObj.value("checked").toBool());
|
action->setChecked(itemObj.value("checked").toBool());
|
||||||
action->setData(itemObj.value("itemId").toString());
|
action->setData(itemObj.value("itemId").toString());
|
||||||
@ -520,6 +541,7 @@ void SystemPluginItem::showContextMenu()
|
|||||||
void SystemPluginItem::menuActionClicked(QAction *action)
|
void SystemPluginItem::menuActionClicked(QAction *action)
|
||||||
{
|
{
|
||||||
invokedMenuItem(action->data().toString(), true);
|
invokedMenuItem(action->data().toString(), true);
|
||||||
|
Q_EMIT execActionFinished();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SystemPluginItem::showCentralWidget()
|
void SystemPluginItem::showCentralWidget()
|
||||||
|
@ -62,9 +62,11 @@ public:
|
|||||||
|
|
||||||
void showPopupApplet(QWidget * const applet);
|
void showPopupApplet(QWidget * const applet);
|
||||||
void hidePopup();
|
void hidePopup();
|
||||||
|
bool containsPoint(QPoint pos);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void itemVisibleChanged(bool visible);
|
void itemVisibleChanged(bool visible);
|
||||||
|
void execActionFinished();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool event(QEvent *event) override;
|
bool event(QEvent *event) override;
|
||||||
|
@ -661,10 +661,13 @@ bool DockPluginController::eventFilter(QObject *object, QEvent *event)
|
|||||||
|
|
||||||
bool DockPluginController::pluginCanDock(PluginsItemInterface *plugin) const
|
bool DockPluginController::pluginCanDock(PluginsItemInterface *plugin) const
|
||||||
{
|
{
|
||||||
// 观察插件是否已经驻留在任务栏上,如果已经驻留在任务栏,则始终显示
|
// 1、如果插件是强制驻留任务栏,则始终显示
|
||||||
if (plugin->flags() & PluginFlag::Attribute_ForceDock)
|
// 2、如果插件是托盘插件,例如U盘插件,则始终显示
|
||||||
|
if ((plugin->flags() & PluginFlag::Attribute_ForceDock)
|
||||||
|
|| (plugin->flags() & PluginFlag::Type_Tray))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
// 3、插件已经驻留在任务栏,则始终显示
|
||||||
const QStringList configPlugins = SETTINGCONFIG->value(DOCK_QUICK_PLUGINS).toStringList();
|
const QStringList configPlugins = SETTINGCONFIG->value(DOCK_QUICK_PLUGINS).toStringList();
|
||||||
return configPlugins.contains(plugin->pluginName());
|
return configPlugins.contains(plugin->pluginName());
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user