| Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/widgets/kernel/qlayout.cpp |
| Source code | Switch to Preprocessed file |
| Line | Source | Count | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | /**************************************************************************** | - | ||||||||||||||||||||||||
| 2 | ** | - | ||||||||||||||||||||||||
| 3 | ** Copyright (C) 2016 The Qt Company Ltd. | - | ||||||||||||||||||||||||
| 4 | ** Contact: https://www.qt.io/licensing/ | - | ||||||||||||||||||||||||
| 5 | ** | - | ||||||||||||||||||||||||
| 6 | ** This file is part of the QtWidgets module of the Qt Toolkit. | - | ||||||||||||||||||||||||
| 7 | ** | - | ||||||||||||||||||||||||
| 8 | ** $QT_BEGIN_LICENSE:LGPL$ | - | ||||||||||||||||||||||||
| 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 https://www.qt.io/terms-conditions. For further | - | ||||||||||||||||||||||||
| 15 | ** information use the contact form at https://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 3 as published by the Free Software | - | ||||||||||||||||||||||||
| 20 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the | - | ||||||||||||||||||||||||
| 21 | ** packaging of this file. Please review the following information to | - | ||||||||||||||||||||||||
| 22 | ** ensure the GNU Lesser General Public License version 3 requirements | - | ||||||||||||||||||||||||
| 23 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. | - | ||||||||||||||||||||||||
| 24 | ** | - | ||||||||||||||||||||||||
| 25 | ** GNU General Public License Usage | - | ||||||||||||||||||||||||
| 26 | ** Alternatively, this file may be used under the terms of the GNU | - | ||||||||||||||||||||||||
| 27 | ** General Public License version 2.0 or (at your option) the GNU General | - | ||||||||||||||||||||||||
| 28 | ** Public license version 3 or any later version approved by the KDE Free | - | ||||||||||||||||||||||||
| 29 | ** Qt Foundation. The licenses are as published by the Free Software | - | ||||||||||||||||||||||||
| 30 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 | - | ||||||||||||||||||||||||
| 31 | ** included in the packaging of this file. Please review the following | - | ||||||||||||||||||||||||
| 32 | ** information to ensure the GNU General Public License requirements will | - | ||||||||||||||||||||||||
| 33 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and | - | ||||||||||||||||||||||||
| 34 | ** https://www.gnu.org/licenses/gpl-3.0.html. | - | ||||||||||||||||||||||||
| 35 | ** | - | ||||||||||||||||||||||||
| 36 | ** $QT_END_LICENSE$ | - | ||||||||||||||||||||||||
| 37 | ** | - | ||||||||||||||||||||||||
| 38 | ****************************************************************************/ | - | ||||||||||||||||||||||||
| 39 | - | |||||||||||||||||||||||||
| 40 | #include "qlayout.h" | - | ||||||||||||||||||||||||
| 41 | - | |||||||||||||||||||||||||
| 42 | #include "qapplication.h" | - | ||||||||||||||||||||||||
| 43 | #include "qlayoutengine_p.h" | - | ||||||||||||||||||||||||
| 44 | #include "qmenubar.h" | - | ||||||||||||||||||||||||
| 45 | #include "qtoolbar.h" | - | ||||||||||||||||||||||||
| 46 | #include "qsizegrip.h" | - | ||||||||||||||||||||||||
| 47 | #include "qevent.h" | - | ||||||||||||||||||||||||
| 48 | #include "qstyle.h" | - | ||||||||||||||||||||||||
| 49 | #include "qvariant.h" | - | ||||||||||||||||||||||||
| 50 | #include "qwidget_p.h" | - | ||||||||||||||||||||||||
| 51 | #include "qlayout_p.h" | - | ||||||||||||||||||||||||
| 52 | #include "qformlayout.h" | - | ||||||||||||||||||||||||
| 53 | - | |||||||||||||||||||||||||
| 54 | QT_BEGIN_NAMESPACE | - | ||||||||||||||||||||||||
| 55 | - | |||||||||||||||||||||||||
| 56 | static int menuBarHeightForWidth(QWidget *menubar, int w) | - | ||||||||||||||||||||||||
| 57 | { | - | ||||||||||||||||||||||||
| 58 | if (menubar && !menubar->isHidden() && !menubar->isWindow()) { | - | ||||||||||||||||||||||||
| 59 | int result = menubar->heightForWidth(qMax(w, menubar->minimumWidth())); | - | ||||||||||||||||||||||||
| 60 | if (result == -1) | - | ||||||||||||||||||||||||
| 61 | result = menubar->sizeHint().height(); | - | ||||||||||||||||||||||||
| 62 | const int min = qSmartMinSize(menubar).height(); | - | ||||||||||||||||||||||||
| 63 | result = qBound(min, result, menubar->maximumSize().height()); | - | ||||||||||||||||||||||||
| 64 | if (result != -1) | - | ||||||||||||||||||||||||
| 65 | return result; | - | ||||||||||||||||||||||||
| 66 | } | - | ||||||||||||||||||||||||
| 67 | return 0; | - | ||||||||||||||||||||||||
| 68 | } | - | ||||||||||||||||||||||||
| 69 | - | |||||||||||||||||||||||||
| 70 | /*! | - | ||||||||||||||||||||||||
| 71 | \class QLayout | - | ||||||||||||||||||||||||
| 72 | \brief The QLayout class is the base class of geometry managers. | - | ||||||||||||||||||||||||
| 73 | - | |||||||||||||||||||||||||
| 74 | \ingroup geomanagement | - | ||||||||||||||||||||||||
| 75 | \inmodule QtWidgets | - | ||||||||||||||||||||||||
| 76 | - | |||||||||||||||||||||||||
| 77 | This is an abstract base class inherited by the concrete classes | - | ||||||||||||||||||||||||
| 78 | QBoxLayout, QGridLayout, QFormLayout, and QStackedLayout. | - | ||||||||||||||||||||||||
| 79 | - | |||||||||||||||||||||||||
| 80 | For users of QLayout subclasses or of QMainWindow there is seldom | - | ||||||||||||||||||||||||
| 81 | any need to use the basic functions provided by QLayout, such as | - | ||||||||||||||||||||||||
| 82 | setSizeConstraint() or setMenuBar(). See \l{Layout Management} | - | ||||||||||||||||||||||||
| 83 | for more information. | - | ||||||||||||||||||||||||
| 84 | - | |||||||||||||||||||||||||
| 85 | To make your own layout manager, implement the functions | - | ||||||||||||||||||||||||
| 86 | addItem(), sizeHint(), setGeometry(), itemAt() and takeAt(). You | - | ||||||||||||||||||||||||
| 87 | should also implement minimumSize() to ensure your layout isn't | - | ||||||||||||||||||||||||
| 88 | resized to zero size if there is too little space. To support | - | ||||||||||||||||||||||||
| 89 | children whose heights depend on their widths, implement | - | ||||||||||||||||||||||||
| 90 | hasHeightForWidth() and heightForWidth(). See the | - | ||||||||||||||||||||||||
| 91 | \l{layouts/borderlayout}{Border Layout} and | - | ||||||||||||||||||||||||
| 92 | \l{layouts/flowlayout}{Flow Layout} examples for | - | ||||||||||||||||||||||||
| 93 | more information about implementing custom layout managers. | - | ||||||||||||||||||||||||
| 94 | - | |||||||||||||||||||||||||
| 95 | Geometry management stops when the layout manager is deleted. | - | ||||||||||||||||||||||||
| 96 | - | |||||||||||||||||||||||||
| 97 | \sa QLayoutItem, {Layout Management}, {Basic Layouts Example}, | - | ||||||||||||||||||||||||
| 98 | {Border Layout Example}, {Flow Layout Example} | - | ||||||||||||||||||||||||
| 99 | */ | - | ||||||||||||||||||||||||
| 100 | - | |||||||||||||||||||||||||
| 101 | - | |||||||||||||||||||||||||
| 102 | /*! | - | ||||||||||||||||||||||||
| 103 | Constructs a new top-level QLayout, with parent \a parent. | - | ||||||||||||||||||||||||
| 104 | \a parent may not be 0. | - | ||||||||||||||||||||||||
| 105 | - | |||||||||||||||||||||||||
| 106 | There can be only one top-level layout for a widget. It is | - | ||||||||||||||||||||||||
| 107 | returned by QWidget::layout(). | - | ||||||||||||||||||||||||
| 108 | */ | - | ||||||||||||||||||||||||
| 109 | QLayout::QLayout(QWidget *parent) | - | ||||||||||||||||||||||||
| 110 | : QObject(*new QLayoutPrivate, parent) | - | ||||||||||||||||||||||||
| 111 | { | - | ||||||||||||||||||||||||
| 112 | if (!parent) | - | ||||||||||||||||||||||||
| 113 | return; | - | ||||||||||||||||||||||||
| 114 | parent->setLayout(this); | - | ||||||||||||||||||||||||
| 115 | } | - | ||||||||||||||||||||||||
| 116 | - | |||||||||||||||||||||||||
| 117 | /*! | - | ||||||||||||||||||||||||
| 118 | Constructs a new child QLayout. | - | ||||||||||||||||||||||||
| 119 | - | |||||||||||||||||||||||||
| 120 | This layout has to be inserted into another layout before geometry | - | ||||||||||||||||||||||||
| 121 | management will work. | - | ||||||||||||||||||||||||
| 122 | */ | - | ||||||||||||||||||||||||
| 123 | QLayout::QLayout() | - | ||||||||||||||||||||||||
| 124 | : QObject(*new QLayoutPrivate, 0) | - | ||||||||||||||||||||||||
| 125 | { | - | ||||||||||||||||||||||||
| 126 | } | - | ||||||||||||||||||||||||
| 127 | - | |||||||||||||||||||||||||
| 128 | - | |||||||||||||||||||||||||
| 129 | /*! \internal | - | ||||||||||||||||||||||||
| 130 | */ | - | ||||||||||||||||||||||||
| 131 | QLayout::QLayout(QLayoutPrivate &dd, QLayout *lay, QWidget *w) | - | ||||||||||||||||||||||||
| 132 | : QObject(dd, lay ? static_cast<QObject*>(lay) : static_cast<QObject*>(w)) | - | ||||||||||||||||||||||||
| 133 | { | - | ||||||||||||||||||||||||
| 134 | Q_D(QLayout); | - | ||||||||||||||||||||||||
| 135 | if (lay) {
| 0 | ||||||||||||||||||||||||
| 136 | lay->addItem(this); | - | ||||||||||||||||||||||||
| 137 | } else if (w) { never executed: end of block
| 0 | ||||||||||||||||||||||||
| 138 | if (Q_UNLIKELY(w->layout())())) {
| 0 | ||||||||||||||||||||||||
| 139 | qWarning("QLayout: Attempting to add QLayout \"%s\"\"%ls\" to %s \"%s\"\"%ls\", which" | - | ||||||||||||||||||||||||
| 140 | " already has a layout", | - | ||||||||||||||||||||||||
| 141 | qPrintableqUtf16Printable(QObject::objectName()), w->metaObject()->className(), | - | ||||||||||||||||||||||||
| 142 | qUtf16Printable(w->objectName().toLocal8Bit().data());())); | - | ||||||||||||||||||||||||
| 143 | setParent(0); | - | ||||||||||||||||||||||||
| 144 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
| 145 | d->topLevel = true; | - | ||||||||||||||||||||||||
| 146 | w->d_func()->layout = this; | - | ||||||||||||||||||||||||
| 147 | QT_TRY { | - | ||||||||||||||||||||||||
| 148 | invalidate(); | - | ||||||||||||||||||||||||
| 149 | } QT_CATCH(...) { never executed: end of blockdead code: { w->d_func()->layout = 0; qt_noop(); } | - | ||||||||||||||||||||||||
| 150 | w->d_func()->layout = 0; dead code: { w->d_func()->layout = 0; qt_noop(); } | - | ||||||||||||||||||||||||
| 151 | QT_RETHROW; dead code: { w->d_func()->layout = 0; qt_noop(); } | - | ||||||||||||||||||||||||
| 152 | } dead code: { w->d_func()->layout = 0; qt_noop(); } | - | ||||||||||||||||||||||||
| 153 | } | - | ||||||||||||||||||||||||
| 154 | } | - | ||||||||||||||||||||||||
| 155 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 156 | - | |||||||||||||||||||||||||
| 157 | QLayoutPrivate::QLayoutPrivate() | - | ||||||||||||||||||||||||
| 158 | : QObjectPrivate(), insideSpacing(-1), userLeftMargin(-1), userTopMargin(-1), userRightMargin(-1), | - | ||||||||||||||||||||||||
| 159 | userBottomMargin(-1), topLevel(false), enabled(true), activated(true), autoNewChild(false), | - | ||||||||||||||||||||||||
| 160 | constraint(QLayout::SetDefaultConstraint), menubar(0) | - | ||||||||||||||||||||||||
| 161 | { | - | ||||||||||||||||||||||||
| 162 | } | - | ||||||||||||||||||||||||
| 163 | - | |||||||||||||||||||||||||
| 164 | void QLayoutPrivate::getMargin(int *result, int userMargin, QStyle::PixelMetric pm) const | - | ||||||||||||||||||||||||
| 165 | { | - | ||||||||||||||||||||||||
| 166 | if (!result) | - | ||||||||||||||||||||||||
| 167 | return; | - | ||||||||||||||||||||||||
| 168 | - | |||||||||||||||||||||||||
| 169 | Q_Q(const QLayout); | - | ||||||||||||||||||||||||
| 170 | if (userMargin >= 0) { | - | ||||||||||||||||||||||||
| 171 | *result = userMargin; | - | ||||||||||||||||||||||||
| 172 | } else if (!topLevel) { | - | ||||||||||||||||||||||||
| 173 | *result = 0; | - | ||||||||||||||||||||||||
| 174 | } else if (QWidget *pw = q->parentWidget()) { | - | ||||||||||||||||||||||||
| 175 | *result = pw->style()->pixelMetric(pm, 0, pw); | - | ||||||||||||||||||||||||
| 176 | } else { | - | ||||||||||||||||||||||||
| 177 | *result = 0; | - | ||||||||||||||||||||||||
| 178 | } | - | ||||||||||||||||||||||||
| 179 | } | - | ||||||||||||||||||||||||
| 180 | - | |||||||||||||||||||||||||
| 181 | // Static item factory functions that allow for hooking things in Designer | - | ||||||||||||||||||||||||
| 182 | - | |||||||||||||||||||||||||
| 183 | QLayoutPrivate::QWidgetItemFactoryMethod QLayoutPrivate::widgetItemFactoryMethod = 0; | - | ||||||||||||||||||||||||
| 184 | QLayoutPrivate::QSpacerItemFactoryMethod QLayoutPrivate::spacerItemFactoryMethod = 0; | - | ||||||||||||||||||||||||
| 185 | - | |||||||||||||||||||||||||
| 186 | QWidgetItem *QLayoutPrivate::createWidgetItem(const QLayout *layout, QWidget *widget) | - | ||||||||||||||||||||||||
| 187 | { | - | ||||||||||||||||||||||||
| 188 | if (widgetItemFactoryMethod) | - | ||||||||||||||||||||||||
| 189 | if (QWidgetItem *wi = (*widgetItemFactoryMethod)(layout, widget)) | - | ||||||||||||||||||||||||
| 190 | return wi; | - | ||||||||||||||||||||||||
| 191 | return new QWidgetItemV2(widget); | - | ||||||||||||||||||||||||
| 192 | } | - | ||||||||||||||||||||||||
| 193 | - | |||||||||||||||||||||||||
| 194 | QSpacerItem *QLayoutPrivate::createSpacerItem(const QLayout *layout, int w, int h, QSizePolicy::Policy hPolicy, QSizePolicy::Policy vPolicy) | - | ||||||||||||||||||||||||
| 195 | { | - | ||||||||||||||||||||||||
| 196 | if (spacerItemFactoryMethod) | - | ||||||||||||||||||||||||
| 197 | if (QSpacerItem *si = (*spacerItemFactoryMethod)(layout, w, h, hPolicy, vPolicy)) | - | ||||||||||||||||||||||||
| 198 | return si; | - | ||||||||||||||||||||||||
| 199 | return new QSpacerItem(w, h, hPolicy, vPolicy); | - | ||||||||||||||||||||||||
| 200 | } | - | ||||||||||||||||||||||||
| 201 | - | |||||||||||||||||||||||||
| 202 | - | |||||||||||||||||||||||||
| 203 | - | |||||||||||||||||||||||||
| 204 | /*! | - | ||||||||||||||||||||||||
| 205 | \fn void QLayout::addItem(QLayoutItem *item) | - | ||||||||||||||||||||||||
| 206 | - | |||||||||||||||||||||||||
| 207 | Implemented in subclasses to add an \a item. How it is added is | - | ||||||||||||||||||||||||
| 208 | specific to each subclass. | - | ||||||||||||||||||||||||
| 209 | - | |||||||||||||||||||||||||
| 210 | This function is not usually called in application code. To add a widget | - | ||||||||||||||||||||||||
| 211 | to a layout, use the addWidget() function; to add a child layout, use the | - | ||||||||||||||||||||||||
| 212 | addLayout() function provided by the relevant QLayout subclass. | - | ||||||||||||||||||||||||
| 213 | - | |||||||||||||||||||||||||
| 214 | \b{Note:} The ownership of \a item is transferred to the layout, and it's | - | ||||||||||||||||||||||||
| 215 | the layout's responsibility to delete it. | - | ||||||||||||||||||||||||
| 216 | - | |||||||||||||||||||||||||
| 217 | \sa addWidget(), QBoxLayout::addLayout(), QGridLayout::addLayout() | - | ||||||||||||||||||||||||
| 218 | */ | - | ||||||||||||||||||||||||
| 219 | - | |||||||||||||||||||||||||
| 220 | /*! | - | ||||||||||||||||||||||||
| 221 | Adds widget \a w to this layout in a manner specific to the | - | ||||||||||||||||||||||||
| 222 | layout. This function uses addItem(). | - | ||||||||||||||||||||||||
| 223 | */ | - | ||||||||||||||||||||||||
| 224 | void QLayout::addWidget(QWidget *w) | - | ||||||||||||||||||||||||
| 225 | { | - | ||||||||||||||||||||||||
| 226 | addChildWidget(w); | - | ||||||||||||||||||||||||
| 227 | addItem(QLayoutPrivate::createWidgetItem(this, w)); | - | ||||||||||||||||||||||||
| 228 | } | - | ||||||||||||||||||||||||
| 229 | - | |||||||||||||||||||||||||
| 230 | - | |||||||||||||||||||||||||
| 231 | - | |||||||||||||||||||||||||
| 232 | /*! | - | ||||||||||||||||||||||||
| 233 | Sets the alignment for widget \a w to \a alignment and returns | - | ||||||||||||||||||||||||
| 234 | true if \a w is found in this layout (not including child | - | ||||||||||||||||||||||||
| 235 | layouts); otherwise returns \c false. | - | ||||||||||||||||||||||||
| 236 | */ | - | ||||||||||||||||||||||||
| 237 | bool QLayout::setAlignment(QWidget *w, Qt::Alignment alignment) | - | ||||||||||||||||||||||||
| 238 | { | - | ||||||||||||||||||||||||
| 239 | int i = 0; | - | ||||||||||||||||||||||||
| 240 | QLayoutItem *item = itemAt(i); | - | ||||||||||||||||||||||||
| 241 | while (item) { | - | ||||||||||||||||||||||||
| 242 | if (item->widget() == w) { | - | ||||||||||||||||||||||||
| 243 | item->setAlignment(alignment); | - | ||||||||||||||||||||||||
| 244 | invalidate(); | - | ||||||||||||||||||||||||
| 245 | return true; | - | ||||||||||||||||||||||||
| 246 | } | - | ||||||||||||||||||||||||
| 247 | ++i; | - | ||||||||||||||||||||||||
| 248 | item = itemAt(i); | - | ||||||||||||||||||||||||
| 249 | } | - | ||||||||||||||||||||||||
| 250 | return false; | - | ||||||||||||||||||||||||
| 251 | } | - | ||||||||||||||||||||||||
| 252 | - | |||||||||||||||||||||||||
| 253 | /*! | - | ||||||||||||||||||||||||
| 254 | \overload | - | ||||||||||||||||||||||||
| 255 | - | |||||||||||||||||||||||||
| 256 | Sets the alignment for the layout \a l to \a alignment and | - | ||||||||||||||||||||||||
| 257 | returns \c true if \a l is found in this layout (not including child | - | ||||||||||||||||||||||||
| 258 | layouts); otherwise returns \c false. | - | ||||||||||||||||||||||||
| 259 | */ | - | ||||||||||||||||||||||||
| 260 | bool QLayout::setAlignment(QLayout *l, Qt::Alignment alignment) | - | ||||||||||||||||||||||||
| 261 | { | - | ||||||||||||||||||||||||
| 262 | int i = 0; | - | ||||||||||||||||||||||||
| 263 | QLayoutItem *item = itemAt(i); | - | ||||||||||||||||||||||||
| 264 | while (item) { | - | ||||||||||||||||||||||||
| 265 | if (item->layout() == l) { | - | ||||||||||||||||||||||||
| 266 | item->setAlignment(alignment); | - | ||||||||||||||||||||||||
| 267 | invalidate(); | - | ||||||||||||||||||||||||
| 268 | return true; | - | ||||||||||||||||||||||||
| 269 | } | - | ||||||||||||||||||||||||
| 270 | ++i; | - | ||||||||||||||||||||||||
| 271 | item = itemAt(i); | - | ||||||||||||||||||||||||
| 272 | } | - | ||||||||||||||||||||||||
| 273 | return false; | - | ||||||||||||||||||||||||
| 274 | } | - | ||||||||||||||||||||||||
| 275 | - | |||||||||||||||||||||||||
| 276 | /*! | - | ||||||||||||||||||||||||
| 277 | \property QLayout::margin | - | ||||||||||||||||||||||||
| 278 | \brief the width of the outside border of the layout | - | ||||||||||||||||||||||||
| 279 | \obsolete | - | ||||||||||||||||||||||||
| 280 | - | |||||||||||||||||||||||||
| 281 | Use setContentsMargins() and getContentsMargins() instead. | - | ||||||||||||||||||||||||
| 282 | - | |||||||||||||||||||||||||
| 283 | \sa contentsRect(), spacing | - | ||||||||||||||||||||||||
| 284 | */ | - | ||||||||||||||||||||||||
| 285 | - | |||||||||||||||||||||||||
| 286 | /*! | - | ||||||||||||||||||||||||
| 287 | \obsolete | - | ||||||||||||||||||||||||
| 288 | */ | - | ||||||||||||||||||||||||
| 289 | int QLayout::margin() const | - | ||||||||||||||||||||||||
| 290 | { | - | ||||||||||||||||||||||||
| 291 | int left, top, right, bottom; | - | ||||||||||||||||||||||||
| 292 | getContentsMargins(&left, &top, &right, &bottom); | - | ||||||||||||||||||||||||
| 293 | if (left == top && top == right && right == bottom) { | - | ||||||||||||||||||||||||
| 294 | return left; | - | ||||||||||||||||||||||||
| 295 | } else { | - | ||||||||||||||||||||||||
| 296 | return -1; | - | ||||||||||||||||||||||||
| 297 | } | - | ||||||||||||||||||||||||
| 298 | } | - | ||||||||||||||||||||||||
| 299 | - | |||||||||||||||||||||||||
| 300 | /*! | - | ||||||||||||||||||||||||
| 301 | \property QLayout::spacing | - | ||||||||||||||||||||||||
| 302 | \brief the spacing between widgets inside the layout | - | ||||||||||||||||||||||||
| 303 | - | |||||||||||||||||||||||||
| 304 | If no value is explicitly set, the layout's spacing is inherited | - | ||||||||||||||||||||||||
| 305 | from the parent layout, or from the style settings for the parent | - | ||||||||||||||||||||||||
| 306 | widget. | - | ||||||||||||||||||||||||
| 307 | - | |||||||||||||||||||||||||
| 308 | For QGridLayout and QFormLayout, it is possible to set different horizontal and | - | ||||||||||||||||||||||||
| 309 | vertical spacings using \l{QGridLayout::}{setHorizontalSpacing()} | - | ||||||||||||||||||||||||
| 310 | and \l{QGridLayout::}{setVerticalSpacing()}. In that case, | - | ||||||||||||||||||||||||
| 311 | spacing() returns -1. | - | ||||||||||||||||||||||||
| 312 | - | |||||||||||||||||||||||||
| 313 | \sa contentsRect(), getContentsMargins(), QStyle::layoutSpacing(), | - | ||||||||||||||||||||||||
| 314 | QStyle::pixelMetric() | - | ||||||||||||||||||||||||
| 315 | */ | - | ||||||||||||||||||||||||
| 316 | - | |||||||||||||||||||||||||
| 317 | int QLayout::spacing() const | - | ||||||||||||||||||||||||
| 318 | { | - | ||||||||||||||||||||||||
| 319 | if (const QBoxLayout* boxlayout = qobject_cast<const QBoxLayout*>(this)) { | - | ||||||||||||||||||||||||
| 320 | return boxlayout->spacing(); | - | ||||||||||||||||||||||||
| 321 | } else if (const QGridLayout* gridlayout = qobject_cast<const QGridLayout*>(this)) { | - | ||||||||||||||||||||||||
| 322 | return gridlayout->spacing(); | - | ||||||||||||||||||||||||
| 323 | } else if (const QFormLayout* formlayout = qobject_cast<const QFormLayout*>(this)) { | - | ||||||||||||||||||||||||
| 324 | return formlayout->spacing(); | - | ||||||||||||||||||||||||
| 325 | } else { | - | ||||||||||||||||||||||||
| 326 | Q_D(const QLayout); | - | ||||||||||||||||||||||||
| 327 | if (d->insideSpacing >=0) { | - | ||||||||||||||||||||||||
| 328 | return d->insideSpacing; | - | ||||||||||||||||||||||||
| 329 | } else { | - | ||||||||||||||||||||||||
| 330 | // arbitrarily prefer horizontal spacing to vertical spacing | - | ||||||||||||||||||||||||
| 331 | return qSmartSpacing(this, QStyle::PM_LayoutHorizontalSpacing); | - | ||||||||||||||||||||||||
| 332 | } | - | ||||||||||||||||||||||||
| 333 | } | - | ||||||||||||||||||||||||
| 334 | } | - | ||||||||||||||||||||||||
| 335 | - | |||||||||||||||||||||||||
| 336 | /*! | - | ||||||||||||||||||||||||
| 337 | \obsolete | - | ||||||||||||||||||||||||
| 338 | */ | - | ||||||||||||||||||||||||
| 339 | void QLayout::setMargin(int margin) | - | ||||||||||||||||||||||||
| 340 | { | - | ||||||||||||||||||||||||
| 341 | setContentsMargins(margin, margin, margin, margin); | - | ||||||||||||||||||||||||
| 342 | } | - | ||||||||||||||||||||||||
| 343 | - | |||||||||||||||||||||||||
| 344 | void QLayout::setSpacing(int spacing) | - | ||||||||||||||||||||||||
| 345 | { | - | ||||||||||||||||||||||||
| 346 | if (QBoxLayout* boxlayout = qobject_cast<QBoxLayout*>(this)) { | - | ||||||||||||||||||||||||
| 347 | boxlayout->setSpacing(spacing); | - | ||||||||||||||||||||||||
| 348 | } else if (QGridLayout* gridlayout = qobject_cast<QGridLayout*>(this)) { | - | ||||||||||||||||||||||||
| 349 | gridlayout->setSpacing(spacing); | - | ||||||||||||||||||||||||
| 350 | } else if (QFormLayout* formlayout = qobject_cast<QFormLayout*>(this)) { | - | ||||||||||||||||||||||||
| 351 | formlayout->setSpacing(spacing); | - | ||||||||||||||||||||||||
| 352 | } else { | - | ||||||||||||||||||||||||
| 353 | Q_D(QLayout); | - | ||||||||||||||||||||||||
| 354 | d->insideSpacing = spacing; | - | ||||||||||||||||||||||||
| 355 | invalidate(); | - | ||||||||||||||||||||||||
| 356 | } | - | ||||||||||||||||||||||||
| 357 | } | - | ||||||||||||||||||||||||
| 358 | - | |||||||||||||||||||||||||
| 359 | /*! | - | ||||||||||||||||||||||||
| 360 | \since 4.3 | - | ||||||||||||||||||||||||
| 361 | - | |||||||||||||||||||||||||
| 362 | Sets the \a left, \a top, \a right, and \a bottom margins to use | - | ||||||||||||||||||||||||
| 363 | around the layout. | - | ||||||||||||||||||||||||
| 364 | - | |||||||||||||||||||||||||
| 365 | By default, QLayout uses the values provided by the style. On | - | ||||||||||||||||||||||||
| 366 | most platforms, the margin is 11 pixels in all directions. | - | ||||||||||||||||||||||||
| 367 | - | |||||||||||||||||||||||||
| 368 | \sa getContentsMargins(), QStyle::pixelMetric(), | - | ||||||||||||||||||||||||
| 369 | {QStyle::}{PM_LayoutLeftMargin}, | - | ||||||||||||||||||||||||
| 370 | {QStyle::}{PM_LayoutTopMargin}, | - | ||||||||||||||||||||||||
| 371 | {QStyle::}{PM_LayoutRightMargin}, | - | ||||||||||||||||||||||||
| 372 | {QStyle::}{PM_LayoutBottomMargin} | - | ||||||||||||||||||||||||
| 373 | */ | - | ||||||||||||||||||||||||
| 374 | void QLayout::setContentsMargins(int left, int top, int right, int bottom) | - | ||||||||||||||||||||||||
| 375 | { | - | ||||||||||||||||||||||||
| 376 | Q_D(QLayout); | - | ||||||||||||||||||||||||
| 377 | - | |||||||||||||||||||||||||
| 378 | if (d->userLeftMargin == left && d->userTopMargin == top && | - | ||||||||||||||||||||||||
| 379 | d->userRightMargin == right && d->userBottomMargin == bottom) | - | ||||||||||||||||||||||||
| 380 | return; | - | ||||||||||||||||||||||||
| 381 | - | |||||||||||||||||||||||||
| 382 | d->userLeftMargin = left; | - | ||||||||||||||||||||||||
| 383 | d->userTopMargin = top; | - | ||||||||||||||||||||||||
| 384 | d->userRightMargin = right; | - | ||||||||||||||||||||||||
| 385 | d->userBottomMargin = bottom; | - | ||||||||||||||||||||||||
| 386 | invalidate(); | - | ||||||||||||||||||||||||
| 387 | } | - | ||||||||||||||||||||||||
| 388 | - | |||||||||||||||||||||||||
| 389 | /*! | - | ||||||||||||||||||||||||
| 390 | \since 4.6 | - | ||||||||||||||||||||||||
| 391 | - | |||||||||||||||||||||||||
| 392 | Sets the \a margins to use around the layout. | - | ||||||||||||||||||||||||
| 393 | - | |||||||||||||||||||||||||
| 394 | By default, QLayout uses the values provided by the style. On | - | ||||||||||||||||||||||||
| 395 | most platforms, the margin is 11 pixels in all directions. | - | ||||||||||||||||||||||||
| 396 | - | |||||||||||||||||||||||||
| 397 | \sa contentsMargins() | - | ||||||||||||||||||||||||
| 398 | */ | - | ||||||||||||||||||||||||
| 399 | void QLayout::setContentsMargins(const QMargins &margins) | - | ||||||||||||||||||||||||
| 400 | { | - | ||||||||||||||||||||||||
| 401 | setContentsMargins(margins.left(), margins.top(), margins.right(), margins.bottom()); | - | ||||||||||||||||||||||||
| 402 | } | - | ||||||||||||||||||||||||
| 403 | - | |||||||||||||||||||||||||
| 404 | /*! | - | ||||||||||||||||||||||||
| 405 | \since 4.3 | - | ||||||||||||||||||||||||
| 406 | - | |||||||||||||||||||||||||
| 407 | Extracts the left, top, right, and bottom margins used around the | - | ||||||||||||||||||||||||
| 408 | layout, and assigns them to *\a left, *\a top, *\a right, and *\a | - | ||||||||||||||||||||||||
| 409 | bottom (unless they are null pointers). | - | ||||||||||||||||||||||||
| 410 | - | |||||||||||||||||||||||||
| 411 | By default, QLayout uses the values provided by the style. On | - | ||||||||||||||||||||||||
| 412 | most platforms, the margin is 11 pixels in all directions. | - | ||||||||||||||||||||||||
| 413 | - | |||||||||||||||||||||||||
| 414 | \sa setContentsMargins(), QStyle::pixelMetric(), | - | ||||||||||||||||||||||||
| 415 | {QStyle::}{PM_LayoutLeftMargin}, | - | ||||||||||||||||||||||||
| 416 | {QStyle::}{PM_LayoutTopMargin}, | - | ||||||||||||||||||||||||
| 417 | {QStyle::}{PM_LayoutRightMargin}, | - | ||||||||||||||||||||||||
| 418 | {QStyle::}{PM_LayoutBottomMargin} | - | ||||||||||||||||||||||||
| 419 | */ | - | ||||||||||||||||||||||||
| 420 | void QLayout::getContentsMargins(int *left, int *top, int *right, int *bottom) const | - | ||||||||||||||||||||||||
| 421 | { | - | ||||||||||||||||||||||||
| 422 | Q_D(const QLayout); | - | ||||||||||||||||||||||||
| 423 | d->getMargin(left, d->userLeftMargin, QStyle::PM_LayoutLeftMargin); | - | ||||||||||||||||||||||||
| 424 | d->getMargin(top, d->userTopMargin, QStyle::PM_LayoutTopMargin); | - | ||||||||||||||||||||||||
| 425 | d->getMargin(right, d->userRightMargin, QStyle::PM_LayoutRightMargin); | - | ||||||||||||||||||||||||
| 426 | d->getMargin(bottom, d->userBottomMargin, QStyle::PM_LayoutBottomMargin); | - | ||||||||||||||||||||||||
| 427 | } | - | ||||||||||||||||||||||||
| 428 | - | |||||||||||||||||||||||||
| 429 | /*! | - | ||||||||||||||||||||||||
| 430 | \since 4.6 | - | ||||||||||||||||||||||||
| 431 | - | |||||||||||||||||||||||||
| 432 | Returns the margins used around the layout. | - | ||||||||||||||||||||||||
| 433 | - | |||||||||||||||||||||||||
| 434 | By default, QLayout uses the values provided by the style. On | - | ||||||||||||||||||||||||
| 435 | most platforms, the margin is 11 pixels in all directions. | - | ||||||||||||||||||||||||
| 436 | - | |||||||||||||||||||||||||
| 437 | \sa setContentsMargins() | - | ||||||||||||||||||||||||
| 438 | */ | - | ||||||||||||||||||||||||
| 439 | QMargins QLayout::contentsMargins() const | - | ||||||||||||||||||||||||
| 440 | { | - | ||||||||||||||||||||||||
| 441 | int left, top, right, bottom; | - | ||||||||||||||||||||||||
| 442 | getContentsMargins(&left, &top, &right, &bottom); | - | ||||||||||||||||||||||||
| 443 | return QMargins(left, top, right, bottom); | - | ||||||||||||||||||||||||
| 444 | } | - | ||||||||||||||||||||||||
| 445 | - | |||||||||||||||||||||||||
| 446 | /*! | - | ||||||||||||||||||||||||
| 447 | \since 4.3 | - | ||||||||||||||||||||||||
| 448 | - | |||||||||||||||||||||||||
| 449 | Returns the layout's geometry() rectangle, but taking into account the | - | ||||||||||||||||||||||||
| 450 | contents margins. | - | ||||||||||||||||||||||||
| 451 | - | |||||||||||||||||||||||||
| 452 | \sa setContentsMargins(), getContentsMargins() | - | ||||||||||||||||||||||||
| 453 | */ | - | ||||||||||||||||||||||||
| 454 | QRect QLayout::contentsRect() const | - | ||||||||||||||||||||||||
| 455 | { | - | ||||||||||||||||||||||||
| 456 | Q_D(const QLayout); | - | ||||||||||||||||||||||||
| 457 | int left, top, right, bottom; | - | ||||||||||||||||||||||||
| 458 | getContentsMargins(&left, &top, &right, &bottom); | - | ||||||||||||||||||||||||
| 459 | return d->rect.adjusted(+left, +top, -right, -bottom); | - | ||||||||||||||||||||||||
| 460 | } | - | ||||||||||||||||||||||||
| 461 | - | |||||||||||||||||||||||||
| 462 | - | |||||||||||||||||||||||||
| 463 | /*! | - | ||||||||||||||||||||||||
| 464 | Returns the parent widget of this layout, or 0 if this layout is | - | ||||||||||||||||||||||||
| 465 | not installed on any widget. | - | ||||||||||||||||||||||||
| 466 | - | |||||||||||||||||||||||||
| 467 | If the layout is a sub-layout, this function returns the parent | - | ||||||||||||||||||||||||
| 468 | widget of the parent layout. | - | ||||||||||||||||||||||||
| 469 | - | |||||||||||||||||||||||||
| 470 | \sa parent() | - | ||||||||||||||||||||||||
| 471 | */ | - | ||||||||||||||||||||||||
| 472 | QWidget *QLayout::parentWidget() const | - | ||||||||||||||||||||||||
| 473 | { | - | ||||||||||||||||||||||||
| 474 | Q_D(const QLayout); | - | ||||||||||||||||||||||||
| 475 | if (!d->topLevel) {
| 0 | ||||||||||||||||||||||||
| 476 | if (parent()) {
| 0 | ||||||||||||||||||||||||
| 477 | QLayout *parentLayout = qobject_cast<QLayout*>(parent()); | - | ||||||||||||||||||||||||
| 478 | if (Q_UNLIKELY(!parentLayout))) {
| 0 | ||||||||||||||||||||||||
| 479 | qWarning("QLayout::parentWidget: A layout can only have another layout as a parent."); | - | ||||||||||||||||||||||||
| 480 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
| 481 | } | - | ||||||||||||||||||||||||
| 482 | return parentLayout->parentWidget(); never executed: return parentLayout->parentWidget(); | 0 | ||||||||||||||||||||||||
| 483 | } else { | - | ||||||||||||||||||||||||
| 484 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
| 485 | } | - | ||||||||||||||||||||||||
| 486 | } else { | - | ||||||||||||||||||||||||
| 487 | Q_ASSERT(parent() && parent()->isWidgetType()); | - | ||||||||||||||||||||||||
| 488 | return static_cast<QWidget *>(parent()); never executed: return static_cast<QWidget *>(parent()); | 0 | ||||||||||||||||||||||||
| 489 | } | - | ||||||||||||||||||||||||
| 490 | } | - | ||||||||||||||||||||||||
| 491 | - | |||||||||||||||||||||||||
| 492 | /*! | - | ||||||||||||||||||||||||
| 493 | \reimp | - | ||||||||||||||||||||||||
| 494 | */ | - | ||||||||||||||||||||||||
| 495 | bool QLayout::isEmpty() const | - | ||||||||||||||||||||||||
| 496 | { | - | ||||||||||||||||||||||||
| 497 | int i = 0; | - | ||||||||||||||||||||||||
| 498 | QLayoutItem *item = itemAt(i); | - | ||||||||||||||||||||||||
| 499 | while (item) { | - | ||||||||||||||||||||||||
| 500 | if (!item->isEmpty()) | - | ||||||||||||||||||||||||
| 501 | return false; | - | ||||||||||||||||||||||||
| 502 | ++i; | - | ||||||||||||||||||||||||
| 503 | item = itemAt(i); | - | ||||||||||||||||||||||||
| 504 | } | - | ||||||||||||||||||||||||
| 505 | return true; | - | ||||||||||||||||||||||||
| 506 | } | - | ||||||||||||||||||||||||
| 507 | - | |||||||||||||||||||||||||
| 508 | /*! | - | ||||||||||||||||||||||||
| 509 | \reimp | - | ||||||||||||||||||||||||
| 510 | */ | - | ||||||||||||||||||||||||
| 511 | QSizePolicy::ControlTypes QLayout::controlTypes() const | - | ||||||||||||||||||||||||
| 512 | { | - | ||||||||||||||||||||||||
| 513 | if (count() == 0) | - | ||||||||||||||||||||||||
| 514 | return QSizePolicy::DefaultType; | - | ||||||||||||||||||||||||
| 515 | QSizePolicy::ControlTypes types; | - | ||||||||||||||||||||||||
| 516 | for (int i = count() - 1; i >= 0; --i) | - | ||||||||||||||||||||||||
| 517 | types |= itemAt(i)->controlTypes(); | - | ||||||||||||||||||||||||
| 518 | return types; | - | ||||||||||||||||||||||||
| 519 | } | - | ||||||||||||||||||||||||
| 520 | - | |||||||||||||||||||||||||
| 521 | /*! | - | ||||||||||||||||||||||||
| 522 | \reimp | - | ||||||||||||||||||||||||
| 523 | */ | - | ||||||||||||||||||||||||
| 524 | void QLayout::setGeometry(const QRect &r) | - | ||||||||||||||||||||||||
| 525 | { | - | ||||||||||||||||||||||||
| 526 | Q_D(QLayout); | - | ||||||||||||||||||||||||
| 527 | d->rect = r; | - | ||||||||||||||||||||||||
| 528 | } | - | ||||||||||||||||||||||||
| 529 | - | |||||||||||||||||||||||||
| 530 | /*! | - | ||||||||||||||||||||||||
| 531 | \reimp | - | ||||||||||||||||||||||||
| 532 | */ | - | ||||||||||||||||||||||||
| 533 | QRect QLayout::geometry() const | - | ||||||||||||||||||||||||
| 534 | { | - | ||||||||||||||||||||||||
| 535 | Q_D(const QLayout); | - | ||||||||||||||||||||||||
| 536 | return d->rect; | - | ||||||||||||||||||||||||
| 537 | } | - | ||||||||||||||||||||||||
| 538 | - | |||||||||||||||||||||||||
| 539 | /*! | - | ||||||||||||||||||||||||
| 540 | \reimp | - | ||||||||||||||||||||||||
| 541 | */ | - | ||||||||||||||||||||||||
| 542 | void QLayout::invalidate() | - | ||||||||||||||||||||||||
| 543 | { | - | ||||||||||||||||||||||||
| 544 | Q_D(QLayout); | - | ||||||||||||||||||||||||
| 545 | d->rect = QRect(); | - | ||||||||||||||||||||||||
| 546 | update(); | - | ||||||||||||||||||||||||
| 547 | } | - | ||||||||||||||||||||||||
| 548 | - | |||||||||||||||||||||||||
| 549 | static bool removeWidgetRecursively(QLayoutItem *li, QObject *w) | - | ||||||||||||||||||||||||
| 550 | { | - | ||||||||||||||||||||||||
| 551 | QLayout *lay = li->layout(); | - | ||||||||||||||||||||||||
| 552 | if (!lay) | - | ||||||||||||||||||||||||
| 553 | return false; | - | ||||||||||||||||||||||||
| 554 | int i = 0; | - | ||||||||||||||||||||||||
| 555 | QLayoutItem *child; | - | ||||||||||||||||||||||||
| 556 | while ((child = lay->itemAt(i))) { | - | ||||||||||||||||||||||||
| 557 | if (child->widget() == w) { | - | ||||||||||||||||||||||||
| 558 | delete lay->takeAt(i); | - | ||||||||||||||||||||||||
| 559 | lay->invalidate(); | - | ||||||||||||||||||||||||
| 560 | return true; | - | ||||||||||||||||||||||||
| 561 | } else if (removeWidgetRecursively(child, w)) { | - | ||||||||||||||||||||||||
| 562 | return true; | - | ||||||||||||||||||||||||
| 563 | } else { | - | ||||||||||||||||||||||||
| 564 | ++i; | - | ||||||||||||||||||||||||
| 565 | } | - | ||||||||||||||||||||||||
| 566 | } | - | ||||||||||||||||||||||||
| 567 | return false; | - | ||||||||||||||||||||||||
| 568 | } | - | ||||||||||||||||||||||||
| 569 | - | |||||||||||||||||||||||||
| 570 | - | |||||||||||||||||||||||||
| 571 | void QLayoutPrivate::doResize(const QSize &r) | - | ||||||||||||||||||||||||
| 572 | { | - | ||||||||||||||||||||||||
| 573 | Q_Q(QLayout); | - | ||||||||||||||||||||||||
| 574 | int mbh = menuBarHeightForWidth(menubar, r.width()); | - | ||||||||||||||||||||||||
| 575 | QWidget *mw = q->parentWidget(); | - | ||||||||||||||||||||||||
| 576 | QRect rect = mw->testAttribute(Qt::WA_LayoutOnEntireRect) ? mw->rect() : mw->contentsRect(); | - | ||||||||||||||||||||||||
| 577 | const int mbTop = rect.top(); | - | ||||||||||||||||||||||||
| 578 | rect.setTop(rect.top() + mbh); | - | ||||||||||||||||||||||||
| 579 | q->setGeometry(rect); | - | ||||||||||||||||||||||||
| 580 | #ifndef QT_NO_MENUBAR | - | ||||||||||||||||||||||||
| 581 | if (menubar) | - | ||||||||||||||||||||||||
| 582 | menubar->setGeometry(rect.left(), mbTop, r.width(), mbh); | - | ||||||||||||||||||||||||
| 583 | #endif | - | ||||||||||||||||||||||||
| 584 | } | - | ||||||||||||||||||||||||
| 585 | - | |||||||||||||||||||||||||
| 586 | - | |||||||||||||||||||||||||
| 587 | /*! | - | ||||||||||||||||||||||||
| 588 | \internal | - | ||||||||||||||||||||||||
| 589 | Performs child widget layout when the parent widget is | - | ||||||||||||||||||||||||
| 590 | resized. Also handles removal of widgets. \a e is the | - | ||||||||||||||||||||||||
| 591 | event | - | ||||||||||||||||||||||||
| 592 | */ | - | ||||||||||||||||||||||||
| 593 | void QLayout::widgetEvent(QEvent *e) | - | ||||||||||||||||||||||||
| 594 | { | - | ||||||||||||||||||||||||
| 595 | Q_D(QLayout); | - | ||||||||||||||||||||||||
| 596 | if (!d->enabled) | - | ||||||||||||||||||||||||
| 597 | return; | - | ||||||||||||||||||||||||
| 598 | - | |||||||||||||||||||||||||
| 599 | switch (e->type()) { | - | ||||||||||||||||||||||||
| 600 | case QEvent::Resize: | - | ||||||||||||||||||||||||
| 601 | if (d->activated) { | - | ||||||||||||||||||||||||
| 602 | QResizeEvent *r = (QResizeEvent *)e; | - | ||||||||||||||||||||||||
| 603 | d->doResize(r->size()); | - | ||||||||||||||||||||||||
| 604 | } else { | - | ||||||||||||||||||||||||
| 605 | activate(); | - | ||||||||||||||||||||||||
| 606 | } | - | ||||||||||||||||||||||||
| 607 | break; | - | ||||||||||||||||||||||||
| 608 | case QEvent::ChildRemoved: | - | ||||||||||||||||||||||||
| 609 | { | - | ||||||||||||||||||||||||
| 610 | QChildEvent *c = (QChildEvent *)e; | - | ||||||||||||||||||||||||
| 611 | if (c->child()->isWidgetType()) { | - | ||||||||||||||||||||||||
| 612 | #ifndef QT_NO_MENUBAR | - | ||||||||||||||||||||||||
| 613 | if (c->child() == d->menubar) | - | ||||||||||||||||||||||||
| 614 | d->menubar = 0; | - | ||||||||||||||||||||||||
| 615 | #endif | - | ||||||||||||||||||||||||
| 616 | removeWidgetRecursively(this, c->child()); | - | ||||||||||||||||||||||||
| 617 | } | - | ||||||||||||||||||||||||
| 618 | } | - | ||||||||||||||||||||||||
| 619 | break; | - | ||||||||||||||||||||||||
| 620 | case QEvent::LayoutRequest: | - | ||||||||||||||||||||||||
| 621 | if (static_cast<QWidget *>(parent())->isVisible()) | - | ||||||||||||||||||||||||
| 622 | activate(); | - | ||||||||||||||||||||||||
| 623 | break; | - | ||||||||||||||||||||||||
| 624 | default: | - | ||||||||||||||||||||||||
| 625 | break; | - | ||||||||||||||||||||||||
| 626 | } | - | ||||||||||||||||||||||||
| 627 | } | - | ||||||||||||||||||||||||
| 628 | - | |||||||||||||||||||||||||
| 629 | /*! | - | ||||||||||||||||||||||||
| 630 | \reimp | - | ||||||||||||||||||||||||
| 631 | */ | - | ||||||||||||||||||||||||
| 632 | void QLayout::childEvent(QChildEvent *e) | - | ||||||||||||||||||||||||
| 633 | { | - | ||||||||||||||||||||||||
| 634 | Q_D(QLayout); | - | ||||||||||||||||||||||||
| 635 | if (!d->enabled) | - | ||||||||||||||||||||||||
| 636 | return; | - | ||||||||||||||||||||||||
| 637 | - | |||||||||||||||||||||||||
| 638 | if (e->type() == QEvent::ChildRemoved) { | - | ||||||||||||||||||||||||
| 639 | QChildEvent *c = (QChildEvent*)e; | - | ||||||||||||||||||||||||
| 640 | int i = 0; | - | ||||||||||||||||||||||||
| 641 | - | |||||||||||||||||||||||||
| 642 | QLayoutItem *item; | - | ||||||||||||||||||||||||
| 643 | while ((item = itemAt(i))) { | - | ||||||||||||||||||||||||
| 644 | if (item == static_cast<QLayout*>(c->child())) { | - | ||||||||||||||||||||||||
| 645 | takeAt(i); | - | ||||||||||||||||||||||||
| 646 | invalidate(); | - | ||||||||||||||||||||||||
| 647 | break; | - | ||||||||||||||||||||||||
| 648 | } else { | - | ||||||||||||||||||||||||
| 649 | ++i; | - | ||||||||||||||||||||||||
| 650 | } | - | ||||||||||||||||||||||||
| 651 | } | - | ||||||||||||||||||||||||
| 652 | } | - | ||||||||||||||||||||||||
| 653 | } | - | ||||||||||||||||||||||||
| 654 | - | |||||||||||||||||||||||||
| 655 | /*! | - | ||||||||||||||||||||||||
| 656 | \internal | - | ||||||||||||||||||||||||
| 657 | Also takes contentsMargins and menu bar into account. | - | ||||||||||||||||||||||||
| 658 | */ | - | ||||||||||||||||||||||||
| 659 | int QLayout::totalHeightForWidth(int w) const | - | ||||||||||||||||||||||||
| 660 | { | - | ||||||||||||||||||||||||
| 661 | Q_D(const QLayout); | - | ||||||||||||||||||||||||
| 662 | int side=0, top=0; | - | ||||||||||||||||||||||||
| 663 | if (d->topLevel) { | - | ||||||||||||||||||||||||
| 664 | QWidget *parent = parentWidget(); | - | ||||||||||||||||||||||||
| 665 | parent->ensurePolished(); | - | ||||||||||||||||||||||||
| 666 | QWidgetPrivate *wd = parent->d_func(); | - | ||||||||||||||||||||||||
| 667 | side += wd->leftmargin + wd->rightmargin; | - | ||||||||||||||||||||||||
| 668 | top += wd->topmargin + wd->bottommargin; | - | ||||||||||||||||||||||||
| 669 | } | - | ||||||||||||||||||||||||
| 670 | int h = heightForWidth(w - side) + top; | - | ||||||||||||||||||||||||
| 671 | #ifndef QT_NO_MENUBAR | - | ||||||||||||||||||||||||
| 672 | h += menuBarHeightForWidth(d->menubar, w); | - | ||||||||||||||||||||||||
| 673 | #endif | - | ||||||||||||||||||||||||
| 674 | return h; | - | ||||||||||||||||||||||||
| 675 | } | - | ||||||||||||||||||||||||
| 676 | - | |||||||||||||||||||||||||
| 677 | /*! | - | ||||||||||||||||||||||||
| 678 | \internal | - | ||||||||||||||||||||||||
| 679 | Also takes contentsMargins and menu bar into account. | - | ||||||||||||||||||||||||
| 680 | */ | - | ||||||||||||||||||||||||
| 681 | QSize QLayout::totalMinimumSize() const | - | ||||||||||||||||||||||||
| 682 | { | - | ||||||||||||||||||||||||
| 683 | Q_D(const QLayout); | - | ||||||||||||||||||||||||
| 684 | int side=0, top=0; | - | ||||||||||||||||||||||||
| 685 | if (d->topLevel) { | - | ||||||||||||||||||||||||
| 686 | QWidget *pw = parentWidget(); | - | ||||||||||||||||||||||||
| 687 | pw->ensurePolished(); | - | ||||||||||||||||||||||||
| 688 | QWidgetPrivate *wd = pw->d_func(); | - | ||||||||||||||||||||||||
| 689 | side += wd->leftmargin + wd->rightmargin; | - | ||||||||||||||||||||||||
| 690 | top += wd->topmargin + wd->bottommargin; | - | ||||||||||||||||||||||||
| 691 | } | - | ||||||||||||||||||||||||
| 692 | - | |||||||||||||||||||||||||
| 693 | QSize s = minimumSize(); | - | ||||||||||||||||||||||||
| 694 | #ifndef QT_NO_MENUBAR | - | ||||||||||||||||||||||||
| 695 | top += menuBarHeightForWidth(d->menubar, s.width() + side); | - | ||||||||||||||||||||||||
| 696 | #endif | - | ||||||||||||||||||||||||
| 697 | return s + QSize(side, top); | - | ||||||||||||||||||||||||
| 698 | } | - | ||||||||||||||||||||||||
| 699 | - | |||||||||||||||||||||||||
| 700 | /*! | - | ||||||||||||||||||||||||
| 701 | \internal | - | ||||||||||||||||||||||||
| 702 | Also takes contentsMargins and menu bar into account. | - | ||||||||||||||||||||||||
| 703 | */ | - | ||||||||||||||||||||||||
| 704 | QSize QLayout::totalSizeHint() const | - | ||||||||||||||||||||||||
| 705 | { | - | ||||||||||||||||||||||||
| 706 | Q_D(const QLayout); | - | ||||||||||||||||||||||||
| 707 | int side=0, top=0; | - | ||||||||||||||||||||||||
| 708 | if (d->topLevel) { | - | ||||||||||||||||||||||||
| 709 | QWidget *pw = parentWidget(); | - | ||||||||||||||||||||||||
| 710 | pw->ensurePolished(); | - | ||||||||||||||||||||||||
| 711 | QWidgetPrivate *wd = pw->d_func(); | - | ||||||||||||||||||||||||
| 712 | side += wd->leftmargin + wd->rightmargin; | - | ||||||||||||||||||||||||
| 713 | top += wd->topmargin + wd->bottommargin; | - | ||||||||||||||||||||||||
| 714 | } | - | ||||||||||||||||||||||||
| 715 | - | |||||||||||||||||||||||||
| 716 | QSize s = sizeHint(); | - | ||||||||||||||||||||||||
| 717 | if (hasHeightForWidth()) | - | ||||||||||||||||||||||||
| 718 | s.setHeight(heightForWidth(s.width() + side)); | - | ||||||||||||||||||||||||
| 719 | #ifndef QT_NO_MENUBAR | - | ||||||||||||||||||||||||
| 720 | top += menuBarHeightForWidth(d->menubar, s.width()); | - | ||||||||||||||||||||||||
| 721 | #endif | - | ||||||||||||||||||||||||
| 722 | return s + QSize(side, top); | - | ||||||||||||||||||||||||
| 723 | } | - | ||||||||||||||||||||||||
| 724 | - | |||||||||||||||||||||||||
| 725 | /*! | - | ||||||||||||||||||||||||
| 726 | \internal | - | ||||||||||||||||||||||||
| 727 | Also takes contentsMargins and menu bar into account. | - | ||||||||||||||||||||||||
| 728 | */ | - | ||||||||||||||||||||||||
| 729 | QSize QLayout::totalMaximumSize() const | - | ||||||||||||||||||||||||
| 730 | { | - | ||||||||||||||||||||||||
| 731 | Q_D(const QLayout); | - | ||||||||||||||||||||||||
| 732 | int side=0, top=0; | - | ||||||||||||||||||||||||
| 733 | if (d->topLevel) { | - | ||||||||||||||||||||||||
| 734 | QWidget *pw = parentWidget(); | - | ||||||||||||||||||||||||
| 735 | pw->ensurePolished(); | - | ||||||||||||||||||||||||
| 736 | QWidgetPrivate *wd = pw->d_func(); | - | ||||||||||||||||||||||||
| 737 | side += wd->leftmargin + wd->rightmargin; | - | ||||||||||||||||||||||||
| 738 | top += wd->topmargin + wd->bottommargin; | - | ||||||||||||||||||||||||
| 739 | } | - | ||||||||||||||||||||||||
| 740 | - | |||||||||||||||||||||||||
| 741 | QSize s = maximumSize(); | - | ||||||||||||||||||||||||
| 742 | #ifndef QT_NO_MENUBAR | - | ||||||||||||||||||||||||
| 743 | top += menuBarHeightForWidth(d->menubar, s.width()); | - | ||||||||||||||||||||||||
| 744 | #endif | - | ||||||||||||||||||||||||
| 745 | - | |||||||||||||||||||||||||
| 746 | if (d->topLevel) | - | ||||||||||||||||||||||||
| 747 | s = QSize(qMin(s.width() + side, QLAYOUTSIZE_MAX), | - | ||||||||||||||||||||||||
| 748 | qMin(s.height() + top, QLAYOUTSIZE_MAX)); | - | ||||||||||||||||||||||||
| 749 | return s; | - | ||||||||||||||||||||||||
| 750 | } | - | ||||||||||||||||||||||||
| 751 | - | |||||||||||||||||||||||||
| 752 | /*! | - | ||||||||||||||||||||||||
| 753 | \internal | - | ||||||||||||||||||||||||
| 754 | Destroys the layout, deleting all child layouts. | - | ||||||||||||||||||||||||
| 755 | Geometry management stops when a top-level layout is deleted. | - | ||||||||||||||||||||||||
| 756 | - | |||||||||||||||||||||||||
| 757 | The layout classes will probably be fatally confused if you delete | - | ||||||||||||||||||||||||
| 758 | a sublayout. | - | ||||||||||||||||||||||||
| 759 | */ | - | ||||||||||||||||||||||||
| 760 | QLayout::~QLayout() | - | ||||||||||||||||||||||||
| 761 | { | - | ||||||||||||||||||||||||
| 762 | Q_D(QLayout); | - | ||||||||||||||||||||||||
| 763 | /* | - | ||||||||||||||||||||||||
| 764 | This function may be called during the QObject destructor, | - | ||||||||||||||||||||||||
| 765 | when the parent no longer is a QWidget. | - | ||||||||||||||||||||||||
| 766 | */ | - | ||||||||||||||||||||||||
| 767 | if (d->topLevel && parent() && parent()->isWidgetType() && | - | ||||||||||||||||||||||||
| 768 | ((QWidget*)parent())->layout() == this) | - | ||||||||||||||||||||||||
| 769 | ((QWidget*)parent())->d_func()->layout = 0; | - | ||||||||||||||||||||||||
| 770 | } | - | ||||||||||||||||||||||||
| 771 | - | |||||||||||||||||||||||||
| 772 | - | |||||||||||||||||||||||||
| 773 | /*! | - | ||||||||||||||||||||||||
| 774 | This function is called from \c addLayout() or \c insertLayout() functions in | - | ||||||||||||||||||||||||
| 775 | subclasses to add layout \a l as a sub-layout. | - | ||||||||||||||||||||||||
| 776 | - | |||||||||||||||||||||||||
| 777 | The only scenario in which you need to call it directly is if you | - | ||||||||||||||||||||||||
| 778 | implement a custom layout that supports nested layouts. | - | ||||||||||||||||||||||||
| 779 | - | |||||||||||||||||||||||||
| 780 | \sa QBoxLayout::addLayout(), QBoxLayout::insertLayout(), QGridLayout::addLayout() | - | ||||||||||||||||||||||||
| 781 | */ | - | ||||||||||||||||||||||||
| 782 | void QLayout::addChildLayout(QLayout *l) | - | ||||||||||||||||||||||||
| 783 | { | - | ||||||||||||||||||||||||
| 784 | if (Q_UNLIKELY(l->parent())())) {
| 0 | ||||||||||||||||||||||||
| 785 | qWarning("QLayout::addChildLayout: layout \"%s\"\"%ls\" already has a parent", | - | ||||||||||||||||||||||||
| 786 | qUtf16Printable(l->objectName().toLocal8Bit().data());())); | - | ||||||||||||||||||||||||
| 787 | return; never executed: return; | 0 | ||||||||||||||||||||||||
| 788 | } | - | ||||||||||||||||||||||||
| 789 | l->setParent(this); | - | ||||||||||||||||||||||||
| 790 | - | |||||||||||||||||||||||||
| 791 | if (QWidget *mw = parentWidget()) {
| 0 | ||||||||||||||||||||||||
| 792 | l->d_func()->reparentChildWidgets(mw); | - | ||||||||||||||||||||||||
| 793 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 794 | - | |||||||||||||||||||||||||
| 795 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 796 | - | |||||||||||||||||||||||||
| 797 | /*! | - | ||||||||||||||||||||||||
| 798 | \internal | - | ||||||||||||||||||||||||
| 799 | */ | - | ||||||||||||||||||||||||
| 800 | bool QLayout::adoptLayout(QLayout *layout) | - | ||||||||||||||||||||||||
| 801 | { | - | ||||||||||||||||||||||||
| 802 | const bool ok = !layout->parent(); | - | ||||||||||||||||||||||||
| 803 | addChildLayout(layout); | - | ||||||||||||||||||||||||
| 804 | return ok; | - | ||||||||||||||||||||||||
| 805 | } | - | ||||||||||||||||||||||||
| 806 | - | |||||||||||||||||||||||||
| 807 | #ifdef QT_DEBUG | - | ||||||||||||||||||||||||
| 808 | static bool layoutDebug() | - | ||||||||||||||||||||||||
| 809 | { | - | ||||||||||||||||||||||||
| 810 | static int checked_env = -1; | - | ||||||||||||||||||||||||
| 811 | if(checked_env == -1) | - | ||||||||||||||||||||||||
| 812 | checked_env = !!qgetenv("QT_LAYOUT_DEBUG").toInt(); | - | ||||||||||||||||||||||||
| 813 | - | |||||||||||||||||||||||||
| 814 | return checked_env; | - | ||||||||||||||||||||||||
| 815 | } | - | ||||||||||||||||||||||||
| 816 | #endif | - | ||||||||||||||||||||||||
| 817 | - | |||||||||||||||||||||||||
| 818 | void QLayoutPrivate::reparentChildWidgets(QWidget *mw) | - | ||||||||||||||||||||||||
| 819 | { | - | ||||||||||||||||||||||||
| 820 | Q_Q(QLayout); | - | ||||||||||||||||||||||||
| 821 | int n = q->count(); | - | ||||||||||||||||||||||||
| 822 | - | |||||||||||||||||||||||||
| 823 | #ifndef QT_NO_MENUBAR | - | ||||||||||||||||||||||||
| 824 | if (menubar && menubar->parentWidget() != mw) {
| 0 | ||||||||||||||||||||||||
| 825 | menubar->setParent(mw); | - | ||||||||||||||||||||||||
| 826 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 827 | #endif | - | ||||||||||||||||||||||||
| 828 | bool mwVisible = mw && mw->isVisible();
| 0 | ||||||||||||||||||||||||
| 829 | for (int i = 0; i < n; ++i) {
| 0 | ||||||||||||||||||||||||
| 830 | QLayoutItem *item = q->itemAt(i); | - | ||||||||||||||||||||||||
| 831 | if (QWidget *w = item->widget()) {
| 0 | ||||||||||||||||||||||||
| 832 | QWidget *pw = w->parentWidget(); | - | ||||||||||||||||||||||||
| 833 | #ifdef QT_DEBUG | - | ||||||||||||||||||||||||
| 834 | if (Q_UNLIKELY(pw && pw != mw && layoutDebug())())) {
| 0 | ||||||||||||||||||||||||
| 835 | qWarning("QLayout::addChildLayout: widget %s \"%s\"\"%ls\" in wrong parent; moved to correct parent", | - | ||||||||||||||||||||||||
| 836 | w->metaObject()->className(), qUtf16Printable(w->objectName().toLocal8Bit().data());())); | - | ||||||||||||||||||||||||
| 837 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 838 | #endif | - | ||||||||||||||||||||||||
| 839 | bool needShow = mwVisible && !(w->isHidden() && w->testAttribute(Qt::WA_WState_ExplicitShowHide));
| 0 | ||||||||||||||||||||||||
| 840 | if (pw != mw)
| 0 | ||||||||||||||||||||||||
| 841 | w->setParent(mw); never executed: w->setParent(mw); | 0 | ||||||||||||||||||||||||
| 842 | if (needShow)
| 0 | ||||||||||||||||||||||||
| 843 | QMetaObject::invokeMethod(w, "_q_showIfNotHidden", Qt::QueuedConnection); //show later never executed: QMetaObject::invokeMethod(w, "_q_showIfNotHidden", Qt::QueuedConnection); | 0 | ||||||||||||||||||||||||
| 844 | } else if (QLayout *l = item->layout()) { never executed: end of block
| 0 | ||||||||||||||||||||||||
| 845 | l->d_func()->reparentChildWidgets(mw); | - | ||||||||||||||||||||||||
| 846 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 847 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 848 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 849 | - | |||||||||||||||||||||||||
| 850 | /*! | - | ||||||||||||||||||||||||
| 851 | Returns \c true if the \a widget can be added to the \a layout; | - | ||||||||||||||||||||||||
| 852 | otherwise returns \c false. | - | ||||||||||||||||||||||||
| 853 | */ | - | ||||||||||||||||||||||||
| 854 | bool QLayoutPrivate::checkWidget(QWidget *widget) const | - | ||||||||||||||||||||||||
| 855 | { | - | ||||||||||||||||||||||||
| 856 | Q_Q(const QLayout); | - | ||||||||||||||||||||||||
| 857 | if (Q_UNLIKELY(!widget))) {
| 0 | ||||||||||||||||||||||||
| 858 | qWarning("QLayout: Cannot add a null widget to %s/%s"%ls", q->metaObject()->className(), | - | ||||||||||||||||||||||||
| 859 | qPrintableqUtf16Printable(q->objectName())); | - | ||||||||||||||||||||||||
| 860 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||
| 861 | } | - | ||||||||||||||||||||||||
| 862 | if (Q_UNLIKELY(widget == q->parentWidget())())) {
| 0 | ||||||||||||||||||||||||
| 863 | qWarning("QLayout: Cannot add parent widget %s/%s%ls to its child layout %s/%s"%ls", | - | ||||||||||||||||||||||||
| 864 | widget->metaObject()->className(), qPrintableqUtf16Printable(widget->objectName()), | - | ||||||||||||||||||||||||
| 865 | q->metaObject()->className(), qPrintableqUtf16Printable(q->objectName())); | - | ||||||||||||||||||||||||
| 866 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||
| 867 | } | - | ||||||||||||||||||||||||
| 868 | return true; never executed: return true; | 0 | ||||||||||||||||||||||||
| 869 | } | - | ||||||||||||||||||||||||
| 870 | - | |||||||||||||||||||||||||
| 871 | /*! | - | ||||||||||||||||||||||||
| 872 | Returns \c true if the \a otherLayout can be added to the \a layout; | - | ||||||||||||||||||||||||
| 873 | otherwise returns \c false. | - | ||||||||||||||||||||||||
| 874 | */ | - | ||||||||||||||||||||||||
| 875 | bool QLayoutPrivate::checkLayout(QLayout *otherLayout) const | - | ||||||||||||||||||||||||
| 876 | { | - | ||||||||||||||||||||||||
| 877 | Q_Q(const QLayout); | - | ||||||||||||||||||||||||
| 878 | if (Q_UNLIKELY(!otherLayout))) {
| 0 | ||||||||||||||||||||||||
| 879 | qWarning("QLayout: Cannot add a null layout to %s/%s"%ls", | - | ||||||||||||||||||||||||
| 880 | q->metaObject()->className(), qPrintableqUtf16Printable(q->objectName())); | - | ||||||||||||||||||||||||
| 881 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||
| 882 | } | - | ||||||||||||||||||||||||
| 883 | if (Q_UNLIKELY(otherLayout == q))) {
| 0 | ||||||||||||||||||||||||
| 884 | qWarning("QLayout: Cannot add layout %s/%s%ls to itself", | - | ||||||||||||||||||||||||
| 885 | q->metaObject()->className(), qPrintableqUtf16Printable(q->objectName())); | - | ||||||||||||||||||||||||
| 886 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||
| 887 | } | - | ||||||||||||||||||||||||
| 888 | return true; never executed: return true; | 0 | ||||||||||||||||||||||||
| 889 | } | - | ||||||||||||||||||||||||
| 890 | - | |||||||||||||||||||||||||
| 891 | /*! | - | ||||||||||||||||||||||||
| 892 | This function is called from \c addWidget() functions in | - | ||||||||||||||||||||||||
| 893 | subclasses to add \a w as a managed widget of a layout. | - | ||||||||||||||||||||||||
| 894 | - | |||||||||||||||||||||||||
| 895 | If \a w is already managed by a layout, this function will give a warning | - | ||||||||||||||||||||||||
| 896 | and remove \a w from that layout. This function must therefore be | - | ||||||||||||||||||||||||
| 897 | called before adding \a w to the layout's data structure. | - | ||||||||||||||||||||||||
| 898 | */ | - | ||||||||||||||||||||||||
| 899 | void QLayout::addChildWidget(QWidget *w) | - | ||||||||||||||||||||||||
| 900 | { | - | ||||||||||||||||||||||||
| 901 | QWidget *mw = parentWidget(); | - | ||||||||||||||||||||||||
| 902 | QWidget *pw = w->parentWidget(); | - | ||||||||||||||||||||||||
| 903 | - | |||||||||||||||||||||||||
| 904 | //Qt::WA_LaidOut is never reset. It only means that the widget at some point has | - | ||||||||||||||||||||||||
| 905 | //been in a layout. | - | ||||||||||||||||||||||||
| 906 | if (pw && w->testAttribute(Qt::WA_LaidOut)) {
| 0 | ||||||||||||||||||||||||
| 907 | QLayout *l = pw->layout(); | - | ||||||||||||||||||||||||
| 908 | if (l && removeWidgetRecursively(l, w)) {
| 0 | ||||||||||||||||||||||||
| 909 | #ifdef QT_DEBUG | - | ||||||||||||||||||||||||
| 910 | if (Q_UNLIKELY(layoutDebug())()))
| 0 | ||||||||||||||||||||||||
| 911 | qWarning("QLayout::addChildWidget: %s \"%s\"\"%ls\" is already in a layout; moved to new layout", never executed: QMessageLogger(__FILE__, 911, __PRETTY_FUNCTION__).warning("QLayout::addChildWidget: %s \"%ls\" is already in a layout; moved to new layout", w->metaObject()->className(), static_cast<const wchar_t*>(static_cast<const void*>(QString(w->objectName()).utf16()))); | 0 | ||||||||||||||||||||||||
| 912 | w->metaObject()->className(), qUtf16Printable(w->objectName().toLocal8Bit().data());())); never executed: QMessageLogger(__FILE__, 911, __PRETTY_FUNCTION__).warning("QLayout::addChildWidget: %s \"%ls\" is already in a layout; moved to new layout", w->metaObject()->className(), static_cast<const wchar_t*>(static_cast<const void*>(QString(w->objectName()).utf16()))); | 0 | ||||||||||||||||||||||||
| 913 | #endif | - | ||||||||||||||||||||||||
| 914 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 915 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 916 | if (pw && mw && pw != mw) {
| 0 | ||||||||||||||||||||||||
| 917 | #ifdef QT_DEBUG | - | ||||||||||||||||||||||||
| 918 | if (Q_UNLIKELY(layoutDebug())()))
| 0 | ||||||||||||||||||||||||
| 919 | qWarning("QLayout::addChildWidget: %s \"%s\"\"%ls\" in wrong parent; moved to correct parent", never executed: QMessageLogger(__FILE__, 919, __PRETTY_FUNCTION__).warning("QLayout::addChildWidget: %s \"%ls\" in wrong parent; moved to correct parent", w->metaObject()->className(), static_cast<const wchar_t*>(static_cast<const void*>(QString(w->objectName()).utf16()))); | 0 | ||||||||||||||||||||||||
| 920 | w->metaObject()->className(), qUtf16Printable(w->objectName().toLocal8Bit().data());())); never executed: QMessageLogger(__FILE__, 919, __PRETTY_FUNCTION__).warning("QLayout::addChildWidget: %s \"%ls\" in wrong parent; moved to correct parent", w->metaObject()->className(), static_cast<const wchar_t*>(static_cast<const void*>(QString(w->objectName()).utf16()))); | 0 | ||||||||||||||||||||||||
| 921 | #endif | - | ||||||||||||||||||||||||
| 922 | pw = 0; | - | ||||||||||||||||||||||||
| 923 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 924 | bool needShow = mw && mw->isVisible() && !(w->isHidden() && w->testAttribute(Qt::WA_WState_ExplicitShowHide));
| 0 | ||||||||||||||||||||||||
| 925 | if (!pw && mw)
| 0 | ||||||||||||||||||||||||
| 926 | w->setParent(mw); never executed: w->setParent(mw); | 0 | ||||||||||||||||||||||||
| 927 | w->setAttribute(Qt::WA_LaidOut); | - | ||||||||||||||||||||||||
| 928 | if (needShow)
| 0 | ||||||||||||||||||||||||
| 929 | QMetaObject::invokeMethod(w, "_q_showIfNotHidden", Qt::QueuedConnection); //show later never executed: QMetaObject::invokeMethod(w, "_q_showIfNotHidden", Qt::QueuedConnection); | 0 | ||||||||||||||||||||||||
| 930 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 931 | - | |||||||||||||||||||||||||
| 932 | - | |||||||||||||||||||||||||
| 933 | - | |||||||||||||||||||||||||
| 934 | - | |||||||||||||||||||||||||
| 935 | - | |||||||||||||||||||||||||
| 936 | - | |||||||||||||||||||||||||
| 937 | - | |||||||||||||||||||||||||
| 938 | - | |||||||||||||||||||||||||
| 939 | /*! | - | ||||||||||||||||||||||||
| 940 | Tells the geometry manager to place the menu bar \a widget at the | - | ||||||||||||||||||||||||
| 941 | top of parentWidget(), outside QWidget::contentsMargins(). All | - | ||||||||||||||||||||||||
| 942 | child widgets are placed below the bottom edge of the menu bar. | - | ||||||||||||||||||||||||
| 943 | */ | - | ||||||||||||||||||||||||
| 944 | void QLayout::setMenuBar(QWidget *widget) | - | ||||||||||||||||||||||||
| 945 | { | - | ||||||||||||||||||||||||
| 946 | Q_D(QLayout); | - | ||||||||||||||||||||||||
| 947 | - | |||||||||||||||||||||||||
| 948 | #ifdef Q_OS_WINCE_WM | - | ||||||||||||||||||||||||
| 949 | if (widget && widget->size().height() > 0) | - | ||||||||||||||||||||||||
| 950 | #else | - | ||||||||||||||||||||||||
| 951 | if (widget) | - | ||||||||||||||||||||||||
| 952 | #endif | - | ||||||||||||||||||||||||
| 953 | addChildWidget(widget); | - | ||||||||||||||||||||||||
| 954 | d->menubar = widget; | - | ||||||||||||||||||||||||
| 955 | } | - | ||||||||||||||||||||||||
| 956 | - | |||||||||||||||||||||||||
| 957 | /*! | - | ||||||||||||||||||||||||
| 958 | Returns the menu bar set for this layout, or 0 if no menu bar is | - | ||||||||||||||||||||||||
| 959 | set. | - | ||||||||||||||||||||||||
| 960 | */ | - | ||||||||||||||||||||||||
| 961 | - | |||||||||||||||||||||||||
| 962 | QWidget *QLayout::menuBar() const | - | ||||||||||||||||||||||||
| 963 | { | - | ||||||||||||||||||||||||
| 964 | Q_D(const QLayout); | - | ||||||||||||||||||||||||
| 965 | return d->menubar; | - | ||||||||||||||||||||||||
| 966 | } | - | ||||||||||||||||||||||||
| 967 | - | |||||||||||||||||||||||||
| 968 | - | |||||||||||||||||||||||||
| 969 | /*! | - | ||||||||||||||||||||||||
| 970 | Returns the minimum size of this layout. This is the smallest | - | ||||||||||||||||||||||||
| 971 | size that the layout can have while still respecting the | - | ||||||||||||||||||||||||
| 972 | specifications. | - | ||||||||||||||||||||||||
| 973 | - | |||||||||||||||||||||||||
| 974 | The returned value doesn't include the space required by | - | ||||||||||||||||||||||||
| 975 | QWidget::setContentsMargins() or menuBar(). | - | ||||||||||||||||||||||||
| 976 | - | |||||||||||||||||||||||||
| 977 | The default implementation allows unlimited resizing. | - | ||||||||||||||||||||||||
| 978 | */ | - | ||||||||||||||||||||||||
| 979 | QSize QLayout::minimumSize() const | - | ||||||||||||||||||||||||
| 980 | { | - | ||||||||||||||||||||||||
| 981 | return QSize(0, 0); | - | ||||||||||||||||||||||||
| 982 | } | - | ||||||||||||||||||||||||
| 983 | - | |||||||||||||||||||||||||
| 984 | /*! | - | ||||||||||||||||||||||||
| 985 | Returns the maximum size of this layout. This is the largest size | - | ||||||||||||||||||||||||
| 986 | that the layout can have while still respecting the | - | ||||||||||||||||||||||||
| 987 | specifications. | - | ||||||||||||||||||||||||
| 988 | - | |||||||||||||||||||||||||
| 989 | The returned value doesn't include the space required by | - | ||||||||||||||||||||||||
| 990 | QWidget::setContentsMargins() or menuBar(). | - | ||||||||||||||||||||||||
| 991 | - | |||||||||||||||||||||||||
| 992 | The default implementation allows unlimited resizing. | - | ||||||||||||||||||||||||
| 993 | */ | - | ||||||||||||||||||||||||
| 994 | QSize QLayout::maximumSize() const | - | ||||||||||||||||||||||||
| 995 | { | - | ||||||||||||||||||||||||
| 996 | return QSize(QLAYOUTSIZE_MAX, QLAYOUTSIZE_MAX); | - | ||||||||||||||||||||||||
| 997 | } | - | ||||||||||||||||||||||||
| 998 | - | |||||||||||||||||||||||||
| 999 | /*! | - | ||||||||||||||||||||||||
| 1000 | Returns whether this layout can make use of more space than | - | ||||||||||||||||||||||||
| 1001 | sizeHint(). A value of Qt::Vertical or Qt::Horizontal means that | - | ||||||||||||||||||||||||
| 1002 | it wants to grow in only one dimension, whereas Qt::Vertical | | - | ||||||||||||||||||||||||
| 1003 | Qt::Horizontal means that it wants to grow in both dimensions. | - | ||||||||||||||||||||||||
| 1004 | - | |||||||||||||||||||||||||
| 1005 | The default implementation returns Qt::Horizontal | Qt::Vertical. | - | ||||||||||||||||||||||||
| 1006 | Subclasses reimplement it to return a meaningful value based on | - | ||||||||||||||||||||||||
| 1007 | their child widgets's \l{QSizePolicy}{size policies}. | - | ||||||||||||||||||||||||
| 1008 | - | |||||||||||||||||||||||||
| 1009 | \sa sizeHint() | - | ||||||||||||||||||||||||
| 1010 | */ | - | ||||||||||||||||||||||||
| 1011 | Qt::Orientations QLayout::expandingDirections() const | - | ||||||||||||||||||||||||
| 1012 | { | - | ||||||||||||||||||||||||
| 1013 | return Qt::Horizontal | Qt::Vertical; | - | ||||||||||||||||||||||||
| 1014 | } | - | ||||||||||||||||||||||||
| 1015 | - | |||||||||||||||||||||||||
| 1016 | void QLayout::activateRecursiveHelper(QLayoutItem *item) | - | ||||||||||||||||||||||||
| 1017 | { | - | ||||||||||||||||||||||||
| 1018 | item->invalidate(); | - | ||||||||||||||||||||||||
| 1019 | QLayout *layout = item->layout(); | - | ||||||||||||||||||||||||
| 1020 | if (layout) { | - | ||||||||||||||||||||||||
| 1021 | QLayoutItem *child; | - | ||||||||||||||||||||||||
| 1022 | int i=0; | - | ||||||||||||||||||||||||
| 1023 | while ((child = layout->itemAt(i++))) | - | ||||||||||||||||||||||||
| 1024 | activateRecursiveHelper(child); | - | ||||||||||||||||||||||||
| 1025 | layout->d_func()->activated = true; | - | ||||||||||||||||||||||||
| 1026 | } | - | ||||||||||||||||||||||||
| 1027 | } | - | ||||||||||||||||||||||||
| 1028 | - | |||||||||||||||||||||||||
| 1029 | /*! | - | ||||||||||||||||||||||||
| 1030 | Updates the layout for parentWidget(). | - | ||||||||||||||||||||||||
| 1031 | - | |||||||||||||||||||||||||
| 1032 | You should generally not need to call this because it is | - | ||||||||||||||||||||||||
| 1033 | automatically called at the most appropriate times. | - | ||||||||||||||||||||||||
| 1034 | - | |||||||||||||||||||||||||
| 1035 | \sa activate(), invalidate() | - | ||||||||||||||||||||||||
| 1036 | */ | - | ||||||||||||||||||||||||
| 1037 | - | |||||||||||||||||||||||||
| 1038 | void QLayout::update() | - | ||||||||||||||||||||||||
| 1039 | { | - | ||||||||||||||||||||||||
| 1040 | QLayout *layout = this; | - | ||||||||||||||||||||||||
| 1041 | while (layout && layout->d_func()->activated) { | - | ||||||||||||||||||||||||
| 1042 | layout->d_func()->activated = false; | - | ||||||||||||||||||||||||
| 1043 | if (layout->d_func()->topLevel) { | - | ||||||||||||||||||||||||
| 1044 | Q_ASSERT(layout->parent()->isWidgetType()); | - | ||||||||||||||||||||||||
| 1045 | QWidget *mw = static_cast<QWidget*>(layout->parent()); | - | ||||||||||||||||||||||||
| 1046 | QApplication::postEvent(mw, new QEvent(QEvent::LayoutRequest)); | - | ||||||||||||||||||||||||
| 1047 | break; | - | ||||||||||||||||||||||||
| 1048 | } | - | ||||||||||||||||||||||||
| 1049 | layout = static_cast<QLayout*>(layout->parent()); | - | ||||||||||||||||||||||||
| 1050 | } | - | ||||||||||||||||||||||||
| 1051 | } | - | ||||||||||||||||||||||||
| 1052 | - | |||||||||||||||||||||||||
| 1053 | /*! | - | ||||||||||||||||||||||||
| 1054 | Redoes the layout for parentWidget() if necessary. | - | ||||||||||||||||||||||||
| 1055 | - | |||||||||||||||||||||||||
| 1056 | You should generally not need to call this because it is | - | ||||||||||||||||||||||||
| 1057 | automatically called at the most appropriate times. It returns | - | ||||||||||||||||||||||||
| 1058 | true if the layout was redone. | - | ||||||||||||||||||||||||
| 1059 | - | |||||||||||||||||||||||||
| 1060 | \sa update(), QWidget::updateGeometry() | - | ||||||||||||||||||||||||
| 1061 | */ | - | ||||||||||||||||||||||||
| 1062 | bool QLayout::activate() | - | ||||||||||||||||||||||||
| 1063 | { | - | ||||||||||||||||||||||||
| 1064 | Q_D(QLayout); | - | ||||||||||||||||||||||||
| 1065 | if (!d->enabled || !parent())
| 0 | ||||||||||||||||||||||||
| 1066 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||
| 1067 | if (!d->topLevel)
| 0 | ||||||||||||||||||||||||
| 1068 | return static_cast<QLayout*>(parent())->activate(); never executed: return static_cast<QLayout*>(parent())->activate(); | 0 | ||||||||||||||||||||||||
| 1069 | if (d->activated)
| 0 | ||||||||||||||||||||||||
| 1070 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||
| 1071 | QWidget *mw = static_cast<QWidget*>(parent()); | - | ||||||||||||||||||||||||
| 1072 | if (Q_UNLIKELY(!mw== 0))) {
| 0 | ||||||||||||||||||||||||
| 1073 | qWarning("QLayout::activate: %s \"%s\"\"%ls\" does not have a main widget", | - | ||||||||||||||||||||||||
| 1074 | QObject::metaObject()->className(), QObject::qUtf16Printable(objectName().toLocal8Bit().data());())); | - | ||||||||||||||||||||||||
| 1075 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||
| 1076 | } | - | ||||||||||||||||||||||||
| 1077 | activateRecursiveHelper(this); | - | ||||||||||||||||||||||||
| 1078 | - | |||||||||||||||||||||||||
| 1079 | QWidgetPrivate *md = mw->d_func(); | - | ||||||||||||||||||||||||
| 1080 | uint explMin = md->extra ? md->extra->explicitMinSize : 0;
| 0 | ||||||||||||||||||||||||
| 1081 | uint explMax = md->extra ? md->extra->explicitMaxSize : 0;
| 0 | ||||||||||||||||||||||||
| 1082 | - | |||||||||||||||||||||||||
| 1083 | switch (d->constraint) { | - | ||||||||||||||||||||||||
| 1084 | case SetFixedSize: never executed: case SetFixedSize: | 0 | ||||||||||||||||||||||||
| 1085 | // will trigger resize | - | ||||||||||||||||||||||||
| 1086 | mw->setFixedSize(totalSizeHint()); | - | ||||||||||||||||||||||||
| 1087 | break; never executed: break; | 0 | ||||||||||||||||||||||||
| 1088 | case SetMinimumSize: never executed: case SetMinimumSize: | 0 | ||||||||||||||||||||||||
| 1089 | mw->setMinimumSize(totalMinimumSize()); | - | ||||||||||||||||||||||||
| 1090 | break; never executed: break; | 0 | ||||||||||||||||||||||||
| 1091 | case SetMaximumSize: never executed: case SetMaximumSize: | 0 | ||||||||||||||||||||||||
| 1092 | mw->setMaximumSize(totalMaximumSize()); | - | ||||||||||||||||||||||||
| 1093 | break; never executed: break; | 0 | ||||||||||||||||||||||||
| 1094 | case SetMinAndMaxSize: never executed: case SetMinAndMaxSize: | 0 | ||||||||||||||||||||||||
| 1095 | mw->setMinimumSize(totalMinimumSize()); | - | ||||||||||||||||||||||||
| 1096 | mw->setMaximumSize(totalMaximumSize()); | - | ||||||||||||||||||||||||
| 1097 | break; never executed: break; | 0 | ||||||||||||||||||||||||
| 1098 | case SetDefaultConstraint: { never executed: case SetDefaultConstraint: | 0 | ||||||||||||||||||||||||
| 1099 | bool widthSet = explMin & Qt::Horizontal; | - | ||||||||||||||||||||||||
| 1100 | bool heightSet = explMin & Qt::Vertical; | - | ||||||||||||||||||||||||
| 1101 | if (mw->isWindow()) {
| 0 | ||||||||||||||||||||||||
| 1102 | QSize ms = totalMinimumSize(); | - | ||||||||||||||||||||||||
| 1103 | if (widthSet)
| 0 | ||||||||||||||||||||||||
| 1104 | ms.setWidth(mw->minimumSize().width()); never executed: ms.setWidth(mw->minimumSize().width()); | 0 | ||||||||||||||||||||||||
| 1105 | if (heightSet)
| 0 | ||||||||||||||||||||||||
| 1106 | ms.setHeight(mw->minimumSize().height()); never executed: ms.setHeight(mw->minimumSize().height()); | 0 | ||||||||||||||||||||||||
| 1107 | mw->setMinimumSize(ms); | - | ||||||||||||||||||||||||
| 1108 | } else if (!widthSet || !heightSet) { never executed: end of block
| 0 | ||||||||||||||||||||||||
| 1109 | QSize ms = mw->minimumSize(); | - | ||||||||||||||||||||||||
| 1110 | if (!widthSet)
| 0 | ||||||||||||||||||||||||
| 1111 | ms.setWidth(0); never executed: ms.setWidth(0); | 0 | ||||||||||||||||||||||||
| 1112 | if (!heightSet)
| 0 | ||||||||||||||||||||||||
| 1113 | ms.setHeight(0); never executed: ms.setHeight(0); | 0 | ||||||||||||||||||||||||
| 1114 | mw->setMinimumSize(ms); | - | ||||||||||||||||||||||||
| 1115 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1116 | break; never executed: break; | 0 | ||||||||||||||||||||||||
| 1117 | } | - | ||||||||||||||||||||||||
| 1118 | case SetNoConstraint: never executed: case SetNoConstraint: | 0 | ||||||||||||||||||||||||
| 1119 | break; never executed: break; | 0 | ||||||||||||||||||||||||
| 1120 | } | - | ||||||||||||||||||||||||
| 1121 | - | |||||||||||||||||||||||||
| 1122 | d->doResize(mw->size()); | - | ||||||||||||||||||||||||
| 1123 | - | |||||||||||||||||||||||||
| 1124 | if (md->extra) {
| 0 | ||||||||||||||||||||||||
| 1125 | md->extra->explicitMinSize = explMin; | - | ||||||||||||||||||||||||
| 1126 | md->extra->explicitMaxSize = explMax; | - | ||||||||||||||||||||||||
| 1127 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1128 | // ideally only if sizeHint() or sizePolicy() has changed | - | ||||||||||||||||||||||||
| 1129 | mw->updateGeometry(); | - | ||||||||||||||||||||||||
| 1130 | return true; never executed: return true; | 0 | ||||||||||||||||||||||||
| 1131 | } | - | ||||||||||||||||||||||||
| 1132 | - | |||||||||||||||||||||||||
| 1133 | /*! | - | ||||||||||||||||||||||||
| 1134 | \since 5.2 | - | ||||||||||||||||||||||||
| 1135 | - | |||||||||||||||||||||||||
| 1136 | Searches for widget \a from and replaces it with widget \a to if found. | - | ||||||||||||||||||||||||
| 1137 | Returns the layout item that contains the widget \a from on success. | - | ||||||||||||||||||||||||
| 1138 | Otherwise \c 0 is returned. If \a options contains \c Qt::FindChildrenRecursively | - | ||||||||||||||||||||||||
| 1139 | (the default), sub-layouts are searched for doing the replacement. | - | ||||||||||||||||||||||||
| 1140 | Any other flag in \a options is ignored. | - | ||||||||||||||||||||||||
| 1141 | - | |||||||||||||||||||||||||
| 1142 | Notice that the returned item therefore might not belong to this layout, | - | ||||||||||||||||||||||||
| 1143 | but to a sub-layout. | - | ||||||||||||||||||||||||
| 1144 | - | |||||||||||||||||||||||||
| 1145 | The returned layout item is no longer owned by the layout and should be | - | ||||||||||||||||||||||||
| 1146 | either deleted or inserted to another layout. The widget \a from is no | - | ||||||||||||||||||||||||
| 1147 | longer managed by the layout and may need to be deleted or hidden. The | - | ||||||||||||||||||||||||
| 1148 | parent of widget \a from is left unchanged. | - | ||||||||||||||||||||||||
| 1149 | - | |||||||||||||||||||||||||
| 1150 | This function works for the built-in Qt layouts, but might not work for | - | ||||||||||||||||||||||||
| 1151 | custom layouts. | - | ||||||||||||||||||||||||
| 1152 | - | |||||||||||||||||||||||||
| 1153 | \sa indexOf() | - | ||||||||||||||||||||||||
| 1154 | */ | - | ||||||||||||||||||||||||
| 1155 | - | |||||||||||||||||||||||||
| 1156 | QLayoutItem *QLayout::replaceWidget(QWidget *from, QWidget *to, Qt::FindChildOptions options) | - | ||||||||||||||||||||||||
| 1157 | { | - | ||||||||||||||||||||||||
| 1158 | Q_D(QLayout); | - | ||||||||||||||||||||||||
| 1159 | if (!from || !to) | - | ||||||||||||||||||||||||
| 1160 | return 0; | - | ||||||||||||||||||||||||
| 1161 | - | |||||||||||||||||||||||||
| 1162 | int index = -1; | - | ||||||||||||||||||||||||
| 1163 | QLayoutItem *item = 0; | - | ||||||||||||||||||||||||
| 1164 | for (int u = 0; u < count(); ++u) { | - | ||||||||||||||||||||||||
| 1165 | item = itemAt(u); | - | ||||||||||||||||||||||||
| 1166 | if (!item) | - | ||||||||||||||||||||||||
| 1167 | continue; | - | ||||||||||||||||||||||||
| 1168 | - | |||||||||||||||||||||||||
| 1169 | if (item->widget() == from) { | - | ||||||||||||||||||||||||
| 1170 | index = u; | - | ||||||||||||||||||||||||
| 1171 | break; | - | ||||||||||||||||||||||||
| 1172 | } | - | ||||||||||||||||||||||||
| 1173 | - | |||||||||||||||||||||||||
| 1174 | if (item->layout() && (options & Qt::FindChildrenRecursively)) { | - | ||||||||||||||||||||||||
| 1175 | QLayoutItem *r = item->layout()->replaceWidget(from, to, options); | - | ||||||||||||||||||||||||
| 1176 | if (r) | - | ||||||||||||||||||||||||
| 1177 | return r; | - | ||||||||||||||||||||||||
| 1178 | } | - | ||||||||||||||||||||||||
| 1179 | } | - | ||||||||||||||||||||||||
| 1180 | if (index == -1) | - | ||||||||||||||||||||||||
| 1181 | return 0; | - | ||||||||||||||||||||||||
| 1182 | - | |||||||||||||||||||||||||
| 1183 | addChildWidget(to); | - | ||||||||||||||||||||||||
| 1184 | QLayoutItem *newitem = new QWidgetItem(to); | - | ||||||||||||||||||||||||
| 1185 | newitem->setAlignment(item->alignment()); | - | ||||||||||||||||||||||||
| 1186 | QLayoutItem *r = d->replaceAt(index, newitem); | - | ||||||||||||||||||||||||
| 1187 | if (!r) | - | ||||||||||||||||||||||||
| 1188 | delete newitem; | - | ||||||||||||||||||||||||
| 1189 | return r; | - | ||||||||||||||||||||||||
| 1190 | } | - | ||||||||||||||||||||||||
| 1191 | - | |||||||||||||||||||||||||
| 1192 | /*! | - | ||||||||||||||||||||||||
| 1193 | \fn QLayoutItem *QLayout::itemAt(int index) const | - | ||||||||||||||||||||||||
| 1194 | - | |||||||||||||||||||||||||
| 1195 | Must be implemented in subclasses to return the layout item at \a | - | ||||||||||||||||||||||||
| 1196 | index. If there is no such item, the function must return 0. | - | ||||||||||||||||||||||||
| 1197 | Items are numbered consecutively from 0. If an item is deleted, other items will be renumbered. | - | ||||||||||||||||||||||||
| 1198 | - | |||||||||||||||||||||||||
| 1199 | This function can be used to iterate over a layout. The following | - | ||||||||||||||||||||||||
| 1200 | code will draw a rectangle for each layout item in the layout structure of the widget. | - | ||||||||||||||||||||||||
| 1201 | - | |||||||||||||||||||||||||
| 1202 | \snippet code/src_gui_kernel_qlayout.cpp 0 | - | ||||||||||||||||||||||||
| 1203 | - | |||||||||||||||||||||||||
| 1204 | \sa count(), takeAt() | - | ||||||||||||||||||||||||
| 1205 | */ | - | ||||||||||||||||||||||||
| 1206 | - | |||||||||||||||||||||||||
| 1207 | /*! | - | ||||||||||||||||||||||||
| 1208 | \fn QLayoutItem *QLayout::takeAt(int index) | - | ||||||||||||||||||||||||
| 1209 | - | |||||||||||||||||||||||||
| 1210 | Must be implemented in subclasses to remove the layout item at \a | - | ||||||||||||||||||||||||
| 1211 | index from the layout, and return the item. If there is no such | - | ||||||||||||||||||||||||
| 1212 | item, the function must do nothing and return 0. Items are numbered | - | ||||||||||||||||||||||||
| 1213 | consecutively from 0. If an item is removed, other items will be | - | ||||||||||||||||||||||||
| 1214 | renumbered. | - | ||||||||||||||||||||||||
| 1215 | - | |||||||||||||||||||||||||
| 1216 | The following code fragment shows a safe way to remove all items | - | ||||||||||||||||||||||||
| 1217 | from a layout: | - | ||||||||||||||||||||||||
| 1218 | - | |||||||||||||||||||||||||
| 1219 | \snippet code/src_gui_kernel_qlayout.cpp 1 | - | ||||||||||||||||||||||||
| 1220 | - | |||||||||||||||||||||||||
| 1221 | \sa itemAt(), count() | - | ||||||||||||||||||||||||
| 1222 | */ | - | ||||||||||||||||||||||||
| 1223 | - | |||||||||||||||||||||||||
| 1224 | /*! | - | ||||||||||||||||||||||||
| 1225 | \fn int *QLayout::count() const | - | ||||||||||||||||||||||||
| 1226 | - | |||||||||||||||||||||||||
| 1227 | Must be implemented in subclasses to return the number of items | - | ||||||||||||||||||||||||
| 1228 | in the layout. | - | ||||||||||||||||||||||||
| 1229 | - | |||||||||||||||||||||||||
| 1230 | \sa itemAt() | - | ||||||||||||||||||||||||
| 1231 | */ | - | ||||||||||||||||||||||||
| 1232 | - | |||||||||||||||||||||||||
| 1233 | /*! | - | ||||||||||||||||||||||||
| 1234 | Searches for widget \a widget in this layout (not including child | - | ||||||||||||||||||||||||
| 1235 | layouts). | - | ||||||||||||||||||||||||
| 1236 | - | |||||||||||||||||||||||||
| 1237 | Returns the index of \a widget, or -1 if \a widget is not found. | - | ||||||||||||||||||||||||
| 1238 | - | |||||||||||||||||||||||||
| 1239 | The default implementation iterates over all items using itemAt() | - | ||||||||||||||||||||||||
| 1240 | */ | - | ||||||||||||||||||||||||
| 1241 | int QLayout::indexOf(QWidget *widget) const | - | ||||||||||||||||||||||||
| 1242 | { | - | ||||||||||||||||||||||||
| 1243 | int i = 0; | - | ||||||||||||||||||||||||
| 1244 | QLayoutItem *item = itemAt(i); | - | ||||||||||||||||||||||||
| 1245 | while (item) { | - | ||||||||||||||||||||||||
| 1246 | if (item->widget() == widget) | - | ||||||||||||||||||||||||
| 1247 | return i; | - | ||||||||||||||||||||||||
| 1248 | ++i; | - | ||||||||||||||||||||||||
| 1249 | item = itemAt(i); | - | ||||||||||||||||||||||||
| 1250 | } | - | ||||||||||||||||||||||||
| 1251 | return -1; | - | ||||||||||||||||||||||||
| 1252 | } | - | ||||||||||||||||||||||||
| 1253 | - | |||||||||||||||||||||||||
| 1254 | /*! | - | ||||||||||||||||||||||||
| 1255 | \enum QLayout::SizeConstraint | - | ||||||||||||||||||||||||
| 1256 | - | |||||||||||||||||||||||||
| 1257 | The possible values are: | - | ||||||||||||||||||||||||
| 1258 | - | |||||||||||||||||||||||||
| 1259 | \value SetDefaultConstraint The main widget's minimum size is set | - | ||||||||||||||||||||||||
| 1260 | to minimumSize(), unless the widget already has | - | ||||||||||||||||||||||||
| 1261 | a minimum size. | - | ||||||||||||||||||||||||
| 1262 | - | |||||||||||||||||||||||||
| 1263 | \value SetFixedSize The main widget's size is set to sizeHint(); it | - | ||||||||||||||||||||||||
| 1264 | cannot be resized at all. | - | ||||||||||||||||||||||||
| 1265 | \value SetMinimumSize The main widget's minimum size is set to | - | ||||||||||||||||||||||||
| 1266 | minimumSize(); it cannot be smaller. | - | ||||||||||||||||||||||||
| 1267 | - | |||||||||||||||||||||||||
| 1268 | \value SetMaximumSize The main widget's maximum size is set to | - | ||||||||||||||||||||||||
| 1269 | maximumSize(); it cannot be larger. | - | ||||||||||||||||||||||||
| 1270 | - | |||||||||||||||||||||||||
| 1271 | \value SetMinAndMaxSize The main widget's minimum size is set to | - | ||||||||||||||||||||||||
| 1272 | minimumSize() and its maximum size is set to | - | ||||||||||||||||||||||||
| 1273 | maximumSize(). | - | ||||||||||||||||||||||||
| 1274 | - | |||||||||||||||||||||||||
| 1275 | \value SetNoConstraint The widget is not constrained. | - | ||||||||||||||||||||||||
| 1276 | - | |||||||||||||||||||||||||
| 1277 | \sa setSizeConstraint() | - | ||||||||||||||||||||||||
| 1278 | */ | - | ||||||||||||||||||||||||
| 1279 | - | |||||||||||||||||||||||||
| 1280 | /*! | - | ||||||||||||||||||||||||
| 1281 | \property QLayout::sizeConstraint | - | ||||||||||||||||||||||||
| 1282 | \brief the resize mode of the layout | - | ||||||||||||||||||||||||
| 1283 | - | |||||||||||||||||||||||||
| 1284 | The default mode is \l {QLayout::SetDefaultConstraint} | - | ||||||||||||||||||||||||
| 1285 | {SetDefaultConstraint}. | - | ||||||||||||||||||||||||
| 1286 | */ | - | ||||||||||||||||||||||||
| 1287 | void QLayout::setSizeConstraint(SizeConstraint constraint) | - | ||||||||||||||||||||||||
| 1288 | { | - | ||||||||||||||||||||||||
| 1289 | Q_D(QLayout); | - | ||||||||||||||||||||||||
| 1290 | if (constraint == d->constraint) | - | ||||||||||||||||||||||||
| 1291 | return; | - | ||||||||||||||||||||||||
| 1292 | - | |||||||||||||||||||||||||
| 1293 | d->constraint = constraint; | - | ||||||||||||||||||||||||
| 1294 | invalidate(); | - | ||||||||||||||||||||||||
| 1295 | } | - | ||||||||||||||||||||||||
| 1296 | - | |||||||||||||||||||||||||
| 1297 | QLayout::SizeConstraint QLayout::sizeConstraint() const | - | ||||||||||||||||||||||||
| 1298 | { | - | ||||||||||||||||||||||||
| 1299 | Q_D(const QLayout); | - | ||||||||||||||||||||||||
| 1300 | return d->constraint; | - | ||||||||||||||||||||||||
| 1301 | } | - | ||||||||||||||||||||||||
| 1302 | - | |||||||||||||||||||||||||
| 1303 | /*! | - | ||||||||||||||||||||||||
| 1304 | Returns the rectangle that should be covered when the geometry of | - | ||||||||||||||||||||||||
| 1305 | this layout is set to \a r, provided that this layout supports | - | ||||||||||||||||||||||||
| 1306 | setAlignment(). | - | ||||||||||||||||||||||||
| 1307 | - | |||||||||||||||||||||||||
| 1308 | The result is derived from sizeHint() and expanding(). It is never | - | ||||||||||||||||||||||||
| 1309 | larger than \a r. | - | ||||||||||||||||||||||||
| 1310 | */ | - | ||||||||||||||||||||||||
| 1311 | QRect QLayout::alignmentRect(const QRect &r) const | - | ||||||||||||||||||||||||
| 1312 | { | - | ||||||||||||||||||||||||
| 1313 | QSize s = sizeHint(); | - | ||||||||||||||||||||||||
| 1314 | Qt::Alignment a = alignment(); | - | ||||||||||||||||||||||||
| 1315 | - | |||||||||||||||||||||||||
| 1316 | /* | - | ||||||||||||||||||||||||
| 1317 | This is a hack to obtain the real maximum size, not | - | ||||||||||||||||||||||||
| 1318 | QSize(QLAYOUTSIZE_MAX, QLAYOUTSIZE_MAX), the value consistently | - | ||||||||||||||||||||||||
| 1319 | returned by QLayoutItems that have an alignment. | - | ||||||||||||||||||||||||
| 1320 | */ | - | ||||||||||||||||||||||||
| 1321 | QLayout *that = const_cast<QLayout *>(this); | - | ||||||||||||||||||||||||
| 1322 | that->setAlignment(0); | - | ||||||||||||||||||||||||
| 1323 | QSize ms = that->maximumSize(); | - | ||||||||||||||||||||||||
| 1324 | that->setAlignment(a); | - | ||||||||||||||||||||||||
| 1325 | - | |||||||||||||||||||||||||
| 1326 | if ((expandingDirections() & Qt::Horizontal) || | - | ||||||||||||||||||||||||
| 1327 | !(a & Qt::AlignHorizontal_Mask)) { | - | ||||||||||||||||||||||||
| 1328 | s.setWidth(qMin(r.width(), ms.width())); | - | ||||||||||||||||||||||||
| 1329 | } | - | ||||||||||||||||||||||||
| 1330 | if ((expandingDirections() & Qt::Vertical) || | - | ||||||||||||||||||||||||
| 1331 | !(a & Qt::AlignVertical_Mask)) { | - | ||||||||||||||||||||||||
| 1332 | s.setHeight(qMin(r.height(), ms.height())); | - | ||||||||||||||||||||||||
| 1333 | } else if (hasHeightForWidth()) { | - | ||||||||||||||||||||||||
| 1334 | int hfw = heightForWidth(s.width()); | - | ||||||||||||||||||||||||
| 1335 | if (hfw < s.height()) | - | ||||||||||||||||||||||||
| 1336 | s.setHeight(qMin(hfw, ms.height())); | - | ||||||||||||||||||||||||
| 1337 | } | - | ||||||||||||||||||||||||
| 1338 | - | |||||||||||||||||||||||||
| 1339 | s = s.boundedTo(r.size()); | - | ||||||||||||||||||||||||
| 1340 | int x = r.x(); | - | ||||||||||||||||||||||||
| 1341 | int y = r.y(); | - | ||||||||||||||||||||||||
| 1342 | - | |||||||||||||||||||||||||
| 1343 | if (a & Qt::AlignBottom) | - | ||||||||||||||||||||||||
| 1344 | y += (r.height() - s.height()); | - | ||||||||||||||||||||||||
| 1345 | else if (!(a & Qt::AlignTop)) | - | ||||||||||||||||||||||||
| 1346 | y += (r.height() - s.height()) / 2; | - | ||||||||||||||||||||||||
| 1347 | - | |||||||||||||||||||||||||
| 1348 | QWidget *parent = parentWidget(); | - | ||||||||||||||||||||||||
| 1349 | a = QStyle::visualAlignment(parent ? parent->layoutDirection() : QApplication::layoutDirection(), a); | - | ||||||||||||||||||||||||
| 1350 | if (a & Qt::AlignRight) | - | ||||||||||||||||||||||||
| 1351 | x += (r.width() - s.width()); | - | ||||||||||||||||||||||||
| 1352 | else if (!(a & Qt::AlignLeft)) | - | ||||||||||||||||||||||||
| 1353 | x += (r.width() - s.width()) / 2; | - | ||||||||||||||||||||||||
| 1354 | - | |||||||||||||||||||||||||
| 1355 | return QRect(x, y, s.width(), s.height()); | - | ||||||||||||||||||||||||
| 1356 | } | - | ||||||||||||||||||||||||
| 1357 | - | |||||||||||||||||||||||||
| 1358 | /*! | - | ||||||||||||||||||||||||
| 1359 | Removes the widget \a widget from the layout. After this call, it | - | ||||||||||||||||||||||||
| 1360 | is the caller's responsibility to give the widget a reasonable | - | ||||||||||||||||||||||||
| 1361 | geometry or to put the widget back into a layout. | - | ||||||||||||||||||||||||
| 1362 | - | |||||||||||||||||||||||||
| 1363 | \b{Note:} The ownership of \a widget remains the same as | - | ||||||||||||||||||||||||
| 1364 | when it was added. | - | ||||||||||||||||||||||||
| 1365 | - | |||||||||||||||||||||||||
| 1366 | \sa removeItem(), QWidget::setGeometry(), addWidget() | - | ||||||||||||||||||||||||
| 1367 | */ | - | ||||||||||||||||||||||||
| 1368 | void QLayout::removeWidget(QWidget *widget) | - | ||||||||||||||||||||||||
| 1369 | { | - | ||||||||||||||||||||||||
| 1370 | int i = 0; | - | ||||||||||||||||||||||||
| 1371 | QLayoutItem *child; | - | ||||||||||||||||||||||||
| 1372 | while ((child = itemAt(i))) { | - | ||||||||||||||||||||||||
| 1373 | if (child->widget() == widget) { | - | ||||||||||||||||||||||||
| 1374 | delete takeAt(i); | - | ||||||||||||||||||||||||
| 1375 | invalidate(); | - | ||||||||||||||||||||||||
| 1376 | } else { | - | ||||||||||||||||||||||||
| 1377 | ++i; | - | ||||||||||||||||||||||||
| 1378 | } | - | ||||||||||||||||||||||||
| 1379 | } | - | ||||||||||||||||||||||||
| 1380 | } | - | ||||||||||||||||||||||||
| 1381 | - | |||||||||||||||||||||||||
| 1382 | /*! | - | ||||||||||||||||||||||||
| 1383 | Removes the layout item \a item from the layout. It is the | - | ||||||||||||||||||||||||
| 1384 | caller's responsibility to delete the item. | - | ||||||||||||||||||||||||
| 1385 | - | |||||||||||||||||||||||||
| 1386 | Notice that \a item can be a layout (since QLayout inherits | - | ||||||||||||||||||||||||
| 1387 | QLayoutItem). | - | ||||||||||||||||||||||||
| 1388 | - | |||||||||||||||||||||||||
| 1389 | \sa removeWidget(), addItem() | - | ||||||||||||||||||||||||
| 1390 | */ | - | ||||||||||||||||||||||||
| 1391 | void QLayout::removeItem(QLayoutItem *item) | - | ||||||||||||||||||||||||
| 1392 | { | - | ||||||||||||||||||||||||
| 1393 | int i = 0; | - | ||||||||||||||||||||||||
| 1394 | QLayoutItem *child; | - | ||||||||||||||||||||||||
| 1395 | while ((child = itemAt(i))) { | - | ||||||||||||||||||||||||
| 1396 | if (child == item) { | - | ||||||||||||||||||||||||
| 1397 | takeAt(i); | - | ||||||||||||||||||||||||
| 1398 | invalidate(); | - | ||||||||||||||||||||||||
| 1399 | } else { | - | ||||||||||||||||||||||||
| 1400 | ++i; | - | ||||||||||||||||||||||||
| 1401 | } | - | ||||||||||||||||||||||||
| 1402 | } | - | ||||||||||||||||||||||||
| 1403 | } | - | ||||||||||||||||||||||||
| 1404 | - | |||||||||||||||||||||||||
| 1405 | /*! | - | ||||||||||||||||||||||||
| 1406 | Enables this layout if \a enable is true, otherwise disables it. | - | ||||||||||||||||||||||||
| 1407 | - | |||||||||||||||||||||||||
| 1408 | An enabled layout adjusts dynamically to changes; a disabled | - | ||||||||||||||||||||||||
| 1409 | layout acts as if it did not exist. | - | ||||||||||||||||||||||||
| 1410 | - | |||||||||||||||||||||||||
| 1411 | By default all layouts are enabled. | - | ||||||||||||||||||||||||
| 1412 | - | |||||||||||||||||||||||||
| 1413 | \sa isEnabled() | - | ||||||||||||||||||||||||
| 1414 | */ | - | ||||||||||||||||||||||||
| 1415 | void QLayout::setEnabled(bool enable) | - | ||||||||||||||||||||||||
| 1416 | { | - | ||||||||||||||||||||||||
| 1417 | Q_D(QLayout); | - | ||||||||||||||||||||||||
| 1418 | d->enabled = enable; | - | ||||||||||||||||||||||||
| 1419 | } | - | ||||||||||||||||||||||||
| 1420 | - | |||||||||||||||||||||||||
| 1421 | /*! | - | ||||||||||||||||||||||||
| 1422 | Returns \c true if the layout is enabled; otherwise returns \c false. | - | ||||||||||||||||||||||||
| 1423 | - | |||||||||||||||||||||||||
| 1424 | \sa setEnabled() | - | ||||||||||||||||||||||||
| 1425 | */ | - | ||||||||||||||||||||||||
| 1426 | bool QLayout::isEnabled() const | - | ||||||||||||||||||||||||
| 1427 | { | - | ||||||||||||||||||||||||
| 1428 | Q_D(const QLayout); | - | ||||||||||||||||||||||||
| 1429 | return d->enabled; | - | ||||||||||||||||||||||||
| 1430 | } | - | ||||||||||||||||||||||||
| 1431 | - | |||||||||||||||||||||||||
| 1432 | /*! | - | ||||||||||||||||||||||||
| 1433 | Returns a size that satisfies all size constraints on \a widget, | - | ||||||||||||||||||||||||
| 1434 | including heightForWidth() and that is as close as possible to \a | - | ||||||||||||||||||||||||
| 1435 | size. | - | ||||||||||||||||||||||||
| 1436 | */ | - | ||||||||||||||||||||||||
| 1437 | - | |||||||||||||||||||||||||
| 1438 | QSize QLayout::closestAcceptableSize(const QWidget *widget, const QSize &size) | - | ||||||||||||||||||||||||
| 1439 | { | - | ||||||||||||||||||||||||
| 1440 | QSize result = size.boundedTo(qSmartMaxSize(widget)); | - | ||||||||||||||||||||||||
| 1441 | result = result.expandedTo(qSmartMinSize(widget)); | - | ||||||||||||||||||||||||
| 1442 | QLayout *l = widget->layout(); | - | ||||||||||||||||||||||||
| 1443 | if (l && l->hasHeightForWidth() && result.height() < l->minimumHeightForWidth(result.width()) ) { | - | ||||||||||||||||||||||||
| 1444 | QSize current = widget->size(); | - | ||||||||||||||||||||||||
| 1445 | int currentHfw = l->minimumHeightForWidth(current.width()); | - | ||||||||||||||||||||||||
| 1446 | int newHfw = l->minimumHeightForWidth(result.width()); | - | ||||||||||||||||||||||||
| 1447 | if (current.height() < currentHfw || currentHfw == newHfw) { | - | ||||||||||||||||||||||||
| 1448 | //handle the constant hfw case and the vertical-only case, as well as the | - | ||||||||||||||||||||||||
| 1449 | // current-size-is-not-correct case | - | ||||||||||||||||||||||||
| 1450 | result.setHeight(newHfw); | - | ||||||||||||||||||||||||
| 1451 | } else { | - | ||||||||||||||||||||||||
| 1452 | // binary search; assume hfw is decreasing ### | - | ||||||||||||||||||||||||
| 1453 | - | |||||||||||||||||||||||||
| 1454 | int maxw = qMax(widget->width(),result.width()); | - | ||||||||||||||||||||||||
| 1455 | int maxh = qMax(widget->height(), result.height()); | - | ||||||||||||||||||||||||
| 1456 | int minw = qMin(widget->width(),result.width()); | - | ||||||||||||||||||||||||
| 1457 | int minh = qMin(widget->height(), result.height()); | - | ||||||||||||||||||||||||
| 1458 | - | |||||||||||||||||||||||||
| 1459 | int minhfw = l->minimumHeightForWidth(minw); | - | ||||||||||||||||||||||||
| 1460 | int maxhfw = l->minimumHeightForWidth(maxw); | - | ||||||||||||||||||||||||
| 1461 | while (minw < maxw) { | - | ||||||||||||||||||||||||
| 1462 | if (minhfw > maxh) { //assume decreasing | - | ||||||||||||||||||||||||
| 1463 | minw = maxw - (maxw-minw)/2; | - | ||||||||||||||||||||||||
| 1464 | minhfw = l->minimumHeightForWidth(minw); | - | ||||||||||||||||||||||||
| 1465 | } else if (maxhfw < minh ) { //assume decreasing | - | ||||||||||||||||||||||||
| 1466 | maxw = minw + (maxw-minw)/2; | - | ||||||||||||||||||||||||
| 1467 | maxhfw = l->minimumHeightForWidth(maxw); | - | ||||||||||||||||||||||||
| 1468 | } else { | - | ||||||||||||||||||||||||
| 1469 | break; | - | ||||||||||||||||||||||||
| 1470 | } | - | ||||||||||||||||||||||||
| 1471 | } | - | ||||||||||||||||||||||||
| 1472 | result = result.expandedTo(QSize(minw, minhfw)); | - | ||||||||||||||||||||||||
| 1473 | } | - | ||||||||||||||||||||||||
| 1474 | } | - | ||||||||||||||||||||||||
| 1475 | return result; | - | ||||||||||||||||||||||||
| 1476 | } | - | ||||||||||||||||||||||||
| 1477 | - | |||||||||||||||||||||||||
| 1478 | QT_END_NAMESPACE | - | ||||||||||||||||||||||||
| 1479 | - | |||||||||||||||||||||||||
| 1480 | #include "moc_qlayout.cpp" | - | ||||||||||||||||||||||||
| Source code | Switch to Preprocessed file |