]> cloud.milkyroute.net Git - dolphin.git/blob - src/search/dolphinsearchbox.h
Use QToolButtons instead of QPushButtons for the searchbar
[dolphin.git] / src / search / dolphinsearchbox.h
1 /***************************************************************************
2 * Copyright (C) 2010 by Peter Penz <peter.penz19@gmail.com> *
3 * *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
8 * *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
13 * *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, write to the *
16 * Free Software Foundation, Inc., *
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
18 ***************************************************************************/
19
20 #ifndef DOLPHINSEARCHBOX_H
21 #define DOLPHINSEARCHBOX_H
22
23 #include <KUrl>
24 #include <QList>
25 #include <QWidget>
26
27 class AbstractSearchFilterWidget;
28 class KLineEdit;
29 class KSeparator;
30 class QFormLayout;
31 class QToolButton;
32 class QScrollArea;
33 class QLabel;
34 class QVBoxLayout;
35
36 /**
37 * @brief Input box for searching files with or without Nepomuk.
38 *
39 * The widget allows to specify:
40 * - Where to search: Everywhere or below the current directory
41 * - What to search: Filenames or content
42 *
43 * If Nepomuk is available and the current folder is indexed, further
44 * options are offered.
45 */
46 class DolphinSearchBox : public QWidget {
47 Q_OBJECT
48
49 public:
50 enum SearchContext {
51 SearchFileName,
52 SearchContent
53 };
54
55 enum SearchLocation {
56 SearchFromHere,
57 SearchEverywhere
58 };
59
60 explicit DolphinSearchBox(QWidget* parent = 0);
61 virtual ~DolphinSearchBox();
62
63 /**
64 * Sets the text that should be used as input for
65 * searching.
66 */
67 void setText(const QString& text);
68
69 /**
70 * Returns the text that should be used as input
71 * for searching.
72 */
73 QString text() const;
74
75 /**
76 * Sets the current path that is used as root for
77 * searching files, if "From Here" has been selected.
78 */
79 void setSearchPath(const KUrl& url);
80 KUrl searchPath() const;
81
82 /** @return URL that will start the searching of files. */
83 KUrl urlForSearching() const;
84
85 /**
86 * Selects the whole text of the search box.
87 */
88 void selectAll();
89
90 /**
91 * @param readOnly If set to true the searchbox cannot be modified
92 * by the user and acts as visual indicator for
93 * an externally triggered search query.
94 * @param query If readOnly is true this URL will be used
95 * to show a human readable information about the
96 * query.
97 */
98 void setReadOnly(bool readOnly, const KUrl& query = KUrl());
99 bool isReadOnly() const;
100
101 protected:
102 virtual bool event(QEvent* event);
103 virtual void showEvent(QShowEvent* event);
104 virtual void keyReleaseEvent(QKeyEvent* event);
105
106 signals:
107 /**
108 * Is emitted when a searching should be triggered
109 * and provides the text that should be used as input
110 * for searching.
111 */
112 void search(const QString& text);
113
114 /**
115 * Is emitted when the user has changed a character of
116 * the text that should be used as input for searching.
117 */
118 void searchTextChanged(const QString& text);
119
120 void returnPressed(const QString& text);
121
122 /**
123 * Is emitted if the search location has been changed by the user.
124 */
125 void searchLocationChanged(SearchLocation location);
126
127 /**
128 * Is emitted if the search context has been changed by the user.
129 */
130 void searchContextChanged(SearchContext context);
131
132 /**
133 * Emitted as soon as the search box should get closed.
134 */
135 void closeRequest();
136
137 private slots:
138 void emitSearchSignal();
139 void slotSearchLocationChanged();
140 void slotSearchContextChanged();
141 void slotConfigurationChanged();
142 void slotSearchTextChanged(const QString& text);
143 void slotReturnPressed(const QString& text);
144
145 private:
146 void initButton(QToolButton* button);
147 void loadSettings();
148 void saveSettings();
149 void init();
150
151 /**
152 * @return URL that represents the Nepomuk query for starting the search.
153 */
154 KUrl nepomukUrlForSearching() const;
155
156 void applyReadOnlyState();
157
158 private:
159 bool m_startedSearching;
160 bool m_readOnly;
161
162 QVBoxLayout* m_topLayout;
163
164 QLabel* m_searchLabel;
165 KLineEdit* m_searchInput;
166 QScrollArea* m_optionsScrollArea;
167 QToolButton* m_fileNameButton;
168 QToolButton* m_contentButton;
169 KSeparator* m_separator;
170 QToolButton* m_fromHereButton;
171 QToolButton* m_everywhereButton;
172
173 KUrl m_searchPath;
174 KUrl m_readOnlyQuery;
175
176 QTimer* m_startSearchTimer;
177 };
178
179 #endif