diff --git a/companion/src/simulation/widgets/radioknobwidget.h b/companion/src/simulation/widgets/radioknobwidget.h index 8ded84ed9..590e0742e 100644 --- a/companion/src/simulation/widgets/radioknobwidget.h +++ b/companion/src/simulation/widgets/radioknobwidget.h @@ -39,124 +39,122 @@ class RadioKnobWidget : public RadioWidget public: explicit RadioKnobWidget(Board::PotType type = Board::POT_WITH_DETENT, QWidget * parent = Q_NULLPTR, Qt::WindowFlags f = Qt::WindowFlags()) : - RadioWidget(parent, f), - m_potType(type) + RadioWidget(parent, f) { - init(); - } - explicit RadioKnobWidget(Board::PotType type, const QString & labelText, int value = 0, QWidget * parent = Q_NULLPTR, Qt::WindowFlags f = Qt::WindowFlags()) : - RadioWidget(labelText, value, parent, f), - m_potType(type) - { - init(); + init(type); } - void init() + explicit RadioKnobWidget(Board::PotType type, const QString & labelText, int value = 0, QWidget * parent = Q_NULLPTR, Qt::WindowFlags f = Qt::WindowFlags()) : + RadioWidget(labelText, value, parent, f) + { + init(type); + } + + void init(Board::PotType potType) { m_type = RADIO_WIDGET_KNOB; - KnobWidget * pot = new KnobWidget(m_potType, this); - pot->setValue(m_value); + m_stepSize = (potType == Board::POT_MULTIPOS_SWITCH) ? 2048 / 5 : 1; - connect(pot, &KnobWidget::valueChanged, this, &RadioWidget::setValue); - connect(this, &RadioWidget::valueChanged, pot, &KnobWidget::setValue); + m_toolTip = tr("
Value (input): %1
"); + if (m_stepSize == 1) + m_toolTip.append(tr("Right-double-click to reset to center.")); - setWidget(pot); + m_dial = new QDial(this); + +#ifdef __APPLE__ + // Set style for dial to show dot instead of arrow pointer for selected position + m_dial->setStyle(QStyleFactory::create("fusion")); +#endif + + m_dial->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); + m_dial->setFixedSize(QSize(42, 42)); + m_dial->setNotchesVisible(true); + + if (m_stepSize > 1) { + m_dial->setMinimum(0); + m_dial->setMaximum(2048); + // this is a bit of a hack to get the notch markers to display correctly + // the actual notches/value are constrained in setValue() + m_dial->setSingleStep(m_stepSize / 10); + m_dial->setPageStep(m_stepSize); + m_dial->setNotchTarget(5.7); + } + else { + m_dial->setMinimum(-1024); + m_dial->setMaximum(1024); + m_dial->setPageStep(128); + m_dial->setNotchTarget(64); + } + + m_dial->setValue(m_value); + + connect(m_dial, &QDial::valueChanged, this, &RadioKnobWidget::setValueFromDial); + connect(this, &RadioWidget::valueChanged, m_dial, &QDial::setValue); + + setWidget(m_dial); + } + + void setValueFromDial(const int & value) + { + int v = value; + if (m_stepSize > 1) { + v = ((v + m_stepSize / 2) / m_stepSize) * m_stepSize; + // Fix values to account for lack of precision from using integer step size + // This makes the values more symmetrical around the center point + // Note: this is specific to the 6 position switch which is currently the only use case here + if (v > 1024) v += 3; + if (v != value) { + // If the desired value is different then update the slider position + // Note: this will trigger another value changed event call back into this function, at which time setValue will be called below + m_dial->setValue(v); + return; + } + } + setValue(value); + } + + void mousePressEvent(QMouseEvent * event) + { + if (m_stepSize == 1 && event->button() == Qt::RightButton && event->type() == QEvent::MouseButtonDblClick) { + m_dial->setValue(0); + event->accept(); + return; + } + RadioWidget::mousePressEvent(event); + } + + void wheelEvent(QWheelEvent * event) + { + if (event->angleDelta().isNull()) + return; + + if (m_stepSize > 1) { + int numSteps = event->angleDelta().y() / 8 / 15 * m_stepSize; // one step per 15deg + m_dial->setValue(m_dial->value() + numSteps); + event->accept(); + return; + } + RadioWidget::wheelEvent(event); + } + + bool event(QEvent *event) + { + if (event->type() == QEvent::ToolTip) { + QHelpEvent * helpEvent = static_castValue (input): %1
"); - - setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); - setFixedSize(QSize(42, 42)); - setNotchesVisible(true); - if (type == Board::POT_MULTIPOS_SWITCH) { - m_stepSize = 2048 / 5; - setMinimum(0); - setMaximum(2048); - // this is a bit of a hack to get the notch markers to display correctly - // the actual notches/value are constrained in setValue() - setSingleStep(m_stepSize / 10); - setPageStep(m_stepSize); - setNotchTarget(5.7); - } - else { - m_stepSize = 1; - m_toolTip.append(tr("Right-double-click to reset to center.")); - setMinimum(-1024); - setMaximum(1024); - setPageStep(128); - setNotchTarget(64); - } - } - - void setValue(int value) - { - if (m_stepSize > 1) { - value = ((value + m_stepSize / 2) / m_stepSize) * m_stepSize; - // Fix values to account for lack of precision from using integer step size - // This makes the values more symmetrical around the center point - // Note: this is specific to the TX16 6 position switch which is currently the only use case here - if (value > 1024) value += 3; - } - QDial::setValue(value); - } - - - bool event(QEvent *event) - { - if (event->type() == QEvent::ToolTip) { - QHelpEvent * helpEvent = static_cast