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 QGRAPHICSANCHORLAYOUT_H
5#define QGRAPHICSANCHORLAYOUT_H
6
7#include <QtWidgets/qtwidgetsglobal.h>
8#include <QtWidgets/qgraphicsitem.h>
9#include <QtWidgets/qgraphicslayout.h>
10
11QT_REQUIRE_CONFIG(graphicsview);
12
13QT_BEGIN_NAMESPACE
14
15class QGraphicsAnchorPrivate;
16class QGraphicsAnchorLayout;
17class QGraphicsAnchorLayoutPrivate;
18
19class Q_WIDGETS_EXPORT QGraphicsAnchor : public QObject
20{
21 Q_OBJECT
22 Q_PROPERTY(qreal spacing READ spacing WRITE setSpacing RESET unsetSpacing)
23 Q_PROPERTY(QSizePolicy::Policy sizePolicy READ sizePolicy WRITE setSizePolicy)
24public:
25 void setSpacing(qreal spacing);
26 void unsetSpacing();
27 qreal spacing() const;
28 void setSizePolicy(QSizePolicy::Policy policy);
29 QSizePolicy::Policy sizePolicy() const;
30 ~QGraphicsAnchor();
31private:
32 QGraphicsAnchor(QGraphicsAnchorLayout *parent);
33
34 Q_DECLARE_PRIVATE(QGraphicsAnchor)
35
36 friend class QGraphicsAnchorLayoutPrivate;
37};
38
39class Q_WIDGETS_EXPORT QGraphicsAnchorLayout : public QGraphicsLayout
40{
41public:
42 QGraphicsAnchorLayout(QGraphicsLayoutItem *parent = nullptr);
43 virtual ~QGraphicsAnchorLayout();
44
45 QGraphicsAnchor *addAnchor(QGraphicsLayoutItem *firstItem, Qt::AnchorPoint firstEdge,
46 QGraphicsLayoutItem *secondItem, Qt::AnchorPoint secondEdge);
47 QGraphicsAnchor *anchor(QGraphicsLayoutItem *firstItem, Qt::AnchorPoint firstEdge,
48 QGraphicsLayoutItem *secondItem, Qt::AnchorPoint secondEdge);
49
50 void addCornerAnchors(QGraphicsLayoutItem *firstItem, Qt::Corner firstCorner,
51 QGraphicsLayoutItem *secondItem, Qt::Corner secondCorner);
52
53 void addAnchors(QGraphicsLayoutItem *firstItem,
54 QGraphicsLayoutItem *secondItem,
55 Qt::Orientations orientations = Qt::Horizontal | Qt::Vertical);
56
57 void setHorizontalSpacing(qreal spacing);
58 void setVerticalSpacing(qreal spacing);
59 void setSpacing(qreal spacing);
60 qreal horizontalSpacing() const;
61 qreal verticalSpacing() const;
62
63 void removeAt(int index) override;
64 void setGeometry(const QRectF &rect) override;
65 int count() const override;
66 QGraphicsLayoutItem *itemAt(int index) const override;
67
68 void invalidate() override;
69protected:
70 QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint = QSizeF()) const override;
71
72private:
73 Q_DISABLE_COPY(QGraphicsAnchorLayout)
74 Q_DECLARE_PRIVATE(QGraphicsAnchorLayout)
75
76 friend class QGraphicsAnchor;
77};
78
79QT_END_NAMESPACE
80
81#endif
82

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