Chris@70: /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ Chris@70: Chris@70: /* Chris@70: Sonic Visualiser Chris@70: An audio file viewer and annotation editor. Chris@70: Centre for Digital Music, Queen Mary, University of London. Chris@70: This file copyright 2006 Chris Cannam. Chris@70: Chris@70: This program is free software; you can redistribute it and/or Chris@70: modify it under the terms of the GNU General Public License as Chris@70: published by the Free Software Foundation; either version 2 of the Chris@70: License, or (at your option) any later version. See the file Chris@70: COPYING included with this distribution for more information. Chris@70: */ Chris@70: Chris@70: #include "ItemEditDialog.h" Chris@70: Chris@70: #include Chris@70: #include Chris@70: #include Chris@70: #include Chris@70: #include Chris@70: #include Chris@70: Chris@70: Chris@70: ItemEditDialog::ItemEditDialog(size_t sampleRate, int options, QWidget *parent) : Chris@70: QDialog(parent), Chris@70: m_sampleRate(sampleRate), Chris@70: m_frame(0), Chris@70: m_duration(0), Chris@70: m_value(0.0) Chris@70: { Chris@70: QGridLayout *grid = new QGridLayout; Chris@70: setLayout(grid); Chris@70: Chris@70: int row = 0; Chris@70: QLineEdit *line = 0; Chris@70: Chris@70: if (options & ShowTime) { Chris@70: Chris@70: grid->addWidget(new QLabel(tr("Frame time:")), row, 0); Chris@70: Chris@70: line = new QLineEdit; Chris@70: line->setValidator(new QIntValidator(this)); Chris@70: grid->addWidget(line, row, 1); Chris@70: connect(line, SIGNAL(textChanged(QString)), Chris@70: this, SLOT(frameTimeChanged(QString))); Chris@70: Chris@70: ++row; Chris@70: Chris@70: grid->addWidget(new QLabel(tr("Secs:")), row, 0); Chris@70: Chris@70: line = new QLineEdit; Chris@70: line->setValidator(new QIntValidator(this)); Chris@70: grid->addWidget(line, row, 1); Chris@70: connect(line, SIGNAL(textChanged(QString)), Chris@70: this, SLOT(realTimeSecsChanged(QString))); Chris@70: Chris@70: ++row; Chris@70: Chris@70: grid->addWidget(new QLabel(tr("Nsecs:")), row, 0); Chris@70: Chris@70: line = new QLineEdit; Chris@70: line->setValidator(new QIntValidator(this)); Chris@70: grid->addWidget(line, row, 1); Chris@70: connect(line, SIGNAL(textChanged(QString)), Chris@70: this, SLOT(realTimeSecsChanged(QString))); Chris@70: Chris@70: ++row; Chris@70: } Chris@70: Chris@70: if (options & ShowDuration) { Chris@70: Chris@70: grid->addWidget(new QLabel(tr("Frame duration:")), row, 0); Chris@70: Chris@70: line = new QLineEdit; Chris@70: line->setValidator(new QIntValidator(this)); Chris@70: grid->addWidget(line, row, 1); Chris@70: connect(line, SIGNAL(textChanged(QString)), Chris@70: this, SLOT(frameDurationChanged(QString))); Chris@70: Chris@70: ++row; Chris@70: Chris@70: grid->addWidget(new QLabel(tr("Secs:")), row, 0); Chris@70: Chris@70: line = new QLineEdit; Chris@70: line->setValidator(new QIntValidator(this)); Chris@70: grid->addWidget(line, row, 1); Chris@70: connect(line, SIGNAL(textChanged(QString)), Chris@70: this, SLOT(realDurationSecsChanged(QString))); Chris@70: Chris@70: ++row; Chris@70: Chris@70: grid->addWidget(new QLabel(tr("Nsecs:")), row, 0); Chris@70: Chris@70: line = new QLineEdit; Chris@70: line->setValidator(new QIntValidator(this)); Chris@70: grid->addWidget(line, row, 1); Chris@70: connect(line, SIGNAL(textChanged(QString)), Chris@70: this, SLOT(realDurationSecsChanged(QString))); Chris@70: Chris@70: ++row; Chris@70: } Chris@70: Chris@70: if (options & ShowValue) { Chris@70: Chris@70: grid->addWidget(new QLabel(tr("Value:")), row, 0); Chris@70: Chris@70: QDoubleSpinBox *spinbox = new QDoubleSpinBox; Chris@70: grid->addWidget(spinbox, row, 1); Chris@70: connect(spinbox, SIGNAL(valueChanged(double)), Chris@70: this, SLOT(valueChanged(double))); Chris@70: Chris@70: ++row; Chris@70: } Chris@70: Chris@70: if (options & ShowText) { Chris@70: Chris@70: grid->addWidget(new QLabel(tr("Text:")), row, 0); Chris@70: Chris@70: line = new QLineEdit; Chris@70: grid->addWidget(line, row, 1); Chris@70: connect(line, SIGNAL(textChanged(QString)), Chris@70: this, SLOT(textChanged(QString))); Chris@70: Chris@70: ++row; Chris@70: } Chris@70: Chris@70: QHBoxLayout *hbox = new QHBoxLayout; Chris@70: grid->addLayout(hbox, row, 0, 1, 2); Chris@70: Chris@70: QPushButton *ok = new QPushButton(tr("OK")); Chris@70: QPushButton *cancel = new QPushButton(tr("Cancel")); Chris@70: hbox->addStretch(10); Chris@70: hbox->addWidget(ok); Chris@70: hbox->addWidget(cancel); Chris@70: connect(ok, SIGNAL(clicked()), this, SLOT(accept())); Chris@70: connect(cancel, SIGNAL(clicked()), this, SLOT(reject())); Chris@70: } Chris@70: Chris@70: void Chris@70: ItemEditDialog::setFrameTime(long frame) Chris@70: { Chris@70: m_frame = frame; Chris@70: //!!! Chris@70: } Chris@70: Chris@70: long Chris@70: ItemEditDialog::getFrameTime() const Chris@70: { Chris@70: return m_frame; Chris@70: } Chris@70: Chris@70: void Chris@70: ItemEditDialog::setRealTime(RealTime rt) Chris@70: { Chris@70: m_frame = RealTime::realTime2Frame(rt, m_sampleRate); Chris@70: //!!! Chris@70: } Chris@70: Chris@70: RealTime Chris@70: ItemEditDialog::getRealTime() const Chris@70: { Chris@70: return RealTime::frame2RealTime(m_frame, m_sampleRate); Chris@70: } Chris@70: Chris@70: void Chris@70: ItemEditDialog::setFrameDuration(long duration) Chris@70: { Chris@70: m_duration = duration; Chris@70: //!!! Chris@70: } Chris@70: Chris@70: long Chris@70: ItemEditDialog::getFrameDuration() const Chris@70: { Chris@70: return m_duration; Chris@70: } Chris@70: Chris@70: void Chris@70: ItemEditDialog::setRealDuration(RealTime rt) Chris@70: { Chris@70: m_duration = RealTime::realTime2Frame(rt, m_sampleRate); Chris@70: } Chris@70: Chris@70: RealTime Chris@70: ItemEditDialog::getRealDuration() const Chris@70: { Chris@70: return RealTime::frame2RealTime(m_duration, m_sampleRate); Chris@70: } Chris@70: Chris@70: void Chris@70: ItemEditDialog::setValue(float v) Chris@70: { Chris@70: m_value = v; Chris@70: //!!! Chris@70: } Chris@70: Chris@70: float Chris@70: ItemEditDialog::getValue() const Chris@70: { Chris@70: return m_value; Chris@70: } Chris@70: Chris@70: void Chris@70: ItemEditDialog::setText(QString text) Chris@70: { Chris@70: m_text = text; Chris@70: //!!! Chris@70: } Chris@70: Chris@70: QString Chris@70: ItemEditDialog::getText() const Chris@70: { Chris@70: return m_text; Chris@70: } Chris@70: Chris@70: void Chris@70: ItemEditDialog::frameTimeChanged(QString s) Chris@70: { Chris@70: setFrameTime(s.toInt()); Chris@70: } Chris@70: Chris@70: void Chris@70: ItemEditDialog::realTimeSecsChanged(QString s) Chris@70: { Chris@70: RealTime rt = getRealTime(); Chris@70: rt.sec = s.toInt(); Chris@70: setRealTime(rt); Chris@70: } Chris@70: Chris@70: void Chris@70: ItemEditDialog::realTimeNSecsChanged(QString s) Chris@70: { Chris@70: RealTime rt = getRealTime(); Chris@70: rt.nsec = s.toInt(); Chris@70: setRealTime(rt); Chris@70: } Chris@70: Chris@70: void Chris@70: ItemEditDialog::frameDurationChanged(QString s) Chris@70: { Chris@70: setFrameDuration(s.toInt()); Chris@70: } Chris@70: Chris@70: void Chris@70: ItemEditDialog::realDurationSecsChanged(QString s) Chris@70: { Chris@70: RealTime rt = getRealDuration(); Chris@70: rt.sec = s.toInt(); Chris@70: setRealDuration(rt); Chris@70: } Chris@70: Chris@70: void Chris@70: ItemEditDialog::realDurationNSecsChanged(QString s) Chris@70: { Chris@70: RealTime rt = getRealDuration(); Chris@70: rt.nsec = s.toInt(); Chris@70: setRealDuration(rt); Chris@70: } Chris@70: Chris@70: void Chris@70: ItemEditDialog::valueChanged(double v) Chris@70: { Chris@70: setValue((float)v); Chris@70: } Chris@70: Chris@70: void Chris@70: ItemEditDialog::textChanged(QString text) Chris@70: { Chris@70: setText(text); Chris@70: } Chris@70: