Merge pull request #506 from andrewcsmith/patch-2
[supercollider.git] / SCClassLibrary / QtCollider / QMultiSliderView.sc
blob5ae220ce6547e6726ed1b38156d5fe40aea1009b
1 QMultiSliderView : QView {
2   var <editable=true;
3   var <elasticMode=false;
4   var <indexThumbSize=12, <valueThumbSize=12, <gap=1;
5   var <drawLines=false, <drawRects=true;
6   var <metaAction;
9   *qtClass { ^'QcMultiSlider' }
11   size { ^this.getProperty(\sliderCount) }
12   size_ { arg int; this.setProperty( \sliderCount, int ) }
14   indexIsHorizontal { ^this.getProperty(\orientation) == QOrientation(\vertical) }
16   indexIsHorizontal_ { arg bool;
17     this.setProperty( \orientation, QOrientation(if(bool){\vertical}{\horizontal}) );
18   }
20   editable_ { arg aBool;
21     editable = aBool;
22     this.setProperty( \editable, aBool );
23   }
25   readOnly {
26     ^editable.not;
27   }
29   readOnly_ { arg bool;
30     this.editable_( bool.not );
31   }
33   step { ^this.getProperty(\step) }
34   step_ { arg val; this.setProperty( \step, val ) }
36   value {
37     ^this.getProperty( \values );
38   }
40   value_ { arg array;
41     if( array.isKindOf(DoubleArray).not and: {array.isKindOf(FloatArray).not} )
42       { array = array.as(DoubleArray) };
43     this.setProperty( \values, array );
44   }
46   valueAction_ { arg val;
47     this.value_(val);
48     action.value(this);
49   }
51   currentvalue {
52     ^this.getProperty( \value );
53   }
55   currentvalue_ { arg aFloat;
56     this.setProperty( \value, aFloat );
57   }
59   index {
60     ^this.getProperty( \index );
61   }
63   index_ { arg anInt;
64     this.setProperty( \index, anInt );
65   }
67   selectionSize {
68     ^this.getProperty( \selectionSize );
69   }
71   selectionSize_ { arg anInt;
72     this.setProperty( \selectionSize, anInt );
73   }
75   reference { ^this.getProperty(\reference) }
77   reference_ { arg array;
78     if( array.isKindOf(DoubleArray).not and: {array.isKindOf(FloatArray).not} )
79       { array = array.as(DoubleArray) };
80     this.setProperty( \reference, array );
81   }
83   startIndex_ { arg anInt;
84     this.setProperty( \startIndex, anInt );
85   }
87   elasticMode_ { arg int;
88     elasticMode = int.booleanValue;
89     this.setProperty( \elastic, elasticMode);
90   }
92   thumbSize_ { arg float;
93     this.indexThumbSize_(float);
94     this.valueThumbSize_(float);
95   }
97   indexThumbSize_ { arg float;
98     indexThumbSize = float;
99     this.setProperty( \indexThumbSize, float );
100   }
102   valueThumbSize_ { arg float;
103     valueThumbSize = float;
104     this.setProperty( \valueThumbSize, float );
105   }
107   gap_ { arg anInt;
108     gap = anInt;
109     this.setProperty( \gap, anInt );
110   }
112   // alias for 'gap'
113   xOffset_ { arg int; this.gap_(int); }
114   xOffset { arg int; ^this.gap; }
116   drawLines_ { arg bool;
117     drawLines = bool;
118     this.setProperty( \drawLines, bool );
119   }
121   drawRects_ { arg bool;
122     drawRects = bool;
123     this.setProperty( \drawRects, bool );
124   }
126   showIndex_ { arg aBool;
127     this.setProperty( \highlight, aBool );
128   }
130   isFilled_ { arg aBool;
131     this.setProperty( \isFilled, aBool );
132   }
134   fillColor { ^this.getProperty(\fillColor) }
135   fillColor_ { arg color; this.setProperty( \fillColor, color ) }
137   strokeColor { ^this.getProperty(\strokeColor) }
138   strokeColor_ { arg color; this.setProperty( \strokeColor, color ) }
140   colors_ { arg colorStroke, colorFill;
141     this.strokeColor_( colorStroke );
142     this.fillColor_ ( colorFill );
143   }
145   metaAction_ { arg func;
146     this.manageMethodConnection( metaAction, func, 'metaAction()', \doMetaAction );
147     metaAction = func;
148   }
150   doMetaAction {
151     metaAction.value(this);
152   }
154   defaultKeyDownAction { arg char, mod, uni, keycode, key;
155     key.switch (
156       QKey.left, { this.index = this.index - 1 },
157       QKey.right, { this.index = this.index + 1 },
158       QKey.up, { this.currentvalue = this.currentvalue + this.step },
159       QKey.down, { this.currentvalue = this.currentvalue - this.step }
160     );
161   }
163   defaultGetDrag {
164     var val = this.value;
165     var c, i;
166     if( val.size < 1 ) {^nil};
167     c = this.selectionSize;
168     if( c > 1 ) {
169       i = this.index;
170       ^val[i..(i+c-1)];
171     }
172     ^this.value;
173   }
174   defaultCanReceiveDrag { ^true; }
175   defaultReceiveDrag {
176     arg data = QView.currentDrag;
177     if( data.size > 0 ) {
178       if( data[0].size > 0 ) {
179         this.value = data[0];
180         this.reference = data[1];
181       }{
182         this.value = data;
183       }
184     };
185   }