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) 2023 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 :
23 : #include "braillepreferencesmodel.h"
24 :
25 : #include <QVariant>
26 :
27 : #include "translation.h"
28 :
29 : using namespace mu::preferences;
30 : using namespace mu::braille;
31 :
32 0 : BraillePreferencesModel::BraillePreferencesModel(QObject* parent)
33 0 : : QObject(parent), muse::Contextable(muse::iocCtxForQmlObject(this))
34 : {
35 0 : }
36 :
37 0 : void BraillePreferencesModel::load()
38 : {
39 0 : brailleConfiguration()->braillePanelEnabledChanged().onNotify(this, [this]() {
40 0 : emit braillePanelEnabledChanged(braillePanelEnabled());
41 0 : });
42 :
43 0 : brailleConfiguration()->intervalDirectionChanged().onNotify(this, [this]() {
44 0 : emit intervalDirectionChanged(intervalDirection());
45 0 : });
46 :
47 0 : brailleConfiguration()->brailleTableChanged().onNotify(this, [this]() {
48 0 : emit brailleTableChanged(brailleTable());
49 0 : });
50 0 : }
51 :
52 0 : bool BraillePreferencesModel::braillePanelEnabled() const
53 : {
54 0 : return brailleConfiguration()->braillePanelEnabled();
55 : }
56 :
57 0 : QString BraillePreferencesModel::brailleTable() const
58 : {
59 0 : return brailleConfiguration()->brailleTable();
60 : }
61 :
62 0 : int BraillePreferencesModel::intervalDirection() const
63 : {
64 0 : return static_cast<int>(brailleConfiguration()->intervalDirection());
65 : }
66 :
67 0 : QStringList BraillePreferencesModel::brailleTables() const
68 : {
69 0 : return brailleConfiguration()->brailleTableList();
70 : }
71 :
72 0 : QVariantList BraillePreferencesModel::intervalDirections() const
73 : {
74 : return QVariantList {
75 0 : QVariantMap {
76 : //: Braille chord interval direction: automatic (based on clef)
77 0 : { "text", muse::qtrc("preferences", "Auto") },
78 0 : { "value", static_cast<int>(BrailleIntervalDirection::Auto) },
79 0 : },
80 0 : QVariantMap {
81 : //: Braille chord interval direction: up (ascending)
82 0 : { "text", muse::qtrc("preferences", "Up") },
83 0 : { "value", static_cast<int>(BrailleIntervalDirection::Up) },
84 0 : },
85 0 : QVariantMap {
86 : //: Braille chord interval direction: down (descending)
87 0 : { "text", muse::qtrc("preferences", "Down") },
88 0 : { "value", static_cast<int>(BrailleIntervalDirection::Down) },
89 0 : },
90 0 : };
91 0 : }
92 :
93 0 : void BraillePreferencesModel::setBraillePanelEnabled(bool value)
94 : {
95 0 : if (value == braillePanelEnabled()) {
96 0 : return;
97 : }
98 :
99 0 : brailleConfiguration()->setBraillePanelEnabled(value);
100 0 : emit braillePanelEnabledChanged(value);
101 : }
102 :
103 0 : void BraillePreferencesModel::setBrailleTable(QString table)
104 : {
105 0 : if (table == brailleTable()) {
106 0 : return;
107 : }
108 :
109 0 : brailleConfiguration()->setBrailleTable(table);
110 0 : emit brailleTableChanged(table);
111 : }
112 :
113 0 : void BraillePreferencesModel::setIntervalDirection(int direction)
114 : {
115 0 : if (direction == intervalDirection()) {
116 0 : return;
117 : }
118 :
119 0 : brailleConfiguration()->setIntervalDirection(static_cast<BrailleIntervalDirection>(direction));
120 0 : emit intervalDirectionChanged(direction);
121 : }
|