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 QSPLITTER_H |
5 | #define QSPLITTER_H |
6 | |
7 | #include <QtWidgets/qtwidgetsglobal.h> |
8 | #include <QtWidgets/qframe.h> |
9 | #include <QtWidgets/qsizepolicy.h> |
10 | |
11 | QT_REQUIRE_CONFIG(splitter); |
12 | |
13 | QT_BEGIN_NAMESPACE |
14 | |
15 | class QSplitterPrivate; |
16 | class QTextStream; |
17 | |
18 | class QSplitterHandle; |
19 | |
20 | class Q_WIDGETS_EXPORT QSplitter : public QFrame |
21 | { |
22 | Q_OBJECT |
23 | |
24 | Q_PROPERTY(Qt::Orientation orientation READ orientation WRITE setOrientation) |
25 | Q_PROPERTY(bool opaqueResize READ opaqueResize WRITE setOpaqueResize) |
26 | Q_PROPERTY(int handleWidth READ handleWidth WRITE setHandleWidth) |
27 | Q_PROPERTY(bool childrenCollapsible READ childrenCollapsible WRITE setChildrenCollapsible) |
28 | |
29 | public: |
30 | explicit QSplitter(QWidget* parent = nullptr); |
31 | explicit QSplitter(Qt::Orientation, QWidget* parent = nullptr); |
32 | ~QSplitter(); |
33 | |
34 | void addWidget(QWidget *widget); |
35 | void insertWidget(int index, QWidget *widget); |
36 | QWidget *replaceWidget(int index, QWidget *widget); |
37 | |
38 | void setOrientation(Qt::Orientation); |
39 | Qt::Orientation orientation() const; |
40 | |
41 | void setChildrenCollapsible(bool); |
42 | bool childrenCollapsible() const; |
43 | |
44 | void setCollapsible(int index, bool); |
45 | bool isCollapsible(int index) const; |
46 | void setOpaqueResize(bool opaque = true); |
47 | bool opaqueResize() const; |
48 | void refresh(); |
49 | |
50 | QSize sizeHint() const override; |
51 | QSize minimumSizeHint() const override; |
52 | |
53 | QList<int> sizes() const; |
54 | void setSizes(const QList<int> &list); |
55 | |
56 | QByteArray saveState() const; |
57 | bool restoreState(const QByteArray &state); |
58 | |
59 | int handleWidth() const; |
60 | void setHandleWidth(int); |
61 | |
62 | int indexOf(QWidget *w) const; |
63 | QWidget *widget(int index) const; |
64 | int count() const; |
65 | |
66 | void getRange(int index, int *, int *) const; |
67 | QSplitterHandle *handle(int index) const; |
68 | |
69 | void setStretchFactor(int index, int stretch); |
70 | |
71 | Q_SIGNALS: |
72 | void splitterMoved(int pos, int index); |
73 | |
74 | protected: |
75 | virtual QSplitterHandle *createHandle(); |
76 | |
77 | void childEvent(QChildEvent *) override; |
78 | |
79 | bool event(QEvent *) override; |
80 | void resizeEvent(QResizeEvent *) override; |
81 | |
82 | void changeEvent(QEvent *) override; |
83 | void moveSplitter(int pos, int index); |
84 | void setRubberBand(int position); |
85 | int closestLegalPosition(int, int); |
86 | |
87 | |
88 | private: |
89 | Q_DISABLE_COPY(QSplitter) |
90 | Q_DECLARE_PRIVATE(QSplitter) |
91 | private: |
92 | friend class QSplitterHandle; |
93 | }; |
94 | |
95 | |
96 | class QSplitterHandlePrivate; |
97 | class Q_WIDGETS_EXPORT QSplitterHandle : public QWidget |
98 | { |
99 | Q_OBJECT |
100 | public: |
101 | explicit QSplitterHandle(Qt::Orientation o, QSplitter *parent); |
102 | ~QSplitterHandle(); |
103 | |
104 | void setOrientation(Qt::Orientation o); |
105 | Qt::Orientation orientation() const; |
106 | bool opaqueResize() const; |
107 | QSplitter *splitter() const; |
108 | |
109 | QSize sizeHint() const override; |
110 | |
111 | protected: |
112 | void paintEvent(QPaintEvent *) override; |
113 | void mouseMoveEvent(QMouseEvent *) override; |
114 | void mousePressEvent(QMouseEvent *) override; |
115 | void mouseReleaseEvent(QMouseEvent *) override; |
116 | void resizeEvent(QResizeEvent *) override; |
117 | bool event(QEvent *) override; |
118 | |
119 | void moveSplitter(int p); |
120 | int closestLegalPosition(int p); |
121 | |
122 | private: |
123 | Q_DISABLE_COPY(QSplitterHandle) |
124 | Q_DECLARE_PRIVATE(QSplitterHandle) |
125 | }; |
126 | |
127 | QT_END_NAMESPACE |
128 | |
129 | #endif // QSPLITTER_H |
130 | |