QmlMaterial 0.1.0
Loading...
Searching...
No Matches
path_wave.hpp
1#pragma once
2
3#include <QtQuick/private/qquickpath_p.h>
4
5#include "qml_material/export.hpp"
6
7namespace qml_material
8{
9
10// Wavy path segment between the previous element's endpoint and (x, y).
11// Geometry mirrors material-components-android LinearDrawingDelegate
12// (two cubic Beziers per cycle, smoothness = 0.48). The wavelength is
13// constant in pixels; the path is truncated with de Casteljau so it lands
14// exactly at the declared endpoint regardless of phase.
15class QML_MATERIAL_API PathWave : public QQuickCurve {
16 Q_OBJECT
17 Q_PROPERTY(qreal amplitude READ amplitude WRITE set_amplitude NOTIFY amplitudeChanged FINAL)
18 Q_PROPERTY(
19 qreal waveLength READ wave_length WRITE set_wave_length NOTIFY waveLengthChanged FINAL)
20 Q_PROPERTY(qreal phase READ phase WRITE set_phase NOTIFY phaseChanged FINAL)
21 Q_PROPERTY(
22 qreal smoothness READ smoothness WRITE set_smoothness NOTIFY smoothnessChanged FINAL)
23 QML_NAMED_ELEMENT(PathWave)
24 QML_ADDED_IN_VERSION(2, 0)
25
26public:
27 explicit PathWave(QObject* parent = nullptr);
28 ~PathWave() override;
29
30 auto amplitude() const noexcept -> qreal;
31 auto wave_length() const noexcept -> qreal;
32 auto phase() const noexcept -> qreal;
33 auto smoothness() const noexcept -> qreal;
34
35 void set_amplitude(qreal);
36 void set_wave_length(qreal);
37 void set_phase(qreal);
38 void set_smoothness(qreal);
39
40 void addToPath(QPainterPath& path, const QQuickPathData& data) override;
41
42Q_SIGNALS:
43 void amplitudeChanged();
44 void waveLengthChanged();
45 void phaseChanged();
46 void smoothnessChanged();
47
48private:
49 qreal m_amplitude { 4.0 };
50 qreal m_wave_length { 30.0 };
51 qreal m_phase { 0.0 };
52 qreal m_smoothness { 0.48 };
53};
54
55} // namespace qml_material