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> 39 m_noMappedUpdate(false),
41 m_orientation(orientation),
47 m_clickRotation(m_rotation),
86 if (
m_min == min)
return;
106 if (
m_max == max)
return;
141 int newValue =
m_rangeMapper->getPositionForValue(mappedValue);
154 int v = int(mappedValue);
186 if (isVisible()) update();
227 QString name = objectName();
232 text = tr(
"%1: %2%3").arg(name).arg(
m_mappedValue).arg(unit);
244 if (step == 0) step = 1;
306 if (e->button() == Qt::MidButton ||
307 ((e->button() == Qt::LeftButton) &&
308 (e->modifiers() & Qt::ControlModifier))) {
310 }
else if (e->button() == Qt::LeftButton) {
322 if (mouseEvent->button() != Qt::LeftButton) {
342 if (objectName() !=
"") {
344 text = tr(
"New value for %1, from %2 to %3 %4:")
345 .arg(objectName()).arg(min).arg(max).arg(unit);
347 text = tr(
"New value for %1, from %2 to %3:")
348 .arg(objectName()).arg(min).arg(max);
352 text = tr(
"Enter a new value from %1 to %2 %3:")
353 .arg(min).arg(max).arg(unit);
355 text = tr(
"Enter a new value from %1 to %2:")
360 float newValue = QInputDialog::getDouble
362 tr(
"Enter new value"),
376 int newValue = QInputDialog::getInt
378 tr(
"Enter new value"),
379 tr(
"Enter a new value from %1 to %2:")
402 if (rotation < 0.f) rotation = 0.f;
403 if (rotation > 1.f) rotation = 1.f;
409 }
else if (fabsf(rotation -
m_rotation) > 0.001) {
430 if (step == 0) step = 1;
432 if (e->delta() > 0) {
444 Profiler profiler(
"Thumbwheel::paintEvent");
447 QPainter paint(
this);
448 paint.drawImage(0, 0,
m_cache);
452 Profiler profiler2(
"Thumbwheel::paintEvent (no cache)");
454 m_cache = QImage(size(), QImage::Format_ARGB32);
461 subclip = QRect(bw, bw+1, width() - bw*2, height() - bw*2 - 2);
463 subclip = QRect(bw+1, bw, width() - bw*2 - 2, height() - bw*2);
467 paint.setClipRect(rect());
468 paint.fillRect(subclip, palette().background().color());
470 paint.setRenderHint(QPainter::Antialiasing,
true);
480 for (
int i = bw-1; i >= 0; --i) {
482 int grey = (i + 1) * (256 / (bw + 1));
483 QColor fc = QColor(grey, grey, grey);
489 path.moveTo(w0 + i, h0 + i + 2);
490 path.quadTo(w/2, i * 1.25, w1 - i, h0 + i + 2);
491 path.lineTo(w1 - i, h1 - i - 2);
492 path.quadTo(w/2, h - i * 1.25, w0 + i, h1 - i - 2);
495 path.moveTo(w0 + i + 2, h0 + i);
496 path.quadTo(i * 1.25, h/2, w0 + i + 2, h1 - i);
497 path.lineTo(w1 - i - 2, h1 - i);
498 path.quadTo(w - i * 1.25, h/2, w1 - i - 2, h0 + i);
502 paint.drawPath(path);
505 paint.setClipRect(subclip);
511 w = (
m_orientation == Qt::Horizontal ? width() : height()) - bw*2;
517 int radius = int(w / 2 + 2);
519 for (
int i = 0; i < notches; ++i) {
521 float a0 = (2.f * M_PI * i) / notches + radians;
522 float a1 = a0 + M_PI / (notches * 2);
523 float a2 = (2.f * M_PI * (i + 1)) / notches + radians;
525 float depth = cosf((a0 + a2) / 2);
526 if (depth < 0)
continue;
528 float x0 = radius * sinf(a0) + w/2;
529 float x1 = radius * sinf(a1) + w/2;
530 float x2 = radius * sinf(a2) + w/2;
531 if (x2 < 0 || x0 > w)
continue;
540 int grey = lrintf(120 * depth);
542 QColor fc = QColor(grey, grey, grey);
543 QColor oc = palette().highlight().color();
552 if (i >= notches / 4) {
553 prop = float(notches - (((i -
float(notches) / 4.f) * 4.f) / 3.f))
560 paint.drawRect(QRectF(x1, height() - (height() - bw*2) * prop - bw,
561 x2 - x1, height() * prop));
563 paint.drawRect(QRectF(bw, x1, (width() - bw*2) * prop, x2 - x1));
568 paint.setBrush(palette().background().color());
571 paint.drawRect(QRectF(x0, bw, x1 - x0, height() - bw*2));
573 paint.drawRect(QRectF(bw, x0, width() - bw*2, x1 - x0));
577 QPainter paint2(
this);
578 paint2.drawImage(0, 0,
m_cache);
585 return QSize(80, 12);
587 return QSize(12, 80);
void setDefaultValue(int deft)
void setRangeMapper(RangeMapper *mapper)
virtual void enterEvent(QEvent *)
int getDefaultValue() const
virtual void leaveEvent(QEvent *)
Thumbwheel(Qt::Orientation orientation, QWidget *parent=0)
int getMinimumValue() const
virtual void mouseMoveEvent(QMouseEvent *e)
virtual void wheelEvent(QWheelEvent *e)
void setShowScale(bool show)
virtual void paintEvent(QPaintEvent *e)
virtual void mouseDoubleClickEvent(QMouseEvent *e)
void setMappedValue(float mappedValue)
void setMinimumValue(int min)
RangeMapper * m_rangeMapper
void setMaximumValue(int max)
bool getShowScale() const
void setTracking(bool tracking)
void updateMappedValue(int value)
void setSpeed(float speed)
float getMappedValue() const
Qt::Orientation m_orientation
int getMaximumValue() const
virtual void mousePressEvent(QMouseEvent *e)
void setShowToolTip(bool show)
virtual void mouseReleaseEvent(QMouseEvent *e)