1 | // Copyright (C) 2016 The Qt Company Ltd. |
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
3 | |
4 | #ifndef ABSTRACTFINDWIDGET_H |
5 | #define ABSTRACTFINDWIDGET_H |
6 | |
7 | #include <QtGui/QIcon> |
8 | #include <QtWidgets/QWidget> |
9 | |
10 | QT_BEGIN_NAMESPACE |
11 | |
12 | class QAction; |
13 | class QCheckBox; |
14 | class QEvent; |
15 | class QKeyEvent; |
16 | class QLabel; |
17 | class QLineEdit; |
18 | class QObject; |
19 | class QToolButton; |
20 | |
21 | class AbstractFindWidget : public QWidget |
22 | { |
23 | Q_OBJECT |
24 | |
25 | public: |
26 | enum FindFlag { |
27 | /// Use a layout that is roughly half as wide and twice as high as the regular one. |
28 | NarrowLayout = 1, |
29 | /// Do not show the "Whole words" checkbox. |
30 | NoWholeWords = 2, |
31 | /// Do not show the "Case sensitive" checkbox. |
32 | NoCaseSensitive = 4 |
33 | }; |
34 | Q_DECLARE_FLAGS(FindFlags, FindFlag) |
35 | |
36 | explicit AbstractFindWidget(FindFlags flags = FindFlags(), QWidget *parent = 0); |
37 | ~AbstractFindWidget() override; |
38 | |
39 | bool eventFilter(QObject *object, QEvent *e) override; |
40 | |
41 | static QIcon findIconSet(); |
42 | QAction *createFindAction(QObject *parent); |
43 | |
44 | public slots: |
45 | void activate(); |
46 | virtual void deactivate(); |
47 | void findNext(); |
48 | void findPrevious(); |
49 | void findCurrentText(); |
50 | |
51 | protected: |
52 | void keyPressEvent(QKeyEvent *event) override; |
53 | |
54 | private slots: |
55 | void updateButtons(); |
56 | |
57 | protected: |
58 | virtual void find(const QString &textToFind, bool skipCurrent, bool backward, bool *found, bool *wrapped) = 0; |
59 | |
60 | bool caseSensitive() const; |
61 | bool wholeWords() const; |
62 | |
63 | private: |
64 | void findInternal(const QString &textToFind, bool skipCurrent, bool backward); |
65 | |
66 | QLineEdit *m_editFind; |
67 | QLabel *m_labelWrapped; |
68 | QToolButton *m_toolNext; |
69 | QToolButton *m_toolClose; |
70 | QToolButton *m_toolPrevious; |
71 | QCheckBox *m_checkCase; |
72 | QCheckBox *m_checkWholeWords; |
73 | }; |
74 | |
75 | Q_DECLARE_OPERATORS_FOR_FLAGS(AbstractFindWidget::FindFlags) |
76 | |
77 | QT_END_NAMESPACE |
78 | |
79 | #endif // ABSTRACTFINDWIDGET_H |
80 | |