author | eckhart.koppen@nokia.com |
Wed, 31 Mar 2010 11:06:36 +0300 | |
changeset 7 | f7bc934e204c |
parent 0 | 1918ee327afb |
child 30 | 5dc02b23752f |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
7
f7bc934e204c
5cabc75a39ca2f064f70b40f72ed93c74c4dc19b
eckhart.koppen@nokia.com
parents:
0
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 4 |
** All rights reserved. |
5 |
** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 |
** |
|
7 |
** This file is part of the QtCore module of the Qt Toolkit. |
|
8 |
** |
|
9 |
** $QT_BEGIN_LICENSE:LGPL$ |
|
10 |
** No Commercial Usage |
|
11 |
** This file contains pre-release code and may not be distributed. |
|
12 |
** You may use this file in accordance with the terms and conditions |
|
13 |
** contained in the Technology Preview License Agreement accompanying |
|
14 |
** this package. |
|
15 |
** |
|
16 |
** GNU Lesser General Public License Usage |
|
17 |
** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 |
** General Public License version 2.1 as published by the Free Software |
|
19 |
** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 |
** packaging of this file. Please review the following information to |
|
21 |
** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 |
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 |
** |
|
24 |
** In addition, as a special exception, Nokia gives you certain additional |
|
25 |
** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 |
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 |
** |
|
28 |
** If you have questions regarding the use of this file, please contact |
|
29 |
** Nokia at qt-info@nokia.com. |
|
30 |
** |
|
31 |
** |
|
32 |
** |
|
33 |
** |
|
34 |
** |
|
35 |
** |
|
36 |
** |
|
37 |
** |
|
38 |
** $QT_END_LICENSE$ |
|
39 |
** |
|
40 |
****************************************************************************/ |
|
41 |
||
42 |
#include "qsize.h" |
|
43 |
#include "qdatastream.h" |
|
44 |
#include "qdebug.h" |
|
45 |
||
46 |
QT_BEGIN_NAMESPACE |
|
47 |
||
48 |
/*! |
|
49 |
\class QSize |
|
50 |
\ingroup painting |
|
51 |
||
52 |
\brief The QSize class defines the size of a two-dimensional |
|
53 |
object using integer point precision. |
|
54 |
||
55 |
A size is specified by a width() and a height(). It can be set in |
|
56 |
the constructor and changed using the setWidth(), setHeight(), or |
|
57 |
scale() functions, or using arithmetic operators. A size can also |
|
58 |
be manipulated directly by retrieving references to the width and |
|
59 |
height using the rwidth() and rheight() functions. Finally, the |
|
60 |
width and height can be swapped using the transpose() function. |
|
61 |
||
62 |
The isValid() function determines if a size is valid (a valid size |
|
63 |
has both width and height greater than zero). The isEmpty() |
|
64 |
function returns true if either of the width and height is less |
|
65 |
than, or equal to, zero, while the isNull() function returns true |
|
66 |
only if both the width and the height is zero. |
|
67 |
||
68 |
Use the expandedTo() function to retrieve a size which holds the |
|
69 |
maximum height and width of \e this size and a given |
|
70 |
size. Similarly, the boundedTo() function returns a size which |
|
71 |
holds the minimum height and width of \e this size and a given |
|
72 |
size. |
|
73 |
||
74 |
QSize objects can be streamed as well as compared. |
|
75 |
||
76 |
\sa QSizeF, QPoint, QRect |
|
77 |
*/ |
|
78 |
||
79 |
||
80 |
/***************************************************************************** |
|
81 |
QSize member functions |
|
82 |
*****************************************************************************/ |
|
83 |
||
84 |
/*! |
|
85 |
\fn QSize::QSize() |
|
86 |
||
87 |
Constructs a size with an invalid width and height (i.e., isValid() |
|
88 |
returns false). |
|
89 |
||
90 |
\sa isValid() |
|
91 |
*/ |
|
92 |
||
93 |
/*! |
|
94 |
\fn QSize::QSize(int width, int height) |
|
95 |
||
96 |
Constructs a size with the given \a width and \a height. |
|
97 |
||
98 |
\sa setWidth(), setHeight() |
|
99 |
*/ |
|
100 |
||
101 |
/*! |
|
102 |
\fn bool QSize::isNull() const |
|
103 |
||
104 |
Returns true if both the width and height is 0; otherwise returns |
|
105 |
false. |
|
106 |
||
107 |
\sa isValid(), isEmpty() |
|
108 |
*/ |
|
109 |
||
110 |
/*! |
|
111 |
\fn bool QSize::isEmpty() const |
|
112 |
||
113 |
Returns true if either of the width and height is less than or |
|
114 |
equal to 0; otherwise returns false. |
|
115 |
||
116 |
\sa isNull(), isValid() |
|
117 |
*/ |
|
118 |
||
119 |
/*! |
|
120 |
\fn bool QSize::isValid() const |
|
121 |
||
122 |
Returns true if both the width and height is equal to or greater |
|
123 |
than 0; otherwise returns false. |
|
124 |
||
125 |
\sa isNull(), isEmpty() |
|
126 |
*/ |
|
127 |
||
128 |
/*! |
|
129 |
\fn int QSize::width() const |
|
130 |
||
131 |
Returns the width. |
|
132 |
||
133 |
\sa height(), setWidth() |
|
134 |
*/ |
|
135 |
||
136 |
/*! |
|
137 |
\fn int QSize::height() const |
|
138 |
||
139 |
Returns the height. |
|
140 |
||
141 |
\sa width(), setHeight() |
|
142 |
*/ |
|
143 |
||
144 |
/*! |
|
145 |
\fn void QSize::setWidth(int width) |
|
146 |
||
147 |
Sets the width to the given \a width. |
|
148 |
||
149 |
\sa rwidth(), width(), setHeight() |
|
150 |
*/ |
|
151 |
||
152 |
/*! |
|
153 |
\fn void QSize::setHeight(int height) |
|
154 |
||
155 |
Sets the height to the given \a height. |
|
156 |
||
157 |
\sa rheight(), height(), setWidth() |
|
158 |
*/ |
|
159 |
||
160 |
/*! |
|
161 |
Swaps the width and height values. |
|
162 |
||
163 |
\sa setWidth(), setHeight() |
|
164 |
*/ |
|
165 |
||
166 |
void QSize::transpose() |
|
167 |
{ |
|
168 |
int tmp = wd; |
|
169 |
wd = ht; |
|
170 |
ht = tmp; |
|
171 |
} |
|
172 |
||
173 |
/*! |
|
174 |
\fn void QSize::scale(int width, int height, Qt::AspectRatioMode mode) |
|
175 |
||
176 |
Scales the size to a rectangle with the given \a width and \a |
|
177 |
height, according to the specified \a mode: |
|
178 |
||
179 |
\list |
|
180 |
\i If \a mode is Qt::IgnoreAspectRatio, the size is set to (\a width, \a height). |
|
181 |
\i If \a mode is Qt::KeepAspectRatio, the current size is scaled to a rectangle |
|
182 |
as large as possible inside (\a width, \a height), preserving the aspect ratio. |
|
183 |
\i If \a mode is Qt::KeepAspectRatioByExpanding, the current size is scaled to a rectangle |
|
184 |
as small as possible outside (\a width, \a height), preserving the aspect ratio. |
|
185 |
\endlist |
|
186 |
||
187 |
Example: |
|
188 |
\snippet doc/src/snippets/code/src_corelib_tools_qsize.cpp 0 |
|
189 |
||
190 |
\sa setWidth(), setHeight() |
|
191 |
*/ |
|
192 |
||
193 |
/*! |
|
194 |
\fn void QSize::scale(const QSize &size, Qt::AspectRatioMode mode) |
|
195 |
\overload |
|
196 |
||
197 |
Scales the size to a rectangle with the given \a size, according to |
|
198 |
the specified \a mode. |
|
199 |
*/ |
|
200 |
void QSize::scale(const QSize &s, Qt::AspectRatioMode mode) |
|
201 |
{ |
|
202 |
if (mode == Qt::IgnoreAspectRatio || wd == 0 || ht == 0) { |
|
203 |
wd = s.wd; |
|
204 |
ht = s.ht; |
|
205 |
} else { |
|
206 |
bool useHeight; |
|
207 |
qint64 rw = qint64(s.ht) * qint64(wd) / qint64(ht); |
|
208 |
||
209 |
if (mode == Qt::KeepAspectRatio) { |
|
210 |
useHeight = (rw <= s.wd); |
|
211 |
} else { // mode == Qt::KeepAspectRatioByExpanding |
|
212 |
useHeight = (rw >= s.wd); |
|
213 |
} |
|
214 |
||
215 |
if (useHeight) { |
|
216 |
wd = rw; |
|
217 |
ht = s.ht; |
|
218 |
} else { |
|
219 |
ht = qint32(qint64(s.wd) * qint64(ht) / qint64(wd)); |
|
220 |
wd = s.wd; |
|
221 |
} |
|
222 |
} |
|
223 |
} |
|
224 |
||
225 |
/*! |
|
226 |
\fn int &QSize::rwidth() |
|
227 |
||
228 |
Returns a reference to the width. |
|
229 |
||
230 |
Using a reference makes it possible to manipulate the width |
|
231 |
directly. For example: |
|
232 |
||
233 |
\snippet doc/src/snippets/code/src_corelib_tools_qsize.cpp 1 |
|
234 |
||
235 |
\sa rheight(), setWidth() |
|
236 |
*/ |
|
237 |
||
238 |
/*! |
|
239 |
\fn int &QSize::rheight() |
|
240 |
||
241 |
Returns a reference to the height. |
|
242 |
||
243 |
Using a reference makes it possible to manipulate the height |
|
244 |
directly. For example: |
|
245 |
||
246 |
\snippet doc/src/snippets/code/src_corelib_tools_qsize.cpp 2 |
|
247 |
||
248 |
\sa rwidth(), setHeight() |
|
249 |
*/ |
|
250 |
||
251 |
/*! |
|
252 |
\fn QSize &QSize::operator+=(const QSize &size) |
|
253 |
||
254 |
Adds the given \a size to \e this size, and returns a reference to |
|
255 |
this size. For example: |
|
256 |
||
257 |
\snippet doc/src/snippets/code/src_corelib_tools_qsize.cpp 3 |
|
258 |
*/ |
|
259 |
||
260 |
/*! |
|
261 |
\fn QSize &QSize::operator-=(const QSize &size) |
|
262 |
||
263 |
Subtracts the given \a size from \e this size, and returns a |
|
264 |
reference to this size. For example: |
|
265 |
||
266 |
\snippet doc/src/snippets/code/src_corelib_tools_qsize.cpp 4 |
|
267 |
*/ |
|
268 |
||
269 |
/*! |
|
270 |
\fn QSize &QSize::operator*=(qreal factor) |
|
271 |
\overload |
|
272 |
||
273 |
Multiplies both the width and height by the given \a factor, and |
|
274 |
returns a reference to the size. |
|
275 |
||
276 |
Note that the result is rounded to the nearest integer. |
|
277 |
||
278 |
\sa scale() |
|
279 |
*/ |
|
280 |
||
281 |
/*! |
|
282 |
\fn bool operator==(const QSize &s1, const QSize &s2) |
|
283 |
\relates QSize |
|
284 |
||
285 |
Returns true if \a s1 and \a s2 are equal; otherwise returns false. |
|
286 |
*/ |
|
287 |
||
288 |
/*! |
|
289 |
\fn bool operator!=(const QSize &s1, const QSize &s2) |
|
290 |
\relates QSize |
|
291 |
||
292 |
Returns true if \a s1 and \a s2 are different; otherwise returns false. |
|
293 |
*/ |
|
294 |
||
295 |
/*! |
|
296 |
\fn const QSize operator+(const QSize &s1, const QSize &s2) |
|
297 |
\relates QSize |
|
298 |
||
299 |
Returns the sum of \a s1 and \a s2; each component is added separately. |
|
300 |
*/ |
|
301 |
||
302 |
/*! |
|
303 |
\fn const QSize operator-(const QSize &s1, const QSize &s2) |
|
304 |
\relates QSize |
|
305 |
||
306 |
Returns \a s2 subtracted from \a s1; each component is subtracted |
|
307 |
separately. |
|
308 |
*/ |
|
309 |
||
310 |
/*! |
|
311 |
\fn const QSize operator*(const QSize &size, qreal factor) |
|
312 |
\relates QSize |
|
313 |
||
314 |
Multiplies the given \a size by the given \a factor, and returns |
|
315 |
the result rounded to the nearest integer. |
|
316 |
||
317 |
\sa QSize::scale() |
|
318 |
*/ |
|
319 |
||
320 |
/*! |
|
321 |
\fn const QSize operator*(qreal factor, const QSize &size) |
|
322 |
\overload |
|
323 |
\relates QSize |
|
324 |
||
325 |
Multiplies the given \a size by the given \a factor, and returns |
|
326 |
the result rounded to the nearest integer. |
|
327 |
*/ |
|
328 |
||
329 |
/*! |
|
330 |
\fn QSize &QSize::operator/=(qreal divisor) |
|
331 |
\overload |
|
332 |
||
333 |
Divides both the width and height by the given \a divisor, and |
|
334 |
returns a reference to the size. |
|
335 |
||
336 |
Note that the result is rounded to the nearest integer. |
|
337 |
||
338 |
\sa QSize::scale() |
|
339 |
*/ |
|
340 |
||
341 |
/*! |
|
342 |
\fn const QSize operator/(const QSize &size, qreal divisor) |
|
343 |
\relates QSize |
|
344 |
\overload |
|
345 |
||
346 |
Divides the given \a size by the given \a divisor, and returns the |
|
347 |
result rounded to the nearest integer. |
|
348 |
||
349 |
\sa QSize::scale() |
|
350 |
*/ |
|
351 |
||
352 |
/*! |
|
353 |
\fn QSize QSize::expandedTo(const QSize & otherSize) const |
|
354 |
||
355 |
Returns a size holding the maximum width and height of this size |
|
356 |
and the given \a otherSize. |
|
357 |
||
358 |
\sa boundedTo(), scale() |
|
359 |
*/ |
|
360 |
||
361 |
/*! |
|
362 |
\fn QSize QSize::boundedTo(const QSize & otherSize) const |
|
363 |
||
364 |
Returns a size holding the minimum width and height of this size |
|
365 |
and the given \a otherSize. |
|
366 |
||
367 |
\sa expandedTo(), scale() |
|
368 |
*/ |
|
369 |
||
370 |
||
371 |
||
372 |
/***************************************************************************** |
|
373 |
QSize stream functions |
|
374 |
*****************************************************************************/ |
|
375 |
#ifndef QT_NO_DATASTREAM |
|
376 |
/*! |
|
377 |
\fn QDataStream &operator<<(QDataStream &stream, const QSize &size) |
|
378 |
\relates QSize |
|
379 |
||
380 |
Writes the given \a size to the given \a stream, and returns a |
|
381 |
reference to the stream. |
|
382 |
||
383 |
\sa {Format of the QDataStream Operators} |
|
384 |
*/ |
|
385 |
||
386 |
QDataStream &operator<<(QDataStream &s, const QSize &sz) |
|
387 |
{ |
|
388 |
if (s.version() == 1) |
|
389 |
s << (qint16)sz.width() << (qint16)sz.height(); |
|
390 |
else |
|
391 |
s << (qint32)sz.width() << (qint32)sz.height(); |
|
392 |
return s; |
|
393 |
} |
|
394 |
||
395 |
/*! |
|
396 |
\fn QDataStream &operator>>(QDataStream &stream, QSize &size) |
|
397 |
\relates QSize |
|
398 |
||
399 |
Reads a size from the given \a stream into the given \a size, and |
|
400 |
returns a reference to the stream. |
|
401 |
||
402 |
\sa {Format of the QDataStream Operators} |
|
403 |
*/ |
|
404 |
||
405 |
QDataStream &operator>>(QDataStream &s, QSize &sz) |
|
406 |
{ |
|
407 |
if (s.version() == 1) { |
|
408 |
qint16 w, h; |
|
409 |
s >> w; sz.rwidth() = w; |
|
410 |
s >> h; sz.rheight() = h; |
|
411 |
} |
|
412 |
else { |
|
413 |
qint32 w, h; |
|
414 |
s >> w; sz.rwidth() = w; |
|
415 |
s >> h; sz.rheight() = h; |
|
416 |
} |
|
417 |
return s; |
|
418 |
} |
|
419 |
#endif // QT_NO_DATASTREAM |
|
420 |
||
421 |
#ifndef QT_NO_DEBUG_STREAM |
|
422 |
QDebug operator<<(QDebug dbg, const QSize &s) { |
|
423 |
dbg.nospace() << "QSize(" << s.width() << ", " << s.height() << ')'; |
|
424 |
return dbg.space(); |
|
425 |
} |
|
426 |
#endif |
|
427 |
||
428 |
||
429 |
||
430 |
/*! |
|
431 |
\class QSizeF |
|
432 |
\brief The QSizeF class defines the size of a two-dimensional object |
|
433 |
using floating point precision. |
|
434 |
||
435 |
\ingroup painting |
|
436 |
||
437 |
A size is specified by a width() and a height(). It can be set in |
|
438 |
the constructor and changed using the setWidth(), setHeight(), or |
|
439 |
scale() functions, or using arithmetic operators. A size can also |
|
440 |
be manipulated directly by retrieving references to the width and |
|
441 |
height using the rwidth() and rheight() functions. Finally, the |
|
442 |
width and height can be swapped using the transpose() function. |
|
443 |
||
444 |
The isValid() function determines if a size is valid. A valid size |
|
445 |
has both width and height greater than or equal to zero. The |
|
446 |
isEmpty() function returns true if either of the width and height |
|
447 |
is \e less than (or equal to) zero, while the isNull() function |
|
448 |
returns true only if both the width and the height is zero. |
|
449 |
||
450 |
Use the expandedTo() function to retrieve a size which holds the |
|
451 |
maximum height and width of this size and a given |
|
452 |
size. Similarly, the boundedTo() function returns a size which |
|
453 |
holds the minimum height and width of this size and a given size. |
|
454 |
||
455 |
The QSizeF class also provides the toSize() function returning a |
|
456 |
QSize copy of this size, constructed by rounding the width and |
|
457 |
height to the nearest integers. |
|
458 |
||
459 |
QSizeF objects can be streamed as well as compared. |
|
460 |
||
461 |
\sa QSize, QPointF, QRectF |
|
462 |
*/ |
|
463 |
||
464 |
||
465 |
/***************************************************************************** |
|
466 |
QSizeF member functions |
|
467 |
*****************************************************************************/ |
|
468 |
||
469 |
/*! |
|
470 |
\fn QSizeF::QSizeF() |
|
471 |
||
472 |
Constructs an invalid size. |
|
473 |
||
474 |
\sa isValid() |
|
475 |
*/ |
|
476 |
||
477 |
/*! |
|
478 |
\fn QSizeF::QSizeF(const QSize &size) |
|
479 |
||
480 |
Constructs a size with floating point accuracy from the given \a |
|
481 |
size. |
|
482 |
||
483 |
\sa toSize() |
|
484 |
*/ |
|
485 |
||
486 |
/*! |
|
487 |
\fn QSizeF::QSizeF(qreal width, qreal height) |
|
488 |
||
489 |
Constructs a size with the given \a width and \a height. |
|
490 |
*/ |
|
491 |
||
492 |
/*! |
|
493 |
\fn bool QSizeF::isNull() const |
|
494 |
||
495 |
Returns true if both the width and height is 0; otherwise returns |
|
496 |
false. |
|
497 |
||
498 |
\sa isValid(), isEmpty() |
|
499 |
*/ |
|
500 |
||
501 |
/*! |
|
502 |
\fn bool QSizeF::isEmpty() const |
|
503 |
||
504 |
Returns true if either of the width and height is less than or |
|
505 |
equal to 0; otherwise returns false. |
|
506 |
||
507 |
\sa isNull(), isValid() |
|
508 |
*/ |
|
509 |
||
510 |
/*! |
|
511 |
\fn bool QSizeF::isValid() const |
|
512 |
||
513 |
Returns true if both the width and height is equal to or greater |
|
514 |
than 0; otherwise returns false. |
|
515 |
||
516 |
\sa isNull(), isEmpty() |
|
517 |
*/ |
|
518 |
||
519 |
/*! |
|
520 |
\fn int QSizeF::width() const |
|
521 |
||
522 |
Returns the width. |
|
523 |
||
524 |
\sa height(), setWidth() |
|
525 |
*/ |
|
526 |
||
527 |
/*! |
|
528 |
\fn int QSizeF::height() const |
|
529 |
||
530 |
Returns the height. |
|
531 |
||
532 |
\sa width(), setHeight() |
|
533 |
*/ |
|
534 |
||
535 |
/*! |
|
536 |
\fn void QSizeF::setWidth(qreal width) |
|
537 |
||
538 |
Sets the width to the given \a width. |
|
539 |
||
540 |
\sa width(), rwidth(), setHeight() |
|
541 |
*/ |
|
542 |
||
543 |
/*! |
|
544 |
\fn void QSizeF::setHeight(qreal height) |
|
545 |
||
546 |
Sets the height to the given \a height. |
|
547 |
||
548 |
\sa height(), rheight(), setWidth() |
|
549 |
*/ |
|
550 |
||
551 |
/*! |
|
552 |
\fn QSize QSizeF::toSize() const |
|
553 |
||
554 |
Returns an integer based copy of this size. |
|
555 |
||
556 |
Note that the coordinates in the returned size will be rounded to |
|
557 |
the nearest integer. |
|
558 |
||
559 |
\sa QSizeF() |
|
560 |
*/ |
|
561 |
||
562 |
/*! |
|
563 |
Swaps the width and height values. |
|
564 |
||
565 |
\sa setWidth(), setHeight() |
|
566 |
*/ |
|
567 |
||
568 |
void QSizeF::transpose() |
|
569 |
{ |
|
570 |
qreal tmp = wd; |
|
571 |
wd = ht; |
|
572 |
ht = tmp; |
|
573 |
} |
|
574 |
||
575 |
/*! |
|
576 |
\fn void QSizeF::scale(qreal width, qreal height, Qt::AspectRatioMode mode) |
|
577 |
||
578 |
Scales the size to a rectangle with the given \a width and \a |
|
579 |
height, according to the specified \a mode. |
|
580 |
||
581 |
\list |
|
582 |
\i If \a mode is Qt::IgnoreAspectRatio, the size is set to (\a width, \a height). |
|
583 |
\i If \a mode is Qt::KeepAspectRatio, the current size is scaled to a rectangle |
|
584 |
as large as possible inside (\a width, \a height), preserving the aspect ratio. |
|
585 |
\i If \a mode is Qt::KeepAspectRatioByExpanding, the current size is scaled to a rectangle |
|
586 |
as small as possible outside (\a width, \a height), preserving the aspect ratio. |
|
587 |
\endlist |
|
588 |
||
589 |
Example: |
|
590 |
\snippet doc/src/snippets/code/src_corelib_tools_qsize.cpp 5 |
|
591 |
||
592 |
\sa setWidth(), setHeight() |
|
593 |
*/ |
|
594 |
||
595 |
/*! |
|
596 |
\fn void QSizeF::scale(const QSizeF &size, Qt::AspectRatioMode mode) |
|
597 |
\overload |
|
598 |
||
599 |
Scales the size to a rectangle with the given \a size, according to |
|
600 |
the specified \a mode. |
|
601 |
*/ |
|
602 |
void QSizeF::scale(const QSizeF &s, Qt::AspectRatioMode mode) |
|
603 |
{ |
|
604 |
if (mode == Qt::IgnoreAspectRatio || qIsNull(wd) || qIsNull(ht)) { |
|
605 |
wd = s.wd; |
|
606 |
ht = s.ht; |
|
607 |
} else { |
|
608 |
bool useHeight; |
|
609 |
qreal rw = s.ht * wd / ht; |
|
610 |
||
611 |
if (mode == Qt::KeepAspectRatio) { |
|
612 |
useHeight = (rw <= s.wd); |
|
613 |
} else { // mode == Qt::KeepAspectRatioByExpanding |
|
614 |
useHeight = (rw >= s.wd); |
|
615 |
} |
|
616 |
||
617 |
if (useHeight) { |
|
618 |
wd = rw; |
|
619 |
ht = s.ht; |
|
620 |
} else { |
|
621 |
ht = s.wd * ht / wd; |
|
622 |
wd = s.wd; |
|
623 |
} |
|
624 |
} |
|
625 |
} |
|
626 |
||
627 |
/*! |
|
628 |
\fn int &QSizeF::rwidth() |
|
629 |
||
630 |
Returns a reference to the width. |
|
631 |
||
632 |
Using a reference makes it possible to manipulate the width |
|
633 |
directly. For example: |
|
634 |
||
635 |
\snippet doc/src/snippets/code/src_corelib_tools_qsize.cpp 6 |
|
636 |
||
637 |
\sa rheight(), setWidth() |
|
638 |
*/ |
|
639 |
||
640 |
/*! |
|
641 |
\fn int &QSizeF::rheight() |
|
642 |
||
643 |
Returns a reference to the height. |
|
644 |
||
645 |
Using a reference makes it possible to manipulate the height |
|
646 |
directly. For example: |
|
647 |
||
648 |
\snippet doc/src/snippets/code/src_corelib_tools_qsize.cpp 7 |
|
649 |
||
650 |
\sa rwidth(), setHeight() |
|
651 |
*/ |
|
652 |
||
653 |
/*! |
|
654 |
\fn QSizeF &QSizeF::operator+=(const QSizeF &size) |
|
655 |
||
656 |
Adds the given \a size to this size and returns a reference to |
|
657 |
this size. For example: |
|
658 |
||
659 |
\snippet doc/src/snippets/code/src_corelib_tools_qsize.cpp 8 |
|
660 |
*/ |
|
661 |
||
662 |
/*! |
|
663 |
\fn QSizeF &QSizeF::operator-=(const QSizeF &size) |
|
664 |
||
665 |
Subtracts the given \a size from this size and returns a reference |
|
666 |
to this size. For example: |
|
667 |
||
668 |
\snippet doc/src/snippets/code/src_corelib_tools_qsize.cpp 9 |
|
669 |
*/ |
|
670 |
||
671 |
/*! |
|
672 |
\fn QSizeF &QSizeF::operator*=(qreal factor) |
|
673 |
\overload |
|
674 |
||
675 |
Multiplies both the width and height by the given \a factor and |
|
676 |
returns a reference to the size. |
|
677 |
||
678 |
\sa scale() |
|
679 |
*/ |
|
680 |
||
681 |
/*! |
|
682 |
\fn bool operator==(const QSizeF &s1, const QSizeF &s2) |
|
683 |
\relates QSizeF |
|
684 |
||
685 |
Returns true if \a s1 and \a s2 are equal; otherwise returns |
|
686 |
false. |
|
687 |
*/ |
|
688 |
||
689 |
/*! |
|
690 |
\fn bool operator!=(const QSizeF &s1, const QSizeF &s2) |
|
691 |
\relates QSizeF |
|
692 |
||
693 |
Returns true if \a s1 and \a s2 are different; otherwise returns false. |
|
694 |
*/ |
|
695 |
||
696 |
/*! |
|
697 |
\fn const QSizeF operator+(const QSizeF &s1, const QSizeF &s2) |
|
698 |
\relates QSizeF |
|
699 |
||
700 |
Returns the sum of \a s1 and \a s2; each component is added separately. |
|
701 |
*/ |
|
702 |
||
703 |
/*! |
|
704 |
\fn const QSizeF operator-(const QSizeF &s1, const QSizeF &s2) |
|
705 |
\relates QSizeF |
|
706 |
||
707 |
Returns \a s2 subtracted from \a s1; each component is subtracted |
|
708 |
separately. |
|
709 |
*/ |
|
710 |
||
711 |
/*! |
|
712 |
\fn const QSizeF operator*(const QSizeF &size, qreal factor) |
|
713 |
||
714 |
\overload |
|
715 |
\relates QSizeF |
|
716 |
||
717 |
Multiplies the given \a size by the given \a factor and returns |
|
718 |
the result. |
|
719 |
||
720 |
\sa QSizeF::scale() |
|
721 |
*/ |
|
722 |
||
723 |
/*! |
|
724 |
\fn const QSizeF operator*(qreal factor, const QSizeF &size) |
|
725 |
||
726 |
\overload |
|
727 |
\relates QSizeF |
|
728 |
||
729 |
Multiplies the given \a size by the given \a factor and returns |
|
730 |
the result. |
|
731 |
*/ |
|
732 |
||
733 |
/*! |
|
734 |
\fn QSizeF &QSizeF::operator/=(qreal divisor) |
|
735 |
||
736 |
\overload |
|
737 |
||
738 |
Divides both the width and height by the given \a divisor and |
|
739 |
returns a reference to the size. |
|
740 |
||
741 |
\sa scale() |
|
742 |
*/ |
|
743 |
||
744 |
/*! |
|
745 |
\fn const QSizeF operator/(const QSizeF &size, qreal divisor) |
|
746 |
||
747 |
\relates QSizeF |
|
748 |
\overload |
|
749 |
||
750 |
Divides the given \a size by the given \a divisor and returns the |
|
751 |
result. |
|
752 |
||
753 |
\sa QSizeF::scale() |
|
754 |
*/ |
|
755 |
||
756 |
/*! |
|
757 |
\fn QSizeF QSizeF::expandedTo(const QSizeF & otherSize) const |
|
758 |
||
759 |
Returns a size holding the maximum width and height of this size |
|
760 |
and the given \a otherSize. |
|
761 |
||
762 |
\sa boundedTo(), scale() |
|
763 |
*/ |
|
764 |
||
765 |
/*! |
|
766 |
\fn QSizeF QSizeF::boundedTo(const QSizeF & otherSize) const |
|
767 |
||
768 |
Returns a size holding the minimum width and height of this size |
|
769 |
and the given \a otherSize. |
|
770 |
||
771 |
\sa expandedTo(), scale() |
|
772 |
*/ |
|
773 |
||
774 |
||
775 |
||
776 |
/***************************************************************************** |
|
777 |
QSizeF stream functions |
|
778 |
*****************************************************************************/ |
|
779 |
#ifndef QT_NO_DATASTREAM |
|
780 |
/*! |
|
781 |
\fn QDataStream &operator<<(QDataStream &stream, const QSizeF &size) |
|
782 |
\relates QSizeF |
|
783 |
||
784 |
Writes the given \a size to the given \a stream and returns a |
|
785 |
reference to the stream. |
|
786 |
||
787 |
\sa {Format of the QDataStream Operators} |
|
788 |
*/ |
|
789 |
||
790 |
QDataStream &operator<<(QDataStream &s, const QSizeF &sz) |
|
791 |
{ |
|
792 |
s << double(sz.width()) << double(sz.height()); |
|
793 |
return s; |
|
794 |
} |
|
795 |
||
796 |
/*! |
|
797 |
\fn QDataStream &operator>>(QDataStream &stream, QSizeF &size) |
|
798 |
\relates QSizeF |
|
799 |
||
800 |
Reads a size from the given \a stream into the given \a size and |
|
801 |
returns a reference to the stream. |
|
802 |
||
803 |
\sa {Format of the QDataStream Operators} |
|
804 |
*/ |
|
805 |
||
806 |
QDataStream &operator>>(QDataStream &s, QSizeF &sz) |
|
807 |
{ |
|
808 |
double w, h; |
|
809 |
s >> w; |
|
810 |
s >> h; |
|
811 |
sz.setWidth(qreal(w)); |
|
812 |
sz.setHeight(qreal(h)); |
|
813 |
return s; |
|
814 |
} |
|
815 |
#endif // QT_NO_DATASTREAM |
|
816 |
||
817 |
#ifndef QT_NO_DEBUG_STREAM |
|
818 |
QDebug operator<<(QDebug dbg, const QSizeF &s) { |
|
819 |
dbg.nospace() << "QSizeF(" << s.width() << ", " << s.height() << ')'; |
|
820 |
return dbg.space(); |
|
821 |
} |
|
822 |
#endif |
|
823 |
||
824 |
QT_END_NAMESPACE |