40 #include "base/RangeMapper.h" 49 #include <QMouseEvent> 50 #include <QPaintEvent> 51 #include <QInputDialog> 54 #include "base/Profiler.h" 69 #define AUDIO_DIAL_MIN (0.25 * M_PI) 70 #define AUDIO_DIAL_MAX (1.75 * M_PI) 71 #define AUDIO_DIAL_RANGE (AUDIO_DIAL_MAX - AUDIO_DIAL_MIN) 78 m_knobColor(Qt::black),
79 m_meterColor(Qt::white),
81 m_defaultMappedValue(0),
83 m_noMappedUpdate(false),
85 m_provideContextMenu(true),
86 m_lastContextMenu(nullptr),
87 m_rangeMapper(nullptr)
91 setContextMenuPolicy(Qt::CustomContextMenu);
92 connect(
this, SIGNAL(customContextMenuRequested(
const QPoint &)),
120 m->addAction(tr(
"&Edit..."),
this, SLOT(
edit()));
121 m->addAction(tr(
"&Reset to Default"),
this, SLOT(
setToDefault()));
123 m->popup(mapToGlobal(pos));
131 connect(
this, SIGNAL(valueChanged(
int)),
144 Profiler profiler(
"AudioDial::paintEvent");
150 (double(QDial::value() - QDial::minimum()) /
151 (double(QDial::maximum() - QDial::minimum()))));
152 int degrees = int(angle * 180.0 / M_PI);
154 int ns = notchSize();
155 int numTicks = 1 + (maximum() + ns - minimum()) / ns;
158 if (knobColor == Qt::black) {
159 knobColor = palette().window().color().lighter(150);
162 (knobColor.red() + knobColor.green() + knobColor.blue() <= 384);
166 meterColor = palette().mid().color();
169 meterColor = palette().text().color();
171 meterColor = palette().highlight().color();
175 QColor notchColor(palette().dark().color());
177 notchColor = palette().text().color();
180 int m_size = width() < height() ? width() : height();
182 int width = m_size - 2*scale;
185 paint.setRenderHint(QPainter::Antialiasing,
true);
186 paint.translate(1, 1);
194 pen.setColor(knobColor);
195 pen.setWidth(scale * 2);
196 pen.setCapStyle(Qt::FlatCap);
201 int indent = (int)(width * 0.15 + 1);
203 paint.drawEllipse(indent-1, indent-1, width-2*indent, width-2*indent);
205 pen.setWidth(3 * scale);
206 int pos = indent-1 + (width-2*indent) / 20;
207 int darkWidth = (width-2*indent) * 3 / 4;
216 paint.drawEllipse(pos, pos, darkWidth, darkWidth);
217 if (!--darkWidth)
break;
218 paint.drawEllipse(pos, pos, darkWidth, darkWidth);
219 if (!--darkWidth)
break;
220 paint.drawEllipse(pos, pos, darkWidth, darkWidth);
226 if ( notchesVisible() ) {
227 pen.setColor(notchColor);
230 for (
int i = 0; i < numTicks; ++i) {
242 pen.setWidth(indent);
247 int arcLen = -(degrees - 45) * 16;
248 if (arcLen == 0) arcLen = -16;
250 paint.drawArc(indent/2, indent/2,
251 width-indent, width-indent, (180 + 45) * 16, arcLen);
253 paint.setBrush(Qt::NoBrush);
262 int shadowAngle = -720;
264 c = knobColor.lighter();
266 c = knobColor.darker();
268 for (
int arc = 120; arc < 2880; arc += 240) {
271 paint.drawArc(indent, indent,
272 width-2*indent, width-2*indent, shadowAngle + arc, 240);
273 paint.drawArc(indent, indent,
274 width-2*indent, width-2*indent, shadowAngle - arc, 240);
285 c = palette().shadow().color();
286 for (
int i = 0; i < 5; ++i) {
289 int arc = i * 240 + 120;
290 paint.drawArc(scale/2, scale/2,
291 width-scale, width-scale, shadowAngle + arc, 240);
294 c = palette().shadow().color();
295 for (
int i = 0; i < 12; ++i) {
298 int arc = i * 240 + 120;
299 paint.drawArc(scale/2, scale/2,
300 width-scale, width-scale, shadowAngle - arc, 240);
307 pen.setColor(palette().mid().color());
309 pen.setColor(palette().shadow().color());
313 for (
int i = 0; i < numTicks; ++i) {
314 if (i != 0 && i != numTicks - 1)
continue;
323 double hyp = double(width) / 2.0;
324 double len = hyp - indent;
330 double x = hyp - len * sin(angle);
331 double y = hyp + len * cos(angle);
342 pen.setWidth(scale * 2);
344 paint.drawLine(
int(x0),
int(y0),
int(x),
int(y));
351 double angle,
int size,
bool internal)
353 double hyp = double(size) / 2.0;
354 double x0 = hyp - (hyp - 1) * sin(angle);
355 double y0 = hyp + (hyp - 1) * cos(angle);
361 double len = hyp / 4;
362 double x1 = hyp - (hyp - len) * sin(angle);
363 double y1 = hyp + (hyp - len) * cos(angle);
365 paint.drawLine(
int(x0),
int(y0),
int(x1),
int(y1));
369 double len = hyp / 4;
370 double x1 = hyp - (hyp + len) * sin(angle);
371 double y1 = hyp + (hyp + len) * cos(angle);
373 paint.drawLine(
int(x0),
int(y0),
int(x1),
int(y1));
408 QDial::setValue(value);
423 int newPosition =
m_rangeMapper->getPositionForValue(mappedValue);
427 SVDEBUG <<
"AudioDial::setMappedValue(" << mappedValue <<
"): new position is " << newPosition << endl;
428 if (newPosition != value()) {
430 }
else if (changed) {
431 emit valueChanged(newPosition);
475 QString name = objectName();
483 text = tr(
"%1: %2").arg(name).arg(label);
493 text = tr(
"%1: %2%3").arg(name).arg(
m_mappedValue).arg(unit);
516 if (dv < minimum()) dv = minimum();
517 if (dv > maximum()) dv = maximum();
525 QDial::mousePressEvent(mouseEvent);
526 }
else if (mouseEvent->button() == Qt::MidButton ||
527 ((mouseEvent->button() == Qt::LeftButton) &&
528 (mouseEvent->modifiers() & Qt::ControlModifier))) {
530 }
else if (mouseEvent->button() == Qt::LeftButton) {
542 QDial::mouseDoubleClickEvent(mouseEvent);
543 }
else if (mouseEvent->button() != Qt::LeftButton) {
568 if (objectName() !=
"") {
570 text = tr(
"New value for %1, from %2 to %3 %4:")
571 .arg(objectName()).arg(min).arg(max).arg(unit);
573 text = tr(
"New value for %1, from %2 to %3:")
574 .arg(objectName()).arg(min).arg(max);
578 text = tr(
"Enter a new value from %1 to %2 %3:")
579 .arg(min).arg(max).arg(unit);
581 text = tr(
"Enter a new value from %1 to %2:")
586 double newValue = QInputDialog::getDouble
588 tr(
"Enter new value"),
602 int newPosition = QInputDialog::getInt
604 tr(
"Enter new value"),
605 tr(
"Enter a new value from %1 to %2:")
606 .arg(minimum()).arg(maximum()),
607 value(), minimum(), maximum(), singleStep(), &ok);
619 QDial::mouseMoveEvent(mouseEvent);
621 const QPoint& posMouse = mouseEvent->pos();
622 int v = QDial::value()
625 if (v > QDial::maximum())
626 v = QDial::maximum();
628 if (v < QDial::minimum())
629 v = QDial::minimum();
639 QDial::mouseReleaseEvent(mouseEvent);
648 QDial::enterEvent(e);
655 QDial::enterEvent(e);
void setMappedValue(double mappedValue)
#define AUDIO_DIAL_MIN
A rotary dial widget.
void mouseMoveEvent(QMouseEvent *pMouseEvent) override
void mouseDoubleClickEvent(QMouseEvent *pMouseEvent) override
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)...
void setDefaultMappedValue(double mappedValue)
void mouseReleaseEvent(QMouseEvent *pMouseEvent) override
void enterEvent(QEvent *) override
void setMouseDial(bool mouseDial)
Specify that the dial should respond to radial mouse movements in the same way as QDial...
void setProvideContextMenu(bool provide)
void mousePressEvent(QMouseEvent *pMouseEvent) override
bool m_provideContextMenu
double mappedValue() const
QMenu * m_lastContextMenu
void leaveEvent(QEvent *) override
void paintEvent(QPaintEvent *) override
RangeMapper * m_rangeMapper
AudioDial(QWidget *parent=0)
void setKnobColor(const QColor &color)
Set the colour of the knob.
void setRangeMapper(RangeMapper *mapper)
void contextMenuRequested(const QPoint &)
void drawTick(QPainter &paint, double angle, int size, bool internal)
double m_defaultMappedValue
void updateMappedValue(int value)
void setShowToolTip(bool show)