Line data Source code
1 : /*
2 : * SPDX-License-Identifier: GPL-3.0-only
3 : * MuseScore-Studio-CLA-applies
4 : *
5 : * MuseScore Studio
6 : * Music Composition & Notation
7 : *
8 : * Copyright (C) 2021 MuseScore Limited and others
9 : *
10 : * This program is free software: you can redistribute it and/or modify
11 : * it under the terms of the GNU General Public License version 3 as
12 : * published by the Free Software Foundation.
13 : *
14 : * This program is distributed in the hope that it will be useful,
15 : * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 : * GNU General Public License for more details.
18 : *
19 : * You should have received a copy of the GNU General Public License
20 : * along with this program. If not, see <https://www.gnu.org/licenses/>.
21 : */
22 : #include "canvaspreferencesmodel.h"
23 :
24 : #include "types/translatablestring.h"
25 :
26 : using namespace mu::preferences;
27 : using namespace mu::notation;
28 :
29 0 : CanvasPreferencesModel::CanvasPreferencesModel(QObject* parent)
30 0 : : QObject(parent), muse::Contextable(muse::iocCtxForQmlObject(this))
31 : {
32 0 : }
33 :
34 0 : void CanvasPreferencesModel::load()
35 : {
36 0 : setupConnections();
37 0 : }
38 :
39 0 : void CanvasPreferencesModel::setupConnections()
40 : {
41 0 : notationConfiguration()->defaultZoomChanged().onNotify(this, [this]() {
42 0 : emit defaultZoomChanged();
43 0 : });
44 0 : notationConfiguration()->mouseZoomPrecisionChanged().onNotify(this, [this]() {
45 0 : emit mouseZoomPrecisionChanged();
46 0 : });
47 0 : notationConfiguration()->canvasOrientation().ch.onReceive(this, [this](muse::Orientation) {
48 0 : emit scrollPagesOrientationChanged();
49 0 : });
50 0 : notationSceneConfiguration()->isLimitCanvasScrollAreaChanged().onNotify(this, [this]() {
51 0 : emit limitScrollAreaChanged();
52 0 : });
53 0 : notationConfiguration()->selectionProximityChanged().onReceive(this, [this](int selectionProximity) {
54 0 : emit selectionProximityChanged(selectionProximity);
55 0 : });
56 0 : }
57 :
58 0 : QVariantList CanvasPreferencesModel::zoomTypes() const
59 : {
60 : QVariantList types = {
61 0 : QVariantMap { { "title", zoomTypeTitle(ZoomType::Percentage).qTranslated() }, { "value", static_cast<int>(ZoomType::Percentage) } },
62 0 : QVariantMap { { "title", zoomTypeTitle(ZoomType::PageWidth).qTranslated() }, { "value", static_cast<int>(ZoomType::PageWidth) } },
63 0 : QVariantMap { { "title", zoomTypeTitle(ZoomType::WholePage).qTranslated() }, { "value", static_cast<int>(ZoomType::WholePage) } },
64 0 : QVariantMap { { "title", zoomTypeTitle(ZoomType::TwoPages).qTranslated() }, { "value", static_cast<int>(ZoomType::TwoPages) } }
65 0 : };
66 :
67 0 : return types;
68 0 : }
69 :
70 0 : QVariantMap CanvasPreferencesModel::defaultZoom() const
71 : {
72 0 : QVariantMap zoom;
73 0 : ZoomType zoomType = defaultZoomType();
74 0 : zoom["type"] = static_cast<int>(zoomType);
75 0 : zoom["isPercentage"] = zoomType == ZoomType::Percentage;
76 0 : zoom["level"] = notationConfiguration()->defaultZoom();
77 :
78 0 : return zoom;
79 0 : }
80 :
81 0 : int CanvasPreferencesModel::mouseZoomPrecision() const
82 : {
83 0 : return notationConfiguration()->mouseZoomPrecision();
84 : }
85 :
86 0 : int CanvasPreferencesModel::scrollPagesOrientation() const
87 : {
88 0 : return static_cast<int>(notationConfiguration()->canvasOrientation().val);
89 : }
90 :
91 0 : bool CanvasPreferencesModel::limitScrollArea() const
92 : {
93 0 : return notationSceneConfiguration()->isLimitCanvasScrollArea();
94 : }
95 :
96 0 : int CanvasPreferencesModel::selectionProximity() const
97 : {
98 0 : return notationConfiguration()->selectionProximity();
99 : }
100 :
101 0 : void CanvasPreferencesModel::setDefaultZoomType(int zoomType)
102 : {
103 0 : ZoomType type = static_cast<ZoomType>(zoomType);
104 0 : if (defaultZoomType() == type) {
105 0 : return;
106 : }
107 :
108 0 : notationConfiguration()->setDefaultZoomType(type);
109 0 : emit defaultZoomChanged();
110 : }
111 :
112 0 : void CanvasPreferencesModel::setDefaultZoomLevel(int zoom)
113 : {
114 0 : if (defaultZoomLevel() == zoom) {
115 0 : return;
116 : }
117 :
118 0 : notationConfiguration()->setDefaultZoom(zoom);
119 0 : emit defaultZoomChanged();
120 : }
121 :
122 0 : void CanvasPreferencesModel::setMouseZoomPrecision(int precision)
123 : {
124 0 : if (mouseZoomPrecision() == precision) {
125 0 : return;
126 : }
127 :
128 0 : notationConfiguration()->setMouseZoomPrecision(precision);
129 0 : emit mouseZoomPrecisionChanged();
130 : }
131 :
132 0 : void CanvasPreferencesModel::setScrollPagesOrientation(int orientation)
133 : {
134 0 : if (orientation == scrollPagesOrientation()) {
135 0 : return;
136 : }
137 :
138 0 : notationConfiguration()->setCanvasOrientation(static_cast<muse::Orientation>(orientation));
139 : }
140 :
141 0 : void CanvasPreferencesModel::setLimitScrollArea(bool limit)
142 : {
143 0 : if (limitScrollArea() == limit) {
144 0 : return;
145 : }
146 :
147 0 : notationSceneConfiguration()->setIsLimitCanvasScrollArea(limit);
148 0 : emit limitScrollAreaChanged();
149 : }
150 :
151 0 : void CanvasPreferencesModel::setSelectionProximity(int proximity)
152 : {
153 0 : if (selectionProximity() == proximity) {
154 0 : return;
155 : }
156 :
157 0 : notationConfiguration()->setSelectionProximity(proximity);
158 0 : emit selectionProximityChanged(proximity);
159 : }
160 :
161 0 : ZoomType CanvasPreferencesModel::defaultZoomType() const
162 : {
163 0 : return notationConfiguration()->defaultZoomType();
164 : }
165 :
166 0 : int CanvasPreferencesModel::defaultZoomLevel() const
167 : {
168 0 : return notationConfiguration()->defaultZoom();
169 : }
|