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>
This commit is contained in:
Richard Moe Gustavsen 2016-04-19 12:50:47 +02:00
parent 2a740b9cf5
commit d3dcc6f610
2 changed files with 22 additions and 6 deletions

View File

@ -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);
cursorOn = enable;
updateCursorBlinking();
}
void QWidgetTextControlPrivate::updateCursorBlinking()
{
cursorBlinkTimer.stop();
if (blinkingEnabled) {
int flashTime = QGuiApplication::styleHints()->cursorFlashTime();
if (flashTime >= 2)
cursorBlinkTimer.start(flashTime / 2, q_func());
}
cursorOn = true;
repaintCursor();
}

View File

@ -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;