svgui  1.9
RangeInputDialog.cpp
Go to the documentation of this file.
00001 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*-  vi:set ts=8 sts=4 sw=4: */
00002 
00003 /*
00004     Sonic Visualiser
00005     An audio file viewer and annotation editor.
00006     Centre for Digital Music, Queen Mary, University of London.
00007     This file copyright 2007 QMUL.
00008     
00009     This program is free software; you can redistribute it and/or
00010     modify it under the terms of the GNU General Public License as
00011     published by the Free Software Foundation; either version 2 of the
00012     License, or (at your option) any later version.  See the file
00013     COPYING included with this distribution for more information.
00014 */
00015 
00016 #include "RangeInputDialog.h"
00017 
00018 #include <QDoubleSpinBox>
00019 #include <QGridLayout>
00020 #include <QLabel>
00021 #include <QHBoxLayout>
00022 #include <QDialogButtonBox>
00023 #include <QPushButton>
00024 
00025 RangeInputDialog::RangeInputDialog(QString title, QString message,
00026                                    QString unit, float min, float max, 
00027                                    QWidget *parent) :
00028     QDialog(parent)
00029 {
00030     QGridLayout *grid = new QGridLayout;
00031     setLayout(grid);
00032 
00033     setWindowTitle(title);
00034     
00035     QLabel *messageLabel = new QLabel;
00036     messageLabel->setText(message);
00037     grid->addWidget(messageLabel, 0, 0, 1, 5);
00038 
00039     m_rangeStart = new QDoubleSpinBox;
00040     m_rangeStart->setDecimals(4);
00041     m_rangeStart->setMinimum(min);
00042     m_rangeStart->setMaximum(max);
00043     m_rangeStart->setSuffix(unit);
00044     grid->addWidget(m_rangeStart, 1, 1);
00045     connect(m_rangeStart, SIGNAL(valueChanged(double)),
00046             this, SLOT(rangeStartChanged(double)));
00047     
00048     grid->addWidget(new QLabel(tr(" to ")), 1, 2);
00049 
00050     m_rangeEnd = new QDoubleSpinBox;
00051     m_rangeEnd->setDecimals(4);
00052     m_rangeEnd->setMinimum(min);
00053     m_rangeEnd->setMaximum(max);
00054     m_rangeEnd->setSuffix(unit);
00055     grid->addWidget(m_rangeEnd, 1, 3);
00056     connect(m_rangeEnd, SIGNAL(valueChanged(double)),
00057             this, SLOT(rangeEndChanged(double)));
00058 
00059     QDialogButtonBox *bb = new QDialogButtonBox(QDialogButtonBox::Ok |
00060                                                 QDialogButtonBox::Cancel);
00061     grid->addWidget(bb, 2, 0, 1, 5);
00062     connect(bb, SIGNAL(accepted()), this, SLOT(accept()));
00063     connect(bb, SIGNAL(rejected()), this, SLOT(reject()));
00064 }
00065 
00066 RangeInputDialog::~RangeInputDialog()
00067 {
00068 }
00069 
00070 void
00071 RangeInputDialog::getRange(float &min, float &max)
00072 {
00073     min = float(m_rangeStart->value());
00074     max = float(m_rangeEnd->value());
00075 
00076     if (min > max) {
00077         float tmp = min;
00078         min = max;
00079         max = tmp;
00080     }
00081 }
00082 
00083 void
00084 RangeInputDialog::setRange(float start, float end)
00085 {
00086     if (start > end) {
00087         float tmp = start;
00088         start = end;
00089         end = tmp;
00090     }
00091 
00092     blockSignals(true);
00093     m_rangeStart->setValue(start);
00094     m_rangeEnd->setValue(end);
00095     blockSignals(false);
00096 }
00097 
00098 void
00099 RangeInputDialog::rangeStartChanged(double min)
00100 {
00101     double max = m_rangeEnd->value();
00102     if (min > max) {
00103         double tmp = min;
00104         min = max;
00105         max = tmp;
00106     }
00107     emit rangeChanged(float(min), float(max));
00108 }
00109 
00110 
00111 void
00112 RangeInputDialog::rangeEndChanged(double max)
00113 {
00114     double min = m_rangeStart->value();
00115     if (min > max) {
00116         double tmp = min;
00117         min = max;
00118         max = tmp;
00119     }
00120     emit rangeChanged(float(min), float(max));
00121 }
00122