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
10QT_BEGIN_NAMESPACE
11
12class QAction;
13class QCheckBox;
14class QEvent;
15class QKeyEvent;
16class QLabel;
17class QLineEdit;
18class QObject;
19class QToolButton;
20
21class AbstractFindWidget : public QWidget
22{
23 Q_OBJECT
24
25public:
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
44public slots:
45 void activate();
46 virtual void deactivate();
47 void findNext();
48 void findPrevious();
49 void findCurrentText();
50
51protected:
52 void keyPressEvent(QKeyEvent *event) override;
53
54private slots:
55 void updateButtons();
56
57protected:
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
63private:
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
75Q_DECLARE_OPERATORS_FOR_FLAGS(AbstractFindWidget::FindFlags)
76
77QT_END_NAMESPACE
78
79#endif // ABSTRACTFINDWIDGET_H
80

source code of qttools/src/shared/findwidget/abstractfindwidget.h