]> git.sur5r.net Git - minitube/commitdiff
Fix serach box focus issues
authorFlavio <flavio@odisseo.local>
Sat, 3 Mar 2012 14:19:33 +0000 (15:19 +0100)
committerFlavio <flavio@odisseo.local>
Sat, 3 Mar 2012 14:19:33 +0000 (15:19 +0100)
src/autocomplete.cpp

index 33f475aa82474193026d48345d58cf65c1dbc180..2ba1826016aef47ac859e8eaccdf7c096e7aefd8 100644 (file)
@@ -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;
     }