comparison d1/qt/core/QRectF.d @ 344:96a75b1e5b26

project structure changes
author Max Samukha <maxter@spambox.com>
date Fri, 14 May 2010 12:14:37 +0300
parents qt/d1/qt/core/QRectF.d@34a37904ff77
children
comparison
equal deleted inserted replaced
343:552647ec0f82 344:96a75b1e5b26
1 module qt.core.QRectF;
2
3 public import qt.QGlobal;
4 public import qt.core.Qt;
5 public import qt.core.QPointF;
6 public import qt.core.QRect;
7 public import qt.core.QSizeF;
8 public import qt.core.QDataStream;
9
10
11 public struct QRectF
12 {
13
14 public static QRectF opCall()
15 {
16 QRectF rt;
17 rt.xp = rt.yp = 0.;
18 rt.w = rt.h = 0.;
19 return rt;
20 }
21
22 public static QRectF opCall(qreal aleft, qreal atop, qreal awidth, qreal aheight)
23 {
24 QRectF rt;
25 rt.xp = aleft;
26 rt.yp = atop;
27 rt.w = awidth;
28 rt.h = aheight;
29 return rt;
30 }
31
32 public static QRectF opCall(in QPointF atopLeft, in QSizeF asize)
33 {
34 QRectF rt;
35 rt.xp = atopLeft.x();
36 rt.yp = atopLeft.y();
37 rt.w = asize.width();
38 rt.h = asize.height();
39 return rt;
40 }
41
42 public static QRectF opCall(in QPointF atopLeft, in QPointF abottomRight)
43 {
44 QRectF rt;
45 rt.xp = atopLeft.x();
46 rt.yp = atopLeft.y();
47 rt.w = abottomRight.x() - rt.xp;
48 rt.h = abottomRight.y() - rt.yp;
49 return rt;
50 }
51
52 public static QRectF opCall(in QRect r)
53 {
54 QRectF rt;
55 rt.xp = r.x();
56 rt.yp = r.y();
57 rt.w = r.width();
58 rt.h = r.height();
59 return rt;
60 }
61
62 bool isNull() // conts
63 { return qIsNull(w) && qIsNull(h); }
64
65 bool isEmpty() // conts
66 { return w <= 0. || h <= 0.; }
67
68 bool isValid() // conts
69 { return w > 0. && h > 0.; }
70
71 qreal x() // conts
72 { return xp; }
73
74 qreal y() // conts
75 { return yp; }
76
77 qreal left() // const
78 { return xp; }
79
80 qreal top() // const
81 { return yp; }
82
83 qreal right() // const
84 { return xp + w; }
85
86 qreal bottom() // const
87 { return yp + h; }
88
89 QPointF topLeft() // const
90 { return QPointF(xp, yp); }
91
92 QPointF bottomRight() // const
93 { return QPointF(xp+w, yp+h); }
94
95 QPointF topRight() // const
96 { return QPointF(xp+w, yp); }
97
98 QPointF bottomLeft() // const
99 { return QPointF(xp, yp+h); }
100
101 void setLeft(qreal pos) { qreal diff = pos - xp; xp += diff; w -= diff; }
102
103 void setRight(qreal pos) { w = pos - xp; }
104
105 void setTop(qreal pos) { qreal diff = pos - yp; yp += diff; h -= diff; }
106
107 void setBottom(qreal pos) { h = pos - yp; }
108
109 void setTopLeft(in QPointF p) { setLeft(p.x()); setTop(p.y()); }
110
111 void setTopRight(in QPointF p) { setRight(p.x()); setTop(p.y()); }
112
113 void setBottomLeft(in QPointF p) { setLeft(p.x()); setBottom(p.y()); }
114
115 void setBottomRight(in QPointF p) { setRight(p.x()); setBottom(p.y()); }
116
117 QPointF center() // conts
118 { return QPointF(xp + w/2, yp + h/2); }
119
120 void moveLeft(qreal pos) { xp = pos; }
121
122 void moveTop(qreal pos) { yp = pos; }
123
124 void moveRight(qreal pos) { xp = pos - w; }
125
126 void moveBottom(qreal pos) { yp = pos - h; }
127
128 void moveTopLeft(in QPointF p) { moveLeft(p.x()); moveTop(p.y()); }
129
130 void moveTopRight(in QPointF p) { moveRight(p.x()); moveTop(p.y()); }
131
132 void moveBottomLeft(in QPointF p) { moveLeft(p.x()); moveBottom(p.y()); }
133
134 void moveBottomRight(in QPointF p) { moveRight(p.x()); moveBottom(p.y()); }
135
136 void moveCenter(in QPointF p) { xp = p.x() - w/2; yp = p.y() - h/2; }
137
138 qreal width() // conts
139 { return w; }
140
141 qreal height() // conts
142 { return h; }
143
144 QSizeF size() // conts
145 { return QSizeF(w, h); }
146
147 void translate(qreal dx, qreal dy)
148 {
149 xp += dx;
150 yp += dy;
151 }
152
153 void translate(in QPointF p)
154 {
155 xp += p.x();
156 yp += p.y();
157 }
158
159 void moveTo(qreal ax, qreal ay)
160 {
161 xp = ax;
162 yp = ay;
163 }
164
165 void moveTo(in QPointF p)
166 {
167 xp = p.x();
168 yp = p.y();
169 }
170
171 QRectF translated(qreal dx, qreal dy) // conts
172 { return QRectF(xp + dx, yp + dy, w, h); }
173
174 QRectF translated(in QPointF p) // conts
175 { return QRectF(xp + p.x(), yp + p.y(), w, h); }
176
177 void getRect(qreal *ax, qreal *ay, qreal *aaw, qreal *aah) // conts
178 {
179 *ax = this.xp;
180 *ay = this.yp;
181 *aaw = this.w;
182 *aah = this.h;
183 }
184
185 void setRect(qreal ax, qreal ay, qreal aaw, qreal aah)
186 {
187 this.xp = ax;
188 this.yp = ay;
189 this.w = aaw;
190 this.h = aah;
191 }
192
193 void getCoords(qreal *xp1, qreal *yp1, qreal *xp2, qreal *yp2) // conts
194 {
195 *xp1 = xp;
196 *yp1 = yp;
197 *xp2 = xp + w;
198 *yp2 = yp + h;
199 }
200
201 void setCoords(qreal xp1, qreal yp1, qreal xp2, qreal yp2)
202 {
203 xp = xp1;
204 yp = yp1;
205 w = xp2 - xp1;
206 h = yp2 - yp1;
207 }
208
209 void adjust(qreal xp1, qreal yp1, qreal xp2, qreal yp2)
210 { xp += xp1; yp += yp1; w += xp2 - xp1; h += yp2 - yp1; }
211
212 QRectF adjusted(qreal xp1, qreal yp1, qreal xp2, qreal yp2) // conts
213 { return QRectF(xp + xp1, yp + yp1, w + xp2 - xp1, h + yp2 - yp1); }
214
215 void setWidth(qreal aw) // for convenience
216 { this.w = aw; }
217
218 void setHeight(qreal ah) // for convenience
219 { this.h = ah; }
220
221 void setSize(in QSizeF s) // for convenience
222 {
223 w = s.width();
224 h = s.height();
225 }
226
227 void width(qreal aw)
228 { this.w = aw; }
229
230 void height(qreal ah)
231 { this.h = ah; }
232
233 void size(in QSizeF s)
234 {
235 w = s.width();
236 h = s.height();
237 }
238
239 bool contains(qreal ax, qreal ay) // conts
240 {
241 return contains(QPointF(ax, ay));
242 }
243
244 QRectF opOrAssign(in QRectF r)
245 {
246 *this = *this | r;
247 return *this;
248 }
249
250 QRectF opAndAssign(in QRectF r)
251 {
252 *this = *this & r;
253 return *this;
254 }
255
256 QRectF intersected(in QRectF r) // conts
257 {
258 return *this & r;
259 }
260
261 QRectF united(in QRectF r) // conts
262 {
263 return *this | r;
264 }
265
266 bool opEquals(in QRectF r)
267 {
268 return qFuzzyCompare(xp, r.xp) && qFuzzyCompare(yp, r.yp)
269 && qFuzzyCompare(w, r.w) && qFuzzyCompare(h, r.h);
270 }
271
272 QRect toRect() // conts
273 {
274 return QRect(qRound(xp), qRound(yp), qRound(w), qRound(h));
275 }
276
277 public final bool contains(QPointF p) {
278 return qtd_QRectF_contains_QPointF(this, &p);
279 }
280
281 public final bool contains(QRectF r) {
282 return qtd_QRectF_contains_QRectF(this, &r);
283 }
284
285 public final bool intersects(QRectF r) {
286 return qtd_QRectF_intersects_QRectF(this, &r);
287 }
288
289 public final QRectF normalized() {
290 return qtd_QRectF_normalized(this);
291 }
292
293 public final QRectF opAnd(in QRectF r) {
294 return qtd_QRectF_operator_and_QRectF(this, &r);
295 }
296
297 public final void writeTo(QDataStream arg__1) {
298 qtd_QRectF_writeTo_QDataStream(this, arg__1 is null ? null : arg__1.__nativeId);
299 }
300
301 public final void readFrom(QDataStream arg__1) {
302 qtd_QRectF_readFrom_QDataStream(this, arg__1 is null ? null : arg__1.__nativeId);
303 }
304
305 public final QRectF opOr(in QRectF r) {
306 return qtd_QRectF_operator_or_QRectF(this, &r);
307 }
308
309 public final QRect toAlignedRect() // const
310 {
311 return qtd_QRectF_toAlignedRect(this);
312 }
313
314 private:
315 qreal xp;
316 qreal yp;
317 qreal w;
318 qreal h;
319 }
320
321
322 // C wrappers
323 private extern(C) bool qtd_QRectF_contains_QPointF(void* __this_nativeId,
324 void* p0);
325 private extern(C) bool qtd_QRectF_contains_QRectF(void* __this_nativeId,
326 void* r0);
327 private extern(C) bool qtd_QRectF_intersects_QRectF(void* __this_nativeId,
328 void* r0);
329 private extern(C) QRectF qtd_QRectF_normalized(void* __this_nativeId);
330 private extern(C) QRectF qtd_QRectF_operator_and_QRectF(void* __this_nativeId,
331 void* r0);
332 private extern(C) void qtd_QRectF_writeTo_QDataStream(void* __this_nativeId,
333 void* arg__1);
334 private extern(C) void qtd_QRectF_readFrom_QDataStream(void* __this_nativeId,
335 void* arg__1);
336 private extern(C) QRectF qtd_QRectF_operator_or_QRectF(void* __this_nativeId,
337 void* r0);
338 private extern(C) QRect qtd_QRectF_toAlignedRect(void* __this_nativeId);