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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
|
//=============================================================================
// MusE
// Linux Music Editor
// $Id:$
//
// Copyright (C) 2002-2006 by Werner Schweer and others
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License version 2.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
//=============================================================================
#include "configtrack.h"
#include "trelement.h"
#include "arranger.h"
//---------------------------------------------------------
// ConfigTrackList
//---------------------------------------------------------
ConfigTrackList::ConfigTrackList(QWidget* parent)
: QDialog(parent)
{
setupUi(this);
// does not work:
configuredList->setSelectionMode(QAbstractItemView::SingleSelection);
availableList->setSelectionMode(QAbstractItemView::SingleSelection);
up->setEnabled(false);
down->setEnabled(false);
addItem->setEnabled(false);
removeItem->setEnabled(false);
dirty = false;
curType = 0;
init();
connect(trackType, SIGNAL(activated(int)), SLOT(trackTypeChanged(int)));
connect(availableList, SIGNAL(itemSelectionChanged()), SLOT(availableSelected()));
connect(configuredList, SIGNAL(itemSelectionChanged()), SLOT(configuredSelected()));
connect(up, SIGNAL(clicked()), SLOT(upClicked()));
connect(down, SIGNAL(clicked()), SLOT(downClicked()));
connect(addItem, SIGNAL(clicked()), SLOT(addItemClicked()));
connect(removeItem, SIGNAL(clicked()), SLOT(removeItemClicked()));
}
//---------------------------------------------------------
// init
//---------------------------------------------------------
void ConfigTrackList::init()
{
trackType->clear();
for (int tt = 0; tt < Track::TRACK_TYPES; ++tt) {
list[tt] = glist[tt];
trackType->addItem(Track::_clname[tt]);
}
trackTypeChanged(curType);
}
//---------------------------------------------------------
// done
//---------------------------------------------------------
void ConfigTrackList::done(int code)
{
if (code) {
// OK pressed
if (dirty)
saveTrackType();
for (int tt = 0; tt < Track::TRACK_TYPES; ++tt)
glist[tt] = list[tt];
emit trackConfigChanged();
}
else {
dirty = false;
init();
}
QDialog::done(code);
}
//---------------------------------------------------------
// saveTrackType
//---------------------------------------------------------
void ConfigTrackList::saveTrackType()
{
dirty = false;
list[curType].clear();
int gn = 0;
TrElementList group;
int n = configuredList->count();
for (int i = 0; i < n; ++i) {
QString s = configuredList->item(i)->text();
int k;
for (k = 0; k < nTrElements; ++k)
if (trElements[k].name == s)
break;
if (trElements[k].grp != gn) {
list[curType].push_back(group);
group.clear();
gn = trElements[k].grp;
}
group.push_back(&trElements[k]);
}
if (!group.empty())
list[curType].push_back(group);
}
//---------------------------------------------------------
// trackTypeChanged
//---------------------------------------------------------
void ConfigTrackList::trackTypeChanged(int type)
{
curType = type;
if (dirty)
saveTrackType();
configuredList->clear();
TrGroupList& gl = list[type];
for (iTrGroup i = gl.begin(); i != gl.end(); ++i) {
for (iTrElement k = i->begin(); k != i->end(); ++k)
configuredList->addItem((*k)->name);
}
availableList->clear();
for (int i = 0; i < nTrElements; ++i) {
QString name(trElements[i].name);
bool f = false;
// is gui element available for this track type?
for (int i = 0; i < nTrElements; ++i) {
const TrElement& el = trElements[i];
if (el.name == name) {
if (el.trackMask & (1 << type)) {
f = true;
break;
}
}
}
if (!f)
continue;
// is gui element already configured?
for (iTrGroup i = gl.begin(); i != gl.end(); ++i) {
for (iTrElement k = i->begin(); k != i->end(); ++k) {
if (name == (*k)->name) {
f = false;
break;
}
}
if (!f)
break;
}
if (f) {
availableList->addItem(name);
}
}
}
//---------------------------------------------------------
// configuredSelected
//---------------------------------------------------------
void ConfigTrackList::configuredSelected()
{
QListWidgetItem* item = configuredList->selectedItems().at(0);
up->setEnabled(item != 0);
down->setEnabled(item != 0);
removeItem->setEnabled(item != 0);
}
//---------------------------------------------------------
// availableSelected
//---------------------------------------------------------
void ConfigTrackList::availableSelected()
{
QListWidgetItem* item = availableList->selectedItems().at(0);
addItem->setEnabled(item != 0);
}
//---------------------------------------------------------
// upClicked
//---------------------------------------------------------
void ConfigTrackList::upClicked()
{
QListWidgetItem* item = configuredList->selectedItems().at(0);
int n = configuredList->row(item);
if (n <= 0)
return;
QString s = item->text();
delete item;
configuredList->insertItem(n-1, s);
configuredList->setItemSelected(configuredList->item(n-1), true);
dirty = true;
}
//---------------------------------------------------------
// downClicked
//---------------------------------------------------------
void ConfigTrackList::downClicked()
{
QListWidgetItem* item = configuredList->selectedItems().at(0);
int n = configuredList->row(item);
if (n >= int(configuredList->count()-1))
return;
QString s = item->text();
delete item;
configuredList->insertItem(n+1, s);
configuredList->setItemSelected(configuredList->item(n+1), true);
dirty = true;
}
//---------------------------------------------------------
// addItemClicked
//---------------------------------------------------------
void ConfigTrackList::addItemClicked()
{
QListWidgetItem* item = availableList->selectedItems().at(0);
if (item == 0)
return;
QString s = item->text();
delete item;
configuredList->addItem(s);
configuredList->setItemSelected(configuredList->item(configuredList->count()-1), true);
QListWidgetItem* ci = availableList->currentItem();
if (ci)
availableList->setItemSelected(ci, true);
dirty = true;
}
//---------------------------------------------------------
// removeItemClicked
//---------------------------------------------------------
void ConfigTrackList::removeItemClicked()
{
QListWidgetItem* item = configuredList->selectedItems().at(0);
if (item == 0)
return;
QString s = item->text();
delete item;
availableList->addItem(s);
availableList->setItemSelected(availableList->item(availableList->count()-1), true);
QListWidgetItem* ci = configuredList->item(configuredList->currentRow());
if (ci)
configuredList->setItemSelected(ci, true);
dirty = true;
}
|