summaryrefslogtreecommitdiffstats
path: root/src/gui/kernel/qstylehints.cpp
diff options
context:
space:
mode:
authorShawn Rutledge <shawn.rutledge@qt.io>2019-07-08 14:59:43 +0200
committerShawn Rutledge <shawn.rutledge@qt.io>2019-07-08 20:29:17 +0200
commit8f75910deaf5a41506dc5cb0fe412a8f4674be0d (patch)
tree361469a377b0762e4668960ce4b3896df86400c9 /src/gui/kernel/qstylehints.cpp
parent6c136973fd9b82420c818668086abe93f534993d (diff)
Add mouseDoubleClickDistance and touchDoubleTapDistance to QStyleHints
Amends ca280bfe3bc551f814d59d25079e098798fbdad7 and 705e3f68df83dca165e3cddb914d3816155323f8 which added these enums only to QPlatformTheme::ThemeHint but not to QPlatformIntegration::StyleHint. Those patches did not add accessors to QStyleHints, probably because the accessors in QStyleHints use the themeableHint() function which takes both enums; so to have an accessor implemented this way, we need it in both enums. But it's getting too silly, since the only platform plugin that modifies MouseDoubleClickDistance is Android, implemented by QAndroidPlatformTheme overriding QPlatformTheme::themeHint(), and thus illustrating that adding the enum to QPlatformIntegration::StyleHint is not the only way to allow a platform plugin to customize the hint. So it seems we need a new way of writing these accessors without needing to duplicate the enum value in QPlatformIntegration::StyleHint. The new version of themeableHint(QPlatformTheme::ThemeHint) falls back on the static QPlatformTheme::defaultThemeHint() accessor. Users should at least be able to see what the default value is; and having these getters will also provide link targets for QtQuick's TapHandler docs. Change-Id: I0f8560062bcd0ca5e6d580071d9fbcf3f07f625f Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Diffstat (limited to 'src/gui/kernel/qstylehints.cpp')
-rw-r--r--src/gui/kernel/qstylehints.cpp44
1 files changed, 44 insertions, 0 deletions
diff --git a/src/gui/kernel/qstylehints.cpp b/src/gui/kernel/qstylehints.cpp
index 9b5b7a6f1e..732ede90d0 100644
--- a/src/gui/kernel/qstylehints.cpp
+++ b/src/gui/kernel/qstylehints.cpp
@@ -65,6 +65,20 @@ static inline QVariant themeableHint(QPlatformTheme::ThemeHint th,
return QGuiApplicationPrivate::platformIntegration()->styleHint(ih);
}
+static inline QVariant themeableHint(QPlatformTheme::ThemeHint th)
+{
+ if (!QCoreApplication::instance()) {
+ qWarning("Must construct a QGuiApplication before accessing a platform theme hint.");
+ return QVariant();
+ }
+ if (const QPlatformTheme *theme = QGuiApplicationPrivate::platformTheme()) {
+ const QVariant themeHint = theme->themeHint(th);
+ if (themeHint.isValid())
+ return themeHint;
+ }
+ return QPlatformTheme::defaultThemeHint(th);
+}
+
class QStyleHintsPrivate : public QObjectPrivate
{
Q_DECLARE_PUBLIC(QStyleHints)
@@ -80,6 +94,8 @@ public:
int m_showShortcutsInContextMenus = -1;
int m_wheelScrollLines = -1;
int m_mouseQuickSelectionThreshold = -1;
+ int m_mouseDoubleClickDistance = -1;
+ int m_touchDoubleTapDistance = -1;
};
/*!
@@ -133,6 +149,34 @@ int QStyleHints::mouseDoubleClickInterval() const
}
/*!
+ \property QStyleHints::mouseDoubleClickDistance
+ \brief the maximum distance, in pixels, that the mouse can be moved between
+ two consecutive mouse clicks and still have it detected as a double-click
+ \since 5.14
+*/
+int QStyleHints::mouseDoubleClickDistance() const
+{
+ Q_D(const QStyleHints);
+ return d->m_mouseDoubleClickDistance >= 0 ?
+ d->m_mouseDoubleClickDistance :
+ themeableHint(QPlatformTheme::MouseDoubleClickDistance).toInt();
+}
+
+/*!
+ \property QStyleHints::touchDoubleTapDistance
+ \brief the maximum distance, in pixels, that a finger can be moved between
+ two consecutive taps and still have it detected as a double-tap
+ \since 5.14
+*/
+int QStyleHints::touchDoubleTapDistance() const
+{
+ Q_D(const QStyleHints);
+ return d->m_touchDoubleTapDistance >= 0 ?
+ d->m_touchDoubleTapDistance :
+ themeableHint(QPlatformTheme::TouchDoubleTapDistance).toInt();
+}
+
+/*!
Sets the \a mousePressAndHoldInterval.
\internal
\sa mousePressAndHoldInterval()