00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "vectorpropertywidgetitem.h"
00023
00024 #include <QHBoxLayout>
00025 #include <QLabel>
00026 #include <QDoubleSpinBox>
00027 #include <cfloat>
00028 #include <QVector3D>
00029 #include <core/gluonvarianttypes.h>
00030
00031 REGISTER_PROPERTYWIDGETITEM( GluonCreator, VectorPropertyWidgetItem )
00032
00033 using namespace GluonCreator;
00034
00035 class VectorPropertyWidgetItem::VectorPropertyWidgetItemPrivate
00036 {
00037 public:
00038 VectorPropertyWidgetItemPrivate() { }
00039
00040 QDoubleSpinBox* x;
00041 QDoubleSpinBox* y;
00042 QDoubleSpinBox* z;
00043
00044 QVector3D value;
00045 };
00046
00047 VectorPropertyWidgetItem::VectorPropertyWidgetItem( QWidget* parent, Qt::WindowFlags f ): PropertyWidgetItem( parent, f )
00048 {
00049 d = new VectorPropertyWidgetItemPrivate;
00050
00051 QWidget* base = new QWidget( this );
00052 QHBoxLayout* layout = new QHBoxLayout();
00053 layout->setSpacing( 0 );
00054 base->setLayout( layout );
00055
00056 d->x = new QDoubleSpinBox( this );
00057 d->x->setPrefix( "X: " );
00058 d->x->setRange( -FLT_MAX, FLT_MAX );
00059 layout->addWidget( d->x );
00060 connect( d->x, SIGNAL( valueChanged( double ) ), SLOT( xValueChanged( double ) ) );
00061
00062 d->y = new QDoubleSpinBox( this );
00063 d->y->setPrefix( "Y: " );
00064 d->y->setRange( -FLT_MAX, FLT_MAX );
00065 layout->addWidget( d->y );
00066 connect( d->y, SIGNAL( valueChanged( double ) ), SLOT( yValueChanged( double ) ) );
00067
00068 d->z = new QDoubleSpinBox( this );
00069 d->z->setPrefix( "Z: " );
00070 d->z->setRange( -FLT_MAX, FLT_MAX );
00071 layout->addWidget( d->z );
00072 connect( d->z, SIGNAL( valueChanged( double ) ), SLOT( zValueChanged( double ) ) );
00073
00074 setEditWidget( base );
00075 }
00076
00077 VectorPropertyWidgetItem::~VectorPropertyWidgetItem()
00078 {
00079 delete d;
00080 }
00081
00082 QStringList
00083 VectorPropertyWidgetItem::supportedDataTypes() const
00084 {
00085 QStringList supportedTypes;
00086 supportedTypes.append( "QVector3D" );
00087 return supportedTypes;
00088 }
00089
00090 PropertyWidgetItem*
00091 VectorPropertyWidgetItem::instantiate()
00092 {
00093 return new VectorPropertyWidgetItem();
00094 }
00095
00096 void VectorPropertyWidgetItem::setEditValue( const QVariant& value )
00097 {
00098 const QVector3D* vector = static_cast<const QVector3D*>( value.data() );
00099
00100 d->x->setValue( vector->x() );
00101 d->y->setValue( vector->y() );
00102 d->z->setValue( vector->z() );
00103 }
00104
00105 void VectorPropertyWidgetItem::xValueChanged( double value )
00106 {
00107 d->value = QVector3D( value, d->y->value(), d->z->value() );
00108 PropertyWidgetItem::valueChanged( QVariant::fromValue<QVector3D>( d->value ) );
00109 }
00110
00111 void VectorPropertyWidgetItem::yValueChanged( double value )
00112 {
00113 d->value = QVector3D( d->x->value(), value, d->z->value() );
00114 PropertyWidgetItem::valueChanged( QVariant::fromValue<QVector3D>( d->value ) );
00115 }
00116
00117 void VectorPropertyWidgetItem::zValueChanged( double value )
00118 {
00119 d->value = QVector3D( d->x->value(), d->y->value(), value );
00120 PropertyWidgetItem::valueChanged( QVariant::fromValue<QVector3D>( d->value ) );
00121 }
00122
00123