]> cloud.milkyroute.net Git - dolphin.git/blob - src/search/dolphinsearchbox.h
DolphinView: get rid of writeStateChanged signal in setActive()
[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 <QUrl>
11 #include <QWidget>
12
13 class DolphinFacetsWidget;
14 class DolphinQuery;
15 class QLineEdit;
16 class KSeparator;
17 class QToolButton;
18 class QScrollArea;
19 class QLabel;
20 class QVBoxLayout;
21 class KMoreToolsMenuFactory;
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 QWidget
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 protected:
91 bool event(QEvent *event) override;
92 void showEvent(QShowEvent *event) override;
93 void hideEvent(QHideEvent *event) override;
94 void keyReleaseEvent(QKeyEvent *event) override;
95 bool eventFilter(QObject *obj, QEvent *event) override;
96
97 Q_SIGNALS:
98 /**
99 * Is emitted when a searching should be triggered.
100 */
101 void searchRequest();
102
103 /**
104 * Is emitted when the user has changed a character of
105 * the text that should be used as input for searching.
106 */
107 void searchTextChanged(const QString &text);
108
109 /**
110 * Emitted as soon as the search box should get closed.
111 */
112 void closeRequest();
113
114 /**
115 * Is emitted when the search box should be opened.
116 */
117 void openRequest();
118
119 /**
120 * Is emitted, if the searchbox has been activated by
121 * an user interaction
122 * @see DolphinSearchBox::setActive()
123 */
124 void activated();
125 void focusViewRequest();
126
127 private Q_SLOTS:
128 void emitSearchRequest();
129 void emitCloseRequest();
130 void slotConfigurationChanged();
131 void slotSearchTextChanged(const QString &text);
132 void slotReturnPressed();
133 void slotFacetChanged();
134 void slotSearchSaved();
135
136 private:
137 void initButton(QToolButton *button);
138 void loadSettings();
139 void saveSettings();
140 void init();
141
142 /**
143 * @return URL that represents the Baloo query for starting the search.
144 */
145 QUrl balooUrlForSearching() const;
146
147 /**
148 * Sets the searchbox UI with the parameters established by the \a query
149 */
150 void updateFromQuery(const DolphinQuery &query);
151
152 void updateFacetsVisible();
153
154 bool isIndexingEnabled() const;
155
156 private:
157 QString queryTitle(const QString &text) const;
158
159 bool m_startedSearching;
160 bool m_active;
161
162 QVBoxLayout *m_topLayout;
163
164 QLineEdit *m_searchInput;
165 QAction *m_saveSearchAction;
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 DolphinFacetsWidget *m_facetsWidget;
173
174 QUrl m_searchPath;
175 QScopedPointer<KMoreToolsMenuFactory> m_menuFactory;
176
177 QTimer *m_startSearchTimer;
178 };
179
180 #endif