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
11namespace zrythm::structure::arrangement
12{
13
17class EditorSettings : public QObject
18{
19 Q_OBJECT
20 QML_ELEMENT
21 Q_PROPERTY (double x READ getX WRITE setX NOTIFY xChanged)
22 Q_PROPERTY (double y READ getY WRITE setY NOTIFY yChanged)
23 Q_PROPERTY (
24 double horizontalZoomLevel READ getHorizontalZoomLevel WRITE
25 setHorizontalZoomLevel NOTIFY horizontalZoomLevelChanged)
26
27public:
28 EditorSettings (QObject * parent = nullptr) : QObject (parent) { }
29
30 // =========================================================
31 // QML interface
32 // =========================================================
33
34 double getX () const { return scroll_start_x_; }
35 void setX (double x)
36 {
37 auto clamped_x = clamp_scroll_start_x (x);
38 if (utils::math::floats_equal (scroll_start_x_, clamped_x))
39 return;
40
41 scroll_start_x_ = clamped_x;
42 Q_EMIT xChanged (scroll_start_x_);
43 }
44 Q_SIGNAL void xChanged (double x);
45
46 double getY () const { return scroll_start_y_; }
47 void setY (double y)
48 {
49 auto clamped_y = clamp_scroll_start_y (y);
50 if (utils::math::floats_equal (scroll_start_y_, clamped_y))
51 return;
52 scroll_start_y_ = clamped_y;
53 Q_EMIT yChanged (scroll_start_y_);
54 }
55 Q_SIGNAL void yChanged (double y);
56
57 double getHorizontalZoomLevel () const { return hzoom_level_; }
58 void setHorizontalZoomLevel (double hzoom_level)
59 {
60 if (utils::math::floats_equal (hzoom_level_, hzoom_level))
61 return;
62 hzoom_level_ = hzoom_level;
63 Q_EMIT horizontalZoomLevelChanged (hzoom_level);
64 }
65 Q_SIGNAL void horizontalZoomLevelChanged (double hzoom_level);
66
67 // =========================================================
68
69 double clamp_scroll_start_x (double x);
70
71 double clamp_scroll_start_y (double y);
72
76 void append_scroll (double dx, double dy, bool validate);
77
78protected:
79 friend void init_from (
80 EditorSettings &obj,
81 const EditorSettings &other,
82 utils::ObjectCloneType clone_type)
83 {
84 obj.scroll_start_x_ = other.scroll_start_x_;
85 obj.scroll_start_y_ = other.scroll_start_y_;
86 obj.hzoom_level_ = other.hzoom_level_;
87 }
88
89private:
90 static constexpr auto kScrollStartXKey = "scrollStartX"sv;
91 static constexpr auto kScrollStartYKey = "scrollStartY"sv;
92 static constexpr auto kHZoomLevelKey = "hZoomLevel"sv;
93 friend void to_json (nlohmann::json &j, const EditorSettings &settings);
94 friend void from_json (const nlohmann::json &j, EditorSettings &settings);
95
96private:
98 double scroll_start_x_ = 0;
99
101 double scroll_start_y_ = 0;
102
104 double hzoom_level_ = 1.0;
105};
106
107}
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