]> cloud.milkyroute.net Git - dolphin.git/blob - src/search/dolphinsearchbox.h
Apply 1 suggestion(s) to 1 file(s)
[dolphin.git] / src / search / dolphinsearchbox.h
1 /*
2 * SPDX-FileCopyrightText: 2010 Peter Penz <peter.penz19@gmail.com>
3 *
4 * SPDX-License-Identifier: GPL-2.0-or-later
5 */
6
7 #ifndef DOLPHINSEARCHBOX_H
8 #define DOLPHINSEARCHBOX_H
9
10 #include "animatedheightwidget.h"
11
12 #include <QUrl>
13
14 class DolphinFacetsWidget;
15 class DolphinQuery;
16 class QLineEdit;
17 class KSeparator;
18 class QToolButton;
19 class QScrollArea;
20 class QLabel;
21 class QVBoxLayout;
22
23 /**
24 * @brief Input box for searching files with or without Baloo.
25 *
26 * The widget allows to specify:
27 * - Where to search: Everywhere or below the current directory
28 * - What to search: Filenames or content
29 *
30 * If Baloo is available and the current folder is indexed, further
31 * options are offered.
32 */
33 class DolphinSearchBox : public AnimatedHeightWidget
34 {
35 Q_OBJECT
36
37 public:
38 explicit DolphinSearchBox(QWidget *parent = nullptr);
39 ~DolphinSearchBox() override;
40
41 /**
42 * Sets the text that should be used as input for
43 * searching.
44 */
45 void setText(const QString &text);
46
47 /**
48 * Returns the text that should be used as input
49 * for searching.
50 */
51 QString text() const;
52
53 /**
54 * Sets the current path that is used as root for searching files.
55 * If @url is the Home dir, "From Here" is selected instead.
56 */
57 void setSearchPath(const QUrl &url);
58 QUrl searchPath() const;
59
60 /** @return URL that will start the searching of files. */
61 QUrl urlForSearching() const;
62
63 /**
64 * Extracts information from the given search \a url to
65 * initialize the search box properly.
66 */
67 void fromSearchUrl(const QUrl &url);
68
69 /**
70 * Selects the whole text of the search box.
71 */
72 void selectAll();
73
74 /**
75 * Set the search box to the active mode, if \a active
76 * is true. The active mode is default. The inactive mode only differs
77 * visually from the active mode, no change of the behavior is given.
78 *
79 * Using the search box in the inactive mode is useful when having split views,
80 * where the inactive view is indicated by an search box visually.
81 */
82 void setActive(bool active);
83
84 /**
85 * @return True, if the search box is in the active mode.
86 * @see DolphinSearchBox::setActive()
87 */
88 bool isActive() const;
89
90 /*
91 * @see AnimatedHeightWidget::setVisible()
92 * @see QWidget::setVisible()
93 */
94 void setVisible(bool visible, Animated animated);
95
96 protected:
97 void showEvent(QShowEvent *event) override;
98 void hideEvent(QHideEvent *event) override;
99 void keyReleaseEvent(QKeyEvent *event) override;
100 bool eventFilter(QObject *obj, QEvent *event) override;
101
102 Q_SIGNALS:
103 /**
104 * Is emitted when a searching should be triggered.
105 */
106 void searchRequest();
107
108 /**
109 * Is emitted when the user has changed a character of
110 * the text that should be used as input for searching.
111 */
112 void searchTextChanged(const QString &text);
113
114 /**
115 * Emitted as soon as the search box should get closed.
116 */
117 void closeRequest();
118
119 /**
120 * Is emitted when the search box should be opened.
121 */
122 void openRequest();
123
124 /**
125 * Is emitted, if the searchbox has been activated by
126 * an user interaction
127 * @see DolphinSearchBox::setActive()
128 */
129 void activated();
130 void focusViewRequest();
131
132 private Q_SLOTS:
133 void emitSearchRequest();
134 void emitCloseRequest();
135 void slotConfigurationChanged();
136 void slotSearchTextChanged(const QString &text);
137 void slotReturnPressed();
138 void slotFacetChanged();
139 void slotSearchSaved();
140
141 private:
142 void initButton(QToolButton *button);
143 void loadSettings();
144 void saveSettings();
145 void init();
146
147 /**
148 * @return URL that represents the Baloo query for starting the search.
149 */
150 QUrl balooUrlForSearching() const;
151
152 /**
153 * Sets the searchbox UI with the parameters established by the \a query
154 */
155 void updateFromQuery(const DolphinQuery &query);
156
157 void updateFacetsVisible();
158
159 bool isIndexingEnabled() const;
160
161 /** @see AnimatedHeightWidget::preferredHeight() */
162 int preferredHeight() const override;
163
164 private:
165 QString queryTitle(const QString &text) const;
166
167 bool m_startedSearching;
168 bool m_active;
169
170 QVBoxLayout *m_topLayout;
171
172 QLineEdit *m_searchInput;
173 QAction *m_saveSearchAction;
174 QScrollArea *m_optionsScrollArea;
175 QToolButton *m_fileNameButton;
176 QToolButton *m_contentButton;
177 KSeparator *m_separator;
178 QToolButton *m_fromHereButton;
179 QToolButton *m_everywhereButton;
180 DolphinFacetsWidget *m_facetsWidget;
181
182 QUrl m_searchPath;
183
184 QTimer *m_startSearchTimer;
185
186 bool m_initialized;
187 };
188
189 #endif