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 ************************************************************************/
23 #include "../QcWidgetFactory.h"
24 #include "../QWidgetProxy.h"
27 #include <QApplication>
28 #include <QDesktopWidget>
30 static QWidgetProxy
*qcInitWindow( QWidget
*window
, PyrObject
*po
, QList
<QVariant
> & arguments
)
32 if( arguments
.count() < 4 ) return 0;
36 QString name
= arguments
[0].toString();
37 window
->setWindowTitle( name
);
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>();
50 window
->setGeometry( geom
);
52 window
->move( geom
.topLeft() );
53 window
->setFixedSize( geom
.size() );
58 bool border
= arguments
[3].value
<bool>();
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()) );
71 QWidgetProxy
*proxy
= new QWidgetProxy( window
, po
);
75 class QcWindowFactory
: public QcWidgetFactory
<QcWindow
>
78 virtual QObjectProxy
*newInstance( PyrObject
*pyrobj
, QList
<QVariant
> & args
)
80 QcWindow
*w
= new QcWindow
;
81 QObjectProxy
*proxy
= qcInitWindow( w
, pyrobj
, args
);
86 QObject::connect( w
, SIGNAL(painting(QPainter
*)),
87 proxy
, SLOT(customPaint(QPainter
*)) );
92 class QcScrollWindowFactory
: public QcWidgetFactory
<QcScrollWindow
>
94 // NOTE: painting will be performed by QcScrollWidget and its factory
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
;
105 static QcWindowFactory winFactory
;
106 static QcScrollWindowFactory scrollWinFactory
;