QmlMaterial 0.1.0
Loading...
Searching...
No Matches
toolbar_layout.hpp
1/*
2 * SPDX-FileCopyrightText: 2020 Arjen Hiemstra <ahiemstra@heimr.nl>
3 *
4 * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
5 *
6 * Adapted from KDE Kirigami; integrated into qml_material.
7 */
8
9#pragma once
10
11#include <QQuickItem>
12#include <QQmlEngine>
13#include <memory>
14#include "qml_material/control/action.hpp"
15#include "qml_material/export.hpp"
16
17namespace qml_material
18{
19
20class ToolBarLayout;
21class ToolBarLayoutPrivate;
22
26class QML_MATERIAL_API ToolBarLayoutAttached : public QObject {
27 Q_OBJECT
28 Q_PROPERTY(Action* action READ action CONSTANT FINAL)
29public:
30 ToolBarLayoutAttached(QObject* parent = nullptr);
31
32 Action* action() const;
33 void setAction(Action* action);
34
35private:
36 Action* m_action = nullptr;
37};
38
42class QML_MATERIAL_API ToolBarLayout : public QQuickItem {
43 Q_OBJECT
44 QML_ELEMENT
45 QML_ATTACHED(ToolBarLayoutAttached)
46 Q_PROPERTY(QQmlListProperty<Action> actions READ actionsProperty NOTIFY actionsChanged FINAL)
47 Q_PROPERTY(QList<Action*> hiddenActions READ hiddenActions NOTIFY hiddenActionsChanged FINAL)
48 Q_PROPERTY(QQmlComponent* fullDelegate READ fullDelegate WRITE setFullDelegate NOTIFY
49 fullDelegateChanged FINAL)
50 Q_PROPERTY(QQmlComponent* iconDelegate READ iconDelegate WRITE setIconDelegate NOTIFY
51 iconDelegateChanged FINAL)
52 Q_PROPERTY(QQmlComponent* separatorDelegate READ separatorDelegate WRITE setSeparatorDelegate
53 NOTIFY separatorDelegateChanged FINAL)
54 Q_PROPERTY(QQuickItem* moreButtonItem READ moreButtonItem NOTIFY moreButtonItemChanged FINAL)
55 Q_PROPERTY(QQmlComponent* moreButton READ moreButton WRITE setMoreButton NOTIFY
56 moreButtonChanged FINAL)
57 Q_PROPERTY(qreal spacing READ spacing WRITE setSpacing NOTIFY spacingChanged FINAL)
58 Q_PROPERTY(
59 Qt::Alignment alignment READ alignment WRITE setAlignment NOTIFY alignmentChanged FINAL)
60 Q_PROPERTY(qreal visibleWidth READ visibleWidth NOTIFY visibleWidthChanged FINAL)
61 Q_PROPERTY(qreal minimumWidth READ minimumWidth NOTIFY minimumWidthChanged FINAL)
62 Q_PROPERTY(Qt::LayoutDirection layoutDirection READ layoutDirection WRITE setLayoutDirection
63 NOTIFY layoutDirectionChanged FINAL)
64 Q_PROPERTY(
65 HeightMode heightMode READ heightMode WRITE setHeightMode NOTIFY heightModeChanged FINAL)
66 Q_PROPERTY(qint32 maxShowActionNum READ maxShowActionNum WRITE setMaxShowActionNum NOTIFY
67 maxShowActionNumChanged FINAL)
68
69public:
70 using ActionsProperty = QQmlListProperty<Action>;
71
72 enum HeightMode
73 {
74 AlwaysCenter,
75 AlwaysFill,
76 ConstrainIfLarger,
77 };
78 Q_ENUM(HeightMode)
79
80 // Folded from former kirigami DisplayHint singleton. QML never referenced
81 // MD.DisplayHint directly; only ToolBarLayout consumes these flags via the
82 // `displayHint` property on Action objects.
83 enum DisplayHint : uint
84 {
85 NoPreference = 0,
86 IconOnly = 1,
87 KeepVisible = 2,
88 AlwaysHide = 4,
89 HideChildIndicator = 8,
90 };
91 Q_DECLARE_FLAGS(DisplayHints, DisplayHint)
92 Q_FLAG(DisplayHints)
93
94 static bool isDisplayHintSet(DisplayHints values, DisplayHint hint);
95
96 ToolBarLayout(QQuickItem* parent = nullptr);
97 ~ToolBarLayout() override;
98
99 ActionsProperty actionsProperty() const;
100 void addAction(Action* action);
101 void removeAction(Action* action);
102 void clearActions();
103 Q_SIGNAL void actionsChanged();
104
105 QList<Action*> hiddenActions() const;
106 Q_SIGNAL void hiddenActionsChanged();
107
108 QQmlComponent* fullDelegate() const;
109 void setFullDelegate(QQmlComponent* newFullDelegate);
110 Q_SIGNAL void fullDelegateChanged();
111
112 QQmlComponent* iconDelegate() const;
113 void setIconDelegate(QQmlComponent* newIconDelegate);
114 Q_SIGNAL void iconDelegateChanged();
115
116 QQmlComponent* separatorDelegate() const;
117 void setSeparatorDelegate(QQmlComponent* newSeparatorDelegate);
118 Q_SIGNAL void separatorDelegateChanged();
119
120 QQuickItem* moreButtonItem() const;
121 Q_SIGNAL void moreButtonItemChanged();
122 QQmlComponent* moreButton() const;
123 void setMoreButton(QQmlComponent* newMoreButton);
124 Q_SIGNAL void moreButtonChanged();
125
126 qreal spacing() const;
127 void setSpacing(qreal newSpacing);
128 Q_SIGNAL void spacingChanged();
129
130 Qt::Alignment alignment() const;
131 void setAlignment(Qt::Alignment newAlignment);
132 Q_SIGNAL void alignmentChanged();
133
134 qreal visibleWidth() const;
135 Q_SIGNAL void visibleWidthChanged();
136
137 qreal minimumWidth() const;
138 Q_SIGNAL void minimumWidthChanged();
139
140 Qt::LayoutDirection layoutDirection() const;
141 void setLayoutDirection(Qt::LayoutDirection& newLayoutDirection);
142 Q_SIGNAL void layoutDirectionChanged();
143
144 HeightMode heightMode() const;
145 void setHeightMode(HeightMode newHeightMode);
146 Q_SIGNAL void heightModeChanged();
147
148 qint32 maxShowActionNum() const;
149 void setMaxShowActionNum(qint32 maxShowActionNum);
150 Q_SIGNAL void maxShowActionNumChanged();
151
152 Q_SLOT void relayout();
153
154 static ToolBarLayoutAttached* qmlAttachedProperties(QObject* object) {
155 return new ToolBarLayoutAttached(object);
156 }
157
158protected:
159 void componentComplete() override;
160 void geometryChange(const QRectF& newGeometry, const QRectF& oldGeometry) override;
161 void itemChange(QQuickItem::ItemChange change, const QQuickItem::ItemChangeData& data) override;
162 void updatePolish() override;
163
164private:
165 friend class ToolBarLayoutPrivate;
166 const std::unique_ptr<ToolBarLayoutPrivate> d;
167};
168
169Q_DECLARE_OPERATORS_FOR_FLAGS(ToolBarLayout::DisplayHints)
170
171} // namespace qml_material
Definition toolbar_layout.hpp:26
Definition toolbar_layout.hpp:42