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>
This commit is contained in:
Alexander Volkov 2019-03-28 17:32:23 +03:00
parent 5f4b03659b
commit ef3daddae1
3 changed files with 21 additions and 10 deletions

View File

@ -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)

View File

@ -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;

View File

@ -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);
}
}