]> git.sur5r.net Git - minitube/commitdiff
autocompleter refinements
authorFlavio Tordini <flavio.tordini@gmail.com>
Wed, 29 Jul 2009 08:51:32 +0000 (10:51 +0200)
committerFlavio Tordini <flavio.tordini@gmail.com>
Wed, 29 Jul 2009 08:51:32 +0000 (10:51 +0200)
src/SearchView.h
src/googlesuggest.cpp
src/googlesuggest.h

index 0db47b749139066007b51ff8cbdd02045f84023d..4690a4425805812d02a722618755d51bb7bc82a3 100644 (file)
@@ -17,6 +17,7 @@ public:
         updateRecentKeywords();
         queryEdit->clear();
         queryEdit->setFocus(Qt::OtherFocusReason);
+        queryEdit->enableSuggest();
     }
 
     void disappear() {}
index 71e545c35406fb8c5027388f68b773d28d675501..234fe61c0c42d2613ba3abac559d2a1e8ce810d5 100644 (file)
@@ -7,7 +7,10 @@ namespace The {
     NetworkAccess* http();
 }
 
-GSuggestCompletion::GSuggestCompletion(QLineEdit *parent): QObject(parent), editor(parent) {
+GSuggestCompletion::GSuggestCompletion(QWidget *parent, QLineEdit *editor):
+        QObject(parent), buddy(parent), editor(editor) {
+
+    enabled = true;
 
     popup = new QListWidget;
     popup->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
@@ -17,12 +20,12 @@ GSuggestCompletion::GSuggestCompletion(QLineEdit *parent): QObject(parent), edit
     connect(popup, SIGNAL(itemClicked(QListWidgetItem*)),
             SLOT(doneCompletion()));
 
-    connect(popup, SIGNAL(currentItemChanged(QListWidgetItem *, QListWidgetItem *)),
-            SLOT(currentItemChanged(QListWidgetItem *)));
+    // connect(popup, SIGNAL(currentItemChanged(QListWidgetItem *, QListWidgetItem *)),
+    //    SLOT(currentItemChanged(QListWidgetItem *)));
 
     // mouse hover
-    connect(popup, SIGNAL(itemEntered(QListWidgetItem*)),
-            SLOT(currentItemChanged(QListWidgetItem *)));
+    // connect(popup, SIGNAL(itemEntered(QListWidgetItem*)),
+    //    SLOT(currentItemChanged(QListWidgetItem *)));
 
     popup->setWindowFlags(Qt::Popup);
     popup->setFocusPolicy(Qt::NoFocus);
@@ -30,7 +33,7 @@ GSuggestCompletion::GSuggestCompletion(QLineEdit *parent): QObject(parent), edit
 
     timer = new QTimer(this);
     timer->setSingleShot(true);
-    timer->setInterval(100);
+    timer->setInterval(300);
     connect(timer, SIGNAL(timeout()), SLOT(autoSuggest()));
     connect(editor, SIGNAL(textEdited(QString)), timer, SLOT(start()));
 
@@ -116,9 +119,10 @@ void GSuggestCompletion::showCompletion(const QStringList &choices) {
     popup->setUpdatesEnabled(true);
 
     int h = popup->sizeHintForRow(0) * choices.count() + 4;
-    popup->resize(popup->width(), h);
+    popup->resize(buddy->width(), h);
+
+    popup->move(buddy->mapToGlobal(QPoint(0, buddy->height())));
 
-    popup->move(editor->mapToGlobal(QPoint(0, editor->height()+4)));
     popup->setFocus();
     popup->show();
 }
@@ -140,9 +144,17 @@ void GSuggestCompletion::doneCompletion() {
 
 void GSuggestCompletion::preventSuggest() {
     timer->stop();
+    enabled = false;
+    popup->hide();
+}
+
+void GSuggestCompletion::enableSuggest() {
+    enabled = true;
 }
 
 void GSuggestCompletion::autoSuggest() {
+    if (!enabled) return;
+
     QString query = editor->text();
     originalText = query;
     qDebug() << "originalText" << originalText;
@@ -161,6 +173,7 @@ void GSuggestCompletion::autoSuggest() {
 }
 
 void GSuggestCompletion::handleNetworkData(QByteArray response) {
+    if (!enabled) return;
 
     QStringList choices;
 
index 8ca766b7f317d99012887f36a7edc8f341372138..9773380db7514520f5435c1933aea72f9045e5a9 100644 (file)
@@ -7,7 +7,7 @@ class GSuggestCompletion : public QObject {
     Q_OBJECT
 
 public:
-    GSuggestCompletion(QLineEdit *parent);
+    GSuggestCompletion(QWidget *parent, QLineEdit *editor);
     ~GSuggestCompletion();
     bool eventFilter(QObject *obj, QEvent *ev);
     void showCompletion(const QStringList &choices);
@@ -15,15 +15,18 @@ public:
 public slots:
     void doneCompletion();
     void preventSuggest();
+    void enableSuggest();
     void autoSuggest();
     void handleNetworkData(QByteArray response);
     void currentItemChanged(QListWidgetItem *current);
 
 private:
+    QWidget *buddy;
     QLineEdit *editor;
     QString originalText;
     QListWidget *popup;
     QTimer *timer;
+    bool enabled;
 
 };