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