-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPreferencesMenu.cpp
More file actions
187 lines (139 loc) · 5.12 KB
/
PreferencesMenu.cpp
File metadata and controls
187 lines (139 loc) · 5.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
// This source code is part of QAbc, a minimal ABC music notation editor.
// QAbc is Copyright © 2021 Benoît Rouits <brouits@free.fr>.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// SPDX-License-Identifier: GPL-3.0-or-later
#include "PreferencesMenu.h"
#include "AbcApplication.h"
#include "editorprefdialog.h"
#include "settings.h"
#include <QDebug>
#include <QInputDialog>
PreferencesMenu::PreferencesMenu(QWidget* parent)
: QMenu(parent)
{
setTitle(tr("Preferences"));
addAction(tr("MIDI Generator"), this, &PreferencesMenu::onPlayerActionTriggered);
addAction(tr("MIDI Synthesizer"), this, &PreferencesMenu::onSynthActionTriggered);
addAction(tr("Score generator"), this, &PreferencesMenu::onCompilerActionTriggered);
addAction(tr("Score viewer"), this, &PreferencesMenu::onViewerActionTriggered);
addAction(tr("Editor settings"), this, &PreferencesMenu::onEditorActionTriggered);
addAction(tr("Reset to defaults"), this, &PreferencesMenu::onResetActionTriggered);
}
PreferencesMenu::~PreferencesMenu()
{
}
void PreferencesMenu::onCompilerActionTriggered()
{
Settings settings;
QVariant compiler = settings.value(COMPILER_KEY);
QInputDialog dlg(this);
dlg.setWindowTitle(tr("Compiler preference"));
dlg.setLabelText(tr("Compiler:"));
dlg.setInputMode(QInputDialog::TextInput);
QLineEdit *edit = dlg.findChild<QLineEdit *>();
if (edit) edit->setMinimumWidth(400);
QString command;
if (!compiler.isNull())
dlg.setTextValue(compiler.toString());
else
dlg.setTextValue(ABCM2PS);
if (dlg.exec() == QDialog::Accepted) {
command = dlg.textValue();
settings.setValue(COMPILER_KEY, command);
settings.sync();
}
}
void PreferencesMenu::onPlayerActionTriggered()
{
Settings settings;
QVariant player = settings.value(PLAYER_KEY);
QInputDialog dlg(this);
dlg.setWindowTitle(tr("Player preference"));
dlg.setLabelText(tr("Player:"));
dlg.setInputMode(QInputDialog::TextInput);
QLineEdit *edit = dlg.findChild<QLineEdit *>();
if (edit) edit->setMinimumWidth(400);
QString command;
if (!player.isNull())
dlg.setTextValue(player.toString());
else
dlg.setTextValue(ABC2MIDI);
if (dlg.exec() == QDialog::Accepted) {
command = dlg.textValue();
settings.setValue(PLAYER_KEY, command);
settings.sync();
}
}
void PreferencesMenu::onSynthActionTriggered()
{
Settings settings;
QVariant synth = settings.value(SYNTH_KEY);
QInputDialog dlg(this);
dlg.setWindowTitle(tr("Synth preference"));
dlg.setLabelText(tr("Synth:"));
dlg.setInputMode(QInputDialog::TextInput);
QLineEdit *edit = dlg.findChild<QLineEdit *>();
if (edit) edit->setMinimumWidth(400);
QString command;
if (!synth.isNull())
dlg.setTextValue(synth.toString());
else
dlg.setTextValue(FLUIDSYNTH);
if (dlg.exec() == QDialog::Accepted) {
command = dlg.textValue();
settings.setValue(SYNTH_KEY, command);
settings.sync();
}
}
void PreferencesMenu::onViewerActionTriggered()
{
Settings settings;
QVariant viewer = settings.value(VIEWER_KEY);
QInputDialog dlg(this);
dlg.setWindowTitle(tr("PS viewer preference"));
dlg.setLabelText(tr("PS viewer:"));
dlg.setInputMode(QInputDialog::TextInput);
QLineEdit *edit = dlg.findChild<QLineEdit *>();
if (edit) edit->setMinimumWidth(400);
QString command;
if (!viewer.isNull())
dlg.setTextValue(viewer.toString());
else
dlg.setTextValue(PSVIEWER);
if (dlg.exec() == QDialog::Accepted) {
command = dlg.textValue();
settings.setValue(VIEWER_KEY, command);
settings.sync();
}
}
void PreferencesMenu::onEditorActionTriggered()
{
AbcApplication* a = static_cast<AbcApplication*>(qApp);
EditorPrefDialog* dialog = new EditorPrefDialog(a->mainWindow());
if (QDialog::Accepted == dialog->exec()) {
Settings settings;
settings.setValue(EDITOR_FONT_BASE, dialog->getBaseFont().family());
settings.setValue(EDITOR_FONT_RANGE, dialog->getFontRange());
settings.setValue(EDITOR_HIGHLIGHT, dialog->getHighlight());
settings.setValue(EDITOR_BAR_COLOR, dialog->getColor(EDITOR_BAR_COLOR));
settings.setValue(EDITOR_COMMENT_COLOR, dialog->getColor(EDITOR_COMMENT_COLOR));
settings.setValue(EDITOR_DECORATION_COLOR, dialog->getColor(EDITOR_DECORATION_COLOR));
settings.setValue(EDITOR_EXTRAINSTR_COLOR, dialog->getColor(EDITOR_EXTRAINSTR_COLOR));
settings.setValue(EDITOR_GCHORD_COLOR, dialog->getColor(EDITOR_GCHORD_COLOR));
settings.setValue(EDITOR_HEADER_COLOR, dialog->getColor(EDITOR_HEADER_COLOR));
settings.setValue(EDITOR_LYRIC_COLOR, dialog->getColor(EDITOR_LYRIC_COLOR));
settings.sync();
}
delete dialog;
}
void PreferencesMenu::onResetActionTriggered()
{
Settings settings;
settings.reset();
settings.sync();
}