Mercurial > hg > svgui
comparison widgets/ItemEditDialog.cpp @ 1515:0fa49a6ce64f time-frequency-boxes
Item-editing updates needed for time-frequency box layer
author | Chris Cannam |
---|---|
date | Fri, 20 Sep 2019 14:19:17 +0100 |
parents | c8a6fd3f9dff |
children | c5d2de8f7647 |
comparison
equal
deleted
inserted
replaced
1514:e453053a44dc | 1515:0fa49a6ce64f |
---|---|
26 #include <QDialogButtonBox> | 26 #include <QDialogButtonBox> |
27 | 27 |
28 #include <float.h> // for FLT_MIN/MAX | 28 #include <float.h> // for FLT_MIN/MAX |
29 | 29 |
30 | 30 |
31 ItemEditDialog::LabelOptions::LabelOptions() : | |
32 valueLabel(tr("Value")), | |
33 levelLabel(tr("Level")) | |
34 { | |
35 } | |
36 | |
31 ItemEditDialog::ItemEditDialog(sv_samplerate_t sampleRate, int options, | 37 ItemEditDialog::ItemEditDialog(sv_samplerate_t sampleRate, int options, |
32 QString valueUnits, QWidget *parent) : | 38 QString scaleUnits, QWidget *parent) : |
39 ItemEditDialog(sampleRate, options, | |
40 [] (QString units) { | |
41 ItemEditDialog::LabelOptions options; | |
42 options.valueUnits = units; | |
43 return options; | |
44 }(scaleUnits), | |
45 parent) {}; | |
46 | |
47 ItemEditDialog::ItemEditDialog(sv_samplerate_t sampleRate, int options, | |
48 LabelOptions labelOptions, QWidget *parent) : | |
33 QDialog(parent), | 49 QDialog(parent), |
34 m_sampleRate(sampleRate), | 50 m_sampleRate(sampleRate), |
35 m_defaultFrame(0), | 51 m_defaultFrame(0), |
36 m_defaultDuration(0), | 52 m_defaultDuration(0), |
37 m_defaultValue(0), | 53 m_defaultValue(0), |
54 m_defaultLevel(0), | |
38 m_frameTimeSpinBox(nullptr), | 55 m_frameTimeSpinBox(nullptr), |
39 m_realTimeSecsSpinBox(nullptr), | 56 m_realTimeSecsSpinBox(nullptr), |
40 m_realTimeUSecsSpinBox(nullptr), | 57 m_realTimeUSecsSpinBox(nullptr), |
41 m_frameDurationSpinBox(nullptr), | 58 m_frameDurationSpinBox(nullptr), |
42 m_realDurationSecsSpinBox(nullptr), | 59 m_realDurationSecsSpinBox(nullptr), |
43 m_realDurationUSecsSpinBox(nullptr), | 60 m_realDurationUSecsSpinBox(nullptr), |
44 m_valueSpinBox(nullptr), | 61 m_valueSpinBox(nullptr), |
62 m_levelSpinBox(nullptr), | |
45 m_textField(nullptr) | 63 m_textField(nullptr) |
46 { | 64 { |
47 QGridLayout *grid = new QGridLayout; | 65 QGridLayout *grid = new QGridLayout; |
48 setLayout(grid); | 66 setLayout(grid); |
49 | 67 |
127 this, SLOT(realDurationUSecsChanged(int))); | 145 this, SLOT(realDurationUSecsChanged(int))); |
128 | 146 |
129 ++subrow; | 147 ++subrow; |
130 } | 148 } |
131 | 149 |
132 if ((options & ShowValue) || (options & ShowText)) { | 150 if ((options & ShowValue) || |
151 (options & ShowLevel) || | |
152 (options & ShowText)) { | |
133 | 153 |
134 valueBox = new QGroupBox; | 154 valueBox = new QGroupBox; |
135 valueBox->setTitle(tr("Properties")); | 155 valueBox->setTitle(tr("Properties")); |
136 grid->addWidget(valueBox, row, 0); | 156 grid->addWidget(valueBox, row, 0); |
137 | 157 |
143 | 163 |
144 subrow = 0; | 164 subrow = 0; |
145 | 165 |
146 if (options & ShowValue) { | 166 if (options & ShowValue) { |
147 | 167 |
148 subgrid->addWidget(new QLabel(tr("Value:")), subrow, 0); | 168 subgrid->addWidget(new QLabel(tr("%1:").arg(labelOptions.valueLabel)), |
169 subrow, 0); | |
149 | 170 |
150 m_valueSpinBox = new QDoubleSpinBox; | 171 m_valueSpinBox = new QDoubleSpinBox; |
151 m_valueSpinBox->setSuffix(QString(" %1").arg(valueUnits)); | 172 m_valueSpinBox->setSuffix(QString(" %1").arg(labelOptions.valueUnits)); |
152 m_valueSpinBox->setDecimals(10); | 173 m_valueSpinBox->setDecimals(10); |
153 m_valueSpinBox->setMinimum(-1e10); | 174 m_valueSpinBox->setMinimum(-1e10); |
154 m_valueSpinBox->setMaximum(1e10); | 175 m_valueSpinBox->setMaximum(1e10); |
155 connect(m_valueSpinBox, SIGNAL(valueChanged(double)), | 176 connect(m_valueSpinBox, SIGNAL(valueChanged(double)), |
156 this, SLOT(valueChanged(double))); | 177 this, SLOT(valueChanged(double))); |
157 subgrid->addWidget(m_valueSpinBox, subrow, 1); | 178 subgrid->addWidget(m_valueSpinBox, subrow, 1); |
158 | 179 |
159 ++subrow; | 180 ++subrow; |
160 } | 181 } |
161 | 182 |
183 if (options & ShowLevel) { | |
184 | |
185 subgrid->addWidget(new QLabel(tr("%1:").arg(labelOptions.levelLabel)), | |
186 subrow, 0); | |
187 | |
188 m_levelSpinBox = new QDoubleSpinBox; | |
189 m_levelSpinBox->setSuffix(QString(" %1").arg(labelOptions.levelUnits)); | |
190 m_levelSpinBox->setDecimals(10); | |
191 m_levelSpinBox->setMinimum(-1e10); | |
192 m_levelSpinBox->setMaximum(1e10); | |
193 connect(m_levelSpinBox, SIGNAL(levelChanged(double)), | |
194 this, SLOT(levelChanged(double))); | |
195 subgrid->addWidget(m_levelSpinBox, subrow, 1); | |
196 | |
197 ++subrow; | |
198 } | |
199 | |
162 if (options & ShowText) { | 200 if (options & ShowText) { |
163 | 201 |
164 subgrid->addWidget(new QLabel(tr("Text:")), subrow, 0); | 202 subgrid->addWidget(new QLabel(tr("Text:")), subrow, 0); |
165 | 203 |
166 m_textField = new QLineEdit; | 204 m_textField = new QLineEdit; |
173 | 211 |
174 if (options & ShowText) { | 212 if (options & ShowText) { |
175 m_textField->setFocus(Qt::OtherFocusReason); | 213 m_textField->setFocus(Qt::OtherFocusReason); |
176 } else if (options & ShowValue) { | 214 } else if (options & ShowValue) { |
177 m_valueSpinBox->setFocus(Qt::OtherFocusReason); | 215 m_valueSpinBox->setFocus(Qt::OtherFocusReason); |
216 } else if (options & ShowLevel) { | |
217 m_levelSpinBox->setFocus(Qt::OtherFocusReason); | |
178 } | 218 } |
179 | 219 |
180 QDialogButtonBox *bb = new QDialogButtonBox(Qt::Horizontal); | 220 QDialogButtonBox *bb = new QDialogButtonBox(Qt::Horizontal); |
181 grid->addWidget(bb, row, 0, 1, 2); | 221 grid->addWidget(bb, row, 0, 1, 2); |
182 | 222 |
269 { | 309 { |
270 return float(m_valueSpinBox->value()); | 310 return float(m_valueSpinBox->value()); |
271 } | 311 } |
272 | 312 |
273 void | 313 void |
314 ItemEditDialog::setLevel(float v) | |
315 { | |
316 if (!m_levelSpinBox) return; | |
317 | |
318 m_levelSpinBox->setValue(v); | |
319 m_defaultLevel = v; | |
320 m_resetButton->setEnabled(false); | |
321 } | |
322 | |
323 float | |
324 ItemEditDialog::getLevel() const | |
325 { | |
326 return float(m_levelSpinBox->value()); | |
327 } | |
328 | |
329 void | |
274 ItemEditDialog::setText(QString text) | 330 ItemEditDialog::setText(QString text) |
275 { | 331 { |
276 if (!m_textField) return; | 332 if (!m_textField) return; |
277 | 333 |
278 m_textField->setText(text); | 334 m_textField->setText(text); |
361 { | 417 { |
362 m_resetButton->setEnabled(true); | 418 m_resetButton->setEnabled(true); |
363 } | 419 } |
364 | 420 |
365 void | 421 void |
422 ItemEditDialog::levelChanged(double) | |
423 { | |
424 m_resetButton->setEnabled(true); | |
425 } | |
426 | |
427 void | |
366 ItemEditDialog::textChanged(QString) | 428 ItemEditDialog::textChanged(QString) |
367 { | 429 { |
368 m_resetButton->setEnabled(true); | 430 m_resetButton->setEnabled(true); |
369 } | 431 } |
370 | 432 |
372 ItemEditDialog::reset() | 434 ItemEditDialog::reset() |
373 { | 435 { |
374 setFrameTime(m_defaultFrame); | 436 setFrameTime(m_defaultFrame); |
375 setFrameDuration(m_defaultDuration); | 437 setFrameDuration(m_defaultDuration); |
376 setValue(m_defaultValue); | 438 setValue(m_defaultValue); |
439 setLevel(m_defaultLevel); | |
377 setText(m_defaultText); | 440 setText(m_defaultText); |
378 m_resetButton->setEnabled(false); | 441 m_resetButton->setEnabled(false); |
379 } | 442 } |
380 | 443 |