QmlMaterial 0.1.0
Loading...
Searching...
No Matches
layout_container.hpp
1#pragma once
2
3#include <QQuickItem>
4#include <QQmlEngine>
5#include <memory>
6
7#include "qml_material/export.hpp"
8
9namespace qml_material
10{
11
12class LayoutContainerPrivate;
13
23class QML_MATERIAL_API LayoutContainer : public QQuickItem {
24 Q_OBJECT
25 QML_ANONYMOUS
26
27 Q_PROPERTY(qreal implicitWidth READ implicitWidth NOTIFY implicitWidthChanged FINAL)
28 Q_PROPERTY(qreal implicitHeight READ implicitHeight NOTIFY implicitHeightChanged FINAL)
29 Q_PROPERTY(
30 qreal leftPadding READ leftPadding WRITE setLeftPadding NOTIFY leftPaddingChanged FINAL)
31 Q_PROPERTY(
32 qreal rightPadding READ rightPadding WRITE setRightPadding NOTIFY rightPaddingChanged FINAL)
33 Q_PROPERTY(qreal topPadding READ topPadding WRITE setTopPadding NOTIFY topPaddingChanged FINAL)
34 Q_PROPERTY(qreal bottomPadding READ bottomPadding WRITE setBottomPadding NOTIFY
35 bottomPaddingChanged FINAL)
36 Q_PROPERTY(
37 Qt::Alignment alignment READ alignment WRITE setAlignment NOTIFY alignmentChanged FINAL)
38 Q_PROPERTY(Qt::LayoutDirection layoutDirection READ layoutDirection WRITE setLayoutDirection
39 NOTIFY layoutDirectionChanged FINAL)
40 Q_PROPERTY(Qt::LayoutDirection effectiveLayoutDirection READ effectiveLayoutDirection NOTIFY
41 effectiveLayoutDirectionChanged FINAL)
42 Q_PROPERTY(qreal contentWidth READ contentWidth NOTIFY contentWidthChanged FINAL)
43 Q_PROPERTY(qreal contentHeight READ contentHeight NOTIFY contentHeightChanged FINAL)
44
45public:
46 ~LayoutContainer() override;
47
48 qreal leftPadding() const;
49 void setLeftPadding(qreal padding);
50 qreal rightPadding() const;
51 void setRightPadding(qreal padding);
52 qreal topPadding() const;
53 void setTopPadding(qreal padding);
54 qreal bottomPadding() const;
55 void setBottomPadding(qreal padding);
56
57 Qt::Alignment alignment() const;
58 void setAlignment(Qt::Alignment alignment);
59
60 Qt::LayoutDirection layoutDirection() const;
61 void setLayoutDirection(Qt::LayoutDirection direction);
62 Qt::LayoutDirection effectiveLayoutDirection() const;
63
64 qreal contentWidth() const;
65 qreal contentHeight() const;
66
67 Q_SIGNAL void leftPaddingChanged();
68 Q_SIGNAL void rightPaddingChanged();
69 Q_SIGNAL void topPaddingChanged();
70 Q_SIGNAL void bottomPaddingChanged();
71 Q_SIGNAL void alignmentChanged();
72 Q_SIGNAL void layoutDirectionChanged();
73 Q_SIGNAL void effectiveLayoutDirectionChanged();
74 Q_SIGNAL void contentWidthChanged();
75 Q_SIGNAL void contentHeightChanged();
76
77protected:
78 enum class Mode
79 {
80 Box,
81 Row,
82 Column,
83 };
84
85 explicit LayoutContainer(Mode mode, QQuickItem* parent = nullptr);
86
87 qreal linearSpacing() const;
88 bool setLinearSpacing(qreal spacing);
89
90 void componentComplete() override;
91 void geometryChange(const QRectF& newGeometry, const QRectF& oldGeometry) override;
92 void itemChange(ItemChange change, const ItemChangeData& data) override;
93 void updatePolish() override;
94
95private:
96 friend class LayoutContainerPrivate;
97 const std::unique_ptr<LayoutContainerPrivate> d;
98};
99
100class QML_MATERIAL_API LinearLayoutContainer : public LayoutContainer {
101 Q_OBJECT
102 QML_ANONYMOUS
103 Q_PROPERTY(qreal spacing READ spacing WRITE setSpacing NOTIFY spacingChanged FINAL)
104
105public:
106 qreal spacing() const;
107 void setSpacing(qreal spacing);
108
109 Q_SIGNAL void spacingChanged();
110
111protected:
112 explicit LinearLayoutContainer(Mode mode, QQuickItem* parent = nullptr);
113};
114
120class QML_MATERIAL_API Box : public LayoutContainer {
121 Q_OBJECT
122 QML_NAMED_ELEMENT(Box)
123
124public:
125 explicit Box(QQuickItem* parent = nullptr);
126};
127
133class QML_MATERIAL_API Row : public LinearLayoutContainer {
134 Q_OBJECT
135 QML_NAMED_ELEMENT(Row)
136
137public:
138 explicit Row(QQuickItem* parent = nullptr);
139};
140
146class QML_MATERIAL_API Column : public LinearLayoutContainer {
147 Q_OBJECT
148 QML_NAMED_ELEMENT(Column)
149
150public:
151 explicit Column(QQuickItem* parent = nullptr);
152};
153
154} // namespace qml_material
Definition layout_container.hpp:120
Definition layout_container.hpp:146
Definition layout_container.hpp:23
Definition layout_container.hpp:133