diff options
| author | Eike Ziller <eike.ziller@digia.com> | 2012-12-20 15:34:42 +0100 |
|---|---|---|
| committer | Robert Loehning <robert.loehning@digia.com> | 2013-01-22 17:48:19 +0100 |
| commit | cec327bd4a8a3a77f09b6e465636db2537b86580 (patch) | |
| tree | e9b38bb286995d926fd25607c2ba9aafd1240d0c | |
| parent | ed69c5f9c9e6c57179fd5bd3189c233e31609e1c (diff) | |
| download | qt-creator-cec327bd4a8a3a77f09b6e465636db2537b86580.tar.gz | |
Close variable chooser when pressing escape.
Even if the variable chooser currently doesn't have focus.
Task-number: QTCREATORBUG-7155
Change-Id: Ie3a7527e13dd6c3f37c1abe86a596753d2b8e286
Reviewed-by: Robert Loehning <robert.loehning@digia.com>
| -rw-r--r-- | src/plugins/coreplugin/variablechooser.cpp | 24 | ||||
| -rw-r--r-- | src/plugins/coreplugin/variablechooser.h | 1 |
2 files changed, 22 insertions, 3 deletions
diff --git a/src/plugins/coreplugin/variablechooser.cpp b/src/plugins/coreplugin/variablechooser.cpp index 5a9bbab6d9..96417b0cd8 100644 --- a/src/plugins/coreplugin/variablechooser.cpp +++ b/src/plugins/coreplugin/variablechooser.cpp @@ -87,7 +87,8 @@ void VariableChooser::updateDescription(const QString &variable) void VariableChooser::updateCurrentEditor(QWidget *old, QWidget *widget) { - Q_UNUSED(old) + if (old) + old->removeEventFilter(this); if (!widget) // we might loose focus, but then keep the previous state return; // prevent children of the chooser itself, and limit to children of chooser's parent @@ -104,6 +105,7 @@ void VariableChooser::updateCurrentEditor(QWidget *old, QWidget *widget) } if (!handle) return; + widget->installEventFilter(this); // for intercepting escape key presses QLineEdit *previousLineEdit = m_lineEdit; m_lineEdit = 0; m_textEdit = 0; @@ -182,10 +184,26 @@ void VariableChooser::insertVariable(const QString &variable) } } -void VariableChooser::keyPressEvent(QKeyEvent *ke) +static bool handleEscapePressed(QKeyEvent *ke, QWidget *widget) { if (ke->key() == Qt::Key_Escape && !ke->modifiers()) { ke->accept(); - QTimer::singleShot(0, this, SLOT(close())); + QTimer::singleShot(0, widget, SLOT(close())); + return true; + } + return false; +} + +void VariableChooser::keyPressEvent(QKeyEvent *ke) +{ + handleEscapePressed(ke, this); +} + +bool VariableChooser::eventFilter(QObject *, QEvent *event) +{ + if (event->type() == QEvent::KeyPress && isVisible()) { + QKeyEvent *ke = static_cast<QKeyEvent *>(event); + return handleEscapePressed(ke, this); } + return false; } diff --git a/src/plugins/coreplugin/variablechooser.h b/src/plugins/coreplugin/variablechooser.h index fe1e38edb2..2fcf8270e7 100644 --- a/src/plugins/coreplugin/variablechooser.h +++ b/src/plugins/coreplugin/variablechooser.h @@ -58,6 +58,7 @@ public: protected: void keyPressEvent(QKeyEvent *ke); + bool eventFilter(QObject *, QEvent *event); private slots: void updateDescription(const QString &variable); |
