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.core.size;
15 extern(C++):
16 
17 import qt.config;
18 import qt.core.global;
19 import qt.core.margins;
20 import qt.core.metatype;
21 import qt.core.namespace;
22 import qt.core.typeinfo;
23 import qt.helpers;
24 
25 /+ #if defined(Q_OS_DARWIN) || defined(Q_QDOC)
26 struct CGSize;
27 #endif +/
28 
29 
30 
31 @(QMetaType.Type.QSize) @Q_MOVABLE_TYPE extern(C++, class) struct /+ Q_CORE_EXPORT +/ QSize
32 {
33 public:
34     /+pragma(inline, true) this()/+ noexcept+/
35     {
36         this.wd = -1;
37         this.ht = -1;
38     }+/
39     pragma(inline, true) this(int w, int h)/+ noexcept+/
40     {
41         this.wd = w;
42         this.ht = h;
43     }
44 
45     pragma(inline, true) bool isNull() const/+ noexcept+/
46     { return wd==0 && ht==0; }
47     pragma(inline, true) bool isEmpty() const/+ noexcept+/
48     { return wd<1 || ht<1; }
49     pragma(inline, true) bool isValid() const/+ noexcept+/
50     { return wd>=0 && ht>=0; }
51 
52     pragma(inline, true) int width() const/+ noexcept+/
53     { return wd; }
54     pragma(inline, true) int height() const/+ noexcept+/
55     { return ht; }
56     pragma(inline, true) void setWidth(int w)/+ noexcept+/
57     { wd = w; }
58     pragma(inline, true) void setHeight(int h)/+ noexcept+/
59     { ht = h; }
60     void transpose()/+ noexcept+/;
61     /+ Q_REQUIRED_RESULT +/ pragma(inline, true) QSize transposed() const/+ noexcept+/
62     { return QSize(ht, wd); }
63 
64     pragma(inline, true) void scale(int w, int h, /+ Qt:: +/qt.core.namespace.AspectRatioMode mode)/+ noexcept+/
65     { auto tmp = QSize(w, h); scale(tmp, mode); }
66     pragma(inline, true) void scale(ref const(QSize) s, /+ Qt:: +/qt.core.namespace.AspectRatioMode mode)/+ noexcept+/
67     { this = scaled(s, mode); }
68     /+ Q_REQUIRED_RESULT +/ pragma(inline, true) QSize scaled(int w, int h, /+ Qt:: +/qt.core.namespace.AspectRatioMode mode) const/+ noexcept+/
69     { auto tmp = QSize(w, h); return scaled(tmp, mode); }
70     /+ Q_REQUIRED_RESULT +/ QSize scaled(ref const(QSize) s, /+ Qt:: +/qt.core.namespace.AspectRatioMode mode) const/+ noexcept+/;
71 
72     /+ Q_REQUIRED_RESULT +/ pragma(inline, true) QSize expandedTo(ref const(QSize) otherSize) const/+ noexcept+/
73     {
74         return QSize(qMax(wd,otherSize.wd), qMax(ht,otherSize.ht));
75     }
76     /+ Q_REQUIRED_RESULT +/ pragma(inline, true) QSize boundedTo(ref const(QSize) otherSize) const/+ noexcept+/
77     {
78         return QSize(qMin(wd,otherSize.wd), qMin(ht,otherSize.ht));
79     }
80 
81     /+ Q_REQUIRED_RESULT +/ QSize grownBy(QMargins m) const/+ noexcept+/
82     { return QSize(width() + m.left() + m.right(), height() + m.top() + m.bottom()); }
83     /+ Q_REQUIRED_RESULT +/ QSize shrunkBy(QMargins m) const/+ noexcept+/
84     { return QSize(width() - m.left() - m.right(), height() - m.top() - m.bottom()); }
85 
86     pragma(inline, true) ref int rwidth()/+ noexcept+/ return
87     { return wd; }
88     pragma(inline, true) ref int rheight()/+ noexcept+/ return
89     { return ht; }
90 
91     pragma(inline, true) ref QSize opOpAssign(string op)(ref const(QSize) s)/+ noexcept+/ if(op == "+")
92     { wd+=s.wd; ht+=s.ht; return this; }
93     pragma(inline, true) ref QSize opOpAssign(string op)(ref const(QSize) s)/+ noexcept+/ if(op == "-")
94     { wd-=s.wd; ht-=s.ht; return this; }
95     /+pragma(inline, true) ref QSize operator *=(qreal c)/+ noexcept+/
96     { wd = qRound(wd*c); ht = qRound(ht*c); return this; }+/
97     /+pragma(inline, true) ref QSize operator /=(qreal c)
98     {
99         (mixin(Q_ASSERT(q{!qFuzzyIsNull(c)})));
100         wd = qRound(wd/c); ht = qRound(ht/c);
101         return this;
102     }+/
103 
104     /+ friend inline bool operator==(const QSize &, const QSize &) noexcept; +/
105     /+ friend inline bool operator!=(const QSize &, const QSize &) noexcept; +/
106     /+ friend inline const QSize operator+(const QSize &, const QSize &) noexcept; +/
107     /+ friend inline const QSize operator-(const QSize &, const QSize &) noexcept; +/
108     /+ friend inline const QSize operator*(const QSize &, qreal) noexcept; +/
109     /+ friend inline const QSize operator*(qreal, const QSize &) noexcept; +/
110     /+ friend inline const QSize operator/(const QSize &, qreal); +/
111 
112     static if((versionIsSet!("OSX") || versionIsSet!("iOS") || versionIsSet!("TVOS") || versionIsSet!("WatchOS")))
113     {
114         /+ Q_REQUIRED_RESULT CGSize toCGSize() const noexcept; +/
115     }
116 
117 private:
118     int wd = -1;
119     int ht = -1;
120 }
121 /+ Q_DECLARE_TYPEINFO(QSize, Q_MOVABLE_TYPE);
122 
123 /*****************************************************************************
124   QSize stream functions
125  *****************************************************************************/
126 
127 #ifndef QT_NO_DATASTREAM
128 Q_CORE_EXPORT QDataStream &operator<<(QDataStream &, const QSize &);
129 Q_CORE_EXPORT QDataStream &operator>>(QDataStream &, QSize &);
130 #endif +/
131 
132 
133 /*****************************************************************************
134   QSize inline functions
135  *****************************************************************************/
136 
137 /+pragma(inline, true) bool operator ==(ref const(QSize) s1, ref const(QSize) s2)/+ noexcept+/
138 { return s1.wd == s2.wd && s1.ht == s2.ht; }+/
139 
140 /+pragma(inline, true) bool operator !=(ref const(QSize) s1, ref const(QSize) s2)/+ noexcept+/
141 { return s1.wd != s2.wd || s1.ht != s2.ht; }+/
142 
143 /+pragma(inline, true) const(QSize) operator +(ref const(QSize)  s1, ref const(QSize)  s2)/+ noexcept+/
144 { return QSize(s1.wd+s2.wd, s1.ht+s2.ht); }+/
145 
146 /+pragma(inline, true) const(QSize) operator -(ref const(QSize) s1, ref const(QSize) s2)/+ noexcept+/
147 { return QSize(s1.wd-s2.wd, s1.ht-s2.ht); }+/
148 
149 /+pragma(inline, true) const(QSize) operator *(ref const(QSize) s, qreal c)/+ noexcept+/
150 { return QSize(qRound(s.wd*c), qRound(s.ht*c)); }+/
151 
152 /+pragma(inline, true) const(QSize) operator *(qreal c, ref const(QSize) s)/+ noexcept+/
153 { return QSize(qRound(s.wd*c), qRound(s.ht*c)); }+/
154 
155 /+pragma(inline, true) const(QSize) operator /(ref const(QSize) s, qreal c)
156 {
157     (mixin(Q_ASSERT(q{!qFuzzyIsNull(c)})));
158     return QSize(qRound(s.wd/c), qRound(s.ht/c));
159 }+/
160 
161 /+ #ifndef QT_NO_DEBUG_STREAM
162 Q_CORE_EXPORT QDebug operator<<(QDebug, const QSize &);
163 #endif +/
164 
165 
166 @(QMetaType.Type.QSizeF) @Q_MOVABLE_TYPE extern(C++, class) struct /+ Q_CORE_EXPORT +/ QSizeF
167 {
168 public:
169     @disable this();
170     /+pragma(inline, true) this()/+ noexcept+/
171     {
172         this.wd = -1.;
173         this.ht = -1.;
174     }+/
175     pragma(inline, true) this(ref const(QSize) sz)/+ noexcept+/
176     {
177         this.wd = sz.width();
178         this.ht = sz.height();
179     }
180     pragma(inline, true) this(qreal w, qreal h)/+ noexcept+/
181     {
182         this.wd = w;
183         this.ht = h;
184     }
185 
186     pragma(inline, true) bool isNull() const/+ noexcept+/
187     { return qIsNull(wd) && qIsNull(ht); }
188     pragma(inline, true) bool isEmpty() const/+ noexcept+/
189     { return wd <= 0. || ht <= 0.; }
190     pragma(inline, true) bool isValid() const/+ noexcept+/
191     { return wd >= 0. && ht >= 0.; }
192 
193     pragma(inline, true) qreal width() const/+ noexcept+/
194     { return wd; }
195     pragma(inline, true) qreal height() const/+ noexcept+/
196     { return ht; }
197     pragma(inline, true) void setWidth(qreal w)/+ noexcept+/
198     { wd = w; }
199     pragma(inline, true) void setHeight(qreal h)/+ noexcept+/
200     { ht = h; }
201     void transpose()/+ noexcept+/;
202     /+ Q_REQUIRED_RESULT +/ pragma(inline, true) QSizeF transposed() const/+ noexcept+/
203     { return QSizeF(ht, wd); }
204 
205     pragma(inline, true) void scale(qreal w, qreal h, /+ Qt:: +/qt.core.namespace.AspectRatioMode mode)/+ noexcept+/
206     { auto tmp = QSizeF(w, h); scale(tmp, mode); }
207     pragma(inline, true) void scale(ref const(QSizeF) s, /+ Qt:: +/qt.core.namespace.AspectRatioMode mode)/+ noexcept+/
208     { this = scaled(s, mode); }
209     /+ Q_REQUIRED_RESULT +/ pragma(inline, true) QSizeF scaled(qreal w, qreal h, /+ Qt:: +/qt.core.namespace.AspectRatioMode mode) const/+ noexcept+/
210     { auto tmp = QSizeF(w, h); return scaled(tmp, mode); }
211     /+ Q_REQUIRED_RESULT +/ QSizeF scaled(ref const(QSizeF) s, /+ Qt:: +/qt.core.namespace.AspectRatioMode mode) const/+ noexcept+/;
212 
213     /+ Q_REQUIRED_RESULT +/ pragma(inline, true) QSizeF expandedTo(ref const(QSizeF) otherSize) const/+ noexcept+/
214     {
215         return QSizeF(qMax(wd,otherSize.wd), qMax(ht,otherSize.ht));
216     }
217     /+ Q_REQUIRED_RESULT +/ pragma(inline, true) QSizeF boundedTo(ref const(QSizeF) otherSize) const/+ noexcept+/
218     {
219         return QSizeF(qMin(wd,otherSize.wd), qMin(ht,otherSize.ht));
220     }
221 
222     /+ Q_REQUIRED_RESULT +/ QSizeF grownBy(QMarginsF m) const/+ noexcept+/
223     { return QSizeF(width() + m.left() + m.right(), height() + m.top() + m.bottom()); }
224     /+ Q_REQUIRED_RESULT +/ QSizeF shrunkBy(QMarginsF m) const/+ noexcept+/
225     { return QSizeF(width() - m.left() - m.right(), height() - m.top() - m.bottom()); }
226 
227     pragma(inline, true) ref qreal rwidth()/+ noexcept+/ return
228     { return wd; }
229     pragma(inline, true) ref qreal rheight()/+ noexcept+/ return
230     { return ht; }
231 
232     pragma(inline, true) ref QSizeF opOpAssign(string op)(ref const(QSizeF) s)/+ noexcept+/ if(op == "+")
233     { wd += s.wd; ht += s.ht; return this; }
234     pragma(inline, true) ref QSizeF opOpAssign(string op)(ref const(QSizeF) s)/+ noexcept+/ if(op == "-")
235     { wd -= s.wd; ht -= s.ht; return this; }
236     /+pragma(inline, true) ref QSizeF operator *=(qreal c)/+ noexcept+/
237     { wd *= c; ht *= c; return this; }+/
238     /+pragma(inline, true) ref QSizeF operator /=(qreal c)
239     {
240         (mixin(Q_ASSERT(q{!qFuzzyIsNull(c)})));
241         wd = wd/c; ht = ht/c;
242         return this;
243     }+/
244 
245     /+ friend inline bool operator==(const QSizeF &, const QSizeF &) noexcept; +/
246     /+ friend inline bool operator!=(const QSizeF &, const QSizeF &) noexcept; +/
247     /+ friend inline const QSizeF operator+(const QSizeF &, const QSizeF &) noexcept; +/
248     /+ friend inline const QSizeF operator-(const QSizeF &, const QSizeF &) noexcept; +/
249     /+ friend inline const QSizeF operator*(const QSizeF &, qreal) noexcept; +/
250     /+ friend inline const QSizeF operator*(qreal, const QSizeF &) noexcept; +/
251     /+ friend inline const QSizeF operator/(const QSizeF &, qreal); +/
252 
253     pragma(inline, true) QSize toSize() const/+ noexcept+/
254     {
255         return QSize(qRound(wd), qRound(ht));
256     }
257 
258     static if((versionIsSet!("OSX") || versionIsSet!("iOS") || versionIsSet!("TVOS") || versionIsSet!("WatchOS")))
259     {
260         /+ Q_REQUIRED_RESULT static QSizeF fromCGSize(CGSize size) noexcept; +/
261         /+ Q_REQUIRED_RESULT CGSize toCGSize() const noexcept; +/
262     }
263 
264 private:
265     qreal wd = -1.;
266     qreal ht = -1.;
267 }
268 /+ Q_DECLARE_TYPEINFO(QSizeF, Q_MOVABLE_TYPE);
269 
270 
271 /*****************************************************************************
272   QSizeF stream functions
273  *****************************************************************************/
274 
275 #ifndef QT_NO_DATASTREAM
276 Q_CORE_EXPORT QDataStream &operator<<(QDataStream &, const QSizeF &);
277 Q_CORE_EXPORT QDataStream &operator>>(QDataStream &, QSizeF &);
278 #endif +/
279 
280 
281 /*****************************************************************************
282   QSizeF inline functions
283  *****************************************************************************/
284 
285 /+pragma(inline, true) bool operator ==(ref const(QSizeF) s1, ref const(QSizeF) s2)/+ noexcept+/
286 { return qFuzzyCompare(s1.wd, s2.wd) && qFuzzyCompare(s1.ht, s2.ht); }+/
287 
288 /+pragma(inline, true) bool operator !=(ref const(QSizeF) s1, ref const(QSizeF) s2)/+ noexcept+/
289 { return !qFuzzyCompare(s1.wd, s2.wd) || !qFuzzyCompare(s1.ht, s2.ht); }+/
290 
291 /+pragma(inline, true) const(QSizeF) operator +(ref const(QSizeF)  s1, ref const(QSizeF)  s2)/+ noexcept+/
292 { return QSizeF(s1.wd+s2.wd, s1.ht+s2.ht); }+/
293 
294 /+pragma(inline, true) const(QSizeF) operator -(ref const(QSizeF) s1, ref const(QSizeF) s2)/+ noexcept+/
295 { return QSizeF(s1.wd-s2.wd, s1.ht-s2.ht); }+/
296 
297 /+pragma(inline, true) const(QSizeF) operator *(ref const(QSizeF) s, qreal c)/+ noexcept+/
298 { return QSizeF(s.wd*c, s.ht*c); }+/
299 
300 /+pragma(inline, true) const(QSizeF) operator *(qreal c, ref const(QSizeF) s)/+ noexcept+/
301 { return QSizeF(s.wd*c, s.ht*c); }+/
302 
303 /+pragma(inline, true) const(QSizeF) operator /(ref const(QSizeF) s, qreal c)
304 {
305     (mixin(Q_ASSERT(q{!qFuzzyIsNull(c)})));
306     return QSizeF(s.wd/c, s.ht/c);
307 }+/
308 
309 /+ #ifndef QT_NO_DEBUG_STREAM
310 Q_CORE_EXPORT QDebug operator<<(QDebug, const QSizeF &);
311 #endif +/
312