]> cloud.milkyroute.net Git - dolphin.git/blob - src/search/dolphinsearchbox.h
Fix forward declation
[dolphin.git] / src / search / dolphinsearchbox.h
1 /***************************************************************************
2 * Copyright (C) 2009 by Peter Penz <peter.penz@gmx.at> *
3 * Copyright (C) 2009 by Matthias Fuchs <mat69@gmx.net> *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
19 ***************************************************************************/
20 #ifndef DOLPHINSEARCHBOX_H
21 #define DOLPHINSEARCHBOX_H
22
23 #include <QWidget>
24
25 #include <KIcon>
26
27 class KLineEdit;
28 class QCompleter;
29 class QModelIndex;
30 class QStandardItemModel;
31
32 /**
33 * @brief Helper class used for completition for the DolphinSearchBox.
34 */
35 class DolphinSearchCompleter : public QObject
36 {
37 Q_OBJECT
38
39 public:
40 DolphinSearchCompleter(KLineEdit *linedit);
41
42 public slots:
43 void highlighted(const QModelIndex& index);
44 void slotTextEdited(const QString &text);
45
46 private:
47 void addCompletionItem(const QString& displayed, const QString& usedForCompletition, const QString& description = QString(), const QString& toolTip = QString(), const KIcon& icon = KIcon());
48
49 void findText(int* wordStart, int* wordEnd, QString* newWord, int cursorPos, const QString &input);
50
51 private:
52 KLineEdit* q;
53 QCompleter* m_completer;
54 QStandardItemModel* m_completionModel;
55 QString m_userText;
56 int m_wordStart;
57 int m_wordEnd;
58 };
59
60 /**
61 * @brief Input box for searching files with Nepomuk.
62 */
63 class DolphinSearchBox : public QWidget
64 {
65 Q_OBJECT
66
67 public:
68 DolphinSearchBox(QWidget* parent = 0);
69 virtual ~DolphinSearchBox();
70
71 /**
72 * Returns the text that should be used as input
73 * for searching.
74 */
75 QString text() const;
76
77 protected:
78 virtual bool event(QEvent* event);
79 virtual bool eventFilter(QObject* watched, QEvent* event);
80
81 signals:
82 /**
83 * Is emitted when the user pressed Return or Enter
84 * and provides the text that should be used as input
85 * for searching.
86 */
87 void search(const QString& text);
88
89 /**
90 * Is emitted when the user has changed a character of
91 * the text that should be used as input for searching.
92 */
93 void searchTextChanged(const QString& text);
94
95 /**
96 * Is emitted if the search box gets the focus or the text
97 * has been changed. It requests the need for an UI that allows to
98 * adjust search options. It is up to the application to ignore
99 * this request.
100 */
101 void requestSearchOptions();
102
103 private slots:
104 void emitSearchSignal();
105 void slotTextChanged(const QString& text);
106
107 private:
108 KLineEdit* m_searchInput;
109 DolphinSearchCompleter* m_completer;
110 };
111
112 #endif