old quark gui: openOS is not osx only
[supercollider.git] / SCClassLibrary / QtCollider / BasicViews.sc
blob87d0458f0d824b41e4dc4a49d51f5b18e953a35f
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 );
158   }
160   visibleOrigin {
161     ^this.getProperty( \visibleOrigin );
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   value {
267     ^this.getProperty( \value );
268   }
270   value_ { arg argVal;
271     this.setProperty( \value, argVal );
272   }
274   valueAction_ { arg anInt;
275     this.value_( anInt );
276     action.value(this);
277   }
279   states_ { arg stateArray;
280     states = stateArray;
281     super.setProperty( \states, stateArray );
282   }
284   action_ { arg func;
285     this.manageMethodConnection( action, func, 'action(int)', \prDoAction );
286     action = func;
287   }
289   doAction { arg modifiers;
290     action.value(this, modifiers);
291   }
293   defaultGetDrag { ^this.value; }
294   defaultCanReceiveDrag { ^true; }
295   defaultReceiveDrag {
296     if( QView.currentDrag.isNumber )
297       { this.valueAction = QView.currentDrag; }
298       { this.action = QView.currentDrag; };
299   }
301   prDoAction { arg mods;
302     this.doAction(QKeyModifiers.toCocoa(mods));
303   }
306 QCheckBox : QView {
308   *qtClass { ^"QcCheckBox" }
310   *new{ |parent,bounds,text|
311     ^super.new(parent,bounds).init(text)
312   }
314   init{ |text|
315     this.string_(text)
316   }
318   value{
319     ^this.getProperty(\value)
320   }
322   value_{ |val|
323     this.setProperty(\value,val)
324   }
326   valueAction_ { |val|
327     this.value_(val);
328     this.doAction;
329   }
331   string_{ |string|
332     this.setProperty(\text,string)
333   }
335   string{
336     ^this.getProperty(\text)
337   }
339   defaultGetDrag { ^this.value; }
340   defaultCanReceiveDrag { ^((QView.currentDrag == true) || (QView.currentDrag == false)); }
341   defaultReceiveDrag {
342     this.valueAction = QView.currentDrag;
343   }
346 QPopUpMenu : QItemViewBase {
348   *qtClass { ^"QcPopUpMenu" }
350   allowsReselection { ^this.getProperty( \signalReactivation ) }
352   allowsReselection_ { arg flag; ^this.setProperty( \signalReactivation, flag ) }
354   value {
355     var v = this.getProperty( \currentIndex );
356     if( v < 0 ) { ^nil } { ^v };
357   }
359   value_ { arg val;
360     this.setProperty( \currentIndex, val ? -1 );
361   }
363   stringColor {
364     ^this.palette.buttonTextColor;
365   }
367   stringColor_ { arg color;
368     this.setProperty( \palette, this.palette.buttonTextColor_(color) );
369   }
371   defaultGetDrag { ^this.value; }
372   defaultCanReceiveDrag { ^QView.currentDrag.isNumber; }
373   defaultReceiveDrag {
374     this.valueAction = QView.currentDrag;
375   }