annotate widgets/ItemEditDialog.cpp @ 1155:d1bab6a99100 project-file-rework

Cut down vastly on the number of config.pri files and places where their contents has to be effectively duplicated without them
author Chris Cannam
date Mon, 24 Oct 2016 17:53:33 +0100
parents 2564d0865feb
children c8a6fd3f9dff
rev   line source
Chris@70 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@70 2
Chris@70 3 /*
Chris@70 4 Sonic Visualiser
Chris@70 5 An audio file viewer and annotation editor.
Chris@70 6 Centre for Digital Music, Queen Mary, University of London.
Chris@70 7 This file copyright 2006 Chris Cannam.
Chris@70 8
Chris@70 9 This program is free software; you can redistribute it and/or
Chris@70 10 modify it under the terms of the GNU General Public License as
Chris@70 11 published by the Free Software Foundation; either version 2 of the
Chris@70 12 License, or (at your option) any later version. See the file
Chris@70 13 COPYING included with this distribution for more information.
Chris@70 14 */
Chris@70 15
Chris@70 16 #include "ItemEditDialog.h"
Chris@70 17
Chris@70 18 #include <QLineEdit>
Chris@70 19 #include <QDoubleSpinBox>
Chris@73 20 #include <QSpinBox>
Chris@70 21 #include <QGridLayout>
Chris@70 22 #include <QHBoxLayout>
Chris@70 23 #include <QLabel>
Chris@70 24 #include <QPushButton>
Chris@73 25 #include <QGroupBox>
Chris@282 26 #include <QDialogButtonBox>
Chris@70 27
Chris@73 28 #include <float.h> // for FLT_MIN/MAX
Chris@70 29
Chris@73 30
Chris@904 31 ItemEditDialog::ItemEditDialog(sv_samplerate_t sampleRate, int options,
Chris@73 32 QString valueUnits, QWidget *parent) :
Chris@70 33 QDialog(parent),
Chris@70 34 m_sampleRate(sampleRate),
Chris@857 35 m_defaultFrame(0),
Chris@857 36 m_defaultDuration(0),
Chris@857 37 m_defaultValue(0),
Chris@73 38 m_frameTimeSpinBox(0),
Chris@73 39 m_realTimeSecsSpinBox(0),
Chris@73 40 m_realTimeUSecsSpinBox(0),
Chris@73 41 m_frameDurationSpinBox(0),
Chris@73 42 m_realDurationSecsSpinBox(0),
Chris@73 43 m_realDurationUSecsSpinBox(0),
Chris@73 44 m_valueSpinBox(0),
Chris@73 45 m_textField(0)
Chris@70 46 {
Chris@70 47 QGridLayout *grid = new QGridLayout;
Chris@70 48 setLayout(grid);
Chris@70 49
Chris@73 50 QGroupBox *timeBox = 0;
Chris@73 51 QGroupBox *valueBox = 0;
Chris@73 52 QGridLayout *subgrid = 0;
Chris@70 53
Chris@73 54 int row = 0, subrow = 0;
Chris@70 55
Chris@807 56 int singleStep = RealTime::frame2RealTime(2, sampleRate).usec() - 1;
Chris@70 57
Chris@73 58 if ((options & ShowTime) || (options & ShowDuration)) {
Chris@70 59
Chris@73 60 timeBox = new QGroupBox;
Chris@73 61 timeBox->setTitle(tr("Timing"));
Chris@73 62 grid->addWidget(timeBox, row, 0);
Chris@70 63
Chris@73 64 subgrid = new QGridLayout;
Chris@73 65 timeBox->setLayout(subgrid);
Chris@70 66
Chris@70 67 ++row;
Chris@70 68 }
Chris@70 69
Chris@73 70 if (options & ShowTime) {
Chris@73 71
Chris@73 72 subgrid->addWidget(new QLabel(tr("Time:")), subrow, 0);
Chris@73 73
Chris@73 74 m_frameTimeSpinBox = new QSpinBox;
Chris@73 75 m_frameTimeSpinBox->setMaximum(INT_MAX);
Chris@73 76 m_frameTimeSpinBox->setSuffix(tr(" frames"));
Chris@73 77 subgrid->addWidget(m_frameTimeSpinBox, subrow, 1, 1, 2);
Chris@73 78 connect(m_frameTimeSpinBox, SIGNAL(valueChanged(int)),
Chris@938 79 this, SLOT(frameTimeChanged(int)));
Chris@73 80
Chris@73 81 ++subrow;
Chris@73 82
Chris@73 83 m_realTimeSecsSpinBox = new QSpinBox;
Chris@73 84 m_realTimeSecsSpinBox->setMaximum(999999);
Chris@73 85 m_realTimeSecsSpinBox->setSuffix(tr(" sec"));
Chris@73 86 subgrid->addWidget(m_realTimeSecsSpinBox, subrow, 1);
Chris@73 87 connect(m_realTimeSecsSpinBox, SIGNAL(valueChanged(int)),
Chris@73 88 this, SLOT(realTimeSecsChanged(int)));
Chris@73 89
Chris@73 90 m_realTimeUSecsSpinBox = new QSpinBox;
Chris@73 91 m_realTimeUSecsSpinBox->setMaximum(999999);
Chris@73 92 m_realTimeUSecsSpinBox->setSuffix(tr(" usec"));
Chris@73 93 m_realTimeUSecsSpinBox->setSingleStep(singleStep);
Chris@73 94 subgrid->addWidget(m_realTimeUSecsSpinBox, subrow, 2);
Chris@73 95 connect(m_realTimeUSecsSpinBox, SIGNAL(valueChanged(int)),
Chris@73 96 this, SLOT(realTimeUSecsChanged(int)));
Chris@73 97
Chris@73 98 ++subrow;
Chris@73 99 }
Chris@73 100
Chris@70 101 if (options & ShowDuration) {
Chris@70 102
Chris@73 103 subgrid->addWidget(new QLabel(tr("Duration:")), subrow, 0);
Chris@70 104
Chris@73 105 m_frameDurationSpinBox = new QSpinBox;
Chris@73 106 m_frameDurationSpinBox->setMaximum(INT_MAX);
Chris@73 107 m_frameDurationSpinBox->setSuffix(tr(" frames"));
Chris@73 108 subgrid->addWidget(m_frameDurationSpinBox, subrow, 1, 1, 2);
Chris@73 109 connect(m_frameDurationSpinBox, SIGNAL(valueChanged(int)),
Chris@938 110 this, SLOT(frameDurationChanged(int)));
Chris@70 111
Chris@73 112 ++subrow;
Chris@70 113
Chris@73 114 m_realDurationSecsSpinBox = new QSpinBox;
Chris@73 115 m_realDurationSecsSpinBox->setMaximum(999999);
Chris@73 116 m_realDurationSecsSpinBox->setSuffix(tr(" sec"));
Chris@73 117 subgrid->addWidget(m_realDurationSecsSpinBox, subrow, 1);
Chris@73 118 connect(m_realDurationSecsSpinBox, SIGNAL(valueChanged(int)),
Chris@73 119 this, SLOT(realDurationSecsChanged(int)));
Chris@70 120
Chris@73 121 m_realDurationUSecsSpinBox = new QSpinBox;
Chris@73 122 m_realDurationUSecsSpinBox->setMaximum(999999);
Chris@73 123 m_realDurationUSecsSpinBox->setSuffix(tr(" usec"));
Chris@73 124 m_realDurationUSecsSpinBox->setSingleStep(singleStep);
Chris@101 125 subgrid->addWidget(m_realDurationUSecsSpinBox, subrow, 2);
Chris@73 126 connect(m_realDurationUSecsSpinBox, SIGNAL(valueChanged(int)),
Chris@73 127 this, SLOT(realDurationUSecsChanged(int)));
Chris@70 128
Chris@73 129 ++subrow;
Chris@73 130 }
Chris@70 131
Chris@73 132 if ((options & ShowValue) || (options & ShowText)) {
Chris@70 133
Chris@73 134 valueBox = new QGroupBox;
Chris@73 135 valueBox->setTitle(tr("Properties"));
Chris@73 136 grid->addWidget(valueBox, row, 0);
Chris@73 137
Chris@73 138 subgrid = new QGridLayout;
Chris@73 139 valueBox->setLayout(subgrid);
Chris@70 140
Chris@70 141 ++row;
Chris@70 142 }
Chris@70 143
Chris@73 144 subrow = 0;
Chris@73 145
Chris@70 146 if (options & ShowValue) {
Chris@70 147
Chris@73 148 subgrid->addWidget(new QLabel(tr("Value:")), subrow, 0);
Chris@70 149
Chris@73 150 m_valueSpinBox = new QDoubleSpinBox;
Chris@73 151 m_valueSpinBox->setSuffix(QString(" %1").arg(valueUnits));
Chris@73 152 m_valueSpinBox->setDecimals(10);
Chris@685 153 m_valueSpinBox->setMinimum(-1e10);
Chris@685 154 m_valueSpinBox->setMaximum(1e10);
Chris@73 155 connect(m_valueSpinBox, SIGNAL(valueChanged(double)),
Chris@70 156 this, SLOT(valueChanged(double)));
Chris@73 157 subgrid->addWidget(m_valueSpinBox, subrow, 1);
Chris@70 158
Chris@73 159 ++subrow;
Chris@70 160 }
Chris@70 161
Chris@70 162 if (options & ShowText) {
Chris@70 163
Chris@73 164 subgrid->addWidget(new QLabel(tr("Text:")), subrow, 0);
Chris@70 165
Chris@73 166 m_textField = new QLineEdit;
Chris@73 167 connect(m_textField, SIGNAL(textChanged(QString)),
Chris@70 168 this, SLOT(textChanged(QString)));
Chris@73 169 subgrid->addWidget(m_textField, subrow, 1);
Chris@70 170
Chris@73 171 ++subrow;
Chris@73 172 }
Chris@73 173
Chris@73 174 if (options & ShowText) {
Chris@73 175 m_textField->setFocus(Qt::OtherFocusReason);
Chris@73 176 } else if (options & ShowValue) {
Chris@73 177 m_valueSpinBox->setFocus(Qt::OtherFocusReason);
Chris@70 178 }
Chris@282 179
Chris@282 180 QDialogButtonBox *bb = new QDialogButtonBox(Qt::Horizontal);
Chris@282 181 grid->addWidget(bb, row, 0, 1, 2);
Chris@70 182
Chris@70 183 QPushButton *ok = new QPushButton(tr("OK"));
Chris@73 184 m_resetButton = new QPushButton(tr("Reset"));
Chris@70 185 QPushButton *cancel = new QPushButton(tr("Cancel"));
Chris@282 186 bb->addButton(ok, QDialogButtonBox::AcceptRole);
Chris@282 187 bb->addButton(m_resetButton, QDialogButtonBox::ResetRole);
Chris@282 188 bb->addButton(cancel, QDialogButtonBox::RejectRole);
Chris@70 189 connect(ok, SIGNAL(clicked()), this, SLOT(accept()));
Chris@73 190 connect(m_resetButton, SIGNAL(clicked()), this, SLOT(reset()));
Chris@70 191 connect(cancel, SIGNAL(clicked()), this, SLOT(reject()));
Chris@73 192 m_resetButton->setEnabled(false);
Chris@70 193 }
Chris@70 194
Chris@70 195 void
Chris@904 196 ItemEditDialog::setFrameTime(sv_frame_t frame)
Chris@70 197 {
Chris@73 198 if (!m_frameTimeSpinBox) return;
Chris@73 199
Chris@73 200 RealTime rt(RealTime::frame2RealTime(frame, m_sampleRate));
Chris@73 201 m_realTimeSecsSpinBox->setValue(rt.sec);
Chris@73 202 m_realTimeUSecsSpinBox->setValue(rt.usec());
Chris@908 203 m_frameTimeSpinBox->setValue(int(frame));
Chris@73 204 m_defaultFrame = frame;
Chris@73 205 m_resetButton->setEnabled(false);
Chris@70 206 }
Chris@70 207
Chris@904 208 sv_frame_t
Chris@70 209 ItemEditDialog::getFrameTime() const
Chris@70 210 {
Chris@73 211 return m_frameTimeSpinBox->value();
Chris@70 212 }
Chris@70 213
Chris@70 214 void
Chris@70 215 ItemEditDialog::setRealTime(RealTime rt)
Chris@70 216 {
Chris@73 217 setFrameTime(RealTime::realTime2Frame(rt, m_sampleRate));
Chris@70 218 }
Chris@70 219
Chris@70 220 RealTime
Chris@70 221 ItemEditDialog::getRealTime() const
Chris@70 222 {
Chris@73 223 return RealTime::frame2RealTime(getFrameTime(), m_sampleRate);
Chris@70 224 }
Chris@70 225
Chris@70 226 void
Chris@904 227 ItemEditDialog::setFrameDuration(sv_frame_t duration)
Chris@70 228 {
Chris@73 229 if (!m_frameDurationSpinBox) return;
Chris@73 230
Chris@73 231 RealTime rt(RealTime::frame2RealTime(duration, m_sampleRate));
Chris@73 232 m_realDurationSecsSpinBox->setValue(rt.sec);
Chris@73 233 m_realDurationUSecsSpinBox->setValue(rt.usec());
Chris@908 234 m_frameDurationSpinBox->setValue(int(duration));
Chris@73 235 m_defaultDuration = duration;
Chris@73 236 m_resetButton->setEnabled(false);
Chris@70 237 }
Chris@70 238
Chris@904 239 sv_frame_t
Chris@70 240 ItemEditDialog::getFrameDuration() const
Chris@70 241 {
Chris@73 242 return m_frameDurationSpinBox->value();
Chris@70 243 }
Chris@70 244
Chris@70 245 void
Chris@70 246 ItemEditDialog::setRealDuration(RealTime rt)
Chris@70 247 {
Chris@73 248 setFrameDuration(RealTime::realTime2Frame(rt, m_sampleRate));
Chris@70 249 }
Chris@70 250
Chris@70 251 RealTime
Chris@70 252 ItemEditDialog::getRealDuration() const
Chris@70 253 {
Chris@73 254 return RealTime::frame2RealTime(getFrameDuration(), m_sampleRate);
Chris@70 255 }
Chris@70 256
Chris@70 257 void
Chris@70 258 ItemEditDialog::setValue(float v)
Chris@70 259 {
Chris@73 260 if (!m_valueSpinBox) return;
Chris@73 261
Chris@73 262 m_valueSpinBox->setValue(v);
Chris@73 263 m_defaultValue = v;
Chris@73 264 m_resetButton->setEnabled(false);
Chris@70 265 }
Chris@70 266
Chris@70 267 float
Chris@70 268 ItemEditDialog::getValue() const
Chris@70 269 {
Chris@908 270 return float(m_valueSpinBox->value());
Chris@70 271 }
Chris@70 272
Chris@70 273 void
Chris@70 274 ItemEditDialog::setText(QString text)
Chris@70 275 {
Chris@73 276 if (!m_textField) return;
Chris@73 277
Chris@73 278 m_textField->setText(text);
Chris@73 279 m_defaultText = text;
Chris@73 280 m_resetButton->setEnabled(false);
Chris@70 281 }
Chris@70 282
Chris@70 283 QString
Chris@70 284 ItemEditDialog::getText() const
Chris@70 285 {
Chris@73 286 return m_textField->text();
Chris@70 287 }
Chris@70 288
Chris@70 289 void
Chris@938 290 ItemEditDialog::frameTimeChanged(int i)
Chris@70 291 {
Chris@73 292 m_realTimeSecsSpinBox->blockSignals(true);
Chris@73 293 m_realTimeUSecsSpinBox->blockSignals(true);
Chris@73 294
Chris@73 295 RealTime rt(RealTime::frame2RealTime(i, m_sampleRate));
Chris@73 296 m_realTimeSecsSpinBox->setValue(rt.sec);
Chris@73 297 m_realTimeUSecsSpinBox->setValue(rt.usec());
Chris@73 298
Chris@73 299 m_realTimeSecsSpinBox->blockSignals(false);
Chris@73 300 m_realTimeUSecsSpinBox->blockSignals(false);
Chris@73 301 m_resetButton->setEnabled(true);
Chris@70 302 }
Chris@70 303
Chris@70 304 void
Chris@73 305 ItemEditDialog::realTimeSecsChanged(int i)
Chris@70 306 {
Chris@70 307 RealTime rt = getRealTime();
Chris@73 308 rt.sec = i;
Chris@904 309 sv_frame_t frame = RealTime::realTime2Frame(rt, m_sampleRate);
Chris@908 310 m_frameTimeSpinBox->setValue(int(frame));
Chris@73 311 m_resetButton->setEnabled(true);
Chris@70 312 }
Chris@70 313
Chris@70 314 void
Chris@73 315 ItemEditDialog::realTimeUSecsChanged(int i)
Chris@70 316 {
Chris@70 317 RealTime rt = getRealTime();
Chris@73 318 rt.nsec = i * 1000;
Chris@904 319 sv_frame_t frame = RealTime::realTime2Frame(rt, m_sampleRate);
Chris@908 320 m_frameTimeSpinBox->setValue(int(frame));
Chris@73 321 m_resetButton->setEnabled(true);
Chris@70 322 }
Chris@70 323
Chris@70 324 void
Chris@938 325 ItemEditDialog::frameDurationChanged(int i)
Chris@70 326 {
Chris@73 327 m_realDurationSecsSpinBox->blockSignals(true);
Chris@73 328 m_realDurationUSecsSpinBox->blockSignals(true);
Chris@73 329
Chris@73 330 RealTime rt(RealTime::frame2RealTime(i, m_sampleRate));
Chris@73 331 m_realDurationSecsSpinBox->setValue(rt.sec);
Chris@73 332 m_realDurationUSecsSpinBox->setValue(rt.usec());
Chris@73 333
Chris@73 334 m_realDurationSecsSpinBox->blockSignals(false);
Chris@73 335 m_realDurationUSecsSpinBox->blockSignals(false);
Chris@73 336 m_resetButton->setEnabled(true);
Chris@70 337 }
Chris@70 338
Chris@70 339 void
Chris@73 340 ItemEditDialog::realDurationSecsChanged(int i)
Chris@70 341 {
Chris@70 342 RealTime rt = getRealDuration();
Chris@73 343 rt.sec = i;
Chris@904 344 sv_frame_t frame = RealTime::realTime2Frame(rt, m_sampleRate);
Chris@908 345 m_frameDurationSpinBox->setValue(int(frame));
Chris@73 346 m_resetButton->setEnabled(true);
Chris@70 347 }
Chris@70 348
Chris@70 349 void
Chris@73 350 ItemEditDialog::realDurationUSecsChanged(int i)
Chris@70 351 {
Chris@70 352 RealTime rt = getRealDuration();
Chris@73 353 rt.nsec = i * 1000;
Chris@904 354 sv_frame_t frame = RealTime::realTime2Frame(rt, m_sampleRate);
Chris@908 355 m_frameDurationSpinBox->setValue(int(frame));
Chris@73 356 m_resetButton->setEnabled(true);
Chris@70 357 }
Chris@70 358
Chris@70 359 void
Chris@73 360 ItemEditDialog::valueChanged(double)
Chris@70 361 {
Chris@73 362 m_resetButton->setEnabled(true);
Chris@70 363 }
Chris@70 364
Chris@70 365 void
Chris@73 366 ItemEditDialog::textChanged(QString)
Chris@70 367 {
Chris@73 368 m_resetButton->setEnabled(true);
Chris@70 369 }
Chris@70 370
Chris@73 371 void
Chris@73 372 ItemEditDialog::reset()
Chris@73 373 {
Chris@73 374 setFrameTime(m_defaultFrame);
Chris@73 375 setFrameDuration(m_defaultDuration);
Chris@73 376 setValue(m_defaultValue);
Chris@73 377 setText(m_defaultText);
Chris@73 378 m_resetButton->setEnabled(false);
Chris@73 379 }
Chris@73 380