1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QGRAPHICSLAYOUTITEM_H
5#define QGRAPHICSLAYOUTITEM_H
6
7#include <QtWidgets/qtwidgetsglobal.h>
8#include <QtCore/qscopedpointer.h>
9#include <QtWidgets/qsizepolicy.h>
10#include <QtGui/qevent.h>
11
12QT_REQUIRE_CONFIG(graphicsview);
13
14QT_BEGIN_NAMESPACE
15
16class QGraphicsLayoutItemPrivate;
17class QGraphicsItem;
18class Q_WIDGETS_EXPORT QGraphicsLayoutItem
19{
20public:
21 QGraphicsLayoutItem(QGraphicsLayoutItem *parent = nullptr, bool isLayout = false);
22 virtual ~QGraphicsLayoutItem();
23
24 void setSizePolicy(const QSizePolicy &policy);
25 void setSizePolicy(QSizePolicy::Policy hPolicy, QSizePolicy::Policy vPolicy, QSizePolicy::ControlType controlType = QSizePolicy::DefaultType);
26 QSizePolicy sizePolicy() const;
27
28 void setMinimumSize(const QSizeF &size);
29 inline void setMinimumSize(qreal w, qreal h);
30 QSizeF minimumSize() const;
31 void setMinimumWidth(qreal width);
32 inline qreal minimumWidth() const;
33 void setMinimumHeight(qreal height);
34 inline qreal minimumHeight() const;
35
36 void setPreferredSize(const QSizeF &size);
37 inline void setPreferredSize(qreal w, qreal h);
38 QSizeF preferredSize() const;
39 void setPreferredWidth(qreal width);
40 inline qreal preferredWidth() const;
41 void setPreferredHeight(qreal height);
42 inline qreal preferredHeight() const;
43
44 void setMaximumSize(const QSizeF &size);
45 inline void setMaximumSize(qreal w, qreal h);
46 QSizeF maximumSize() const;
47 void setMaximumWidth(qreal width);
48 inline qreal maximumWidth() const;
49 void setMaximumHeight(qreal height);
50 inline qreal maximumHeight() const;
51
52 virtual void setGeometry(const QRectF &rect);
53 QRectF geometry() const;
54 virtual void getContentsMargins(qreal *left, qreal *top, qreal *right, qreal *bottom) const;
55 QRectF contentsRect() const;
56
57 QSizeF effectiveSizeHint(Qt::SizeHint which, const QSizeF &constraint = QSizeF()) const;
58
59 virtual void updateGeometry();
60
61 virtual bool isEmpty() const;
62 QGraphicsLayoutItem *parentLayoutItem() const;
63 void setParentLayoutItem(QGraphicsLayoutItem *parent);
64
65 bool isLayout() const;
66 QGraphicsItem *graphicsItem() const;
67 bool ownedByLayout() const;
68
69protected:
70 void setGraphicsItem(QGraphicsItem *item);
71 void setOwnedByLayout(bool ownedByLayout);
72 QGraphicsLayoutItem(QGraphicsLayoutItemPrivate &dd);
73
74 virtual QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint = QSizeF()) const = 0;
75 QScopedPointer<QGraphicsLayoutItemPrivate> d_ptr;
76
77private:
78 QSizeF *effectiveSizeHints(const QSizeF &constraint) const;
79 Q_DECLARE_PRIVATE(QGraphicsLayoutItem)
80
81 friend class QGraphicsLayout;
82};
83
84#ifndef Q_QDOC
85Q_DECLARE_INTERFACE(QGraphicsLayoutItem, "org.qt-project.Qt.QGraphicsLayoutItem")
86#endif
87
88inline void QGraphicsLayoutItem::setMinimumSize(qreal aw, qreal ah)
89{ setMinimumSize(QSizeF(aw, ah)); }
90inline void QGraphicsLayoutItem::setPreferredSize(qreal aw, qreal ah)
91{ setPreferredSize(QSizeF(aw, ah)); }
92inline void QGraphicsLayoutItem::setMaximumSize(qreal aw, qreal ah)
93{ setMaximumSize(QSizeF(aw, ah)); }
94
95inline qreal QGraphicsLayoutItem::minimumWidth() const
96{ return effectiveSizeHint(which: Qt::MinimumSize).width(); }
97inline qreal QGraphicsLayoutItem::minimumHeight() const
98{ return effectiveSizeHint(which: Qt::MinimumSize).height(); }
99
100inline qreal QGraphicsLayoutItem::preferredWidth() const
101{ return effectiveSizeHint(which: Qt::PreferredSize).width(); }
102inline qreal QGraphicsLayoutItem::preferredHeight() const
103{ return effectiveSizeHint(which: Qt::PreferredSize).height(); }
104
105inline qreal QGraphicsLayoutItem::maximumWidth() const
106{ return effectiveSizeHint(which: Qt::MaximumSize).width(); }
107inline qreal QGraphicsLayoutItem::maximumHeight() const
108{ return effectiveSizeHint(which: Qt::MaximumSize).height(); }
109
110QT_END_NAMESPACE
111
112#endif
113

source code of qtbase/src/widgets/graphicsview/qgraphicslayoutitem.h