1 //=========================================================
2 // MusE
3 // Linux Music Editor
4 // $Id: legato.cpp,v 1.1.1.1 2011/05/05 18:51:04 flo93 Exp $
5 // (C) Copyright 2011 Florian Jung (flo93@sourceforge.net)
6 //
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License
9 // as published by the Free Software Foundation; version 2 of
10 // the License, or (at your option) any later version.
11 //
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
16 //
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 //
21 //=========================================================
22
23 #include <QButtonGroup>
24 #include "legato.h"
25 #include "xml.h"
26
27 namespace MusEGui {
28
29 FunctionReturnDialogFlags_t Legato::_ret_flags = FunctionReturnNoFlags;
30 FunctionDialogElements_t Legato::_elements = FunctionDialogNoElements;
31 int Legato::_range = FunctionSelectedEventsButton;
32 int Legato::_parts = FunctionSelectedPartsButton;
33 int Legato::min_len = 0;
34 bool Legato::allow_shortening = 0;
35
Legato(QWidget * parent)36 Legato::Legato(QWidget* parent)
37 : FunctionDialogBase(parent)
38 {
39 setupUi(this);
40
41 //--------------------------------------------
42 // Set range and parts containers if available.
43 //--------------------------------------------
44
45 _range_container = rangeBox;
46 _parts_container = partsBox;
47
48 //--------------------------------------------
49 // Add element widgets to range and parts groups.
50 //--------------------------------------------
51
52 _range_group->addButton(all_events_button, FunctionAllEventsButton);
53 _range_group->addButton(selected_events_button,FunctionSelectedEventsButton);
54 _range_group->addButton(looped_events_button, FunctionLoopedButton);
55 _range_group->addButton(selected_looped_button, FunctionSelectedLoopedButton);
56
57 _parts_group->addButton(not_all_parts_button, FunctionSelectedPartsButton);
58 _parts_group->addButton(all_parts_button, FunctionAllPartsButton);
59 }
60
pull_values()61 void Legato::pull_values()
62 {
63 //--------------------------------------------
64 // Grab IDs or values from common base object
65 // (range and parts groups etc.)
66 //--------------------------------------------
67
68 FunctionDialogBase::pull_values();
69
70 //--------------------------------------------
71 // Grab this dialog's specific IDs or values.
72 //--------------------------------------------
73
74 min_len = len_spinbox->value();
75 allow_shortening = allow_shorten_checkbox->isChecked();
76 }
77
setupDialog()78 void Legato::setupDialog()
79 {
80 //------------------------------------
81 // Setup common base object items.
82 //------------------------------------
83
84 FunctionDialogBase::setupDialog();
85
86 //------------------------------------
87 // Setup this dialog's specific items.
88 //------------------------------------
89
90 len_spinbox->setValue(min_len);
91 allow_shorten_checkbox->setChecked(allow_shortening);
92 }
93
read_configuration(MusECore::Xml & xml)94 void Legato::read_configuration(MusECore::Xml& xml)
95 {
96 for (;;)
97 {
98 MusECore::Xml::Token token = xml.parse();
99 if (token == MusECore::Xml::Error || token == MusECore::Xml::End)
100 break;
101
102 const QString& tag = xml.s1();
103 switch (token)
104 {
105 case MusECore::Xml::TagStart:
106
107 //-----------------------------------------
108 // Handle any common base settings.
109 //-----------------------------------------
110
111 if(!FunctionDialogBase::read_configuration(tag, xml))
112 {
113 //-----------------------------------------
114 // Handle this dialog's specific settings.
115 //-----------------------------------------
116
117 if (tag == "range")
118 _range = xml.parseInt();
119 else if (tag == "parts")
120 _parts = xml.parseInt();
121 else if (tag == "min_len")
122 min_len=xml.parseInt();
123 else if (tag == "allow_shortening")
124 allow_shortening=xml.parseInt();
125 else
126 xml.unknown("Legato");
127 }
128 break;
129
130 case MusECore::Xml::TagEnd:
131 if (tag == "legato")
132 return;
133
134 default:
135 break;
136 }
137 }
138 }
139
write_configuration(int level,MusECore::Xml & xml)140 void Legato::write_configuration(int level, MusECore::Xml& xml)
141 {
142 xml.tag(level++, "legato");
143
144 //-----------------------------------------
145 // Write any common base settings.
146 //-----------------------------------------
147
148 FunctionDialogBase::write_configuration(level, xml);
149
150 //-----------------------------------------
151 // Write this dialog's specific settings.
152 //-----------------------------------------
153
154 xml.intTag(level, "range", _range);
155 xml.intTag(level, "parts", _parts);
156 xml.intTag(level, "min_len", min_len);
157 xml.intTag(level, "allow_shortening", allow_shortening);
158 xml.tag(level, "/legato");
159 }
160
161 } // namespace MusEGui
162