Zrythm v2.0.0-DEV
a highly automated and intuitive digital audio workstation
Loading...
Searching...
No Matches
colored_object.h
1// SPDX-FileCopyrightText: © 2024-2026 Alexandros Theodotou <alex@zrythm.org>
2// SPDX-License-Identifier: LicenseRef-ZrythmLicense
3
4#pragma once
5
6#include "utils/color.h"
7#include "utils/icloneable.h"
8
9#include <QtQmlIntegration/qqmlintegration.h>
10
11namespace zrythm::structure::arrangement
12{
13
14class ArrangerObjectColor : public QObject
15{
16 Q_OBJECT
17 Q_PROPERTY (bool useColor READ useColor NOTIFY useColorChanged)
18 Q_PROPERTY (QColor color READ color WRITE setColor NOTIFY colorChanged)
19 QML_ELEMENT
20 QML_UNCREATABLE ("")
21
22public:
23 ArrangerObjectColor (QObject * parent = nullptr) noexcept : QObject (parent)
24 {
25 }
26 ~ArrangerObjectColor () noexcept override = default;
27 Z_DISABLE_COPY_MOVE (ArrangerObjectColor)
28
29 using Color = zrythm::utils::Color;
30
31 // ========================================================================
32 // QML Interface
33 // ========================================================================
34
35 bool useColor () const { return color_.has_value (); }
36
37 QColor color () const
38 {
39 if (useColor ())
40 {
41 return color_->to_qcolor ();
42 }
43 return {};
44 }
45 void setColor (QColor color);
46
47 Q_INVOKABLE void unsetColor ()
48 {
49 color_.reset ();
50 Q_EMIT useColorChanged (false);
51 }
52
53 Q_SIGNAL void colorChanged (QColor color);
54 Q_SIGNAL void useColorChanged (bool use_color);
55
56 // ========================================================================
57
58private:
59 static constexpr std::string_view kColorKey = "color";
60 friend void to_json (nlohmann::json &j, const ArrangerObjectColor &obj);
61 friend void from_json (const nlohmann::json &j, ArrangerObjectColor &obj);
62 friend void init_from (
63 ArrangerObjectColor &obj,
64 const ArrangerObjectColor &other,
65 utils::ObjectCloneType clone_type);
66
67private:
73 std::optional<Color> color_;
74
75 BOOST_DESCRIBE_CLASS (ArrangerObjectColor, (), (), (), (color_))
76};
77
78} // namespace zrythm::structure::arrangement