#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);
connect(buddy, SIGNAL(textEdited(QString)), timer, SLOT(start()));
}
-AutoComplete::~AutoComplete() {
- delete popup;
-}
-
bool AutoComplete::eventFilter(QObject *obj, QEvent *ev) {
if (obj != popup) {
popup->setUpdatesEnabled(true);
if (popup->isHidden()) {
+ itemHovering = false;
popup->show();
+ QTimer::singleShot(100, this, SLOT(enableItemHovering()));
}
}
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
}
void AutoComplete::itemEntered(QListWidgetItem *item) {
+ if (!itemHovering) return;
if (!item) return;
item->setSelected(true);
popup->setCurrentItem(item);
public:
AutoComplete(SearchLineEdit *buddy, QLineEdit *lineEdit);
- ~AutoComplete();
void setSuggester(Suggester* suggester);
QListWidget* getPopup() { return popup; }
void preventSuggest();
void currentItemChanged(QListWidgetItem *item);
void suggestionsReady(const QList<Suggestion*> &suggestions);
void adjustPosition();
+ void enableItemHovering();
private:
void showSuggestions(const QList<Suggestion*> &suggestions);
bool enabled;
Suggester *suggester;
QList<Suggestion*> suggestions;
-
+ bool itemHovering;
};
#endif // AUTOCOMPLETE_H