Add mouseDoubleClickDistance and touchDoubleTapDistance to QStyleHints

Amends ca280bfe3b and
705e3f68df 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>
This commit is contained in:
Shawn Rutledge 2019-07-08 14:59:43 +02:00
parent 6c136973fd
commit 8f75910dea
2 changed files with 48 additions and 0 deletions

View File

@ -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;
};
/*!
@ -132,6 +148,34 @@ int QStyleHints::mouseDoubleClickInterval() const
themeableHint(QPlatformTheme::MouseDoubleClickInterval, QPlatformIntegration::MouseDoubleClickInterval).toInt();
}
/*!
\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

View File

@ -74,10 +74,14 @@ class Q_GUI_EXPORT QStyleHints : public QObject
Q_PROPERTY(bool useHoverEffects READ useHoverEffects WRITE setUseHoverEffects NOTIFY useHoverEffectsChanged FINAL)
Q_PROPERTY(int wheelScrollLines READ wheelScrollLines NOTIFY wheelScrollLinesChanged FINAL)
Q_PROPERTY(int mouseQuickSelectionThreshold READ mouseQuickSelectionThreshold WRITE setMouseQuickSelectionThreshold NOTIFY mouseQuickSelectionThresholdChanged FINAL)
Q_PROPERTY(int mouseDoubleClickDistance READ mouseDoubleClickDistance STORED false CONSTANT FINAL)
Q_PROPERTY(int touchDoubleTapDistance READ touchDoubleTapDistance STORED false CONSTANT FINAL)
public:
void setMouseDoubleClickInterval(int mouseDoubleClickInterval);
int mouseDoubleClickInterval() const;
int mouseDoubleClickDistance() const;
int touchDoubleTapDistance() const;
void setMousePressAndHoldInterval(int mousePressAndHoldInterval);
int mousePressAndHoldInterval() const;
void setStartDragDistance(int startDragDistance);