Loading...
Searching...
No Matches
ColorReference.hpp
1#pragma once
2#include <score/model/Skin.hpp>
3#include <score/serialization/DataStreamFwd.hpp>
4#include <score/tools/Debug.hpp>
5#include <score/tools/std/Optional.hpp>
6
7#include <QColor>
8
9#include <utility>
10
11namespace score
12{
20struct SCORE_LIB_BASE_EXPORT ColorRef
21{
22 friend bool operator==(ColorRef lhs, ColorRef rhs) { return lhs.ref == rhs.ref; }
23
24 friend bool operator!=(ColorRef lhs, ColorRef rhs) { return lhs.ref != rhs.ref; }
25
26public:
27 constexpr ColorRef() noexcept = default;
28 constexpr ColorRef(const ColorRef& other) noexcept = default;
29 constexpr ColorRef(ColorRef&& other) noexcept = default;
30 constexpr ColorRef& operator=(const ColorRef& other) noexcept = default;
31 constexpr ColorRef& operator=(ColorRef&& other) noexcept = default;
32
34 : ref{&(score::Skin::instance().*s)}
35 {
36 }
37
38 constexpr ColorRef(const Brush* col) noexcept
39 : ref{col}
40 {
41 }
42
43 void setColor(Brush Skin::*s) noexcept
44 {
45 // Set color by reference
46 ref = &(score::Skin::instance().*s);
47 }
48
49 const Brush& getBrush() const
50 {
51 SCORE_ASSERT(ref);
52 return *ref;
53 }
54
55 QString name() const noexcept { return score::Skin::instance().toString(ref); }
56
57 static std::optional<ColorRef> ColorFromString(const QString&) noexcept;
58 static std::optional<ColorRef> SimilarColor(QColor other) noexcept;
59
60private:
61 const Brush* ref{};
62};
63}
64
65SCORE_SERIALIZE_DATASTREAM_DECLARE(SCORE_LIB_BASE_EXPORT, score::ColorRef);
66Q_DECLARE_METATYPE(score::ColorRef)
67W_REGISTER_ARGTYPE(score::ColorRef)
Definition Skin.hpp:93
Base toolkit upon which the software is built.
Definition Application.cpp:90
Definition Skin.hpp:55
A reference to a color. Used for skinning.
Definition ColorReference.hpp:21