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