Add QPen printing support (and PDF export) with new QPenPrinter class.
[supercollider.git] / QtCollider / widgets / QcWindow.cpp
blob9c16396210756a423e3f2ec522cc63fd6c90c95c
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 static QWidgetProxy *qcInitWindow( QWidget *window, PyrObject *po, QList<QVariant> & arguments )
32 if( arguments.count() < 4 ) return 0;
34 // window title
36 QString name = arguments[0].toString();
37 window->setWindowTitle( name );
39 // size, resizability
41 QRect geom = arguments[1].value<QRect>();
43 if( geom.isEmpty() ) {
44 geom = QApplication::desktop()->availableGeometry();
45 geom.setSize( window->sizeHint() );
48 bool resizable = arguments[2].value<bool>();
49 if( resizable ) {
50 window->setGeometry( geom );
51 } else {
52 window->move( geom.topLeft() );
53 window->setFixedSize( geom.size() );
56 // frameless?
58 bool border = arguments[3].value<bool>();
59 if( !border )
60 window->setWindowFlags( window->windowFlags() | Qt::FramelessWindowHint );
62 // Ctrl+W shortcut: close the window
64 QShortcut *closeShortcut =
65 new QShortcut( QKeySequence( Qt::CTRL | Qt::Key_W ), window );
66 QObject::connect( closeShortcut, SIGNAL(activated()),
67 window, SLOT(close()) );
69 // make the proxy
71 QWidgetProxy *proxy = new QWidgetProxy( window, po );
72 return proxy;
75 class QcWindowFactory : public QcWidgetFactory<QcWindow>
77 public:
78 virtual QObjectProxy *newInstance( PyrObject *pyrobj, QList<QVariant> & args )
80 QcWindow *w = new QcWindow;
81 QObjectProxy *proxy = qcInitWindow( w, pyrobj, args );
82 if( !proxy ) {
83 delete w;
84 return 0;
86 QObject::connect( w, SIGNAL(painting(QPainter*)),
87 proxy, SLOT(customPaint(QPainter*)) );
88 return proxy;
92 class QcScrollWindowFactory : public QcWidgetFactory<QcScrollWindow>
94 // NOTE: painting will be performed by QcScrollWidget and its factory
95 public:
96 virtual QObjectProxy *newInstance( PyrObject *pyrobj, QList<QVariant> & args )
98 QcScrollWindow *w = new QcScrollWindow;
99 QObjectProxy *proxy = qcInitWindow( w, pyrobj, args );
100 if( !proxy ) delete w;
101 return proxy;
105 static QcWindowFactory winFactory;
106 static QcScrollWindowFactory scrollWinFactory;