common: win32utils - compile fix
[supercollider.git] / QtCollider / QcWidgetFactory.h
blob11b993a167ac12861fa48e62bc5801fd306cecda
1 /************************************************************************
3 * Copyright 2010-2012 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 #ifndef QC_WIDGET_FACTORY_H
23 #define QC_WIDGET_FACTORY_H
25 #include "QcObjectFactory.h"
26 #include "QWidgetProxy.h"
28 #include <QLayout>
30 template <class QWIDGET>
31 class QcWidgetFactory : public QcObjectFactory<QWIDGET>
33 public:
35 virtual QObjectProxy *newInstance( PyrObject *scObject, QtCollider::Variant arg[10] ) {
37 // Omit the first two arguments - parent and bounds
39 QWIDGET *w;
41 if( arg[2].type() == QMetaType::Void ) {
42 w = new QWIDGET;
44 else {
45 QObject *obj = QWIDGET::staticMetaObject.newInstance(
46 arg[2].asGenericArgument(),
47 arg[3].asGenericArgument(),
48 arg[4].asGenericArgument(),
49 arg[5].asGenericArgument(),
50 arg[6].asGenericArgument(),
51 arg[7].asGenericArgument(),
52 arg[8].asGenericArgument(),
53 arg[9].asGenericArgument()
56 w = qobject_cast<QWIDGET*>(obj);
57 if( !w ) {
58 qcNoConstructorMsg( QcObjectFactory<QWIDGET>::metaObject(), 8, &arg[2] );
59 return 0;
63 QObjectProxy *prox( proxy(w, scObject) );
65 // check if parent arg is valid;
67 QObjectProxy *parentProxy( arg[0].value<QObjectProxy*>() );
70 // set requested geometry
72 QRect r( arg[1].value<QRectF>().toRect() );
73 if( r.size().isEmpty() ) r.setSize( w->sizeHint() );
75 w->setGeometry( r );
77 // automatically support drag and drop
79 w->setAcceptDrops( true );
81 // set parent
83 QWidget *parent = parentProxy ? qobject_cast<QWidget*>( parentProxy->object() ) : 0;
85 if( parent ) {
87 // Ok, we have the parent, so stuff the child in
89 const QMetaObject *mo = parent->metaObject();
90 bool ok = mo->invokeMethod( parent, "addChild", Q_ARG( QWidget*, w ) );
92 if( !ok ) w->setParent( parent );
94 w->show();
97 return prox;
100 protected:
102 virtual QObjectProxy * proxy( QWIDGET *w, PyrObject *sc_obj )
104 QWidgetProxy *prox( new QWidgetProxy( w, sc_obj ) );
105 initialize( prox, w );
106 return prox;
109 virtual void initialize( QWidgetProxy *proxy, QWIDGET *obj ) {};
112 #define QC_DECLARE_QWIDGET_FACTORY( QWIDGET ) QC_DECLARE_FACTORY( QWIDGET, QcWidgetFactory<QWIDGET> )
114 #endif