2 * SPDX-FileCopyrightText: 2011 Tirtha Chatterjee <tirtha.p.chatterjee@gmail.com>
4 * Based on the Itemviews NG project from Trolltech Labs
6 * SPDX-License-Identifier: GPL-2.0-or-later
9 #ifndef KITEMLISTKEYBOARDSEARCHMANAGER_H
10 #define KITEMLISTKEYBOARDSEARCHMANAGER_H
12 #include "dolphin_export.h"
13 #include "kitemviews/kitemset.h"
15 #include <QElapsedTimer>
20 * @brief Controls the keyboard searching ability for a KItemListController.
22 * @see KItemListController
25 class DOLPHIN_EXPORT KItemListKeyboardSearchManager
: public QObject
31 explicit KItemListKeyboardSearchManager(QObject
* parent
= nullptr);
32 ~KItemListKeyboardSearchManager() override
;
35 * Add \a keys to the text buffer used for searching.
37 void addKeys(const QString
& keys
);
39 * @returns true if the next call to addKeys() will trigger a new search.
40 * Returns false if the next added key char will be added to the search string that was used previously.
42 bool addKeyBeginsNewSearch() const;
45 * Sets the delay after which the search is cancelled to \a milliseconds.
46 * If the time interval between two calls of addKeys(const QString&) is
47 * larger than this, the second call will start a new search, rather than
48 * combining the keys received from both calls to a single search string.
50 void setTimeout(qint64 milliseconds
);
51 qint64
timeout() const;
57 void slotCurrentChanged(int current
, int previous
);
58 void slotSelectionChanged(const KItemSet
& current
, const KItemSet
& previous
);
62 * Is emitted if the current item should be changed corresponding
64 * @param searchFromNextItem If true start searching from item next to the
65 * current item. Otherwise, search from the
68 // TODO: Think about getting rid of the bool parameter
69 // (see https://doc.qt.io/archives/qq/qq13-apis.html#thebooleanparametertrap)
70 void changeCurrentItem(const QString
& string
, bool searchFromNextItem
);
73 bool shouldClearSearchIfInputTimeReached();
76 QString m_searchedString
;
77 bool m_isSearchRestarted
;
78 /** Measures the time since the last key press. */
79 QElapsedTimer m_keyboardInputTime
;
80 /** Time in milliseconds in which a key press is considered as a continuation of the previous search input. */