From e1ad39dad6849b4113219defbba3341a7a4cd61c Mon Sep 17 00:00:00 2001 From: liuxing Date: Mon, 7 Sep 2020 23:51:50 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=A7=A6=E5=B1=8F=E9=9C=80=E8=A6=81?= =?UTF-8?q?=E5=B1=8F=E8=94=BDhover=E6=95=88=E6=9E=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 之前需求里面没有说明,没有特意做相关的屏蔽操作,导致触屏也会出现hover效果 Log: 屏蔽任务栏触屏hover效果 Bug: https://pms.uniontech.com/zentao/bug-view-46245.html Change-Id: I7a1ff66faea486a4946a5ab77d9e7ac6ae663fcd Reviewed-on: http://gerrit.uniontech.com/c/dde-dock/+/3942 Reviewed-by: Reviewed-by: wangwei Reviewed-by: fanpengcheng Tested-by: --- frame/item/dockitem.cpp | 6 ++- frame/main.cpp | 4 +- frame/util/dockapplication.cpp | 19 ++++++++ frame/util/dockapplication.h | 50 ++++++++++++++++++++ interfaces/constants.h | 2 + plugins/tray/snitraywidget.cpp | 5 +- plugins/tray/system-trays/systemtrayitem.cpp | 5 +- 7 files changed, 86 insertions(+), 5 deletions(-) create mode 100644 frame/util/dockapplication.cpp create mode 100644 frame/util/dockapplication.h diff --git a/frame/item/dockitem.cpp b/frame/item/dockitem.cpp index 620d9177f..34b775a86 100644 --- a/frame/item/dockitem.cpp +++ b/frame/item/dockitem.cpp @@ -182,7 +182,11 @@ void DockItem::enterEvent(QEvent *e) m_hover = true; //FIXME: 可能是qt的bug,概率性导致崩溃,待修复 // m_hoverEffect->setHighlighting(true); - m_popupTipsDelayTimer->start(); + + // 触屏不显示hover效果 + if (!qApp->property(IS_TOUCH_STATE).toBool()) { + m_popupTipsDelayTimer->start(); + } update(); diff --git a/frame/main.cpp b/frame/main.cpp index 0a9d9ece0..9548d4f88 100644 --- a/frame/main.cpp +++ b/frame/main.cpp @@ -23,13 +23,13 @@ #include "window/accessible.h" #include "util/themeappicon.h" #include "controller/dockitemmanager.h" +#include "util/dockapplication.h" #include #include #include #include -#include #include #include #include @@ -185,7 +185,7 @@ void sig_crash(int sig) int main(int argc, char *argv[]) { DGuiApplicationHelper::setUseInactiveColorGroup(false); - DApplication app(argc, argv); + DockApplication app(argc, argv); //崩溃信号 signal(SIGTERM, sig_crash); diff --git a/frame/util/dockapplication.cpp b/frame/util/dockapplication.cpp new file mode 100644 index 000000000..6813b5cab --- /dev/null +++ b/frame/util/dockapplication.cpp @@ -0,0 +1,19 @@ +#include "dockapplication.h" +#include "constants.h" + +#include + +DockApplication::DockApplication(int &argc, char **argv) : DApplication (argc, argv) +{ +} + +bool DockApplication::notify(QObject *obj, QEvent *event) +{ + QMouseEvent *mouseEvent = dynamic_cast(event); + if (mouseEvent) { + // 鼠标事件可以通过source函数确定是否触屏事件,并将结果写入qApp的动态属性中 + qApp->setProperty(IS_TOUCH_STATE, (mouseEvent->source() == Qt::MouseEventSynthesizedByQt)); + } + + return DApplication::notify(obj, event); +} diff --git a/frame/util/dockapplication.h b/frame/util/dockapplication.h new file mode 100644 index 000000000..654eaaf8d --- /dev/null +++ b/frame/util/dockapplication.h @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2018 ~ 2028 Uniontech Technology Co., Ltd. + * + * Author: liuxing + * + * Maintainer: liuxing + * + * 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 . + */ + +#ifndef DOCKAPPLICATION_H +#define DOCKAPPLICATION_H + +#include + +DWIDGET_USE_NAMESPACE +#ifdef DCORE_NAMESPACE +DCORE_USE_NAMESPACE +#else +DUTIL_USE_NAMESPACE +#endif + +/** + * @brief The DockApplication class + * 本类通过重写application的notify函数监控应用的鼠标事件,判断是否为触屏状态 + */ +class DockApplication : public DApplication +{ + Q_OBJECT +public: + explicit DockApplication(int &argc, char **argv); + virtual bool notify(QObject *obj, QEvent *event) override; + +signals: + +public slots: +}; + +#endif // DOCKAPPLICATION_H diff --git a/interfaces/constants.h b/interfaces/constants.h index 5a85f647c..f94c94cde 100644 --- a/interfaces/constants.h +++ b/interfaces/constants.h @@ -91,6 +91,8 @@ enum HideState { Hide = 2, }; +#define IS_TOUCH_STATE "isTouchState" + } Q_DECLARE_METATYPE(Dock::DisplayMode) diff --git a/plugins/tray/snitraywidget.cpp b/plugins/tray/snitraywidget.cpp index aea173fbf..de6afa53b 100644 --- a/plugins/tray/snitraywidget.cpp +++ b/plugins/tray/snitraywidget.cpp @@ -566,7 +566,10 @@ QPixmap SNITrayWidget::newIconPixmap(IconType iconType) void SNITrayWidget::enterEvent(QEvent *event) { - m_popupTipsDelayTimer->start(); + // 触屏不显示hover效果 + if (!qApp->property(IS_TOUCH_STATE).toBool()) { + m_popupTipsDelayTimer->start(); + } AbstractTrayWidget::enterEvent(event); } diff --git a/plugins/tray/system-trays/systemtrayitem.cpp b/plugins/tray/system-trays/systemtrayitem.cpp index bba912445..907c54fe1 100644 --- a/plugins/tray/system-trays/systemtrayitem.cpp +++ b/plugins/tray/system-trays/systemtrayitem.cpp @@ -206,7 +206,10 @@ void SystemTrayItem::enterEvent(QEvent *event) return; } - m_popupTipsDelayTimer->start(); + // 触屏不显示hover效果 + if (!qApp->property(IS_TOUCH_STATE).toBool()) { + m_popupTipsDelayTimer->start(); + } update(); AbstractTrayWidget::enterEvent(event);