Zrythm v2.0.0-DEV
a highly automated and intuitive digital audio workstation
Loading...
Searching...
No Matches
editor_settings.h
1// SPDX-FileCopyrightText: © 2020-2022, 2024-2025 Alexandros Theodotou <alex@zrythm.org>
2// SPDX-License-Identifier: LicenseRef-ZrythmLicense
3
4#pragma once
5
6#include "utils/icloneable.h"
7#include "utils/math_utils.h"
8
9#include <QtQmlIntegration/qqmlintegration.h>
10
11#include <nlohmann/json_fwd.hpp>
12
13namespace zrythm::structure::arrangement
14{
15
19class EditorSettings : public QObject
20{
21 Q_OBJECT
22 QML_ELEMENT
23 Q_PROPERTY (double x READ getX WRITE setX NOTIFY xChanged)
24 Q_PROPERTY (double y READ getY WRITE setY NOTIFY yChanged)
25 Q_PROPERTY (
26 double horizontalZoomLevel READ getHorizontalZoomLevel WRITE
27 setHorizontalZoomLevel NOTIFY horizontalZoomLevelChanged)
28
29public:
30 EditorSettings (QObject * parent = nullptr) : QObject (parent) { }
31
32 // =========================================================
33 // QML interface
34 // =========================================================
35
36 double getX () const { return scroll_start_x_; }
37 void setX (double x)
38 {
39 auto clamped_x = clamp_scroll_start_x (x);
40 if (utils::math::floats_equal (scroll_start_x_, clamped_x))
41 return;
42
43 scroll_start_x_ = clamped_x;
44 Q_EMIT xChanged (scroll_start_x_);
45 }
46 Q_SIGNAL void xChanged (double x);
47
48 double getY () const { return scroll_start_y_; }
49 void setY (double y)
50 {
51 auto clamped_y = clamp_scroll_start_y (y);
52 if (utils::math::floats_equal (scroll_start_y_, clamped_y))
53 return;
54 scroll_start_y_ = clamped_y;
55 Q_EMIT yChanged (scroll_start_y_);
56 }
57 Q_SIGNAL void yChanged (double y);
58
59 double getHorizontalZoomLevel () const { return hzoom_level_; }
60 void setHorizontalZoomLevel (double hzoom_level)
61 {
62 if (utils::math::floats_equal (hzoom_level_, hzoom_level))
63 return;
64 hzoom_level_ = hzoom_level;
65 Q_EMIT horizontalZoomLevelChanged (hzoom_level);
66 }
67 Q_SIGNAL void horizontalZoomLevelChanged (double hzoom_level);
68
69 // =========================================================
70
71 double clamp_scroll_start_x (double x);
72
73 double clamp_scroll_start_y (double y);
74
78 void append_scroll (double dx, double dy, bool validate);
79
80protected:
81 friend void init_from (
82 EditorSettings &obj,
83 const EditorSettings &other,
84 utils::ObjectCloneType clone_type)
85 {
86 obj.scroll_start_x_ = other.scroll_start_x_;
87 obj.scroll_start_y_ = other.scroll_start_y_;
88 obj.hzoom_level_ = other.hzoom_level_;
89 }
90
91private:
92 static constexpr auto kScrollStartXKey = "scrollStartX"sv;
93 static constexpr auto kScrollStartYKey = "scrollStartY"sv;
94 static constexpr auto kHZoomLevelKey = "hZoomLevel"sv;
95 friend void to_json (nlohmann::json &j, const EditorSettings &settings);
96 friend void from_json (const nlohmann::json &j, EditorSettings &settings);
97
98private:
100 double scroll_start_x_ = 0;
101
103 double scroll_start_y_ = 0;
104
106 double hzoom_level_ = 1.0;
107};
108
109}
void append_scroll(double dx, double dy, bool validate)
Appends the given deltas to the scroll x/y values.
constexpr bool floats_equal(T a, T b)
Checks if 2 floating point numbers are equal.
Definition math_utils.h:75