]> cloud.milkyroute.net Git - dolphin.git/blob - src/kitemviews/private/kitemlistkeyboardsearchmanager.h
Add clang-format and format code as in Frameworks
[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 explicit KItemListKeyboardSearchManager(QObject *parent = nullptr);
31 ~KItemListKeyboardSearchManager() override;
32
33 /**
34 * Add \a keys to the text buffer used for searching.
35 */
36 void addKeys(const QString &keys);
37 /**
38 * @returns true if the next call to addKeys() will trigger a new search.
39 * Returns false if the next added key char will be added to the search string that was used previously.
40 */
41 bool addKeyBeginsNewSearch() const;
42
43 /**
44 * Sets the delay after which the search is cancelled to \a milliseconds.
45 * If the time interval between two calls of addKeys(const QString&) is
46 * larger than this, the second call will start a new search, rather than
47 * combining the keys received from both calls to a single search string.
48 */
49 void setTimeout(qint64 milliseconds);
50 qint64 timeout() const;
51
52 void cancelSearch();
53
54 public Q_SLOTS:
55
56 void slotCurrentChanged(int current, int previous);
57 void slotSelectionChanged(const KItemSet &current, const KItemSet &previous);
58
59 Q_SIGNALS:
60 /**
61 * Is emitted if the current item should be changed corresponding
62 * to \a text.
63 * @param searchFromNextItem If true start searching from item next to the
64 * current item. Otherwise, search from the
65 * current item.
66 */
67 // TODO: Think about getting rid of the bool parameter
68 // (see https://doc.qt.io/archives/qq/qq13-apis.html#thebooleanparametertrap)
69 void changeCurrentItem(const QString &string, bool searchFromNextItem);
70
71 private:
72 bool shouldClearSearchIfInputTimeReached();
73
74 private:
75 QString m_searchedString;
76 bool m_isSearchRestarted;
77 /** Measures the time since the last key press. */
78 QElapsedTimer m_keyboardInputTime;
79 /** Time in milliseconds in which a key press is considered as a continuation of the previous search input. */
80 qint64 m_timeout;
81 };
82
83 #endif