Mercurial > hg > svgui
comparison widgets/AudioDial.cpp @ 34:c43f2c4f66f2
* As previous commit
author | Chris Cannam |
---|---|
date | Fri, 17 Feb 2006 18:11:08 +0000 |
parents | c53b949ef142 |
children | 01ab51f72e84 |
comparison
equal
deleted
inserted
replaced
33:651e4e868bcc | 34:c43f2c4f66f2 |
---|---|
39 #include <QPainter> | 39 #include <QPainter> |
40 #include <QPixmap> | 40 #include <QPixmap> |
41 #include <QColormap> | 41 #include <QColormap> |
42 #include <QMouseEvent> | 42 #include <QMouseEvent> |
43 #include <QPaintEvent> | 43 #include <QPaintEvent> |
44 #include <QInputDialog> | |
44 | 45 |
45 using std::endl; | 46 using std::endl; |
46 using std::cerr; | 47 using std::cerr; |
47 | 48 |
48 | 49 |
59 | 60 |
60 | 61 |
61 // Constructor. | 62 // Constructor. |
62 AudioDial::AudioDial(QWidget *parent) : | 63 AudioDial::AudioDial(QWidget *parent) : |
63 QDial(parent), | 64 QDial(parent), |
64 m_knobColor(Qt::black), m_meterColor(Qt::white) | 65 m_knobColor(Qt::black), m_meterColor(Qt::white), |
66 m_defaultValue(0) | |
65 { | 67 { |
66 m_mouseDial = false; | 68 m_mouseDial = false; |
67 m_mousePressed = false; | 69 m_mousePressed = false; |
68 } | 70 } |
69 | 71 |
137 ++pos; --darkWidth; | 139 ++pos; --darkWidth; |
138 } | 140 } |
139 | 141 |
140 // Tick notches... | 142 // Tick notches... |
141 | 143 |
142 if ( true/* notchesVisible() */) { | 144 if ( notchesVisible() ) { |
143 // std::cerr << "Notches visible" << std::endl; | 145 // std::cerr << "Notches visible" << std::endl; |
144 pen.setColor(palette().dark().color()); | 146 pen.setColor(palette().dark().color()); |
145 pen.setWidth(scale); | 147 pen.setWidth(scale); |
146 paint.setPen(pen); | 148 paint.setPen(pen); |
147 for (int i = 0; i < numTicks; ++i) { | 149 for (int i = 0; i < numTicks; ++i) { |
291 { | 293 { |
292 m_mouseDial = mouseDial; | 294 m_mouseDial = mouseDial; |
293 } | 295 } |
294 | 296 |
295 | 297 |
298 void AudioDial::setDefaultValue(int defaultValue) | |
299 { | |
300 m_defaultValue = defaultValue; | |
301 } | |
302 | |
303 | |
296 // Alternate mouse behavior event handlers. | 304 // Alternate mouse behavior event handlers. |
297 void AudioDial::mousePressEvent(QMouseEvent *mouseEvent) | 305 void AudioDial::mousePressEvent(QMouseEvent *mouseEvent) |
298 { | 306 { |
299 if (m_mouseDial) { | 307 if (m_mouseDial) { |
300 QDial::mousePressEvent(mouseEvent); | 308 QDial::mousePressEvent(mouseEvent); |
301 } else if (mouseEvent->button() == Qt::LeftButton) { | 309 } else if (mouseEvent->button() == Qt::LeftButton) { |
302 m_mousePressed = true; | 310 m_mousePressed = true; |
303 m_posMouse = mouseEvent->pos(); | 311 m_posMouse = mouseEvent->pos(); |
312 } else if (mouseEvent->button() == Qt::MidButton) { | |
313 int dv = m_defaultValue; | |
314 if (dv < minimum()) dv = minimum(); | |
315 if (dv > maximum()) dv = maximum(); | |
316 setValue(m_defaultValue); | |
317 } | |
318 } | |
319 | |
320 | |
321 void AudioDial::mouseDoubleClickEvent(QMouseEvent *mouseEvent) | |
322 { | |
323 if (m_mouseDial) { | |
324 QDial::mouseDoubleClickEvent(mouseEvent); | |
325 } else if (mouseEvent->button() == Qt::LeftButton) { | |
326 bool ok = false; | |
327 int newValue = QInputDialog::getInteger | |
328 (this, | |
329 tr("Enter new value"), | |
330 tr("Select a new value in the range %1 to %2:") | |
331 .arg(minimum()).arg(maximum()), | |
332 value(), minimum(), maximum(), pageStep(), &ok); | |
333 if (ok) { | |
334 setValue(newValue); | |
335 } | |
304 } | 336 } |
305 } | 337 } |
306 | 338 |
307 | 339 |
308 void AudioDial::mouseMoveEvent(QMouseEvent *mouseEvent) | 340 void AudioDial::mouseMoveEvent(QMouseEvent *mouseEvent) |