Widgets: Stop cursor blink timer when QLineEdit is read-only
This prevents unnecessary updates, since the cursor is not visible. Change-Id: Iec54ed338a0cb526a03cd611de4d823e26f3d804 Reviewed-by: Jan Arve Sæther <jan-arve.saether@digia.com>bb10
parent
85ff27d9ec
commit
9346cb9552
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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; }
|
||||
|
||||
|
|
|
|||
|
|
@ -189,6 +189,8 @@ private slots:
|
|||
|
||||
void isReadOnly();
|
||||
|
||||
void noCursorBlinkWhenReadOnly();
|
||||
|
||||
void cursorPosition();
|
||||
|
||||
void cursorPositionChanged_data();
|
||||
|
|
@ -1828,6 +1830,42 @@ void tst_QLineEdit::isReadOnly()
|
|||
QCOMPARE(testWidget->text(), QString("the quick dark brown fox"));
|
||||
}
|
||||
|
||||
class BlinkTestLineEdit : public QLineEdit
|
||||
{
|
||||
public:
|
||||
void paintEvent(QPaintEvent *e)
|
||||
{
|
||||
++updates;
|
||||
QLineEdit::paintEvent(e);
|
||||
}
|
||||
|
||||
int updates;
|
||||
};
|
||||
|
||||
void tst_QLineEdit::noCursorBlinkWhenReadOnly()
|
||||
{
|
||||
int cursorFlashTime = QApplication::cursorFlashTime();
|
||||
if (cursorFlashTime == 0)
|
||||
return;
|
||||
BlinkTestLineEdit le;
|
||||
le.show();
|
||||
le.setFocus();
|
||||
QTest::qWaitForWindowActive(&le);
|
||||
le.updates = 0;
|
||||
QTest::qWait(cursorFlashTime);
|
||||
QVERIFY(le.updates > 0);
|
||||
le.setReadOnly(true);
|
||||
QTest::qWait(10);
|
||||
le.updates = 0;
|
||||
QTest::qWait(cursorFlashTime);
|
||||
QCOMPARE(le.updates, 0);
|
||||
le.setReadOnly(false);
|
||||
QTest::qWait(10);
|
||||
le.updates = 0;
|
||||
QTest::qWait(cursorFlashTime);
|
||||
QVERIFY(le.updates > 0);
|
||||
}
|
||||
|
||||
static void figureOutProperKey(Qt::Key &key, Qt::KeyboardModifiers &pressState)
|
||||
{
|
||||
#ifdef Q_OS_MAC
|
||||
|
|
|
|||
Loading…
Reference in New Issue