]> cloud.milkyroute.net Git - dolphin.git/blob - src/search/dolphinsearchbox.h
add A search options widget, which later on will include Adam Kidder's search prototy...
[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 KUrl;
29 class QCompleter;
30 class QModelIndex;
31 class QStandardItemModel;
32 class QToolButton;
33
34 /**
35 * @brief used for completition for the DolphinSearchBox
36 */
37 class DolphinSearchCompleter : public QObject
38 {
39 Q_OBJECT
40
41 public:
42 DolphinSearchCompleter(KLineEdit *linedit);
43
44 public slots:
45 void highlighted(const QModelIndex& index);
46 void activated(const QModelIndex& index);
47 void slotTextEdited(const QString &text);
48
49 private:
50 void addCompletionItem(const QString& displayed, const QString& usedForCompletition, const QString& description = QString(), const QString& toolTip = QString(), const KIcon& icon = KIcon());
51
52 void findText(int* wordStart, int* wordEnd, QString* newWord, int cursorPos, const QString &input);
53
54 private:
55 KLineEdit* q;
56 QCompleter* m_completer;
57 QStandardItemModel* m_completionModel;
58 QString m_userText;
59 int m_wordStart;
60 int m_wordEnd;
61 };
62
63 /**
64 * @brief Input box for searching files with Nepomuk.
65 */
66 class DolphinSearchBox : public QWidget
67 {
68 Q_OBJECT
69
70 public:
71 DolphinSearchBox(QWidget* parent = 0);
72 virtual ~DolphinSearchBox();
73
74 protected:
75 virtual bool event(QEvent* event);
76 virtual bool eventFilter(QObject* watched, QEvent* event);
77
78 signals:
79 /**
80 * Is emitted when the user pressed Return or Enter
81 * and provides the Nepomuk URL that should be used
82 * for searching.
83 */
84 void search(const KUrl& url);
85
86 /**
87 * Is emitted if the text of the searchbox has been changed.
88 */
89 void textChanged(const QString& text);
90
91 private slots:
92 void emitSearchSignal();
93
94 private:
95 KLineEdit* m_searchInput;
96 QToolButton* m_searchButton;
97
98 DolphinSearchCompleter* m_completer;
99 };
100
101 #endif