]> git.sur5r.net Git - minitube/commitdiff
Finally fixed mouse tracking bug 2.3
authorFlavio <flavio.tordini@gmail.com>
Thu, 23 Oct 2014 10:46:00 +0000 (12:46 +0200)
committerFlavio <flavio.tordini@gmail.com>
Thu, 23 Oct 2014 10:46:00 +0000 (12:46 +0200)
src/autocomplete.cpp
src/autocomplete.h

index e20f1ba6e05efbac442b4f2189e6dc892d3442cf..badfd708092f685192ffd46f4b66e572a44dde98 100644 (file)
@@ -42,18 +42,14 @@ QDebug operator<<(QDebug str, const QEvent * ev) {
 #endif
 
 AutoComplete::AutoComplete(SearchLineEdit *buddy, QLineEdit *lineEdit):
-    QObject(buddy), buddy(buddy), lineEdit(lineEdit), enabled(true), suggester(0) {
+    QObject(buddy), buddy(buddy), lineEdit(lineEdit), enabled(true), suggester(0), itemHovering(false) {
 
     popup = new QListWidget();
     popup->setWindowFlags(Qt::Popup);
     popup->setFocusProxy(buddy);
     popup->installEventFilter(this);
     buddy->window()->installEventFilter(this);
-#if defined(APP_MAC) || defined(APP_WIN)
-    // #FIXME on Linux, mouse tracking triggers an "Enter" event when popup is shown
-    // this triggers item entering and replaces text while writing
     popup->setMouseTracking(true);
-#endif
 
     // style
     popup->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
@@ -73,10 +69,6 @@ AutoComplete::AutoComplete(SearchLineEdit *buddy, QLineEdit *lineEdit):
     connect(buddy, SIGNAL(textEdited(QString)), timer, SLOT(start()));
 }
 
-AutoComplete::~AutoComplete() {
-    delete popup;
-}
-
 bool AutoComplete::eventFilter(QObject *obj, QEvent *ev) {
 
     if (obj != popup) {
@@ -181,7 +173,9 @@ void AutoComplete::showSuggestions(const QList<Suggestion *> &suggestions) {
     popup->setUpdatesEnabled(true);
 
     if (popup->isHidden()) {
+        itemHovering = false;
         popup->show();
+        QTimer::singleShot(100, this, SLOT(enableItemHovering()));
     }
 }
 
@@ -240,7 +234,12 @@ void AutoComplete::adjustPosition() {
     popup->move(buddy->mapToGlobal(QPoint(0, buddy->height())));
 }
 
+void AutoComplete::enableItemHovering() {
+    itemHovering = true;
+}
+
 void AutoComplete::hideSuggestions() {
+    itemHovering = false;
 #ifdef APP_MAC
     mac::fadeOutWindow(popup);
 #else
@@ -256,6 +255,7 @@ void AutoComplete::hideSuggestions() {
 }
 
 void AutoComplete::itemEntered(QListWidgetItem *item) {
+    if (!itemHovering) return;
     if (!item) return;
     item->setSelected(true);
     popup->setCurrentItem(item);
index f2e9e1371abcd0bcfa95abbb1c308883e7370350..eaf4eb182bf642ddb86e78141dbf21d9b01ad6a7 100644 (file)
@@ -32,7 +32,6 @@ class AutoComplete : public QObject {
 
 public:
     AutoComplete(SearchLineEdit *buddy, QLineEdit *lineEdit);
-    ~AutoComplete();
     void setSuggester(Suggester* suggester);
     QListWidget* getPopup() { return popup; }
     void preventSuggest();
@@ -52,6 +51,7 @@ private slots:
     void currentItemChanged(QListWidgetItem *item);
     void suggestionsReady(const QList<Suggestion*> &suggestions);
     void adjustPosition();
+    void enableItemHovering();
 
 private:
     void showSuggestions(const QList<Suggestion*> &suggestions);
@@ -65,7 +65,7 @@ private:
     bool enabled;
     Suggester *suggester;
     QList<Suggestion*> suggestions;
-
+    bool itemHovering;
 };
 
 #endif // AUTOCOMPLETE_H