From c13601622051fa35fd6aff539971ca907fd61388 Mon Sep 17 00:00:00 2001 From: Christoffer Klang Date: Sun, 11 Aug 2013 00:03:16 +0200 Subject: [PATCH] Move escape handling to search edit Makes more sense there --- zeal/lineedit.cpp | 15 --------------- zeal/lineedit.h | 1 - zeal/widgets/zealsearchedit.cpp | 13 +++++++++++++ 3 files changed, 13 insertions(+), 16 deletions(-) diff --git a/zeal/lineedit.cpp b/zeal/lineedit.cpp index b1189ed..8b272f0 100644 --- a/zeal/lineedit.cpp +++ b/zeal/lineedit.cpp @@ -34,21 +34,6 @@ LineEdit::LineEdit(QWidget *parent) qMax(msz.height(), clearButton->sizeHint().height() + frameWidth * 2 + 2)); } -void LineEdit::keyPressEvent(QKeyEvent * evt) -{ - if(evt->key() == Qt::Key_Escape) { - ZealSearchQuery currentQuery(text()); - // Keep the filter for the first esc press - if(currentQuery.getDocsetFilter().size() > 0 && currentQuery.getCoreQuery().size() > 0) { - setText(currentQuery.getDocsetFilter() + ZealSearchQuery::DOCSET_FILTER_SEPARATOR); - } else { - clear(); - } - } else { - QLineEdit::keyPressEvent(evt); - } -} - void LineEdit::clear() { QLineEdit::clear(); if(hideOnClear) hide(); diff --git a/zeal/lineedit.h b/zeal/lineedit.h index 0b5ed70..f5e4f23 100644 --- a/zeal/lineedit.h +++ b/zeal/lineedit.h @@ -24,7 +24,6 @@ public: protected: void resizeEvent(QResizeEvent *); - void keyPressEvent(QKeyEvent * evt); public slots: void clear(); diff --git a/zeal/widgets/zealsearchedit.cpp b/zeal/widgets/zealsearchedit.cpp index 031d27e..d935d3f 100644 --- a/zeal/widgets/zealsearchedit.cpp +++ b/zeal/widgets/zealsearchedit.cpp @@ -3,6 +3,8 @@ #include #include +#include "zealsearchquery.h" + ZealSearchEdit::ZealSearchEdit(QWidget *parent) : LineEdit(parent) { @@ -24,6 +26,17 @@ bool ZealSearchEdit::eventFilter(QObject *obj, QEvent *ev) QCoreApplication::instance()->sendEvent(treeView, keyEvent); return true; } + + // Clear input with consideration to docset filters when the user presses escape. + if(keyEvent->key() == Qt::Key_Escape) { + ZealSearchQuery currentQuery(text()); + // Keep the filter for the first esc press + if(currentQuery.getDocsetFilter().size() > 0 && currentQuery.getCoreQuery().size() > 0) { + setText(currentQuery.getDocsetFilter() + ZealSearchQuery::DOCSET_FILTER_SEPARATOR); + } else { + clear(); + } + } } return QLineEdit::eventFilter(obj, ev); }