# HG changeset patch # User Chris Cannam # Date 1568985557 -3600 # Node ID 0fa49a6ce64f7950e2ad4351a97a8fe6fee3606a # Parent e453053a44dceeae1a0384ee2a18e48de3fd3b01 Item-editing updates needed for time-frequency box layer diff -r e453053a44dc -r 0fa49a6ce64f layer/FlexiNoteLayer.cpp --- a/layer/FlexiNoteLayer.cpp Fri Sep 20 11:25:47 2019 +0100 +++ b/layer/FlexiNoteLayer.cpp Fri Sep 20 14:19:17 2019 +0100 @@ -1604,13 +1604,12 @@ Event note(0); if (!getPointToDrag(v, e->x(), e->y(), note)) return false; -// Event note = *points.begin(); - ItemEditDialog *dialog = new ItemEditDialog (model->getSampleRate(), ItemEditDialog::ShowTime | ItemEditDialog::ShowDuration | ItemEditDialog::ShowValue | + ItemEditDialog::ShowLevel | ItemEditDialog::ShowText, getScaleUnits()); diff -r e453053a44dc -r 0fa49a6ce64f layer/NoteLayer.cpp --- a/layer/NoteLayer.cpp Fri Sep 20 11:25:47 2019 +0100 +++ b/layer/NoteLayer.cpp Fri Sep 20 14:19:17 2019 +0100 @@ -1062,13 +1062,12 @@ Event note(0); if (!getPointToDrag(v, e->x(), e->y(), note)) return false; -// Event note = *points.begin(); - ItemEditDialog *dialog = new ItemEditDialog (model->getSampleRate(), ItemEditDialog::ShowTime | ItemEditDialog::ShowDuration | ItemEditDialog::ShowValue | + ItemEditDialog::ShowLevel | ItemEditDialog::ShowText, getScaleUnits()); diff -r e453053a44dc -r 0fa49a6ce64f layer/TimeFrequencyBoxLayer.cpp --- a/layer/TimeFrequencyBoxLayer.cpp Fri Sep 20 11:25:47 2019 +0100 +++ b/layer/TimeFrequencyBoxLayer.cpp Fri Sep 20 14:19:17 2019 +0100 @@ -939,16 +939,24 @@ Event region(0); if (!getPointToDrag(v, e->x(), e->y(), region)) return false; + ItemEditDialog::LabelOptions labelOptions; + labelOptions.valueLabel = tr("Minimum Frequency"); + labelOptions.levelLabel = tr("Frequency Extent"); + labelOptions.valueUnits = getScaleUnits(); + labelOptions.levelUnits = getScaleUnits(); + ItemEditDialog *dialog = new ItemEditDialog (model->getSampleRate(), ItemEditDialog::ShowTime | ItemEditDialog::ShowDuration | ItemEditDialog::ShowValue | + ItemEditDialog::ShowLevel | ItemEditDialog::ShowText, - getScaleUnits()); + labelOptions); dialog->setFrameTime(region.getFrame()); dialog->setValue(region.getValue()); + dialog->setLevel(region.getLevel()); dialog->setFrameDuration(region.getDuration()); dialog->setText(region.getLabel()); @@ -957,6 +965,7 @@ Event newTimeFrequencyBox = region .withFrame(dialog->getFrameTime()) .withValue(dialog->getValue()) + .withLevel(dialog->getLevel()) .withDuration(dialog->getFrameDuration()) .withLabel(dialog->getText()); @@ -1143,12 +1152,11 @@ void TimeFrequencyBoxLayer::toXml(QTextStream &stream, - QString indent, QString extraAttributes) const + QString indent, QString extraAttributes) const { QString s; - s += QString("verticalScale=\"%1\" ") - .arg(m_verticalScale); + s += QString("verticalScale=\"%1\" ").arg(m_verticalScale); SingleColourLayer::toXml(stream, indent, extraAttributes + " " + s); } diff -r e453053a44dc -r 0fa49a6ce64f widgets/ItemEditDialog.cpp --- a/widgets/ItemEditDialog.cpp Fri Sep 20 11:25:47 2019 +0100 +++ b/widgets/ItemEditDialog.cpp Fri Sep 20 14:19:17 2019 +0100 @@ -28,13 +28,30 @@ #include // for FLT_MIN/MAX +ItemEditDialog::LabelOptions::LabelOptions() : + valueLabel(tr("Value")), + levelLabel(tr("Level")) +{ +} + ItemEditDialog::ItemEditDialog(sv_samplerate_t sampleRate, int options, - QString valueUnits, QWidget *parent) : + QString scaleUnits, QWidget *parent) : + ItemEditDialog(sampleRate, options, + [] (QString units) { + ItemEditDialog::LabelOptions options; + options.valueUnits = units; + return options; + }(scaleUnits), + parent) {}; + +ItemEditDialog::ItemEditDialog(sv_samplerate_t sampleRate, int options, + LabelOptions labelOptions, QWidget *parent) : QDialog(parent), m_sampleRate(sampleRate), m_defaultFrame(0), m_defaultDuration(0), m_defaultValue(0), + m_defaultLevel(0), m_frameTimeSpinBox(nullptr), m_realTimeSecsSpinBox(nullptr), m_realTimeUSecsSpinBox(nullptr), @@ -42,6 +59,7 @@ m_realDurationSecsSpinBox(nullptr), m_realDurationUSecsSpinBox(nullptr), m_valueSpinBox(nullptr), + m_levelSpinBox(nullptr), m_textField(nullptr) { QGridLayout *grid = new QGridLayout; @@ -129,7 +147,9 @@ ++subrow; } - if ((options & ShowValue) || (options & ShowText)) { + if ((options & ShowValue) || + (options & ShowLevel) || + (options & ShowText)) { valueBox = new QGroupBox; valueBox->setTitle(tr("Properties")); @@ -145,10 +165,11 @@ if (options & ShowValue) { - subgrid->addWidget(new QLabel(tr("Value:")), subrow, 0); + subgrid->addWidget(new QLabel(tr("%1:").arg(labelOptions.valueLabel)), + subrow, 0); m_valueSpinBox = new QDoubleSpinBox; - m_valueSpinBox->setSuffix(QString(" %1").arg(valueUnits)); + m_valueSpinBox->setSuffix(QString(" %1").arg(labelOptions.valueUnits)); m_valueSpinBox->setDecimals(10); m_valueSpinBox->setMinimum(-1e10); m_valueSpinBox->setMaximum(1e10); @@ -159,6 +180,23 @@ ++subrow; } + if (options & ShowLevel) { + + subgrid->addWidget(new QLabel(tr("%1:").arg(labelOptions.levelLabel)), + subrow, 0); + + m_levelSpinBox = new QDoubleSpinBox; + m_levelSpinBox->setSuffix(QString(" %1").arg(labelOptions.levelUnits)); + m_levelSpinBox->setDecimals(10); + m_levelSpinBox->setMinimum(-1e10); + m_levelSpinBox->setMaximum(1e10); + connect(m_levelSpinBox, SIGNAL(levelChanged(double)), + this, SLOT(levelChanged(double))); + subgrid->addWidget(m_levelSpinBox, subrow, 1); + + ++subrow; + } + if (options & ShowText) { subgrid->addWidget(new QLabel(tr("Text:")), subrow, 0); @@ -175,6 +213,8 @@ m_textField->setFocus(Qt::OtherFocusReason); } else if (options & ShowValue) { m_valueSpinBox->setFocus(Qt::OtherFocusReason); + } else if (options & ShowLevel) { + m_levelSpinBox->setFocus(Qt::OtherFocusReason); } QDialogButtonBox *bb = new QDialogButtonBox(Qt::Horizontal); @@ -271,6 +311,22 @@ } void +ItemEditDialog::setLevel(float v) +{ + if (!m_levelSpinBox) return; + + m_levelSpinBox->setValue(v); + m_defaultLevel = v; + m_resetButton->setEnabled(false); +} + +float +ItemEditDialog::getLevel() const +{ + return float(m_levelSpinBox->value()); +} + +void ItemEditDialog::setText(QString text) { if (!m_textField) return; @@ -363,6 +419,12 @@ } void +ItemEditDialog::levelChanged(double) +{ + m_resetButton->setEnabled(true); +} + +void ItemEditDialog::textChanged(QString) { m_resetButton->setEnabled(true); @@ -374,6 +436,7 @@ setFrameTime(m_defaultFrame); setFrameDuration(m_defaultDuration); setValue(m_defaultValue); + setLevel(m_defaultLevel); setText(m_defaultText); m_resetButton->setEnabled(false); } diff -r e453053a44dc -r 0fa49a6ce64f widgets/ItemEditDialog.h --- a/widgets/ItemEditDialog.h Fri Sep 20 11:25:47 2019 +0100 +++ b/widgets/ItemEditDialog.h Fri Sep 20 14:19:17 2019 +0100 @@ -34,10 +34,26 @@ ShowTime = 1 << 0, ShowDuration = 1 << 1, ShowValue = 1 << 2, - ShowText = 1 << 3 + ShowText = 1 << 3, + ShowLevel = 1 << 4 }; - ItemEditDialog(sv_samplerate_t sampleRate, int options, QString valueUnits = "", + struct LabelOptions { + LabelOptions(); + QString valueLabel; + QString levelLabel; + QString valueUnits; + QString levelUnits; + }; + + ItemEditDialog(sv_samplerate_t sampleRate, + int options, + LabelOptions labelOptions = {}, + QWidget *parent = 0); + + ItemEditDialog(sv_samplerate_t sampleRate, + int options, + QString scaleUnits, QWidget *parent = 0); void setFrameTime(sv_frame_t frame); @@ -55,6 +71,9 @@ void setValue(float value); float getValue() const; + void setLevel(float level); + float getLevel() const; + void setText(QString text); QString getText() const; @@ -66,6 +85,7 @@ void realDurationSecsChanged(int); void realDurationUSecsChanged(int); void valueChanged(double); + void levelChanged(double); void textChanged(QString); void reset(); @@ -74,6 +94,7 @@ sv_frame_t m_defaultFrame; sv_frame_t m_defaultDuration; float m_defaultValue; + float m_defaultLevel; QString m_defaultText; QSpinBox *m_frameTimeSpinBox; QSpinBox *m_realTimeSecsSpinBox; @@ -82,6 +103,7 @@ QSpinBox *m_realDurationSecsSpinBox; QSpinBox *m_realDurationUSecsSpinBox; QDoubleSpinBox *m_valueSpinBox; + QDoubleSpinBox *m_levelSpinBox; QLineEdit *m_textField; QPushButton *m_resetButton; };