From 2b41cb10a264a446e457e170d71facfbdddbd9cb Mon Sep 17 00:00:00 2001 From: Flavio Tordini Date: Sun, 3 Jan 2010 23:52:29 +0100 Subject: [PATCH] Fixed toolbar search suggestions working just once --- src/SearchView.cpp | 2 -- src/googlesuggest.cpp | 4 +++- src/searchlineedit.cpp | 18 ++++++++++++------ src/searchlineedit.h | 1 + 4 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/SearchView.cpp b/src/SearchView.cpp index f7d857d..a8a8ab4 100644 --- a/src/SearchView.cpp +++ b/src/SearchView.cpp @@ -166,8 +166,6 @@ void SearchView::watch(QString query) { return; } - queryEdit->preventSuggest(); - // go! emit search(query); } diff --git a/src/googlesuggest.cpp b/src/googlesuggest.cpp index 141bf23..0002ed0 100644 --- a/src/googlesuggest.cpp +++ b/src/googlesuggest.cpp @@ -90,7 +90,7 @@ bool GSuggestCompletion::eventFilter(QObject *obj, QEvent *ev) { break; default: - qDebug() << keyEvent->text(); + // qDebug() << keyEvent->text(); editor->setFocus(); editor->event(ev); popup->hide(); @@ -144,12 +144,14 @@ void GSuggestCompletion::doneCompletion() { } void GSuggestCompletion::preventSuggest() { + // qDebug() << "preventSuggest"; timer->stop(); enabled = false; popup->hide(); } void GSuggestCompletion::enableSuggest() { + // qDebug() << "enableSuggest"; enabled = true; } diff --git a/src/searchlineedit.cpp b/src/searchlineedit.cpp index bb1cebb..2e5dc6d 100644 --- a/src/searchlineedit.cpp +++ b/src/searchlineedit.cpp @@ -50,7 +50,7 @@ #include "googlesuggest.h" ClearButton::ClearButton(QWidget *parent) - : QAbstractButton(parent) + : QAbstractButton(parent) { setCursor(Qt::ArrowCursor); setToolTip(tr("Clear")); @@ -68,7 +68,7 @@ void ClearButton::paintEvent(QPaintEvent *event) QColor color = palette().color(QPalette::Mid); painter.setBrush(isDown() ? palette().color(QPalette::Dark) - : palette().color(QPalette::Mid)); + : palette().color(QPalette::Mid)); painter.setPen(painter.brush().color()); int size = width(); int offset = size / 3.5; @@ -101,8 +101,8 @@ protected: }; SearchButton::SearchButton(QWidget *parent) - : QAbstractButton(parent), - m_menu(0) + : QAbstractButton(parent), + m_menu(0) { setObjectName(QLatin1String("SearchButton")); setCursor(Qt::ArrowCursor); @@ -247,8 +247,10 @@ QMenu *SearchLineEdit::menu() const void SearchLineEdit::returnPressed() { - completion->preventSuggest(); - emit search(lineEdit()->text()); + if (!lineEdit()->text().isEmpty()) { + completion->preventSuggest(); + emit search(lineEdit()->text()); + } } void SearchLineEdit::enableSuggest() { @@ -258,3 +260,7 @@ void SearchLineEdit::enableSuggest() { void SearchLineEdit::preventSuggest() { completion->preventSuggest(); } + +void SearchLineEdit::focusInEvent(QFocusEvent * /* event */) { + enableSuggest(); +} diff --git a/src/searchlineedit.h b/src/searchlineedit.h index 0f20a08..a1d71c4 100644 --- a/src/searchlineedit.h +++ b/src/searchlineedit.h @@ -97,6 +97,7 @@ public: protected: void resizeEvent(QResizeEvent *event); void paintEvent(QPaintEvent *event); + void focusInEvent(QFocusEvent *event); private slots: void returnPressed(); -- 2.39.5