From: Flavio Date: Thu, 23 Oct 2014 10:46:00 +0000 (+0200) Subject: Finally fixed mouse tracking bug X-Git-Tag: 2.3 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=bda7a0b4de3c51f32e2f04a8880f5a3fb4fdca06;p=minitube Finally fixed mouse tracking bug --- diff --git a/src/autocomplete.cpp b/src/autocomplete.cpp index e20f1ba..badfd70 100644 --- a/src/autocomplete.cpp +++ b/src/autocomplete.cpp @@ -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 &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); diff --git a/src/autocomplete.h b/src/autocomplete.h index f2e9e13..eaf4eb1 100644 --- a/src/autocomplete.h +++ b/src/autocomplete.h @@ -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 &suggestions); void adjustPosition(); + void enableItemHovering(); private: void showSuggestions(const QList &suggestions); @@ -65,7 +65,7 @@ private: bool enabled; Suggester *suggester; QList suggestions; - + bool itemHovering; }; #endif // AUTOCOMPLETE_H