From: Flavio Date: Sat, 3 Mar 2012 14:19:33 +0000 (+0100) Subject: Fix serach box focus issues X-Git-Tag: 1.7.1~2 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=7bf6ae46116314c5aaef5638d5d73ac6752a34ce;p=minitube Fix serach box focus issues --- diff --git a/src/autocomplete.cpp b/src/autocomplete.cpp index 33f475a..2ba1826 100644 --- a/src/autocomplete.cpp +++ b/src/autocomplete.cpp @@ -13,7 +13,7 @@ AutoComplete::AutoComplete(QWidget *parent, QLineEdit *editor): popup->installEventFilter(this); popup->setWindowFlags(Qt::Popup); popup->setFocusPolicy(Qt::NoFocus); - popup->setFocusProxy(parent); + popup->setFocusProxy(buddy); connect(popup, SIGNAL(itemClicked(QListWidgetItem*)), SLOT(doneCompletion())); @@ -28,11 +28,7 @@ AutoComplete::AutoComplete(QWidget *parent, QLineEdit *editor): timer->setSingleShot(true); timer->setInterval(600); connect(timer, SIGNAL(timeout()), SLOT(autoSuggest())); -#ifdef APP_MAC - connect(parent, SIGNAL(textChanged(QString)), timer, SLOT(start())); -#else - connect(editor, SIGNAL(textEdited(QString)), timer, SLOT(start())); -#endif + connect(buddy, SIGNAL(textChanged(QString)), timer, SLOT(start())); } @@ -44,9 +40,15 @@ bool AutoComplete::eventFilter(QObject *obj, QEvent *ev) { if (obj != popup) return false; + if (ev->type() == QEvent::FocusOut) { + popup->hide(); + buddy->setFocus(); + return true; + } + if (ev->type() == QEvent::MouseButtonPress) { popup->hide(); - editor->setFocus(); + buddy->setFocus(); editor->setText(originalText); return true; } @@ -65,14 +67,14 @@ bool AutoComplete::eventFilter(QObject *obj, QEvent *ev) { doneCompletion(); consumed = true; } else { - editor->setFocus(); + buddy->setFocus(); editor->event(ev); popup->hide(); } break; case Qt::Key_Escape: - editor->setFocus(); + buddy->setFocus(); editor->setText(originalText); popup->hide(); consumed = true; @@ -88,7 +90,7 @@ bool AutoComplete::eventFilter(QObject *obj, QEvent *ev) { default: // qDebug() << keyEvent->text(); - editor->setFocus(); + buddy->setFocus(); editor->event(ev); popup->hide(); break; @@ -121,14 +123,14 @@ void AutoComplete::showCompletion(const QStringList &choices) { popup->move(buddy->mapToGlobal(QPoint(0, buddy->height()))); - // popup->setFocus(); + popup->setFocus(); popup->show(); } void AutoComplete::doneCompletion() { timer->stop(); popup->hide(); - editor->setFocus(); + buddy->setFocus(); QListWidgetItem *item = popup->currentItem(); if (item) { editor->setText(item->text()); @@ -156,12 +158,14 @@ void AutoComplete::setSuggester(Suggester* suggester) { void AutoComplete::autoSuggest() { if (!enabled) return; + if (!buddy->hasFocus()) return; QString query = editor->text(); originalText = query; // qDebug() << "originalText" << originalText; if (query.isEmpty()) { popup->hide(); + buddy->setFocus(); return; }