From 87cabd0b92bc348f73be2fe0a20a57fa485f6665 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Wed, 28 Sep 2022 21:25:53 +0200 Subject: [PATCH] Add QStyleHints::keyboardAutoRepeatRateF() The keyboardAutoRepeatRate() function returning an int assumes the rate can not be lower than one event per second, but this is not always the case, e.g. on macOS where the slowest setting for key repeat results in a two second delay between events. Change-Id: I806fb57883ce0085c835fb0a43d6b86bd6da375a Reviewed-by: Volker Hilsheimer --- src/gui/kernel/qstylehints.cpp | 13 +++++++++++++ src/gui/kernel/qstylehints.h | 5 +++++ src/widgets/widgets/qabstractspinbox.cpp | 2 +- src/widgets/widgets/qabstractspinbox_p.h | 2 +- 4 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/gui/kernel/qstylehints.cpp b/src/gui/kernel/qstylehints.cpp index 6819aeaf2e6..8374379d5a5 100644 --- a/src/gui/kernel/qstylehints.cpp +++ b/src/gui/kernel/qstylehints.cpp @@ -278,15 +278,28 @@ 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 Use keyboardAutoRepeatRateF() instead */ int QStyleHints::keyboardAutoRepeatRate() const { return themeableHint(QPlatformTheme::KeyboardAutoRepeatRate, QPlatformIntegration::KeyboardAutoRepeatRate).toInt(); } +#endif + +/*! + \property QStyleHints::keyboardAutoRepeatRateF + \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. diff --git a/src/gui/kernel/qstylehints.h b/src/gui/kernel/qstylehints.h index e32d9b5df3f..37e742a24dd 100644 --- a/src/gui/kernel/qstylehints.h +++ b/src/gui/kernel/qstylehints.h @@ -20,6 +20,7 @@ class Q_GUI_EXPORT QStyleHints : public QObject Q_PROPERTY(int cursorFlashTime READ cursorFlashTime NOTIFY cursorFlashTimeChanged FINAL) Q_PROPERTY(qreal fontSmoothingGamma READ fontSmoothingGamma STORED false CONSTANT FINAL) Q_PROPERTY(int keyboardAutoRepeatRate READ keyboardAutoRepeatRate STORED false CONSTANT FINAL) + Q_PROPERTY(int keyboardAutoRepeatRateF READ keyboardAutoRepeatRateF STORED false CONSTANT FINAL) Q_PROPERTY(int keyboardInputInterval READ keyboardInputInterval NOTIFY keyboardInputIntervalChanged FINAL) Q_PROPERTY(int mouseDoubleClickInterval READ mouseDoubleClickInterval @@ -65,7 +66,11 @@ public: int startDragVelocity() const; void setKeyboardInputInterval(int keyboardInputInterval); int keyboardInputInterval() const; +#if QT_DEPRECATED_SINCE(6, 5) + QT_DEPRECATED_VERSION_X_6_5("Use keyboardAutoRepeatRateF() instead") int keyboardAutoRepeatRate() const; +#endif + qreal keyboardAutoRepeatRateF() const; void setCursorFlashTime(int cursorFlashTime); int cursorFlashTime() const; bool showIsFullScreen() const; diff --git a/src/widgets/widgets/qabstractspinbox.cpp b/src/widgets/widgets/qabstractspinbox.cpp index ff41a72fcae..b0552008b50 100644 --- a/src/widgets/widgets/qabstractspinbox.cpp +++ b/src/widgets/widgets/qabstractspinbox.cpp @@ -1236,7 +1236,7 @@ void QAbstractSpinBox::timerEvent(QTimerEvent *event) killTimer(d->spinClickThresholdTimerId); d->spinClickThresholdTimerId = -1; d->effectiveSpinRepeatRate = d->buttonState & Keyboard - ? QGuiApplication::styleHints()->keyboardAutoRepeatRate() + ? QGuiApplication::styleHints()->keyboardAutoRepeatRateF() : d->spinClickTimerInterval; d->spinClickTimerId = startTimer(d->effectiveSpinRepeatRate); doStep = true; diff --git a/src/widgets/widgets/qabstractspinbox_p.h b/src/widgets/widgets/qabstractspinbox_p.h index be91917832c..efc23586cf4 100644 --- a/src/widgets/widgets/qabstractspinbox_p.h +++ b/src/widgets/widgets/qabstractspinbox_p.h @@ -102,7 +102,7 @@ public: int spinClickTimerInterval = 100; int spinClickThresholdTimerId = -1; int spinClickThresholdTimerInterval = -1; - int effectiveSpinRepeatRate = 1; + qreal effectiveSpinRepeatRate = 1; int acceleration = 0; int wheelDeltaRemainder = 0;