mirror of
https://github.com/zealdocs/zeal.git
synced 2024-11-23 22:37:09 +03:00
Move escape handling to search edit
Makes more sense there
This commit is contained in:
parent
953c4b631f
commit
c136016220
@ -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();
|
||||
|
@ -24,7 +24,6 @@ public:
|
||||
|
||||
protected:
|
||||
void resizeEvent(QResizeEvent *);
|
||||
void keyPressEvent(QKeyEvent * evt);
|
||||
|
||||
public slots:
|
||||
void clear();
|
||||
|
@ -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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user