| Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/widgets/graphicsview/qgraphicslayoutitem.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 "qglobal.h" | - | ||||||||||||||||||
| 41 | - | |||||||||||||||||||
| 42 | #ifndef QT_NO_GRAPHICSVIEW | - | ||||||||||||||||||
| 43 | - | |||||||||||||||||||
| 44 | #include "qgraphicslayout.h" | - | ||||||||||||||||||
| 45 | #include "qgraphicsscene.h" | - | ||||||||||||||||||
| 46 | #include "qgraphicslayoutitem.h" | - | ||||||||||||||||||
| 47 | #include "qgraphicslayoutitem_p.h" | - | ||||||||||||||||||
| 48 | #include "qwidget.h" | - | ||||||||||||||||||
| 49 | #include "qgraphicswidget.h" | - | ||||||||||||||||||
| 50 | - | |||||||||||||||||||
| 51 | #include <QtDebug> | - | ||||||||||||||||||
| 52 | - | |||||||||||||||||||
| 53 | QT_BEGIN_NAMESPACE | - | ||||||||||||||||||
| 54 | - | |||||||||||||||||||
| 55 | /* | - | ||||||||||||||||||
| 56 | COMBINE_SIZE() is identical to combineSize(), except that it | - | ||||||||||||||||||
| 57 | doesn't evaluate 'size' unless necessary. | - | ||||||||||||||||||
| 58 | */ | - | ||||||||||||||||||
| 59 | #define COMBINE_SIZE(result, size) \ | - | ||||||||||||||||||
| 60 | do { \ | - | ||||||||||||||||||
| 61 | if ((result).width() < 0 || (result).height() < 0) \ | - | ||||||||||||||||||
| 62 | combineSize((result), (size)); \ | - | ||||||||||||||||||
| 63 | } while (false) | - | ||||||||||||||||||
| 64 | - | |||||||||||||||||||
| 65 | static void combineSize(QSizeF &result, const QSizeF &size) | - | ||||||||||||||||||
| 66 | { | - | ||||||||||||||||||
| 67 | if (result.width() < 0)
| 0 | ||||||||||||||||||
| 68 | result.setWidth(size.width()); never executed: result.setWidth(size.width()); | 0 | ||||||||||||||||||
| 69 | if (result.height() < 0)
| 0 | ||||||||||||||||||
| 70 | result.setHeight(size.height()); never executed: result.setHeight(size.height()); | 0 | ||||||||||||||||||
| 71 | } never executed: end of block | 0 | ||||||||||||||||||
| 72 | - | |||||||||||||||||||
| 73 | static void boundSize(QSizeF &result, const QSizeF &size) | - | ||||||||||||||||||
| 74 | { | - | ||||||||||||||||||
| 75 | if (size.width() >= 0 && size.width() < result.width())
| 0 | ||||||||||||||||||
| 76 | result.setWidth(size.width()); never executed: result.setWidth(size.width()); | 0 | ||||||||||||||||||
| 77 | if (size.height() >= 0 && size.height() < result.height())
| 0 | ||||||||||||||||||
| 78 | result.setHeight(size.height()); never executed: result.setHeight(size.height()); | 0 | ||||||||||||||||||
| 79 | } never executed: end of block | 0 | ||||||||||||||||||
| 80 | - | |||||||||||||||||||
| 81 | static void expandSize(QSizeF &result, const QSizeF &size) | - | ||||||||||||||||||
| 82 | { | - | ||||||||||||||||||
| 83 | if (size.width() >= 0 && size.width() > result.width())
| 0 | ||||||||||||||||||
| 84 | result.setWidth(size.width()); never executed: result.setWidth(size.width()); | 0 | ||||||||||||||||||
| 85 | if (size.height() >= 0 && size.height() > result.height())
| 0 | ||||||||||||||||||
| 86 | result.setHeight(size.height()); never executed: result.setHeight(size.height()); | 0 | ||||||||||||||||||
| 87 | } never executed: end of block | 0 | ||||||||||||||||||
| 88 | - | |||||||||||||||||||
| 89 | static void normalizeHints(qreal &minimum, qreal &preferred, qreal &maximum, qreal &descent) | - | ||||||||||||||||||
| 90 | { | - | ||||||||||||||||||
| 91 | if (minimum >= 0 && maximum >= 0 && minimum > maximum)
| 0 | ||||||||||||||||||
| 92 | minimum = maximum; never executed: minimum = maximum; | 0 | ||||||||||||||||||
| 93 | - | |||||||||||||||||||
| 94 | if (preferred >= 0) {
| 0 | ||||||||||||||||||
| 95 | if (minimum >= 0 && preferred < minimum) {
| 0 | ||||||||||||||||||
| 96 | preferred = minimum; | - | ||||||||||||||||||
| 97 | } else if (maximum >= 0 && preferred > maximum) { never executed: end of block
| 0 | ||||||||||||||||||
| 98 | preferred = maximum; | - | ||||||||||||||||||
| 99 | } never executed: end of block | 0 | ||||||||||||||||||
| 100 | } never executed: end of block | 0 | ||||||||||||||||||
| 101 | - | |||||||||||||||||||
| 102 | if (minimum >= 0 && descent > minimum)
| 0 | ||||||||||||||||||
| 103 | descent = minimum; never executed: descent = minimum; | 0 | ||||||||||||||||||
| 104 | } never executed: end of block | 0 | ||||||||||||||||||
| 105 | - | |||||||||||||||||||
| 106 | /*! | - | ||||||||||||||||||
| 107 | \internal | - | ||||||||||||||||||
| 108 | */ | - | ||||||||||||||||||
| 109 | QGraphicsLayoutItemPrivate::QGraphicsLayoutItemPrivate(QGraphicsLayoutItem *par, bool layout) | - | ||||||||||||||||||
| 110 | : parent(par), userSizeHints(0), isLayout(layout), ownedByLayout(false), graphicsItem(0) | - | ||||||||||||||||||
| 111 | { | - | ||||||||||||||||||
| 112 | } never executed: end of block | 0 | ||||||||||||||||||
| 113 | - | |||||||||||||||||||
| 114 | /*! | - | ||||||||||||||||||
| 115 | \internal | - | ||||||||||||||||||
| 116 | */ | - | ||||||||||||||||||
| 117 | QGraphicsLayoutItemPrivate::~QGraphicsLayoutItemPrivate() | - | ||||||||||||||||||
| 118 | { | - | ||||||||||||||||||
| 119 | // Remove any lazily allocated data | - | ||||||||||||||||||
| 120 | delete[] userSizeHints; | - | ||||||||||||||||||
| 121 | } never executed: end of block | 0 | ||||||||||||||||||
| 122 | - | |||||||||||||||||||
| 123 | /*! | - | ||||||||||||||||||
| 124 | \internal | - | ||||||||||||||||||
| 125 | */ | - | ||||||||||||||||||
| 126 | void QGraphicsLayoutItemPrivate::init() | - | ||||||||||||||||||
| 127 | { | - | ||||||||||||||||||
| 128 | sizeHintCacheDirty = true; | - | ||||||||||||||||||
| 129 | sizeHintWithConstraintCacheDirty = true; | - | ||||||||||||||||||
| 130 | } never executed: end of block | 0 | ||||||||||||||||||
| 131 | - | |||||||||||||||||||
| 132 | /*! | - | ||||||||||||||||||
| 133 | \internal | - | ||||||||||||||||||
| 134 | */ | - | ||||||||||||||||||
| 135 | QSizeF *QGraphicsLayoutItemPrivate::effectiveSizeHints(const QSizeF &constraint) const | - | ||||||||||||||||||
| 136 | { | - | ||||||||||||||||||
| 137 | Q_Q(const QGraphicsLayoutItem); | - | ||||||||||||||||||
| 138 | QSizeF *sizeHintCache; | - | ||||||||||||||||||
| 139 | const bool hasConstraint = constraint.width() >= 0 || constraint.height() >= 0;
| 0 | ||||||||||||||||||
| 140 | if (hasConstraint) {
| 0 | ||||||||||||||||||
| 141 | if (!sizeHintWithConstraintCacheDirty && constraint == cachedConstraint)
| 0 | ||||||||||||||||||
| 142 | return cachedSizeHintsWithConstraints; never executed: return cachedSizeHintsWithConstraints; | 0 | ||||||||||||||||||
| 143 | sizeHintCache = cachedSizeHintsWithConstraints; | - | ||||||||||||||||||
| 144 | } else { never executed: end of block | 0 | ||||||||||||||||||
| 145 | if (!sizeHintCacheDirty)
| 0 | ||||||||||||||||||
| 146 | return cachedSizeHints; never executed: return cachedSizeHints; | 0 | ||||||||||||||||||
| 147 | sizeHintCache = cachedSizeHints; | - | ||||||||||||||||||
| 148 | } never executed: end of block | 0 | ||||||||||||||||||
| 149 | - | |||||||||||||||||||
| 150 | for (int i = 0; i < Qt::NSizeHints; ++i) {
| 0 | ||||||||||||||||||
| 151 | sizeHintCache[i] = constraint; | - | ||||||||||||||||||
| 152 | if (userSizeHints)
| 0 | ||||||||||||||||||
| 153 | combineSize(sizeHintCache[i], userSizeHints[i]); never executed: combineSize(sizeHintCache[i], userSizeHints[i]); | 0 | ||||||||||||||||||
| 154 | } never executed: end of block | 0 | ||||||||||||||||||
| 155 | - | |||||||||||||||||||
| 156 | QSizeF &minS = sizeHintCache[Qt::MinimumSize]; | - | ||||||||||||||||||
| 157 | QSizeF &prefS = sizeHintCache[Qt::PreferredSize]; | - | ||||||||||||||||||
| 158 | QSizeF &maxS = sizeHintCache[Qt::MaximumSize]; | - | ||||||||||||||||||
| 159 | QSizeF &descentS = sizeHintCache[Qt::MinimumDescent]; | - | ||||||||||||||||||
| 160 | - | |||||||||||||||||||
| 161 | normalizeHints(minS.rwidth(), prefS.rwidth(), maxS.rwidth(), descentS.rwidth()); | - | ||||||||||||||||||
| 162 | normalizeHints(minS.rheight(), prefS.rheight(), maxS.rheight(), descentS.rheight()); | - | ||||||||||||||||||
| 163 | - | |||||||||||||||||||
| 164 | // if the minimum, preferred and maximum sizes contradict each other | - | ||||||||||||||||||
| 165 | // (e.g. the minimum is larger than the maximum) we give priority to | - | ||||||||||||||||||
| 166 | // the maximum size, then the minimum size and finally the preferred size | - | ||||||||||||||||||
| 167 | COMBINE_SIZE(maxS, q->sizeHint(Qt::MaximumSize, maxS)); never executed: combineSize((maxS), (q->sizeHint(Qt::MaximumSize, maxS)));
| 0 | ||||||||||||||||||
| 168 | combineSize(maxS, QSizeF(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX)); | - | ||||||||||||||||||
| 169 | expandSize(maxS, prefS); | - | ||||||||||||||||||
| 170 | expandSize(maxS, minS); | - | ||||||||||||||||||
| 171 | boundSize(maxS, QSizeF(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX)); | - | ||||||||||||||||||
| 172 | - | |||||||||||||||||||
| 173 | COMBINE_SIZE(minS, q->sizeHint(Qt::MinimumSize, minS)); never executed: combineSize((minS), (q->sizeHint(Qt::MinimumSize, minS)));
| 0 | ||||||||||||||||||
| 174 | expandSize(minS, QSizeF(0, 0)); | - | ||||||||||||||||||
| 175 | boundSize(minS, prefS); | - | ||||||||||||||||||
| 176 | boundSize(minS, maxS); | - | ||||||||||||||||||
| 177 | - | |||||||||||||||||||
| 178 | COMBINE_SIZE(prefS, q->sizeHint(Qt::PreferredSize, prefS)); never executed: combineSize((prefS), (q->sizeHint(Qt::PreferredSize, prefS)));
| 0 | ||||||||||||||||||
| 179 | expandSize(prefS, minS); | - | ||||||||||||||||||
| 180 | boundSize(prefS, maxS); | - | ||||||||||||||||||
| 181 | - | |||||||||||||||||||
| 182 | // Not supported yet | - | ||||||||||||||||||
| 183 | // COMBINE_SIZE(descentS, q->sizeHint(Qt::MinimumDescent, constraint)); | - | ||||||||||||||||||
| 184 | - | |||||||||||||||||||
| 185 | if (hasConstraint) {
| 0 | ||||||||||||||||||
| 186 | cachedConstraint = constraint; | - | ||||||||||||||||||
| 187 | sizeHintWithConstraintCacheDirty = false; | - | ||||||||||||||||||
| 188 | } else { never executed: end of block | 0 | ||||||||||||||||||
| 189 | sizeHintCacheDirty = false; | - | ||||||||||||||||||
| 190 | } never executed: end of block | 0 | ||||||||||||||||||
| 191 | return sizeHintCache; never executed: return sizeHintCache; | 0 | ||||||||||||||||||
| 192 | } | - | ||||||||||||||||||
| 193 | - | |||||||||||||||||||
| 194 | - | |||||||||||||||||||
| 195 | /*! | - | ||||||||||||||||||
| 196 | \internal | - | ||||||||||||||||||
| 197 | - | |||||||||||||||||||
| 198 | Returns the parent item of this layout, or 0 if this layout is | - | ||||||||||||||||||
| 199 | not installed on any widget. | - | ||||||||||||||||||
| 200 | - | |||||||||||||||||||
| 201 | If this is the item that the layout is installed on, it will return "itself". | - | ||||||||||||||||||
| 202 | - | |||||||||||||||||||
| 203 | If the layout is a sub-layout, this function returns the parent | - | ||||||||||||||||||
| 204 | widget of the parent layout. | - | ||||||||||||||||||
| 205 | - | |||||||||||||||||||
| 206 | Note that it will traverse up the layout item hierarchy instead of just calling | - | ||||||||||||||||||
| 207 | QGraphicsItem::parentItem(). This is on purpose. | - | ||||||||||||||||||
| 208 | - | |||||||||||||||||||
| 209 | \sa parent() | - | ||||||||||||||||||
| 210 | */ | - | ||||||||||||||||||
| 211 | QGraphicsItem *QGraphicsLayoutItemPrivate::parentItem() const | - | ||||||||||||||||||
| 212 | { | - | ||||||||||||||||||
| 213 | Q_Q(const QGraphicsLayoutItem); | - | ||||||||||||||||||
| 214 | - | |||||||||||||||||||
| 215 | const QGraphicsLayoutItem *parent = q; | - | ||||||||||||||||||
| 216 | while (parent && parent->isLayout()) {
| 0 | ||||||||||||||||||
| 217 | parent = parent->parentLayoutItem(); | - | ||||||||||||||||||
| 218 | } never executed: end of block | 0 | ||||||||||||||||||
| 219 | return parent ? parent->graphicsItem() : 0; never executed: return parent ? parent->graphicsItem() : 0; | 0 | ||||||||||||||||||
| 220 | } | - | ||||||||||||||||||
| 221 | - | |||||||||||||||||||
| 222 | /*! | - | ||||||||||||||||||
| 223 | \internal | - | ||||||||||||||||||
| 224 | - | |||||||||||||||||||
| 225 | Ensures that userSizeHints is allocated. | - | ||||||||||||||||||
| 226 | This function must be called before any dereferencing. | - | ||||||||||||||||||
| 227 | */ | - | ||||||||||||||||||
| 228 | void QGraphicsLayoutItemPrivate::ensureUserSizeHints() | - | ||||||||||||||||||
| 229 | { | - | ||||||||||||||||||
| 230 | if (!userSizeHints)
| 0 | ||||||||||||||||||
| 231 | userSizeHints = new QSizeF[Qt::NSizeHints]; never executed: userSizeHints = new QSizeF[Qt::NSizeHints]; | 0 | ||||||||||||||||||
| 232 | } never executed: end of block | 0 | ||||||||||||||||||
| 233 | - | |||||||||||||||||||
| 234 | /*! | - | ||||||||||||||||||
| 235 | \internal | - | ||||||||||||||||||
| 236 | - | |||||||||||||||||||
| 237 | Sets the user size hint \a which to \a size. Use an invalid size to unset the size hint. | - | ||||||||||||||||||
| 238 | */ | - | ||||||||||||||||||
| 239 | void QGraphicsLayoutItemPrivate::setSize(Qt::SizeHint which, const QSizeF &size) | - | ||||||||||||||||||
| 240 | { | - | ||||||||||||||||||
| 241 | Q_Q(QGraphicsLayoutItem); | - | ||||||||||||||||||
| 242 | - | |||||||||||||||||||
| 243 | if (userSizeHints) {
| 0 | ||||||||||||||||||
| 244 | if (size == userSizeHints[which])
| 0 | ||||||||||||||||||
| 245 | return; never executed: return; | 0 | ||||||||||||||||||
| 246 | } else if (size.width() < 0 && size.height() < 0) { never executed: end of block
| 0 | ||||||||||||||||||
| 247 | return; never executed: return; | 0 | ||||||||||||||||||
| 248 | } | - | ||||||||||||||||||
| 249 | - | |||||||||||||||||||
| 250 | ensureUserSizeHints(); | - | ||||||||||||||||||
| 251 | userSizeHints[which] = size; | - | ||||||||||||||||||
| 252 | q->updateGeometry(); | - | ||||||||||||||||||
| 253 | } never executed: end of block | 0 | ||||||||||||||||||
| 254 | - | |||||||||||||||||||
| 255 | /*! | - | ||||||||||||||||||
| 256 | \internal | - | ||||||||||||||||||
| 257 | - | |||||||||||||||||||
| 258 | Sets the width of the user size hint \a which to \a width. | - | ||||||||||||||||||
| 259 | */ | - | ||||||||||||||||||
| 260 | void QGraphicsLayoutItemPrivate::setSizeComponent( | - | ||||||||||||||||||
| 261 | Qt::SizeHint which, SizeComponent component, qreal value) | - | ||||||||||||||||||
| 262 | { | - | ||||||||||||||||||
| 263 | Q_Q(QGraphicsLayoutItem); | - | ||||||||||||||||||
| 264 | ensureUserSizeHints(); | - | ||||||||||||||||||
| 265 | qreal &userValue = (component == Width)
| 0 | ||||||||||||||||||
| 266 | ? userSizeHints[which].rwidth() | - | ||||||||||||||||||
| 267 | : userSizeHints[which].rheight(); | - | ||||||||||||||||||
| 268 | if (value == userValue)
| 0 | ||||||||||||||||||
| 269 | return; never executed: return; | 0 | ||||||||||||||||||
| 270 | userValue = value; | - | ||||||||||||||||||
| 271 | q->updateGeometry(); | - | ||||||||||||||||||
| 272 | } never executed: end of block | 0 | ||||||||||||||||||
| 273 | - | |||||||||||||||||||
| 274 | - | |||||||||||||||||||
| 275 | bool QGraphicsLayoutItemPrivate::hasHeightForWidth() const | - | ||||||||||||||||||
| 276 | { | - | ||||||||||||||||||
| 277 | Q_Q(const QGraphicsLayoutItem); | - | ||||||||||||||||||
| 278 | if (isLayout) {
| 0 | ||||||||||||||||||
| 279 | const QGraphicsLayout *l = static_cast<const QGraphicsLayout *>(q); | - | ||||||||||||||||||
| 280 | for (int i = l->count() - 1; i >= 0; --i) {
| 0 | ||||||||||||||||||
| 281 | if (QGraphicsLayoutItemPrivate::get(l->itemAt(i))->hasHeightForWidth())
| 0 | ||||||||||||||||||
| 282 | return true; never executed: return true; | 0 | ||||||||||||||||||
| 283 | } never executed: end of block | 0 | ||||||||||||||||||
| 284 | } else if (QGraphicsItem *item = q->graphicsItem()) { never executed: end of block
| 0 | ||||||||||||||||||
| 285 | if (item->isWidget()) {
| 0 | ||||||||||||||||||
| 286 | QGraphicsWidget *w = static_cast<QGraphicsWidget *>(item); | - | ||||||||||||||||||
| 287 | if (w->layout()) {
| 0 | ||||||||||||||||||
| 288 | return QGraphicsLayoutItemPrivate::get(w->layout())->hasHeightForWidth(); never executed: return QGraphicsLayoutItemPrivate::get(w->layout())->hasHeightForWidth(); | 0 | ||||||||||||||||||
| 289 | } | - | ||||||||||||||||||
| 290 | } never executed: end of block | 0 | ||||||||||||||||||
| 291 | } never executed: end of block | 0 | ||||||||||||||||||
| 292 | return q->sizePolicy().hasHeightForWidth(); never executed: return q->sizePolicy().hasHeightForWidth(); | 0 | ||||||||||||||||||
| 293 | } | - | ||||||||||||||||||
| 294 | - | |||||||||||||||||||
| 295 | bool QGraphicsLayoutItemPrivate::hasWidthForHeight() const | - | ||||||||||||||||||
| 296 | { | - | ||||||||||||||||||
| 297 | Q_Q(const QGraphicsLayoutItem); | - | ||||||||||||||||||
| 298 | if (isLayout) {
| 0 | ||||||||||||||||||
| 299 | const QGraphicsLayout *l = static_cast<const QGraphicsLayout *>(q); | - | ||||||||||||||||||
| 300 | for (int i = l->count() - 1; i >= 0; --i) {
| 0 | ||||||||||||||||||
| 301 | if (QGraphicsLayoutItemPrivate::get(l->itemAt(i))->hasWidthForHeight())
| 0 | ||||||||||||||||||
| 302 | return true; never executed: return true; | 0 | ||||||||||||||||||
| 303 | } never executed: end of block | 0 | ||||||||||||||||||
| 304 | } else if (QGraphicsItem *item = q->graphicsItem()) { never executed: end of block
| 0 | ||||||||||||||||||
| 305 | if (item->isWidget()) {
| 0 | ||||||||||||||||||
| 306 | QGraphicsWidget *w = static_cast<QGraphicsWidget *>(item); | - | ||||||||||||||||||
| 307 | if (w->layout()) {
| 0 | ||||||||||||||||||
| 308 | return QGraphicsLayoutItemPrivate::get(w->layout())->hasWidthForHeight(); never executed: return QGraphicsLayoutItemPrivate::get(w->layout())->hasWidthForHeight(); | 0 | ||||||||||||||||||
| 309 | } | - | ||||||||||||||||||
| 310 | } never executed: end of block | 0 | ||||||||||||||||||
| 311 | } never executed: end of block | 0 | ||||||||||||||||||
| 312 | return q->sizePolicy().hasWidthForHeight(); never executed: return q->sizePolicy().hasWidthForHeight(); | 0 | ||||||||||||||||||
| 313 | } | - | ||||||||||||||||||
| 314 | - | |||||||||||||||||||
| 315 | /*! | - | ||||||||||||||||||
| 316 | \class QGraphicsLayoutItem | - | ||||||||||||||||||
| 317 | \brief The QGraphicsLayoutItem class can be inherited to allow your custom | - | ||||||||||||||||||
| 318 | items to be managed by layouts. | - | ||||||||||||||||||
| 319 | \since 4.4 | - | ||||||||||||||||||
| 320 | \ingroup graphicsview-api | - | ||||||||||||||||||
| 321 | \inmodule QtWidgets | - | ||||||||||||||||||
| 322 | - | |||||||||||||||||||
| 323 | QGraphicsLayoutItem is an abstract class that defines a set of virtual | - | ||||||||||||||||||
| 324 | functions describing sizes, size policies, and size hints for any object | - | ||||||||||||||||||
| 325 | arranged by QGraphicsLayout. The API contains functions relevant | - | ||||||||||||||||||
| 326 | for both the item itself and for the user of the item as most of | - | ||||||||||||||||||
| 327 | QGraphicsLayoutItem's functions are also part of the subclass' public API. | - | ||||||||||||||||||
| 328 | - | |||||||||||||||||||
| 329 | In most cases, existing layout-aware classes such as QGraphicsWidget and | - | ||||||||||||||||||
| 330 | QGraphicsLayout already provide the functionality you require. However, | - | ||||||||||||||||||
| 331 | subclassing these classes will enable you to create both graphical | - | ||||||||||||||||||
| 332 | elements that work well with layouts (QGraphicsWidget) or custom layouts | - | ||||||||||||||||||
| 333 | (QGraphicsLayout). | - | ||||||||||||||||||
| 334 | - | |||||||||||||||||||
| 335 | \section1 Subclassing QGraphicsLayoutItem | - | ||||||||||||||||||
| 336 | - | |||||||||||||||||||
| 337 | If you create a subclass of QGraphicsLayoutItem and reimplement its | - | ||||||||||||||||||
| 338 | virtual functions, you will enable the layout to resize and position your | - | ||||||||||||||||||
| 339 | item along with other QGraphicsLayoutItems including QGraphicsWidget | - | ||||||||||||||||||
| 340 | and QGraphicsLayout. | - | ||||||||||||||||||
| 341 | - | |||||||||||||||||||
| 342 | You can start by reimplementing important functions: the protected | - | ||||||||||||||||||
| 343 | sizeHint() function, as well as the public setGeometry() | - | ||||||||||||||||||
| 344 | function. If you want your items to be aware of immediate geometry | - | ||||||||||||||||||
| 345 | changes, you can also reimplement updateGeometry(). | - | ||||||||||||||||||
| 346 | - | |||||||||||||||||||
| 347 | The geometry, size hint, and size policy affect the item's size and | - | ||||||||||||||||||
| 348 | position. Calling setGeometry() will always resize and reposition the item | - | ||||||||||||||||||
| 349 | immediately. Normally, this function is called by QGraphicsLayout after | - | ||||||||||||||||||
| 350 | the layout has been activated, but it can also be called by the item's user | - | ||||||||||||||||||
| 351 | at any time. | - | ||||||||||||||||||
| 352 | - | |||||||||||||||||||
| 353 | The sizeHint() function returns the item' minimum, preferred and maximum | - | ||||||||||||||||||
| 354 | size hints. You can override these properties by calling setMinimumSize(), | - | ||||||||||||||||||
| 355 | setPreferredSize() or setMaximumSize(). You can also use functions such as | - | ||||||||||||||||||
| 356 | setMinimumWidth() or setMaximumHeight() to set only the width or height | - | ||||||||||||||||||
| 357 | component if desired. | - | ||||||||||||||||||
| 358 | - | |||||||||||||||||||
| 359 | The effectiveSizeHint() function, on the other hand, returns a size hint | - | ||||||||||||||||||
| 360 | for any given Qt::SizeHint, and guarantees that the returned size is bound | - | ||||||||||||||||||
| 361 | to the minimum and maximum sizes and size hints. You can set the item's | - | ||||||||||||||||||
| 362 | vertical and horizontal size policy by calling setSizePolicy(). The | - | ||||||||||||||||||
| 363 | sizePolicy property is used by the layout system to describe how this item | - | ||||||||||||||||||
| 364 | prefers to grow or shrink. | - | ||||||||||||||||||
| 365 | - | |||||||||||||||||||
| 366 | \section1 Nesting QGraphicsLayoutItems | - | ||||||||||||||||||
| 367 | - | |||||||||||||||||||
| 368 | QGraphicsLayoutItems can be nested within other QGraphicsLayoutItems, | - | ||||||||||||||||||
| 369 | similar to layouts that can contain sublayouts. This is done either by | - | ||||||||||||||||||
| 370 | passing a QGraphicsLayoutItem pointer to QGraphicsLayoutItem's | - | ||||||||||||||||||
| 371 | protected constructor, or by calling setParentLayoutItem(). The | - | ||||||||||||||||||
| 372 | parentLayoutItem() function returns a pointer to the item's layoutItem | - | ||||||||||||||||||
| 373 | parent. If the item's parent is 0 or if the parent does not inherit | - | ||||||||||||||||||
| 374 | from QGraphicsItem, the parentLayoutItem() function then returns 0. | - | ||||||||||||||||||
| 375 | isLayout() returns \c true if the QGraphicsLayoutItem subclass is itself a | - | ||||||||||||||||||
| 376 | layout, or false otherwise. | - | ||||||||||||||||||
| 377 | - | |||||||||||||||||||
| 378 | Qt uses QGraphicsLayoutItem to provide layout functionality in the | - | ||||||||||||||||||
| 379 | \l{Graphics View Framework}, but in the future its use may spread | - | ||||||||||||||||||
| 380 | throughout Qt itself. | - | ||||||||||||||||||
| 381 | - | |||||||||||||||||||
| 382 | \sa QGraphicsWidget, QGraphicsLayout, QGraphicsLinearLayout, | - | ||||||||||||||||||
| 383 | QGraphicsGridLayout | - | ||||||||||||||||||
| 384 | */ | - | ||||||||||||||||||
| 385 | - | |||||||||||||||||||
| 386 | /*! | - | ||||||||||||||||||
| 387 | Constructs the QGraphicsLayoutItem object. \a parent becomes the object's | - | ||||||||||||||||||
| 388 | parent. If \a isLayout is true the item is a layout, otherwise | - | ||||||||||||||||||
| 389 | \a isLayout is false. | - | ||||||||||||||||||
| 390 | */ | - | ||||||||||||||||||
| 391 | QGraphicsLayoutItem::QGraphicsLayoutItem(QGraphicsLayoutItem *parent, bool isLayout) | - | ||||||||||||||||||
| 392 | : d_ptr(new QGraphicsLayoutItemPrivate(parent, isLayout)) | - | ||||||||||||||||||
| 393 | { | - | ||||||||||||||||||
| 394 | Q_D(QGraphicsLayoutItem); | - | ||||||||||||||||||
| 395 | d->init(); | - | ||||||||||||||||||
| 396 | d->sizePolicy = QSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); | - | ||||||||||||||||||
| 397 | d->q_ptr = this; | - | ||||||||||||||||||
| 398 | } never executed: end of block | 0 | ||||||||||||||||||
| 399 | - | |||||||||||||||||||
| 400 | /*! | - | ||||||||||||||||||
| 401 | \internal | - | ||||||||||||||||||
| 402 | */ | - | ||||||||||||||||||
| 403 | QGraphicsLayoutItem::QGraphicsLayoutItem(QGraphicsLayoutItemPrivate &dd) | - | ||||||||||||||||||
| 404 | : d_ptr(&dd) | - | ||||||||||||||||||
| 405 | { | - | ||||||||||||||||||
| 406 | Q_D(QGraphicsLayoutItem); | - | ||||||||||||||||||
| 407 | d->init(); | - | ||||||||||||||||||
| 408 | d->q_ptr = this; | - | ||||||||||||||||||
| 409 | } never executed: end of block | 0 | ||||||||||||||||||
| 410 | - | |||||||||||||||||||
| 411 | /*! | - | ||||||||||||||||||
| 412 | Destroys the QGraphicsLayoutItem object. | - | ||||||||||||||||||
| 413 | */ | - | ||||||||||||||||||
| 414 | QGraphicsLayoutItem::~QGraphicsLayoutItem() | - | ||||||||||||||||||
| 415 | { | - | ||||||||||||||||||
| 416 | QGraphicsLayoutItem *parentLI = parentLayoutItem(); | - | ||||||||||||||||||
| 417 | if (parentLI && parentLI->isLayout()) {
| 0 | ||||||||||||||||||
| 418 | QGraphicsLayout *lay = static_cast<QGraphicsLayout*>(parentLI); | - | ||||||||||||||||||
| 419 | // this is not optimal | - | ||||||||||||||||||
| 420 | for (int i = lay->count() - 1; i >= 0; --i) {
| 0 | ||||||||||||||||||
| 421 | if (lay->itemAt(i) == this) {
| 0 | ||||||||||||||||||
| 422 | lay->removeAt(i); | - | ||||||||||||||||||
| 423 | break; never executed: break; | 0 | ||||||||||||||||||
| 424 | } | - | ||||||||||||||||||
| 425 | } never executed: end of block | 0 | ||||||||||||||||||
| 426 | } never executed: end of block | 0 | ||||||||||||||||||
| 427 | } never executed: end of block | 0 | ||||||||||||||||||
| 428 | - | |||||||||||||||||||
| 429 | /*! | - | ||||||||||||||||||
| 430 | \fn virtual QSizeF QGraphicsLayoutItem::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const = 0; | - | ||||||||||||||||||
| 431 | - | |||||||||||||||||||
| 432 | This pure virtual function returns the size hint for \a which of the | - | ||||||||||||||||||
| 433 | QGraphicsLayoutItem, using the width or height of \a constraint to | - | ||||||||||||||||||
| 434 | constrain the output. | - | ||||||||||||||||||
| 435 | - | |||||||||||||||||||
| 436 | Reimplement this function in a subclass of QGraphicsLayoutItem to | - | ||||||||||||||||||
| 437 | provide the necessary size hints for your items. | - | ||||||||||||||||||
| 438 | - | |||||||||||||||||||
| 439 | \sa effectiveSizeHint() | - | ||||||||||||||||||
| 440 | */ | - | ||||||||||||||||||
| 441 | - | |||||||||||||||||||
| 442 | /*! | - | ||||||||||||||||||
| 443 | Sets the size policy to \a policy. The size policy describes how the item | - | ||||||||||||||||||
| 444 | should grow horizontally and vertically when arranged in a layout. | - | ||||||||||||||||||
| 445 | - | |||||||||||||||||||
| 446 | QGraphicsLayoutItem's default size policy is (QSizePolicy::Fixed, | - | ||||||||||||||||||
| 447 | QSizePolicy::Fixed, QSizePolicy::DefaultType), but it is common for | - | ||||||||||||||||||
| 448 | subclasses to change the default. For example, QGraphicsWidget defaults | - | ||||||||||||||||||
| 449 | to (QSizePolicy::Preferred, QSizePolicy::Preferred, | - | ||||||||||||||||||
| 450 | QSizePolicy::DefaultType). | - | ||||||||||||||||||
| 451 | - | |||||||||||||||||||
| 452 | \sa sizePolicy(), QWidget::sizePolicy() | - | ||||||||||||||||||
| 453 | */ | - | ||||||||||||||||||
| 454 | void QGraphicsLayoutItem::setSizePolicy(const QSizePolicy &policy) | - | ||||||||||||||||||
| 455 | { | - | ||||||||||||||||||
| 456 | Q_D(QGraphicsLayoutItem); | - | ||||||||||||||||||
| 457 | if (d->sizePolicy == policy)
| 0 | ||||||||||||||||||
| 458 | return; never executed: return; | 0 | ||||||||||||||||||
| 459 | d->sizePolicy = policy; | - | ||||||||||||||||||
| 460 | updateGeometry(); | - | ||||||||||||||||||
| 461 | } never executed: end of block | 0 | ||||||||||||||||||
| 462 | - | |||||||||||||||||||
| 463 | /*! | - | ||||||||||||||||||
| 464 | \overload | - | ||||||||||||||||||
| 465 | - | |||||||||||||||||||
| 466 | This function is equivalent to calling | - | ||||||||||||||||||
| 467 | setSizePolicy(QSizePolicy(\a hPolicy, \a vPolicy, \a controlType)). | - | ||||||||||||||||||
| 468 | - | |||||||||||||||||||
| 469 | \sa sizePolicy(), QWidget::sizePolicy() | - | ||||||||||||||||||
| 470 | */ | - | ||||||||||||||||||
| 471 | void QGraphicsLayoutItem::setSizePolicy(QSizePolicy::Policy hPolicy, | - | ||||||||||||||||||
| 472 | QSizePolicy::Policy vPolicy, | - | ||||||||||||||||||
| 473 | QSizePolicy::ControlType controlType) | - | ||||||||||||||||||
| 474 | { | - | ||||||||||||||||||
| 475 | setSizePolicy(QSizePolicy(hPolicy, vPolicy, controlType)); | - | ||||||||||||||||||
| 476 | } never executed: end of block | 0 | ||||||||||||||||||
| 477 | - | |||||||||||||||||||
| 478 | /*! | - | ||||||||||||||||||
| 479 | Returns the current size policy. | - | ||||||||||||||||||
| 480 | - | |||||||||||||||||||
| 481 | \sa setSizePolicy(), QWidget::sizePolicy() | - | ||||||||||||||||||
| 482 | */ | - | ||||||||||||||||||
| 483 | QSizePolicy QGraphicsLayoutItem::sizePolicy() const | - | ||||||||||||||||||
| 484 | { | - | ||||||||||||||||||
| 485 | Q_D(const QGraphicsLayoutItem); | - | ||||||||||||||||||
| 486 | return d->sizePolicy; never executed: return d->sizePolicy; | 0 | ||||||||||||||||||
| 487 | } | - | ||||||||||||||||||
| 488 | - | |||||||||||||||||||
| 489 | /*! | - | ||||||||||||||||||
| 490 | Sets the minimum size to \a size. This property overrides sizeHint() for | - | ||||||||||||||||||
| 491 | Qt::MinimumSize and ensures that effectiveSizeHint() will never return | - | ||||||||||||||||||
| 492 | a size smaller than \a size. In order to unset the minimum size, use an | - | ||||||||||||||||||
| 493 | invalid size. | - | ||||||||||||||||||
| 494 | - | |||||||||||||||||||
| 495 | \sa minimumSize(), maximumSize(), preferredSize(), Qt::MinimumSize, | - | ||||||||||||||||||
| 496 | sizeHint(), setMinimumWidth(), setMinimumHeight() | - | ||||||||||||||||||
| 497 | */ | - | ||||||||||||||||||
| 498 | void QGraphicsLayoutItem::setMinimumSize(const QSizeF &size) | - | ||||||||||||||||||
| 499 | { | - | ||||||||||||||||||
| 500 | d_ptr->setSize(Qt::MinimumSize, size); | - | ||||||||||||||||||
| 501 | } never executed: end of block | 0 | ||||||||||||||||||
| 502 | - | |||||||||||||||||||
| 503 | /*! | - | ||||||||||||||||||
| 504 | \fn QGraphicsLayoutItem::setMinimumSize(qreal w, qreal h) | - | ||||||||||||||||||
| 505 | - | |||||||||||||||||||
| 506 | This convenience function is equivalent to calling | - | ||||||||||||||||||
| 507 | setMinimumSize(QSizeF(\a w, \a h)). | - | ||||||||||||||||||
| 508 | - | |||||||||||||||||||
| 509 | \sa minimumSize(), setMaximumSize(), setPreferredSize(), sizeHint() | - | ||||||||||||||||||
| 510 | */ | - | ||||||||||||||||||
| 511 | - | |||||||||||||||||||
| 512 | /*! | - | ||||||||||||||||||
| 513 | Returns the minimum size. | - | ||||||||||||||||||
| 514 | - | |||||||||||||||||||
| 515 | \sa setMinimumSize(), preferredSize(), maximumSize(), Qt::MinimumSize, | - | ||||||||||||||||||
| 516 | sizeHint() | - | ||||||||||||||||||
| 517 | */ | - | ||||||||||||||||||
| 518 | QSizeF QGraphicsLayoutItem::minimumSize() const | - | ||||||||||||||||||
| 519 | { | - | ||||||||||||||||||
| 520 | return effectiveSizeHint(Qt::MinimumSize); never executed: return effectiveSizeHint(Qt::MinimumSize); | 0 | ||||||||||||||||||
| 521 | } | - | ||||||||||||||||||
| 522 | - | |||||||||||||||||||
| 523 | /*! | - | ||||||||||||||||||
| 524 | Sets the minimum width to \a width. | - | ||||||||||||||||||
| 525 | - | |||||||||||||||||||
| 526 | \sa minimumWidth(), setMinimumSize(), minimumSize() | - | ||||||||||||||||||
| 527 | */ | - | ||||||||||||||||||
| 528 | void QGraphicsLayoutItem::setMinimumWidth(qreal width) | - | ||||||||||||||||||
| 529 | { | - | ||||||||||||||||||
| 530 | d_ptr->setSizeComponent(Qt::MinimumSize, d_ptr->Width, width); | - | ||||||||||||||||||
| 531 | } never executed: end of block | 0 | ||||||||||||||||||
| 532 | - | |||||||||||||||||||
| 533 | /*! | - | ||||||||||||||||||
| 534 | Sets the minimum height to \a height. | - | ||||||||||||||||||
| 535 | - | |||||||||||||||||||
| 536 | \sa minimumHeight(), setMinimumSize(), minimumSize() | - | ||||||||||||||||||
| 537 | */ | - | ||||||||||||||||||
| 538 | void QGraphicsLayoutItem::setMinimumHeight(qreal height) | - | ||||||||||||||||||
| 539 | { | - | ||||||||||||||||||
| 540 | d_ptr->setSizeComponent(Qt::MinimumSize, d_ptr->Height, height); | - | ||||||||||||||||||
| 541 | } never executed: end of block | 0 | ||||||||||||||||||
| 542 | - | |||||||||||||||||||
| 543 | - | |||||||||||||||||||
| 544 | /*! | - | ||||||||||||||||||
| 545 | Sets the preferred size to \a size. This property overrides sizeHint() for | - | ||||||||||||||||||
| 546 | Qt::PreferredSize and provides the default value for effectiveSizeHint(). | - | ||||||||||||||||||
| 547 | In order to unset the preferred size, use an invalid size. | - | ||||||||||||||||||
| 548 | - | |||||||||||||||||||
| 549 | \sa preferredSize(), minimumSize(), maximumSize(), Qt::PreferredSize, | - | ||||||||||||||||||
| 550 | sizeHint() | - | ||||||||||||||||||
| 551 | */ | - | ||||||||||||||||||
| 552 | void QGraphicsLayoutItem::setPreferredSize(const QSizeF &size) | - | ||||||||||||||||||
| 553 | { | - | ||||||||||||||||||
| 554 | d_ptr->setSize(Qt::PreferredSize, size); | - | ||||||||||||||||||
| 555 | } never executed: end of block | 0 | ||||||||||||||||||
| 556 | - | |||||||||||||||||||
| 557 | /*! | - | ||||||||||||||||||
| 558 | \fn QGraphicsLayoutItem::setPreferredSize(qreal w, qreal h) | - | ||||||||||||||||||
| 559 | - | |||||||||||||||||||
| 560 | This convenience function is equivalent to calling | - | ||||||||||||||||||
| 561 | setPreferredSize(QSizeF(\a w, \a h)). | - | ||||||||||||||||||
| 562 | - | |||||||||||||||||||
| 563 | \sa preferredSize(), setMaximumSize(), setMinimumSize(), sizeHint() | - | ||||||||||||||||||
| 564 | */ | - | ||||||||||||||||||
| 565 | - | |||||||||||||||||||
| 566 | /*! | - | ||||||||||||||||||
| 567 | Returns the preferred size. | - | ||||||||||||||||||
| 568 | - | |||||||||||||||||||
| 569 | \sa setPreferredSize(), minimumSize(), maximumSize(), Qt::PreferredSize, | - | ||||||||||||||||||
| 570 | sizeHint() | - | ||||||||||||||||||
| 571 | */ | - | ||||||||||||||||||
| 572 | QSizeF QGraphicsLayoutItem::preferredSize() const | - | ||||||||||||||||||
| 573 | { | - | ||||||||||||||||||
| 574 | return effectiveSizeHint(Qt::PreferredSize); never executed: return effectiveSizeHint(Qt::PreferredSize); | 0 | ||||||||||||||||||
| 575 | } | - | ||||||||||||||||||
| 576 | - | |||||||||||||||||||
| 577 | /*! | - | ||||||||||||||||||
| 578 | Sets the preferred height to \a height. | - | ||||||||||||||||||
| 579 | - | |||||||||||||||||||
| 580 | \sa preferredWidth(), setPreferredSize(), preferredSize() | - | ||||||||||||||||||
| 581 | */ | - | ||||||||||||||||||
| 582 | void QGraphicsLayoutItem::setPreferredHeight(qreal height) | - | ||||||||||||||||||
| 583 | { | - | ||||||||||||||||||
| 584 | d_ptr->setSizeComponent(Qt::PreferredSize, d_ptr->Height, height); | - | ||||||||||||||||||
| 585 | } never executed: end of block | 0 | ||||||||||||||||||
| 586 | - | |||||||||||||||||||
| 587 | /*! | - | ||||||||||||||||||
| 588 | Sets the preferred width to \a width. | - | ||||||||||||||||||
| 589 | - | |||||||||||||||||||
| 590 | \sa preferredHeight(), setPreferredSize(), preferredSize() | - | ||||||||||||||||||
| 591 | */ | - | ||||||||||||||||||
| 592 | void QGraphicsLayoutItem::setPreferredWidth(qreal width) | - | ||||||||||||||||||
| 593 | { | - | ||||||||||||||||||
| 594 | d_ptr->setSizeComponent(Qt::PreferredSize, d_ptr->Width, width); | - | ||||||||||||||||||
| 595 | } never executed: end of block | 0 | ||||||||||||||||||
| 596 | - | |||||||||||||||||||
| 597 | /*! | - | ||||||||||||||||||
| 598 | Sets the maximum size to \a size. This property overrides sizeHint() for | - | ||||||||||||||||||
| 599 | Qt::MaximumSize and ensures that effectiveSizeHint() will never return a | - | ||||||||||||||||||
| 600 | size larger than \a size. In order to unset the maximum size, use an | - | ||||||||||||||||||
| 601 | invalid size. | - | ||||||||||||||||||
| 602 | - | |||||||||||||||||||
| 603 | \sa maximumSize(), minimumSize(), preferredSize(), Qt::MaximumSize, | - | ||||||||||||||||||
| 604 | sizeHint() | - | ||||||||||||||||||
| 605 | */ | - | ||||||||||||||||||
| 606 | void QGraphicsLayoutItem::setMaximumSize(const QSizeF &size) | - | ||||||||||||||||||
| 607 | { | - | ||||||||||||||||||
| 608 | d_ptr->setSize(Qt::MaximumSize, size); | - | ||||||||||||||||||
| 609 | } never executed: end of block | 0 | ||||||||||||||||||
| 610 | - | |||||||||||||||||||
| 611 | /*! | - | ||||||||||||||||||
| 612 | \fn QGraphicsLayoutItem::setMaximumSize(qreal w, qreal h) | - | ||||||||||||||||||
| 613 | - | |||||||||||||||||||
| 614 | This convenience function is equivalent to calling | - | ||||||||||||||||||
| 615 | setMaximumSize(QSizeF(\a w, \a h)). | - | ||||||||||||||||||
| 616 | - | |||||||||||||||||||
| 617 | \sa maximumSize(), setMinimumSize(), setPreferredSize(), sizeHint() | - | ||||||||||||||||||
| 618 | */ | - | ||||||||||||||||||
| 619 | - | |||||||||||||||||||
| 620 | /*! | - | ||||||||||||||||||
| 621 | Returns the maximum size. | - | ||||||||||||||||||
| 622 | - | |||||||||||||||||||
| 623 | \sa setMaximumSize(), minimumSize(), preferredSize(), Qt::MaximumSize, | - | ||||||||||||||||||
| 624 | sizeHint() | - | ||||||||||||||||||
| 625 | */ | - | ||||||||||||||||||
| 626 | QSizeF QGraphicsLayoutItem::maximumSize() const | - | ||||||||||||||||||
| 627 | { | - | ||||||||||||||||||
| 628 | return effectiveSizeHint(Qt::MaximumSize); never executed: return effectiveSizeHint(Qt::MaximumSize); | 0 | ||||||||||||||||||
| 629 | } | - | ||||||||||||||||||
| 630 | - | |||||||||||||||||||
| 631 | /*! | - | ||||||||||||||||||
| 632 | Sets the maximum width to \a width. | - | ||||||||||||||||||
| 633 | - | |||||||||||||||||||
| 634 | \sa maximumWidth(), setMaximumSize(), maximumSize() | - | ||||||||||||||||||
| 635 | */ | - | ||||||||||||||||||
| 636 | void QGraphicsLayoutItem::setMaximumWidth(qreal width) | - | ||||||||||||||||||
| 637 | { | - | ||||||||||||||||||
| 638 | d_ptr->setSizeComponent(Qt::MaximumSize, d_ptr->Width, width); | - | ||||||||||||||||||
| 639 | } never executed: end of block | 0 | ||||||||||||||||||
| 640 | - | |||||||||||||||||||
| 641 | /*! | - | ||||||||||||||||||
| 642 | Sets the maximum height to \a height. | - | ||||||||||||||||||
| 643 | - | |||||||||||||||||||
| 644 | \sa maximumHeight(), setMaximumSize(), maximumSize() | - | ||||||||||||||||||
| 645 | */ | - | ||||||||||||||||||
| 646 | void QGraphicsLayoutItem::setMaximumHeight(qreal height) | - | ||||||||||||||||||
| 647 | { | - | ||||||||||||||||||
| 648 | d_ptr->setSizeComponent(Qt::MaximumSize, d_ptr->Height, height); | - | ||||||||||||||||||
| 649 | } never executed: end of block | 0 | ||||||||||||||||||
| 650 | - | |||||||||||||||||||
| 651 | /*! | - | ||||||||||||||||||
| 652 | \fn qreal QGraphicsLayoutItem::minimumWidth() const | - | ||||||||||||||||||
| 653 | - | |||||||||||||||||||
| 654 | Returns the minimum width. | - | ||||||||||||||||||
| 655 | - | |||||||||||||||||||
| 656 | \sa setMinimumWidth(), setMinimumSize(), minimumSize() | - | ||||||||||||||||||
| 657 | */ | - | ||||||||||||||||||
| 658 | - | |||||||||||||||||||
| 659 | /*! | - | ||||||||||||||||||
| 660 | \fn qreal QGraphicsLayoutItem::minimumHeight() const | - | ||||||||||||||||||
| 661 | - | |||||||||||||||||||
| 662 | Returns the minimum height. | - | ||||||||||||||||||
| 663 | - | |||||||||||||||||||
| 664 | \sa setMinimumHeight(), setMinimumSize(), minimumSize() | - | ||||||||||||||||||
| 665 | */ | - | ||||||||||||||||||
| 666 | - | |||||||||||||||||||
| 667 | /*! | - | ||||||||||||||||||
| 668 | \fn qreal QGraphicsLayoutItem::preferredWidth() const | - | ||||||||||||||||||
| 669 | - | |||||||||||||||||||
| 670 | Returns the preferred width. | - | ||||||||||||||||||
| 671 | - | |||||||||||||||||||
| 672 | \sa setPreferredWidth(), setPreferredSize(), preferredSize() | - | ||||||||||||||||||
| 673 | */ | - | ||||||||||||||||||
| 674 | - | |||||||||||||||||||
| 675 | /*! | - | ||||||||||||||||||
| 676 | \fn qreal QGraphicsLayoutItem::preferredHeight() const | - | ||||||||||||||||||
| 677 | - | |||||||||||||||||||
| 678 | Returns the preferred height. | - | ||||||||||||||||||
| 679 | - | |||||||||||||||||||
| 680 | \sa setPreferredHeight(), setPreferredSize(), preferredSize() | - | ||||||||||||||||||
| 681 | */ | - | ||||||||||||||||||
| 682 | - | |||||||||||||||||||
| 683 | /*! | - | ||||||||||||||||||
| 684 | \fn qreal QGraphicsLayoutItem::maximumWidth() const | - | ||||||||||||||||||
| 685 | - | |||||||||||||||||||
| 686 | Returns the maximum width. | - | ||||||||||||||||||
| 687 | - | |||||||||||||||||||
| 688 | \sa setMaximumWidth(), setMaximumSize(), maximumSize() | - | ||||||||||||||||||
| 689 | */ | - | ||||||||||||||||||
| 690 | - | |||||||||||||||||||
| 691 | /*! | - | ||||||||||||||||||
| 692 | \fn qreal QGraphicsLayoutItem::maximumHeight() const | - | ||||||||||||||||||
| 693 | - | |||||||||||||||||||
| 694 | Returns the maximum height. | - | ||||||||||||||||||
| 695 | - | |||||||||||||||||||
| 696 | \sa setMaximumHeight(), setMaximumSize(), maximumSize() | - | ||||||||||||||||||
| 697 | */ | - | ||||||||||||||||||
| 698 | - | |||||||||||||||||||
| 699 | /*! | - | ||||||||||||||||||
| 700 | \fn virtual void QGraphicsLayoutItem::setGeometry(const QRectF &rect) | - | ||||||||||||||||||
| 701 | - | |||||||||||||||||||
| 702 | This virtual function sets the geometry of the QGraphicsLayoutItem to | - | ||||||||||||||||||
| 703 | \a rect, which is in parent coordinates (e.g., the top-left corner of \a rect | - | ||||||||||||||||||
| 704 | is equivalent to the item's position in parent coordinates). | - | ||||||||||||||||||
| 705 | - | |||||||||||||||||||
| 706 | You must reimplement this function in a subclass of QGraphicsLayoutItem to | - | ||||||||||||||||||
| 707 | receive geometry updates. The layout will call this function when it does a | - | ||||||||||||||||||
| 708 | rearrangement. | - | ||||||||||||||||||
| 709 | - | |||||||||||||||||||
| 710 | If \a rect is outside of the bounds of minimumSize and maximumSize, it | - | ||||||||||||||||||
| 711 | will be adjusted to its closest size so that it is within the legal | - | ||||||||||||||||||
| 712 | bounds. | - | ||||||||||||||||||
| 713 | - | |||||||||||||||||||
| 714 | \sa geometry() | - | ||||||||||||||||||
| 715 | */ | - | ||||||||||||||||||
| 716 | void QGraphicsLayoutItem::setGeometry(const QRectF &rect) | - | ||||||||||||||||||
| 717 | { | - | ||||||||||||||||||
| 718 | Q_D(QGraphicsLayoutItem); | - | ||||||||||||||||||
| 719 | QSizeF effectiveSize = rect.size().expandedTo(effectiveSizeHint(Qt::MinimumSize)) | - | ||||||||||||||||||
| 720 | .boundedTo(effectiveSizeHint(Qt::MaximumSize)); | - | ||||||||||||||||||
| 721 | d->geom = QRectF(rect.topLeft(), effectiveSize); | - | ||||||||||||||||||
| 722 | } never executed: end of block | 0 | ||||||||||||||||||
| 723 | - | |||||||||||||||||||
| 724 | /*! | - | ||||||||||||||||||
| 725 | \fn QRectF QGraphicsLayoutItem::geometry() const | - | ||||||||||||||||||
| 726 | - | |||||||||||||||||||
| 727 | Returns the item's geometry (e.g., position and size) as a | - | ||||||||||||||||||
| 728 | QRectF. This function is equivalent to QRectF(pos(), size()). | - | ||||||||||||||||||
| 729 | - | |||||||||||||||||||
| 730 | \sa setGeometry() | - | ||||||||||||||||||
| 731 | */ | - | ||||||||||||||||||
| 732 | QRectF QGraphicsLayoutItem::geometry() const | - | ||||||||||||||||||
| 733 | { | - | ||||||||||||||||||
| 734 | Q_D(const QGraphicsLayoutItem); | - | ||||||||||||||||||
| 735 | return d->geom; never executed: return d->geom; | 0 | ||||||||||||||||||
| 736 | } | - | ||||||||||||||||||
| 737 | - | |||||||||||||||||||
| 738 | /*! | - | ||||||||||||||||||
| 739 | This virtual function provides the \a left, \a top, \a right and \a bottom | - | ||||||||||||||||||
| 740 | contents margins for this QGraphicsLayoutItem. The default implementation | - | ||||||||||||||||||
| 741 | assumes all contents margins are 0. The parameters point to values stored | - | ||||||||||||||||||
| 742 | in qreals. If any of the pointers is 0, that value will not be updated. | - | ||||||||||||||||||
| 743 | - | |||||||||||||||||||
| 744 | \sa QGraphicsWidget::setContentsMargins() | - | ||||||||||||||||||
| 745 | */ | - | ||||||||||||||||||
| 746 | void QGraphicsLayoutItem::getContentsMargins(qreal *left, qreal *top, qreal *right, qreal *bottom) const | - | ||||||||||||||||||
| 747 | { | - | ||||||||||||||||||
| 748 | if (left)
| 0 | ||||||||||||||||||
| 749 | *left = 0; never executed: *left = 0; | 0 | ||||||||||||||||||
| 750 | if (top)
| 0 | ||||||||||||||||||
| 751 | *top = 0; never executed: *top = 0; | 0 | ||||||||||||||||||
| 752 | if (right)
| 0 | ||||||||||||||||||
| 753 | *right = 0; never executed: *right = 0; | 0 | ||||||||||||||||||
| 754 | if (bottom)
| 0 | ||||||||||||||||||
| 755 | *bottom = 0; never executed: *bottom = 0; | 0 | ||||||||||||||||||
| 756 | } never executed: end of block | 0 | ||||||||||||||||||
| 757 | - | |||||||||||||||||||
| 758 | /*! | - | ||||||||||||||||||
| 759 | Returns the contents rect in local coordinates. | - | ||||||||||||||||||
| 760 | - | |||||||||||||||||||
| 761 | The contents rect defines the subrectangle used by an associated layout | - | ||||||||||||||||||
| 762 | when arranging subitems. This function is a convenience function that | - | ||||||||||||||||||
| 763 | adjusts the item's geometry() by its contents margins. Note that | - | ||||||||||||||||||
| 764 | getContentsMargins() is a virtual function that you can reimplement to | - | ||||||||||||||||||
| 765 | return the item's contents margins. | - | ||||||||||||||||||
| 766 | - | |||||||||||||||||||
| 767 | \sa getContentsMargins(), geometry() | - | ||||||||||||||||||
| 768 | */ | - | ||||||||||||||||||
| 769 | QRectF QGraphicsLayoutItem::contentsRect() const | - | ||||||||||||||||||
| 770 | { | - | ||||||||||||||||||
| 771 | qreal left, top, right, bottom; | - | ||||||||||||||||||
| 772 | getContentsMargins(&left, &top, &right, &bottom); | - | ||||||||||||||||||
| 773 | return QRectF(QPointF(), geometry().size()).adjusted(+left, +top, -right, -bottom); never executed: return QRectF(QPointF(), geometry().size()).adjusted(+left, +top, -right, -bottom); | 0 | ||||||||||||||||||
| 774 | } | - | ||||||||||||||||||
| 775 | - | |||||||||||||||||||
| 776 | /*! | - | ||||||||||||||||||
| 777 | Returns the effective size hint for this QGraphicsLayoutItem. | - | ||||||||||||||||||
| 778 | - | |||||||||||||||||||
| 779 | \a which is the size hint in question. | - | ||||||||||||||||||
| 780 | \a constraint is an optional argument that defines a special constrain | - | ||||||||||||||||||
| 781 | when calculating the effective size hint. By default, \a constraint is | - | ||||||||||||||||||
| 782 | QSizeF(-1, -1), which means there is no constraint to the size hint. | - | ||||||||||||||||||
| 783 | - | |||||||||||||||||||
| 784 | If you want to specify the widget's size hint for a given width or height, | - | ||||||||||||||||||
| 785 | you can provide the fixed dimension in \a constraint. This is useful for | - | ||||||||||||||||||
| 786 | widgets that can grow only either vertically or horizontally, and need to | - | ||||||||||||||||||
| 787 | set either their width or their height to a special value. | - | ||||||||||||||||||
| 788 | - | |||||||||||||||||||
| 789 | For example, a text paragraph item fit into a column width of 200 may | - | ||||||||||||||||||
| 790 | grow vertically. You can pass QSizeF(200, -1) as a constraint to get a | - | ||||||||||||||||||
| 791 | suitable minimum, preferred and maximum height). | - | ||||||||||||||||||
| 792 | - | |||||||||||||||||||
| 793 | You can adjust the effective size hint by reimplementing sizeHint() | - | ||||||||||||||||||
| 794 | in a QGraphicsLayoutItem subclass, or by calling one of the following | - | ||||||||||||||||||
| 795 | functions: setMinimumSize(), setPreferredSize, or setMaximumSize() | - | ||||||||||||||||||
| 796 | (or a combination of both). | - | ||||||||||||||||||
| 797 | - | |||||||||||||||||||
| 798 | This function caches each of the size hints and guarantees that | - | ||||||||||||||||||
| 799 | sizeHint() will be called only once for each value of \a which - unless | - | ||||||||||||||||||
| 800 | \a constraint is not specified and updateGeometry() has been called. | - | ||||||||||||||||||
| 801 | - | |||||||||||||||||||
| 802 | \sa sizeHint() | - | ||||||||||||||||||
| 803 | */ | - | ||||||||||||||||||
| 804 | QSizeF QGraphicsLayoutItem::effectiveSizeHint(Qt::SizeHint which, const QSizeF &constraint) const | - | ||||||||||||||||||
| 805 | { | - | ||||||||||||||||||
| 806 | Q_D(const QGraphicsLayoutItem); | - | ||||||||||||||||||
| 807 | - | |||||||||||||||||||
| 808 | if (!d->userSizeHints && constraint.isValid())
| 0 | ||||||||||||||||||
| 809 | return constraint; never executed: return constraint; | 0 | ||||||||||||||||||
| 810 | - | |||||||||||||||||||
| 811 | // ### should respect size policy??? | - | ||||||||||||||||||
| 812 | return d_ptr->effectiveSizeHints(constraint)[which]; never executed: return d_ptr->effectiveSizeHints(constraint)[which]; | 0 | ||||||||||||||||||
| 813 | } | - | ||||||||||||||||||
| 814 | - | |||||||||||||||||||
| 815 | /*! | - | ||||||||||||||||||
| 816 | This virtual function discards any cached size hint information. You | - | ||||||||||||||||||
| 817 | should always call this function if you change the return value of the | - | ||||||||||||||||||
| 818 | sizeHint() function. Subclasses must always call the base implementation | - | ||||||||||||||||||
| 819 | when reimplementing this function. | - | ||||||||||||||||||
| 820 | - | |||||||||||||||||||
| 821 | \sa effectiveSizeHint() | - | ||||||||||||||||||
| 822 | */ | - | ||||||||||||||||||
| 823 | void QGraphicsLayoutItem::updateGeometry() | - | ||||||||||||||||||
| 824 | { | - | ||||||||||||||||||
| 825 | Q_D(QGraphicsLayoutItem); | - | ||||||||||||||||||
| 826 | d->sizeHintCacheDirty = true; | - | ||||||||||||||||||
| 827 | d->sizeHintWithConstraintCacheDirty = true; | - | ||||||||||||||||||
| 828 | } never executed: end of block | 0 | ||||||||||||||||||
| 829 | - | |||||||||||||||||||
| 830 | /*! | - | ||||||||||||||||||
| 831 | Returns the parent of this QGraphicsLayoutItem, or 0 if there is no parent, | - | ||||||||||||||||||
| 832 | or if the parent does not inherit from QGraphicsLayoutItem | - | ||||||||||||||||||
| 833 | (QGraphicsLayoutItem is often used through multiple inheritance with | - | ||||||||||||||||||
| 834 | QObject-derived classes). | - | ||||||||||||||||||
| 835 | - | |||||||||||||||||||
| 836 | \sa setParentLayoutItem() | - | ||||||||||||||||||
| 837 | */ | - | ||||||||||||||||||
| 838 | QGraphicsLayoutItem *QGraphicsLayoutItem::parentLayoutItem() const | - | ||||||||||||||||||
| 839 | { | - | ||||||||||||||||||
| 840 | return d_func()->parent; never executed: return d_func()->parent; | 0 | ||||||||||||||||||
| 841 | } | - | ||||||||||||||||||
| 842 | - | |||||||||||||||||||
| 843 | /*! | - | ||||||||||||||||||
| 844 | Sets the parent of this QGraphicsLayoutItem to \a parent. | - | ||||||||||||||||||
| 845 | - | |||||||||||||||||||
| 846 | \sa parentLayoutItem() | - | ||||||||||||||||||
| 847 | */ | - | ||||||||||||||||||
| 848 | void QGraphicsLayoutItem::setParentLayoutItem(QGraphicsLayoutItem *parent) | - | ||||||||||||||||||
| 849 | { | - | ||||||||||||||||||
| 850 | d_func()->parent = parent; | - | ||||||||||||||||||
| 851 | } never executed: end of block | 0 | ||||||||||||||||||
| 852 | - | |||||||||||||||||||
| 853 | /*! | - | ||||||||||||||||||
| 854 | Returns \c true if this QGraphicsLayoutItem is a layout (e.g., is inherited | - | ||||||||||||||||||
| 855 | by an object that arranges other QGraphicsLayoutItem objects); otherwise | - | ||||||||||||||||||
| 856 | returns \c false. | - | ||||||||||||||||||
| 857 | - | |||||||||||||||||||
| 858 | \sa QGraphicsLayout | - | ||||||||||||||||||
| 859 | */ | - | ||||||||||||||||||
| 860 | bool QGraphicsLayoutItem::isLayout() const | - | ||||||||||||||||||
| 861 | { | - | ||||||||||||||||||
| 862 | return d_func()->isLayout; never executed: return d_func()->isLayout; | 0 | ||||||||||||||||||
| 863 | } | - | ||||||||||||||||||
| 864 | - | |||||||||||||||||||
| 865 | /*! | - | ||||||||||||||||||
| 866 | \since 4.6 | - | ||||||||||||||||||
| 867 | - | |||||||||||||||||||
| 868 | Returns whether a layout should delete this item in its destructor. | - | ||||||||||||||||||
| 869 | If its true, then the layout will delete it. If its false, then it is | - | ||||||||||||||||||
| 870 | assumed that another object has the ownership of it, and the layout won't | - | ||||||||||||||||||
| 871 | delete this item. | - | ||||||||||||||||||
| 872 | - | |||||||||||||||||||
| 873 | If the item inherits both QGraphicsItem and QGraphicsLayoutItem (such | - | ||||||||||||||||||
| 874 | as QGraphicsWidget does) the item is really part of two ownership | - | ||||||||||||||||||
| 875 | hierarchies. This property informs what the layout should do with its | - | ||||||||||||||||||
| 876 | child items when it is destructed. In the case of QGraphicsWidget, it | - | ||||||||||||||||||
| 877 | is preferred that when the layout is deleted it won't delete its children | - | ||||||||||||||||||
| 878 | (since they are also part of the graphics item hierarchy). | - | ||||||||||||||||||
| 879 | - | |||||||||||||||||||
| 880 | By default this value is initialized to false in QGraphicsLayoutItem, | - | ||||||||||||||||||
| 881 | but it is overridden by QGraphicsLayout to return true. This is because | - | ||||||||||||||||||
| 882 | QGraphicsLayout is not normally part of the QGraphicsItem hierarchy, so the | - | ||||||||||||||||||
| 883 | parent layout should delete it. | - | ||||||||||||||||||
| 884 | Subclasses might override this default behaviour by calling | - | ||||||||||||||||||
| 885 | setOwnedByLayout(true). | - | ||||||||||||||||||
| 886 | - | |||||||||||||||||||
| 887 | \sa setOwnedByLayout() | - | ||||||||||||||||||
| 888 | */ | - | ||||||||||||||||||
| 889 | bool QGraphicsLayoutItem::ownedByLayout() const | - | ||||||||||||||||||
| 890 | { | - | ||||||||||||||||||
| 891 | return d_func()->ownedByLayout; never executed: return d_func()->ownedByLayout; | 0 | ||||||||||||||||||
| 892 | } | - | ||||||||||||||||||
| 893 | /*! | - | ||||||||||||||||||
| 894 | \since 4.6 | - | ||||||||||||||||||
| 895 | - | |||||||||||||||||||
| 896 | Sets whether a layout should delete this item in its destructor or not. | - | ||||||||||||||||||
| 897 | \a ownership must be true to in order for the layout to delete it. | - | ||||||||||||||||||
| 898 | \sa ownedByLayout() | - | ||||||||||||||||||
| 899 | */ | - | ||||||||||||||||||
| 900 | void QGraphicsLayoutItem::setOwnedByLayout(bool ownership) | - | ||||||||||||||||||
| 901 | { | - | ||||||||||||||||||
| 902 | d_func()->ownedByLayout = ownership; | - | ||||||||||||||||||
| 903 | } never executed: end of block | 0 | ||||||||||||||||||
| 904 | - | |||||||||||||||||||
| 905 | /*! | - | ||||||||||||||||||
| 906 | * Returns the QGraphicsItem that this layout item represents. | - | ||||||||||||||||||
| 907 | * For QGraphicsWidget it will return itself. For custom items it can return an | - | ||||||||||||||||||
| 908 | * aggregated value. | - | ||||||||||||||||||
| 909 | * | - | ||||||||||||||||||
| 910 | * \sa setGraphicsItem() | - | ||||||||||||||||||
| 911 | */ | - | ||||||||||||||||||
| 912 | QGraphicsItem *QGraphicsLayoutItem::graphicsItem() const | - | ||||||||||||||||||
| 913 | { | - | ||||||||||||||||||
| 914 | return d_func()->graphicsItem; never executed: return d_func()->graphicsItem; | 0 | ||||||||||||||||||
| 915 | } | - | ||||||||||||||||||
| 916 | - | |||||||||||||||||||
| 917 | /*! | - | ||||||||||||||||||
| 918 | * If the QGraphicsLayoutItem represents a QGraphicsItem, and it wants to take | - | ||||||||||||||||||
| 919 | * advantage of the automatic reparenting capabilities of QGraphicsLayout it | - | ||||||||||||||||||
| 920 | * should set this value. | - | ||||||||||||||||||
| 921 | * Note that if you delete \a item and not delete the layout item, you are | - | ||||||||||||||||||
| 922 | * responsible of calling setGraphicsItem(0) in order to avoid having a | - | ||||||||||||||||||
| 923 | * dangling pointer. | - | ||||||||||||||||||
| 924 | * | - | ||||||||||||||||||
| 925 | * \sa graphicsItem() | - | ||||||||||||||||||
| 926 | */ | - | ||||||||||||||||||
| 927 | void QGraphicsLayoutItem::setGraphicsItem(QGraphicsItem *item) | - | ||||||||||||||||||
| 928 | { | - | ||||||||||||||||||
| 929 | d_func()->graphicsItem = item; | - | ||||||||||||||||||
| 930 | } never executed: end of block | 0 | ||||||||||||||||||
| 931 | - | |||||||||||||||||||
| 932 | QT_END_NAMESPACE | - | ||||||||||||||||||
| 933 | - | |||||||||||||||||||
| 934 | #endif //QT_NO_GRAPHICSVIEW | - | ||||||||||||||||||
| Source code | Switch to Preprocessed file |