QmlMaterial 0.1.0
Loading...
Searching...
No Matches
fab_menu.hpp
1#pragma once
2
3#include "qml_material/control/command_button.hpp"
4#include "qml_material/control/container.hpp"
5
6namespace qml_material
7{
8class Flickable;
9
10class QML_MATERIAL_API FABMenuItem : public CommandButton {
11 Q_OBJECT
12 QML_NAMED_ELEMENT(FABMenuItemBase)
13 Q_PROPERTY(bool revealed READ revealed NOTIFY presentationChanged FINAL)
14 Q_PROPERTY(bool motionEnabled READ motionEnabled NOTIFY presentationChanged FINAL)
15 Q_PROPERTY(bool alignRight READ alignRight NOTIFY presentationChanged FINAL)
16 Q_PROPERTY(qreal fullWidth READ fullWidth NOTIFY fullWidthChanged FINAL)
17 Q_PROPERTY(
18 qreal widthProgress READ widthProgress WRITE setWidthProgress NOTIFY progressChanged FINAL)
19 Q_PROPERTY(
20 qreal alphaProgress READ alphaProgress WRITE setAlphaProgress NOTIFY progressChanged FINAL)
21 Q_PROPERTY(bool animating READ animating WRITE setAnimating NOTIFY animatingChanged FINAL)
22 Q_PROPERTY(bool inputEnabled READ inputEnabled NOTIFY inputEnabledChanged FINAL)
23public:
24 explicit FABMenuItem(QQuickItem* parent = nullptr): CommandButton(parent) {}
25 bool revealed() const { return m_revealed; }
26 bool motionEnabled() const { return m_motionEnabled; }
27 bool alignRight() const { return m_alignRight; }
28 qreal fullWidth() const { return m_fullWidth; }
29 qreal widthProgress() const { return m_widthProgress; }
30 qreal alphaProgress() const { return m_alphaProgress; }
31 bool animating() const { return m_animating; }
32 bool inputEnabled() const { return m_inputEnabled; }
33 bool contains(const QPointF&) const override;
34 void setWidthProgress(qreal);
35 void setAlphaProgress(qreal);
36 void setAnimating(bool);
37 Q_SIGNAL void presentationChanged();
38 Q_SIGNAL void fullWidthChanged();
39 Q_SIGNAL void progressChanged();
40 Q_SIGNAL void animatingChanged();
41 Q_SIGNAL void inputEnabledChanged();
42
43protected:
44 void focusInEvent(QFocusEvent*) override;
45 bool canActivate() const override { return m_inputEnabled && CommandButton::canActivate(); }
46
47private:
48 friend class FABMenu;
49 void setInputEnabled(bool);
50 bool m_revealed = true;
51 bool m_motionEnabled = false;
52 bool m_alignRight = true;
53 bool m_animating = false;
54 bool m_inputEnabled = true;
55 qreal m_fullWidth = 0;
56 qreal m_widthProgress = 1;
57 qreal m_alphaProgress = 1;
58};
59
63class QML_MATERIAL_API FABMenu : public Container {
64 Q_OBJECT
65 QML_NAMED_ELEMENT(FABMenuBase)
66 Q_PROPERTY(bool expanded READ expanded WRITE setExpanded NOTIFY expandedChanged FINAL)
67 Q_PROPERTY(QQuickItem* button READ button WRITE setButton NOTIFY buttonChanged FINAL)
68 Q_PROPERTY(Qt::Alignment horizontalAlignment READ horizontalAlignment WRITE
69 setHorizontalAlignment NOTIFY horizontalAlignmentChanged FINAL)
70 Q_PROPERTY(qreal buttonSpacing READ buttonSpacing WRITE setButtonSpacing NOTIFY
71 buttonSpacingChanged FINAL)
72 Q_PROPERTY(int visibleCount READ visibleCount NOTIFY visibleCountChanged FINAL)
73 Q_PROPERTY(
74 qreal revealCount READ revealCount WRITE setRevealCount NOTIFY revealCountChanged FINAL)
75 Q_PROPERTY(bool motionEnabled READ motionEnabled NOTIFY motionEnabledChanged FINAL)
76 Q_PROPERTY(bool sequencing READ sequencing WRITE setSequencing NOTIFY sequencingChanged FINAL)
77 Q_PROPERTY(bool animationsEnabled READ animationsEnabled WRITE setAnimationsEnabled NOTIFY
78 animationsEnabledChanged FINAL)
79 Q_PROPERTY(bool transitioning READ transitioning NOTIFY transitioningChanged FINAL)
80 Q_PROPERTY(QQuickItem* viewport READ viewport CONSTANT FINAL)
81public:
82 explicit FABMenu(QQuickItem* parent = nullptr);
83 ~FABMenu() override;
84 bool expanded() const { return m_expanded; }
85 void setExpanded(bool);
86 QQuickItem* button() const { return m_button; }
87 void setButton(QQuickItem*);
88 Qt::Alignment horizontalAlignment() const { return m_alignment; }
89 void setHorizontalAlignment(Qt::Alignment);
90 qreal buttonSpacing() const { return m_buttonSpacing; }
91 void setButtonSpacing(qreal);
92 int visibleCount() const { return m_visibleCount; }
93 qreal revealCount() const { return m_revealCount; }
94 void setRevealCount(qreal);
95 bool motionEnabled() const { return m_ready; }
96 bool sequencing() const { return m_sequencing; }
97 bool animationsEnabled() const { return m_animationsEnabled; }
98 void setAnimationsEnabled(bool);
99 void setSequencing(bool);
100 bool transitioning() const { return m_transitioning; }
101 QQuickItem* viewport() const;
102 Q_INVOKABLE void open() { setExpanded(true); }
103 Q_INVOKABLE void close() { setExpanded(false); }
104 Q_INVOKABLE void toggle() { setExpanded(! m_expanded); }
105 Q_INVOKABLE void requestExpanded(bool);
106 Q_SIGNAL void expandedChangeRequested(bool expanded);
107 Q_SIGNAL void expandedChanged();
108 Q_SIGNAL void buttonChanged();
109 Q_SIGNAL void horizontalAlignmentChanged();
110 Q_SIGNAL void buttonSpacingChanged();
111 Q_SIGNAL void visibleCountChanged();
112 Q_SIGNAL void revealCountChanged();
113 Q_SIGNAL void motionEnabledChanged();
114 Q_SIGNAL void sequencingChanged();
115 Q_SIGNAL void animationsEnabledChanged();
116 Q_SIGNAL void transitioningChanged();
117
118protected:
119 bool isContent(QQuickItem*) const override;
120 void itemAdded(QQuickItem*) override;
121 void itemRemoved(QQuickItem*) override;
122 void updatePolish() override;
123 bool eventFilter(QObject*, QEvent*) override;
124
125private:
126 void updateTransitioning();
127 void updateInput();
128 QList<FABMenuItem*> visibleItems() const;
129 Flickable* m_viewport;
130 QPointer<QQuickItem> m_button;
131 QList<QMetaObject::Connection> m_buttonConnections;
132 QHash<QQuickItem*, QList<QMetaObject::Connection>> m_itemConnections;
133 Qt::Alignment m_alignment = Qt::AlignRight;
134 qreal m_buttonSpacing = 8;
135 qreal m_revealCount = 0;
136 int m_visibleCount = 0;
137 bool m_expanded = false;
138 bool m_ready = false;
139 bool m_sequencing = false;
140 bool m_animationsEnabled = true;
141 bool m_transitioning = false;
142};
143} // namespace qml_material
Definition container.hpp:14
Definition fab_menu.hpp:63