diff options
| author | J-P Nurmi <[email protected]> | 2016-06-29 15:58:23 +0200 |
|---|---|---|
| committer | J-P Nurmi <[email protected]> | 2016-07-20 18:33:59 +0000 |
| commit | 4e6dd1c50a08877189891806ed0dc977aafceade (patch) | |
| tree | 69753811900e27ec3910cfce03a4e541cbee3038 /src/gui/kernel | |
| parent | 494ced13292fa9d7b572f5310090f6b8fab36e26 (diff) | |
Add QStyleHints::useHoverEffects
The delivery of hover events creates unnecessary overhead on touch
platforms. This allows Qt Quick Controls 2 to determine whether the
underlying platform wants hover effects. The hover effects are enabled
by default for the classic desktop platforms: Linux, Windows & macOS.
Change-Id: Ia4e7b5c0fcb7af8f1c47e06fb28086cffdf35976
Task-number: QTBUG-50003
Reviewed-by: Friedemann Kleint <[email protected]>
Reviewed-by: Mitch Curtis <[email protected]>
Reviewed-by: Shawn Rutledge <[email protected]>
Diffstat (limited to 'src/gui/kernel')
| -rw-r--r-- | src/gui/kernel/qplatformintegration.cpp | 2 | ||||
| -rw-r--r-- | src/gui/kernel/qplatformintegration.h | 3 | ||||
| -rw-r--r-- | src/gui/kernel/qplatformtheme.cpp | 2 | ||||
| -rw-r--r-- | src/gui/kernel/qplatformtheme.h | 3 | ||||
| -rw-r--r-- | src/gui/kernel/qstylehints.cpp | 32 | ||||
| -rw-r--r-- | src/gui/kernel/qstylehints.h | 4 |
6 files changed, 44 insertions, 2 deletions
diff --git a/src/gui/kernel/qplatformintegration.cpp b/src/gui/kernel/qplatformintegration.cpp index 3490e786a83..5bf0df67dbb 100644 --- a/src/gui/kernel/qplatformintegration.cpp +++ b/src/gui/kernel/qplatformintegration.cpp @@ -402,6 +402,8 @@ QVariant QPlatformIntegration::styleHint(StyleHint hint) const return true; case ItemViewActivateItemOnSingleClick: return QPlatformTheme::defaultThemeHint(QPlatformTheme::ItemViewActivateItemOnSingleClick); + case UiEffects: + return QPlatformTheme::defaultThemeHint(QPlatformTheme::UiEffects); } return 0; diff --git a/src/gui/kernel/qplatformintegration.h b/src/gui/kernel/qplatformintegration.h index 8754ff555f8..22a834f0e11 100644 --- a/src/gui/kernel/qplatformintegration.h +++ b/src/gui/kernel/qplatformintegration.h @@ -156,7 +156,8 @@ public: MousePressAndHoldInterval, TabFocusBehavior, ReplayMousePressOutsidePopup, - ItemViewActivateItemOnSingleClick + ItemViewActivateItemOnSingleClick, + UiEffects }; virtual QVariant styleHint(StyleHint hint) const; diff --git a/src/gui/kernel/qplatformtheme.cpp b/src/gui/kernel/qplatformtheme.cpp index 7f74959a60e..32ad0574528 100644 --- a/src/gui/kernel/qplatformtheme.cpp +++ b/src/gui/kernel/qplatformtheme.cpp @@ -444,6 +444,8 @@ QVariant QPlatformTheme::themeHint(ThemeHint hint) const return QGuiApplicationPrivate::platformIntegration()->styleHint(QPlatformIntegration::MousePressAndHoldInterval); case QPlatformTheme::ItemViewActivateItemOnSingleClick: return QGuiApplicationPrivate::platformIntegration()->styleHint(QPlatformIntegration::ItemViewActivateItemOnSingleClick); + case QPlatformTheme::UiEffects: + return QGuiApplicationPrivate::platformIntegration()->styleHint(QPlatformIntegration::UiEffects); default: return QPlatformTheme::defaultThemeHint(hint); } diff --git a/src/gui/kernel/qplatformtheme.h b/src/gui/kernel/qplatformtheme.h index a5bd8b24ba6..b16fdd7939d 100644 --- a/src/gui/kernel/qplatformtheme.h +++ b/src/gui/kernel/qplatformtheme.h @@ -270,7 +270,8 @@ public: AnimateComboUiEffect = 0x8, AnimateTooltipUiEffect = 0x10, FadeTooltipUiEffect = 0x20, - AnimateToolBoxUiEffect = 0x40 + AnimateToolBoxUiEffect = 0x40, + HoverEffect = 0x80 }; enum IconOption { diff --git a/src/gui/kernel/qstylehints.cpp b/src/gui/kernel/qstylehints.cpp index ecc2886a044..7ccf1d86b08 100644 --- a/src/gui/kernel/qstylehints.cpp +++ b/src/gui/kernel/qstylehints.cpp @@ -77,6 +77,7 @@ public: , m_keyboardInputInterval(-1) , m_cursorFlashTime(-1) , m_tabFocusBehavior(-1) + , m_uiEffects(-1) {} int m_mouseDoubleClickInterval; @@ -86,6 +87,7 @@ public: int m_keyboardInputInterval; int m_cursorFlashTime; int m_tabFocusBehavior; + int m_uiEffects; }; /*! @@ -451,4 +453,34 @@ bool QStyleHints::singleClickActivation() const return themeableHint(QPlatformTheme::ItemViewActivateItemOnSingleClick, QPlatformIntegration::ItemViewActivateItemOnSingleClick).toBool(); } +/*! + \property QStyleHints::useHoverEffects + \brief \c true if UI elements should use hover effects. This is the + standard behavior on desktop platforms with a mouse pointer, whereas + on touch platforms the overhead of hover event delivery can be avoided. + + \since 5.8 +*/ +bool QStyleHints::useHoverEffects() const +{ + Q_D(const QStyleHints); + return (d->m_uiEffects >= 0 ? + d->m_uiEffects : + themeableHint(QPlatformTheme::UiEffects, QPlatformIntegration::UiEffects).toInt()) & QPlatformTheme::HoverEffect; +} + +void QStyleHints::setUseHoverEffects(bool useHoverEffects) +{ + Q_D(QStyleHints); + if (d->m_uiEffects >= 0 && useHoverEffects == bool(d->m_uiEffects & QPlatformTheme::HoverEffect)) + return; + if (d->m_uiEffects == -1) + d->m_uiEffects = 0; + if (useHoverEffects) + d->m_uiEffects |= QPlatformTheme::HoverEffect; + else + d->m_uiEffects &= ~QPlatformTheme::HoverEffect; + emit useHoverEffectsChanged(useHoverEffects); +} + QT_END_NAMESPACE diff --git a/src/gui/kernel/qstylehints.h b/src/gui/kernel/qstylehints.h index 7be8b3a33a0..fb55cc7ed67 100644 --- a/src/gui/kernel/qstylehints.h +++ b/src/gui/kernel/qstylehints.h @@ -70,6 +70,7 @@ class Q_GUI_EXPORT QStyleHints : public QObject Q_PROPERTY(bool useRtlExtensions READ useRtlExtensions STORED false CONSTANT FINAL) Q_PROPERTY(Qt::TabFocusBehavior tabFocusBehavior READ tabFocusBehavior NOTIFY tabFocusBehaviorChanged FINAL) Q_PROPERTY(bool singleClickActivation READ singleClickActivation STORED false CONSTANT FINAL) + Q_PROPERTY(bool useHoverEffects READ useHoverEffects WRITE setUseHoverEffects NOTIFY useHoverEffectsChanged FINAL) public: void setMouseDoubleClickInterval(int mouseDoubleClickInterval); @@ -96,6 +97,8 @@ public: Qt::TabFocusBehavior tabFocusBehavior() const; void setTabFocusBehavior(Qt::TabFocusBehavior tabFocusBehavior); bool singleClickActivation() const; + bool useHoverEffects() const; + void setUseHoverEffects(bool useHoverEffects); Q_SIGNALS: void cursorFlashTimeChanged(int cursorFlashTime); @@ -105,6 +108,7 @@ Q_SIGNALS: void startDragDistanceChanged(int startDragDistance); void startDragTimeChanged(int startDragTime); void tabFocusBehaviorChanged(Qt::TabFocusBehavior tabFocusBehavior); + void useHoverEffectsChanged(bool useHoverEffects); private: friend class QGuiApplication; |
