-#ifndef SUGGESTCOMPLETION_H
-#define SUGGESTCOMPLETION_H
+/* $BEGIN_LICENSE
+
+This file is part of Minitube.
+Copyright 2009, Flavio Tordini <flavio.tordini@gmail.com>
+
+Minitube is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+Minitube is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with Minitube. If not, see <http://www.gnu.org/licenses/>.
+
+$END_LICENSE */
+#ifndef AUTOCOMPLETE_H
+#define AUTOCOMPLETE_H
#include <QtGui>
class Suggester;
+class Suggestion;
+class SearchWidget;
+
+QT_FORWARD_DECLARE_CLASS(QListWidget)
+QT_FORWARD_DECLARE_CLASS(QListWidgetItem)
+QT_FORWARD_DECLARE_CLASS(QLineEdit)
class AutoComplete : public QObject {
+
Q_OBJECT
public:
- AutoComplete(QWidget *parent, QLineEdit *editor);
- ~AutoComplete();
- bool eventFilter(QObject *obj, QEvent *ev);
- void showCompletion(const QStringList &choices);
+ AutoComplete(SearchWidget *buddy, QLineEdit *lineEdit);
void setSuggester(Suggester* suggester);
-
-public slots:
- void doneCompletion();
+ QListWidget* getPopup() { return popup; }
void preventSuggest();
void enableSuggest();
- void autoSuggest();
- void currentItemChanged(QListWidgetItem *current);
- void suggestionsReady(QStringList suggestions);
+
+signals:
+ void suggestionAccepted(Suggestion *suggestion);
+ void suggestionAccepted(const QString &value);
+
+protected:
+ bool eventFilter(QObject *obj, QEvent *ev);
+
+private slots:
+ void acceptSuggestion();
+ void suggest();
+ void itemEntered(QListWidgetItem *item);
+ void currentItemChanged(QListWidgetItem *item);
+ void suggestionsReady(const QVector<Suggestion*> &suggestions);
+ void adjustPosition();
+ void enableItemHovering();
private:
- QWidget *buddy;
- QLineEdit *editor;
+ void showSuggestions(const QVector<Suggestion*> &suggestions);
+ void hideSuggestions();
+
+ SearchWidget *buddy;
+ QLineEdit *lineEdit;
QString originalText;
QListWidget *popup;
QTimer *timer;
bool enabled;
- Suggester* suggester;
-
+ Suggester *suggester;
+ QVector<Suggestion*> suggestions;
+ bool itemHovering;
};
-#endif // SUGGESTCOMPLETION_H
+#endif // AUTOCOMPLETE_H