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 class QcWindowFactory
: public QcObjectFactory
<QcWindow
>
32 // NOTE: use basic object contruction, but return widget proxy
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
*)) );
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
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
)
62 window
->setWindowTitle( title
);
66 QRect
geom(geom_
.toRect());
68 if( geom
.isEmpty() ) {
69 geom
= QApplication::desktop()->availableGeometry();
70 geom
.setSize( window
->sizeHint() );
74 window
->setGeometry( geom
);
76 window
->move( geom
.topLeft() );
77 window
->setFixedSize( geom
.size() );
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
);