1 /****************************************************************************
2 **
3 ** DQt - D bindings for the Qt Toolkit
4 **
5 ** GNU Lesser General Public License Usage
6 ** This file may be used under the terms of the GNU Lesser
7 ** General Public License version 3 as published by the Free Software
8 ** Foundation and appearing in the file LICENSE.LGPL3 included in the
9 ** packaging of this file. Please review the following information to
10 ** ensure the GNU Lesser General Public License version 3 requirements
11 ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
12 **
13 ****************************************************************************/
14 module qt.widgets.sizepolicy;
15 extern(C++):
16 
17 import qt.config;
18 import qt.core.flags;
19 import qt.core.global;
20 import qt.core.metatype;
21 import qt.core.namespace;
22 import qt.core.objectdefs;
23 import qt.core.typeinfo;
24 import qt.core.variant;
25 import qt.helpers;
26 
27 // gcc < 4.8.0 has problems with init'ing variant members in constexpr ctors
28 // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=54922
29 /+ #if !defined(Q_CC_GNU) || defined(Q_CC_INTEL) || defined(Q_CC_CLANG) || Q_CC_GNU >= 408
30 # define QT_SIZEPOLICY_CONSTEXPR Q_DECL_CONSTEXPR
31 # if defined(Q_COMPILER_UNIFORM_INIT)
32 #  define QT_SIZEPOLICY_CONSTEXPR_AND_UNIFORM_INIT Q_DECL_CONSTEXPR
33 # endif // uniform-init
34 #endif
35 
36 #ifndef QT_SIZEPOLICY_CONSTEXPR
37 # define QT_SIZEPOLICY_CONSTEXPR
38 #endif
39 #ifndef QT_SIZEPOLICY_CONSTEXPR_AND_UNIFORM_INIT
40 # define QT_SIZEPOLICY_CONSTEXPR_AND_UNIFORM_INIT
41 #endif
42 
43 class QVariant;
44 class QSizePolicy;
45 
46 Q_DECL_CONST_FUNCTION inline uint qHash(QSizePolicy key, uint seed = 0) noexcept; +/
47 
48 @(QMetaType.Type.QSizePolicy) @Q_RELOCATABLE_TYPE extern(C++, class) struct /+ Q_WIDGETS_EXPORT +/ QSizePolicy
49 {
50     mixin(Q_GADGET);
51 
52 public:
53     enum PolicyFlag {
54         GrowFlag = 1,
55         ExpandFlag = 2,
56         ShrinkFlag = 4,
57         IgnoreFlag = 8
58     }
59 
60     enum Policy {
61         Fixed = 0,
62         Minimum = PolicyFlag.GrowFlag,
63         Maximum = PolicyFlag.ShrinkFlag,
64         Preferred = PolicyFlag.GrowFlag | PolicyFlag.ShrinkFlag,
65         MinimumExpanding = PolicyFlag.GrowFlag | PolicyFlag.ExpandFlag,
66         Expanding = PolicyFlag.GrowFlag | PolicyFlag.ShrinkFlag | PolicyFlag.ExpandFlag,
67         Ignored = PolicyFlag.ShrinkFlag | PolicyFlag.GrowFlag | PolicyFlag.IgnoreFlag
68     }
69     /+ Q_ENUM(Policy) +/
70 
71     enum ControlType {
72         DefaultType      = 0x00000001,
73         ButtonBox        = 0x00000002,
74         CheckBox         = 0x00000004,
75         ComboBox         = 0x00000008,
76         Frame            = 0x00000010,
77         GroupBox         = 0x00000020,
78         Label            = 0x00000040,
79         Line             = 0x00000080,
80         LineEdit         = 0x00000100,
81         PushButton       = 0x00000200,
82         RadioButton      = 0x00000400,
83         Slider           = 0x00000800,
84         SpinBox          = 0x00001000,
85         TabWidget        = 0x00002000,
86         ToolButton       = 0x00004000
87     }
88     /+ Q_DECLARE_FLAGS(ControlTypes, ControlType) +/
89 alias ControlTypes = QFlags!(ControlType);    /+ Q_FLAG(ControlTypes) +/
90 
91     @disable this();
92     /+this()/+ noexcept+/
93     {
94         this.data = 0;
95     }+/
96 
97 /+ #if defined(Q_COMPILER_UNIFORM_INIT) && !defined(Q_QDOC)
98     QSizePolicy(Policy horizontal, Policy vertical, ControlType type = DefaultType) noexcept
99         : bits{0, 0, quint32(horizontal), quint32(vertical),
100                type == DefaultType ? 0 : toControlTypeFieldValue(type), 0, 0, 0}
101     {}
102 #else +/
103     this(Policy horizontal, Policy vertical, ControlType type = ControlType.DefaultType)/+ noexcept+/
104     {
105         this.data = 0;
106 
107         bits.horPolicy = horizontal;
108         bits.verPolicy = vertical;
109         setControlType(type);
110     }
111 /+ #endif +/ // uniform-init
112     Policy horizontalPolicy() const/+ noexcept+/ { return static_cast!(Policy)(bits.horPolicy); }
113     Policy verticalPolicy() const/+ noexcept+/ { return static_cast!(Policy)(bits.verPolicy); }
114     ControlType controlType() const/+ noexcept+/;
115 
116     void setHorizontalPolicy(Policy d)/+ noexcept+/ { bits.horPolicy = d; }
117     void setVerticalPolicy(Policy d)/+ noexcept+/ { bits.verPolicy = d; }
118     void setControlType(ControlType type)/+ noexcept+/;
119 
120     /+ Qt:: +/qt.core.namespace.Orientations expandingDirections() const/+ noexcept+/ {
121         return ( (verticalPolicy()   & PolicyFlag.ExpandFlag) ? /+ Qt:: +/qt.core.namespace.Orientations.Vertical   : /+ Qt:: +/qt.core.namespace.Orientations() )
122              | ( (horizontalPolicy() & PolicyFlag.ExpandFlag) ? /+ Qt:: +/qt.core.namespace.Orientations.Horizontal : /+ Qt:: +/qt.core.namespace.Orientations() ) ;
123     }
124 
125     void setHeightForWidth(bool b)/+ noexcept+/ { bits.hfw = b;  }
126     bool hasHeightForWidth() const/+ noexcept+/ { return !!bits.hfw; }
127     void setWidthForHeight(bool b)/+ noexcept+/ { bits.wfh = b;  }
128     bool hasWidthForHeight() const/+ noexcept+/ { return !!bits.wfh; }
129 
130     /+bool operator ==(ref const(QSizePolicy) s) const/+ noexcept+/ { return data == s.data; }+/
131     /+bool operator !=(ref const(QSizePolicy) s) const/+ noexcept+/ { return data != s.data; }+/
132 
133     /+ friend Q_DECL_CONST_FUNCTION uint qHash(QSizePolicy key, uint seed) noexcept { return qHash(key.data, seed); } +/
134 
135     /+auto opCast(T : QVariant)() const;+/
136 
137     int horizontalStretch() const/+ noexcept+/ { return static_cast!(int)(bits.horStretch); }
138     int verticalStretch() const/+ noexcept+/ { return static_cast!(int)(bits.verStretch); }
139     void setHorizontalStretch(int stretchFactor) { bits.horStretch = static_cast!(quint32)(qBound(0, stretchFactor, 255)); }
140     void setVerticalStretch(int stretchFactor) { bits.verStretch = static_cast!(quint32)(qBound(0, stretchFactor, 255)); }
141 
142 //    bool retainSizeWhenHidden() const/+ noexcept+/ { return bits.retainSizeWhenHidden; }
143 //    void setRetainSizeWhenHidden(bool retainSize)/+ noexcept+/ { bits.retainSizeWhenHidden = retainSize; }
144 
145 //    void transpose()/+ noexcept+/ { this = transposed(); }
146     /+ Q_REQUIRED_RESULT +/
147     /+ #ifndef Q_QDOC
148         QT_SIZEPOLICY_CONSTEXPR_AND_UNIFORM_INIT
149     #endif +/
150 /+        QSizePolicy transposed() const/+ noexcept+/
151     {
152         return QSizePolicy(bits.transposed());
153     }+/
154 
155 private:
156     version(QT_NO_DATASTREAM){}else
157     {
158         /+ friend Q_WIDGETS_EXPORT QDataStream &operator<<(QDataStream &, const QSizePolicy &); +/
159         /+ friend Q_WIDGETS_EXPORT QDataStream &operator>>(QDataStream &, QSizePolicy &); +/
160     }
161     this(int i)/+ noexcept+/
162     {
163         this.data = i;
164     }
165     /+
166     struct Bits;
167     +/
168     /+/+ explicit +/this(Bits b)/+ noexcept+/
169     {
170         this.bits = b;
171     }+/
172 
173 /+    static quint32 toControlTypeFieldValue(ControlType type)/+ noexcept+/
174     {
175         /*
176           The control type is a flag type, with values 0x1, 0x2, 0x4, 0x8, 0x10,
177           etc. In memory, we pack it onto the available bits (CTSize) in
178           setControlType(), and unpack it here.
179 
180           Example:
181 
182           0x00000001 maps to 0
183           0x00000002 maps to 1
184           0x00000004 maps to 2
185           0x00000008 maps to 3
186           etc.
187         */
188 
189         return qCountTrailingZeroBits(static_cast!(quint32)(type));
190     }+/
191 
192     struct Bits {
193         /+ quint32 horStretch : 8; +/
194         uint bitfieldData_horStretch;
195         final quint32 horStretch() const
196         {
197             return (bitfieldData_horStretch >> 0) & 0xff;
198         }
199         final uint horStretch(uint value)
200         {
201             bitfieldData_horStretch = (bitfieldData_horStretch & ~0xff) | ((value & 0xff) << 0);
202             return value;
203         }
204         /+ quint32 verStretch : 8; +/
205         final quint32 verStretch() const
206         {
207             return (bitfieldData_horStretch >> 8) & 0xff;
208         }
209         final uint verStretch(uint value)
210         {
211             bitfieldData_horStretch = (bitfieldData_horStretch & ~0xff00) | ((value & 0xff) << 8);
212             return value;
213         }
214         /+ quint32 horPolicy : 4; +/
215         final quint32 horPolicy() const
216         {
217             return (bitfieldData_horStretch >> 16) & 0xf;
218         }
219         final uint horPolicy(uint value)
220         {
221             bitfieldData_horStretch = (bitfieldData_horStretch & ~0xf0000) | ((value & 0xf) << 16);
222             return value;
223         }
224         /+ quint32 verPolicy : 4; +/
225         final quint32 verPolicy() const
226         {
227             return (bitfieldData_horStretch >> 20) & 0xf;
228         }
229         final uint verPolicy(uint value)
230         {
231             bitfieldData_horStretch = (bitfieldData_horStretch & ~0xf00000) | ((value & 0xf) << 20);
232             return value;
233         }
234         /+ quint32 ctype : 5; +/
235         final quint32 ctype() const
236         {
237             return (bitfieldData_horStretch >> 24) & 0x1f;
238         }
239         final uint ctype(uint value)
240         {
241             bitfieldData_horStretch = (bitfieldData_horStretch & ~0x1f000000) | ((value & 0x1f) << 24);
242             return value;
243         }
244         /+ quint32 hfw : 1; +/
245         final quint32 hfw() const
246         {
247             return (bitfieldData_horStretch >> 29) & 0x1;
248         }
249         final uint hfw(uint value)
250         {
251             bitfieldData_horStretch = (bitfieldData_horStretch & ~0x20000000) | ((value & 0x1) << 29);
252             return value;
253         }
254         /+ quint32 wfh : 1; +/
255         final quint32 wfh() const
256         {
257             return (bitfieldData_horStretch >> 30) & 0x1;
258         }
259         final uint wfh(uint value)
260         {
261             bitfieldData_horStretch = (bitfieldData_horStretch & ~0x40000000) | ((value & 0x1) << 30);
262             return value;
263         }
264         /+ quint32 retainSizeWhenHidden : 1; +/
265         final quint32 retainSizeWhenHidden() const
266         {
267             return (bitfieldData_horStretch >> 31) & 0x1;
268         }
269         final uint retainSizeWhenHidden(uint value)
270         {
271             bitfieldData_horStretch = (bitfieldData_horStretch & ~0x80000000) | ((value & 0x1) << 31);
272             return value;
273         }
274 
275         /+ QT_SIZEPOLICY_CONSTEXPR_AND_UNIFORM_INIT +/
276 /+        Bits transposed() const/+ noexcept+/
277         {
278             return Bits(verStretch, // \ swap
279                     horStretch, // /
280                     verPolicy, // \ swap
281                     horPolicy, // /
282                     ctype,
283                     hfw, // \ don't swap (historic behavior)
284                     wfh, // /
285                     retainSizeWhenHidden);
286         }+/
287     }
288     union {
289         Bits bits;
290         quint32 data;
291     }
292 }
293 /+ #if QT_VERSION >= QT_VERSION_CHECK(6,0,0)
294 // Can't add in Qt 5, as QList<QSizePolicy> would be BiC:
295 Q_DECLARE_TYPEINFO(QSizePolicy, Q_PRIMITIVE_TYPE);
296 #else
297 Q_DECLARE_TYPEINFO(QSizePolicy, Q_RELOCATABLE_TYPE);
298 #endif +/
299 /+pragma(inline, true) QFlags!(QSizePolicy.ControlTypes.enum_type) operator |(QSizePolicy.ControlTypes.enum_type f1, QSizePolicy.ControlTypes.enum_type f2)/+noexcept+/{return QFlags!(QSizePolicy.ControlTypes.enum_type)(f1)|f2;}+/
300 /+pragma(inline, true) QFlags!(QSizePolicy.ControlTypes.enum_type) operator |(QSizePolicy.ControlTypes.enum_type f1, QFlags!(QSizePolicy.ControlTypes.enum_type) f2)/+noexcept+/{return f2|f1;}+/
301 /+pragma(inline, true) QIncompatibleFlag operator |(QSizePolicy.ControlTypes.enum_type f1, int f2)/+noexcept+/{return QIncompatibleFlag(int(f1)|f2);}+/
302 
303 /+ Q_DECLARE_OPERATORS_FOR_FLAGS(QSizePolicy::ControlTypes)
304 #ifndef QT_NO_DATASTREAM
305 Q_WIDGETS_EXPORT QDataStream &operator<<(QDataStream &, const QSizePolicy &);
306 Q_WIDGETS_EXPORT QDataStream &operator>>(QDataStream &, QSizePolicy &);
307 #endif
308 
309 #ifndef QT_NO_DEBUG_STREAM
310 Q_WIDGETS_EXPORT QDebug operator<<(QDebug dbg, const QSizePolicy &);
311 #endif
312 
313 
314 #undef QT_SIZEPOLICY_CONSTEXPR
315 #undef QT_SIZEPOLICY_CONSTEXPR_AND_UNIFORM_INIT +/
316 
317