aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel d'Andrada <daniel.dandrada@canonical.com>2012-12-19 15:31:16 -0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-01-09 18:42:42 +0100
commit1c522ec7c7f5e9755075f62866098b9a54b35739 (patch)
tree8560e9d4ff2996d1a12e506cceae2bf67c9120a1
parent5644e4f46c39964c0541d29740a9f741a0830f66 (diff)
Fix bug where a tap over stacked mouse areas generates a double click
You have two mouse areas, one on top of the other. 1 - You tap the top one. 2 - That top mouse area receives a mouse press event but doesn't accept it Expected outcome: 3 - the bottom mouse area gets clicked (besides press and release mouse events) Bogus outcome: 3 - the bottom mouse area gets double clicked. Change-Id: I10cac52b5e8edea781fe88e70c4092eb38bcf763 Reviewed-by: Shawn Rutledge <shawn.rutledge@digia.com>
-rw-r--r--src/quick/items/qquickwindow.cpp29
-rw-r--r--src/quick/items/qquickwindow_p.h1
2 files changed, 25 insertions, 5 deletions
diff --git a/src/quick/items/qquickwindow.cpp b/src/quick/items/qquickwindow.cpp
index 2cde3cc434..ccb95e6ea9 100644
--- a/src/quick/items/qquickwindow.cpp
+++ b/src/quick/items/qquickwindow.cpp
@@ -447,6 +447,29 @@ static QMouseEvent *touchToMouseEvent(QEvent::Type type, const QTouchEvent::Touc
return me;
}
+bool QQuickWindowPrivate::checkIfDoubleClicked(ulong newPressEventTimestamp)
+{
+ bool doubleClicked;
+
+ if (touchMousePressTimestamp == 0) {
+ // just initialize the variable
+ touchMousePressTimestamp = newPressEventTimestamp;
+ doubleClicked = false;
+ } else {
+ ulong timeBetweenPresses = newPressEventTimestamp - touchMousePressTimestamp;
+ ulong doubleClickInterval = static_cast<ulong>(qApp->styleHints()->
+ mouseDoubleClickInterval());
+ doubleClicked = timeBetweenPresses < doubleClickInterval;
+ if (doubleClicked) {
+ touchMousePressTimestamp = 0;
+ } else {
+ touchMousePressTimestamp = newPressEventTimestamp;
+ }
+ }
+
+ return doubleClicked;
+}
+
bool QQuickWindowPrivate::translateTouchToMouse(QQuickItem *item, QTouchEvent *event)
{
Q_Q(QQuickWindow);
@@ -463,9 +486,6 @@ bool QQuickWindowPrivate::translateTouchToMouse(QQuickItem *item, QTouchEvent *e
if (!item->contains(pos))
break;
- bool doubleClick = event->timestamp() - touchMousePressTimestamp
- < static_cast<ulong>(qApp->styleHints()->mouseDoubleClickInterval());
- touchMousePressTimestamp = event->timestamp();
// Store the id already here and restore it to -1 if the event does not get
// accepted. Cannot defer setting the new value because otherwise if the event
// handler spins the event loop all subsequent moves and releases get lost.
@@ -489,8 +509,7 @@ bool QQuickWindowPrivate::translateTouchToMouse(QQuickItem *item, QTouchEvent *e
item->ungrabMouse();
}
- if (doubleClick && mousePress->isAccepted()) {
- touchMousePressTimestamp = 0;
+ if (mousePress->isAccepted() && checkIfDoubleClicked(event->timestamp())) {
QScopedPointer<QMouseEvent> mouseDoubleClick(touchToMouseEvent(QEvent::MouseButtonDblClick, p, event, item));
q->sendEvent(item, mouseDoubleClick.data());
event->setAccepted(mouseDoubleClick->isAccepted());
diff --git a/src/quick/items/qquickwindow_p.h b/src/quick/items/qquickwindow_p.h
index c8ecd43238..a70d972499 100644
--- a/src/quick/items/qquickwindow_p.h
+++ b/src/quick/items/qquickwindow_p.h
@@ -120,6 +120,7 @@ public:
QQuickDragGrabber dragGrabber;
#endif
int touchMouseId;
+ bool checkIfDoubleClicked(ulong newPressEventTimestamp);
ulong touchMousePressTimestamp;
// Mouse positions are saved in widget coordinates