| 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 | #ifndef QGRAPHICSLAYOUTITEM_H |
| 41 | #define QGRAPHICSLAYOUTITEM_H |
| 42 | |
| 43 | #include <QtWidgets/qtwidgetsglobal.h> |
| 44 | #include <QtCore/qscopedpointer.h> |
| 45 | #include <QtWidgets/qsizepolicy.h> |
| 46 | #include <QtGui/qevent.h> |
| 47 | |
| 48 | QT_REQUIRE_CONFIG(graphicsview); |
| 49 | |
| 50 | QT_BEGIN_NAMESPACE |
| 51 | |
| 52 | class QGraphicsLayoutItemPrivate; |
| 53 | class QGraphicsItem; |
| 54 | class Q_WIDGETS_EXPORT QGraphicsLayoutItem |
| 55 | { |
| 56 | public: |
| 57 | QGraphicsLayoutItem(QGraphicsLayoutItem *parent = nullptr, bool isLayout = false); |
| 58 | virtual ~QGraphicsLayoutItem(); |
| 59 | |
| 60 | void setSizePolicy(const QSizePolicy &policy); |
| 61 | void setSizePolicy(QSizePolicy::Policy hPolicy, QSizePolicy::Policy vPolicy, QSizePolicy::ControlType controlType = QSizePolicy::DefaultType); |
| 62 | QSizePolicy sizePolicy() const; |
| 63 | |
| 64 | void setMinimumSize(const QSizeF &size); |
| 65 | inline void setMinimumSize(qreal w, qreal h); |
| 66 | QSizeF minimumSize() const; |
| 67 | void setMinimumWidth(qreal width); |
| 68 | inline qreal minimumWidth() const; |
| 69 | void setMinimumHeight(qreal height); |
| 70 | inline qreal minimumHeight() const; |
| 71 | |
| 72 | void setPreferredSize(const QSizeF &size); |
| 73 | inline void setPreferredSize(qreal w, qreal h); |
| 74 | QSizeF preferredSize() const; |
| 75 | void setPreferredWidth(qreal width); |
| 76 | inline qreal preferredWidth() const; |
| 77 | void setPreferredHeight(qreal height); |
| 78 | inline qreal preferredHeight() const; |
| 79 | |
| 80 | void setMaximumSize(const QSizeF &size); |
| 81 | inline void setMaximumSize(qreal w, qreal h); |
| 82 | QSizeF maximumSize() const; |
| 83 | void setMaximumWidth(qreal width); |
| 84 | inline qreal maximumWidth() const; |
| 85 | void setMaximumHeight(qreal height); |
| 86 | inline qreal maximumHeight() const; |
| 87 | |
| 88 | virtual void setGeometry(const QRectF &rect); |
| 89 | QRectF geometry() const; |
| 90 | virtual void getContentsMargins(qreal *left, qreal *top, qreal *right, qreal *bottom) const; |
| 91 | QRectF contentsRect() const; |
| 92 | |
| 93 | QSizeF effectiveSizeHint(Qt::SizeHint which, const QSizeF &constraint = QSizeF()) const; |
| 94 | |
| 95 | virtual void updateGeometry(); |
| 96 | |
| 97 | QGraphicsLayoutItem *parentLayoutItem() const; |
| 98 | void setParentLayoutItem(QGraphicsLayoutItem *parent); |
| 99 | |
| 100 | bool isLayout() const; |
| 101 | QGraphicsItem *graphicsItem() const; |
| 102 | bool ownedByLayout() const; |
| 103 | |
| 104 | protected: |
| 105 | void setGraphicsItem(QGraphicsItem *item); |
| 106 | void setOwnedByLayout(bool ownedByLayout); |
| 107 | QGraphicsLayoutItem(QGraphicsLayoutItemPrivate &dd); |
| 108 | |
| 109 | virtual QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint = QSizeF()) const = 0; |
| 110 | QScopedPointer<QGraphicsLayoutItemPrivate> d_ptr; |
| 111 | |
| 112 | private: |
| 113 | QSizeF *effectiveSizeHints(const QSizeF &constraint) const; |
| 114 | Q_DECLARE_PRIVATE(QGraphicsLayoutItem) |
| 115 | |
| 116 | friend class QGraphicsLayout; |
| 117 | }; |
| 118 | |
| 119 | #ifndef Q_CLANG_QDOC |
| 120 | Q_DECLARE_INTERFACE(QGraphicsLayoutItem, "org.qt-project.Qt.QGraphicsLayoutItem" ) |
| 121 | #endif |
| 122 | |
| 123 | inline void QGraphicsLayoutItem::setMinimumSize(qreal aw, qreal ah) |
| 124 | { setMinimumSize(QSizeF(aw, ah)); } |
| 125 | inline void QGraphicsLayoutItem::setPreferredSize(qreal aw, qreal ah) |
| 126 | { setPreferredSize(QSizeF(aw, ah)); } |
| 127 | inline void QGraphicsLayoutItem::setMaximumSize(qreal aw, qreal ah) |
| 128 | { setMaximumSize(QSizeF(aw, ah)); } |
| 129 | |
| 130 | inline qreal QGraphicsLayoutItem::minimumWidth() const |
| 131 | { return effectiveSizeHint(which: Qt::MinimumSize).width(); } |
| 132 | inline qreal QGraphicsLayoutItem::minimumHeight() const |
| 133 | { return effectiveSizeHint(which: Qt::MinimumSize).height(); } |
| 134 | |
| 135 | inline qreal QGraphicsLayoutItem::preferredWidth() const |
| 136 | { return effectiveSizeHint(which: Qt::PreferredSize).width(); } |
| 137 | inline qreal QGraphicsLayoutItem::preferredHeight() const |
| 138 | { return effectiveSizeHint(which: Qt::PreferredSize).height(); } |
| 139 | |
| 140 | inline qreal QGraphicsLayoutItem::maximumWidth() const |
| 141 | { return effectiveSizeHint(which: Qt::MaximumSize).width(); } |
| 142 | inline qreal QGraphicsLayoutItem::maximumHeight() const |
| 143 | { return effectiveSizeHint(which: Qt::MaximumSize).height(); } |
| 144 | |
| 145 | QT_END_NAMESPACE |
| 146 | |
| 147 | #endif |
| 148 | |