40 #include "base/RangeMapper.h" 49 #include <QMouseEvent> 50 #include <QPaintEvent> 51 #include <QInputDialog> 53 #include "base/Profiler.h" 66 #define AUDIO_DIAL_MIN (0.25 * M_PI) 67 #define AUDIO_DIAL_MAX (1.75 * M_PI) 68 #define AUDIO_DIAL_RANGE (AUDIO_DIAL_MAX - AUDIO_DIAL_MIN) 77 m_knobColor(Qt::black),
78 m_meterColor(Qt::white),
80 m_defaultMappedValue(0),
82 m_noMappedUpdate(false),
107 connect(
this, SIGNAL(valueChanged(
int)),
120 Profiler profiler(
"AudioDial::paintEvent");
126 (float(QDial::value() - QDial::minimum()) /
127 (float(QDial::maximum() - QDial::minimum()))));
128 int degrees = int(angle * 180.0 / M_PI);
130 int ns = notchSize();
131 int numTicks = 1 + (maximum() + ns - minimum()) / ns;
143 int m_size = width() < height() ? width() : height();
145 int width = m_size - 2*scale;
148 paint.setRenderHint(QPainter::Antialiasing,
true);
149 paint.translate(1, 1);
158 pen.setWidth(scale * 2);
159 pen.setCapStyle(Qt::FlatCap);
164 int indent = (int)(width * 0.15 + 1);
166 paint.drawEllipse(indent-1, indent-1, width-2*indent, width-2*indent);
168 pen.setWidth(3 * scale);
169 int pos = indent-1 + (width-2*indent) / 20;
170 int darkWidth = (width-2*indent) * 3 / 4;
175 paint.drawEllipse(pos, pos, darkWidth, darkWidth);
176 if (!--darkWidth)
break;
177 paint.drawEllipse(pos, pos, darkWidth, darkWidth);
178 if (!--darkWidth)
break;
179 paint.drawEllipse(pos, pos, darkWidth, darkWidth);
185 if ( notchesVisible() ) {
187 pen.setColor(palette().dark().color());
190 for (
int i = 0; i < numTicks; ++i) {
202 pen.setWidth(indent);
207 int arcLen = -(degrees - 45) * 16;
208 if (arcLen == 0) arcLen = -16;
210 paint.drawArc(indent/2, indent/2,
211 width-indent, width-indent, (180 + 45) * 16, arcLen);
213 paint.setBrush(Qt::NoBrush);
222 int shadowAngle = -720;
224 for (
int arc = 120; arc < 2880; arc += 240) {
227 paint.drawArc(indent, indent,
228 width-2*indent, width-2*indent, shadowAngle + arc, 240);
229 paint.drawArc(indent, indent,
230 width-2*indent, width-2*indent, shadowAngle - arc, 240);
237 c = palette().shadow().color();
238 for (
int i = 0; i < 5; ++i) {
241 int arc = i * 240 + 120;
242 paint.drawArc(scale/2, scale/2,
243 width-scale, width-scale, shadowAngle + arc, 240);
246 c = palette().shadow().color();
247 for (
int i = 0; i < 12; ++i) {
250 int arc = i * 240 + 120;
251 paint.drawArc(scale/2, scale/2,
252 width-scale, width-scale, shadowAngle - arc, 240);
258 pen.setColor(palette().shadow().color());
261 for (
int i = 0; i < numTicks; ++i) {
262 if (i != 0 && i != numTicks - 1)
continue;
271 float hyp = float(width) / 2.0;
272 float len = hyp - indent;
278 float x = hyp - len * sin(angle);
279 float y = hyp + len * cos(angle);
281 c = palette().dark().color();
282 pen.setColor(isEnabled() ? c.dark(130) : c);
283 pen.setWidth(scale * 2);
285 paint.drawLine(
int(x0),
int(y0),
int(x),
int(y));
292 float angle,
int size,
bool internal)
294 float hyp = float(size) / 2.0;
295 float x0 = hyp - (hyp - 1) * sin(angle);
296 float y0 = hyp + (hyp - 1) * cos(angle);
303 float x1 = hyp - (hyp - len) * sin(angle);
304 float y1 = hyp + (hyp - len) * cos(angle);
306 paint.drawLine(
int(x0),
int(y0),
int(x1),
int(y1));
311 float x1 = hyp - (hyp + len) * sin(angle);
312 float y1 = hyp + (hyp + len) * cos(angle);
314 paint.drawLine(
int(x0),
int(y0),
int(x1),
int(y1));
349 QDial::setValue(value);
368 SVDEBUG <<
"AudioDial::setMappedValue(" <<
mappedValue <<
"): new position is " << newPosition << endl;
369 if (newPosition != value()) {
371 }
else if (changed) {
372 emit valueChanged(newPosition);
411 QString name = objectName();
416 text = tr(
"%1: %2%3").arg(name).arg(
m_mappedValue).arg(unit);
432 if (dv < minimum()) dv = minimum();
433 if (dv > maximum()) dv = maximum();
441 QDial::mousePressEvent(mouseEvent);
442 }
else if (mouseEvent->button() == Qt::MidButton ||
443 ((mouseEvent->button() == Qt::LeftButton) &&
444 (mouseEvent->modifiers() & Qt::ControlModifier))) {
446 }
else if (mouseEvent->button() == Qt::LeftButton) {
458 QDial::mouseDoubleClickEvent(mouseEvent);
459 }
else if (mouseEvent->button() != Qt::LeftButton) {
479 if (objectName() !=
"") {
481 text = tr(
"New value for %1, from %2 to %3 %4:")
482 .arg(objectName()).arg(min).arg(max).arg(unit);
484 text = tr(
"New value for %1, from %2 to %3:")
485 .arg(objectName()).arg(min).arg(max);
489 text = tr(
"Enter a new value from %1 to %2 %3:")
490 .arg(min).arg(max).arg(unit);
492 text = tr(
"Enter a new value from %1 to %2:")
497 float newValue = QInputDialog::getDouble
499 tr(
"Enter new value"),
513 int newPosition = QInputDialog::getInt
515 tr(
"Enter new value"),
516 tr(
"Enter a new value from %1 to %2:")
517 .arg(minimum()).arg(maximum()),
518 value(), minimum(), maximum(), singleStep(), &ok);
530 QDial::mouseMoveEvent(mouseEvent);
532 const QPoint& posMouse = mouseEvent->pos();
533 int v = QDial::value()
536 if (v > QDial::maximum())
537 v = QDial::maximum();
539 if (v < QDial::minimum())
540 v = QDial::minimum();
550 QDial::mouseReleaseEvent(mouseEvent);
559 QDial::enterEvent(e);
566 QDial::enterEvent(e);
#define AUDIO_DIAL_MIN
A rotary dial widget.
void setDefaultValue(int defaultValue)
void setMeterColor(const QColor &color)
Set the colour of the meter (the highlighted area around the knob that shows the current value).
float mappedValue() const
void setMappedValue(float mappedValue)
void setDefaultMappedValue(float mappedValue)
void setMouseDial(bool mouseDial)
Specify that the dial should respond to radial mouse movements in the same way as QDial.
virtual void enterEvent(QEvent *)
virtual void mouseDoubleClickEvent(QMouseEvent *pMouseEvent)
float m_defaultMappedValue
void drawTick(QPainter &paint, float angle, int size, bool internal)
RangeMapper * m_rangeMapper
AudioDial(QWidget *parent=0)
void setKnobColor(const QColor &color)
Set the colour of the knob.
void setRangeMapper(RangeMapper *mapper)
virtual void paintEvent(QPaintEvent *)
virtual void mouseReleaseEvent(QMouseEvent *pMouseEvent)
virtual void mousePressEvent(QMouseEvent *pMouseEvent)
void updateMappedValue(int value)
virtual void leaveEvent(QEvent *)
virtual void mouseMoveEvent(QMouseEvent *pMouseEvent)
void setShowToolTip(bool show)