mirror of
https://github.com/linuxdeepin/dde-dock.git
synced 2025-06-04 17:33:05 +00:00
Revert "feat: 任务栏拖拽图标交互优化"
This reverts commit 04762453fa1b27e0e1497833bb2b15c89a6cc236. Change-Id: I3a98ad32dd7ecac22e4d6c9148c30521fb4295fe
This commit is contained in:
parent
8d36e2e52a
commit
86362dcf17
@ -42,7 +42,6 @@ DockItem::DockItem(QWidget *parent)
|
|||||||
, m_draging(false)
|
, m_draging(false)
|
||||||
, m_popupTipsDelayTimer(new QTimer(this))
|
, m_popupTipsDelayTimer(new QTimer(this))
|
||||||
, m_popupAdjustDelayTimer(new QTimer(this))
|
, m_popupAdjustDelayTimer(new QTimer(this))
|
||||||
, m_contextMenu(new Menu(this, this))
|
|
||||||
{
|
{
|
||||||
if (PopupWindow.isNull()) {
|
if (PopupWindow.isNull()) {
|
||||||
DockPopupWindow *arrowRectangle = new DockPopupWindow(nullptr);
|
DockPopupWindow *arrowRectangle = new DockPopupWindow(nullptr);
|
||||||
@ -65,7 +64,7 @@ DockItem::DockItem(QWidget *parent)
|
|||||||
|
|
||||||
connect(m_popupTipsDelayTimer, &QTimer::timeout, this, &DockItem::showHoverTips);
|
connect(m_popupTipsDelayTimer, &QTimer::timeout, this, &DockItem::showHoverTips);
|
||||||
connect(m_popupAdjustDelayTimer, &QTimer::timeout, this, &DockItem::updatePopupPosition, Qt::QueuedConnection);
|
connect(m_popupAdjustDelayTimer, &QTimer::timeout, this, &DockItem::updatePopupPosition, Qt::QueuedConnection);
|
||||||
connect(m_contextMenu, &Menu::triggered, this, &DockItem::menuActionClicked);
|
connect(&m_contextMenu, &QMenu::triggered, this, &DockItem::menuActionClicked);
|
||||||
|
|
||||||
grabGesture(Qt::TapAndHoldGesture);
|
grabGesture(Qt::TapAndHoldGesture);
|
||||||
|
|
||||||
@ -234,7 +233,7 @@ void DockItem::showContextMenu()
|
|||||||
|
|
||||||
QJsonObject jsonMenu = jsonDocument.object();
|
QJsonObject jsonMenu = jsonDocument.object();
|
||||||
|
|
||||||
qDeleteAll(m_contextMenu->actions());
|
qDeleteAll(m_contextMenu.actions());
|
||||||
|
|
||||||
QJsonArray jsonMenuItems = jsonMenu.value("items").toArray();
|
QJsonArray jsonMenuItems = jsonMenu.value("items").toArray();
|
||||||
for (auto item : jsonMenuItems) {
|
for (auto item : jsonMenuItems) {
|
||||||
@ -244,13 +243,13 @@ void DockItem::showContextMenu()
|
|||||||
action->setChecked(itemObj.value("checked").toBool());
|
action->setChecked(itemObj.value("checked").toBool());
|
||||||
action->setData(itemObj.value("itemId").toString());
|
action->setData(itemObj.value("itemId").toString());
|
||||||
action->setEnabled(itemObj.value("isActive").toBool());
|
action->setEnabled(itemObj.value("isActive").toBool());
|
||||||
m_contextMenu->addAction(action);
|
m_contextMenu.addAction(action);
|
||||||
}
|
}
|
||||||
|
|
||||||
hidePopup();
|
hidePopup();
|
||||||
emit requestWindowAutoHide(false);
|
emit requestWindowAutoHide(false);
|
||||||
|
|
||||||
m_contextMenu->popup(QCursor::pos());
|
m_contextMenu.popup(QCursor::pos());
|
||||||
|
|
||||||
onContextMenuAccepted();
|
onContextMenuAccepted();
|
||||||
}
|
}
|
||||||
|
@ -24,7 +24,6 @@
|
|||||||
|
|
||||||
#include "constants.h"
|
#include "constants.h"
|
||||||
#include "dockpopupwindow.h"
|
#include "dockpopupwindow.h"
|
||||||
#include "menudialog.h"
|
|
||||||
|
|
||||||
#include <QFrame>
|
#include <QFrame>
|
||||||
#include <QPointer>
|
#include <QPointer>
|
||||||
@ -111,12 +110,12 @@ protected:
|
|||||||
bool m_popupShown;
|
bool m_popupShown;
|
||||||
bool m_tapAndHold;
|
bool m_tapAndHold;
|
||||||
bool m_draging;
|
bool m_draging;
|
||||||
|
QMenu m_contextMenu;
|
||||||
|
|
||||||
QPointer<QWidget> m_lastPopupWidget;
|
QPointer<QWidget> m_lastPopupWidget;
|
||||||
|
|
||||||
QTimer *m_popupTipsDelayTimer;
|
QTimer *m_popupTipsDelayTimer;
|
||||||
QTimer *m_popupAdjustDelayTimer;
|
QTimer *m_popupAdjustDelayTimer;
|
||||||
Menu *m_contextMenu;
|
|
||||||
|
|
||||||
static Position DockPosition;
|
static Position DockPosition;
|
||||||
static DisplayMode DockDisplayMode;
|
static DisplayMode DockDisplayMode;
|
||||||
|
@ -1,99 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2020 ~ 2021 Deepin Technology Co., Ltd.
|
|
||||||
*
|
|
||||||
* Author: songwentao <songwentao@uniontech.com>
|
|
||||||
*
|
|
||||||
* Maintainer: songwentao <songwentao@uniontech.com>
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*
|
|
||||||
* This program aims to cache the the icon and name of apps to the hash table,
|
|
||||||
* which can decrease the repeated resource consumption of loading the app info in the
|
|
||||||
* running time.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "menudialog.h"
|
|
||||||
|
|
||||||
#include <QApplication>
|
|
||||||
#include <QEvent>
|
|
||||||
#include <QMouseEvent>
|
|
||||||
|
|
||||||
Menu::Menu(QWidget *dockItem, QWidget *parent)
|
|
||||||
: QMenu(parent)
|
|
||||||
, m_dockItem(dockItem)
|
|
||||||
, m_eventInter(new XEventMonitor("com.deepin.api.XEventMonitor", "/com/deepin/api/XEventMonitor", QDBusConnection::sessionBus(), this))
|
|
||||||
, m_dockInter(new DBusDock("com.deepin.dde.daemon.Dock", "/com/deepin/dde/daemon/Dock", QDBusConnection::sessionBus(), this))
|
|
||||||
{
|
|
||||||
setWindowFlags(Qt::WindowStaysOnTopHint | Qt::X11BypassWindowManagerHint | Qt::Dialog);
|
|
||||||
setObjectName("rightMenu");
|
|
||||||
qApp->installEventFilter(this);
|
|
||||||
|
|
||||||
if (m_dockItem)
|
|
||||||
m_dockItem->installEventFilter(this);
|
|
||||||
|
|
||||||
// 点击任务栏以外区域时,关闭右键菜单
|
|
||||||
connect(m_eventInter, &XEventMonitor::ButtonPress, this, &Menu::onButtonPress);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Menu::onButtonPress()
|
|
||||||
{
|
|
||||||
if (!QRect(m_dockInter->frontendWindowRect()).contains(QCursor::pos()))
|
|
||||||
this->hide();
|
|
||||||
}
|
|
||||||
|
|
||||||
/** 右键菜单显示后在很多场景下都需要隐藏,为避免在各个控件中分别做隐藏右键菜单窗口的处理,
|
|
||||||
* 因此这里统一做了处理。
|
|
||||||
* @brief Menu::eventFilter
|
|
||||||
* @param watched 过滤器监听对象
|
|
||||||
* @param event 过滤器事件对象
|
|
||||||
* @return 返回true, 事件不再向下传递,返回false,事件向下传递
|
|
||||||
*/
|
|
||||||
bool Menu::eventFilter(QObject *watched, QEvent *event)
|
|
||||||
{
|
|
||||||
// 存在rightMenu和rightMenuWindow的对象名
|
|
||||||
if (!watched->objectName().startsWith("rightMenu")) {
|
|
||||||
if (event->type() == QEvent::MouseButtonPress) {
|
|
||||||
if (watched != m_dockItem && watched != this && this->isVisible()) {
|
|
||||||
// 鼠标点击时,除当前菜单外,其他显示的菜单都要隐藏
|
|
||||||
hide();
|
|
||||||
}
|
|
||||||
} else if (event->type() == QEvent::DragMove || event->type() == QEvent::Wheel || event->type() == QEvent::Move) {
|
|
||||||
// 按下应用拖动,按下应用从菜单上方移动时,鼠标滚轮滚动时,隐藏右键菜单
|
|
||||||
hide();
|
|
||||||
}
|
|
||||||
|
|
||||||
// 当右键菜单显示时捕获鼠标的release事件,click=press+release,
|
|
||||||
// 让click无效,从而让启动器窗口不关闭
|
|
||||||
if (event->type() == QEvent::MouseButtonRelease) {
|
|
||||||
QMouseEvent *mouseEvent = static_cast<QMouseEvent *>(event);
|
|
||||||
if (mouseEvent->source() == Qt::MouseEventSynthesizedByQt) {
|
|
||||||
if (isVisible())
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 处理当右键菜单显示时,esc按下,关闭右键菜单,保持和模态框一样的效果
|
|
||||||
if (event->type() == QEvent::KeyPress) {
|
|
||||||
QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event);
|
|
||||||
if (keyEvent->key() == Qt::Key_Escape) {
|
|
||||||
if (isVisible()) {
|
|
||||||
hide();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return QMenu::eventFilter(watched, event);
|
|
||||||
}
|
|
@ -1,56 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2020 ~ 2021 Deepin Technology Co., Ltd.
|
|
||||||
*
|
|
||||||
* Author: songwentao <songwentao@uniontech.com>
|
|
||||||
*
|
|
||||||
* Maintainer: songwentao <songwentao@uniontech.com>
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*
|
|
||||||
* This program aims to cache the the icon and name of apps to the hash table,
|
|
||||||
* which can decrease the repeated resource consumption of loading the app info in the
|
|
||||||
* running time.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef MYMENU_H
|
|
||||||
#define MYMENU_H
|
|
||||||
|
|
||||||
#include <com_deepin_api_xeventmonitor.h>
|
|
||||||
#include <com_deepin_dde_daemon_dock.h>
|
|
||||||
|
|
||||||
#include <QMenu>
|
|
||||||
#include <QWidget>
|
|
||||||
|
|
||||||
using DBusDock = com::deepin::dde::daemon::Dock;
|
|
||||||
using XEventMonitor = ::com::deepin::api::XEventMonitor;
|
|
||||||
|
|
||||||
class Menu : public QMenu
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
public:
|
|
||||||
explicit Menu(QWidget *dockItem = nullptr, QWidget *parent = nullptr);
|
|
||||||
|
|
||||||
void onButtonPress();
|
|
||||||
|
|
||||||
protected:
|
|
||||||
bool eventFilter(QObject *watched, QEvent *event);
|
|
||||||
|
|
||||||
private:
|
|
||||||
QWidget *m_dockItem;
|
|
||||||
XEventMonitor *m_eventInter;
|
|
||||||
DBusDock *m_dockInter;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif //MYMENU_H
|
|
@ -28,7 +28,7 @@ DBusAdaptors::DBusAdaptors(QObject *parent)
|
|||||||
m_keyboard(new Keyboard("com.deepin.daemon.InputDevices",
|
m_keyboard(new Keyboard("com.deepin.daemon.InputDevices",
|
||||||
"/com/deepin/daemon/InputDevice/Keyboard",
|
"/com/deepin/daemon/InputDevice/Keyboard",
|
||||||
QDBusConnection::sessionBus(), this)),
|
QDBusConnection::sessionBus(), this)),
|
||||||
m_menu(new Menu()),
|
m_menu(new QMenu()),
|
||||||
m_gsettings(Utils::ModuleSettingsPtr("keyboard", QByteArray(), this))
|
m_gsettings(Utils::ModuleSettingsPtr("keyboard", QByteArray(), this))
|
||||||
{
|
{
|
||||||
m_keyboard->setSync(false);
|
m_keyboard->setSync(false);
|
||||||
@ -36,7 +36,7 @@ DBusAdaptors::DBusAdaptors(QObject *parent)
|
|||||||
connect(m_keyboard, &Keyboard::CurrentLayoutChanged, this, &DBusAdaptors::onCurrentLayoutChanged);
|
connect(m_keyboard, &Keyboard::CurrentLayoutChanged, this, &DBusAdaptors::onCurrentLayoutChanged);
|
||||||
connect(m_keyboard, &Keyboard::UserLayoutListChanged, this, &DBusAdaptors::onUserLayoutListChanged);
|
connect(m_keyboard, &Keyboard::UserLayoutListChanged, this, &DBusAdaptors::onUserLayoutListChanged);
|
||||||
|
|
||||||
connect(m_menu, &Menu::triggered, this, &DBusAdaptors::handleActionTriggered);
|
connect(m_menu, &QMenu::triggered, this, &DBusAdaptors::handleActionTriggered);
|
||||||
|
|
||||||
// init data
|
// init data
|
||||||
initAllLayoutList();
|
initAllLayoutList();
|
||||||
|
@ -20,8 +20,6 @@
|
|||||||
#ifndef DBUSADAPTORS_H
|
#ifndef DBUSADAPTORS_H
|
||||||
#define DBUSADAPTORS_H
|
#define DBUSADAPTORS_H
|
||||||
|
|
||||||
#include "menudialog.h"
|
|
||||||
|
|
||||||
#include <QMenu>
|
#include <QMenu>
|
||||||
#include <QtDBus/QtDBus>
|
#include <QtDBus/QtDBus>
|
||||||
#include <com_deepin_daemon_inputdevice_keyboard.h>
|
#include <com_deepin_daemon_inputdevice_keyboard.h>
|
||||||
@ -75,7 +73,7 @@ private:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
Keyboard *m_keyboard;
|
Keyboard *m_keyboard;
|
||||||
Menu *m_menu;
|
QMenu *m_menu;
|
||||||
QAction *m_addLayoutAction;
|
QAction *m_addLayoutAction;
|
||||||
|
|
||||||
QString m_currentLayoutRaw;
|
QString m_currentLayoutRaw;
|
||||||
|
@ -39,10 +39,10 @@ QPointer<DockPopupWindow> SNITrayWidget::PopupWindow = nullptr;
|
|||||||
Dock::Position SNITrayWidget::DockPosition = Dock::Position::Top;
|
Dock::Position SNITrayWidget::DockPosition = Dock::Position::Top;
|
||||||
using namespace Dock;
|
using namespace Dock;
|
||||||
SNITrayWidget::SNITrayWidget(const QString &sniServicePath, QWidget *parent)
|
SNITrayWidget::SNITrayWidget(const QString &sniServicePath, QWidget *parent)
|
||||||
: AbstractTrayWidget(parent)
|
: AbstractTrayWidget(parent),
|
||||||
, m_dbusMenuImporter(nullptr)
|
m_dbusMenuImporter(nullptr),
|
||||||
, m_menu(nullptr)
|
m_menu(nullptr),
|
||||||
, m_updateIconTimer(new QTimer(this))
|
m_updateIconTimer(new QTimer(this))
|
||||||
, m_updateOverlayIconTimer(new QTimer(this))
|
, m_updateOverlayIconTimer(new QTimer(this))
|
||||||
, m_updateAttentionIconTimer(new QTimer(this))
|
, m_updateAttentionIconTimer(new QTimer(this))
|
||||||
, m_sniServicePath(sniServicePath)
|
, m_sniServicePath(sniServicePath)
|
||||||
@ -181,7 +181,6 @@ void SNITrayWidget::sendClick(uint8_t mouseButton, int x, int y)
|
|||||||
if (LeftClickInvalidIdList.contains(m_sniId)) {
|
if (LeftClickInvalidIdList.contains(m_sniId)) {
|
||||||
showContextMenu(x, y);
|
showContextMenu(x, y);
|
||||||
} else {
|
} else {
|
||||||
// 输入法切换等功能入口
|
|
||||||
m_sniInter->Activate(x, y);
|
m_sniInter->Activate(x, y);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -192,6 +191,7 @@ void SNITrayWidget::sendClick(uint8_t mouseButton, int x, int y)
|
|||||||
showContextMenu(x, y);
|
showContextMenu(x, y);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
qDebug() << "unknown mouse button key";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -272,13 +272,15 @@ void SNITrayWidget::initMenu()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
qDebug() << "using sni service path:" << m_dbusService << "menu path:" << sniMenuPath;
|
||||||
|
|
||||||
m_dbusMenuImporter = new DBusMenuImporter(m_dbusService, sniMenuPath, ASYNCHRONOUS, this);
|
m_dbusMenuImporter = new DBusMenuImporter(m_dbusService, sniMenuPath, ASYNCHRONOUS, this);
|
||||||
|
|
||||||
// 创建sni协议插件的右键菜单
|
qDebug() << "generate the sni menu object";
|
||||||
|
|
||||||
m_menu = m_dbusMenuImporter->menu();
|
m_menu = m_dbusMenuImporter->menu();
|
||||||
m_menu->setObjectName("sniMenu");
|
|
||||||
m_menu->setWindowFlags(Qt::WindowStaysOnTopHint | Qt::X11BypassWindowManagerHint | Qt::Dialog);
|
qDebug() << "the sni menu obect is:" << m_menu;
|
||||||
qApp->installEventFilter(this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SNITrayWidget::refreshIcon()
|
void SNITrayWidget::refreshIcon()
|
||||||
@ -335,7 +337,7 @@ void SNITrayWidget::showContextMenu(int x, int y)
|
|||||||
// 这里的PopupWindow属性是置顶的,如果不隐藏,会导致菜单显示不出来
|
// 这里的PopupWindow属性是置顶的,如果不隐藏,会导致菜单显示不出来
|
||||||
hidePopup();
|
hidePopup();
|
||||||
|
|
||||||
// 第三方的右键菜单,事件过滤方式无法捕获,修改x,y值不能改变菜单弹出位置
|
// ContextMenu does not work
|
||||||
if (m_sniMenuPath.path().startsWith("/NO_DBUSMENU")) {
|
if (m_sniMenuPath.path().startsWith("/NO_DBUSMENU")) {
|
||||||
m_sniInter->ContextMenu(x, y);
|
m_sniInter->ContextMenu(x, y);
|
||||||
} else {
|
} else {
|
||||||
@ -730,66 +732,6 @@ const QPoint SNITrayWidget::popupMarkPoint() const
|
|||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SNITrayWidget::eventFilter(QObject *watched, QEvent *event)
|
|
||||||
{
|
|
||||||
if (!m_menu)
|
|
||||||
return QWidget::eventFilter(watched, event);
|
|
||||||
|
|
||||||
QPoint startPos = QPoint();
|
|
||||||
if (!watched->objectName().startsWith("sniMenu")) {
|
|
||||||
if (event->type() == QEvent::MouseButtonPress) {
|
|
||||||
QMouseEvent *mouseEvent = static_cast<QMouseEvent *>(event);
|
|
||||||
if (mouseEvent->button() == Qt::LeftButton) {
|
|
||||||
if (m_sniMenuPath.path().startsWith("/NO_DBUSMENU")) {
|
|
||||||
// 关闭中文输入法或者五笔输入法,当前的关闭方式无效
|
|
||||||
QMouseEvent *pressEvent = new QMouseEvent(QEvent::MouseButtonPress, mapToGlobal(this->pos()), Qt::LeftButton, Qt::LeftButton, Qt::NoModifier);
|
|
||||||
qApp->postEvent(this->parentWidget(), pressEvent);
|
|
||||||
} else {
|
|
||||||
m_menu->hide();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
startPos = mouseEvent->pos();
|
|
||||||
} else if (event->type() == QEvent::DragMove || event->type() == QEvent::Move) {
|
|
||||||
if (m_sniMenuPath.path().startsWith("/NO_DBUSMENU")) {
|
|
||||||
// 关闭中文输入法或者五笔输入法,当前的关闭方式无效
|
|
||||||
QMouseEvent *pressEvent = new QMouseEvent(QEvent::MouseButtonPress, mapToGlobal(this->pos()), Qt::LeftButton, Qt::LeftButton, Qt::NoModifier);
|
|
||||||
qApp->postEvent(this->parentWidget(), pressEvent);
|
|
||||||
} else {
|
|
||||||
m_menu->hide();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 让click无效,避免点击到插件上
|
|
||||||
if (event->type() == QEvent::MouseButtonRelease) {
|
|
||||||
QMouseEvent *mouseEvent = static_cast<QMouseEvent *>(event);
|
|
||||||
if (mouseEvent->source() == Qt::MouseEventSynthesizedByQt) {
|
|
||||||
if (isVisible())
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 处理当右键菜单显示时,esc按下,关闭右键菜单,保持和模态框一样的效果
|
|
||||||
if (event->type() == QEvent::KeyPress) {
|
|
||||||
QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event);
|
|
||||||
if (keyEvent->key() == Qt::Key_Escape) {
|
|
||||||
if (!isVisible())
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if (m_sniMenuPath.path().startsWith("/NO_DBUSMENU")) {
|
|
||||||
// 关闭中文输入法或者五笔输入法,当前的关闭方式无效
|
|
||||||
QMouseEvent *pressEvent = new QMouseEvent(QEvent::MouseButtonPress, mapToGlobal(this->pos()), Qt::LeftButton, Qt::LeftButton, Qt::NoModifier);
|
|
||||||
qApp->postEvent(this->parentWidget(), pressEvent);
|
|
||||||
} else {
|
|
||||||
m_menu->hide();
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return QWidget::eventFilter(watched, event);
|
|
||||||
}
|
|
||||||
|
|
||||||
void SNITrayWidget::showPopupWindow(QWidget *const content, const bool model)
|
void SNITrayWidget::showPopupWindow(QWidget *const content, const bool model)
|
||||||
{
|
{
|
||||||
m_popupShown = true;
|
m_popupShown = true;
|
||||||
|
@ -74,13 +74,6 @@ public:
|
|||||||
|
|
||||||
static void setDockPostion(const Dock::Position pos) { DockPosition = pos; }
|
static void setDockPostion(const Dock::Position pos) { DockPosition = pos; }
|
||||||
|
|
||||||
protected:
|
|
||||||
bool eventFilter(QObject *watched, QEvent *event) override;
|
|
||||||
void enterEvent(QEvent *event) override;
|
|
||||||
void leaveEvent(QEvent *event) override;
|
|
||||||
void mousePressEvent(QMouseEvent *event) override;
|
|
||||||
void mouseReleaseEvent(QMouseEvent *e) override;
|
|
||||||
|
|
||||||
Q_SIGNALS:
|
Q_SIGNALS:
|
||||||
void statusChanged(SNITrayWidget::ItemStatus status);
|
void statusChanged(SNITrayWidget::ItemStatus status);
|
||||||
|
|
||||||
@ -107,6 +100,10 @@ private Q_SLOTS:
|
|||||||
void hidePopup();
|
void hidePopup();
|
||||||
void hideNonModel();
|
void hideNonModel();
|
||||||
void popupWindowAccept();
|
void popupWindowAccept();
|
||||||
|
void enterEvent(QEvent *event) override;
|
||||||
|
void leaveEvent(QEvent *event) override;
|
||||||
|
void mousePressEvent(QMouseEvent *event) override;
|
||||||
|
void mouseReleaseEvent(QMouseEvent *e) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void paintEvent(QPaintEvent *e) override;
|
void paintEvent(QPaintEvent *e) override;
|
||||||
|
@ -21,11 +21,9 @@
|
|||||||
|
|
||||||
#include "systemtrayitem.h"
|
#include "systemtrayitem.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
#include "menudialog.h"
|
|
||||||
|
|
||||||
#include <QProcess>
|
#include <QProcess>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QObject>
|
|
||||||
|
|
||||||
#include <xcb/xproto.h>
|
#include <xcb/xproto.h>
|
||||||
|
|
||||||
@ -38,7 +36,6 @@ SystemTrayItem::SystemTrayItem(PluginsItemInterface *const pluginInter, const QS
|
|||||||
, m_tapAndHold(false)
|
, m_tapAndHold(false)
|
||||||
, m_pluginInter(pluginInter)
|
, m_pluginInter(pluginInter)
|
||||||
, m_centralWidget(m_pluginInter->itemWidget(itemKey))
|
, m_centralWidget(m_pluginInter->itemWidget(itemKey))
|
||||||
, m_contextMenu(new Menu)
|
|
||||||
, m_popupTipsDelayTimer(new QTimer(this))
|
, m_popupTipsDelayTimer(new QTimer(this))
|
||||||
, m_popupAdjustDelayTimer(new QTimer(this))
|
, m_popupAdjustDelayTimer(new QTimer(this))
|
||||||
, m_itemKey(itemKey)
|
, m_itemKey(itemKey)
|
||||||
@ -85,7 +82,7 @@ SystemTrayItem::SystemTrayItem(PluginsItemInterface *const pluginInter, const QS
|
|||||||
|
|
||||||
connect(m_popupTipsDelayTimer, &QTimer::timeout, this, &SystemTrayItem::showHoverTips);
|
connect(m_popupTipsDelayTimer, &QTimer::timeout, this, &SystemTrayItem::showHoverTips);
|
||||||
connect(m_popupAdjustDelayTimer, &QTimer::timeout, this, &SystemTrayItem::updatePopupPosition, Qt::QueuedConnection);
|
connect(m_popupAdjustDelayTimer, &QTimer::timeout, this, &SystemTrayItem::updatePopupPosition, Qt::QueuedConnection);
|
||||||
connect(m_contextMenu, &QMenu::triggered, this, &SystemTrayItem::menuActionClicked);
|
connect(&m_contextMenu, &QMenu::triggered, this, &SystemTrayItem::menuActionClicked);
|
||||||
|
|
||||||
if (m_gsettings)
|
if (m_gsettings)
|
||||||
connect(m_gsettings, &QGSettings::changed, this, &SystemTrayItem::onGSettingsChanged);
|
connect(m_gsettings, &QGSettings::changed, this, &SystemTrayItem::onGSettingsChanged);
|
||||||
@ -97,8 +94,6 @@ SystemTrayItem::~SystemTrayItem()
|
|||||||
{
|
{
|
||||||
if (m_popupShown)
|
if (m_popupShown)
|
||||||
popupWindowAccept();
|
popupWindowAccept();
|
||||||
|
|
||||||
delete m_contextMenu;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QString SystemTrayItem::itemKeyForConfig()
|
QString SystemTrayItem::itemKeyForConfig()
|
||||||
@ -432,7 +427,7 @@ void SystemTrayItem::showContextMenu()
|
|||||||
|
|
||||||
QJsonObject jsonMenu = jsonDocument.object();
|
QJsonObject jsonMenu = jsonDocument.object();
|
||||||
|
|
||||||
qDeleteAll(m_contextMenu->actions());
|
qDeleteAll(m_contextMenu.actions());
|
||||||
|
|
||||||
QJsonArray jsonMenuItems = jsonMenu.value("items").toArray();
|
QJsonArray jsonMenuItems = jsonMenu.value("items").toArray();
|
||||||
for (auto item : jsonMenuItems) {
|
for (auto item : jsonMenuItems) {
|
||||||
@ -442,13 +437,13 @@ void SystemTrayItem::showContextMenu()
|
|||||||
action->setChecked(itemObj.value("checked").toBool());
|
action->setChecked(itemObj.value("checked").toBool());
|
||||||
action->setData(itemObj.value("itemId").toString());
|
action->setData(itemObj.value("itemId").toString());
|
||||||
action->setEnabled(itemObj.value("isActive").toBool());
|
action->setEnabled(itemObj.value("isActive").toBool());
|
||||||
m_contextMenu->addAction(action);
|
m_contextMenu.addAction(action);
|
||||||
}
|
}
|
||||||
|
|
||||||
hidePopup();
|
hidePopup();
|
||||||
emit requestWindowAutoHide(false);
|
emit requestWindowAutoHide(false);
|
||||||
|
|
||||||
m_contextMenu->popup(QCursor::pos());
|
m_contextMenu.exec(QCursor::pos());
|
||||||
|
|
||||||
onContextMenuAccepted();
|
onContextMenuAccepted();
|
||||||
}
|
}
|
||||||
|
@ -28,6 +28,7 @@
|
|||||||
#include "pluginsiteminterface.h"
|
#include "pluginsiteminterface.h"
|
||||||
|
|
||||||
#include <QGestureEvent>
|
#include <QGestureEvent>
|
||||||
|
#include <QMenu>
|
||||||
|
|
||||||
class QGSettings;
|
class QGSettings;
|
||||||
class Menu;
|
class Menu;
|
||||||
@ -96,10 +97,10 @@ private:
|
|||||||
private:
|
private:
|
||||||
bool m_popupShown;
|
bool m_popupShown;
|
||||||
bool m_tapAndHold;
|
bool m_tapAndHold;
|
||||||
|
QMenu m_contextMenu;
|
||||||
|
|
||||||
PluginsItemInterface* m_pluginInter;
|
PluginsItemInterface* m_pluginInter;
|
||||||
QWidget *m_centralWidget;
|
QWidget *m_centralWidget;
|
||||||
Menu *m_contextMenu;
|
|
||||||
|
|
||||||
QTimer *m_popupTipsDelayTimer;
|
QTimer *m_popupTipsDelayTimer;
|
||||||
QTimer *m_popupAdjustDelayTimer;
|
QTimer *m_popupAdjustDelayTimer;
|
||||||
|
@ -141,27 +141,12 @@ void XEmbedTrayWidget::paintEvent(QPaintEvent *e)
|
|||||||
painter.end();
|
painter.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
void XEmbedTrayWidget::mousePressEvent(QMouseEvent *e)
|
|
||||||
{
|
|
||||||
// 支持触摸屏触摸按下,显示右键菜单
|
|
||||||
if (e->source() == Qt::MouseEventSynthesizedByQt) {
|
|
||||||
QTimer::singleShot(100, this, [ & ] {
|
|
||||||
// 右键
|
|
||||||
sendClick(XCB_BUTTON_INDEX_3, QCursor::pos().x(), QCursor::pos().y());
|
|
||||||
});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void XEmbedTrayWidget::mouseMoveEvent(QMouseEvent *e)
|
void XEmbedTrayWidget::mouseMoveEvent(QMouseEvent *e)
|
||||||
{
|
{
|
||||||
AbstractTrayWidget::mouseMoveEvent(e);
|
AbstractTrayWidget::mouseMoveEvent(e);
|
||||||
|
|
||||||
// ignore the touchEvent
|
// ignore the touchEvent
|
||||||
if (e->source() == Qt::MouseEventSynthesizedByQt) {
|
if (e->source() == Qt::MouseEventSynthesizedByQt) {
|
||||||
// 临时方案隐藏微信等应用的右键菜单
|
|
||||||
// 左键
|
|
||||||
sendClick(XCB_BUTTON_INDEX_2, QCursor::pos().x(), QCursor::pos().y());
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -51,7 +51,6 @@ public:
|
|||||||
private:
|
private:
|
||||||
void showEvent(QShowEvent *e) override;
|
void showEvent(QShowEvent *e) override;
|
||||||
void paintEvent(QPaintEvent *e) override;
|
void paintEvent(QPaintEvent *e) override;
|
||||||
void mousePressEvent(QMouseEvent *e) override;
|
|
||||||
void mouseMoveEvent(QMouseEvent *e) override;
|
void mouseMoveEvent(QMouseEvent *e) override;
|
||||||
void configContainerPosition();
|
void configContainerPosition();
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user