forked from qt-creator/qt-creator
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>
This commit is contained in:
committed by
Robert Loehning
parent
ed69c5f9c9
commit
cec327bd4a
@@ -87,7 +87,8 @@ void VariableChooser::updateDescription(const QString &variable)
|
|||||||
|
|
||||||
void VariableChooser::updateCurrentEditor(QWidget *old, QWidget *widget)
|
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
|
if (!widget) // we might loose focus, but then keep the previous state
|
||||||
return;
|
return;
|
||||||
// prevent children of the chooser itself, and limit to children of chooser's parent
|
// 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)
|
if (!handle)
|
||||||
return;
|
return;
|
||||||
|
widget->installEventFilter(this); // for intercepting escape key presses
|
||||||
QLineEdit *previousLineEdit = m_lineEdit;
|
QLineEdit *previousLineEdit = m_lineEdit;
|
||||||
m_lineEdit = 0;
|
m_lineEdit = 0;
|
||||||
m_textEdit = 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()) {
|
if (ke->key() == Qt::Key_Escape && !ke->modifiers()) {
|
||||||
ke->accept();
|
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;
|
||||||
}
|
}
|
||||||
|
@@ -58,6 +58,7 @@ public:
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
void keyPressEvent(QKeyEvent *ke);
|
void keyPressEvent(QKeyEvent *ke);
|
||||||
|
bool eventFilter(QObject *, QEvent *event);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void updateDescription(const QString &variable);
|
void updateDescription(const QString &variable);
|
||||||
|
Reference in New Issue
Block a user