Mercurial > projects > qtd
annotate d2/qt/core/QRect.d @ 372:a032df77b6ab
Simple debug helper. Unittests. Meta-object for polymorphic non-QObjects
author | Max Samukha <maxter@spambox.com> |
---|---|
date | Thu, 08 Jul 2010 17:19:05 +0300 |
parents | 96a75b1e5b26 |
children |
rev | line source |
---|---|
188 | 1 module qt.core.QRect; |
2 | |
3 public import qt.QGlobal; | |
4 public import qt.core.Qt; | |
5 public import qt.core.QDataStream; | |
6 public import qt.core.QSize; | |
7 public import qt.core.QPoint; | |
8 | |
9 | |
10 public struct QRect | |
11 { | |
12 public static QRect opCall() { | |
13 QRect rt; | |
14 rt.x1 = rt.y1 = 0; | |
15 rt.x2 = rt.y2 = -1; | |
16 return rt; | |
17 } | |
18 | |
19 public this(int aleft, int atop, int awidth, int aheight) | |
20 { | |
21 x1 = aleft; | |
22 y1 = atop; | |
23 x2 = (aleft + awidth - 1); | |
24 y2 = (atop + aheight - 1); | |
25 } | |
26 | |
27 public this(QPoint atopLeft, QPoint abottomRight) | |
28 { | |
29 x1 = atopLeft.x(); | |
30 y1 = atopLeft.y(); | |
31 x2 = abottomRight.x(); | |
32 y2 = abottomRight.y(); | |
33 } | |
34 | |
35 public this(ref QPoint atopLeft, ref QSize asize) | |
36 { | |
37 x1 = atopLeft.x(); | |
38 y1 = atopLeft.y(); | |
39 x2 = (x1+asize.width() - 1); | |
40 y2 = (y1+asize.height() - 1); | |
41 } | |
42 | |
204 | 43 bool isNull() const |
188 | 44 { return x2 == x1 - 1 && y2 == y1 - 1; } |
45 | |
204 | 46 bool isEmpty() const |
188 | 47 { return x1 > x2 || y1 > y2; } |
48 | |
204 | 49 bool isValid() const |
188 | 50 { return x1 <= x2 && y1 <= y2; } |
51 | |
204 | 52 int left() const |
188 | 53 { return x1; } |
54 | |
204 | 55 int top() const |
188 | 56 { return y1; } |
57 | |
204 | 58 int right() const |
188 | 59 { return x2; } |
60 | |
204 | 61 int bottom() const |
188 | 62 { return y2; } |
63 | |
204 | 64 int x() const |
188 | 65 { return x1; } |
66 | |
204 | 67 int y() const |
188 | 68 { return y1; } |
69 | |
70 void left(int pos) | |
71 { x1 = pos; } | |
72 | |
73 void top(int pos) | |
74 { y1 = pos; } | |
75 | |
76 void right(int pos) | |
77 { x2 = pos; } | |
78 | |
79 void bottom(int pos) | |
80 { y2 = pos; } | |
81 | |
82 void setLeft(int pos) | |
83 { x1 = pos; } | |
84 | |
85 void setTop(int pos) | |
86 { y1 = pos; } | |
87 | |
88 void setRight(int pos) | |
89 { x2 = pos; } | |
90 | |
91 void setBottom(int pos) | |
92 { y2 = pos; } | |
93 | |
205 | 94 void setTopLeft(const QPoint p) |
188 | 95 { x1 = p.x(); y1 = p.y(); } |
96 | |
205 | 97 void setBottomRight(const QPoint p) |
188 | 98 { x2 = p.x(); y2 = p.y(); } |
99 | |
205 | 100 void setTopRight(const QPoint p) |
188 | 101 { x2 = p.x(); y1 = p.y(); } |
102 | |
205 | 103 void setBottomLeft(const QPoint p) |
188 | 104 { x1 = p.x(); y2 = p.y(); } |
105 | |
106 void setX(int ax) | |
107 { x1 = ax; } | |
108 | |
109 void setY(int ay) | |
110 { y1 = ay; } | |
111 | |
204 | 112 QPoint topLeft() const |
188 | 113 { return QPoint(x1, y1); } |
114 | |
204 | 115 QPoint bottomRight() const |
188 | 116 { return QPoint(x2, y2); } |
117 | |
204 | 118 QPoint topRight() const |
188 | 119 { return QPoint(x2, y1); } |
120 | |
204 | 121 QPoint bottomLeft() const |
188 | 122 { return QPoint(x1, y2); } |
123 | |
204 | 124 QPoint center() const |
188 | 125 { return QPoint((x1+x2)/2, (y1+y2)/2); } |
126 | |
204 | 127 int width() const |
188 | 128 { return x2 - x1 + 1; } |
129 | |
204 | 130 int height() const |
188 | 131 { return y2 - y1 + 1; } |
132 | |
204 | 133 QSize size() const |
188 | 134 { return QSize(width(), height()); } |
135 | |
136 void translate(int dx, int dy) | |
137 { | |
138 x1 += dx; | |
139 y1 += dy; | |
140 x2 += dx; | |
141 y2 += dy; | |
142 } | |
143 | |
205 | 144 void translate(const QPoint p) |
188 | 145 { |
146 x1 += p.x(); | |
147 y1 += p.y(); | |
148 x2 += p.x(); | |
149 y2 += p.y(); | |
150 } | |
151 | |
204 | 152 QRect translated(int dx, int dy) const |
188 | 153 { return QRect(QPoint(x1 + dx, y1 + dy), QPoint(x2 + dx, y2 + dy)); } |
154 | |
205 | 155 QRect translated(const QPoint p) const |
188 | 156 { return QRect(QPoint(x1 + p.x(), y1 + p.y()), QPoint(x2 + p.x(), y2 + p.y())); } |
157 | |
158 void moveTo(int ax, int ay) | |
159 { | |
160 x2 += ax - x1; | |
161 y2 += ay - y1; | |
162 x1 = ax; | |
163 y1 = ay; | |
164 } | |
165 | |
205 | 166 void moveTo(const QPoint p) |
188 | 167 { |
168 x2 += p.x() - x1; | |
169 y2 += p.y() - y1; | |
170 x1 = p.x(); | |
171 y1 = p.y(); | |
172 } | |
173 | |
174 void moveLeft(int pos) | |
175 { x2 += (pos - x1); x1 = pos; } | |
176 | |
177 void moveTop(int pos) | |
178 { y2 += (pos - y1); y1 = pos; } | |
179 | |
180 void moveRight(int pos) | |
181 { | |
182 x1 += (pos - x2); | |
183 x2 = pos; | |
184 } | |
185 | |
186 void moveBottom(int pos) | |
187 { | |
188 y1 += (pos - y2); | |
189 y2 = pos; | |
190 } | |
191 | |
205 | 192 void moveTopLeft(const QPoint p) |
188 | 193 { |
194 moveLeft(p.x()); | |
195 moveTop(p.y()); | |
196 } | |
197 | |
205 | 198 void moveBottomRight(const QPoint p) |
188 | 199 { |
200 moveRight(p.x()); | |
201 moveBottom(p.y()); | |
202 } | |
203 | |
205 | 204 void moveTopRight(const QPoint p) |
188 | 205 { |
206 moveRight(p.x()); | |
207 moveTop(p.y()); | |
208 } | |
209 | |
205 | 210 void moveBottomLeft(const QPoint p) |
188 | 211 { |
212 moveLeft(p.x()); | |
213 moveBottom(p.y()); | |
214 } | |
215 | |
204 | 216 void getRect(int *ax, int *ay, int *aw, int *ah) const |
188 | 217 { |
218 *ax = x1; | |
219 *ay = y1; | |
220 *aw = x2 - x1 + 1; | |
221 *ah = y2 - y1 + 1; | |
222 } | |
223 | |
224 void setRect(int ax, int ay, int aw, int ah) | |
225 { | |
226 x1 = ax; | |
227 y1 = ay; | |
228 x2 = (ax + aw - 1); | |
229 y2 = (ay + ah - 1); | |
230 } | |
231 | |
204 | 232 void getCoords(int *xp1, int *yp1, int *xp2, int *yp2) const |
188 | 233 { |
234 *xp1 = x1; | |
235 *yp1 = y1; | |
236 *xp2 = x2; | |
237 *yp2 = y2; | |
238 } | |
239 | |
240 void setCoords(int xp1, int yp1, int xp2, int yp2) | |
241 { | |
242 x1 = xp1; | |
243 y1 = yp1; | |
244 x2 = xp2; | |
245 y2 = yp2; | |
246 } | |
247 | |
204 | 248 QRect adjusted(int xp1, int yp1, int xp2, int yp2) const |
188 | 249 { return QRect(QPoint(x1 + xp1, y1 + yp1), QPoint(x2 + xp2, y2 + yp2)); } |
250 | |
251 void adjust(int dx1, int dy1, int dx2, int dy2) | |
252 { | |
253 x1 += dx1; | |
254 y1 += dy1; | |
255 x2 += dx2; | |
256 y2 += dy2; | |
257 } | |
258 | |
259 void setWidth(int w) | |
260 { x2 = (x1 + w - 1); } | |
261 | |
262 void setHeight(int h) | |
263 { y2 = (y1 + h - 1); } | |
264 | |
205 | 265 void setSize(const QSize s) |
188 | 266 { |
267 x2 = (s.width() + x1 - 1); | |
268 y2 = (s.height() + y1 - 1); | |
269 } | |
270 | |
204 | 271 bool contains(int ax, int ay, bool aproper) const |
188 | 272 { |
273 return contains(QPoint(ax, ay), aproper); | |
274 } | |
275 | |
204 | 276 bool contains(int ax, int ay) const |
188 | 277 { |
278 return contains(QPoint(ax, ay), false); | |
279 } | |
280 | |
205 | 281 QRect opOrAssign(const QRect r) |
188 | 282 { |
283 this = this | r; | |
284 return this; | |
285 } | |
286 | |
205 | 287 QRect opAndAssign(const QRect r) |
188 | 288 { |
289 this = this & r; | |
290 return this; | |
291 } | |
292 | |
205 | 293 QRect intersected(const QRect other) const |
188 | 294 { |
295 return this & other; | |
296 } | |
297 | |
205 | 298 QRect united(const QRect r) const |
188 | 299 { |
300 return this | r; | |
301 } | |
302 | |
325 | 303 bool opEquals(ref const QRect r) const |
188 | 304 { |
305 return x1==r.x1 && x2==r.x2 && y1==r.y1 && y2==r.y2; | |
306 } | |
307 | |
308 public final void writeTo(QDataStream arg__1) { | |
372
a032df77b6ab
Simple debug helper. Unittests. Meta-object for polymorphic non-QObjects
Max Samukha <maxter@spambox.com>
parents:
344
diff
changeset
|
309 qtd_QRect_writeTo_QDataStream(&this, arg__1 is null ? null : arg__1.qtdNativeId); |
188 | 310 } |
311 | |
312 public final void readFrom(QDataStream arg__1) { | |
372
a032df77b6ab
Simple debug helper. Unittests. Meta-object for polymorphic non-QObjects
Max Samukha <maxter@spambox.com>
parents:
344
diff
changeset
|
313 qtd_QRect_readFrom_QDataStream(&this, arg__1 is null ? null : arg__1.qtdNativeId); |
188 | 314 } |
315 | |
205 | 316 public final QRect opAnd(const QRect r) const { |
317 return qtd_QRect_operator_and_QRect(&this, &r); | |
188 | 318 } |
319 | |
205 | 320 public final QRect opOr(const QRect r) const { |
321 return qtd_QRect_operator_or_QRect(&this, &r); | |
188 | 322 } |
323 | |
205 | 324 public final bool contains(const QPoint p, bool proper = false) const { |
325 return qtd_QRect_contains_QPoint_bool(&this, &p, proper); | |
188 | 326 } |
327 | |
205 | 328 public final bool contains(const QRect r, bool proper = false) const { |
329 return qtd_QRect_contains_QRect_bool(&this, &r, proper); | |
188 | 330 } |
254 | 331 |
205 | 332 public final bool intersects(const QRect r) const { |
333 return qtd_QRect_intersects_QRect(&this, &r); | |
188 | 334 } |
335 | |
204 | 336 public final QRect normalized() const { |
205 | 337 return qtd_QRect_normalized(&this); |
188 | 338 } |
254 | 339 |
295
463563fc9e17
more of QList. const functions in C++ are now const in D too. Drop of the store result feature, which was incompatible with const functions and introduced too much of the bloat in the generator.
eldar
parents:
254
diff
changeset
|
340 // service stuff |
463563fc9e17
more of QList. const functions in C++ are now const in D too. Drop of the store result feature, which was incompatible with const functions and introduced too much of the bloat in the generator.
eldar
parents:
254
diff
changeset
|
341 public alias void __isNativeValueType; |
463563fc9e17
more of QList. const functions in C++ are now const in D too. Drop of the store result feature, which was incompatible with const functions and introduced too much of the bloat in the generator.
eldar
parents:
254
diff
changeset
|
342 |
463563fc9e17
more of QList. const functions in C++ are now const in D too. Drop of the store result feature, which was incompatible with const functions and introduced too much of the bloat in the generator.
eldar
parents:
254
diff
changeset
|
343 struct QTypeInfo |
463563fc9e17
more of QList. const functions in C++ are now const in D too. Drop of the store result feature, which was incompatible with const functions and introduced too much of the bloat in the generator.
eldar
parents:
254
diff
changeset
|
344 { |
463563fc9e17
more of QList. const functions in C++ are now const in D too. Drop of the store result feature, which was incompatible with const functions and introduced too much of the bloat in the generator.
eldar
parents:
254
diff
changeset
|
345 enum bool isComplex = true; |
463563fc9e17
more of QList. const functions in C++ are now const in D too. Drop of the store result feature, which was incompatible with const functions and introduced too much of the bloat in the generator.
eldar
parents:
254
diff
changeset
|
346 enum bool isStatic = false; |
463563fc9e17
more of QList. const functions in C++ are now const in D too. Drop of the store result feature, which was incompatible with const functions and introduced too much of the bloat in the generator.
eldar
parents:
254
diff
changeset
|
347 enum bool isLarge = true; |
463563fc9e17
more of QList. const functions in C++ are now const in D too. Drop of the store result feature, which was incompatible with const functions and introduced too much of the bloat in the generator.
eldar
parents:
254
diff
changeset
|
348 enum bool isPointer = false; |
463563fc9e17
more of QList. const functions in C++ are now const in D too. Drop of the store result feature, which was incompatible with const functions and introduced too much of the bloat in the generator.
eldar
parents:
254
diff
changeset
|
349 enum bool isDummy = false; |
463563fc9e17
more of QList. const functions in C++ are now const in D too. Drop of the store result feature, which was incompatible with const functions and introduced too much of the bloat in the generator.
eldar
parents:
254
diff
changeset
|
350 } |
463563fc9e17
more of QList. const functions in C++ are now const in D too. Drop of the store result feature, which was incompatible with const functions and introduced too much of the bloat in the generator.
eldar
parents:
254
diff
changeset
|
351 |
463563fc9e17
more of QList. const functions in C++ are now const in D too. Drop of the store result feature, which was incompatible with const functions and introduced too much of the bloat in the generator.
eldar
parents:
254
diff
changeset
|
352 |
188 | 353 private: |
354 version(OSX) | |
355 { | |
356 int y1; | |
357 int x1; | |
358 int y2; | |
359 int x2; | |
360 } | |
361 else | |
362 { | |
363 int x1; | |
364 int y1; | |
365 int x2; | |
366 int y2; | |
367 } | |
368 } | |
369 | |
370 | |
371 // C wrappers | |
205 | 372 private extern(C) bool qtd_QRect_contains_QPoint_bool(const void* __this_nativeId, |
373 const void* p0, | |
188 | 374 bool proper1); |
205 | 375 private extern(C) bool qtd_QRect_contains_QRect_bool(const void* __this_nativeId, |
376 const void* r0, | |
188 | 377 bool proper1); |
205 | 378 private extern(C) bool qtd_QRect_intersects_QRect(const void* __this_nativeId, |
379 const void* r0); | |
380 private extern(C) QRect qtd_QRect_normalized(const void* __this_nativeId); | |
188 | 381 private extern(C) void qtd_QRect_writeTo_QDataStream(void* __this_nativeId, |
382 void* arg__1); | |
383 private extern(C) void qtd_QRect_readFrom_QDataStream(void* __this_nativeId, | |
384 void* arg__1); | |
205 | 385 private extern(C) QRect qtd_QRect_operator_and_QRect(const void* __this_nativeId, |
386 const void* r0); | |
387 private extern(C) QRect qtd_QRect_operator_or_QRect(const void* __this_nativeId, | |
372
a032df77b6ab
Simple debug helper. Unittests. Meta-object for polymorphic non-QObjects
Max Samukha <maxter@spambox.com>
parents:
344
diff
changeset
|
388 const void* r0); |