diff options
author | J-P Nurmi <jpnurmi@qt.io> | 2016-06-29 15:58:23 +0200 |
---|---|---|
committer | J-P Nurmi <jpnurmi@qt.io> | 2016-07-20 18:33:59 +0000 |
commit | 4e6dd1c50a08877189891806ed0dc977aafceade (patch) | |
tree | 69753811900e27ec3910cfce03a4e541cbee3038 | |
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 <Friedemann.Kleint@qt.io>
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
-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 | ||||
-rw-r--r-- | src/platformsupport/themes/genericunix/qgenericunixthemes.cpp | 2 | ||||
-rw-r--r-- | src/plugins/platforms/cocoa/qcocoatheme.mm | 2 | ||||
-rw-r--r-- | src/plugins/platforms/windows/qwindowstheme.cpp | 2 |
9 files changed, 49 insertions, 3 deletions
diff --git a/src/gui/kernel/qplatformintegration.cpp b/src/gui/kernel/qplatformintegration.cpp index 3490e786a8..5bf0df67db 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 8754ff555f..22a834f0e1 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 7f74959a60..32ad057452 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 a5bd8b24ba..b16fdd7939 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 ecc2886a04..7ccf1d86b0 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 7be8b3a33a..fb55cc7ed6 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; diff --git a/src/platformsupport/themes/genericunix/qgenericunixthemes.cpp b/src/platformsupport/themes/genericunix/qgenericunixthemes.cpp index 5e5c931c2c..32ca381b93 100644 --- a/src/platformsupport/themes/genericunix/qgenericunixthemes.cpp +++ b/src/platformsupport/themes/genericunix/qgenericunixthemes.cpp @@ -666,6 +666,8 @@ QVariant QGnomeTheme::themeHint(QPlatformTheme::ThemeHint hint) const return QVariant(int(GnomeKeyboardScheme)); case QPlatformTheme::PasswordMaskCharacter: return QVariant(QChar(0x2022)); + case QPlatformTheme::UiEffects: + return QVariant(int(HoverEffect)); default: break; } diff --git a/src/plugins/platforms/cocoa/qcocoatheme.mm b/src/plugins/platforms/cocoa/qcocoatheme.mm index 9e2fca23a1..aa9eb38384 100644 --- a/src/plugins/platforms/cocoa/qcocoatheme.mm +++ b/src/plugins/platforms/cocoa/qcocoatheme.mm @@ -329,6 +329,8 @@ QVariant QCocoaTheme::themeHint(ThemeHint hint) const } case QPlatformTheme::PasswordMaskCharacter: return QVariant(QChar(kBulletUnicode)); + case QPlatformTheme::UiEffects: + return QVariant(int(HoverEffect)); default: break; } diff --git a/src/plugins/platforms/windows/qwindowstheme.cpp b/src/plugins/platforms/windows/qwindowstheme.cpp index 6c6eb42d63..397da61604 100644 --- a/src/plugins/platforms/windows/qwindowstheme.cpp +++ b/src/plugins/platforms/windows/qwindowstheme.cpp @@ -347,7 +347,7 @@ static inline QStringList styleNames() static inline int uiEffects() { - int result = 0; + int result = QPlatformTheme::HoverEffect; if (booleanSystemParametersInfo(SPI_GETUIEFFECTS, false)) result |= QPlatformTheme::GeneralUiEffect; if (booleanSystemParametersInfo(SPI_GETMENUANIMATION, false)) |