| Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/widgets/kernel/qsizepolicy.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 QtWidgets 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 "qsizepolicy.h" | - | ||||||
| 35 | - | |||||||
| 36 | #include <qdatastream.h> | - | ||||||
| 37 | #include <qdebug.h> | - | ||||||
| 38 | #include <qvariant.h> | - | ||||||
| 39 | - | |||||||
| 40 | QT_BEGIN_NAMESPACE | - | ||||||
| 41 | - | |||||||
| 42 | /*! | - | ||||||
| 43 | \class QSizePolicy | - | ||||||
| 44 | \brief The QSizePolicy class is a layout attribute describing horizontal | - | ||||||
| 45 | and vertical resizing policy. | - | ||||||
| 46 | - | |||||||
| 47 | \ingroup geomanagement | - | ||||||
| 48 | \inmodule QtWidgets | - | ||||||
| 49 | - | |||||||
| 50 | The size policy of a widget is an expression of its willingness to | - | ||||||
| 51 | be resized in various ways, and affects how the widget is treated | - | ||||||
| 52 | by the \l{Layout Management}{layout engine}. Each widget returns a | - | ||||||
| 53 | QSizePolicy that describes the horizontal and vertical resizing | - | ||||||
| 54 | policy it prefers when being laid out. You can change this for | - | ||||||
| 55 | a specific widget by changing its QWidget::sizePolicy property. | - | ||||||
| 56 | - | |||||||
| 57 | QSizePolicy contains two independent QSizePolicy::Policy values | - | ||||||
| 58 | and two stretch factors; one describes the widgets's horizontal | - | ||||||
| 59 | size policy, and the other describes its vertical size policy. It | - | ||||||
| 60 | also contains a flag to indicate whether the height and width of | - | ||||||
| 61 | its preferred size are related. | - | ||||||
| 62 | - | |||||||
| 63 | The horizontal and vertical policies can be set in the | - | ||||||
| 64 | constructor, and altered using the setHorizontalPolicy() and | - | ||||||
| 65 | setVerticalPolicy() functions. The stretch factors can be set | - | ||||||
| 66 | using the setHorizontalStretch() and setVerticalStretch() | - | ||||||
| 67 | functions. The flag indicating whether the widget's | - | ||||||
| 68 | \l{QWidget::sizeHint()}{sizeHint()} is width-dependent (such as a | - | ||||||
| 69 | menu bar or a word-wrapping label) can be set using the | - | ||||||
| 70 | setHeightForWidth() function. | - | ||||||
| 71 | - | |||||||
| 72 | The current size policies and stretch factors be retrieved using | - | ||||||
| 73 | the horizontalPolicy(), verticalPolicy(), horizontalStretch() and | - | ||||||
| 74 | verticalStretch() functions. Alternatively, use the transpose() | - | ||||||
| 75 | function to swap the horizontal and vertical policies and | - | ||||||
| 76 | stretches. The hasHeightForWidth() function returns the current | - | ||||||
| 77 | status of the flag indicating the size hint dependencies. | - | ||||||
| 78 | - | |||||||
| 79 | Use the expandingDirections() function to determine whether the | - | ||||||
| 80 | associated widget can make use of more space than its | - | ||||||
| 81 | \l{QWidget::sizeHint()}{sizeHint()} function indicates, as well as | - | ||||||
| 82 | find out in which directions it can expand. | - | ||||||
| 83 | - | |||||||
| 84 | Finally, the QSizePolicy class provides operators comparing this | - | ||||||
| 85 | size policy to a given policy, as well as a QVariant operator | - | ||||||
| 86 | storing this QSizePolicy as a QVariant object. | - | ||||||
| 87 | - | |||||||
| 88 | \sa QSize, QWidget::sizeHint(), QWidget::sizePolicy, | - | ||||||
| 89 | QLayoutItem::sizeHint() | - | ||||||
| 90 | */ | - | ||||||
| 91 | - | |||||||
| 92 | /*! | - | ||||||
| 93 | \enum QSizePolicy::PolicyFlag | - | ||||||
| 94 | - | |||||||
| 95 | These flags are combined together to form the various \l{Policy} | - | ||||||
| 96 | values: | - | ||||||
| 97 | - | |||||||
| 98 | \value GrowFlag The widget can grow beyond its size hint if necessary. | - | ||||||
| 99 | \value ExpandFlag The widget should get as much space as possible. | - | ||||||
| 100 | \value ShrinkFlag The widget can shrink below its size hint if necessary. | - | ||||||
| 101 | \value IgnoreFlag The widget's size hint is ignored. The widget will get | - | ||||||
| 102 | as much space as possible. | - | ||||||
| 103 | - | |||||||
| 104 | \sa Policy | - | ||||||
| 105 | */ | - | ||||||
| 106 | - | |||||||
| 107 | /*! | - | ||||||
| 108 | \enum QSizePolicy::Policy | - | ||||||
| 109 | - | |||||||
| 110 | This enum describes the various per-dimension sizing types used | - | ||||||
| 111 | when constructing a QSizePolicy. | - | ||||||
| 112 | - | |||||||
| 113 | \value Fixed The QWidget::sizeHint() is the only acceptable | - | ||||||
| 114 | alternative, so the widget can never grow or shrink (e.g. the | - | ||||||
| 115 | vertical direction of a push button). | - | ||||||
| 116 | - | |||||||
| 117 | \value Minimum The sizeHint() is minimal, and sufficient. The | - | ||||||
| 118 | widget can be expanded, but there is no advantage to it being | - | ||||||
| 119 | larger (e.g. the horizontal direction of a push button). | - | ||||||
| 120 | It cannot be smaller than the size provided by sizeHint(). | - | ||||||
| 121 | - | |||||||
| 122 | \value Maximum The sizeHint() is a maximum. The widget can be | - | ||||||
| 123 | shrunk any amount without detriment if other widgets need the | - | ||||||
| 124 | space (e.g. a separator line). | - | ||||||
| 125 | It cannot be larger than the size provided by sizeHint(). | - | ||||||
| 126 | - | |||||||
| 127 | \value Preferred The sizeHint() is best, but the widget can be | - | ||||||
| 128 | shrunk and still be useful. The widget can be expanded, but there | - | ||||||
| 129 | is no advantage to it being larger than sizeHint() (the default | - | ||||||
| 130 | QWidget policy). | - | ||||||
| 131 | - | |||||||
| 132 | \value Expanding The sizeHint() is a sensible size, but the | - | ||||||
| 133 | widget can be shrunk and still be useful. The widget can make use | - | ||||||
| 134 | of extra space, so it should get as much space as possible (e.g. | - | ||||||
| 135 | the horizontal direction of a horizontal slider). | - | ||||||
| 136 | - | |||||||
| 137 | \value MinimumExpanding The sizeHint() is minimal, and sufficient. | - | ||||||
| 138 | The widget can make use of extra space, so it should get as much | - | ||||||
| 139 | space as possible (e.g. the horizontal direction of a horizontal | - | ||||||
| 140 | slider). | - | ||||||
| 141 | - | |||||||
| 142 | \value Ignored The sizeHint() is ignored. The widget will get as | - | ||||||
| 143 | much space as possible. | - | ||||||
| 144 | - | |||||||
| 145 | \sa PolicyFlag, setHorizontalPolicy(), setVerticalPolicy() | - | ||||||
| 146 | */ | - | ||||||
| 147 | - | |||||||
| 148 | /*! | - | ||||||
| 149 | \fn QSizePolicy::QSizePolicy() | - | ||||||
| 150 | - | |||||||
| 151 | Constructs a QSizePolicy object with \l Fixed as its horizontal | - | ||||||
| 152 | and vertical policies. | - | ||||||
| 153 | - | |||||||
| 154 | The policies can be altered using the setHorizontalPolicy() and | - | ||||||
| 155 | setVerticalPolicy() functions. Use the setHeightForWidth() | - | ||||||
| 156 | function if the preferred height of the widget is dependent on the | - | ||||||
| 157 | width of the widget (for example, a QLabel with line wrapping). | - | ||||||
| 158 | - | |||||||
| 159 | \sa setHorizontalStretch(), setVerticalStretch() | - | ||||||
| 160 | */ | - | ||||||
| 161 | - | |||||||
| 162 | /*! | - | ||||||
| 163 | \fn QSizePolicy::QSizePolicy(Policy horizontal, Policy vertical, ControlType type) | - | ||||||
| 164 | \since 4.3 | - | ||||||
| 165 | - | |||||||
| 166 | Constructs a QSizePolicy object with the given \a horizontal and | - | ||||||
| 167 | \a vertical policies, and the specified control \a type. | - | ||||||
| 168 | - | |||||||
| 169 | Use setHeightForWidth() if the preferred height of the widget is | - | ||||||
| 170 | dependent on the width of the widget (for example, a QLabel with | - | ||||||
| 171 | line wrapping). | - | ||||||
| 172 | - | |||||||
| 173 | \sa setHorizontalStretch(), setVerticalStretch(), controlType() | - | ||||||
| 174 | */ | - | ||||||
| 175 | - | |||||||
| 176 | /*! | - | ||||||
| 177 | \fn QSizePolicy::Policy QSizePolicy::horizontalPolicy() const | - | ||||||
| 178 | - | |||||||
| 179 | Returns the horizontal component of the size policy. | - | ||||||
| 180 | - | |||||||
| 181 | \sa setHorizontalPolicy(), verticalPolicy(), horizontalStretch() | - | ||||||
| 182 | */ | - | ||||||
| 183 | - | |||||||
| 184 | /*! | - | ||||||
| 185 | \fn QSizePolicy::Policy QSizePolicy::verticalPolicy() const | - | ||||||
| 186 | - | |||||||
| 187 | Returns the vertical component of the size policy. | - | ||||||
| 188 | - | |||||||
| 189 | \sa setVerticalPolicy(), horizontalPolicy(), verticalStretch() | - | ||||||
| 190 | */ | - | ||||||
| 191 | - | |||||||
| 192 | /*! | - | ||||||
| 193 | \fn void QSizePolicy::setHorizontalPolicy(Policy policy) | - | ||||||
| 194 | - | |||||||
| 195 | Sets the horizontal component to the given \a policy. | - | ||||||
| 196 | - | |||||||
| 197 | \sa horizontalPolicy(), setVerticalPolicy(), setHorizontalStretch() | - | ||||||
| 198 | */ | - | ||||||
| 199 | - | |||||||
| 200 | /*! | - | ||||||
| 201 | \fn void QSizePolicy::setVerticalPolicy(Policy policy) | - | ||||||
| 202 | - | |||||||
| 203 | Sets the vertical component to the given \a policy. | - | ||||||
| 204 | - | |||||||
| 205 | \sa verticalPolicy(), setHorizontalPolicy(), setVerticalStretch() | - | ||||||
| 206 | */ | - | ||||||
| 207 | - | |||||||
| 208 | /*! | - | ||||||
| 209 | \fn Qt::Orientations QSizePolicy::expandingDirections() const | - | ||||||
| 210 | - | |||||||
| 211 | Returns whether a widget can make use of more space than the | - | ||||||
| 212 | QWidget::sizeHint() function indicates. | - | ||||||
| 213 | - | |||||||
| 214 | A value of Qt::Horizontal or Qt::Vertical means that the widget | - | ||||||
| 215 | can grow horizontally or vertically (i.e., the horizontal or | - | ||||||
| 216 | vertical policy is \l Expanding or \l MinimumExpanding), whereas | - | ||||||
| 217 | Qt::Horizontal | Qt::Vertical means that it can grow in both | - | ||||||
| 218 | dimensions. | - | ||||||
| 219 | - | |||||||
| 220 | \sa horizontalPolicy(), verticalPolicy() | - | ||||||
| 221 | */ | - | ||||||
| 222 | - | |||||||
| 223 | /*! | - | ||||||
| 224 | \since 4.3 | - | ||||||
| 225 | - | |||||||
| 226 | Returns the control type associated with the widget for which | - | ||||||
| 227 | this size policy applies. | - | ||||||
| 228 | */ | - | ||||||
| 229 | QSizePolicy::ControlType QSizePolicy::controlType() const | - | ||||||
| 230 | { | - | ||||||
| 231 | return QSizePolicy::ControlType(1 << bits.ctype); never executed: return QSizePolicy::ControlType(1 << bits.ctype); | 0 | ||||||
| 232 | } | - | ||||||
| 233 | - | |||||||
| 234 | - | |||||||
| 235 | /*! | - | ||||||
| 236 | \since 4.3 | - | ||||||
| 237 | - | |||||||
| 238 | Sets the control type associated with the widget for which this | - | ||||||
| 239 | size policy applies to \a type. | - | ||||||
| 240 | - | |||||||
| 241 | The control type specifies the type of the widget for which this | - | ||||||
| 242 | size policy applies. It is used by some styles, notably | - | ||||||
| 243 | QMacStyle, to insert proper spacing between widgets. For example, | - | ||||||
| 244 | the \macos Aqua guidelines specify that push buttons should be | - | ||||||
| 245 | separated by 12 pixels, whereas vertically stacked radio buttons | - | ||||||
| 246 | only require 6 pixels. | - | ||||||
| 247 | - | |||||||
| 248 | \sa QStyle::layoutSpacing() | - | ||||||
| 249 | */ | - | ||||||
| 250 | void QSizePolicy::setControlType(ControlType type) | - | ||||||
| 251 | { | - | ||||||
| 252 | /* | - | ||||||
| 253 | The control type is a flag type, with values 0x1, 0x2, 0x4, 0x8, 0x10, | - | ||||||
| 254 | etc. In memory, we pack it onto the available bits (CTSize) in | - | ||||||
| 255 | setControlType(), and unpack it here. | - | ||||||
| 256 | - | |||||||
| 257 | Example: | - | ||||||
| 258 | - | |||||||
| 259 | 0x00000001 maps to 0 | - | ||||||
| 260 | 0x00000002 maps to 1 | - | ||||||
| 261 | 0x00000004 maps to 2 | - | ||||||
| 262 | 0x00000008 maps to 3 | - | ||||||
| 263 | etc. | - | ||||||
| 264 | */ | - | ||||||
| 265 | - | |||||||
| 266 | int i = 0; | - | ||||||
| 267 | while (true) { | - | ||||||
| 268 | if (type & (0x1 << i)) {
| 0 | ||||||
| 269 | bits.ctype = i; | - | ||||||
| 270 | return; never executed: return; | 0 | ||||||
| 271 | } | - | ||||||
| 272 | ++i; | - | ||||||
| 273 | } never executed: end of block | 0 | ||||||
| 274 | } never executed: end of block | 0 | ||||||
| 275 | - | |||||||
| 276 | /*! | - | ||||||
| 277 | \fn void QSizePolicy::setHeightForWidth(bool dependent) | - | ||||||
| 278 | - | |||||||
| 279 | Sets the flag determining whether the widget's preferred height | - | ||||||
| 280 | depends on its width, to \a dependent. | - | ||||||
| 281 | - | |||||||
| 282 | \sa hasHeightForWidth(), setWidthForHeight() | - | ||||||
| 283 | */ | - | ||||||
| 284 | - | |||||||
| 285 | /*! | - | ||||||
| 286 | \fn bool QSizePolicy::hasHeightForWidth() const | - | ||||||
| 287 | - | |||||||
| 288 | Returns \c true if the widget's preferred height depends on its | - | ||||||
| 289 | width; otherwise returns \c false. | - | ||||||
| 290 | - | |||||||
| 291 | \sa setHeightForWidth() | - | ||||||
| 292 | */ | - | ||||||
| 293 | - | |||||||
| 294 | /*! | - | ||||||
| 295 | \fn void QSizePolicy::setWidthForHeight(bool dependent) | - | ||||||
| 296 | - | |||||||
| 297 | Sets the flag determining whether the widget's width | - | ||||||
| 298 | depends on its height, to \a dependent. | - | ||||||
| 299 | - | |||||||
| 300 | This is only supported for QGraphicsLayout's subclasses. | - | ||||||
| 301 | It is not possible to have a layout with both height-for-width | - | ||||||
| 302 | and width-for-height constraints at the same time. | - | ||||||
| 303 | - | |||||||
| 304 | \sa hasWidthForHeight(), setHeightForWidth() | - | ||||||
| 305 | */ | - | ||||||
| 306 | - | |||||||
| 307 | /*! | - | ||||||
| 308 | \fn bool QSizePolicy::hasWidthForHeight() const | - | ||||||
| 309 | - | |||||||
| 310 | Returns \c true if the widget's width depends on its | - | ||||||
| 311 | height; otherwise returns \c false. | - | ||||||
| 312 | - | |||||||
| 313 | \sa setWidthForHeight() | - | ||||||
| 314 | */ | - | ||||||
| 315 | - | |||||||
| 316 | /*! | - | ||||||
| 317 | \fn bool QSizePolicy::operator==(const QSizePolicy &other) const | - | ||||||
| 318 | - | |||||||
| 319 | Returns \c true if this policy is equal to \a other; otherwise | - | ||||||
| 320 | returns \c false. | - | ||||||
| 321 | - | |||||||
| 322 | \sa operator!=() | - | ||||||
| 323 | */ | - | ||||||
| 324 | - | |||||||
| 325 | /*! | - | ||||||
| 326 | \fn bool QSizePolicy::operator!=(const QSizePolicy &other) const | - | ||||||
| 327 | - | |||||||
| 328 | Returns \c true if this policy is different from \a other; otherwise | - | ||||||
| 329 | returns \c false. | - | ||||||
| 330 | - | |||||||
| 331 | \sa operator==() | - | ||||||
| 332 | */ | - | ||||||
| 333 | - | |||||||
| 334 | /*! | - | ||||||
| 335 | \fn uint qHash(QSizePolicy key, uint seed = 0) | - | ||||||
| 336 | \since 5.6 | - | ||||||
| 337 | \relates QSizePolicy | - | ||||||
| 338 | - | |||||||
| 339 | Returns the hash value for \a key, using | - | ||||||
| 340 | \a seed to seed the calculation. | - | ||||||
| 341 | */ | - | ||||||
| 342 | - | |||||||
| 343 | /*! | - | ||||||
| 344 | \fn int QSizePolicy::horizontalStretch() const | - | ||||||
| 345 | - | |||||||
| 346 | Returns the horizontal stretch factor of the size policy. | - | ||||||
| 347 | - | |||||||
| 348 | \sa setHorizontalStretch(), verticalStretch(), horizontalPolicy() | - | ||||||
| 349 | */ | - | ||||||
| 350 | - | |||||||
| 351 | /*! | - | ||||||
| 352 | \fn int QSizePolicy::verticalStretch() const | - | ||||||
| 353 | - | |||||||
| 354 | Returns the vertical stretch factor of the size policy. | - | ||||||
| 355 | - | |||||||
| 356 | \sa setVerticalStretch(), horizontalStretch(), verticalPolicy() | - | ||||||
| 357 | */ | - | ||||||
| 358 | - | |||||||
| 359 | /*! | - | ||||||
| 360 | \fn void QSizePolicy::setHorizontalStretch(int stretchFactor) | - | ||||||
| 361 | - | |||||||
| 362 | Sets the horizontal stretch factor of the size policy to the given \a | - | ||||||
| 363 | stretchFactor. \a stretchFactor must be in the range [0,255]. | - | ||||||
| 364 | - | |||||||
| 365 | When two widgets are adjacent to each other in a horizontal layout, | - | ||||||
| 366 | setting the horizontal stretch factor of the widget on the left to 2 | - | ||||||
| 367 | and the factor of widget on the right to 1 will ensure that the widget | - | ||||||
| 368 | on the left will always be twice the size of the one on the right. | - | ||||||
| 369 | - | |||||||
| 370 | \sa horizontalStretch(), setVerticalStretch(), setHorizontalPolicy() | - | ||||||
| 371 | */ | - | ||||||
| 372 | - | |||||||
| 373 | /*! | - | ||||||
| 374 | \fn void QSizePolicy::setVerticalStretch(int stretchFactor) | - | ||||||
| 375 | - | |||||||
| 376 | Sets the vertical stretch factor of the size policy to the given | - | ||||||
| 377 | \a stretchFactor. \a stretchFactor must be in the range [0,255]. | - | ||||||
| 378 | - | |||||||
| 379 | When two widgets are adjacent to each other in a vertical layout, | - | ||||||
| 380 | setting the vertical stretch factor of the widget on the top to 2 | - | ||||||
| 381 | and the factor of widget on the bottom to 1 will ensure that | - | ||||||
| 382 | the widget on the top will always be twice the size of the one | - | ||||||
| 383 | on the bottom. | - | ||||||
| 384 | - | |||||||
| 385 | \sa verticalStretch(), setHorizontalStretch(), setVerticalPolicy() | - | ||||||
| 386 | */ | - | ||||||
| 387 | - | |||||||
| 388 | /*! | - | ||||||
| 389 | \fn void QSizePolicy::transpose() | - | ||||||
| 390 | - | |||||||
| 391 | Swaps the horizontal and vertical policies and stretches. | - | ||||||
| 392 | */ | - | ||||||
| 393 | - | |||||||
| 394 | /*! | - | ||||||
| 395 | \fn void QSizePolicy::retainSizeWhenHidden() const | - | ||||||
| 396 | \since 5.2 | - | ||||||
| 397 | - | |||||||
| 398 | Returns whether the layout should retain the widget's size when it is hidden. | - | ||||||
| 399 | This is \c false by default. | - | ||||||
| 400 | - | |||||||
| 401 | \sa setRetainSizeWhenHidden() | - | ||||||
| 402 | */ | - | ||||||
| 403 | - | |||||||
| 404 | /*! | - | ||||||
| 405 | \fn void QSizePolicy::setRetainSizeWhenHidden(bool retainSize) | - | ||||||
| 406 | \since 5.2 | - | ||||||
| 407 | - | |||||||
| 408 | Sets whether a layout should retain the widget's size when it is hidden. | - | ||||||
| 409 | If \a retainSize is \c true, the layout will not be changed by hiding the widget. | - | ||||||
| 410 | - | |||||||
| 411 | \sa retainSizeWhenHidden() | - | ||||||
| 412 | */ | - | ||||||
| 413 | - | |||||||
| 414 | /*! | - | ||||||
| 415 | \enum QSizePolicy::ControlType | - | ||||||
| 416 | \since 4.3 | - | ||||||
| 417 | - | |||||||
| 418 | This enum specifies the different types of widgets in terms of | - | ||||||
| 419 | layout interaction: | - | ||||||
| 420 | - | |||||||
| 421 | \value DefaultType The default type, when none is specified. | - | ||||||
| 422 | \value ButtonBox A QDialogButtonBox instance. | - | ||||||
| 423 | \value CheckBox A QCheckBox instance. | - | ||||||
| 424 | \value ComboBox A QComboBox instance. | - | ||||||
| 425 | \value Frame A QFrame instance. | - | ||||||
| 426 | \value GroupBox A QGroupBox instance. | - | ||||||
| 427 | \value Label A QLabel instance. | - | ||||||
| 428 | \value Line A QFrame instance with QFrame::HLine or QFrame::VLine. | - | ||||||
| 429 | \value LineEdit A QLineEdit instance. | - | ||||||
| 430 | \value PushButton A QPushButton instance. | - | ||||||
| 431 | \value RadioButton A QRadioButton instance. | - | ||||||
| 432 | \value Slider A QAbstractSlider instance. | - | ||||||
| 433 | \value SpinBox A QAbstractSpinBox instance. | - | ||||||
| 434 | \value TabWidget A QTabWidget instance. | - | ||||||
| 435 | \value ToolButton A QToolButton instance. | - | ||||||
| 436 | - | |||||||
| 437 | \sa setControlType(), controlType() | - | ||||||
| 438 | */ | - | ||||||
| 439 | - | |||||||
| 440 | /*! | - | ||||||
| 441 | Returns a QVariant storing this QSizePolicy. | - | ||||||
| 442 | */ | - | ||||||
| 443 | QSizePolicy::operator QVariant() const | - | ||||||
| 444 | { | - | ||||||
| 445 | return QVariant(QVariant::SizePolicy, this); never executed: return QVariant(QVariant::SizePolicy, this); | 0 | ||||||
| 446 | } | - | ||||||
| 447 | - | |||||||
| 448 | #ifndef QT_NO_DATASTREAM | - | ||||||
| 449 | - | |||||||
| 450 | /*! | - | ||||||
| 451 | \relates QSizePolicy | - | ||||||
| 452 | \since 4.2 | - | ||||||
| 453 | - | |||||||
| 454 | Writes the size \a policy to the data stream \a stream. | - | ||||||
| 455 | - | |||||||
| 456 | \sa{Serializing Qt Data Types}{Format of the QDataStream operators} | - | ||||||
| 457 | */ | - | ||||||
| 458 | QDataStream &operator<<(QDataStream &stream, const QSizePolicy &policy) | - | ||||||
| 459 | { | - | ||||||
| 460 | // The order here is for historical reasons. (compatibility with Qt4) | - | ||||||
| 461 | quint32 data = (policy.bits.horPolicy | // [0, 3] | - | ||||||
| 462 | policy.bits.verPolicy << 4 | // [4, 7] | - | ||||||
| 463 | policy.bits.hfw << 8 | // [8] | - | ||||||
| 464 | policy.bits.ctype << 9 | // [9, 13] | - | ||||||
| 465 | policy.bits.wfh << 14 | // [14] | - | ||||||
| 466 | policy.bits.retainSizeWhenHidden << 15 | // [15] | - | ||||||
| 467 | policy.bits.verStretch << 16 | // [16, 23] | - | ||||||
| 468 | policy.bits.horStretch << 24); // [24, 31] | - | ||||||
| 469 | return stream << data; never executed: return stream << data; | 0 | ||||||
| 470 | } | - | ||||||
| 471 | - | |||||||
| 472 | #define VALUE_OF_BITS(data, bitstart, bitcount) ((data >> bitstart) & ((1 << bitcount) -1)) | - | ||||||
| 473 | - | |||||||
| 474 | /*! | - | ||||||
| 475 | \relates QSizePolicy | - | ||||||
| 476 | \since 4.2 | - | ||||||
| 477 | - | |||||||
| 478 | Reads the size \a policy from the data stream \a stream. | - | ||||||
| 479 | - | |||||||
| 480 | \sa{Serializing Qt Data Types}{Format of the QDataStream operators} | - | ||||||
| 481 | */ | - | ||||||
| 482 | QDataStream &operator>>(QDataStream &stream, QSizePolicy &policy) | - | ||||||
| 483 | { | - | ||||||
| 484 | quint32 data; | - | ||||||
| 485 | stream >> data; | - | ||||||
| 486 | policy.bits.horPolicy = VALUE_OF_BITS(data, 0, 4); | - | ||||||
| 487 | policy.bits.verPolicy = VALUE_OF_BITS(data, 4, 4); | - | ||||||
| 488 | policy.bits.hfw = VALUE_OF_BITS(data, 8, 1); | - | ||||||
| 489 | policy.bits.ctype = VALUE_OF_BITS(data, 9, 5); | - | ||||||
| 490 | policy.bits.wfh = VALUE_OF_BITS(data, 14, 1); | - | ||||||
| 491 | policy.bits.retainSizeWhenHidden = VALUE_OF_BITS(data, 15, 1); | - | ||||||
| 492 | policy.bits.verStretch = VALUE_OF_BITS(data, 16, 8); | - | ||||||
| 493 | policy.bits.horStretch = VALUE_OF_BITS(data, 24, 8); | - | ||||||
| 494 | return stream; never executed: return stream; | 0 | ||||||
| 495 | } | - | ||||||
| 496 | #endif // QT_NO_DATASTREAM | - | ||||||
| 497 | - | |||||||
| 498 | #ifndef QT_NO_DEBUG_STREAM | - | ||||||
| 499 | QDebug operator<<(QDebug dbg, const QSizePolicy &p) | - | ||||||
| 500 | { | - | ||||||
| 501 | QDebugStateSaver saver(dbg); | - | ||||||
| 502 | dbg.nospace() << "QSizePolicy(horizontalPolicy = " << p.horizontalPolicy() | - | ||||||
| 503 | << ", verticalPolicy = " << p.verticalPolicy() << ')'; | - | ||||||
| 504 | return dbg; never executed: return dbg; | 0 | ||||||
| 505 | } | - | ||||||
| 506 | #endif | - | ||||||
| 507 | - | |||||||
| 508 | QT_END_NAMESPACE | - | ||||||
| 509 | - | |||||||
| 510 | #include "moc_qsizepolicy.cpp" | - | ||||||
| Source code | Switch to Preprocessed file |