00001 /****************************************************************************** 00002 * This file is part of the Gluon Development Platform 00003 * Copyright (c) 2009 Dan Leinir Turthra Jensen <admin@leinir.dk> 00004 * Copyright (c) 2010 Arjen Hiemstra <ahiemstra@heimr.nl> 00005 * 00006 * This library is free software; you can redistribute it and/or 00007 * modify it under the terms of the GNU Lesser General Public 00008 * License as published by the Free Software Foundation; either 00009 * version 2.1 of the License, or (at your option) any later version. 00010 * 00011 * This library is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 * Lesser General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU Lesser General Public 00017 * License along with this library; if not, write to the Free Software 00018 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00019 */ 00020 00021 #include "propertywidget.h" 00022 00023 using namespace GluonCreator; 00024 00025 #include "propertywidgetcontainer.h" 00026 #include "propertywidgetitem.h" 00027 #include "propertywidgetitemfactory.h" 00028 00029 #include <core/gluonobject.h> 00030 #include <core/debughelper.h> 00031 00032 #include <QtCore/QVariant> 00033 #include <QtCore/QMetaClassInfo> 00034 00035 #include <QtGui/QBoxLayout> 00036 #include <QtGui/QGridLayout> 00037 #include <QtGui/QGroupBox> 00038 #include <QtGui/QLabel> 00039 #include <QtGui/QToolButton> 00040 00041 #include <KDE/KIcon> 00042 #include <KDE/KLocalizedString> 00043 #include <engine/asset.h> 00044 #include <engine/scene.h> 00045 00046 class PropertyWidget::PropertyWidgetPrivate 00047 { 00048 public: 00049 PropertyWidgetPrivate() 00050 { 00051 object = 0; 00052 layout = 0; 00053 } 00054 GluonCore::GluonObject* object; 00055 QVBoxLayout* layout; 00056 00057 void appendMetaObject( QWidget* parent, QObject* object, QGridLayout* layout ); 00058 }; 00059 00060 00061 PropertyWidget::PropertyWidget( QWidget* parent ): QScrollArea( parent ), d( new PropertyWidgetPrivate ) 00062 { 00063 } 00064 00065 PropertyWidget::~PropertyWidget() 00066 { 00067 delete d; 00068 } 00069 00070 GluonCore::GluonObject* PropertyWidget::object() const 00071 { 00072 return d->object; 00073 } 00074 00075 void PropertyWidget::setObject( GluonCore::GluonObject* object ) 00076 { 00077 if( object ) 00078 { 00079 d->object = object; 00080 d->layout = new QVBoxLayout( this ); 00081 d->layout->setSpacing( 0 ); 00082 d->layout->setContentsMargins( 0, 0, 0, 0 ); 00083 d->layout->setAlignment( Qt::AlignTop ); 00084 00085 appendObject( object, true ); 00086 for( int i = 0; i < object->children().count(); i++ ) 00087 { 00088 GluonCore::GluonObject* theChild = object->child( i ); 00089 if( theChild ) 00090 { 00091 if( qobject_cast<GluonEngine::Asset*>( theChild ) ) 00092 continue; 00093 if( qobject_cast<GluonEngine::Scene*>( theChild ) ) 00094 continue; 00095 if( theChild->metaObject()->className() == QString( "GluonCore::GluonObject" ) ) 00096 continue; 00097 appendObject( theChild ); 00098 } 00099 } 00100 d->layout->addStretch(); 00101 00102 QWidget* containerWidget = new QWidget( this ); 00103 containerWidget->setLayout( d->layout ); 00104 00105 setWidget( containerWidget ); 00106 setWidgetResizable( true ); 00107 } 00108 } 00109 00110 void PropertyWidget::clear() 00111 { 00112 delete widget(); 00113 } 00114 00115 void PropertyWidget::appendObject( GluonCore::GluonObject* obj, bool first ) 00116 { 00117 if( !first && obj->metaObject()->className() == QString( "GluonEngine::GameObject" ) ) 00118 { 00119 return; 00120 } 00121 00122 d->layout->addWidget( new PropertyWidgetContainer( obj, this ) ); 00123 } 00124 00125 //#include "propertywidget.moc"