QmlMaterial 0.1.0
Loading...
Searching...
No Matches
toolbarlayout.h
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
7#ifndef TOOLBARLAYOUT_H
8#define TOOLBARLAYOUT_H
9
10#include <QQuickItem>
11#include <memory>
12
13class ToolBarLayoutPrivate;
14
18class ToolBarLayoutAttached : public QObject
19{
20 Q_OBJECT
24 Q_PROPERTY(QObject *action READ action CONSTANT FINAL)
25public:
26 ToolBarLayoutAttached(QObject *parent = nullptr);
27
28 QObject *action() const;
29 void setAction(QObject *action);
30
31private:
32 QObject *m_action = nullptr;
33};
34
48class ToolBarLayout : public QQuickItem
49{
50 Q_OBJECT
51 QML_ELEMENT
52 QML_ATTACHED(ToolBarLayoutAttached)
56 Q_PROPERTY(QQmlListProperty<QObject> actions READ actionsProperty NOTIFY actionsChanged FINAL)
60 Q_PROPERTY(QList<QObject *> hiddenActions READ hiddenActions NOTIFY hiddenActionsChanged FINAL)
71 Q_PROPERTY(QQmlComponent *fullDelegate READ fullDelegate WRITE setFullDelegate NOTIFY fullDelegateChanged FINAL)
77 Q_PROPERTY(QQmlComponent *iconDelegate READ iconDelegate WRITE setIconDelegate NOTIFY iconDelegateChanged FINAL)
83 Q_PROPERTY(QQmlComponent *separatorDelegate READ separatorDelegate WRITE setSeparatorDelegate NOTIFY separatorDelegateChanged FINAL)
91 Q_PROPERTY(QQmlComponent *moreButton READ moreButton WRITE setMoreButton NOTIFY moreButtonChanged FINAL)
95 Q_PROPERTY(qreal spacing READ spacing WRITE setSpacing NOTIFY spacingChanged FINAL)
104 Q_PROPERTY(Qt::Alignment alignment READ alignment WRITE setAlignment NOTIFY alignmentChanged FINAL)
108 Q_PROPERTY(qreal visibleWidth READ visibleWidth NOTIFY visibleWidthChanged FINAL)
114 Q_PROPERTY(qreal minimumWidth READ minimumWidth NOTIFY minimumWidthChanged FINAL)
128 Q_PROPERTY(Qt::LayoutDirection layoutDirection READ layoutDirection WRITE setLayoutDirection NOTIFY layoutDirectionChanged FINAL)
139 Q_PROPERTY(HeightMode heightMode READ heightMode WRITE setHeightMode NOTIFY heightModeChanged FINAL)
140
141 Q_PROPERTY(qint32 maxShowActionNum READ maxShowActionNum WRITE setMaxShowActionNum NOTIFY maxShowActionNumChanged FINAL)
142
143public:
144 using ActionsProperty = QQmlListProperty<QObject>;
145
155 Q_ENUM(HeightMode)
156
157 ToolBarLayout(QQuickItem *parent = nullptr);
158 ~ToolBarLayout() override;
159
160 ActionsProperty actionsProperty() const;
166 void addAction(QObject *action);
172 void removeAction(QObject *action);
176 void clearActions();
177 Q_SIGNAL void actionsChanged();
178
179 QList<QObject *> hiddenActions() const;
180 Q_SIGNAL void hiddenActionsChanged();
181
182 QQmlComponent *fullDelegate() const;
183 void setFullDelegate(QQmlComponent *newFullDelegate);
184 Q_SIGNAL void fullDelegateChanged();
185
186 QQmlComponent *iconDelegate() const;
187 void setIconDelegate(QQmlComponent *newIconDelegate);
188 Q_SIGNAL void iconDelegateChanged();
189
190 QQmlComponent *separatorDelegate() const;
191 void setSeparatorDelegate(QQmlComponent *newSeparatorDelegate);
192 Q_SIGNAL void separatorDelegateChanged();
193
194 QQmlComponent *moreButton() const;
195 void setMoreButton(QQmlComponent *newMoreButton);
196 Q_SIGNAL void moreButtonChanged();
197
198 qreal spacing() const;
199 void setSpacing(qreal newSpacing);
200 Q_SIGNAL void spacingChanged();
201
202 Qt::Alignment alignment() const;
203 void setAlignment(Qt::Alignment newAlignment);
204 Q_SIGNAL void alignmentChanged();
205
206 qreal visibleWidth() const;
207 Q_SIGNAL void visibleWidthChanged();
208
209 qreal minimumWidth() const;
210 Q_SIGNAL void minimumWidthChanged();
211
212 Qt::LayoutDirection layoutDirection() const;
213 void setLayoutDirection(Qt::LayoutDirection &newLayoutDirection);
214 Q_SIGNAL void layoutDirectionChanged();
215
216 HeightMode heightMode() const;
217 void setHeightMode(HeightMode newHeightMode);
218 Q_SIGNAL void heightModeChanged();
219
220 qint32 maxShowActionNum() const;
221 void setMaxShowActionNum(qint32 maxShowActionNum);
222 Q_SIGNAL void maxShowActionNumChanged();
223
229 Q_SLOT void relayout();
230
231 static ToolBarLayoutAttached *qmlAttachedProperties(QObject *object)
232 {
233 return new ToolBarLayoutAttached(object);
234 }
235
236protected:
237 void componentComplete() override;
238 void geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry) override;
239 void itemChange(QQuickItem::ItemChange change, const QQuickItem::ItemChangeData &data) override;
240 void updatePolish() override;
241
242private:
243 friend class ToolBarLayoutPrivate;
244 const std::unique_ptr<ToolBarLayoutPrivate> d;
245};
246
247QML_DECLARE_TYPEINFO(ToolBarLayout, QML_HAS_ATTACHED_PROPERTIES)
248
249#endif // TOOLBARLAYOUT_H
Definition toolbarlayout.h:19
QObject * action
Definition toolbarlayout.h:24
Definition toolbarlayout.h:49
QQmlComponent * iconDelegate
Definition toolbarlayout.h:77
Q_SLOT void relayout()
Definition toolbarlayout.cpp:281
Qt::Alignment alignment
Definition toolbarlayout.h:104
QQmlComponent * moreButton
Definition toolbarlayout.h:91
QQmlListProperty< QObject > actions
Definition toolbarlayout.h:56
void removeAction(QObject *action)
Definition toolbarlayout.cpp:132
Qt::LayoutDirection layoutDirection
Definition toolbarlayout.h:128
HeightMode heightMode
Definition toolbarlayout.h:139
void clearActions()
Definition toolbarlayout.cpp:146
qreal visibleWidth
Definition toolbarlayout.h:108
qreal spacing
Definition toolbarlayout.h:95
qreal minimumWidth
Definition toolbarlayout.h:114
QQmlComponent * fullDelegate
Definition toolbarlayout.h:71
void addAction(QObject *action)
Definition toolbarlayout.cpp:110
QQmlComponent * separatorDelegate
Definition toolbarlayout.h:83
HeightMode
Definition toolbarlayout.h:150
@ AlwaysFill
Always match the height of the layout. Larger items will be reduced in height, smaller items will be ...
Definition toolbarlayout.h:152
@ ConstrainIfLarger
If the item is larger than the toolbar, reduce its height. Otherwise center it in the toolbar.
Definition toolbarlayout.h:153
@ AlwaysCenter
Always center items, allowing them to go outside the bounds of the layout if they are larger.
Definition toolbarlayout.h:151
QList< QObject * > hiddenActions
Definition toolbarlayout.h:60