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(qreal smoothness READ smoothness WRITE set_smoothness NOTIFY smoothnessChanged FINAL)
22 QML_NAMED_ELEMENT(PathWave)
23 QML_ADDED_IN_VERSION(2, 0)
24
25public:
26 explicit PathWave(QObject* parent = nullptr);
27 ~PathWave() override;
28
29 auto amplitude() const noexcept -> qreal;
30 auto wave_length() const noexcept -> qreal;
31 auto phase() const noexcept -> qreal;
32 auto smoothness() const noexcept -> qreal;
33
34 void set_amplitude(qreal);
35 void set_wave_length(qreal);
36 void set_phase(qreal);
37 void set_smoothness(qreal);
38
39 void addToPath(QPainterPath& path, const QQuickPathData& data) override;
40
41Q_SIGNALS:
42 void amplitudeChanged();
43 void waveLengthChanged();
44 void phaseChanged();
45 void smoothnessChanged();
46
47private:
48 qreal m_amplitude { 4.0 };
49 qreal m_wave_length { 30.0 };
50 qreal m_phase { 0.0 };
51 qreal m_smoothness { 0.48 };
52};
53
54} // namespace qml_material