summaryrefslogtreecommitdiff
path: root/client/widgets/lineedit.cc
diff options
context:
space:
mode:
Diffstat (limited to 'client/widgets/lineedit.cc')
-rw-r--r--client/widgets/lineedit.cc43
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();
+ }
+}