diff options
author | Richard Moe Gustavsen <richard.gustavsen@theqtcompany.com> | 2016-04-19 12:50:47 +0200 |
---|---|---|
committer | Richard Moe Gustavsen <richard.gustavsen@theqtcompany.com> | 2016-04-25 05:56:13 +0000 |
commit | d3dcc6f610b97be7cbfbb0a65988e5940568c825 (patch) | |
tree | d06252a3f4cbbeb32f6d114af35bc7d38ae733a0 /src/widgets/widgets | |
parent | 2a740b9cf59b2a343d19b2a45614ee2827c98da2 (diff) |
QWidgetTextControl: respect run-time changes to cursorFlashTime
cursorFlashTime will now change dynamically from QPA while platform
controlled text selection (on mobile) is ongoing. This patch
will therefore update QWidgetTextControl so that it listens to the
cursorFlashTimeChanged signal and changes the blinking rate when
triggered.
Change-Id: I89bdfaab0e93d1d055baba6b132a7911d2ae84f6
Reviewed-by: Jan Arve Sæther <jan-arve.saether@theqtcompany.com>
Diffstat (limited to 'src/widgets/widgets')
-rw-r--r-- | src/widgets/widgets/qwidgettextcontrol.cpp | 26 | ||||
-rw-r--r-- | src/widgets/widgets/qwidgettextcontrol_p_p.h | 2 |
2 files changed, 22 insertions, 6 deletions
diff --git a/src/widgets/widgets/qwidgettextcontrol.cpp b/src/widgets/widgets/qwidgettextcontrol.cpp index cc1726c362..571563d29a 100644 --- a/src/widgets/widgets/qwidgettextcontrol.cpp +++ b/src/widgets/widgets/qwidgettextcontrol.cpp @@ -112,7 +112,7 @@ static QTextLine currentTextLine(const QTextCursor &cursor) } QWidgetTextControlPrivate::QWidgetTextControlPrivate() - : doc(0), cursorOn(false), cursorIsFocusIndicator(false), + : doc(0), cursorOn(false), blinkingEnabled(false), cursorIsFocusIndicator(false), #ifndef Q_OS_ANDROID interactionFlags(Qt::TextEditorInteraction), #else @@ -687,15 +687,29 @@ void QWidgetTextControlPrivate::_q_documentLayoutChanged() void QWidgetTextControlPrivate::setBlinkingCursorEnabled(bool enable) { - Q_Q(QWidgetTextControl); + if (blinkingEnabled == enable) + return; - if (enable && QApplication::cursorFlashTime() > 0) - cursorBlinkTimer.start(QApplication::cursorFlashTime() / 2, q); + blinkingEnabled = enable; + + if (enable) + connect(qApp->styleHints(), &QStyleHints::cursorFlashTimeChanged, this, &QWidgetTextControlPrivate::updateCursorBlinking); else - cursorBlinkTimer.stop(); + disconnect(qApp->styleHints(), &QStyleHints::cursorFlashTimeChanged, this, &QWidgetTextControlPrivate::updateCursorBlinking); + + updateCursorBlinking(); +} - cursorOn = enable; +void QWidgetTextControlPrivate::updateCursorBlinking() +{ + cursorBlinkTimer.stop(); + if (blinkingEnabled) { + int flashTime = QGuiApplication::styleHints()->cursorFlashTime(); + if (flashTime >= 2) + cursorBlinkTimer.start(flashTime / 2, q_func()); + } + cursorOn = true; repaintCursor(); } diff --git a/src/widgets/widgets/qwidgettextcontrol_p_p.h b/src/widgets/widgets/qwidgettextcontrol_p_p.h index 4feebdd9ef..16a3a153cc 100644 --- a/src/widgets/widgets/qwidgettextcontrol_p_p.h +++ b/src/widgets/widgets/qwidgettextcontrol_p_p.h @@ -112,6 +112,7 @@ public: void _q_contentsChanged(int from, int charsRemoved, int charsAdded); void setBlinkingCursorEnabled(bool enable); + void updateCursorBlinking(); void extendWordwiseSelection(int suggestedNewPosition, qreal mouseXPosition); void extendBlockwiseSelection(int suggestedNewPosition); @@ -175,6 +176,7 @@ public: QTextDocument *doc; bool cursorOn; + bool blinkingEnabled; QTextCursor cursor; bool cursorIsFocusIndicator; QTextCharFormat lastCharFormat; |