Phosphor
Qt6 / Wayland library suite for window-management tools
Loading...
Searching...
No Matches
ShaderPreset.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
6#include <PhosphorShaders/phosphorshaders_export.h>
7
8#include <QHash>
9#include <QJsonObject>
10#include <QPair>
11#include <QString>
12#include <QStringView>
13#include <QVariant>
14#include <QVariantMap>
15
16#include <cstddef>
17#include <optional>
18
19namespace PhosphorShaders {
20
34
42constexpr std::size_t ShaderFamilyCount = 4;
43static_assert(static_cast<std::size_t>(ShaderFamily::Overlay) + 1 == ShaderFamilyCount,
44 "ShaderFamilyCount must match the number of ShaderFamily enumerators");
45
47PHOSPHORSHADERS_EXPORT QLatin1StringView shaderFamilyToken(ShaderFamily family);
48
51using PresetValueRange = QPair<QVariant, QVariant>;
52
61using PresetValueBounds = QHash<QString, PresetValueRange>;
62
69template<typename ParameterList>
70PresetValueBounds presetBoundsFrom(const ParameterList& parameters)
71{
72 PresetValueBounds bounds;
73 for (const auto& parameter : parameters) {
74 if (parameter.minValue.isValid() || parameter.maxValue.isValid()) {
75 bounds.insert(parameter.id, PresetValueRange(parameter.minValue, parameter.maxValue));
76 }
77 }
78 return bounds;
79}
80
97struct PHOSPHORSHADERS_EXPORT ShaderPreset
98{
107 QString id;
108
111 QString name;
112
115 QString packId;
116
120 QVariantMap params;
121
125 bool readOnly = false;
126
129 QString sourcePath;
130
134 static constexpr qsizetype MaxNameChars = 128;
135
138 static constexpr qsizetype MaxIdChars = 256;
139
148 static constexpr qsizetype MaxParams = 64;
149
153 static constexpr qsizetype MaxValueChars = 1024;
154
161 static bool isUsableId(const QString& id);
162
163 bool isValid() const
164 {
165 return !id.isEmpty() && !packId.isEmpty();
166 }
167
170 QJsonObject toJson() const;
171
178 static ShaderPreset fromJson(const QJsonObject& obj, const QString& fallbackId = QString());
179
180 bool operator==(const ShaderPreset& other) const;
181 bool operator!=(const ShaderPreset& other) const
182 {
183 return !(*this == other);
184 }
185};
186
196PHOSPHORSHADERS_EXPORT QVariantMap overlayPresetDeltas(const QVariantMap& base, const QVariantMap& deltas);
197
198} // namespace PhosphorShaders
Definition ShaderProfile.h:21
PresetValueBounds presetBoundsFrom(const ParameterList &parameters)
Collect PresetValueBounds from any family's declared parameter list.
Definition ShaderPreset.h:70
ShaderFamily
Which shader family a preset belongs to.
Definition ShaderPreset.h:28
@ Pointer
Definition ShaderPreset.h:31
@ Overlay
Definition ShaderPreset.h:32
@ Surface
Definition ShaderPreset.h:30
@ Animation
Definition ShaderPreset.h:29
QPair< QVariant, QVariant > PresetValueRange
A pack's declared numeric range for one parameter: { min, max }, either of which may be an invalid QV...
Definition ShaderPreset.h:51
PHOSPHORSHADERS_EXPORT QVariantMap overlayPresetDeltas(const QVariantMap &base, const QVariantMap &deltas)
Overlay deltas onto base and return the result — the one definition of how a preset and an assignment...
constexpr std::size_t ShaderFamilyCount
How many families there are, for the one-slot-per-family arrays that index by static_cast<std::size_t...
Definition ShaderPreset.h:42
PHOSPHORSHADERS_EXPORT QLatin1StringView shaderFamilyToken(ShaderFamily family)
Wire token for family: "animation" / "surface" / "pointer" / "overlay".
QHash< QString, PresetValueRange > PresetValueBounds
The declared ranges for a pack's parameters, by parameter id.
Definition ShaderPreset.h:61
One named parameter tuning for one shader pack.
Definition ShaderPreset.h:98
QString name
Display name.
Definition ShaderPreset.h:111
QString packId
The pack this preset tunes.
Definition ShaderPreset.h:115
bool operator!=(const ShaderPreset &other) const
Definition ShaderPreset.h:181
QJsonObject toJson() const
Serialise a USER preset.
QVariantMap params
The tuning itself: { paramId -> value }.
Definition ShaderPreset.h:120
static bool isUsableId(const QString &id)
Whether id is safe to use as both an identity and a path component.
static constexpr qsizetype MaxIdChars
Longest id isUsableId accepts.
Definition ShaderPreset.h:138
static ShaderPreset fromJson(const QJsonObject &obj, const QString &fallbackId=QString())
Parse a user preset file body.
static constexpr qsizetype MaxValueChars
Longest string VALUE kept in a preset's parameter map (an image path or a colour literal).
Definition ShaderPreset.h:153
static constexpr qsizetype MaxNameChars
Longest display name fromJson keeps, matching the cap the settings app's rename dialog applies to a t...
Definition ShaderPreset.h:134
bool isValid() const
Definition ShaderPreset.h:163
bool readOnly
True for a pack-declared preset.
Definition ShaderPreset.h:125
QString sourcePath
Absolute path of the file backing a user preset.
Definition ShaderPreset.h:129
QString id
Stable id, MEANT to be unique within (family, packId) — the settings app mints a UUID for each user p...
Definition ShaderPreset.h:107
bool operator==(const ShaderPreset &other) const
static constexpr qsizetype MaxParams
Most parameter entries fromJson keeps, and the cap the settings bridge applies when it WRITES a prese...
Definition ShaderPreset.h:148