1 | /**************************************************************************** |
2 | ** |
3 | ** Copyright (C) 2016 The Qt Company Ltd. |
4 | ** Contact: https://www.qt.io/licensing/ |
5 | ** |
6 | ** This file is part of the QtWidgets module of the Qt Toolkit. |
7 | ** |
8 | ** $QT_BEGIN_LICENSE:LGPL$ |
9 | ** Commercial License Usage |
10 | ** Licensees holding valid commercial Qt licenses may use this file in |
11 | ** accordance with the commercial license agreement provided with the |
12 | ** Software or, alternatively, in accordance with the terms contained in |
13 | ** a written agreement between you and The Qt Company. For licensing terms |
14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
15 | ** information use the contact form at https://www.qt.io/contact-us. |
16 | ** |
17 | ** GNU Lesser General Public License Usage |
18 | ** Alternatively, this file may be used under the terms of the GNU Lesser |
19 | ** General Public License version 3 as published by the Free Software |
20 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the |
21 | ** packaging of this file. Please review the following information to |
22 | ** ensure the GNU Lesser General Public License version 3 requirements |
23 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. |
24 | ** |
25 | ** GNU General Public License Usage |
26 | ** Alternatively, this file may be used under the terms of the GNU |
27 | ** General Public License version 2.0 or (at your option) the GNU General |
28 | ** Public license version 3 or any later version approved by the KDE Free |
29 | ** Qt Foundation. The licenses are as published by the Free Software |
30 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 |
31 | ** included in the packaging of this file. Please review the following |
32 | ** information to ensure the GNU General Public License requirements will |
33 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and |
34 | ** https://www.gnu.org/licenses/gpl-3.0.html. |
35 | ** |
36 | ** $QT_END_LICENSE$ |
37 | ** |
38 | ****************************************************************************/ |
39 | |
40 | #ifndef QSPLITTER_H |
41 | #define QSPLITTER_H |
42 | |
43 | #include <QtWidgets/qtwidgetsglobal.h> |
44 | #include <QtWidgets/qframe.h> |
45 | #include <QtWidgets/qsizepolicy.h> |
46 | |
47 | QT_REQUIRE_CONFIG(splitter); |
48 | |
49 | QT_BEGIN_NAMESPACE |
50 | |
51 | class QSplitterPrivate; |
52 | class QTextStream; |
53 | template <typename T> class QList; |
54 | |
55 | class QSplitterHandle; |
56 | |
57 | class Q_WIDGETS_EXPORT QSplitter : public QFrame |
58 | { |
59 | Q_OBJECT |
60 | |
61 | Q_PROPERTY(Qt::Orientation orientation READ orientation WRITE setOrientation) |
62 | Q_PROPERTY(bool opaqueResize READ opaqueResize WRITE setOpaqueResize) |
63 | Q_PROPERTY(int handleWidth READ handleWidth WRITE setHandleWidth) |
64 | Q_PROPERTY(bool childrenCollapsible READ childrenCollapsible WRITE setChildrenCollapsible) |
65 | |
66 | public: |
67 | explicit QSplitter(QWidget* parent = nullptr); |
68 | explicit QSplitter(Qt::Orientation, QWidget* parent = nullptr); |
69 | ~QSplitter(); |
70 | |
71 | void addWidget(QWidget *widget); |
72 | void insertWidget(int index, QWidget *widget); |
73 | QWidget *replaceWidget(int index, QWidget *widget); |
74 | |
75 | void setOrientation(Qt::Orientation); |
76 | Qt::Orientation orientation() const; |
77 | |
78 | void setChildrenCollapsible(bool); |
79 | bool childrenCollapsible() const; |
80 | |
81 | void setCollapsible(int index, bool); |
82 | bool isCollapsible(int index) const; |
83 | void setOpaqueResize(bool opaque = true); |
84 | bool opaqueResize() const; |
85 | void refresh(); |
86 | |
87 | QSize sizeHint() const override; |
88 | QSize minimumSizeHint() const override; |
89 | |
90 | QList<int> sizes() const; |
91 | void setSizes(const QList<int> &list); |
92 | |
93 | QByteArray saveState() const; |
94 | bool restoreState(const QByteArray &state); |
95 | |
96 | int handleWidth() const; |
97 | void setHandleWidth(int); |
98 | |
99 | int indexOf(QWidget *w) const; |
100 | QWidget *widget(int index) const; |
101 | int count() const; |
102 | |
103 | void getRange(int index, int *, int *) const; |
104 | QSplitterHandle *handle(int index) const; |
105 | |
106 | void setStretchFactor(int index, int stretch); |
107 | |
108 | Q_SIGNALS: |
109 | void splitterMoved(int pos, int index); |
110 | |
111 | protected: |
112 | virtual QSplitterHandle *createHandle(); |
113 | |
114 | void childEvent(QChildEvent *) override; |
115 | |
116 | bool event(QEvent *) override; |
117 | void resizeEvent(QResizeEvent *) override; |
118 | |
119 | void changeEvent(QEvent *) override; |
120 | void moveSplitter(int pos, int index); |
121 | void setRubberBand(int position); |
122 | int closestLegalPosition(int, int); |
123 | |
124 | |
125 | private: |
126 | Q_DISABLE_COPY(QSplitter) |
127 | Q_DECLARE_PRIVATE(QSplitter) |
128 | private: |
129 | friend class QSplitterHandle; |
130 | }; |
131 | |
132 | #if QT_DEPRECATED_SINCE(5, 13) |
133 | QT_DEPRECATED_X("Use QSplitter::saveState() instead" ) |
134 | Q_WIDGETS_EXPORT QTextStream& operator<<(QTextStream&, const QSplitter&); |
135 | QT_DEPRECATED_X("Use QSplitter::restoreState() instead" ) |
136 | Q_WIDGETS_EXPORT QTextStream& operator>>(QTextStream&, QSplitter&); |
137 | #endif |
138 | |
139 | class QSplitterHandlePrivate; |
140 | class Q_WIDGETS_EXPORT QSplitterHandle : public QWidget |
141 | { |
142 | Q_OBJECT |
143 | public: |
144 | explicit QSplitterHandle(Qt::Orientation o, QSplitter *parent); |
145 | ~QSplitterHandle(); |
146 | |
147 | void setOrientation(Qt::Orientation o); |
148 | Qt::Orientation orientation() const; |
149 | bool opaqueResize() const; |
150 | QSplitter *splitter() const; |
151 | |
152 | QSize sizeHint() const override; |
153 | |
154 | protected: |
155 | void paintEvent(QPaintEvent *) override; |
156 | void mouseMoveEvent(QMouseEvent *) override; |
157 | void mousePressEvent(QMouseEvent *) override; |
158 | void mouseReleaseEvent(QMouseEvent *) override; |
159 | void resizeEvent(QResizeEvent *) override; |
160 | bool event(QEvent *) override; |
161 | |
162 | void moveSplitter(int p); |
163 | int closestLegalPosition(int p); |
164 | |
165 | private: |
166 | Q_DISABLE_COPY(QSplitterHandle) |
167 | Q_DECLARE_PRIVATE(QSplitterHandle) |
168 | }; |
169 | |
170 | QT_END_NAMESPACE |
171 | |
172 | #endif // QSPLITTER_H |
173 | |