1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
|
#ifndef _CONTROLLER_SPIN_BOX_H
#define _CONTROLLER_SPIN_BOX_H 1
// ControllerSpinBox is like QSpinBox, except it has a second special value
// "PB" (in addition to the standard minimum value of -1, representing blank),
// representing the virtual pitch bend controller.
#include <QSpinBox>
#include <QString>
#include "shared/midi_device.h"
class ControllerSpinBox : public QSpinBox {
Q_OBJECT
public:
ControllerSpinBox(QWidget *parent) : QSpinBox(parent) {}
int valueFromText(const QString &text) const override
{
if (text == "PB") {
return MIDIReceiver::PITCH_BEND_CONTROLLER;
} else {
return QSpinBox::valueFromText(text);
}
}
QString textFromValue(int value) const override
{
if (value == MIDIReceiver::PITCH_BEND_CONTROLLER) {
return "PB";
} else {
return QSpinBox::textFromValue(value);
}
}
QValidator::State validate(QString &input, int &pos) const override
{
if (input == "PB") {
return QValidator::Acceptable;
} else {
return QSpinBox::validate(input, pos);
}
}
};
#endif // !defined(_CONTROLLER_SPIN_BOX_H)
|