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(QQmlComponent* moreButton READ moreButton WRITE setMoreButton NOTIFY
55 moreButtonChanged FINAL)
56 Q_PROPERTY(qreal spacing READ spacing WRITE setSpacing NOTIFY spacingChanged FINAL)
57 Q_PROPERTY(
58 Qt::Alignment alignment READ alignment WRITE setAlignment NOTIFY alignmentChanged FINAL)
59 Q_PROPERTY(qreal visibleWidth READ visibleWidth NOTIFY visibleWidthChanged FINAL)
60 Q_PROPERTY(qreal minimumWidth READ minimumWidth NOTIFY minimumWidthChanged FINAL)
61 Q_PROPERTY(Qt::LayoutDirection layoutDirection READ layoutDirection WRITE setLayoutDirection
62 NOTIFY layoutDirectionChanged FINAL)
63 Q_PROPERTY(
64 HeightMode heightMode READ heightMode WRITE setHeightMode NOTIFY heightModeChanged FINAL)
65 Q_PROPERTY(qint32 maxShowActionNum READ maxShowActionNum WRITE setMaxShowActionNum NOTIFY
66 maxShowActionNumChanged FINAL)
67
68public:
69 using ActionsProperty = QQmlListProperty<Action>;
70
71 enum HeightMode
72 {
73 AlwaysCenter,
74 AlwaysFill,
75 ConstrainIfLarger,
76 };
77 Q_ENUM(HeightMode)
78
79 // Folded from former kirigami DisplayHint singleton. QML never referenced
80 // MD.DisplayHint directly; only ToolBarLayout consumes these flags via the
81 // `displayHint` property on Action objects.
82 enum DisplayHint : uint
83 {
84 NoPreference = 0,
85 IconOnly = 1,
86 KeepVisible = 2,
87 AlwaysHide = 4,
88 HideChildIndicator = 8,
89 };
90 Q_DECLARE_FLAGS(DisplayHints, DisplayHint)
91 Q_FLAG(DisplayHints)
92
93 static bool isDisplayHintSet(DisplayHints values, DisplayHint hint);
94
95 ToolBarLayout(QQuickItem* parent = nullptr);
96 ~ToolBarLayout() override;
97
98 ActionsProperty actionsProperty() const;
99 void addAction(Action* action);
100 void removeAction(Action* action);
101 void clearActions();
102 Q_SIGNAL void actionsChanged();
103
104 QList<Action*> hiddenActions() const;
105 Q_SIGNAL void hiddenActionsChanged();
106
107 QQmlComponent* fullDelegate() const;
108 void setFullDelegate(QQmlComponent* newFullDelegate);
109 Q_SIGNAL void fullDelegateChanged();
110
111 QQmlComponent* iconDelegate() const;
112 void setIconDelegate(QQmlComponent* newIconDelegate);
113 Q_SIGNAL void iconDelegateChanged();
114
115 QQmlComponent* separatorDelegate() const;
116 void setSeparatorDelegate(QQmlComponent* newSeparatorDelegate);
117 Q_SIGNAL void separatorDelegateChanged();
118
119 QQmlComponent* moreButton() const;
120 void setMoreButton(QQmlComponent* newMoreButton);
121 Q_SIGNAL void moreButtonChanged();
122
123 qreal spacing() const;
124 void setSpacing(qreal newSpacing);
125 Q_SIGNAL void spacingChanged();
126
127 Qt::Alignment alignment() const;
128 void setAlignment(Qt::Alignment newAlignment);
129 Q_SIGNAL void alignmentChanged();
130
131 qreal visibleWidth() const;
132 Q_SIGNAL void visibleWidthChanged();
133
134 qreal minimumWidth() const;
135 Q_SIGNAL void minimumWidthChanged();
136
137 Qt::LayoutDirection layoutDirection() const;
138 void setLayoutDirection(Qt::LayoutDirection& newLayoutDirection);
139 Q_SIGNAL void layoutDirectionChanged();
140
141 HeightMode heightMode() const;
142 void setHeightMode(HeightMode newHeightMode);
143 Q_SIGNAL void heightModeChanged();
144
145 qint32 maxShowActionNum() const;
146 void setMaxShowActionNum(qint32 maxShowActionNum);
147 Q_SIGNAL void maxShowActionNumChanged();
148
149 Q_SLOT void relayout();
150
151 static ToolBarLayoutAttached* qmlAttachedProperties(QObject* object) {
152 return new ToolBarLayoutAttached(object);
153 }
154
155protected:
156 void componentComplete() override;
157 void geometryChange(const QRectF& newGeometry, const QRectF& oldGeometry) override;
158 void itemChange(QQuickItem::ItemChange change, const QQuickItem::ItemChangeData& data) override;
159 void updatePolish() override;
160
161private:
162 friend class ToolBarLayoutPrivate;
163 const std::unique_ptr<ToolBarLayoutPrivate> d;
164};
165
166Q_DECLARE_OPERATORS_FOR_FLAGS(ToolBarLayout::DisplayHints)
167
168} // namespace qml_material
Definition toolbar_layout.hpp:26
Definition toolbar_layout.hpp:42