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