File: QNumberBox.sc

package info (click to toggle)
supercollider 1%3A3.13.0%2Brepack-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 80,292 kB
  • sloc: cpp: 476,363; lisp: 84,680; ansic: 77,685; sh: 25,509; python: 7,909; makefile: 3,440; perl: 1,964; javascript: 974; xml: 826; java: 677; yacc: 314; lex: 175; objc: 152; ruby: 136
file content (126 lines) | stat: -rw-r--r-- 2,910 bytes parent folder | download | duplicates (6)
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
NumberBox : QAbstractStepValue {
	var <scroll, <scroll_step;
	var <align, <buttonsVisible = false;
	var <normalColor, <typingColor;
	var <object, <>setBoth = true;

	*qtClass { ^'QcNumberBox' }

	*new { arg parent, bounds;
		var obj = super.new( parent, bounds );
		obj.initNumberBox;
		^obj;
	}

	initNumberBox {
		scroll = true;
		scroll_step = 1;
		normalColor = Color.black;
		typingColor = Color.red;
	}

	object_  { arg obj;
		if( setBoth ) {
			if( obj.isNumber ) { this.value = obj } { this.string = obj.asString }
		};
		object = obj
	}

	value {
		var type = this.getProperty( \valueType );
		var val;
		switch( type,
			0 /* Number */, { val = this.getProperty( \value ) },
			1 /* Inf */, { val = inf },
			2 /* -Inf */, { val = -inf },
			3 /* NaN */, { val = 0 },
			4 /* Text */, { val = 0 }
		);
		^val;
	}

	value_ { arg value;
		case
		// isNaN has to be on the first plase, because a NaN is also equal to inf and -inf
		{ value.isNaN } { this.invokeMethod( \setNaN ); }
		{ value == inf } { this.invokeMethod( \setInfinite, true ); }
		{ value == -inf } { this.invokeMethod( \setInfinite, false ); }
		{ this.setProperty( \value, value.asFloat ); }
		;
	}

	valueAction_ { arg val;
		this.value_(val);
		action.value(this);
	}

	string { ^this.getProperty( \text ); }

	string_ { arg string; this.setProperty( \text, string ); }

	clipLo { ^this.getProperty(\minimum) }
	clipLo_ { arg aFloat; this.setProperty( \minimum, aFloat ) }

	clipHi { ^this.getProperty(\maximum) }
	clipHi_ { arg aFloat; this.setProperty( \maximum, aFloat ) }

	scroll_ { arg aBool;
		scroll = aBool;
		this.setProperty( \scroll, aBool );
	}

	scroll_step_ { arg aFloat;
		scroll_step = aFloat;
		this.setProperty( \scrollStep, aFloat );
	}

	decimals { ^this.getProperty(\decimals); }
	minDecimals { ^this.getProperty(\minDecimals); }
	maxDecimals { ^this.getProperty(\maxDecimals); }

	decimals_ {  arg decimals; this.setProperty( \decimals, decimals ); }
	minDecimals_ { arg decimals; this.setProperty( \minDecimals, decimals ); }
	maxDecimals_ { arg decimals; this.setProperty( \maxDecimals, decimals ); }

	align_ { arg alignment;
		align = alignment;
		this.setProperty( \alignment, QAlignment(alignment));
	}

	stringColor {
		^this.palette.baseText;
	}

	stringColor_ { arg color;
		this.palette = this.palette.baseText_(color);
	}

	normalColor_ { arg aColor;
		normalColor = aColor;
		this.setProperty( \normalColor, aColor );
	}

	typingColor_ { arg aColor;
		typingColor = aColor;
		this.setProperty( \editingColor, aColor );
	}

	background {
		^this.palette.base;
	}

	background_ { arg color;
		this.palette = this.palette.base_(color);
	}

	buttonsVisible_ { arg aBool;
		buttonsVisible = aBool;
		this.setProperty( \buttonsVisible, aBool );
	}

	defaultGetDrag { ^this.value; }
	defaultCanReceiveDrag { ^View.currentDrag.isNumber; }
	defaultReceiveDrag {
		this.valueAction = View.currentDrag;
	}
}