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;
49 static constexpr int MaxMinDistancePx = 100000;
50
51 Profile() = default;
52
53 Profile(const Profile&) = default;
54 Profile& operator=(const Profile&) = default;
55 Profile(Profile&&) = default;
56 Profile& operator=(Profile&&) = default;
57
59 std::shared_ptr<const Curve> curve;
60
62 std::optional<qreal> duration;
63
65 std::optional<int> minDistance;
66
67 std::optional<SequenceMode> sequenceMode;
68
70 std::optional<int> staggerInterval;
71
73 std::optional<QString> presetName;
74
75 qreal effectiveDuration() const
76 {
77 return duration.value_or(DefaultDuration);
78 }
80 {
81 return minDistance.value_or(DefaultMinDistance);
82 }
84 {
85 return sequenceMode.value_or(DefaultSequenceMode);
86 }
88 {
89 return staggerInterval.value_or(DefaultStaggerInterval);
90 }
91
99
100 // JSON field names — shared with consumers that build Profile blobs externally.
101 static constexpr auto JsonFieldCurve = "curve";
102 static constexpr auto JsonFieldDuration = "duration";
103 static constexpr auto JsonFieldMinDistance = "minDistance";
104 static constexpr auto JsonFieldSequenceMode = "sequenceMode";
105 static constexpr auto JsonFieldStaggerInterval = "staggerInterval";
106 static constexpr auto JsonFieldPresetName = "presetName";
107
109 QJsonObject toJson() const;
110
139 static Profile fromJson(const QJsonObject& obj, const CurveRegistry& registry);
140
141 bool operator==(const Profile& other) const;
142 bool operator!=(const Profile& other) const
143 {
144 return !(*this == other);
145 }
146};
147
148} // namespace PhosphorAnimation
String-id <-> curve factory registry.
Definition CurveRegistry.h:26
Configuration for a single animation event.
Definition Profile.h:33
SequenceMode effectiveSequenceMode() const
Definition Profile.h:83
std::optional< int > minDistance
Skip threshold in px — animation skipped if distance < this and no size change.
Definition Profile.h:65
std::optional< SequenceMode > sequenceMode
Definition Profile.h:67
Profile & operator=(Profile &&)=default
bool operator!=(const Profile &other) const
Definition Profile.h:142
Profile(const Profile &)=default
static Profile fromJson(const QJsonObject &obj, const CurveRegistry &registry)
Parse from JSON.
int effectiveMinDistance() const
Definition Profile.h:79
bool operator==(const Profile &other) const
std::optional< qreal > duration
Animation length in ms. Spring curves derive their own settle time.
Definition Profile.h:62
Profile withDefaults() const
Copy with every unset field filled from library defaults — curve is backfilled with a default-constru...
std::shared_ptr< const Curve > curve
nullptr = inherit from parent / library default (outCubic bezier).
Definition Profile.h:59
std::optional< int > staggerInterval
Milliseconds between cascade starts.
Definition Profile.h:70
std::optional< QString > presetName
Optional user-assigned preset name. Purely decorative for UI.
Definition Profile.h:73
Profile & operator=(const Profile &)=default
QJsonObject toJson() const
Serialize to JSON. Only set fields are emitted.
qreal effectiveDuration() const
Definition Profile.h:75
int effectiveStaggerInterval() const
Definition Profile.h:87
Profile(Profile &&)=default
Definition AnimatedValue.h:32
SequenceMode
How a batch of animations starts. Numeric values match the historical wire format.
Definition Profile.h:21