Fix QT_NO_DATASTREAM macro checks and improve readability
[qt-netbsd.git] / src / gui / kernel / qsizepolicy.h
blob32b3b4f958a30418d4baad075d9bb7534c69dfa3
1 /****************************************************************************
2 **
3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: Qt Software Information (qt-info@nokia.com)
5 **
6 ** This file is part of the QtGui module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** No Commercial Usage
10 ** This file contains pre-release code and may not be distributed.
11 ** You may use this file in accordance with the terms and conditions
12 ** contained in the either Technology Preview License Agreement or the
13 ** Beta Release License Agreement.
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.
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.
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.
36 ** If you are unsure which license is appropriate for your use, please
37 ** contact the sales department at qt-sales@nokia.com.
38 ** $QT_END_LICENSE$
40 ****************************************************************************/
42 #ifndef QSIZEPOLICY_H
43 #define QSIZEPOLICY_H
45 #include <QtCore/qobject.h>
47 QT_BEGIN_HEADER
49 QT_BEGIN_NAMESPACE
51 QT_MODULE(Gui)
53 class QVariant;
55 class Q_GUI_EXPORT QSizePolicy
57 Q_GADGET
58 Q_ENUMS(Policy)
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
72 public:
73 enum PolicyFlag {
74 GrowFlag = 1,
75 ExpandFlag = 2,
76 ShrinkFlag = 4,
77 IgnoreFlag = 8
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
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
107 Q_DECLARE_FLAGS(ControlTypes, ControlType)
109 QSizePolicy() : data(0) { }
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); }
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;
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);
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;
134 void setHeightForWidth(bool b) { data = b ? (data | (1 << 2*HSize)) : (data & ~(1 << 2*HSize)); }
135 bool hasHeightForWidth() const { return data & (1 << 2*HSize); }
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
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); }
146 void transpose();
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
158 #else
159 enum ExpandData {
160 NoDirection = 0x0,
161 Horizontally = 0x1,
162 Vertically = 0x2,
163 BothDirections = 0x3
165 #endif // qdoc
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(); }
174 QT3_SUPPORT_CONSTRUCTOR QSizePolicy(Policy hor, Policy ver, bool hfw)
175 : data(hor | (ver<<HSize) | (hfw ? (1U<<2*HSize) : 0)) { }
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);
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); }
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
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) { }
201 quint32 data;
204 Q_DECLARE_OPERATORS_FOR_FLAGS(QSizePolicy::ControlTypes)
206 #ifndef QT_NO_DATASTREAM
207 // implemented in qlayout.cpp
208 Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QSizePolicy &);
209 Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QSizePolicy &);
210 #endif
212 inline void QSizePolicy::transpose() {
213 Policy hData = horizontalPolicy();
214 Policy vData = verticalPolicy();
215 uchar hStretch = horizontalStretch();
216 uchar vStretch = verticalStretch();
217 setHorizontalPolicy(vData);
218 setVerticalPolicy(hData);
219 setHorizontalStretch(vStretch);
220 setVerticalStretch(hStretch);
223 QT_END_NAMESPACE
225 QT_END_HEADER
227 #endif // QSIZEPOLICY_H