QmlMaterial 0.1.0
Loading...
Searching...
No Matches
loading_indicator_updator.hpp
1#pragma once
2
3#include <QtCore/QList>
4#include <QtGui/QColor>
5#include <QtGui/QPolygonF>
6#include <QtQml/QQmlEngine>
7
8#include "qml_material/core.hpp"
9
10namespace qml_material
11{
12
13class LoadingIndicatorUpdator : public QObject {
14 Q_OBJECT
15 QML_ELEMENT
16
17 // ── Animated outputs ────────────────────────────────────────────────────
18 Q_PROPERTY(QPolygonF currentShape READ currentShape NOTIFY updated FINAL)
19 Q_PROPERTY(double rotation READ rotation NOTIFY updated FINAL)
20 Q_PROPERTY(QColor color READ color NOTIFY updated FINAL)
21 Q_PROPERTY(double morphFraction READ morphFraction NOTIFY updated FINAL)
22
23 // ── Driver input ────────────────────────────────────────────────────────
24 Q_PROPERTY(double progress READ progress WRITE setProgress NOTIFY updated FINAL)
25
26 // ── Configuration ───────────────────────────────────────────────────────
27 Q_PROPERTY(QList<QColor> colors READ colors WRITE setColors NOTIFY colorsChanged FINAL)
28
29 // ── Constants exposed to QML (avoids hard-coding magic numbers) ─────────
30 Q_PROPERTY(int shapeCount READ shapeCount CONSTANT FINAL)
31 Q_PROPERTY(int msPerShape READ msPerShape CONSTANT FINAL)
32
33public:
34 explicit LoadingIndicatorUpdator(QObject* parent = nullptr);
35
36 // Animated outputs
37 auto currentShape() const noexcept -> QPolygonF;
38 auto rotation() const noexcept -> double;
39 auto color() const noexcept -> QColor;
40 auto morphFraction() const noexcept -> double;
41
42 // Driver
43 auto progress() const noexcept -> double;
44 void setProgress(double p);
45
46 // Configuration
47 auto colors() const -> QList<QColor>;
48 void setColors(const QList<QColor>& colors);
49
50 // Constants
51 static int shapeCount() { return SHAPE_COUNT; }
52 static int msPerShape() { return MS_PER_SHAPE; }
53
54 Q_SIGNAL void updated();
55 Q_SIGNAL void colorsChanged();
56
57private:
58 void updateInternal() noexcept;
59
60 auto interpolateShapes(const QPolygonF& s1, const QPolygonF& s2,
61 double t) const -> QPolygonF;
62
63 // State
64 double m_progress;
65 double m_morph_fraction;
66 double m_rotation;
67 QColor m_color;
68 QList<QColor> m_colors;
69
70 // Pre-built shape data
71 QList<QPolygonF> m_predefined_shapes; // original shapes
72 QList<QPolygonF> m_aligned_shapes; // s[i] rotated to best match s[i-1]
73
74 // Constants
75 static constexpr int SHAPE_COUNT = 7;
76 static constexpr int SAMPLE_COUNT = 64; // points per shape (power-of-2)
77 static constexpr int MS_PER_SHAPE = 650;
78};
79
80} // namespace qml_material