Move escape handling to search edit

Makes more sense there
This commit is contained in:
Christoffer Klang 2013-08-11 00:03:16 +02:00
parent 953c4b631f
commit c136016220
3 changed files with 13 additions and 16 deletions

View File

@ -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();

View File

@ -24,7 +24,6 @@ public:
protected:
void resizeEvent(QResizeEvent *);
void keyPressEvent(QKeyEvent * evt);
public slots:
void clear();

View File

@ -3,6 +3,8 @@
#include <QKeyEvent>
#include <QDebug>
#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);
}