~oif-team/ubuntu/natty/qt4-x11/xi2.1

« back to all changes in this revision

Viewing changes to src/corelib/tools/qsize.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Adam Conrad
  • Date: 2005-08-24 04:09:09 UTC
  • Revision ID: james.westby@ubuntu.com-20050824040909-xmxe9jfr4a0w5671
Tags: upstream-4.0.0
ImportĀ upstreamĀ versionĀ 4.0.0

Show diffs side-by-side

added added

removed removed

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