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