File: controller_spin_box.h

package info (click to toggle)
nageru 2.3.2-1
  • links: PTS
  • area: main
  • in suites: forky, sid
  • size: 3,120 kB
  • sloc: cpp: 39,131; perl: 94; sh: 18; makefile: 4
file content (47 lines) | stat: -rw-r--r-- 1,074 bytes parent folder | download | duplicates (5)
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)