diff --git a/frame/item/appitem.cpp b/frame/item/appitem.cpp index 1009dd3c9..59e6e616f 100644 --- a/frame/item/appitem.cpp +++ b/frame/item/appitem.cpp @@ -290,6 +290,11 @@ void AppItem::mouseReleaseEvent(QMouseEvent *e) if (e->button() == Qt::MiddleButton) { m_itemEntryInter->NewInstance(QX11Info::getTimestamp()); } else if (e->button() == Qt::LeftButton) { + if (checkAndResetTapHoldGestureState()) { + qDebug() << "tap and hold gesture detected, ignore the synthesized mouse release event"; + return; + } + qDebug() << "app item clicked, name:" << m_itemEntryInter->name() << "id:" << m_itemEntryInter->id() << "my-id:" << m_id << "icon:" << m_itemEntryInter->icon(); diff --git a/frame/item/dockitem.cpp b/frame/item/dockitem.cpp index e3b9c1bf6..49b868ccc 100644 --- a/frame/item/dockitem.cpp +++ b/frame/item/dockitem.cpp @@ -35,6 +35,7 @@ DockItem::DockItem(QWidget *parent) : QWidget(parent), m_hover(false), m_popupShown(false), + m_tapAndHold(false), m_hoverEffect(new HoverHighlightEffect(this)), @@ -65,6 +66,8 @@ DockItem::DockItem(QWidget *parent) connect(m_popupTipsDelayTimer, &QTimer::timeout, this, &DockItem::showHoverTips); connect(m_popupAdjustDelayTimer, &QTimer::timeout, this, &DockItem::updatePopupPosition, Qt::QueuedConnection); + + grabGesture(Qt::TapAndHoldGesture); } DockItem::~DockItem() @@ -83,6 +86,21 @@ void DockItem::setDockDisplayMode(const DisplayMode mode) DockDisplayMode = mode; } +void DockItem::gestureEvent(QGestureEvent *event) +{ + if (!event) + return; + + QGesture *gesture = event->gesture(Qt::TapAndHoldGesture); + + if (!gesture) + return; + + qDebug() << "got TapAndHoldGesture"; + + m_tapAndHold = true; +} + bool DockItem::event(QEvent *event) { if (m_popupShown) @@ -97,6 +115,9 @@ bool DockItem::event(QEvent *event) } } + if (event->type() == QEvent::Gesture) + gestureEvent(static_cast(event)); + return QWidget::event(event); } @@ -307,6 +328,18 @@ QWidget *DockItem::popupTips() return nullptr; } +/*! + * \brief DockItem::checkAndResetTapHoldGestureState checks if a QTapAndHoldGesture + * happens during the mouse press and release event pair. + * \return true if yes, otherwise false. + */ +bool DockItem::checkAndResetTapHoldGestureState() +{ + bool ret = m_tapAndHold; + m_tapAndHold = false; + return ret; +} + const QPoint DockItem::popupMarkPoint() const { QPoint p(topleftPoint()); diff --git a/frame/item/dockitem.h b/frame/item/dockitem.h index 348986996..e3c2b12d9 100644 --- a/frame/item/dockitem.h +++ b/frame/item/dockitem.h @@ -28,6 +28,7 @@ #include #include +#include #include @@ -88,6 +89,9 @@ protected: virtual const QString contextMenu() const; virtual QWidget *popupTips(); + bool checkAndResetTapHoldGestureState(); + virtual void gestureEvent(QGestureEvent *event); + protected slots: void showContextMenu(); void onContextMenuAccepted(); @@ -98,6 +102,7 @@ private: protected: bool m_hover; bool m_popupShown; + bool m_tapAndHold; QPointer m_lastPopupWidget; QPointer m_hoverEffect; diff --git a/frame/item/launcheritem.cpp b/frame/item/launcheritem.cpp index 04fb601b8..ddf143c1a 100644 --- a/frame/item/launcheritem.cpp +++ b/frame/item/launcheritem.cpp @@ -87,20 +87,17 @@ void LauncherItem::mousePressEvent(QMouseEvent *e) { hidePopup(); - if (e->button() == Qt::RightButton/* && !perfectIconRect().contains(e->pos())*/) - return QWidget::mousePressEvent(e); + return QWidget::mousePressEvent(e); +} +void LauncherItem::mouseReleaseEvent(QMouseEvent *e) +{ if (e->button() != Qt::LeftButton) return; - QProcess *proc = new QProcess; - - connect(proc, static_cast(&QProcess::finished), proc, &QProcess::deleteLater); - if (!m_launcherInter->IsVisible()) { m_launcherInter->Show(); } - } QWidget *LauncherItem::popupTips() diff --git a/frame/item/launcheritem.h b/frame/item/launcheritem.h index 23b3dda86..b7596c82a 100644 --- a/frame/item/launcheritem.h +++ b/frame/item/launcheritem.h @@ -44,6 +44,7 @@ private: void paintEvent(QPaintEvent *e); void resizeEvent(QResizeEvent *e); void mousePressEvent(QMouseEvent *e); + void mouseReleaseEvent(QMouseEvent *e); QWidget *popupTips(); diff --git a/frame/item/pluginsitem.cpp b/frame/item/pluginsitem.cpp index 678bf746e..a975c283a 100644 --- a/frame/item/pluginsitem.cpp +++ b/frame/item/pluginsitem.cpp @@ -150,6 +150,11 @@ void PluginsItem::mouseReleaseEvent(QMouseEvent *e) if (e->button() != Qt::LeftButton) return; + if (checkAndResetTapHoldGestureState()) { + qDebug() << "tap and hold gesture detected, ignore the synthesized mouse release event"; + return; + } + e->accept(); const QPoint distance = e->pos() - MousePressPoint;