summaryrefslogtreecommitdiffstats
path: root/src/widgets/widgets/qwidgetlinecontrol.cpp
diff options
context:
space:
mode:
authorRichard Moe Gustavsen <richard.gustavsen@theqtcompany.com>2016-04-19 10:15:54 +0200
committerRichard Moe Gustavsen <richard.gustavsen@theqtcompany.com>2016-04-25 05:55:57 +0000
commit1b5bc9723c0b23ca5197097c3087df6bbe024a2a (patch)
treedfbc879e0e966e9ac4bdf720c8aac70e09acaf24 /src/widgets/widgets/qwidgetlinecontrol.cpp
parente36f03f97a20494857225a0e77aa5d358f686faf (diff)
QWidgetLineControl: 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 QWidgetLineControl so that it listens to the cursorFlashTimeChanged signal and changes the blinking rate when triggered. The previous code had a function setBlinkingRate, which is now changed to setBlinkingCursorEnabled (like in QWidgetTextControl). 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 QWidgetLineControl, 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: I7d39882de192a23e6e7ba370749892c7702c3d3b Reviewed-by: Jan Arve Sæther <jan-arve.saether@theqtcompany.com>
Diffstat (limited to 'src/widgets/widgets/qwidgetlinecontrol.cpp')
-rw-r--r--src/widgets/widgets/qwidgetlinecontrol.cpp51
1 files changed, 34 insertions, 17 deletions
diff --git a/src/widgets/widgets/qwidgetlinecontrol.cpp b/src/widgets/widgets/qwidgetlinecontrol.cpp
index 24edca172b..86903dc0c3 100644
--- a/src/widgets/widgets/qwidgetlinecontrol.cpp
+++ b/src/widgets/widgets/qwidgetlinecontrol.cpp
@@ -636,7 +636,7 @@ void QWidgetLineControl::draw(QPainter *painter, const QPoint &offset, const QRe
o.format.setForeground(m_palette.brush(QPalette::HighlightedText));
} else {
// mask selection
- if(!m_blinkPeriod || m_blinkStatus){
+ if (m_blinkStatus){
o.start = m_cursor;
o.length = 1;
o.format.setBackground(m_palette.brush(QPalette::Text));
@@ -653,7 +653,7 @@ void QWidgetLineControl::draw(QPainter *painter, const QPoint &offset, const QRe
int cursor = m_cursor;
if (m_preeditCursor != -1)
cursor += m_preeditCursor;
- if (!m_hideCursor && (!m_blinkPeriod || m_blinkStatus))
+ if (!m_hideCursor && m_blinkStatus)
textLayout()->drawCursor(painter, offset, cursor, m_cursorWidth);
}
}
@@ -1486,38 +1486,55 @@ void QWidgetLineControl::complete(int key)
void QWidgetLineControl::setReadOnly(bool enable)
{
+ if (m_readOnly == enable)
+ return;
+
m_readOnly = enable;
+ updateCursorBlinking();
+}
+
+void QWidgetLineControl::setBlinkingCursorEnabled(bool enable)
+{
+ if (m_blinkEnabled == enable)
+ return;
+
+ m_blinkEnabled = enable;
+
if (enable)
- setCursorBlinkPeriod(0);
+ connect(qApp->styleHints(), &QStyleHints::cursorFlashTimeChanged, this, &QWidgetLineControl::updateCursorBlinking);
else
- setCursorBlinkPeriod(QApplication::cursorFlashTime());
+ disconnect(qApp->styleHints(), &QStyleHints::cursorFlashTimeChanged, this, &QWidgetLineControl::updateCursorBlinking);
+
+ updateCursorBlinking();
}
-void QWidgetLineControl::setCursorBlinkPeriod(int msec)
+void QWidgetLineControl::updateCursorBlinking()
{
- if (msec == m_blinkPeriod)
- return;
if (m_blinkTimer) {
killTimer(m_blinkTimer);
- }
- if (msec > 0 && !m_readOnly) {
- m_blinkTimer = startTimer(msec / 2);
- m_blinkStatus = 1;
- } else {
m_blinkTimer = 0;
- if (m_blinkStatus == 1)
- emit updateNeeded(inputMask().isEmpty() ? cursorRect() : QRect());
}
- m_blinkPeriod = msec;
+
+ if (m_blinkEnabled && !m_readOnly) {
+ int flashTime = QGuiApplication::styleHints()->cursorFlashTime();
+ if (flashTime >= 2)
+ m_blinkTimer = startTimer(flashTime / 2);
+ }
+
+ m_blinkStatus = 1;
+ emit updateNeeded(inputMask().isEmpty() ? cursorRect() : QRect());
}
// This is still used by QDeclarativeTextInput in the qtquick1 repo
void QWidgetLineControl::resetCursorBlinkTimer()
{
- if (m_blinkPeriod == 0 || m_blinkTimer == 0)
+ if (!m_blinkEnabled || m_blinkTimer == 0)
return;
killTimer(m_blinkTimer);
- m_blinkTimer = startTimer(m_blinkPeriod / 2);
+ m_blinkTimer = 0;
+ int flashTime = QGuiApplication::styleHints()->cursorFlashTime();
+ if (flashTime >= 2)
+ m_blinkTimer = startTimer(flashTime / 2);
m_blinkStatus = 1;
}