Skip to content

Commit

Permalink
Add mouseDoubleClickDistance and touchDoubleTapDistance to QStyleHints
Browse files Browse the repository at this point in the history
Amends ca280bf and
705e3f6 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ø <[email protected]>
  • Loading branch information
ec1oud committed Jul 8, 2019
1 parent 6c13697 commit 8f75910
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
44 changes: 44 additions & 0 deletions src/gui/kernel/qstylehints.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -80,6 +94,8 @@ class QStyleHintsPrivate : public QObjectPrivate
int m_showShortcutsInContextMenus = -1;
int m_wheelScrollLines = -1;
int m_mouseQuickSelectionThreshold = -1;
int m_mouseDoubleClickDistance = -1;
int m_touchDoubleTapDistance = -1;
};

/*!
Expand Down Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions src/gui/kernel/qstylehints.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 8f75910

Please sign in to comment.