18 #include "base/RangeMapper.h" 19 #include "base/Profiler.h" 21 #include <QMouseEvent> 22 #include <QPaintEvent> 23 #include <QWheelEvent> 24 #include <QInputDialog> 26 #include <QPainterPath> 42 m_noMappedUpdate(false),
44 m_orientation(orientation),
50 m_clickRotation(m_rotation),
52 m_provideContextMenu(true),
53 m_lastContextMenu(nullptr),
54 m_rangeMapper(nullptr)
56 setContextMenuPolicy(Qt::CustomContextMenu);
57 connect(
this, SIGNAL(customContextMenuRequested(
const QPoint &)),
84 m->addAction(tr(
"&Edit..."),
this, SLOT(
edit()));
85 m->addAction(tr(
"&Reset to Default"),
this, SLOT(
resetToDefault()));
87 m->popup(mapToGlobal(pos));
124 if (
m_min == min)
return;
144 if (
m_max == max)
return;
179 int newValue =
m_rangeMapper->getPositionForValue(mappedValue);
192 int v = int(mappedValue);
274 QString name = objectName();
281 text = tr(
"%1: %2%3").arg(name).arg(mappedValue).arg(unit);
283 text = tr(
"%2%3").arg(mappedValue).arg(unit);
298 int step = int(lrintf(
m_speed));
299 if (step == 0) step = 1;
361 if (e->button() == Qt::MidButton ||
362 ((e->button() == Qt::LeftButton) &&
363 (e->modifiers() & Qt::ControlModifier))) {
365 }
else if (e->button() == Qt::LeftButton) {
377 if (mouseEvent->button() != Qt::LeftButton) {
403 if (objectName() !=
"") {
405 text = tr(
"New value for %1, from %2 to %3 %4:")
406 .arg(objectName()).arg(min).arg(max).arg(unit);
408 text = tr(
"New value for %1, from %2 to %3:")
409 .arg(objectName()).arg(min).arg(max);
413 text = tr(
"Enter a new value from %1 to %2 %3:")
414 .arg(min).arg(max).arg(unit);
416 text = tr(
"Enter a new value from %1 to %2:")
421 double newValue = QInputDialog::getDouble
423 tr(
"Enter new value"),
437 int newValue = QInputDialog::getInt
439 tr(
"Enter new value"),
440 tr(
"Enter a new value from %1 to %2:")
463 if (rotation < 0.f) rotation = 0.f;
464 if (rotation > 1.f) rotation = 1.f;
469 m_rotation = rotation;
470 }
else if (fabsf(rotation - m_rotation) > 0.001) {
471 m_rotation = rotation;
503 Profiler profiler(
"Thumbwheel::paintEvent");
506 QPainter paint(
this);
511 Profiler profiler2(
"Thumbwheel::paintEvent (no cache)");
513 QSize imageSize = size() * devicePixelRatio();
514 m_cache = QImage(imageSize, QImage::Format_ARGB32);
523 subclip = QRect(bw, bw+1, w - bw*2, h - bw*2 - 2);
525 subclip = QRect(bw+1, bw, w - bw*2 - 2, h - bw*2);
529 paint.setClipRect(
m_cache.rect());
530 paint.fillRect(subclip, palette().window().color());
532 paint.setRenderHint(QPainter::Antialiasing,
true);
540 for (
int i = bw-1; i >= 0; --i) {
542 int grey = (i + 1) * (256 / (bw + 1));
543 QColor fc = QColor(grey, grey, grey);
549 path.moveTo(w0 + i, h0 + i + 2);
550 path.quadTo(w/2, i * 1.25, w1 - i, h0 + i + 2);
551 path.lineTo(w1 - i, h1 - i - 2);
552 path.quadTo(w/2, h - i * 1.25, w0 + i, h1 - i - 2);
555 path.moveTo(w0 + i + 2, h0 + i);
556 path.quadTo(i * 1.25, h/2, w0 + i + 2, h1 - i);
557 path.lineTo(w1 - i - 2, h1 - i);
558 path.quadTo(w - i * 1.25, h/2, w1 - i - 2, h0 + i);
562 paint.drawPath(path);
565 paint.setClipRect(subclip);
577 int radius = int(ww / 2 + 2);
579 for (
int i = 0; i < notches; ++i) {
581 double a0 = (2.0 * M_PI * i) / notches + radians;
582 double a1 = a0 + M_PI / (notches * 2);
583 double a2 = (2.0 * M_PI * (i + 1)) / notches + radians;
585 double depth = cos((a0 + a2) / 2);
586 if (depth < 0)
continue;
588 double x0 = radius * sin(a0) + ww/2;
589 double x1 = radius * sin(a1) + ww/2;
590 double x2 = radius * sin(a2) + ww/2;
591 if (x2 < 0 || x0 > ww)
continue;
594 if (x2 > ww) x2 = ww;
600 int grey = int(lrint(120 * depth));
602 QColor fc = QColor(grey, grey, grey);
603 QColor oc = palette().highlight().color();
612 if (i >= notches / 4) {
613 prop = double(notches - (((i -
double(notches) / 4.f) * 4.f) / 3.f))
620 paint.drawRect(QRectF(x1, h - (h - bw*2) * prop - bw,
623 paint.drawRect(QRectF(bw, x1, (w - bw*2) * prop, x2 - x1));
628 paint.setBrush(palette().window().color());
631 paint.drawRect(QRectF(x0, bw, x1 - x0, h - bw*2));
633 paint.drawRect(QRectF(bw, x0, w - bw*2, x1 - x0));
637 QPainter paint2(
this);
645 return QSize(80, 12);
647 return QSize(12, 80);
void setDefaultValue(int deft)
int getMinimumValue() const
void paintEvent(QPaintEvent *e) override
bool m_provideContextMenu
void contextMenuRequested(const QPoint &)
void setRangeMapper(RangeMapper *mapper)
bool getShowScale() const
Thumbwheel(Qt::Orientation orientation, QWidget *parent=0)
double getMappedValue() const
void enterEvent(QEvent *) override
void setShowScale(bool show)
void mouseDoubleClickEvent(QMouseEvent *e) override
void setMappedValue(double mappedValue)
void mouseReleaseEvent(QMouseEvent *e) override
void setMinimumValue(int min)
QSize sizeHint() const override
RangeMapper * m_rangeMapper
void setMaximumValue(int max)
WheelCounter m_wheelCounter
void setTracking(bool tracking)
void updateMappedValue(int value)
void mousePressEvent(QMouseEvent *e) override
QMenu * m_lastContextMenu
void mouseMoveEvent(QMouseEvent *e) override
void setSpeed(float speed)
Qt::Orientation m_orientation
void leaveEvent(QEvent *) override
int getDefaultValue() const
int count(QWheelEvent *e)
void setProvideContextMenu(bool provide)
int getMaximumValue() const
void wheelEvent(QWheelEvent *e) override
void setShowToolTip(bool show)