From bda7a0b4de3c51f32e2f04a8880f5a3fb4fdca06 Mon Sep 17 00:00:00 2001 From: Flavio Date: Thu, 23 Oct 2014 12:46:00 +0200 Subject: [PATCH] Finally fixed mouse tracking bug --- src/autocomplete.cpp | 18 +++++++++--------- src/autocomplete.h | 4 ++-- 2 files changed, 11 insertions(+), 11 deletions(-) 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 -- 2.39.5