806114d359
OBS-URL: https://build.opensuse.org/package/show/KDE:Frameworks5/kdeclarative?expand=0&rev=7f4398aace1fb69ca80207d6b1100010
148 lines
5.2 KiB
Diff
148 lines
5.2 KiB
Diff
From e2795e9472333d5e8b2ce70017ca705474ebe3d2 Mon Sep 17 00:00:00 2001
|
|
From: Kai Uwe Broulik <kde@privat.broulik.de>
|
|
Date: Thu, 23 Nov 2017 11:04:01 +0100
|
|
Subject: [MouseEventListener] Allow accepting mouse event
|
|
|
|
This will keep the event from propagating. Accepting a press event will also not result in
|
|
clicked or pressAndHold being handled.
|
|
|
|
In Qt 5.10 event propagation changed resulting in FolderView opening both the item context menu
|
|
and containment context menu. Imho this actually makes sense since we never accepted the
|
|
mouse event there.
|
|
|
|
Differential Revision: https://phabricator.kde.org/D8864
|
|
---
|
|
.../kquickcontrolsaddons/mouseeventlistener.cpp | 30 ++++++++++++++++++++++
|
|
.../kquickcontrolsaddons/mouseeventlistener.h | 13 ++++++++++
|
|
2 files changed, 43 insertions(+)
|
|
|
|
diff --git a/src/qmlcontrols/kquickcontrolsaddons/mouseeventlistener.cpp b/src/qmlcontrols/kquickcontrolsaddons/mouseeventlistener.cpp
|
|
index 0b8d981..10aa2f7 100644
|
|
--- a/src/qmlcontrols/kquickcontrolsaddons/mouseeventlistener.cpp
|
|
+++ b/src/qmlcontrols/kquickcontrolsaddons/mouseeventlistener.cpp
|
|
@@ -171,6 +171,11 @@ void MouseEventListener::mousePressEvent(QMouseEvent *me)
|
|
emit pressed(&dme);
|
|
emit pressedChanged();
|
|
|
|
+ if (dme.isAccepted()) {
|
|
+ me->setAccepted(true);
|
|
+ return;
|
|
+ }
|
|
+
|
|
m_pressAndHoldTimer->start(QGuiApplication::styleHints()->mousePressAndHoldInterval());
|
|
}
|
|
|
|
@@ -187,6 +192,10 @@ void MouseEventListener::mouseMoveEvent(QMouseEvent *me)
|
|
|
|
KDeclarativeMouseEvent dme(me->pos().x(), me->pos().y(), me->screenPos().x(), me->screenPos().y(), me->button(), me->buttons(), me->modifiers(), screenForGlobalPos(me->globalPos()));
|
|
emit positionChanged(&dme);
|
|
+
|
|
+ if (dme.isAccepted()) {
|
|
+ me->setAccepted(true);
|
|
+ }
|
|
}
|
|
|
|
void MouseEventListener::mouseReleaseEvent(QMouseEvent *me)
|
|
@@ -205,6 +214,10 @@ void MouseEventListener::mouseReleaseEvent(QMouseEvent *me)
|
|
emit clicked(&dme);
|
|
m_pressAndHoldTimer->stop();
|
|
}
|
|
+
|
|
+ if (dme.isAccepted()) {
|
|
+ me->setAccepted(true);
|
|
+ }
|
|
}
|
|
|
|
void MouseEventListener::wheelEvent(QWheelEvent *we)
|
|
@@ -260,7 +273,12 @@ bool MouseEventListener::childMouseEventFilter(QQuickItem *item, QEvent *event)
|
|
emit pressed(&dme);
|
|
emit pressedChanged();
|
|
|
|
+ if (dme.isAccepted()) {
|
|
+ return true;
|
|
+ }
|
|
+
|
|
m_pressAndHoldTimer->start(QGuiApplication::styleHints()->mousePressAndHoldInterval());
|
|
+
|
|
break;
|
|
}
|
|
case QEvent::HoverMove: {
|
|
@@ -280,6 +298,10 @@ bool MouseEventListener::childMouseEventFilter(QQuickItem *item, QEvent *event)
|
|
KDeclarativeMouseEvent dme(myPos.x(), myPos.y(), screenPos.x(), screenPos.y(), Qt::NoButton, Qt::NoButton, he->modifiers(), nullptr);
|
|
//qDebug() << "positionChanged..." << dme.x() << dme.y();
|
|
emit positionChanged(&dme);
|
|
+
|
|
+ if (dme.isAccepted()) {
|
|
+ return true;
|
|
+ }
|
|
break;
|
|
}
|
|
case QEvent::MouseMove: {
|
|
@@ -304,6 +326,10 @@ bool MouseEventListener::childMouseEventFilter(QQuickItem *item, QEvent *event)
|
|
m_pressAndHoldEvent = new KDeclarativeMouseEvent(myPos.x(), myPos.y(), me->screenPos().x(), me->screenPos().y(), me->button(), me->buttons(), me->modifiers(), screenForGlobalPos(me->globalPos()));
|
|
}
|
|
emit positionChanged(&dme);
|
|
+
|
|
+ if (dme.isAccepted()) {
|
|
+ return true;
|
|
+ }
|
|
break;
|
|
}
|
|
case QEvent::MouseButtonRelease: {
|
|
@@ -321,6 +347,10 @@ bool MouseEventListener::childMouseEventFilter(QQuickItem *item, QEvent *event)
|
|
emit clicked(&dme);
|
|
m_pressAndHoldTimer->stop();
|
|
}
|
|
+
|
|
+ if (dme.isAccepted()) {
|
|
+ return true;
|
|
+ }
|
|
break;
|
|
}
|
|
case QEvent::UngrabMouse: {
|
|
diff --git a/src/qmlcontrols/kquickcontrolsaddons/mouseeventlistener.h b/src/qmlcontrols/kquickcontrolsaddons/mouseeventlistener.h
|
|
index 2799fda..c34ca25 100644
|
|
--- a/src/qmlcontrols/kquickcontrolsaddons/mouseeventlistener.h
|
|
+++ b/src/qmlcontrols/kquickcontrolsaddons/mouseeventlistener.h
|
|
@@ -43,6 +43,7 @@ class KDeclarativeMouseEvent : public QObject
|
|
Q_PROPERTY(Qt::MouseButtons buttons READ buttons)
|
|
Q_PROPERTY(Qt::KeyboardModifiers modifiers READ modifiers)
|
|
Q_PROPERTY(QScreen* screen READ screen CONSTANT)
|
|
+ Q_PROPERTY(bool accepted READ isAccepted WRITE setAccepted NOTIFY acceptedChanged)
|
|
|
|
public:
|
|
KDeclarativeMouseEvent(int x, int y, int screenX, int screenY,
|
|
@@ -69,10 +70,21 @@ public:
|
|
Qt::KeyboardModifiers modifiers() const { return m_modifiers; }
|
|
QScreen* screen() const { return m_screen; }
|
|
|
|
+ bool isAccepted() const { return m_accepted; }
|
|
+ void setAccepted(bool accepted) {
|
|
+ if (m_accepted != accepted) {
|
|
+ m_accepted = accepted;
|
|
+ emit acceptedChanged();
|
|
+ }
|
|
+ }
|
|
+
|
|
// only for internal usage
|
|
void setX(int x) { m_x = x; }
|
|
void setY(int y) { m_y = y; }
|
|
|
|
+Q_SIGNALS:
|
|
+ void acceptedChanged();
|
|
+
|
|
private:
|
|
int m_x;
|
|
int m_y;
|
|
@@ -82,6 +94,7 @@ private:
|
|
Qt::MouseButtons m_buttons;
|
|
Qt::KeyboardModifiers m_modifiers;
|
|
QScreen *m_screen;
|
|
+ bool m_accepted = false;
|
|
};
|
|
|
|
class KDeclarativeWheelEvent : public QObject
|
|
--
|
|
cgit v0.11.2
|
|
|