summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexander Volkov <a.volkov@rusbitech.ru>2019-03-28 17:32:23 +0300
committerAlexander Volkov <a.volkov@rusbitech.ru>2019-05-01 20:29:16 +0000
commitef3daddae1720956e746142ac7ee54a27b9299d7 (patch)
treea2dfe70653fc6d4a0b55be135e57a1c42af7a948
parent5f4b03659b1e2318acb87fd9bf7325f707dfa0ad (diff)
Use QPlatformTheme::TouchDoubleTapDistance for touch events
... and update the cached values on theme change. Modify tst_QWidget::touchEventSynthesizedMouseEvent() to avoid unexpected double click detection. Change-Id: I151c47e851ebba7550b1b09caca2781c28d7d3d9 Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
-rw-r--r--src/gui/kernel/qguiapplication.cpp20
-rw-r--r--src/gui/kernel/qguiapplication_p.h1
-rw-r--r--tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp10
3 files changed, 21 insertions, 10 deletions
diff --git a/src/gui/kernel/qguiapplication.cpp b/src/gui/kernel/qguiapplication.cpp
index 424af20f26..a67214bd9a 100644
--- a/src/gui/kernel/qguiapplication.cpp
+++ b/src/gui/kernel/qguiapplication.cpp
@@ -181,7 +181,9 @@ ulong QGuiApplicationPrivate::mousePressTime = 0;
Qt::MouseButton QGuiApplicationPrivate::mousePressButton = Qt::NoButton;
int QGuiApplicationPrivate::mousePressX = 0;
int QGuiApplicationPrivate::mousePressY = 0;
-int QGuiApplicationPrivate::mouse_double_click_distance = -1;
+
+static int mouseDoubleClickDistance = -1;
+static int touchDoubleTapDistance = -1;
QWindow *QGuiApplicationPrivate::currentMousePressWindow = 0;
@@ -257,6 +259,12 @@ static inline void clearFontUnlocked()
QGuiApplicationPrivate::app_font = 0;
}
+static void initThemeHints()
+{
+ mouseDoubleClickDistance = QGuiApplicationPrivate::platformTheme()->themeHint(QPlatformTheme::MouseDoubleClickDistance).toInt();
+ touchDoubleTapDistance = QGuiApplicationPrivate::platformTheme()->themeHint(QPlatformTheme::TouchDoubleTapDistance).toInt();
+}
+
static bool checkNeedPortalSupport()
{
#if QT_CONFIG(dbus)
@@ -1519,8 +1527,7 @@ void QGuiApplicationPrivate::init()
initPalette();
QFont::initialize();
-
- mouse_double_click_distance = platformTheme()->themeHint(QPlatformTheme::MouseDoubleClickDistance).toInt();
+ initThemeHints();
#ifndef QT_NO_CURSOR
QCursorData::initialize();
@@ -2030,8 +2037,10 @@ void QGuiApplicationPrivate::processMouseEvent(QWindowSystemInterfacePrivate::Mo
if (mouseMove) {
QGuiApplicationPrivate::lastCursorPosition = globalPoint;
- if (qAbs(globalPoint.x() - mousePressX) > mouse_double_click_distance||
- qAbs(globalPoint.y() - mousePressY) > mouse_double_click_distance)
+ const auto doubleClickDistance = e->source == Qt::MouseEventNotSynthesized ?
+ mouseDoubleClickDistance : touchDoubleTapDistance;
+ if (qAbs(globalPoint.x() - mousePressX) > doubleClickDistance ||
+ qAbs(globalPoint.y() - mousePressY) > doubleClickDistance)
mousePressButton = Qt::NoButton;
} else {
mouse_buttons = e->buttons;
@@ -3988,6 +3997,7 @@ void QGuiApplicationPrivate::notifyThemeChanged()
clearFontUnlocked();
initFontUnlocked();
}
+ initThemeHints();
}
void QGuiApplicationPrivate::sendApplicationPaletteChange(bool toAllWidgets, const char *className)
diff --git a/src/gui/kernel/qguiapplication_p.h b/src/gui/kernel/qguiapplication_p.h
index 042a36c31f..482d45e5c3 100644
--- a/src/gui/kernel/qguiapplication_p.h
+++ b/src/gui/kernel/qguiapplication_p.h
@@ -211,7 +211,6 @@ public:
static Qt::MouseButton mousePressButton;
static int mousePressX;
static int mousePressY;
- static int mouse_double_click_distance;
static QPointF lastCursorPosition;
static QWindow *currentMouseWindow;
static QWindow *currentMousePressWindow;
diff --git a/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp b/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp
index 3b9c9060fa..780cb01e40 100644
--- a/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp
+++ b/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp
@@ -10152,7 +10152,8 @@ void tst_QWidget::touchEventSynthesizedMouseEvent()
// We should see propagation of the TouchBegin into a MouseButtonPress
TouchMouseWidget parent;
TouchMouseWidget child(&parent);
- child.move(5, 5);
+ const QPoint childPos(5, 5);
+ child.move(childPos);
child.setAcceptMouse(false);
parent.show();
QVERIFY(QTest::qWaitForWindowExposed(parent.windowHandle()));
@@ -10161,13 +10162,14 @@ void tst_QWidget::touchEventSynthesizedMouseEvent()
QCOMPARE(child.m_touchEventCount, 0);
QCOMPARE(child.m_mouseEventCount, 0);
- QTest::touchEvent(parent.window(), m_touchScreen).press(0, QPoint(10, 10), &child);
+ const QPoint touchPos(20, 20);
+ QTest::touchEvent(parent.window(), m_touchScreen).press(0, touchPos, &child);
QCOMPARE(parent.m_touchEventCount, 0);
QCOMPARE(parent.m_mouseEventCount, 1);
- QCOMPARE(parent.m_lastMouseEventPos, QPointF(15, 15));
+ QCOMPARE(parent.m_lastMouseEventPos, childPos + touchPos);
QCOMPARE(child.m_touchEventCount, 0);
QCOMPARE(child.m_mouseEventCount, 1); // Attempt at mouse event before propagation
- QCOMPARE(child.m_lastMouseEventPos, QPointF(10, 10));
+ QCOMPARE(child.m_lastMouseEventPos, touchPos);
}
}