1 | /****************************************************************************
|
---|
2 | **
|
---|
3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
---|
4 | ** Contact: Qt Software Information ([email protected])
|
---|
5 | **
|
---|
6 | ** This file is part of the QtGui module of the Qt Toolkit.
|
---|
7 | **
|
---|
8 | ** $QT_BEGIN_LICENSE:LGPL$
|
---|
9 | ** Commercial Usage
|
---|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
---|
11 | ** accordance with the Qt Commercial License Agreement provided with the
|
---|
12 | ** Software or, alternatively, in accordance with the terms contained in
|
---|
13 | ** a written agreement between you and Nokia.
|
---|
14 | **
|
---|
15 | ** GNU Lesser General Public License Usage
|
---|
16 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
---|
17 | ** General Public License version 2.1 as published by the Free Software
|
---|
18 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
---|
19 | ** packaging of this file. Please review the following information to
|
---|
20 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
---|
21 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
---|
22 | **
|
---|
23 | ** In addition, as a special exception, Nokia gives you certain
|
---|
24 | ** additional rights. These rights are described in the Nokia Qt LGPL
|
---|
25 | ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
|
---|
26 | ** package.
|
---|
27 | **
|
---|
28 | ** GNU General Public License Usage
|
---|
29 | ** Alternatively, this file may be used under the terms of the GNU
|
---|
30 | ** General Public License version 3.0 as published by the Free Software
|
---|
31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
---|
32 | ** packaging of this file. Please review the following information to
|
---|
33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
---|
34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
---|
35 | **
|
---|
36 | ** If you are unsure which license is appropriate for your use, please
|
---|
37 | ** contact the sales department at [email protected].
|
---|
38 | ** $QT_END_LICENSE$
|
---|
39 | **
|
---|
40 | ****************************************************************************/
|
---|
41 |
|
---|
42 | #ifndef QSIZEPOLICY_H
|
---|
43 | #define QSIZEPOLICY_H
|
---|
44 |
|
---|
45 | #include <QtCore/qobject.h>
|
---|
46 |
|
---|
47 | QT_BEGIN_HEADER
|
---|
48 |
|
---|
49 | QT_BEGIN_NAMESPACE
|
---|
50 |
|
---|
51 | QT_MODULE(Gui)
|
---|
52 |
|
---|
53 | class QVariant;
|
---|
54 |
|
---|
55 | class Q_GUI_EXPORT QSizePolicy
|
---|
56 | {
|
---|
57 | Q_GADGET
|
---|
58 | Q_ENUMS(Policy)
|
---|
59 |
|
---|
60 | private:
|
---|
61 | enum SizePolicyMasks {
|
---|
62 | HSize = 4,
|
---|
63 | HMask = 0x0f,
|
---|
64 | VMask = HMask << HSize,
|
---|
65 | CTShift = 9,
|
---|
66 | CTSize = 5,
|
---|
67 | CTMask = ((0x1 << CTSize) - 1) << CTShift,
|
---|
68 | UnusedShift = CTShift + CTSize,
|
---|
69 | UnusedSize = 2
|
---|
70 | };
|
---|
71 |
|
---|
72 | public:
|
---|
73 | enum PolicyFlag {
|
---|
74 | GrowFlag = 1,
|
---|
75 | ExpandFlag = 2,
|
---|
76 | ShrinkFlag = 4,
|
---|
77 | IgnoreFlag = 8
|
---|
78 | };
|
---|
79 |
|
---|
80 | enum Policy {
|
---|
81 | Fixed = 0,
|
---|
82 | Minimum = GrowFlag,
|
---|
83 | Maximum = ShrinkFlag,
|
---|
84 | Preferred = GrowFlag | ShrinkFlag,
|
---|
85 | MinimumExpanding = GrowFlag | ExpandFlag,
|
---|
86 | Expanding = GrowFlag | ShrinkFlag | ExpandFlag,
|
---|
87 | Ignored = ShrinkFlag | GrowFlag | IgnoreFlag
|
---|
88 | };
|
---|
89 |
|
---|
90 | enum ControlType {
|
---|
91 | DefaultType = 0x00000001,
|
---|
92 | ButtonBox = 0x00000002,
|
---|
93 | CheckBox = 0x00000004,
|
---|
94 | ComboBox = 0x00000008,
|
---|
95 | Frame = 0x00000010,
|
---|
96 | GroupBox = 0x00000020,
|
---|
97 | Label = 0x00000040,
|
---|
98 | Line = 0x00000080,
|
---|
99 | LineEdit = 0x00000100,
|
---|
100 | PushButton = 0x00000200,
|
---|
101 | RadioButton = 0x00000400,
|
---|
102 | Slider = 0x00000800,
|
---|
103 | SpinBox = 0x00001000,
|
---|
104 | TabWidget = 0x00002000,
|
---|
105 | ToolButton = 0x00004000
|
---|
106 | };
|
---|
107 | Q_DECLARE_FLAGS(ControlTypes, ControlType)
|
---|
108 |
|
---|
109 | QSizePolicy() : data(0) { }
|
---|
110 |
|
---|
111 | // ### Qt 5: merge these two constructors (with type == DefaultType)
|
---|
112 | QSizePolicy(Policy horizontal, Policy vertical)
|
---|
113 | : data(horizontal | (vertical << HSize)) { }
|
---|
114 | QSizePolicy(Policy horizontal, Policy vertical, ControlType type)
|
---|
115 | : data(horizontal | (vertical << HSize)) { setControlType(type); }
|
---|
116 |
|
---|
117 | Policy horizontalPolicy() const { return static_cast<Policy>(data & HMask); }
|
---|
118 | Policy verticalPolicy() const { return static_cast<Policy>((data & VMask) >> HSize); }
|
---|
119 | ControlType controlType() const;
|
---|
120 |
|
---|
121 | void setHorizontalPolicy(Policy d) { data = (data & ~HMask) | d; }
|
---|
122 | void setVerticalPolicy(Policy d) { data = (data & ~(HMask << HSize)) | (d << HSize); }
|
---|
123 | void setControlType(ControlType type);
|
---|
124 |
|
---|
125 | Qt::Orientations expandingDirections() const {
|
---|
126 | Qt::Orientations result;
|
---|
127 | if (verticalPolicy() & ExpandFlag)
|
---|
128 | result |= Qt::Vertical;
|
---|
129 | if (horizontalPolicy() & ExpandFlag)
|
---|
130 | result |= Qt::Horizontal;
|
---|
131 | return result;
|
---|
132 | }
|
---|
133 |
|
---|
134 | void setHeightForWidth(bool b) { data = b ? (data | (1 << 2*HSize)) : (data & ~(1 << 2*HSize)); }
|
---|
135 | bool hasHeightForWidth() const { return data & (1 << 2*HSize); }
|
---|
136 |
|
---|
137 | bool operator==(const QSizePolicy& s) const { return data == s.data; }
|
---|
138 | bool operator!=(const QSizePolicy& s) const { return data != s.data; }
|
---|
139 | operator QVariant() const; // implemented in qabstractlayout.cpp
|
---|
140 |
|
---|
141 | int horizontalStretch() const { return data >> 24; }
|
---|
142 | int verticalStretch() const { return (data >> 16) & 0xff; }
|
---|
143 | void setHorizontalStretch(uchar stretchFactor) { data = (data&0x00ffffff) | (uint(stretchFactor)<<24); }
|
---|
144 | void setVerticalStretch(uchar stretchFactor) { data = (data&0xff00ffff) | (uint(stretchFactor)<<16); }
|
---|
145 |
|
---|
146 | void transpose();
|
---|
147 |
|
---|
148 | #ifdef QT3_SUPPORT
|
---|
149 | typedef Policy SizeType;
|
---|
150 | #ifndef qdoc
|
---|
151 | typedef Qt::Orientations ExpandData;
|
---|
152 | enum {
|
---|
153 | NoDirection = 0,
|
---|
154 | Horizontally = 1,
|
---|
155 | Vertically = 2,
|
---|
156 | BothDirections = Horizontally | Vertically
|
---|
157 | };
|
---|
158 | #else
|
---|
159 | enum ExpandData {
|
---|
160 | NoDirection = 0x0,
|
---|
161 | Horizontally = 0x1,
|
---|
162 | Vertically = 0x2,
|
---|
163 | BothDirections = 0x3
|
---|
164 | };
|
---|
165 | #endif // qdoc
|
---|
166 |
|
---|
167 | inline QT3_SUPPORT bool mayShrinkHorizontally() const
|
---|
168 | { return horizontalPolicy() & ShrinkFlag; }
|
---|
169 | inline QT3_SUPPORT bool mayShrinkVertically() const { return verticalPolicy() & ShrinkFlag; }
|
---|
170 | inline QT3_SUPPORT bool mayGrowHorizontally() const { return horizontalPolicy() & GrowFlag; }
|
---|
171 | inline QT3_SUPPORT bool mayGrowVertically() const { return verticalPolicy() & GrowFlag; }
|
---|
172 | inline QT3_SUPPORT Qt::Orientations expanding() const { return expandingDirections(); }
|
---|
173 |
|
---|
174 | QT3_SUPPORT_CONSTRUCTOR QSizePolicy(Policy hor, Policy ver, bool hfw)
|
---|
175 | : data(hor | (ver<<HSize) | (hfw ? (1U<<2*HSize) : 0)) { }
|
---|
176 |
|
---|
177 | QT3_SUPPORT_CONSTRUCTOR QSizePolicy(Policy hor, Policy ver, uchar hors, uchar vers, bool hfw = false)
|
---|
178 | : data(hor | (ver<<HSize) | (hfw ? (1U<<2*HSize) : 0)) {
|
---|
179 | setHorizontalStretch(hors);
|
---|
180 | setVerticalStretch(vers);
|
---|
181 | }
|
---|
182 |
|
---|
183 | inline QT3_SUPPORT Policy horData() const { return static_cast<Policy>(data & HMask); }
|
---|
184 | inline QT3_SUPPORT Policy verData() const { return static_cast<Policy>((data & VMask) >> HSize); }
|
---|
185 | inline QT3_SUPPORT void setHorData(Policy d) { setHorizontalPolicy(d); }
|
---|
186 | inline QT3_SUPPORT void setVerData(Policy d) { setVerticalPolicy(d); }
|
---|
187 |
|
---|
188 | inline QT3_SUPPORT uint horStretch() const { return horizontalStretch(); }
|
---|
189 | inline QT3_SUPPORT uint verStretch() const { return verticalStretch(); }
|
---|
190 | inline QT3_SUPPORT void setHorStretch(uchar sf) { setHorizontalStretch(sf); }
|
---|
191 | inline QT3_SUPPORT void setVerStretch(uchar sf) { setVerticalStretch(sf); }
|
---|
192 | #endif
|
---|
193 |
|
---|
194 | private:
|
---|
195 | #ifndef QT_NO_DATASTREAM
|
---|
196 | friend Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QSizePolicy &);
|
---|
197 | friend Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QSizePolicy &);
|
---|
198 | #endif
|
---|
199 | QSizePolicy(int i) : data(i) { }
|
---|
200 |
|
---|
201 | quint32 data;
|
---|
202 | };
|
---|
203 |
|
---|
204 | Q_DECLARE_OPERATORS_FOR_FLAGS(QSizePolicy::ControlTypes)
|
---|
205 |
|
---|
206 | // implemented in qlayout.cpp
|
---|
207 | Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QSizePolicy &);
|
---|
208 | Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QSizePolicy &);
|
---|
209 |
|
---|
210 | inline void QSizePolicy::transpose() {
|
---|
211 | Policy hData = horizontalPolicy();
|
---|
212 | Policy vData = verticalPolicy();
|
---|
213 | uchar hStretch = horizontalStretch();
|
---|
214 | uchar vStretch = verticalStretch();
|
---|
215 | setHorizontalPolicy(vData);
|
---|
216 | setVerticalPolicy(hData);
|
---|
217 | setHorizontalStretch(vStretch);
|
---|
218 | setVerticalStretch(hStretch);
|
---|
219 | }
|
---|
220 |
|
---|
221 | QT_END_NAMESPACE
|
---|
222 |
|
---|
223 | QT_END_HEADER
|
---|
224 |
|
---|
225 | #endif // QSIZEPOLICY_H
|
---|