00001 #include "NodePropertiesWidget.h"
00002 #include "node.h"
00003 #include "MainWindow.h"
00004 #include <KDebug>
00005 #include "NodeItem.h"
00006 #include "graph.h"
00007 #include "model_GraphProperties.h"
00008
00009 NodePropertiesWidget::NodePropertiesWidget( QWidget* ): QWidget( 0 )
00010 {
00011 setupUi( this );
00012 _item = 0;
00013 _node = 0;
00014 }
00015
00016 void NodePropertiesWidget::setNode( NodeItem* n, QPointF pos )
00017 {
00018 if( _node == n->node() )
00019 return;
00020
00021 if( _node )
00022 {
00023 disconnectNode( _node );
00024 }
00025
00026 _node = n->node();
00027 if( ! _item )
00028 {
00029 _svgFile = _node->iconPackage();
00030 }
00031
00032 _item = n;
00033 move( pos.x() + 10, pos.y() + 10 );
00034
00035 show();
00036 activateWindow();
00037 raise();
00038
00039 reflectAttributes();
00040
00041 connect( _node, SIGNAL( changed() ), this, SLOT( reflectAttributes() ) );
00042 connect( _node->parent(), SIGNAL( automateChanged( bool ) ), this, SLOT( updateAutomateAttributes( bool ) ) );
00043
00044 connect( _showName, SIGNAL( toggled( bool ) ), _node, SLOT( hideName( bool ) ) );
00045 connect( _showValue, SIGNAL( toggled( bool ) ), _node, SLOT( hideValue( bool ) ) );
00046 connect( _begin, SIGNAL( toggled( bool ) ), _node, SLOT( setBegin( bool ) ) );
00047 connect( _end, SIGNAL( toggled( bool ) ), _node, SLOT( setEnd( bool ) ) );
00048 connect( _name, SIGNAL( textChanged( QString ) ), _node, SLOT( setName( QString ) ) );
00049 connect( _value, SIGNAL( textChanged( QString ) ), _node, SLOT( setValue( QString ) ) );
00050 connect( _x, SIGNAL( valueChanged( int ) ), _node, SLOT( setX( int ) ) );
00051 connect( _y, SIGNAL( valueChanged( int ) ), _node, SLOT( setY( int ) ) );
00052 connect( _width, SIGNAL( valueChanged( double ) ), _node, SLOT( setWidth( double ) ) );
00053
00054 GraphPropertiesModel* model = new GraphPropertiesModel();
00055 model->setDataSource( _node );
00056
00057 _propertiesTable->setModel( model );
00058
00059 }
00060
00061 void NodePropertiesWidget::reflectAttributes()
00062 {
00063 _color->setColor( _node->color() );
00064 _x->setValue( _node->x() );
00065 _y->setValue( _node->y() );
00066 _name->setText( _node->name() );
00067 _value->setText( _node->value().toString() );
00068 _width->setValue( _node->width() );
00069 _showName->setChecked( _node->showName() );
00070 _showValue->setChecked( _node->showValue() );
00071 updateAutomateAttributes( qobject_cast< Graph* >( _node->parent() )->automate() );
00072 _propertyName->setText( "" );
00073 _propertyValue->setText( "" );
00074 _image->setPixmap( _node->image() );
00075 _isPropertyGlobal->setCheckState( Qt::Unchecked );
00076 if(( _svgFile == _node->iconPackage() ) && ( _images->count() != 0 ) )
00077 {
00078 kDebug() << _svgFile << "already set, and images combo box is not empty";
00079 return;
00080 }
00081 _images->clear();
00082 QFile svgFile( _item->node()->iconPackage() );
00083 if( !svgFile.open( QIODevice::ReadOnly | QIODevice::Text ) )
00084 {
00085 kDebug() << "could not open file for reading";
00086 return;
00087 }
00088
00089 QXmlStreamReader reader( &svgFile );
00090 while( !reader.atEnd() )
00091 {
00092 reader.readNext();
00093 if( reader.attributes().hasAttribute( "id" ) )
00094 {
00095 QString attribute = reader.attributes().value( "id" ).toString();
00096 if( attribute.startsWith( "rocs_" ) )
00097 {
00098 attribute.remove( "rocs_" );
00099 _images->addItem( attribute );
00100 }
00101 }
00102 }
00103 }
00104
00105 void NodePropertiesWidget::on__images_activated( const QString& s )
00106 {
00107 _node->setIcon( "rocs_" + s );
00108 }
00109
00110 void NodePropertiesWidget::on__color_activated( const QColor& c )
00111 {
00112 _node->setColor( c.name() );
00113 }
00114
00115 void NodePropertiesWidget::updateAutomateAttributes( bool b )
00116 {
00117 if( b )
00118 {
00119 _begin->setChecked( _node->begin() );
00120 _end->setChecked( _node->end() );
00121 _begin->show();
00122 _end->show();
00123 }
00124 else
00125 {
00126 _begin->setChecked( false );
00127 _end->setChecked( false );
00128 _begin->hide();
00129 _end->hide();
00130 }
00131 }
00132
00133 void NodePropertiesWidget::on__addProperty_clicked()
00134 {
00135
00136 GraphPropertiesModel* model = qobject_cast< GraphPropertiesModel*>( _propertiesTable->model() );
00137 model->addDynamicProperty( _propertyName->text(),
00138 QVariant( _propertyValue->text() ),
00139 _node,
00140 ( _isPropertyGlobal->checkState() == Qt::Checked ) );
00141
00142 }
00143
00144 void NodePropertiesWidget::disconnectNode( Node* n )
00145 {
00146
00147 disconnect( n, SIGNAL( changed() ), this, SLOT( reflectAttributes() ) );
00148 disconnect( n->parent(), SIGNAL( automateChanged( bool ) ), this, SLOT( updateAutomateAttributes( bool ) ) );
00149
00150 disconnect( _showName, SIGNAL( toggled( bool ) ), n, SLOT( hideName( bool ) ) );
00151 disconnect( _showValue, SIGNAL( toggled( bool ) ), n, SLOT( hideValue( bool ) ) );
00152 disconnect( _begin, SIGNAL( toggled( bool ) ), n, SLOT( setBegin( bool ) ) );
00153 disconnect( _end, SIGNAL( toggled( bool ) ), n, SLOT( setEnd( bool ) ) );
00154 disconnect( _name, SIGNAL( textChanged( QString ) ), n, SLOT( setName( QString ) ) );
00155 disconnect( _value, SIGNAL( textChanged( QString ) ), n, SLOT( setValue( QString ) ) );
00156 disconnect( _x, SIGNAL( valueChanged( int ) ), n, SLOT( setX( int ) ) );
00157 disconnect( _y, SIGNAL( valueChanged( int ) ), n, SLOT( setY( int ) ) );
00158 disconnect( _width, SIGNAL( valueChanged( double ) ), n, SLOT( setWidth( double ) ) );
00159
00160 }