aboutsummaryrefslogtreecommitdiffstats
path: root/src/quick/items/qquicktextinput.cpp
diff options
context:
space:
mode:
authorRichard Moe Gustavsen <richard.gustavsen@theqtcompany.com>2016-04-20 11:35:42 +0200
committerRichard Moe Gustavsen <richard.gustavsen@theqtcompany.com>2016-04-21 13:15:18 +0000
commitc598d52561e048319c6c3656bedf4bb665603dc7 (patch)
tree3f59da3e0aa75ef43591b5f42ba51037eedf8775 /src/quick/items/qquicktextinput.cpp
parent597370b36487d2d2ed438db531f2d4aad4e55744 (diff)
QQuickTextInput: 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 QWidgetLineControl so that it listens to the cursorFlashTimeChanged signal and changes the blinking rate when triggered. The previous code had a function setCursorBlinkPeriod, which is now changed to setBlinkingCursorEnabled (like in QQuickTextControlPrivate). This is because all callers of the function did either pass "QApplication::cursorFlashTime" or "0", which basically means enable or disable blinking. This moves the control of the blinking rate fully to updateCursorFlashTime, which simplifies the code a bit, especially when cursorFlashTime can change. Note that when setting a blink period to 0, it means "show the cursor without blinking". AFAICS, the current implementation did not guarantee that. This is now made more explicit in the code. If hiding the cursor is needed, a separate function "setCursorVisible" is already available for controlling that. Change-Id: Ie3222525474e03b485ff8585fd8d7da6fd5b26e5 Reviewed-by: Jan Arve Sæther <jan-arve.saether@theqtcompany.com>
Diffstat (limited to 'src/quick/items/qquicktextinput.cpp')
-rw-r--r--src/quick/items/qquicktextinput.cpp71
1 files changed, 35 insertions, 36 deletions
diff --git a/src/quick/items/qquicktextinput.cpp b/src/quick/items/qquicktextinput.cpp
index f93857a892..ab7a0f02dd 100644
--- a/src/quick/items/qquicktextinput.cpp
+++ b/src/quick/items/qquicktextinput.cpp
@@ -760,12 +760,8 @@ void QQuickTextInput::setCursorVisible(bool on)
d->cursorVisible = on;
if (on && isComponentComplete())
QQuickTextUtil::createCursor(d);
- if (!d->cursorItem) {
- d->setCursorBlinkPeriod(on ? QGuiApplication::styleHints()->cursorFlashTime() : 0);
- d->updateType = QQuickTextInputPrivate::UpdatePaintNode;
- polish();
- update();
- }
+ if (!d->cursorItem)
+ d->updateCursorBlinking();
emit cursorVisibleChanged(d->cursorVisible);
}
@@ -1782,7 +1778,7 @@ QSGNode *QQuickTextInput::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData
node = new QQuickTextNode(this);
d->textNode = node;
- const bool showCursor = !isReadOnly() && d->cursorItem == 0 && d->cursorVisible && (d->m_blinkStatus || d->m_blinkPeriod == 0);
+ const bool showCursor = !isReadOnly() && d->cursorItem == 0 && d->cursorVisible && d->m_blinkStatus;
if (!d->textLayoutDirty && oldNode != 0) {
if (showCursor)
@@ -2518,8 +2514,10 @@ void QQuickTextInputPrivate::handleFocusEvent(QFocusEvent *event)
{
Q_Q(QQuickTextInput);
bool focus = event->gotFocus();
- if (!m_readOnly)
+ if (!m_readOnly) {
q->setCursorVisible(focus);
+ setBlinkingCursorEnabled(focus);
+ }
if (focus) {
q->q_updateAlignment();
#ifndef QT_NO_IM
@@ -4219,26 +4217,39 @@ bool QQuickTextInputPrivate::emitCursorPositionChanged()
}
-void QQuickTextInputPrivate::setCursorBlinkPeriod(int msec)
+void QQuickTextInputPrivate::setBlinkingCursorEnabled(bool enable)
{
- Q_Q(QQuickTextInput);
- if (msec == m_blinkPeriod)
+ if (enable == m_blinkEnabled)
return;
+
+ m_blinkEnabled = enable;
+ updateCursorBlinking();
+
+ if (enable)
+ connect(qApp->styleHints(), &QStyleHints::cursorFlashTimeChanged, this, &QQuickTextInputPrivate::updateCursorBlinking);
+ else
+ disconnect(qApp->styleHints(), &QStyleHints::cursorFlashTimeChanged, this, &QQuickTextInputPrivate::updateCursorBlinking);
+}
+
+void QQuickTextInputPrivate::updateCursorBlinking()
+{
+ Q_Q(QQuickTextInput);
+
if (m_blinkTimer) {
q->killTimer(m_blinkTimer);
- }
- if (msec) {
- m_blinkTimer = q->startTimer(msec / 2);
- m_blinkStatus = 1;
- } else {
m_blinkTimer = 0;
- if (m_blinkStatus == 1) {
- updateType = UpdatePaintNode;
- q->polish();
- q->update();
- }
}
- m_blinkPeriod = msec;
+
+ if (m_blinkEnabled && cursorVisible && !cursorItem && !m_readOnly) {
+ int flashTime = QGuiApplication::styleHints()->cursorFlashTime();
+ if (flashTime >= 2)
+ m_blinkTimer = q->startTimer(flashTime / 2);
+ }
+
+ m_blinkStatus = 1;
+ updateType = UpdatePaintNode;
+ q->polish();
+ q->update();
}
void QQuickTextInput::timerEvent(QTimerEvent *event)
@@ -4275,20 +4286,8 @@ void QQuickTextInputPrivate::processKeyEvent(QKeyEvent* event)
return;
}
- if (m_blinkPeriod > 0) {
- if (m_blinkTimer)
- q->killTimer(m_blinkTimer);
-
- m_blinkTimer = q->startTimer(m_blinkPeriod / 2);
-
- if (m_blinkStatus == 0) {
- m_blinkStatus = 1;
-
- updateType = UpdatePaintNode;
- q->polish();
- q->update();
- }
- }
+ if (m_blinkEnabled)
+ updateCursorBlinking();
if (m_echoMode == QQuickTextInput::PasswordEchoOnEdit
&& !m_passwordEchoEditing