comparison widgets/Fader.cpp @ 187:e7cf6044c2a0

* better icon * support range mappers in thumbwheel * supply range mapper for vertical zoom from spectrogram * fix bug in fftmodel for scaled ffts * make the various widgets all respond to double-click for edit, middle-click for reset, ctrl-left-click for reset
author Chris Cannam
date Fri, 12 Jan 2007 14:49:18 +0000
parents d1e5cd4574a0
children 5b7472db612b
comparison
equal deleted inserted replaced
186:8dd247c4c5f1 187:e7cf6044c2a0
51 #include <QMouseEvent> 51 #include <QMouseEvent>
52 #include <QPixmap> 52 #include <QPixmap>
53 #include <QWheelEvent> 53 #include <QWheelEvent>
54 #include <QPaintEvent> 54 #include <QPaintEvent>
55 #include <QPainter> 55 #include <QPainter>
56 #include <QInputDialog>
57
58 #include <iostream>
56 59
57 Fader::Fader(QWidget *parent, bool withoutKnob) : 60 Fader::Fader(QWidget *parent, bool withoutKnob) :
58 QWidget(parent), 61 QWidget(parent),
59 m_withoutKnob(withoutKnob), 62 m_withoutKnob(withoutKnob),
60 m_value(1.0), 63 m_value(1.0),
61 m_peakLeft(0.0), 64 m_peakLeft(0.0),
62 m_peakRight(0.0) 65 m_peakRight(0.0),
66 m_mousePressed(false)
63 { 67 {
64 setMinimumSize(116, 23); 68 setMinimumSize(116, 23);
65 setMaximumSize(116, 23); 69 setMaximumSize(116, 23);
66 resize(116, 23); 70 resize(116, 23);
67 71
97 101
98 void 102 void
99 Fader::mouseMoveEvent(QMouseEvent *ev) 103 Fader::mouseMoveEvent(QMouseEvent *ev)
100 { 104 {
101 if (ev->button() == Qt::MidButton) { 105 if (ev->button() == Qt::MidButton) {
106 setValue(1.0);
107 emit valueChanged(1.0);
108 update();
102 ev->accept(); 109 ev->accept();
103 return; 110 return;
104 } 111 }
105 112 if (!m_mousePressed) return;
106 int x = ev->x() - 6; 113
107 const int max_x = 116 - 12; 114 int x = ev->x();
108 115 int diff = x - m_mousePressX;
109 int value = x; 116 if (diff == 0) return;
110 117
111 if (value > max_x) { 118 int vx = AudioLevel::multiplier_to_fader
112 value = max_x; 119 (m_mousePressValue, getMaxX(), AudioLevel::LongFader);
113 } else if (value < 0) { 120
114 value = 0; 121 vx += diff;
115 } 122
116 123 if (vx > getMaxX()) vx = getMaxX();
117 // float fval = float(value) / float(max_x); 124 if (vx < 0) vx = 0;
125
118 float fval = AudioLevel::fader_to_multiplier 126 float fval = AudioLevel::fader_to_multiplier
119 (value, max_x, AudioLevel::LongFader); 127 (vx, getMaxX(), AudioLevel::LongFader);
120 128
121 setValue(fval); 129 setValue(fval);
122 emit valueChanged(fval); 130 emit valueChanged(fval);
123 131 ev->accept();
124 update();
125 } 132 }
126 133
127 134
128 void 135 void
129 Fader::mouseReleaseEvent(QMouseEvent *ev) 136 Fader::mouseReleaseEvent(QMouseEvent *ev)
130 { 137 {
131 mouseMoveEvent(ev); 138 if (m_mousePressed) {
132 } 139 mouseMoveEvent(ev);
133 140 m_mousePressed = false;
141 }
142 }
134 143
135 void 144 void
136 Fader::mouseDoubleClickEvent(QMouseEvent *) 145 Fader::mouseDoubleClickEvent(QMouseEvent *)
137 { 146 {
138 setValue(1.0); 147 bool ok = false;
139 emit valueChanged(1.0); 148 float min = AudioLevel::fader_to_dB
140 update(); 149 (0, getMaxX(), AudioLevel::LongFader);
150 float max = AudioLevel::fader_to_dB
151 (getMaxX(), getMaxX(), AudioLevel::LongFader);
152 float deft = AudioLevel::multiplier_to_dB(m_value);
153
154 float dB = QInputDialog::getDouble
155 (this,
156 tr("Enter new fader level"),
157 tr("New fader level, from %1 to %2 dBFS:").arg(min).arg(max),
158 deft, min, max, 3, &ok);
159
160 if (ok) {
161 float value = AudioLevel::dB_to_multiplier(dB);
162 setValue(value);
163 emit valueChanged(value);
164 update();
165 }
141 } 166 }
142 167
143 void 168 void
144 Fader::mousePressEvent(QMouseEvent *ev) 169 Fader::mousePressEvent(QMouseEvent *ev)
145 { 170 {
146 if (ev->button() == Qt::MidButton) { 171 if (ev->button() == Qt::MidButton ||
172 ((ev->button() == Qt::LeftButton) &&
173 (ev->modifiers() & Qt::ControlModifier))) {
147 setValue(1.0); 174 setValue(1.0);
148 emit valueChanged(1.0); 175 emit valueChanged(1.0);
149 update(); 176 update();
150 return; 177 return;
151 } 178 }
152 179
153 int x = ev->x() - 6; 180 if (ev->button() != Qt::LeftButton) return;
154 const int max_x = 116 - 12; 181 m_mousePressed = true;
155 182 m_mousePressX = ev->x();
156 int value = x; 183 m_mousePressValue = getValue();
157
158 if (value > max_x) {
159 value = max_x;
160 } else if (value < 0) {
161 value = 0;
162 }
163
164 float fval = AudioLevel::fader_to_multiplier
165 (value, max_x, AudioLevel::LongFader);
166
167 setValue(fval);
168 emit valueChanged(fval);
169
170 update();
171 } 184 }
172 185
173 186
174 void 187 void
175 Fader::wheelEvent(QWheelEvent *ev) 188 Fader::wheelEvent(QWheelEvent *ev)
201 } 214 }
202 215
203 if (m_value != v) { 216 if (m_value != v) {
204 m_value = v; 217 m_value = v;
205 float db = AudioLevel::multiplier_to_dB(m_value); 218 float db = AudioLevel::multiplier_to_dB(m_value);
219 QString text;
206 if (db <= AudioLevel::DB_FLOOR) { 220 if (db <= AudioLevel::DB_FLOOR) {
207 setToolTip(tr("Level: Off")); 221 text = tr("Level: Off");
208 } else { 222 } else {
209 setToolTip(tr("Level: %1%2.%3%4 dB") 223 text = tr("Level: %1%2.%3%4 dB")
210 .arg(db < 0.0 ? "-" : "") 224 .arg(db < 0.0 ? "-" : "")
211 .arg(abs(int(db))) 225 .arg(abs(int(db)))
212 .arg(abs(int(db * 10.0) % 10)) 226 .arg(abs(int(db * 10.0) % 10))
213 .arg(abs(int(db * 100.0) % 10))); 227 .arg(abs(int(db * 100.0) % 10));
214 } 228 }
229 std::cerr << "Fader: setting tooltip to \"" << text.toStdString() << "\"" << std::endl;
230 QWidget::setToolTip(text);
215 update(); 231 update();
216 } 232 }
217 } 233 }
218 234
219 235
279 clipping ? m_clip : m_knob, 295 clipping ? m_clip : m_knob,
280 QRect(0, 0, knob_width, knob_height)); 296 QRect(0, 0, knob_width, knob_height));
281 } 297 }
282 } 298 }
283 299
284 300 int
301 Fader::getMaxX() const
302 {
303 return 116 - 12;
304 }