Examples under Synth:new should not use SynthDef:play to make nodes
[supercollider.git] / SCClassLibrary / QtCollider / BasicViews.sc
blobd10051cfe42066d14f74853fc706fe99117178b9
1 /////////////////////// ABSTRACT CLASSES ////////////////////////////
3 QTextViewBase : QView {
4   var <object, <>setBoth = true;
5   var <align;
7   object_  { arg obj;
8     if( setBoth ) { this.string = obj.asString };
9     object = obj
10   }
12   align_ { arg aSymbol;
13     align = aSymbol;
14     this.setProperty( \alignment, QAlignment(aSymbol) );
15   }
18 QItemViewBase : QView
20   var <items;
22   items_ { arg stringArray;
23     items = stringArray;
24     this.setProperty( \items, stringArray);
25   }
27   item {
28     ^items.at( this.value );
29   }
31   valueAction_ { arg val;
32     this.value_(val);
33     action.value(this);
34   }
37 QAbstractScroll : QView {
38   var <hasHorizontalScroller = true, <hasVerticalScroller = true;
39   var <autohidesScrollers = true;
41   autohidesScrollers_ { arg aBool;
42     if( aBool ) {
43       if( hasHorizontalScroller ) {
44         this.setProperty( \horizontalScrollBarPolicy, 0 );
45       };
46       if( hasVerticalScroller ) {
47         this.setProperty( \verticalScrollBarPolicy, 0 );
48       };
49     } {
50       if( hasHorizontalScroller ) {
51         this.setProperty( \horizontalScrollBarPolicy, 2 )
52       };
53       if( hasVerticalScroller ) {
54         this.setProperty( \verticalScrollBarPolicy, 2 );
55       };
56     };
57     autohidesScrollers = aBool;
58   }
60   hasHorizontalScroller_ { arg aBool;
61     var policy;
62     if( aBool ) {
63       if( autohidesScrollers ) { policy = 0 } { policy = 2 };
64       this.setProperty( \horizontalScrollBarPolicy, policy );
65     } {
66       this.setProperty( \horizontalScrollBarPolicy, 1 );
67     };
68     hasHorizontalScroller = aBool;
69   }
71   hasVerticalScroller_ { arg aBool;
72     var policy;
73     if( aBool ) {
74       if( autohidesScrollers ) { policy = 0 } { policy = 2 };
75       this.setProperty( \verticalScrollBarPolicy, policy );
76     } {
77       this.setProperty( \verticalScrollBarPolicy, 1 );
78     };
79     hasVerticalScroller = aBool;
80   }
83 QAbstractStepValue : QView {
84   var <step = 0.1, <shift_scale = 100.0, <ctrl_scale = 10.0, <alt_scale = 0.1;
86   step_ { arg aFloat;
87     step = aFloat;
88     this.setProperty( \step, aFloat );
89   }
91   shift_scale_ { arg aFloat;
92     shift_scale = aFloat;
93     this.setProperty( \shiftScale, aFloat );
94   }
96   ctrl_scale_ { arg aFloat;
97     ctrl_scale = aFloat;
98     this.setProperty( \ctrlScale, aFloat );
99   }
101   alt_scale_ { arg aFloat;
102     alt_scale = aFloat;
103     this.setProperty( \altScale, aFloat );
104   }
106   getScale { |modifiers|
107     ^case
108       { modifiers.isShift } { shift_scale }
109       { modifiers.isCtrl } { ctrl_scale }
110       { modifiers.isAlt } { alt_scale }
111       { 1 };
112   }
114   increment { arg factor = 1.0; this.invokeMethod( \increment, factor.asFloat ); }
115   decrement { arg factor = 1.0; this.invokeMethod( \decrement, factor.asFloat ); }
118 /////////////////////// CONTAINERS ////////////////////////////////
120 QHLayoutView : QView {
121   *qtClass { ^"QcHLayoutWidget" }
124 QVLayoutView : QView {
125   *qtClass { ^"QcVLayoutWidget" }
128 QScrollCanvas : QObject {
129   *qtClass { ^'QcScrollWidget' }
132 QScrollView : QAbstractScroll {
133   var <canvas;
134   var <background, <hasBorder=true;
136   *new { arg parent, bounds;
137     ^super.new( parent, bounds ).initQScrollView;
138   }
140   *qtClass { ^"QcScrollArea" }
142   children { arg class = QView;
143     ^canvas.children( class );
144   }
146   background_ { arg aColor;
147     background = aColor;
148     canvas.setProperty( \background, aColor, true );
149   }
151   hasBorder_ { arg aBool;
152     hasBorder = aBool;
153     this.setProperty( \hasBorder, aBool );
154   }
156   innerBounds {
157     ^this.getProperty( \innerBounds, Rect.new );
158   }
160   visibleOrigin {
161     ^this.getProperty( \visibleOrigin, Point.new );
162   }
164   visibleOrigin_ { arg point;
165     this.setProperty( \visibleOrigin, point );
166   }
168   canvas_ { arg view;
169     canvas = view;
170     this.invokeMethod( \setWidget, view, true );
171   }
173   initQScrollView {
174     // NOTE: The canvas widget must not be a QView, so that asking its
175     // children for parent will skip it and hit this view instead.
176     this.canvas = QScrollCanvas();
177   }
180 /////////////////////////// WIDGETS ///////////////////////////////
182 QStaticText : QTextViewBase {
183   var <string;
185   *qtClass { ^"QLabel" }
187   *new { arg aParent, aBounds;
188     var obj = super.new( aParent, aBounds );
189     obj.setProperty(\wordWrap, true);
190     ^obj;
191   }
193   background_ { arg aColor;
194     if( this.background.isNil ) {
195       this.setProperty( \autoFillBackground, true);
196     };
197     super.background_( aColor );
198   }
200   string_ { arg text;
201     string = text;
202     this.setProperty( \text, text );
203   }
205   stringColor {
206     ^this.palette.windowTextColor;
207   }
209   stringColor_ { arg color;
210     this.setProperty( \palette, this.palette.windowTextColor_(color) );
211   }
214 QTextField : QTextViewBase {
215   *qtClass { ^"QcTextField" }
217   string {
218     ^this.getProperty( \text );
219   }
221   string_ { arg text;
222     this.setProperty( \text, text );
223   }
225   stringColor {
226     ^this.palette.baseTextColor;
227   }
229   stringColor_ { arg color;
230     this.setProperty( \palette, this.palette.baseTextColor_(color) );
231   }
233   background {
234     ^this.palette.baseColor;
235   }
237   background_ { arg color;
238     this.setProperty( \palette, this.palette.baseColor_(color) )
239   }
241   value {
242     ^this.string;
243   }
245   value_ { arg val;
246     this.string_( val.asString );
247   }
249   valueAction_ { arg val;
250     this.string_( val.asString );
251     this.doAction;
252   }
254   defaultGetDrag { ^this.string; }
255   defaultCanReceiveDrag { ^true; }
256   defaultReceiveDrag {
257     this.valueAction = QView.currentDrag;
258   }
261 QButton : QView {
262   var <states;
264   *qtClass { ^"QcButton" }
266   *properties {
267     ^[\string, \states];
268   }
270   value {
271     ^this.getProperty( \value );
272   }
274   value_ { arg argVal;
275     this.setProperty( \value, argVal );
276   }
278   valueAction_ { arg anInt;
279     this.value_( anInt );
280     action.value(this);
281   }
283   states_ { arg stateArray;
284     states = stateArray;
285     super.setProperty( \states, stateArray );
286   }
288   defaultGetDrag { ^this.value; }
289   defaultCanReceiveDrag { ^true; }
290   defaultReceiveDrag {
291     if( QView.currentDrag.isNumber )
292       { this.valueAction = QView.currentDrag; }
293       { this.action = QView.currentDrag; };
294   }
297 QCheckBox : QView {
299   *qtClass { ^"QcCheckBox" }
301   *new{ |parent,bounds,text|
302     ^super.new(parent,bounds).init(text)
303   }
305   init{ |text|
306     this.string_(text)
307   }
309   value{
310     ^this.getProperty(\value)
311   }
313   value_{ |val|
314     this.setProperty(\value,val)
315   }
317   valueAction_ { |val|
318     this.value_(val);
319     this.doAction;
320   }
322   string_{ |string|
323     this.setProperty(\text,string)
324   }
326   string{
327     ^this.getProperty(\text)
328   }
330   defaultGetDrag { ^this.value; }
331   defaultCanReceiveDrag { ^((QView.currentDrag == true) || (QView.currentDrag == false)); }
332   defaultReceiveDrag {
333     this.valueAction = QView.currentDrag;
334   }
337 QPopUpMenu : QItemViewBase {
339   *qtClass { ^"QcPopUpMenu" }
341   allowsReselection { ^this.getProperty( \signalReactivation ) }
343   allowsReselection_ { arg flag; ^this.setProperty( \signalReactivation, flag ) }
345   value {
346     var v = this.getProperty( \currentIndex );
347     if( v < 0 ) { ^nil } { ^v };
348   }
350   value_ { arg val;
351     this.setProperty( \currentIndex, val ? -1 );
352   }
354   stringColor {
355     ^this.palette.buttonTextColor;
356   }
358   stringColor_ { arg color;
359     this.setProperty( \palette, this.palette.buttonTextColor_(color) );
360   }
362   defaultGetDrag { ^this.value; }
363   defaultCanReceiveDrag { ^QView.currentDrag.isNumber; }
364   defaultReceiveDrag {
365     this.valueAction = QView.currentDrag;
366   }