comparison widgets/RangeInputDialog.cpp @ 188:dd573e090eed

* Add range input dialog * Make Panner support middle-click/ctrl-left-click to reset and emit doubleClicked when doubleClicked instead of resetting * Use range input dialog to enter new values for panner on double-click
author Chris Cannam
date Fri, 12 Jan 2007 21:52:56 +0000
parents
children 4edaff85875d
comparison
equal deleted inserted replaced
187:e7cf6044c2a0 188:dd573e090eed
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 <QPushButton>
23
24 RangeInputDialog::RangeInputDialog(QString title, QString message,
25 QString unit, float min, float max,
26 QWidget *parent) :
27 QDialog(parent)
28 {
29 QGridLayout *grid = new QGridLayout;
30 setLayout(grid);
31
32 setWindowTitle(title);
33
34 QLabel *messageLabel = new QLabel;
35 messageLabel->setText(message);
36 grid->addWidget(messageLabel, 0, 0, 1, 5);
37
38 m_rangeStart = new QDoubleSpinBox;
39 m_rangeStart->setDecimals(4);
40 m_rangeStart->setMinimum(min);
41 m_rangeStart->setMaximum(max);
42 m_rangeStart->setSuffix(unit);
43 grid->addWidget(m_rangeStart, 1, 1);
44 connect(m_rangeStart, SIGNAL(valueChanged(double)),
45 this, SLOT(rangeStartChanged(double)));
46
47 grid->addWidget(new QLabel(tr(" to ")), 1, 2);
48
49 m_rangeEnd = new QDoubleSpinBox;
50 m_rangeEnd->setDecimals(4);
51 m_rangeEnd->setMinimum(min);
52 m_rangeEnd->setMaximum(max);
53 m_rangeEnd->setSuffix(unit);
54 grid->addWidget(m_rangeEnd, 1, 3);
55 connect(m_rangeEnd, SIGNAL(valueChanged(double)),
56 this, SLOT(rangeEndChanged(double)));
57
58 QHBoxLayout *hbox = new QHBoxLayout;
59 grid->addLayout(hbox, 2, 0, 1, 5);
60
61 QPushButton *ok = new QPushButton(tr("OK"), this);
62 ok->setDefault(true);
63
64 QPushButton *cancel = new QPushButton(tr("Cancel"), this);
65
66 QSize bs = ok->sizeHint().expandedTo(cancel->sizeHint());
67 ok->setFixedSize(bs);
68 cancel->setFixedSize(bs);
69
70 hbox->addStretch();
71 hbox->addWidget(ok);
72 hbox->addWidget(cancel);
73
74 QObject::connect(ok, SIGNAL(clicked()), this, SLOT(accept()));
75 QObject::connect(cancel, SIGNAL(clicked()), this, SLOT(reject()));
76 }
77
78 RangeInputDialog::~RangeInputDialog()
79 {
80 }
81
82 void
83 RangeInputDialog::getRange(float &min, float &max)
84 {
85 min = float(m_rangeStart->value());
86 max = float(m_rangeEnd->value());
87
88 if (min > max) {
89 float tmp = min;
90 min = max;
91 max = tmp;
92 }
93 }
94
95 void
96 RangeInputDialog::setRange(float start, float end)
97 {
98 if (start > end) {
99 float tmp = start;
100 start = end;
101 end = tmp;
102 }
103
104 blockSignals(true);
105 m_rangeStart->setValue(start);
106 m_rangeEnd->setValue(end);
107 blockSignals(false);
108 }
109
110 void
111 RangeInputDialog::rangeStartChanged(double min)
112 {
113 double max = m_rangeEnd->value();
114 if (min > max) {
115 double tmp = min;
116 min = max;
117 max = tmp;
118 }
119 emit rangeChanged(float(min), float(max));
120 }
121
122
123 void
124 RangeInputDialog::rangeEndChanged(double max)
125 {
126 double min = m_rangeStart->value();
127 if (min > max) {
128 double tmp = min;
129 min = max;
130 max = tmp;
131 }
132 emit rangeChanged(float(min), float(max));
133 }
134