QmlMaterial 0.1.0
Loading...
Searching...
No Matches
progress_indicator_geometry.hpp
1#pragma once
2
3#include "qml_material/path/measured_path.hpp"
4#include <QtGui/QColor>
5#include <QtCore/QSizeF>
6
7namespace qml_material
8{
9struct ProgressSegment {
10 qreal start = 0;
11 qreal end = 0;
12 QColor color;
13 qreal gapSize = 0;
14 qreal trackGapSize = -1;
15};
16
17struct ProgressIndicatorState {
18 bool circular = false;
19 bool indeterminate = false;
20 bool wavy = false;
21 bool mirrored = false;
22 bool legacyRadius = false;
23 bool legacyCenter = false;
24 bool legacySegments = false;
25 qreal position = 0;
26 qreal phase = 0;
27 qreal amplitudeFraction = 1;
28 qreal rotation = 0;
29 qreal startAngle = -90;
30 qreal strokeWidth = 4;
31 qreal waveLength = 40;
32 qreal waveAmplitude = 3;
33 qreal gapSize = 4;
34 qreal gapAngle = -1;
35 qreal drain = 0;
36 qreal opacity = 1;
37 QColor trackColor;
38 QColor stopColor;
39 bool stopVisible = true;
40 std::vector<ProgressSegment> segments;
41 // Compatibility helpers supply an explicit inactive arc.
42 bool explicitTrack = false;
43 qreal trackStart = 0;
44 qreal trackSweep = 0;
45};
46
47struct ProgressDrawPath {
48 QPainterPath path;
49 QColor color;
50 qreal strokeWidth = 0;
51};
52
53class QML_MATERIAL_API ProgressIndicatorGeometry {
54public:
55 static QPointF lineBounds(qreal start, qreal end, qreal gap, qreal stroke, qreal width);
56 // The result is retained until the next render on this instance.
57 const std::vector<ProgressDrawPath>& render(const ProgressIndicatorState& state, QSizeF size);
58 quint64 cacheRevision() const { return m_revision; }
59
60private:
61 void rebuild(const ProgressIndicatorState& state, QSizeF size);
62 QSizeF m_size;
63 bool m_circular = false;
64 bool m_wavy = false;
65 bool m_legacyRadius = false;
66 bool m_legacyCenter = false;
67 qreal m_stroke = -1;
68 qreal m_wavelength = -1;
69 qreal m_amplitude = -1;
70 qreal m_radius = 0;
71 qreal m_actualWavelength = 0;
72 int m_cycles = 0;
73 MeasuredPath m_wave;
74 MeasuredPath m_circle;
75 quint64 m_revision = 0;
76 std::vector<ProgressDrawPath> m_result;
77};
78} // namespace qml_material