diff options
Diffstat (limited to 'src/gui/kernel/qstylehints.cpp')
-rw-r--r-- | src/gui/kernel/qstylehints.cpp | 131 |
1 files changed, 105 insertions, 26 deletions
diff --git a/src/gui/kernel/qstylehints.cpp b/src/gui/kernel/qstylehints.cpp index cb07888170..0d15d114ec 100644 --- a/src/gui/kernel/qstylehints.cpp +++ b/src/gui/kernel/qstylehints.cpp @@ -2,6 +2,7 @@ // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only #include <qstylehints.h> +#include "qstylehints_p.h" #include <qpa/qplatformintegration.h> #include <qpa/qplatformtheme.h> #include <private/qguiapplication_p.h> @@ -43,25 +44,6 @@ static inline QVariant themeableHint(QPlatformTheme::ThemeHint th) return QPlatformTheme::defaultThemeHint(th); } -class QStyleHintsPrivate : public QObjectPrivate -{ - Q_DECLARE_PUBLIC(QStyleHints) -public: - int m_mouseDoubleClickInterval = -1; - int m_mousePressAndHoldInterval = -1; - int m_startDragDistance = -1; - int m_startDragTime = -1; - int m_keyboardInputInterval = -1; - int m_cursorFlashTime = -1; - int m_tabFocusBehavior = -1; - int m_uiEffects = -1; - int m_showShortcutsInContextMenus = -1; - int m_wheelScrollLines = -1; - int m_mouseQuickSelectionThreshold = -1; - int m_mouseDoubleClickDistance = -1; - int m_touchDoubleTapDistance = -1; -}; - /*! \class QStyleHints \since 5.0 @@ -71,11 +53,10 @@ public: An object of this class, obtained from QGuiApplication, provides access to certain global user interface parameters of the current platform. - Access is read only; typically the platform itself provides the user a way to tune these - parameters. - - Access to these parameters are useful when implementing custom user interface components, in that - they allow the components to exhibit the same behaviour and feel as other components. + Access to most settings is read only. The platform itself usually provides the user with + ways to tune these parameters. Authors of custom user interface components should read + relevant settings to allow the components to exhibit the same behavior and feel as other + components. \sa QGuiApplication::styleHints() */ @@ -123,7 +104,7 @@ int QStyleHints::mouseDoubleClickDistance() const Q_D(const QStyleHints); return d->m_mouseDoubleClickDistance >= 0 ? d->m_mouseDoubleClickDistance : - themeableHint(QPlatformTheme::MouseDoubleClickDistance).toInt(); + themeableHint(QPlatformTheme::MouseDoubleClickDistance, QPlatformIntegration::MouseDoubleClickDistance).toInt(); } /*! @@ -141,6 +122,63 @@ int QStyleHints::touchDoubleTapDistance() const } /*! + \property QStyleHints::colorScheme + \brief the color scheme used by the application. + + By default, this follows the system's default color scheme (also known as appearance), + and changes when the system color scheme changes (e.g. during dusk or dawn). + Setting the color scheme to an explicit value will override the system setting and + ignore any changes to the system's color scheme. However, doing so is a hint to the + system, and overriding the color scheme is not supported on all platforms. + + Resetting this property, or setting it to \l{Qt::ColorScheme::Unknown}, will remove + the override and make the application follow the system default again. The property + value will change to the color scheme the system currently has. + + When this property changes, Qt will read the system palette and update the default + palette, but won't overwrite palette entries that have been explicitly set by the + application. When the colorSchemeChange() signal gets emitted, the old palette is + still in effect. + + Application-specific colors should be selected to work well with the effective + palette, taking the current color scheme into account. To update application- + specific colors when the effective palette changes, handle + \l{QEvent::}{PaletteChange} or \l{QEvent::}{ApplicationPaletteChange} events. + + \sa Qt::ColorScheme, QGuiApplication::palette(), QEvent::PaletteChange + \since 6.5 +*/ +Qt::ColorScheme QStyleHints::colorScheme() const +{ + Q_D(const QStyleHints); + return d->colorScheme(); +} + +/*! + \since 6.8 + + Sets the color scheme used by the application to an explicit \a scheme, or + revert to the system's current color scheme if \a scheme is Qt::ColorScheme::Unknown. +*/ +void QStyleHints::setColorScheme(Qt::ColorScheme scheme) +{ + if (!QCoreApplication::instance()) { + qWarning("Must construct a QGuiApplication before accessing a platform theme hint."); + return; + } + if (QPlatformTheme *theme = QGuiApplicationPrivate::platformTheme()) + theme->requestColorScheme(scheme); +} + +/*! + \fn void QStyleHints::unsetColorScheme() + \since 6.8 + + Restores the color scheme to the system's current color scheme. +*/ + + +/*! Sets the \a mousePressAndHoldInterval. \internal \sa mousePressAndHoldInterval() @@ -286,15 +324,29 @@ int QStyleHints::keyboardInputInterval() const themeableHint(QPlatformTheme::KeyboardInputInterval, QPlatformIntegration::KeyboardInputInterval).toInt(); } +#if QT_DEPRECATED_SINCE(6, 5) /*! \property QStyleHints::keyboardAutoRepeatRate \brief the rate, in events per second, in which additional repeated key presses will automatically be generated if a key is being held down. + \deprecated [6.5] Use keyboardAutoRepeatRateF() instead */ int QStyleHints::keyboardAutoRepeatRate() const { return themeableHint(QPlatformTheme::KeyboardAutoRepeatRate, QPlatformIntegration::KeyboardAutoRepeatRate).toInt(); } +#endif + +/*! + \property QStyleHints::keyboardAutoRepeatRateF + \since 6.5 + \brief the rate, in events per second, in which additional repeated key + presses will automatically be generated if a key is being held down. +*/ +qreal QStyleHints::keyboardAutoRepeatRateF() const +{ + return themeableHint(QPlatformTheme::KeyboardAutoRepeatRate, QPlatformIntegration::KeyboardAutoRepeatRate).toReal(); +} /*! Sets the \a cursorFlashTime. @@ -370,6 +422,8 @@ bool QStyleHints::showIsMaximized() const Since Qt 5.13, the setShowShortcutsInContextMenus() function can be used to override the platform default. + + \sa Qt::AA_DontShowShortcutsInContextMenus */ bool QStyleHints::showShortcutsInContextMenus() const { @@ -440,7 +494,7 @@ bool QStyleHints::useRtlExtensions() const */ bool QStyleHints::setFocusOnTouchRelease() const { - return hint(QPlatformIntegration::SetFocusOnTouchRelease).toBool(); + return themeableHint(QPlatformTheme::SetFocusOnTouchRelease, QPlatformIntegration::SetFocusOnTouchRelease).toBool(); } /*! @@ -584,6 +638,31 @@ int QStyleHints::mouseQuickSelectionThreshold() const return themeableHint(QPlatformTheme::MouseQuickSelectionThreshold, QPlatformIntegration::MouseQuickSelectionThreshold).toInt(); } +/*! + \internal + QStyleHintsPrivate::updateColorScheme - set a new color scheme. + + This function is called by the QPA plugin when the system theme changes. This in + turn might be the result of an explicit request of a color scheme via setColorScheme. + + Set \a colorScheme as the new color scheme of the QStyleHints. + The colorSchemeChanged signal will be emitted if present and new color scheme differ. + */ +void QStyleHintsPrivate::updateColorScheme(Qt::ColorScheme colorScheme) +{ + if (m_colorScheme == colorScheme) + return; + m_colorScheme = colorScheme; + Q_Q(QStyleHints); + emit q->colorSchemeChanged(colorScheme); +} + +QStyleHintsPrivate *QStyleHintsPrivate::get(QStyleHints *q) +{ + Q_ASSERT(q); + return q->d_func(); +} + QT_END_NAMESPACE #include "moc_qstylehints.cpp" |