Skip to content

Commit

Permalink
ticket:3987
Browse files Browse the repository at this point in the history
Clear contents of search field by clicking ESC key.
  • Loading branch information
adeas31 committed Jul 1, 2016
1 parent 14f3280 commit 612047b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
24 changes: 24 additions & 0 deletions OMEdit/OMEditGUI/Util/Utilities.cpp
Expand Up @@ -58,6 +58,7 @@ TreeSearchFilters::TreeSearchFilters(QWidget *pParent)
{
// create the search text box
mpSearchTextBox = new QLineEdit;
mpSearchTextBox->installEventFilter(this);
// show hide button
mpShowHideButton = new QToolButton;
QString text = tr("Show/hide filters");
Expand Down Expand Up @@ -105,6 +106,29 @@ TreeSearchFilters::TreeSearchFilters(QWidget *pParent)
setLayout(pMainLayout);
}

/*!
* \brief TreeSearchFilters::eventFilter
* Handles the ESC key press for search text box
* \param pObject
* \param pEvent
* \return
*/
bool TreeSearchFilters::eventFilter(QObject *pObject, QEvent *pEvent)
{
/* Ticket #3987
* Clear contents of search field by clicking ESC key.
*/
QLineEdit *pSearchTextBox = qobject_cast<QLineEdit*>(pObject);
if (pSearchTextBox && pEvent->type() == QEvent::KeyPress) {
QKeyEvent *pKeyEvent = static_cast<QKeyEvent*>(pEvent);
if (pKeyEvent && pKeyEvent->key() == Qt::Key_Escape) {
pSearchTextBox->clear();
return true;
}
}
return QWidget::eventFilter(pObject, pEvent);
}

void TreeSearchFilters::showHideFilters(bool On)
{
if (On) {
Expand Down
2 changes: 2 additions & 0 deletions OMEdit/OMEditGUI/Util/Utilities.h
Expand Up @@ -94,6 +94,8 @@ class TreeSearchFilters : public QWidget
QCheckBox* getCaseSensitiveCheckBox() {return mpCaseSensitiveCheckBox;}
QPushButton* getExpandAllButton() {return mpExpandAllButton;}
QPushButton* getCollapseAllButton() {return mpCollapseAllButton;}

bool eventFilter(QObject *pObject, QEvent *pEvent);
private:
QLineEdit *mpSearchTextBox;
QToolButton *mpShowHideButton;
Expand Down

0 comments on commit 612047b

Please sign in to comment.