-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Expand file tree
/
Copy pathCutterSearchable.h
More file actions
94 lines (78 loc) · 2.43 KB
/
CutterSearchable.h
File metadata and controls
94 lines (78 loc) · 2.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#ifndef CUTTERSEARCHABLE_H
#define CUTTERSEARCHABLE_H
class QString;
class QSortFilterProxyModel;
class SearchBarWidget;
class QWidget;
enum SearchOption {
CaseSensitive = 1,
WholeWords = 1 << 1,
RegExp = 1 << 2,
HighlightMatches = 1 << 3
};
/**
* @brief Interface for any widget that needs a search bar
*/
class CutterSearchable
{
public:
virtual ~CutterSearchable() = default;
/**
* @brief Widget which the search bar will be shown relative to
*/
virtual QWidget *searchableArea() const = 0;
/**
* @brief Padding from the right
*/
virtual int searchHPadding() const = 0;
/**
* @brief Padding from the top
*/
virtual int searchVPadding() const = 0;
/**
* @brief Called when the user types in the search bar or changes search options
* Text has a debounce timer of 200ms
*/
virtual void searchChanged(const QString &text, int options) = 0;
virtual void findNext() = 0;
virtual void findPrev() = 0;
virtual void findLast() = 0;
/**
* @brief Called when the search bar is closed
*/
virtual void searchBarHidden() = 0;
/**
* @brief Called when the search bar is shown
*/
virtual void searchBarShown() = 0;
};
/**
* @brief Helper functions for the search bar
*/
namespace CutterSearchableHelper {
/**
* @brief Connects the search bar to the parent widget
* @param parent The widget that owns the search bar
* @param bar The search bar to connect
*/
void setupConnections(QWidget *parent, SearchBarWidget *bar);
/**
* @brief Sets the search bar position
* Call this in the resizeEvent of the parent widget
* @param parent The main widget holding the search bar
* @param searchBar The search bar being moved
* @param searchArea The widget which the search bar will be shown relative to
* @param hPadding Padding from the right
* @param vPadding Padding from the top
*/
void positionSearchBar(QWidget *parent, SearchBarWidget *searchBar, QWidget *searchArea,
int hPadding, int vPadding);
/**
* @brief Applies filter options to a proxy model
* @param proxyModel The proxy model to filter
* @param filterText The text to filter by
* @param options Bitwise combination of SearchOption flags (CaseSensitive, WholeWords, RegExp)
*/
void applyFilter(QSortFilterProxyModel *proxyModel, const QString &filterText, int options);
} // namespace CutterSearchableHelper
#endif // CUTTERSEARCHABLE_H