diff options
author | Richard Moe Gustavsen <richard.gustavsen@theqtcompany.com> | 2016-04-18 10:02:16 +0200 |
---|---|---|
committer | Richard Moe Gustavsen <richard.gustavsen@theqtcompany.com> | 2016-04-21 13:15:15 +0000 |
commit | 597370b36487d2d2ed438db531f2d4aad4e55744 (patch) | |
tree | 79b6f2261c91cafd58a7f499042308b2cf3b8b7f | |
parent | 3c5e438890db63ecde98c84d221f87a3af52e1bf (diff) |
QQuickTextControlPrivate: Listen for changes to cursorFlashTime
cursorFlashTime will now change dynamically from QPA while platform
controlled text selection (on mobile) is ongoing. This patch
will therefore update QQuickTextControlPrivate so that it listens to the
cursorFlashTimeChanged signal and changes the blinking rate when
triggered.
Change-Id: Ifea202bc9f57af8c5959594eb50f2aacff284d68
Reviewed-by: Jan Arve Sæther <jan-arve.saether@theqtcompany.com>
-rw-r--r-- | src/quick/items/qquicktextcontrol.cpp | 27 | ||||
-rw-r--r-- | src/quick/items/qquicktextcontrol_p_p.h | 2 |
2 files changed, 24 insertions, 5 deletions
diff --git a/src/quick/items/qquicktextcontrol.cpp b/src/quick/items/qquicktextcontrol.cpp index e2f4d51542..0cee9c7d27 100644 --- a/src/quick/items/qquicktextcontrol.cpp +++ b/src/quick/items/qquicktextcontrol.cpp @@ -108,6 +108,7 @@ QQuickTextControlPrivate::QQuickTextControlPrivate() overwriteMode(false), acceptRichText(true), cursorVisible(false), + cursorBlinkingEnabled(false), hasFocus(false), hadSelectionOnMousePress(false), wordSelectionEnabled(false), @@ -462,14 +463,30 @@ void QQuickTextControlPrivate::_q_updateCursorPosChanged(const QTextCursor &some void QQuickTextControlPrivate::setBlinkingCursorEnabled(bool enable) { - Q_Q(QQuickTextControl); + if (cursorBlinkingEnabled == enable) + return; + + cursorBlinkingEnabled = enable; + updateCursorFlashTime(); - if (enable && QGuiApplication::styleHints()->cursorFlashTime() > 0) - cursorBlinkTimer.start(QGuiApplication::styleHints()->cursorFlashTime() / 2, q); + if (enable) + connect(qApp->styleHints(), &QStyleHints::cursorFlashTimeChanged, this, &QQuickTextControlPrivate::updateCursorFlashTime); else - cursorBlinkTimer.stop(); + disconnect(qApp->styleHints(), &QStyleHints::cursorFlashTimeChanged, this, &QQuickTextControlPrivate::updateCursorFlashTime); +} - cursorOn = enable; +void QQuickTextControlPrivate::updateCursorFlashTime() +{ + // Note: cursorOn represents the current blinking state controlled by a timer, and + // should not be confused with cursorVisible or cursorBlinkingEnabled. However, we + // interpretate a cursorFlashTime of 0 to mean "always on, never blink". + cursorOn = true; + int flashTime = QGuiApplication::styleHints()->cursorFlashTime(); + + if (cursorBlinkingEnabled && flashTime >= 2) + cursorBlinkTimer.start(flashTime / 2, q_func()); + else + cursorBlinkTimer.stop(); repaintCursor(); } diff --git a/src/quick/items/qquicktextcontrol_p_p.h b/src/quick/items/qquicktextcontrol_p_p.h index f312fcb1ce..0f78feb5de 100644 --- a/src/quick/items/qquicktextcontrol_p_p.h +++ b/src/quick/items/qquicktextcontrol_p_p.h @@ -97,6 +97,7 @@ public: void _q_updateCursorPosChanged(const QTextCursor &someCursor); void setBlinkingCursorEnabled(bool enable); + void updateCursorFlashTime(); void extendWordwiseSelection(int suggestedNewPosition, qreal mouseXPosition); void extendBlockwiseSelection(int suggestedNewPosition); @@ -156,6 +157,7 @@ public: bool overwriteMode : 1; bool acceptRichText : 1; bool cursorVisible : 1; // used to hide the cursor in the preedit area + bool cursorBlinkingEnabled : 1; bool hasFocus : 1; bool hadSelectionOnMousePress : 1; bool wordSelectionEnabled : 1; |