Skip to content
This repository has been archived by the owner on Jun 8, 2021. It is now read-only.

Commit

Permalink
platformtheme: Implement DoubleClick/DoubleTap distances
Browse files Browse the repository at this point in the history
In Qt 5.12.4[1], Qt started checking for the distance between two clicks
or taps when deciding whether a Clicked event should become a
DoubleClicked event. The default distance in Qt 5.12.9 is 5 pixels
horizontally or vertically from the initial click point. The double tap
distance is defined as twice the double click distance[2].

We can use the DPI value of the screen to determine a likely value of
.15 (3/20) of an inch for distance between click events, and .30 of an
inch for touch events. These values, and most of the implementation,
were taken from the Android QPA[3].

Fixes ubports/keyboard-component#159
Fixes ubports/keyboard-component#158

[1] qt/qtdeclarative@56fbc27
[2] https://github.com/qt/qtbase/blob/5.12.9/src/gui/kernel/qplatformtheme.cpp#L548-L563
[3]https://github.com/qt/qtbase/blob/v5.12.9/src/plugins/platforms/android/qandroidplatformtheme.cpp#L469
  • Loading branch information
UniversalSuperBox committed Mar 5, 2021
1 parent f7b6791 commit 080035d
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/shared/ubuntutheme.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

#include <QVariant>
#include <QtThemeSupport/private/qgenericunixthemes_p.h>
#include <QGuiApplication>
#include <QScreen>

class UbuntuTheme : public QGenericUnixTheme
{
Expand All @@ -40,6 +42,22 @@ class UbuntuTheme : public QGenericUnixTheme
return iconTheme;
}
}
case QPlatformTheme::MouseDoubleClickDistance: {
// Impl mostly yoinked from the QAndroidPlatformTheme
QScreen *screen = qGuiApp->primaryScreen();
if (screen) {
qreal dotsPerInch = screen->physicalDotsPerInch();
// Allow 15% of an inch between taps when double clicking
return qRound(dotsPerInch * 0.15);
} else {
return 5;
}
}
case QPlatformTheme::TouchDoubleTapDistance: {
bool ok = false;
int dist = themeHint(QPlatformTheme::MouseDoubleClickDistance).toInt(&ok) * 2;
return QVariant(ok ? dist : 10);
}
default:
break;
}
Expand Down

0 comments on commit 080035d

Please sign in to comment.