diff options
author | deva <deva> | 2010-04-29 12:26:01 +0000 |
---|---|---|
committer | deva <deva> | 2010-04-29 12:26:01 +0000 |
commit | 0d76adfb6dce6dec1367913752f7b0a818e1bc21 (patch) | |
tree | db67eab193681dea72df4a14bbdac39b67fcf106 /client/widgets/lineedit.cc | |
parent | c96a2e557f0a9322c9369a06041e894cc2f11e93 (diff) |
Backported some widget behaviour from head.
Diffstat (limited to 'client/widgets/lineedit.cc')
-rw-r--r-- | client/widgets/lineedit.cc | 43 |
1 files changed, 36 insertions, 7 deletions
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 <QCoreApplication> +bool LineEdit::eventFilter(QObject *, QEvent *event) +{ + if (event->type() == QEvent::KeyPress) { + QKeyEvent *keyEvent = static_cast<QKeyEvent *>(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(); + } +} |