From 9346cb955230b3fbca8062a2fe8c912713011ce4 Mon Sep 17 00:00:00 2001 From: Gabriel de Dietrich Date: Wed, 14 Nov 2012 10:52:16 +0100 Subject: Widgets: Stop cursor blink timer when QLineEdit is read-only MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This prevents unnecessary updates, since the cursor is not visible. Change-Id: Iec54ed338a0cb526a03cd611de4d823e26f3d804 Reviewed-by: Jan Arve Sæther --- src/widgets/widgets/qwidgetlinecontrol.cpp | 20 ++++++++++---------- src/widgets/widgets/qwidgetlinecontrol_p.h | 3 +-- 2 files changed, 11 insertions(+), 12 deletions(-) (limited to 'src/widgets') diff --git a/src/widgets/widgets/qwidgetlinecontrol.cpp b/src/widgets/widgets/qwidgetlinecontrol.cpp index bed8296989..a44ac12fa4 100644 --- a/src/widgets/widgets/qwidgetlinecontrol.cpp +++ b/src/widgets/widgets/qwidgetlinecontrol.cpp @@ -1456,6 +1456,15 @@ void QWidgetLineControl::complete(int key) } #endif +void QWidgetLineControl::setReadOnly(bool enable) +{ + m_readOnly = enable; + if (enable) + setCursorBlinkPeriod(0); + else + setCursorBlinkPeriod(QApplication::cursorFlashTime()); +} + void QWidgetLineControl::setCursorBlinkPeriod(int msec) { if (msec == m_blinkPeriod) @@ -1463,7 +1472,7 @@ void QWidgetLineControl::setCursorBlinkPeriod(int msec) if (m_blinkTimer) { killTimer(m_blinkTimer); } - if (msec) { + if (msec && !m_readOnly) { m_blinkTimer = startTimer(msec / 2); m_blinkStatus = 1; } else { @@ -1474,15 +1483,6 @@ void QWidgetLineControl::setCursorBlinkPeriod(int msec) m_blinkPeriod = msec; } -void QWidgetLineControl::resetCursorBlinkTimer() -{ - if (m_blinkPeriod == 0 || m_blinkTimer == 0) - return; - killTimer(m_blinkTimer); - m_blinkTimer = startTimer(m_blinkPeriod / 2); - m_blinkStatus = 1; -} - void QWidgetLineControl::timerEvent(QTimerEvent *event) { if (event->timerId() == m_blinkTimer) { diff --git a/src/widgets/widgets/qwidgetlinecontrol_p.h b/src/widgets/widgets/qwidgetlinecontrol_p.h index 185bc117b6..d88d75c651 100644 --- a/src/widgets/widgets/qwidgetlinecontrol_p.h +++ b/src/widgets/widgets/qwidgetlinecontrol_p.h @@ -213,7 +213,7 @@ public: } bool isReadOnly() const { return m_readOnly; } - void setReadOnly(bool enable) { m_readOnly = enable; } + void setReadOnly(bool enable); QString text() const { @@ -338,7 +338,6 @@ public: int cursorBlinkPeriod() const { return m_blinkPeriod; } void setCursorBlinkPeriod(int msec); - void resetCursorBlinkTimer(); bool cursorBlinkStatus() const { return m_blinkStatus; } -- cgit v1.2.3