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 QGRAPHICSGRIDLAYOUTENGINE_P_H |
5 | #define QGRAPHICSGRIDLAYOUTENGINE_P_H |
6 | |
7 | // |
8 | // W A R N I N G |
9 | // ------------- |
10 | // |
11 | // This file is not part of the Qt API. It exists purely as an |
12 | // implementation detail. This header file may change from version to |
13 | // version without notice, or even be removed. |
14 | // |
15 | // We mean it. |
16 | // |
17 | |
18 | #include <QtWidgets/private/qtwidgetsglobal_p.h> |
19 | #include <QtGui/private/qgridlayoutengine_p.h> |
20 | |
21 | #include <QtWidgets/qsizepolicy.h> |
22 | #include <QtWidgets/qstyle.h> |
23 | #include <QtWidgets/qstyleoption.h> |
24 | #include "qgraphicslayoutitem.h" |
25 | |
26 | QT_REQUIRE_CONFIG(graphicsview); |
27 | |
28 | QT_BEGIN_NAMESPACE |
29 | |
30 | class QGraphicsLayoutPrivate; |
31 | |
32 | class QGraphicsGridLayoutEngineItem : public QGridLayoutItem { |
33 | public: |
34 | QGraphicsGridLayoutEngineItem(QGraphicsLayoutItem *item, int row, int columns, int rowSpan = 1, int columnSpan = 1, |
35 | Qt::Alignment alignment = { }) |
36 | : QGridLayoutItem(row, columns, rowSpan, columnSpan, alignment), q_layoutItem(item) {} |
37 | |
38 | virtual QLayoutPolicy::Policy sizePolicy(Qt::Orientation orientation) const override |
39 | { |
40 | QSizePolicy sizePolicy(q_layoutItem->sizePolicy()); |
41 | return (QLayoutPolicy::Policy)((orientation == Qt::Horizontal) ? sizePolicy.horizontalPolicy() |
42 | : sizePolicy.verticalPolicy()); |
43 | } |
44 | |
45 | virtual QLayoutPolicy::ControlTypes controlTypes(LayoutSide) const override |
46 | { |
47 | const QSizePolicy::ControlType ct = q_layoutItem->sizePolicy().controlType(); |
48 | return (QLayoutPolicy::ControlTypes)ct; |
49 | } |
50 | |
51 | virtual QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint) const override |
52 | { |
53 | return q_layoutItem->effectiveSizeHint(which, constraint); |
54 | } |
55 | |
56 | virtual void setGeometry(const QRectF &rect) override |
57 | { |
58 | q_layoutItem->setGeometry(rect); |
59 | } |
60 | |
61 | virtual bool hasDynamicConstraint() const override; |
62 | virtual Qt::Orientation dynamicConstraintOrientation() const override; |
63 | |
64 | virtual bool isEmpty() const override; |
65 | |
66 | QGraphicsLayoutItem *layoutItem() const { return q_layoutItem; } |
67 | |
68 | protected: |
69 | QGraphicsLayoutItem *q_layoutItem; |
70 | }; |
71 | |
72 | |
73 | class QGraphicsGridLayoutEngine : public QGridLayoutEngine |
74 | { |
75 | public: |
76 | QGraphicsGridLayoutEngineItem *findLayoutItem(QGraphicsLayoutItem *layoutItem) const |
77 | { |
78 | const int index = indexOf(item: layoutItem); |
79 | if (index < 0) |
80 | return nullptr; |
81 | return static_cast<QGraphicsGridLayoutEngineItem*>(q_items.at(i: index)); |
82 | } |
83 | |
84 | int indexOf(QGraphicsLayoutItem *item) const |
85 | { |
86 | for (int i = 0; i < q_items.size(); ++i) { |
87 | if (item == static_cast<QGraphicsGridLayoutEngineItem*>(q_items.at(i))->layoutItem()) |
88 | return i; |
89 | } |
90 | return -1; |
91 | } |
92 | |
93 | void setAlignment(QGraphicsLayoutItem *graphicsLayoutItem, Qt::Alignment alignment); |
94 | Qt::Alignment alignment(QGraphicsLayoutItem *graphicsLayoutItem) const; |
95 | |
96 | void setStretchFactor(QGraphicsLayoutItem *layoutItem, int stretch, Qt::Orientation orientation); |
97 | int stretchFactor(QGraphicsLayoutItem *layoutItem, Qt::Orientation orientation) const; |
98 | |
99 | }; |
100 | |
101 | QT_END_NAMESPACE |
102 | |
103 | #endif // QGRAPHICSGRIDLAYOUTENGINE_P_H |
104 | |