00001 /****************************************************************************** 00002 * This file is part of the Gluon Development Platform 00003 * Copyright (C) 2010 Kim Jung Nissen <jungnissen@gmail.com> 00004 * 00005 * This library is free software; you can redistribute it and/or 00006 * modify it under the terms of the GNU Lesser General Public 00007 * License as published by the Free Software Foundation; either 00008 * version 2.1 of the License, or (at your option) any later version. 00009 * 00010 * This library is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 * Lesser General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU Lesser General Public 00016 * License along with this library; if not, write to the Free Software 00017 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00018 */ 00019 00020 #include "qrealpropertywidgetitem.h" 00021 00022 #include <cfloat> 00023 #include <core/gluonobject.h> 00024 #include <core/metainfo.h> 00025 00026 #include <knuminput.h> 00027 00028 #include <QtGui/QDoubleSpinBox> 00029 REGISTER_PROPERTYWIDGETITEM( GluonCreator, QRealPropertyWidgetItem ) 00030 00031 using namespace GluonCreator; 00032 00033 QRealPropertyWidgetItem::QRealPropertyWidgetItem( QWidget* parent, Qt::WindowFlags f ) 00034 : PropertyWidgetItem( parent, f ) 00035 { 00036 } 00037 00038 QRealPropertyWidgetItem::~QRealPropertyWidgetItem() 00039 { 00040 } 00041 00042 QStringList 00043 QRealPropertyWidgetItem::supportedDataTypes() const 00044 { 00045 QList<QString> supportedTypes; 00046 supportedTypes.append( "qreal" ); 00047 supportedTypes.append( "float" ); 00048 supportedTypes.append( "double" ); 00049 return supportedTypes; 00050 } 00051 00052 PropertyWidgetItem * 00053 QRealPropertyWidgetItem::instantiate() 00054 { 00055 return new QRealPropertyWidgetItem(); 00056 } 00057 00058 void 00059 QRealPropertyWidgetItem::setEditProperty( const QString& value ) 00060 { 00061 // Clean up any possible leftovers 00062 delete editWidget(); 00063 00064 GluonCore::GluonObject* theObject = qobject_cast<GluonCore::GluonObject*>( editObject() ); 00065 bool noPropertyRange = true;; 00066 if( theObject ) 00067 { 00068 if( theObject->hasMetaInfo() ) 00069 { 00070 if( theObject->metaInfo()->hasPropertyRange( value ) ) 00071 { 00072 noPropertyRange = false; 00073 KDoubleNumInput* editor = new KDoubleNumInput( this ); 00074 editor->setRange( theObject->metaInfo()->propertyRangeMin( value ), theObject->metaInfo()->propertyRangeMax( value ) ); 00075 setEditWidget( editor ); 00076 } 00077 } 00078 } 00079 00080 if( noPropertyRange ) 00081 { 00082 QDoubleSpinBox* spinBox = new QDoubleSpinBox( this ); 00083 setEditWidget( spinBox ); 00084 00085 } 00086 00087 connect( editWidget(), SIGNAL( valueChanged( double ) ), SLOT( qrealValueChanged( double ) ) ); 00088 GluonCreator::PropertyWidgetItem::setEditProperty( value ); 00089 } 00090 00091 void 00092 QRealPropertyWidgetItem::setEditValue( const QVariant& value ) 00093 { 00094 editWidget()->setProperty( "value", value ); 00095 } 00096 00097 void 00098 QRealPropertyWidgetItem::qrealValueChanged( double value ) 00099 { 00100 PropertyWidgetItem::valueChanged( QVariant( value ) ); 00101 } 00102 00103 // #include "qrealpropertywidgetitem.moc"