RangeInputDialog.cpp
Go to the documentation of this file.
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
2 
3 /*
4  Sonic Visualiser
5  An audio file viewer and annotation editor.
6  Centre for Digital Music, Queen Mary, University of London.
7  This file copyright 2007 QMUL.
8 
9  This program is free software; you can redistribute it and/or
10  modify it under the terms of the GNU General Public License as
11  published by the Free Software Foundation; either version 2 of the
12  License, or (at your option) any later version. See the file
13  COPYING included with this distribution for more information.
14 */
15 
16 #include "RangeInputDialog.h"
17 
18 #include <QDoubleSpinBox>
19 #include <QGridLayout>
20 #include <QLabel>
21 #include <QHBoxLayout>
22 #include <QDialogButtonBox>
23 #include <QPushButton>
24 
25 RangeInputDialog::RangeInputDialog(QString title, QString message,
26  QString unit, float min, float max,
27  QWidget *parent) :
28  QDialog(parent)
29 {
30  QGridLayout *grid = new QGridLayout;
31  setLayout(grid);
32 
33  setWindowTitle(title);
34 
35  QLabel *messageLabel = new QLabel;
36  messageLabel->setText(message);
37  grid->addWidget(messageLabel, 0, 0, 1, 5);
38 
39  m_rangeStart = new QDoubleSpinBox;
40  m_rangeStart->setDecimals(4);
41  m_rangeStart->setMinimum(min);
42  m_rangeStart->setMaximum(max);
43  m_rangeStart->setSuffix(unit);
44  grid->addWidget(m_rangeStart, 1, 1);
45  connect(m_rangeStart, SIGNAL(valueChanged(double)),
46  this, SLOT(rangeStartChanged(double)));
47 
48  grid->addWidget(new QLabel(tr(" to ")), 1, 2);
49 
50  m_rangeEnd = new QDoubleSpinBox;
51  m_rangeEnd->setDecimals(4);
52  m_rangeEnd->setMinimum(min);
53  m_rangeEnd->setMaximum(max);
54  m_rangeEnd->setSuffix(unit);
55  grid->addWidget(m_rangeEnd, 1, 3);
56  connect(m_rangeEnd, SIGNAL(valueChanged(double)),
57  this, SLOT(rangeEndChanged(double)));
58 
59  QDialogButtonBox *bb = new QDialogButtonBox(QDialogButtonBox::Ok |
60  QDialogButtonBox::Cancel);
61  grid->addWidget(bb, 2, 0, 1, 5);
62  connect(bb, SIGNAL(accepted()), this, SLOT(accept()));
63  connect(bb, SIGNAL(rejected()), this, SLOT(reject()));
64 }
65 
67 {
68 }
69 
70 void
71 RangeInputDialog::getRange(float &min, float &max)
72 {
73  min = float(m_rangeStart->value());
74  max = float(m_rangeEnd->value());
75 
76  if (min > max) {
77  float tmp = min;
78  min = max;
79  max = tmp;
80  }
81 }
82 
83 void
84 RangeInputDialog::setRange(float start, float end)
85 {
86  if (start > end) {
87  float tmp = start;
88  start = end;
89  end = tmp;
90  }
91 
92  blockSignals(true);
93  m_rangeStart->setValue(start);
94  m_rangeEnd->setValue(end);
95  blockSignals(false);
96 }
97 
98 void
100 {
101  double max = m_rangeEnd->value();
102  if (min > max) {
103  double tmp = min;
104  min = max;
105  max = tmp;
106  }
107  emit rangeChanged(float(min), float(max));
108 }
109 
110 
111 void
113 {
114  double min = m_rangeStart->value();
115  if (min > max) {
116  double tmp = min;
117  min = max;
118  max = tmp;
119  }
120  emit rangeChanged(float(min), float(max));
121 }
122 
void getRange(float &start, float &end)
void rangeStartChanged(double)
void rangeChanged(float start, float end)
void rangeEndChanged(double)
QDoubleSpinBox * m_rangeEnd
RangeInputDialog(QString title, QString message, QString unit, float min, float max, QWidget *parent=0)
void setRange(float start, float end)
virtual ~RangeInputDialog()
QDoubleSpinBox * m_rangeStart