1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
2
3 /*
4 Rosegarden
5 A MIDI and audio sequencer and musical notation editor.
6 Copyright 2000-2012 the Rosegarden development team.
7
8 Other copyrights also apply to some parts of this work. Please
9 see the AUTHORS file and individual file headers for details.
10
11 This program is free software; you can redistribute it and/or
12 modify it under the terms of the GNU General Public License as
13 published by the Free Software Foundation; either version 2 of the
14 License, or (at your option) any later version. See the file
15 COPYING included with this distribution for more information.
16 */
17
18 #include "GeneratedRegionDialog.h"
19 #include "base/Segment.h"
20 #include "base/figuration/SegmentFigData.h"
21 #include "document/Command.h"
22 #include "misc/Strings.h"
23 #include <QDialogButtonBox>
24 #include <QComboBox>
25 #include <QLabel>
26
27 namespace Rosegarden
28 {
29 //
30 GeneratedRegionDialog::
GeneratedRegionDialog(QWidget * parent,NotePixmapFactory *,GeneratedRegion defaultGeneratedRegion,QString commandName)31 GeneratedRegionDialog(QWidget *parent,
32 NotePixmapFactory */*npf*/,
33 GeneratedRegion defaultGeneratedRegion,
34 QString commandName) :
35 QDialog(parent),
36 m_generatedRegion(defaultGeneratedRegion),
37 m_command(new MacroCommand(commandName))
38 {
39 setModal(true);
40 setWindowTitle(tr("Generated region"));
41 resize(328, 247);
42
43 QDialogButtonBox *buttonBox;
44 QLabel *label;
45 QLabel *label_2;
46
47
48 label = new QLabel(this);
49 label->setGeometry(QRect(10, 30, 111, 20));
50 label->setText(tr("Figuration source"));
51 m_figSourcesBox = new QComboBox(this);
52 m_figSourcesBox->setGeometry(QRect(100, 30, 200, 22));
53 label_2 = new QLabel(this);
54 label_2->setGeometry(QRect(10, 110, 81, 16));
55 label_2->setText(tr("Chord source"));
56 m_chordSourcesBox = new QComboBox(this);
57 m_chordSourcesBox->setGeometry(QRect(100, 110, 200, 22));
58
59 buttonBox = new QDialogButtonBox(this);
60 buttonBox->setGeometry(QRect(-80, 190, 341, 32));
61 buttonBox->setOrientation(Qt::Horizontal);
62 buttonBox->setStandardButtons(QDialogButtonBox::Cancel|QDialogButtonBox::Ok);
63
64 initializeCombos();
65
66 connect(buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept);
67 connect(buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
68
69 connect(m_figSourcesBox, SIGNAL(currentIndexChanged(int)),
70 this, SLOT(assignFigurationSource(int)));
71 connect(m_chordSourcesBox, SIGNAL(currentIndexChanged(int)),
72 this, SLOT(assignChordSource(int)));
73 }
74
75 void
76 GeneratedRegionDialog::
initializeCombos()77 initializeCombos()
78 {
79 typedef SegmentFigData::SegmentFigDataMap SegMap;
80 typedef SegMap::iterator iterator;
81
82 SegMap involvedSegments = SegmentFigData::getInvolvedSegments(false, m_command);
83
84 for (iterator i = involvedSegments.begin();
85 i != involvedSegments.end();
86 ++i) {
87 Segment *s = i->first;
88 SegmentFigData &data = i->second;
89 if (data.isa(SegmentFigData::FigurationSource)) {
90 m_figSourcesBox->addItem (strtoqstr(s->getLabel()), data.getID());
91 }
92 if (data.isa(SegmentFigData::ChordSource)) {
93 m_chordSourcesBox->addItem (strtoqstr(s->getLabel()), data.getID());
94 }
95 }
96
97 initComboToID(m_figSourcesBox, m_generatedRegion.getFigurationSourceID());
98 initComboToID(m_chordSourcesBox, m_generatedRegion.getChordSourceID());
99 }
100
101 void
102 GeneratedRegionDialog::
initComboToID(QComboBox * comboBox,int id)103 initComboToID(QComboBox* comboBox, int id)
104 {
105 int index = comboBox->findData(id);
106 comboBox->setCurrentIndex(index);
107 }
108
109 void
110 GeneratedRegionDialog::
assignChordSource(int itemIndex)111 assignChordSource(int itemIndex)
112 {
113 if (itemIndex < 0) { return; }
114 bool ok;
115 int id = m_chordSourcesBox->itemData(itemIndex).toInt(&ok);
116 if (!ok) { return; }
117 m_generatedRegion.setChordSourceID(id);
118 }
119
120 void
121 GeneratedRegionDialog::
assignFigurationSource(int itemIndex)122 assignFigurationSource(int itemIndex)
123 {
124 if (itemIndex < 0) { return; }
125 bool ok;
126 int id = m_figSourcesBox->itemData(itemIndex).toInt(&ok);
127 if (!ok) { return; }
128 m_generatedRegion.setFigurationSourceID(id);
129 }
130
131 }
132
133