annotate widgets/RangeInputDialog.cpp @ 271:1a49bd0d8375

* Change a number of keyboard shortcuts -- get rid of all the Alt+ shortcuts and introduce a few more Ctrl+ ones instead, as well as a number of plain single keypresses * Add Playback menu * Add time-ruler support for snap to feature, use it in ffwd/rewind (rewind still needs fixing) * restore layer hierarchy window prior to making it work correctly
author Chris Cannam
date Thu, 28 Jun 2007 14:50:58 +0000
parents dd573e090eed
children 4edaff85875d
rev   line source
Chris@188 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@188 2
Chris@188 3 /*
Chris@188 4 Sonic Visualiser
Chris@188 5 An audio file viewer and annotation editor.
Chris@188 6 Centre for Digital Music, Queen Mary, University of London.
Chris@188 7 This file copyright 2007 QMUL.
Chris@188 8
Chris@188 9 This program is free software; you can redistribute it and/or
Chris@188 10 modify it under the terms of the GNU General Public License as
Chris@188 11 published by the Free Software Foundation; either version 2 of the
Chris@188 12 License, or (at your option) any later version. See the file
Chris@188 13 COPYING included with this distribution for more information.
Chris@188 14 */
Chris@188 15
Chris@188 16 #include "RangeInputDialog.h"
Chris@188 17
Chris@188 18 #include <QDoubleSpinBox>
Chris@188 19 #include <QGridLayout>
Chris@188 20 #include <QLabel>
Chris@188 21 #include <QHBoxLayout>
Chris@188 22 #include <QPushButton>
Chris@188 23
Chris@188 24 RangeInputDialog::RangeInputDialog(QString title, QString message,
Chris@188 25 QString unit, float min, float max,
Chris@188 26 QWidget *parent) :
Chris@188 27 QDialog(parent)
Chris@188 28 {
Chris@188 29 QGridLayout *grid = new QGridLayout;
Chris@188 30 setLayout(grid);
Chris@188 31
Chris@188 32 setWindowTitle(title);
Chris@188 33
Chris@188 34 QLabel *messageLabel = new QLabel;
Chris@188 35 messageLabel->setText(message);
Chris@188 36 grid->addWidget(messageLabel, 0, 0, 1, 5);
Chris@188 37
Chris@188 38 m_rangeStart = new QDoubleSpinBox;
Chris@188 39 m_rangeStart->setDecimals(4);
Chris@188 40 m_rangeStart->setMinimum(min);
Chris@188 41 m_rangeStart->setMaximum(max);
Chris@188 42 m_rangeStart->setSuffix(unit);
Chris@188 43 grid->addWidget(m_rangeStart, 1, 1);
Chris@188 44 connect(m_rangeStart, SIGNAL(valueChanged(double)),
Chris@188 45 this, SLOT(rangeStartChanged(double)));
Chris@188 46
Chris@188 47 grid->addWidget(new QLabel(tr(" to ")), 1, 2);
Chris@188 48
Chris@188 49 m_rangeEnd = new QDoubleSpinBox;
Chris@188 50 m_rangeEnd->setDecimals(4);
Chris@188 51 m_rangeEnd->setMinimum(min);
Chris@188 52 m_rangeEnd->setMaximum(max);
Chris@188 53 m_rangeEnd->setSuffix(unit);
Chris@188 54 grid->addWidget(m_rangeEnd, 1, 3);
Chris@188 55 connect(m_rangeEnd, SIGNAL(valueChanged(double)),
Chris@188 56 this, SLOT(rangeEndChanged(double)));
Chris@188 57
Chris@188 58 QHBoxLayout *hbox = new QHBoxLayout;
Chris@188 59 grid->addLayout(hbox, 2, 0, 1, 5);
Chris@188 60
Chris@188 61 QPushButton *ok = new QPushButton(tr("OK"), this);
Chris@188 62 ok->setDefault(true);
Chris@188 63
Chris@188 64 QPushButton *cancel = new QPushButton(tr("Cancel"), this);
Chris@188 65
Chris@188 66 QSize bs = ok->sizeHint().expandedTo(cancel->sizeHint());
Chris@188 67 ok->setFixedSize(bs);
Chris@188 68 cancel->setFixedSize(bs);
Chris@188 69
Chris@188 70 hbox->addStretch();
Chris@188 71 hbox->addWidget(ok);
Chris@188 72 hbox->addWidget(cancel);
Chris@188 73
Chris@188 74 QObject::connect(ok, SIGNAL(clicked()), this, SLOT(accept()));
Chris@188 75 QObject::connect(cancel, SIGNAL(clicked()), this, SLOT(reject()));
Chris@188 76 }
Chris@188 77
Chris@188 78 RangeInputDialog::~RangeInputDialog()
Chris@188 79 {
Chris@188 80 }
Chris@188 81
Chris@188 82 void
Chris@188 83 RangeInputDialog::getRange(float &min, float &max)
Chris@188 84 {
Chris@188 85 min = float(m_rangeStart->value());
Chris@188 86 max = float(m_rangeEnd->value());
Chris@188 87
Chris@188 88 if (min > max) {
Chris@188 89 float tmp = min;
Chris@188 90 min = max;
Chris@188 91 max = tmp;
Chris@188 92 }
Chris@188 93 }
Chris@188 94
Chris@188 95 void
Chris@188 96 RangeInputDialog::setRange(float start, float end)
Chris@188 97 {
Chris@188 98 if (start > end) {
Chris@188 99 float tmp = start;
Chris@188 100 start = end;
Chris@188 101 end = tmp;
Chris@188 102 }
Chris@188 103
Chris@188 104 blockSignals(true);
Chris@188 105 m_rangeStart->setValue(start);
Chris@188 106 m_rangeEnd->setValue(end);
Chris@188 107 blockSignals(false);
Chris@188 108 }
Chris@188 109
Chris@188 110 void
Chris@188 111 RangeInputDialog::rangeStartChanged(double min)
Chris@188 112 {
Chris@188 113 double max = m_rangeEnd->value();
Chris@188 114 if (min > max) {
Chris@188 115 double tmp = min;
Chris@188 116 min = max;
Chris@188 117 max = tmp;
Chris@188 118 }
Chris@188 119 emit rangeChanged(float(min), float(max));
Chris@188 120 }
Chris@188 121
Chris@188 122
Chris@188 123 void
Chris@188 124 RangeInputDialog::rangeEndChanged(double max)
Chris@188 125 {
Chris@188 126 double min = m_rangeStart->value();
Chris@188 127 if (min > max) {
Chris@188 128 double tmp = min;
Chris@188 129 min = max;
Chris@188 130 max = tmp;
Chris@188 131 }
Chris@188 132 emit rangeChanged(float(min), float(max));
Chris@188 133 }
Chris@188 134