Dept. of incomplete documentation: what if BufDelay* needs to be multichannel?
[supercollider.git] / SCClassLibrary / QtCollider / QWindow.sc
blobbed1b89a89fe9083144e9cdf31594bb07a89fa48
1 QTopScrollWidget : QScrollCanvas {
2   var <>win;
3   doDrawFunc { win.drawFunc.value(win); }
6 QScrollTopView : QScrollView {
7   var >window;
9   *qtClass {^'QcScrollWindow'}
11   *new { arg win, name, bounds, resizable, border;
12     ^super.newCustom([name, bounds, resizable, border])
13           .initQScrollTopView(win);
14   }
16   initQScrollTopView { arg win;
17     var cnv;
18     window = win;
19     // NOTE: The canvas widget must not be a QView, so that asking its
20     // children for parent will skip it and hit this view instead.
21     cnv = QTopScrollWidget.new;
22     cnv.win = win;
23     this.canvas = cnv;
24   }
26   bounds {
27     var r;
28     r = this.getProperty( \geometry );
29     ^r.moveTo(0,0);
30   }
32   bounds_ { arg rect;
33     var rNew = rect.asRect;
34     var rOld = this.getProperty( \geometry );
35     this.setProperty( \geometry, rOld.resizeTo( rNew.width, rNew.height ) );
36   }
38   drawingEnabled_ { arg bool; canvas.setProperty( \drawingEnabled, bool ); }
40   findWindow { ^window; }
43 QTopView : QView {
44   var >window;
46   *qtClass {^'QcWindow'}
48   *new { arg win, name, bounds, resizable, border;
49     ^super.newCustom([name, bounds, resizable, border])
50           .initQTopView(win);
51   }
53   initQTopView { arg win; window = win; }
55   bounds {
56     var r;
57     r = this.getProperty( \geometry );
58     ^r.moveTo(0,0);
59   }
61   bounds_ { arg rect;
62     var rNew = rect.asRect;
63     var rOld = this.getProperty( \geometry );
64     this.setProperty( \geometry, rOld.resizeTo( rNew.width, rNew.height ) );
65   }
67   background_ { arg color;
68     // Do not autoFillBackground; the widget will paint it if necessary.
69     this.palette = this.palette.window_(color);
70   }
72   drawingEnabled_ { arg bool; this.setProperty( \drawingEnabled, bool ); }
74   findWindow { ^window; }
76   doDrawFunc { window.drawFunc.value(window) }
79 QWindow
81   classvar <allWindows, <>initAction;
83   var resizable, <drawFunc, <onClose;
84   var <view;
86   //TODO
87   var <>acceptsClickThrough=false;
88   var <currentSheet;
90   *initClass {
91     ShutDown.add( { QWindow.closeAll } );
92   }
94   *screenBounds {
95     _QWindow_ScreenBounds
96   }
98   *availableBounds {
99     _QWindow_AvailableGeometry
100   }
102   *closeAll {
103     allWindows.copy.do { |win| win.close };
104   }
106   /* NOTE:
107     - 'server' is only for compatibility with SwingOSC
108     - all args have to be of correct type for QWidget constructor to match!
109   */
110   *new { arg name="",
111          bounds,
112          resizable = true,
113          border = true,
114          server,
115          scroll = false;
117     if( bounds.isNil ) {
118       bounds = Rect(0,0,400,400).center_( QWindow.availableBounds.center );
119     }{
120       bounds = QWindow.flipY( bounds.asRect );
121     };
122     ^super.new.initQWindow( name, bounds, resizable, border, scroll );
123   }
125   //------------------------ QWindow specific  -----------------------//
127   initQWindow { arg name, bounds, resize, border, scroll;
128     if( scroll )
129       { view = QScrollTopView.new(this,name,bounds,resize,border); }
130       { view = QTopView.new(this,name,bounds,resize,border); };
132     // set some necessary object vars
133     resizable = resize == true;
135     // allWindows array management
136     QWindow.addWindow( this );
137     view.connectFunction( 'destroyed()', { QWindow.removeWindow(this); }, false );
139     // action to call whenever a window is created
140     QWindow.initAction.value( this );
141   }
143   asView {
144     ^view;
145   }
147   bounds_ { arg aRect;
148     var r = QWindow.flipY( aRect.asRect );
149     view.setProperty( \geometry, r );
150     if( resizable.not ) { view.fixedSize = r.size }
151   }
153   bounds {
154     ^QWindow.flipY( view.getProperty( \geometry ) );
155   }
157   setInnerExtent { arg w, h;
158     // bypass this.bounds, to avoid QWindow flipping the y coordinate
159     var r = view.getProperty(\geometry );
160     view.setProperty(\geometry, r.resizeTo( w, h ); )
161   }
163   background { ^view.background; }
165   background_ { arg aColor; view.background = aColor; }
167   drawFunc_ { arg aFunction;
168     view.drawingEnabled = aFunction.notNil;
169     drawFunc = aFunction;
170   }
172   setTopLeftBounds{ arg rect, menuSpacer=45;
173     view.setProperty( \geometry, rect.moveBy( 0, menuSpacer ) );
174   }
176   onClose_ { arg func;
177     view.manageFunctionConnection( onClose, func, 'destroyed()', false );
178     onClose = func;
179   }
181   // TODO
182   addToOnClose{ arg function; }
183   removeFromOnClose{ arg function; }
185   //------------------- simply redirected to QView ---------------------//
187   sizeHint { ^view.sizeHint }
188   minSizeHint { ^view.minSizeHint }
189   alpha_ { arg value; view.alpha_(value); }
190   addFlowLayout { arg margin, gap; ^view.addFlowLayout( margin, gap ); }
191   close { view.close; }
192   isClosed { ^view.isClosed; }
193   visible { ^view.visible; }
194   visible_ { arg boolean; view.visible_(boolean); }
195   front { view.front; }
196   fullScreen { view.fullScreen; }
197   endFullScreen { view.endFullScreen; }
198   minimize { view.minimize; }
199   unminimize { view.unminimize; }
200   name { ^view.name; }
201   name_ { arg string; view.name_(string); }
202   refresh { view.refresh; }
203   userCanClose { ^view.userCanClose; }
204   userCanClose_ { arg boolean; view.userCanClose_( boolean ); }
205   alwaysOnTop { ^view.alwaysOnTop; }
206   alwaysOnTop_ { arg boolean; view.alwaysOnTop_(boolean); }
207   layout { ^view.layout; }
208   layout_ { arg layout; view.layout_(layout); }
209   toFrontAction_ { arg action; view.toFrontAction_(action) }
210   toFrontAction { ^view.toFrontAction }
211   endFrontAction_ { arg action; view.endFrontAction_(action) }
212   endFrontAction { ^view.endFrontAction }
213   acceptsMouseOver { ^view.acceptsMouseOver }
214   acceptsMouseOver_ { arg flag; view.acceptsMouseOver_(flag) }
216   // ---------------------- private ------------------------------------
218   *flipY { arg aRect;
219     var flippedTop = QWindow.screenBounds.height - aRect.top - aRect.height;
220     ^Rect( aRect.left, flippedTop, aRect.width, aRect.height );
221   }
223   *addWindow { arg window;
224     allWindows = allWindows.add( window );
225   }
227   *removeWindow { arg window;
228     allWindows.remove( window );
229   }