From 0d76adfb6dce6dec1367913752f7b0a818e1bc21 Mon Sep 17 00:00:00 2001 From: deva Date: Thu, 29 Apr 2010 12:26:01 +0000 Subject: Backported some widget behaviour from head. --- client/widgets/lineedit.cc | 43 ++++++++++++++++++++++++++++++++++++------- 1 file changed, 36 insertions(+), 7 deletions(-) (limited to 'client/widgets/lineedit.cc') diff --git a/client/widgets/lineedit.cc b/client/widgets/lineedit.cc index 49b3704..c3a799a 100644 --- a/client/widgets/lineedit.cc +++ b/client/widgets/lineedit.cc @@ -48,23 +48,30 @@ LineEdit::LineEdit(QDomNode &node, MacroWindow *macrowindow) connect(this, SIGNAL(textChanged(QString)), this, SLOT(changed())); connect(this, SIGNAL(textEdited(QString)), this, SLOT(user_changed())); + + installEventFilter(this); // Detect keyboard input. } void LineEdit::changed() { QPalette palette; - if(regexpValidator()) { - if(luaValidator()) { - // valid string - palette.setBrush(QPalette::Base, QBrush(QColor(255, 255, 255))); + if(isEnabled()) { + if(regexpValidator()) { + if(luaValidator()) { + // valid string + palette.setBrush(QPalette::Base, QBrush(QColor(255, 255, 255))); + } else { + // invalid string + palette.setBrush(QPalette::Base, QBrush(QColor(200, 230, 200))); + } } else { // invalid string - palette.setBrush(QPalette::Base, QBrush(QColor(200, 230, 200))); + palette.setBrush(QPalette::Base, QBrush(QColor(230, 200, 200))); } } else { - // invalid string - palette.setBrush(QPalette::Base, QBrush(QColor(230, 200, 200))); + // valid string + palette.setBrush(QPalette::Base, QBrush(QColor(255, 255, 255))); } setPalette(palette); @@ -127,3 +134,25 @@ void LineEdit::setVisibility(bool visible) { setVisible(visible); } + + +#include +bool LineEdit::eventFilter(QObject *, QEvent *event) +{ + if (event->type() == QEvent::KeyPress) { + QKeyEvent *keyEvent = static_cast(event); + if(keyEvent->key() == Qt::Key_Return || + keyEvent->key() == Qt::Key_Enter) { + QKeyEvent tabevent(QEvent::KeyPress, Qt::Key_Tab, Qt::NoModifier); + QCoreApplication::sendEvent(this, &tabevent); + } + } + return false; +} + +void LineEdit::changeEvent(QEvent *event) +{ + if(event->type() == QEvent::EnabledChange) { + changed(); + } +} -- cgit v1.2.3