Phosphor
Qt6 / Wayland library suite for window-management tools
 
Loading...
Searching...
No Matches
Profile.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2026 fuddlesworth
2// SPDX-License-Identifier: LGPL-2.1-or-later
3
4#pragma once
5
7#include <PhosphorAnimation/phosphoranimation_export.h>
8
9#include <QJsonObject>
10#include <QString>
11#include <QtGlobal>
12
13#include <memory>
14#include <optional>
15
16namespace PhosphorAnimation {
17
18class CurveRegistry;
19
21enum class SequenceMode : int {
22 AllAtOnce = 0,
23 Cascade = 1,
24};
25
32class PHOSPHORANIMATION_EXPORT Profile
33{
34public:
35 static constexpr qreal DefaultDuration = 150.0;
36 static constexpr int DefaultMinDistance = 0;
37 static constexpr SequenceMode DefaultSequenceMode = SequenceMode::AllAtOnce;
38 static constexpr int DefaultStaggerInterval = 30;
39
40 // Upper bounds — anything beyond 1 hour is clearly malformed.
41 static constexpr qreal MaxDurationMs = 60.0 * 60.0 * 1000.0;
42 static constexpr int MaxStaggerIntervalMs = 60 * 60 * 1000;
43
44 Profile() = default;
45
46 Profile(const Profile&) = default;
47 Profile& operator=(const Profile&) = default;
48 Profile(Profile&&) = default;
49 Profile& operator=(Profile&&) = default;
50
52 std::shared_ptr<const Curve> curve;
53
55 std::optional<qreal> duration;
56
58 std::optional<int> minDistance;
59
60 std::optional<SequenceMode> sequenceMode;
61
63 std::optional<int> staggerInterval;
64
66 std::optional<QString> presetName;
67
68 qreal effectiveDuration() const
69 {
70 return duration.value_or(DefaultDuration);
71 }
73 {
74 return minDistance.value_or(DefaultMinDistance);
75 }
77 {
78 return sequenceMode.value_or(DefaultSequenceMode);
79 }
81 {
82 return staggerInterval.value_or(DefaultStaggerInterval);
83 }
84
88
89 // JSON field names — shared with consumers that build Profile blobs externally.
90 static constexpr auto JsonFieldCurve = "curve";
91 static constexpr auto JsonFieldDuration = "duration";
92 static constexpr auto JsonFieldMinDistance = "minDistance";
93 static constexpr auto JsonFieldSequenceMode = "sequenceMode";
94 static constexpr auto JsonFieldStaggerInterval = "staggerInterval";
95 static constexpr auto JsonFieldPresetName = "presetName";
96
98 QJsonObject toJson() const;
99
102 static Profile fromJson(const QJsonObject& obj, const CurveRegistry& registry);
103
104 bool operator==(const Profile& other) const;
105 bool operator!=(const Profile& other) const
106 {
107 return !(*this == other);
108 }
109};
110
111} // namespace PhosphorAnimation
String-id <-> curve factory registry.
Definition CurveRegistry.h:22
Configuration for a single animation event.
Definition Profile.h:33
SequenceMode effectiveSequenceMode() const
Definition Profile.h:76
std::optional< int > minDistance
Skip threshold in px — animation skipped if distance < this and no size change.
Definition Profile.h:58
std::optional< SequenceMode > sequenceMode
Definition Profile.h:60
Profile & operator=(Profile &&)=default
bool operator!=(const Profile &other) const
Definition Profile.h:105
Profile(const Profile &)=default
static Profile fromJson(const QJsonObject &obj, const CurveRegistry &registry)
Parse from JSON.
int effectiveMinDistance() const
Definition Profile.h:72
bool operator==(const Profile &other) const
std::optional< qreal > duration
Animation length in ms. Spring curves derive their own settle time.
Definition Profile.h:55
Profile withDefaults() const
Copy with every unset field filled from library defaults.
std::shared_ptr< const Curve > curve
nullptr = inherit from parent / library default (outCubic bezier).
Definition Profile.h:52
std::optional< int > staggerInterval
Milliseconds between cascade starts.
Definition Profile.h:63
std::optional< QString > presetName
Optional user-assigned preset name. Purely decorative for UI.
Definition Profile.h:66
Profile & operator=(const Profile &)=default
QJsonObject toJson() const
Serialize to JSON. Only set fields are emitted.
qreal effectiveDuration() const
Definition Profile.h:68
int effectiveStaggerInterval() const
Definition Profile.h:80
Profile(Profile &&)=default
Definition AnimatedValue.h:31
SequenceMode
How a batch of animations starts. Numeric values match the historical wire format.
Definition Profile.h:21