class library: PriorityQueue - implement removeValue, hide array
[supercollider.git] / QtCollider / widgets / QcWindow.cpp
blobc623cf3fff529293314d9b8dfc4aec5845ab4b81
1 /************************************************************************
3 * Copyright 2010-2011 Jakob Leben (jakob.leben@gmail.com)
5 * This file is part of SuperCollider Qt GUI.
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 ************************************************************************/
22 #include "QcWindow.h"
23 #include "../QcWidgetFactory.h"
24 #include "../QWidgetProxy.h"
26 #include <QShortcut>
27 #include <QApplication>
28 #include <QDesktopWidget>
30 class QcWindowFactory : public QcObjectFactory<QcWindow>
32 // NOTE: use basic object contruction, but return widget proxy
33 public:
34 virtual QObjectProxy *proxy( QcWindow *obj, PyrObject *sc_obj )
36 QObjectProxy *proxy = new QWidgetProxy( obj, sc_obj );
37 QObject::connect( obj, SIGNAL(painting(QPainter*)),
38 proxy, SLOT(customPaint(QPainter*)) );
39 return proxy;
43 class QcScrollWindowFactory : public QcObjectFactory<QcScrollWindow>
45 // NOTE: use basic object contruction, but return widget proxy
46 // NOTE: painting will be performed by QcScrollWidget and its factory
47 public:
48 virtual QObjectProxy *proxy( QcWindow *obj, PyrObject *sc_obj )
50 return new QWidgetProxy( obj, sc_obj );
54 static QcWindowFactory winFactory;
55 static QcScrollWindowFactory scrollWinFactory;
57 static void qcInitWindow
58 ( QWidget *window, const QString &title, const QRectF & geom_, bool resizable, bool frame )
60 // window title
62 window->setWindowTitle( title );
64 // size, resizability
66 QRect geom(geom_.toRect());
68 if( geom.isEmpty() ) {
69 geom = QApplication::desktop()->availableGeometry();
70 geom.setSize( window->sizeHint() );
73 if( resizable ) {
74 window->setGeometry( geom );
75 } else {
76 window->move( geom.topLeft() );
77 window->setFixedSize( geom.size() );
80 // frameless?
82 if( !frame )
83 window->setWindowFlags( window->windowFlags() | Qt::FramelessWindowHint );
85 // Ctrl+W shortcut: close the window
87 QShortcut *closeShortcut =
88 new QShortcut( QKeySequence( Qt::CTRL | Qt::Key_W ), window );
89 QObject::connect( closeShortcut, SIGNAL(activated()),
90 window, SLOT(close()) );
93 QcWindow::QcWindow( const QString &title, const QRectF & geom, bool resizable, bool frame )
95 qcInitWindow( this, title, geom, resizable, frame );
98 QcScrollWindow::QcScrollWindow( const QString &title, const QRectF & geom, bool resizable, bool frame )
100 qcInitWindow( this, title, geom, resizable, frame );