From 597370b36487d2d2ed438db531f2d4aad4e55744 Mon Sep 17 00:00:00 2001 From: Richard Moe Gustavsen Date: Mon, 18 Apr 2016 10:02:16 +0200 Subject: QQuickTextControlPrivate: Listen for changes to cursorFlashTime MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- src/quick/items/qquicktextcontrol.cpp | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) (limited to 'src/quick/items/qquicktextcontrol.cpp') 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(); } -- cgit v1.2.3