1 | // Copyright (C) 2016 The Qt Company Ltd. |
---|---|
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 |
3 | |
4 | #ifndef OPENPAGESWIDGET_H |
5 | #define OPENPAGESWIDGET_H |
6 | |
7 | #include <QtWidgets/QStyledItemDelegate> |
8 | #include <QtWidgets/QTreeView> |
9 | |
10 | QT_BEGIN_NAMESPACE |
11 | |
12 | class OpenPagesModel; |
13 | |
14 | class OpenPagesDelegate : public QStyledItemDelegate |
15 | { |
16 | Q_OBJECT |
17 | public: |
18 | explicit OpenPagesDelegate(QObject *parent = nullptr); |
19 | void paint(QPainter *painter, const QStyleOptionViewItem &option, |
20 | const QModelIndex &index) const override; |
21 | |
22 | mutable QModelIndex pressedIndex; |
23 | }; |
24 | |
25 | class OpenPagesWidget : public QTreeView |
26 | { |
27 | Q_OBJECT |
28 | public: |
29 | OpenPagesWidget(OpenPagesModel *model); |
30 | ~OpenPagesWidget() override; |
31 | |
32 | void selectCurrentPage(); |
33 | void allowContextMenu(bool ok); |
34 | |
35 | signals: |
36 | void setCurrentPage(const QModelIndex &index); |
37 | void closePage(const QModelIndex &index); |
38 | void closePagesExcept(const QModelIndex &index); |
39 | |
40 | private slots: |
41 | void contextMenuRequested(QPoint pos); |
42 | void handlePressed(const QModelIndex &index); |
43 | void handleClicked(const QModelIndex &index); |
44 | |
45 | private: |
46 | bool eventFilter(QObject *obj, QEvent *event) override; |
47 | |
48 | bool m_allowContextMenu; |
49 | OpenPagesDelegate *m_delegate; |
50 | }; |
51 | |
52 | QT_END_NAMESPACE |
53 | |
54 | #endif // OPENPAGESWIDGET_H |
55 |