Mercurial > hg > svgui
changeset 889:cd59f6e1aa26
hz -> freq, and some layout rearrangement
author | Chris Cannam |
---|---|
date | Tue, 09 Dec 2014 11:45:34 +0000 |
parents | cb3a3e20634d |
children | 1f2dc7fcad92 |
files | widgets/UnitConverter.cpp widgets/UnitConverter.h |
diffstat | 2 files changed, 54 insertions(+), 37 deletions(-) [+] |
line wrap: on
line diff
--- a/widgets/UnitConverter.cpp Mon Dec 08 15:37:49 2014 +0000 +++ b/widgets/UnitConverter.cpp Tue Dec 09 11:45:34 2014 +0000 @@ -20,6 +20,7 @@ #include <QLabel> #include <QDialogButtonBox> #include <QGridLayout> +#include <QTabWidget> #include "base/Debug.h" #include "base/Pitch.h" @@ -35,17 +36,30 @@ UnitConverter::UnitConverter(QWidget *parent) : QDialog(parent) { + QGridLayout *maingrid = new QGridLayout; + setLayout(maingrid); + + QTabWidget *tabs = new QTabWidget; + maingrid->addWidget(tabs, 0, 0); + + QDialogButtonBox *bb = new QDialogButtonBox(QDialogButtonBox::Close); + maingrid->addWidget(bb, 1, 0); + connect(bb, SIGNAL(rejected()), this, SLOT(close())); + + QFrame *frame = new QFrame; + tabs->addTab(frame, tr("Pitch")); + QGridLayout *grid = new QGridLayout; - setLayout(grid); + frame->setLayout(grid); - m_hz = new QDoubleSpinBox; - m_hz->setSuffix(QString(" Hz")); - m_hz->setDecimals(6); - m_hz->setMinimum(1e-3); - m_hz->setMaximum(1e6); - m_hz->setValue(440); - connect(m_hz, SIGNAL(valueChanged(double)), - this, SLOT(hzChanged(double))); + m_freq = new QDoubleSpinBox; + m_freq->setSuffix(QString(" Hz")); + m_freq->setDecimals(6); + m_freq->setMinimum(1e-3); + m_freq->setMaximum(1e6); + m_freq->setValue(440); + connect(m_freq, SIGNAL(valueChanged(double)), + this, SLOT(freqChanged(double))); // The min and max range values for all the remaining controls are // determined by the min and max Hz above @@ -82,11 +96,11 @@ int row = 1; - grid->addWidget(m_hz, row, 0); - grid->addWidget(new QLabel(tr("=")), row, 1); + grid->addWidget(m_freq, row, 0, 2, 1); + grid->addWidget(new QLabel(tr("=")), row, 1, 2, 1); - grid->addWidget(new QLabel(tr("+")), row, 7); - grid->addWidget(m_cents, row, 8); + grid->addWidget(new QLabel(tr("+")), row, 7, 2, 1); + grid->addWidget(m_cents, row, 8, 2, 1); grid->addWidget(new QLabel(tr("Piano note")), row, 2, 1, 2); grid->addWidget(m_note, row, 4); @@ -117,11 +131,13 @@ ++row; - QDialogButtonBox *bb = new QDialogButtonBox(QDialogButtonBox::Close); - grid->addWidget(bb, row, 0, 1, 9); - connect(bb, SIGNAL(rejected()), this, SLOT(close())); + QFrame *frame = new QFrame; + tabs->addTab(frame, tr("Pitch")); + + QGridLayout *grid = new QGridLayout; + frame->setLayout(grid); - updateAllFromHz(); + updatePitchesFromFreq(); } UnitConverter::~UnitConverter() @@ -129,19 +145,19 @@ } void -UnitConverter::hzChanged(double hz) +UnitConverter::freqChanged(double freq) { - cerr << "hzChanged: " << hz << endl; - updateAllFromHz(); + cerr << "freqChanged: " << freq << endl; + updatePitchesFromFreq(); } void UnitConverter::midiChanged(int midi) { cerr << "midiChanged: " << midi << endl; - double hz = Pitch::getFrequencyForPitch(m_midi->value(), m_cents->value()); - cerr << "hz -> " << hz << endl; - m_hz->setValue(hz); + double freq = Pitch::getFrequencyForPitch(m_midi->value(), m_cents->value()); + cerr << "freq -> " << freq << endl; + m_freq->setValue(freq); } void @@ -150,9 +166,9 @@ cerr << "noteChanged: " << note << endl; int pitch = Pitch::getPitchForNoteAndOctave(m_note->currentIndex(), m_octave->value()); - double hz = Pitch::getFrequencyForPitch(pitch, m_cents->value()); - cerr << "hz -> " << hz << endl; - m_hz->setValue(hz); + double freq = Pitch::getFrequencyForPitch(pitch, m_cents->value()); + cerr << "freq -> " << freq << endl; + m_freq->setValue(freq); } void @@ -161,18 +177,18 @@ cerr << "octaveChanged: " << oct << endl; int pitch = Pitch::getPitchForNoteAndOctave(m_note->currentIndex(), m_octave->value()); - double hz = Pitch::getFrequencyForPitch(pitch, m_cents->value()); - cerr << "hz -> " << hz << endl; - m_hz->setValue(hz); + double freq = Pitch::getFrequencyForPitch(pitch, m_cents->value()); + cerr << "freq -> " << freq << endl; + m_freq->setValue(freq); } void UnitConverter::centsChanged(double cents) { cerr << "centsChanged: " << cents << endl; - double hz = Pitch::getFrequencyForPitch(m_midi->value(), m_cents->value()); - cerr << "hz -> " << hz << endl; - m_hz->setValue(hz); + double freq = Pitch::getFrequencyForPitch(m_midi->value(), m_cents->value()); + cerr << "freq -> " << freq << endl; + m_freq->setValue(freq); } void @@ -182,10 +198,10 @@ } void -UnitConverter::updateAllFromHz() +UnitConverter::updatePitchesFromFreq() { float cents = 0; - int pitch = Pitch::getPitchForFrequency(m_hz->value(), ¢s); + int pitch = Pitch::getPitchForFrequency(m_freq->value(), ¢s); int note, octave; Pitch::getNoteAndOctaveForPitch(pitch, note, octave);
--- a/widgets/UnitConverter.h Mon Dec 08 15:37:49 2014 +0000 +++ b/widgets/UnitConverter.h Tue Dec 09 11:45:34 2014 +0000 @@ -30,22 +30,23 @@ virtual ~UnitConverter(); private slots: - void hzChanged(double); + void freqChanged(double); void midiChanged(int); void noteChanged(int); void octaveChanged(int); void centsChanged(double); void pianoChanged(int); + private: - QDoubleSpinBox *m_hz; + QDoubleSpinBox *m_freq; QSpinBox *m_midi; QComboBox *m_note; QSpinBox *m_octave; QDoubleSpinBox *m_cents; QSpinBox *m_piano; - void updateAllFromHz(); + void updatePitchesFromFreq(); }; #endif