]> cloud.milkyroute.net Git - dolphin.git/blob - src/kitemviews/private/kitemlistkeyboardsearchmanager.h
Output of licensedigger + manual cleanup afterwards.
[dolphin.git] / src / kitemviews / private / kitemlistkeyboardsearchmanager.h
1 /*
2 * SPDX-FileCopyrightText: 2011 Tirtha Chatterjee <tirtha.p.chatterjee@gmail.com>
3 *
4 * Based on the Itemviews NG project from Trolltech Labs
5 *
6 * SPDX-License-Identifier: GPL-2.0-or-later
7 */
8
9 #ifndef KITEMLISTKEYBOARDSEARCHMANAGER_H
10 #define KITEMLISTKEYBOARDSEARCHMANAGER_H
11
12 #include "dolphin_export.h"
13 #include "kitemviews/kitemset.h"
14
15 #include <QElapsedTimer>
16 #include <QObject>
17 #include <QString>
18
19 /**
20 * @brief Controls the keyboard searching ability for a KItemListController.
21 *
22 * @see KItemListController
23 * @see KItemModelBase
24 */
25 class DOLPHIN_EXPORT KItemListKeyboardSearchManager : public QObject
26 {
27 Q_OBJECT
28
29 public:
30
31 explicit KItemListKeyboardSearchManager(QObject* parent = nullptr);
32 ~KItemListKeyboardSearchManager() override;
33
34 /**
35 * Add \a keys to the text buffer used for searching.
36 */
37 void addKeys(const QString& keys);
38
39 /**
40 * Sets the delay after which the search is cancelled to \a milliseconds.
41 * If the time interval between two calls of addKeys(const QString&) is
42 * larger than this, the second call will start a new search, rather than
43 * combining the keys received from both calls to a single search string.
44 */
45 void setTimeout(qint64 milliseconds);
46 qint64 timeout() const;
47
48 void cancelSearch();
49 bool shouldClearSearchIfInputTimeReached();
50
51 public slots:
52
53 void slotCurrentChanged(int current, int previous);
54 void slotSelectionChanged(const KItemSet& current, const KItemSet& previous);
55
56 signals:
57 /**
58 * Is emitted if the current item should be changed corresponding
59 * to \a text.
60 * @param searchFromNextItem If true start searching from item next to the
61 * current item. Otherwise, search from the
62 * current item.
63 */
64 // TODO: Think about getting rid of the bool parameter
65 // (see https://doc.qt.io/archives/qq/qq13-apis.html#thebooleanparametertrap)
66 void changeCurrentItem(const QString& string, bool searchFromNextItem);
67
68 private:
69 QString m_searchedString;
70 bool m_isSearchRestarted;
71 QElapsedTimer m_keyboardInputTime;
72 qint64 m_timeout;
73 };
74
75 #endif
76
77