QmlMaterial 0.1.0
Loading...
Searching...
No Matches
progress_indicator.hpp
1#pragma once
2
3#include "qml_material/control/progress_bar.hpp"
4#include "qml_material/indicator/progress_indicator_geometry.hpp"
5
6namespace qml_material
7{
9class QML_MATERIAL_API ProgressIndicator : public ProgressBar {
10 Q_OBJECT
11 QML_ANONYMOUS
12 Q_PROPERTY(
13 bool running READ running WRITE setRunning RESET resetRunning NOTIFY runningChanged FINAL)
14 Q_PROPERTY(bool wavy READ wavy WRITE setWavy NOTIFY wavyChanged FINAL)
15 Q_PROPERTY(bool animationsEnabled READ animationsEnabled WRITE setAnimationsEnabled NOTIFY
16 animationsEnabledChanged FINAL)
17 Q_PROPERTY(bool animating READ animating NOTIFY frameChanged FINAL)
18 Q_PROPERTY(
19 qreal strokeWidth READ strokeWidth WRITE setStrokeWidth NOTIFY strokeWidthChanged FINAL)
20 Q_PROPERTY(qreal waveLength READ waveLength WRITE setWaveLength RESET resetWaveLength NOTIFY
21 waveLengthChanged FINAL)
22 Q_PROPERTY(qreal waveAmplitude READ waveAmplitude WRITE setWaveAmplitude NOTIFY
23 waveAmplitudeChanged FINAL)
24 Q_PROPERTY(int waveCycleDuration READ waveCycleDuration WRITE setWaveCycleDuration RESET
25 resetWaveCycleDuration NOTIFY waveCycleDurationChanged FINAL)
26 Q_PROPERTY(
27 qreal gapSize READ gapSize WRITE setGapSize RESET resetGapSize NOTIFY gapSizeChanged FINAL)
28 Q_PROPERTY(qreal gapAngle READ gapAngle WRITE setGapAngle RESET resetGapAngle NOTIFY
29 gapAngleChanged FINAL)
30 Q_PROPERTY(qreal startAngle READ startAngle WRITE setStartAngle NOTIFY startAngleChanged FINAL)
31 Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged FINAL)
32 Q_PROPERTY(QColor trackColor READ trackColor WRITE setTrackColor NOTIFY trackColorChanged FINAL)
33 Q_PROPERTY(
34 QColor inactiveColor READ trackColor WRITE setTrackColor NOTIFY trackColorChanged FINAL)
35 Q_PROPERTY(QColor stopIndicatorColor READ stopIndicatorColor WRITE setStopIndicatorColor NOTIFY
36 stopIndicatorColorChanged FINAL)
37 Q_PROPERTY(int type READ type WRITE setType RESET resetType NOTIFY typeChanged FINAL)
38 Q_PROPERTY(AnimStateType animationState READ animationState WRITE setAnimationState NOTIFY
39 frameChanged FINAL)
40 Q_PROPERTY(CompletionBehavior completionBehavior READ completionBehavior WRITE
41 setCompletionBehavior NOTIFY completionBehaviorChanged FINAL)
42 Q_PROPERTY(qreal displayedPosition READ displayedPosition NOTIFY frameChanged FINAL)
43 Q_PROPERTY(qreal phase READ phase NOTIFY frameChanged FINAL)
44 Q_PROPERTY(qreal amplitudeFraction READ amplitudeFraction NOTIFY frameChanged FINAL)
45 Q_PROPERTY(qreal progress READ progress NOTIFY frameChanged FINAL)
46 Q_PROPERTY(QSizeF preferredSize READ preferredSize NOTIFY parametersChanged FINAL)
47public:
48 enum AnimStateType
49 {
50 Running = 0,
51 Completing = 1,
52 Stopped = 2
53 };
54 Q_ENUM(AnimStateType)
55 enum CompletionBehavior
56 {
57 Keep = 0,
58 Drain = 1
59 };
60 Q_ENUM(CompletionBehavior)
61 ~ProgressIndicator() override;
62 bool running() const;
63 bool wavy() const;
64 bool animationsEnabled() const;
65 bool animating() const;
66 qreal strokeWidth() const;
67 qreal waveLength() const;
68 qreal waveAmplitude() const;
69 int waveCycleDuration() const;
70 qreal gapSize() const;
71 qreal gapAngle() const;
72 qreal startAngle() const;
73 QColor color() const;
74 QColor trackColor() const;
75 QColor stopIndicatorColor() const;
76 int type() const;
77 AnimStateType animationState() const;
78 CompletionBehavior completionBehavior() const;
79 qreal displayedPosition() const;
80 qreal phase() const;
81 qreal amplitudeFraction() const;
82 qreal progress() const;
83 QSizeF preferredSize() const;
84 ProgressIndicatorState renderState() const;
85 void setRunning(bool value);
86 void resetRunning();
87 void setWavy(bool value);
88 void setAnimationsEnabled(bool value);
89 void setStrokeWidth(qreal value);
90 void setWaveLength(qreal value);
91 void resetWaveLength();
92 void setWaveAmplitude(qreal value);
93 void setWaveCycleDuration(int value);
94 void resetWaveCycleDuration();
95 void setGapSize(qreal value);
96 void resetGapSize();
97 void setGapAngle(qreal value);
98 void resetGapAngle();
99 void setStartAngle(qreal value);
100 void setColor(QColor value);
101 void setTrackColor(QColor value);
102 void setStopIndicatorColor(QColor value);
103 void setType(int value);
104 void resetType();
105 void setAnimationState(AnimStateType value);
106 void setCompletionBehavior(CompletionBehavior value);
107 Q_SIGNAL void parametersChanged();
108 Q_SIGNAL void runningChanged();
109 Q_SIGNAL void wavyChanged();
110 Q_SIGNAL void animationsEnabledChanged();
111 Q_SIGNAL void strokeWidthChanged();
112 Q_SIGNAL void waveLengthChanged();
113 Q_SIGNAL void waveAmplitudeChanged();
114 Q_SIGNAL void waveCycleDurationChanged();
115 Q_SIGNAL void gapSizeChanged();
116 Q_SIGNAL void gapAngleChanged();
117 Q_SIGNAL void startAngleChanged();
118 Q_SIGNAL void colorChanged();
119 Q_SIGNAL void trackColorChanged();
120 Q_SIGNAL void stopIndicatorColorChanged();
121 Q_SIGNAL void typeChanged();
122 Q_SIGNAL void completionBehaviorChanged();
123 Q_SIGNAL void frameChanged();
124
125protected:
126 explicit ProgressIndicator(bool circular, QQuickItem* parent = nullptr);
127 void componentComplete() override;
128 void updatePolish() override;
129 // Deterministic elapsed sampling, shared by the window clock and native tests.
130 void advanceAnimations(qreal elapsedMs);
131
132private:
133 struct Private;
134 std::unique_ptr<Private> d;
135 void synchronize(bool immediate = false);
136 void notifyParameters();
137 void publish();
138 void bindWindow(QQuickWindow* window);
139 void observeViewport();
140 void refreshViewport();
141 void schedule();
142 bool eligible() const;
143 bool needsAnimation() const;
144};
145
147class QML_MATERIAL_API LinearIndicator : public ProgressIndicator {
148 Q_OBJECT
149 QML_NAMED_ELEMENT(LinearIndicatorBase)
150public:
151 enum AnimType
152 {
153 Disjoint = 0,
154 Contiguous = 1
155 };
156 Q_ENUM(AnimType)
157 explicit LinearIndicator(QQuickItem* parent = nullptr): ProgressIndicator(false, parent) {}
158};
159
161class QML_MATERIAL_API CircularIndicator : public ProgressIndicator {
162 Q_OBJECT
163 QML_NAMED_ELEMENT(CircularIndicatorBase)
164public:
165 enum AnimType
166 {
167 Advance = 0,
168 Reteat = 1,
169 Retreat = 1
170 };
171 Q_ENUM(AnimType)
172 explicit CircularIndicator(QQuickItem* parent = nullptr): ProgressIndicator(true, parent) {}
173};
174} // namespace qml_material
Material Design 3 circular progress indicator.
Definition CircularIndicator.qml:6
Material Design 3 linear progress indicator.
Definition LinearIndicator.qml:6