comparison widgets/ItemEditDialog.cpp @ 70:bf306158803d

* Add stub for item-edit dialog (for editing properties of an item on double- click) -- doesn't actually do anything yet * Add code to invoke said non-working item-edit dialog on double-click in time-value, time-instants and note layers * Add overlay mode (no text, basic text, all text)
author Chris Cannam
date Thu, 30 Mar 2006 15:00:22 +0000
parents
children ad1fe715b480
comparison
equal deleted inserted replaced
69:6dad2724f3aa 70:bf306158803d
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
2
3 /*
4 Sonic Visualiser
5 An audio file viewer and annotation editor.
6 Centre for Digital Music, Queen Mary, University of London.
7 This file copyright 2006 Chris Cannam.
8
9 This program is free software; you can redistribute it and/or
10 modify it under the terms of the GNU General Public License as
11 published by the Free Software Foundation; either version 2 of the
12 License, or (at your option) any later version. See the file
13 COPYING included with this distribution for more information.
14 */
15
16 #include "ItemEditDialog.h"
17
18 #include <QLineEdit>
19 #include <QDoubleSpinBox>
20 #include <QGridLayout>
21 #include <QHBoxLayout>
22 #include <QLabel>
23 #include <QPushButton>
24
25
26 ItemEditDialog::ItemEditDialog(size_t sampleRate, int options, QWidget *parent) :
27 QDialog(parent),
28 m_sampleRate(sampleRate),
29 m_frame(0),
30 m_duration(0),
31 m_value(0.0)
32 {
33 QGridLayout *grid = new QGridLayout;
34 setLayout(grid);
35
36 int row = 0;
37 QLineEdit *line = 0;
38
39 if (options & ShowTime) {
40
41 grid->addWidget(new QLabel(tr("Frame time:")), row, 0);
42
43 line = new QLineEdit;
44 line->setValidator(new QIntValidator(this));
45 grid->addWidget(line, row, 1);
46 connect(line, SIGNAL(textChanged(QString)),
47 this, SLOT(frameTimeChanged(QString)));
48
49 ++row;
50
51 grid->addWidget(new QLabel(tr("Secs:")), row, 0);
52
53 line = new QLineEdit;
54 line->setValidator(new QIntValidator(this));
55 grid->addWidget(line, row, 1);
56 connect(line, SIGNAL(textChanged(QString)),
57 this, SLOT(realTimeSecsChanged(QString)));
58
59 ++row;
60
61 grid->addWidget(new QLabel(tr("Nsecs:")), row, 0);
62
63 line = new QLineEdit;
64 line->setValidator(new QIntValidator(this));
65 grid->addWidget(line, row, 1);
66 connect(line, SIGNAL(textChanged(QString)),
67 this, SLOT(realTimeSecsChanged(QString)));
68
69 ++row;
70 }
71
72 if (options & ShowDuration) {
73
74 grid->addWidget(new QLabel(tr("Frame duration:")), row, 0);
75
76 line = new QLineEdit;
77 line->setValidator(new QIntValidator(this));
78 grid->addWidget(line, row, 1);
79 connect(line, SIGNAL(textChanged(QString)),
80 this, SLOT(frameDurationChanged(QString)));
81
82 ++row;
83
84 grid->addWidget(new QLabel(tr("Secs:")), row, 0);
85
86 line = new QLineEdit;
87 line->setValidator(new QIntValidator(this));
88 grid->addWidget(line, row, 1);
89 connect(line, SIGNAL(textChanged(QString)),
90 this, SLOT(realDurationSecsChanged(QString)));
91
92 ++row;
93
94 grid->addWidget(new QLabel(tr("Nsecs:")), row, 0);
95
96 line = new QLineEdit;
97 line->setValidator(new QIntValidator(this));
98 grid->addWidget(line, row, 1);
99 connect(line, SIGNAL(textChanged(QString)),
100 this, SLOT(realDurationSecsChanged(QString)));
101
102 ++row;
103 }
104
105 if (options & ShowValue) {
106
107 grid->addWidget(new QLabel(tr("Value:")), row, 0);
108
109 QDoubleSpinBox *spinbox = new QDoubleSpinBox;
110 grid->addWidget(spinbox, row, 1);
111 connect(spinbox, SIGNAL(valueChanged(double)),
112 this, SLOT(valueChanged(double)));
113
114 ++row;
115 }
116
117 if (options & ShowText) {
118
119 grid->addWidget(new QLabel(tr("Text:")), row, 0);
120
121 line = new QLineEdit;
122 grid->addWidget(line, row, 1);
123 connect(line, SIGNAL(textChanged(QString)),
124 this, SLOT(textChanged(QString)));
125
126 ++row;
127 }
128
129 QHBoxLayout *hbox = new QHBoxLayout;
130 grid->addLayout(hbox, row, 0, 1, 2);
131
132 QPushButton *ok = new QPushButton(tr("OK"));
133 QPushButton *cancel = new QPushButton(tr("Cancel"));
134 hbox->addStretch(10);
135 hbox->addWidget(ok);
136 hbox->addWidget(cancel);
137 connect(ok, SIGNAL(clicked()), this, SLOT(accept()));
138 connect(cancel, SIGNAL(clicked()), this, SLOT(reject()));
139 }
140
141 void
142 ItemEditDialog::setFrameTime(long frame)
143 {
144 m_frame = frame;
145 //!!!
146 }
147
148 long
149 ItemEditDialog::getFrameTime() const
150 {
151 return m_frame;
152 }
153
154 void
155 ItemEditDialog::setRealTime(RealTime rt)
156 {
157 m_frame = RealTime::realTime2Frame(rt, m_sampleRate);
158 //!!!
159 }
160
161 RealTime
162 ItemEditDialog::getRealTime() const
163 {
164 return RealTime::frame2RealTime(m_frame, m_sampleRate);
165 }
166
167 void
168 ItemEditDialog::setFrameDuration(long duration)
169 {
170 m_duration = duration;
171 //!!!
172 }
173
174 long
175 ItemEditDialog::getFrameDuration() const
176 {
177 return m_duration;
178 }
179
180 void
181 ItemEditDialog::setRealDuration(RealTime rt)
182 {
183 m_duration = RealTime::realTime2Frame(rt, m_sampleRate);
184 }
185
186 RealTime
187 ItemEditDialog::getRealDuration() const
188 {
189 return RealTime::frame2RealTime(m_duration, m_sampleRate);
190 }
191
192 void
193 ItemEditDialog::setValue(float v)
194 {
195 m_value = v;
196 //!!!
197 }
198
199 float
200 ItemEditDialog::getValue() const
201 {
202 return m_value;
203 }
204
205 void
206 ItemEditDialog::setText(QString text)
207 {
208 m_text = text;
209 //!!!
210 }
211
212 QString
213 ItemEditDialog::getText() const
214 {
215 return m_text;
216 }
217
218 void
219 ItemEditDialog::frameTimeChanged(QString s)
220 {
221 setFrameTime(s.toInt());
222 }
223
224 void
225 ItemEditDialog::realTimeSecsChanged(QString s)
226 {
227 RealTime rt = getRealTime();
228 rt.sec = s.toInt();
229 setRealTime(rt);
230 }
231
232 void
233 ItemEditDialog::realTimeNSecsChanged(QString s)
234 {
235 RealTime rt = getRealTime();
236 rt.nsec = s.toInt();
237 setRealTime(rt);
238 }
239
240 void
241 ItemEditDialog::frameDurationChanged(QString s)
242 {
243 setFrameDuration(s.toInt());
244 }
245
246 void
247 ItemEditDialog::realDurationSecsChanged(QString s)
248 {
249 RealTime rt = getRealDuration();
250 rt.sec = s.toInt();
251 setRealDuration(rt);
252 }
253
254 void
255 ItemEditDialog::realDurationNSecsChanged(QString s)
256 {
257 RealTime rt = getRealDuration();
258 rt.nsec = s.toInt();
259 setRealDuration(rt);
260 }
261
262 void
263 ItemEditDialog::valueChanged(double v)
264 {
265 setValue((float)v);
266 }
267
268 void
269 ItemEditDialog::textChanged(QString text)
270 {
271 setText(text);
272 }
273