00001 /****************************************************************************** 00002 * This file is part of the Gluon Development Platform 00003 * Copyright (c) 2010 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 00022 #include "qsizefpropertywidgetitem.h" 00023 00024 #include <QtGui/QDoubleSpinBox> 00025 #include <QtGui/QHBoxLayout> 00026 00027 #include <cfloat> 00028 00029 REGISTER_PROPERTYWIDGETITEM( GluonCreator, QSizeFPropertyWidgetItem ) 00030 00031 using namespace GluonCreator; 00032 00033 class QSizeFPropertyWidgetItem::QSizeFPropertyWidgetItemPrivate 00034 { 00035 public: 00036 QSizeFPropertyWidgetItemPrivate() {}; 00037 00038 QDoubleSpinBox* height; 00039 QDoubleSpinBox* width; 00040 00041 QSizeF value; 00042 }; 00043 00044 QSizeFPropertyWidgetItem::QSizeFPropertyWidgetItem( QWidget* parent, Qt::WindowFlags f ) 00045 : PropertyWidgetItem( parent, f ) 00046 { 00047 d = new QSizeFPropertyWidgetItemPrivate; 00048 00049 QWidget* widget = new QWidget( this ); 00050 QHBoxLayout* layout = new QHBoxLayout(); 00051 layout->setSpacing( 0 ); 00052 widget->setLayout( layout ); 00053 00054 d->height = new QDoubleSpinBox( this ); 00055 d->height->setPrefix( tr( "Height: " ) ); 00056 d->height->setRange( -FLT_MAX, FLT_MAX ); 00057 layout->addWidget( d->height ); 00058 connect( d->height, SIGNAL( valueChanged( double ) ), SLOT( heightValueChanged( double ) ) ); 00059 00060 d->width = new QDoubleSpinBox( this ); 00061 d->width->setPrefix( tr( "Width: " ) ); 00062 d->width->setRange( -FLT_MAX, FLT_MAX ); 00063 layout->addWidget( d->width ); 00064 connect( d->width, SIGNAL( valueChanged( double ) ), SLOT( widthValueChanged( double ) ) ); 00065 00066 setEditWidget( widget ); 00067 } 00068 00069 QSizeFPropertyWidgetItem::~QSizeFPropertyWidgetItem() 00070 { 00071 delete d; 00072 } 00073 00074 QStringList 00075 QSizeFPropertyWidgetItem::supportedDataTypes() const 00076 { 00077 QStringList supportedTypes; 00078 supportedTypes.append( "QSizeF" ); 00079 return supportedTypes; 00080 } 00081 00082 PropertyWidgetItem* 00083 QSizeFPropertyWidgetItem::instantiate() 00084 { 00085 return new QSizeFPropertyWidgetItem(); 00086 } 00087 00088 void 00089 QSizeFPropertyWidgetItem::setEditValue( const QVariant& value ) 00090 { 00091 d->value = value.toSizeF(); 00092 00093 d->height->setValue( d->value.height() ); 00094 d->width->setValue( d->value.width() ); 00095 } 00096 00097 void 00098 QSizeFPropertyWidgetItem::heightValueChanged( double value ) 00099 { 00100 d->value.setHeight( value ); 00101 PropertyWidgetItem::valueChanged( QVariant( d->value ) ); 00102 } 00103 00104 void 00105 QSizeFPropertyWidgetItem::widthValueChanged( double value ) 00106 { 00107 d->value.setWidth( value ); 00108 PropertyWidgetItem::valueChanged( QVariant( d->value ) ); 00109 } 00110 00111 // #include "qsizefpropertywidgetitem.moc"