5 * th9x - http://code.google.com/p/th9x
6 * er9x - http://code.google.com/p/er9x
7 * gruvin9x - http://code.google.com/p/gruvin9x
9 * License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2 as
13 * published by the Free Software Foundation.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
21 #ifndef _RADIOKNOBWIDGET_H_
22 #define _RADIOKNOBWIDGET_H_
24 #include "radiowidget.h"
28 #include <QMouseEvent>
32 class RadioKnobWidget
: public RadioWidget
38 explicit RadioKnobWidget(Board::PotType type
= Board::POT_WITH_DETENT
, QWidget
* parent
= Q_NULLPTR
, Qt::WindowFlags f
= Qt::WindowFlags()) :
39 RadioWidget(parent
, f
),
44 explicit RadioKnobWidget(Board::PotType type
, const QString
& labelText
, int value
= 0, QWidget
* parent
= Q_NULLPTR
, Qt::WindowFlags f
= Qt::WindowFlags()) :
45 RadioWidget(labelText
, value
, parent
, f
),
53 m_type
= RADIO_WIDGET_KNOB
;
55 KnobWidget
* pot
= new KnobWidget(m_potType
, this);
56 pot
->setValue(m_value
);
58 connect(pot
, &KnobWidget::valueChanged
, this, &RadioWidget::setValue
);
59 connect(this, &RadioWidget::valueChanged
, pot
, &KnobWidget::setValue
);
66 Board::PotType m_potType
;
68 class KnobWidget
: public QDial
72 explicit KnobWidget(Board::PotType type
, QWidget
* parent
= 0):
75 m_toolTip
= tr("<p>Value (input): <b>%1</b></p>");
77 setSizePolicy(QSizePolicy::Fixed
, QSizePolicy::Fixed
);
78 setFixedSize(QSize(42, 42));
79 setNotchesVisible(true);
80 if (type
== Board::POT_MULTIPOS_SWITCH
) {
81 m_stepSize
= 2048 / 5;
84 // this is a bit of a hack to get the notch markers to display correctly
85 // the actual notches/value are constrained in setValue()
86 setSingleStep(m_stepSize
/ 10);
87 setPageStep(m_stepSize
);
92 m_toolTip
.append(tr("Right-double-click to reset to center."));
100 void setValue(int value
)
102 if (m_stepSize
> 1) {
103 value
= value
/ m_stepSize
* m_stepSize
;
105 QDial::setValue(value
);
109 bool event(QEvent
*event
)
111 if (event
->type() == QEvent::ToolTip
) {
112 QHelpEvent
* helpEvent
= static_cast<QHelpEvent
*>(event
);
114 QToolTip::showText(helpEvent
->globalPos(), m_toolTip
.arg(this->value()));
118 return QWidget::event(event
);
121 void mousePressEvent(QMouseEvent
* event
)
123 if (m_stepSize
== 1 && event
->button() == Qt::RightButton
&& event
->type() == QEvent::MouseButtonDblClick
) {
128 QDial::mousePressEvent(event
);
131 void wheelEvent(QWheelEvent
* event
)
133 if (event
->angleDelta().isNull())
136 if (m_stepSize
> 1) {
137 int numSteps
= event
->angleDelta().y() / 8 / 15 * m_stepSize
; // one step per 15deg
138 setValue(value() + numSteps
);
142 QDial::wheelEvent(event
);
152 #endif // _RADIOKNOBWIDGET_H_