source: trunk/src/gui/kernel/qsizepolicy.h@ 651

Last change on this file since 651 was 651, checked in by Dmitry A. Kuminov, 15 years ago

trunk: Merged in qt 4.6.2 sources.

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