00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "MainWindow.h"
00022
00023
00024
00025 #include <KActionCollection>
00026 #include <KIcon>
00027 #include <KDebug>
00028
00029 #include <klocalizedstring.h>
00030
00031
00032
00033 #include "GraphVisualEditor.h"
00034 #include "GraphScene.h"
00035
00036
00037 #include "model_GraphDocument.h"
00038
00039
00040 #include "graphDocument.h"
00041 #include "graph.h"
00042
00043
00044 #include "AbstractAction.h"
00045 #include "AddNode.h"
00046 #include "AddTypedNode.h"
00047 #include "AddEdge.h"
00048 #include "MoveNode.h"
00049 #include "Select.h"
00050 #include "DeleteAction.h"
00051 #include "AlignAction.h"
00052
00053
00054 #include <kstandarddirs.h>
00055 #include <QtGui/QActionGroup>
00056 #include <QtCore/QList>
00057 #include <QtCore/QFile>
00058 #include <KPushButton>
00059 #include <core/gluonobject.h>
00060 #include <core/gdlhandler.h>
00061 #include <creator/lib/abstractundocommand.h>
00062 #include <creator/lib/objectmanager.h>
00063 #include <QtCore/QDir>
00064
00065
00066 MainWindow::MainWindow() : QWidget()
00067 {
00068 _tDocument = new GraphDocument( "Untitled" );
00069
00070 setupWidgets();
00071 setupActions();
00072 setupLists();
00073
00074 setActiveGraphDocument( _tDocument );
00075 _graph = _tDocument->addGraph();
00076 setActiveGraph( _graph );
00077 _lastScene = "";
00078 _skipNextUpdate = false;
00079 _isGameObject = false;
00080 _isGameComponent = false;
00081 connect( GluonEngine::Game::instance(), SIGNAL( currentSceneChanged( GluonEngine::Scene* ) ), this, SLOT( readTheScene() ) );
00082 connect( GluonCreator::HistoryManager::instance(), SIGNAL( historyChanged( const QUndoCommand* ) ), SLOT( updateNodesFromModel( const QUndoCommand* ) ) );
00083 connect( GluonCreator::ObjectManager::instance(), SIGNAL( newGameObject( GluonEngine::GameObject* ) ), this, SLOT( markAsGameObject() ) );
00084 connect( GluonCreator::ObjectManager::instance(), SIGNAL( newComponent( GluonEngine::Component* ) ), this, SLOT( markAsGameComponent() ) );
00085 }
00086
00087 GraphDocument* MainWindow::activeDocument() const
00088 {
00089 return _tDocument;
00090 }
00091
00092 void MainWindow::eatChildren( GluonEngine::GameObject* trap )
00093 {
00094 qsrand( trap->childCount() );
00095 int i = trap->childCount();
00096 while( i > 0 )
00097 {
00098 _graph->addNode( trap->childGameObject( i - 1 )->name(), QPointF((( double( qrand() ) / RAND_MAX )*_graph->document()->width() ) + 10, (( double( qrand() ) / RAND_MAX )*_graph->document()->height() ) + 10 ), "base" );
00099 _graph->node( trap->childGameObject( i - 1 )->name() )->setProperty( "parentObject", trap->objectName() );
00100 foreach( QString s, _objectTypes )
00101 {
00102 foreach( GluonEngine::Component * c, trap->childGameObject( i - 1 )->findComponentsByType( s ) )
00103 {
00104 _graph->addNode( c->name(), QPointF((( double( qrand() ) / RAND_MAX )*_graph->document()->width() ) + 10, (( double( qrand() ) / RAND_MAX )*_graph->document()->height() ) + 10 ), "others" );
00105 _graph->node( c->name() )->setValue( s );
00106 _graph->node( c->name() )->setValueHeader( "Type" );
00107 _graph->node( c->name() )->setProperty( "parentObject", c->parent()->objectName() );
00108 _graph->node( c->name() )->hideValue( true );
00109 }
00110 }
00111 if( trap->childGameObject( i - 1 )->childCount() > 0 )
00112 {
00113 eatChildren( trap->childGameObject( i - 1 ) );
00114 }
00115 i--;
00116 }
00117 }
00118
00119 GluonCore::GluonObject* MainWindow::surfNodesIntoTree()
00120 {
00121 GluonCore::GluonObject* nodelist = new GluonCore::GluonObject( "plantaseedgrowatree" );
00122 foreach( Edge * e, _graph->edges() )
00123 {
00124 if( _graph->node( e->fromNode() )->in_edges().count() < 1 )
00125 {
00126 GluonCore::GluonObject* node = new GluonCore::GluonObject( e->fromNode(), nodelist );
00127 traceNodeGen( node );
00128 }
00129
00130 }
00131 return nodelist;
00132 }
00133
00134 void MainWindow::traceNodeGen( GluonCore::GluonObject* n )
00135 {
00136 foreach( Edge * e, _graph->node( n->objectName() )->out_edges() )
00137 {
00138 GluonCore::GluonObject* node = new GluonCore::GluonObject( e->toNode(), n );
00139 traceNodeGen( node );
00140 }
00141 }
00142
00143 void MainWindow::markAsGameObject()
00144 {
00145 _isGameObject = true;
00146 }
00147
00148 void MainWindow::markAsGameComponent()
00149 {
00150 _isGameComponent = true;
00151 }
00152
00153 void MainWindow::updateNodesFromModel( const QUndoCommand* cmd )
00154 {
00155 if( _skipNextUpdate != false )
00156 {
00157 if( dynamic_cast<const GluonCreator::AbstractUndoCommand*>( cmd ) != NULL && dynamic_cast<const GluonCreator::AbstractUndoCommand*>( cmd )->commandName() == "NewObjectCommand" && ( _isGameObject || _isGameComponent ) )
00158 {
00159 if( dynamic_cast<const GluonCreator::AbstractUndoCommand*>( cmd )->commandDirection() == "redo" )
00160 {
00161 if( _isGameObject )
00162 {
00163 _graph->addNode( dynamic_cast<const GluonCreator::AbstractUndoCommand*>( cmd )->object()->objectName(), QPointF((( double( qrand() ) / RAND_MAX )*_graph->document()->width() ) + 10, (( double( qrand() ) / RAND_MAX )*_graph->document()->height() ) + 10 ), "base" );
00164 _graph->node( dynamic_cast<const GluonCreator::AbstractUndoCommand*>( cmd )->object()->objectName() )->setProperty( "parentObject", dynamic_cast<const GluonCreator::AbstractUndoCommand*>( cmd )->object()->parent()->objectName() );
00165 }
00166 if( _isGameComponent )
00167 {
00168 _graph->addNode( dynamic_cast<const GluonCreator::AbstractUndoCommand*>( cmd )->object()->objectName(), QPointF((( double( qrand() ) / RAND_MAX )*_graph->document()->width() ) + 10, (( double( qrand() ) / RAND_MAX )*_graph->document()->height() ) + 10 ), "others" );
00169 _graph->node( dynamic_cast<const GluonCreator::AbstractUndoCommand*>( cmd )->object()->objectName() )->setValue( QString( dynamic_cast<GluonEngine::Component*>( dynamic_cast<const GluonCreator::AbstractUndoCommand*>( cmd )->object() )->metaObject()->className() ) );
00170 _graph->node( dynamic_cast<const GluonCreator::AbstractUndoCommand*>( cmd )->object()->objectName() )->setValueHeader( "Type" );
00171 _graph->node( dynamic_cast<const GluonCreator::AbstractUndoCommand*>( cmd )->object()->objectName() )->setProperty( "parentObject", dynamic_cast<const GluonCreator::AbstractUndoCommand*>( cmd )->object()->parent()->objectName() );
00172 _graph->node( dynamic_cast<const GluonCreator::AbstractUndoCommand*>( cmd )->object()->objectName() )->hideValue( true );
00173 }
00174 }
00175 else
00176 {
00177 _graph->remove( _graph->node( dynamic_cast<const GluonCreator::AbstractUndoCommand*>( cmd )->object()->objectName() ) );
00178 }
00179 }
00180 else if( dynamic_cast<const GluonCreator::AbstractUndoCommand*>( cmd ) != NULL && dynamic_cast<const GluonCreator::AbstractUndoCommand*>( cmd )->commandName() == "DeleteObjectCommand" )
00181 {
00182 if( dynamic_cast<const GluonCreator::AbstractUndoCommand*>( cmd )->commandDirection() == "redo" )
00183 {
00184 _graph->remove( _graph->node( dynamic_cast<const GluonCreator::AbstractUndoCommand*>( cmd )->object()->objectName() ) );
00185 }
00186 else
00187 {
00188 if( dynamic_cast<GluonEngine::GameObject*>( dynamic_cast<const GluonCreator::AbstractUndoCommand*>( cmd )->object() ) != NULL )
00189 {
00190 _graph->addNode( dynamic_cast<const GluonCreator::AbstractUndoCommand*>( cmd )->object()->objectName(), QPointF((( double( qrand() ) / RAND_MAX )*_graph->document()->width() ) + 10, (( double( qrand() ) / RAND_MAX )*_graph->document()->height() ) + 10 ), "base" );
00191 _graph->node( dynamic_cast<const GluonCreator::AbstractUndoCommand*>( cmd )->object()->objectName() )->setProperty( "parentObject", dynamic_cast<const GluonCreator::AbstractUndoCommand*>( cmd )->object()->parent()->objectName() );
00192 }
00193 if( dynamic_cast<GluonEngine::Component*>( dynamic_cast<const GluonCreator::AbstractUndoCommand*>( cmd )->object() ) != NULL )
00194 {
00195 _graph->addNode( dynamic_cast<const GluonCreator::AbstractUndoCommand*>( cmd )->object()->objectName(), QPointF((( double( qrand() ) / RAND_MAX )*_graph->document()->width() ) + 10, (( double( qrand() ) / RAND_MAX )*_graph->document()->height() ) + 10 ), "others" );
00196 _graph->node( dynamic_cast<const GluonCreator::AbstractUndoCommand*>( cmd )->object()->objectName() )->setValue( QString( dynamic_cast<GluonEngine::Component*>( dynamic_cast<const GluonCreator::AbstractUndoCommand*>( cmd )->object() )->metaObject()->className() ) );
00197 _graph->node( dynamic_cast<const GluonCreator::AbstractUndoCommand*>( cmd )->object()->objectName() )->setValueHeader( "Type" );
00198 _graph->node( dynamic_cast<const GluonCreator::AbstractUndoCommand*>( cmd )->object()->objectName() )->setProperty( "parentObject", dynamic_cast<const GluonCreator::AbstractUndoCommand*>( cmd )->object()->parent()->objectName() );
00199 _graph->node( dynamic_cast<const GluonCreator::AbstractUndoCommand*>( cmd )->object()->objectName() )->hideValue( true );
00200 }
00201 }
00202 }
00203 }
00204 _skipNextUpdate = false;
00205 _isGameObject = false;
00206 _isGameComponent = false;
00207 }
00208
00209 void MainWindow::deleteThisSceneObject( QString objectName, QString objectParent )
00210 {
00211
00212 GluonEngine::GameObject* parent;
00213 if( GluonEngine::Game::instance()->getFromScene( objectParent ) != NULL )
00214 {
00215 parent = GluonEngine::Game::instance()->getFromScene( objectParent );
00216 }
00217 else
00218 {
00219 parent = GluonEngine::Game::instance()->currentScene()->sceneContents();
00220 }
00221 if( parent->child( objectName ) != NULL )
00222 {
00223 _skipNextUpdate = true;
00224 if( qobject_cast<GluonEngine::GameObject*>( parent->findItemByName( objectName ) ) != NULL ) GluonCreator::ObjectManager::instance()->deleteGameObject( qobject_cast<GluonEngine::GameObject*>( parent->findItemByName( objectName ) ) );
00225 if( qobject_cast<GluonEngine::Component*>( parent->findItemByName( objectName ) ) != NULL ) parent->removeChild( parent->findItemByName( objectName ) );
00226 }
00227 }
00228
00229 void MainWindow::exportFromThisNode( GluonCore::GluonObject* o, QTextStream* file )
00230 {
00231 if( _graph->node( o->objectName() )->type() == "if" )
00232 {
00233 *file << "if(" + _graph->node( o->objectName() )->value().toString() + ")\n{\n";
00234 foreach( Edge * e, _graph->node( o->objectName() )->out_edges() )
00235 {
00236 if( e->fromConnector() == "true" )
00237 {
00238 foreach( QObject * obj, o->children() )
00239 {
00240 if( e->toNode() == qobject_cast<GluonCore::GluonObject*>( obj )->objectName() ) exportFromThisNode( qobject_cast<GluonCore::GluonObject*>( obj ), file );
00241 }
00242 }
00243 else if( e->fromConnector() == "false" )
00244 {
00245 *file << "}\n else{\n";
00246 foreach( QObject * obj, o->children() )
00247 {
00248 if( e->toNode() == qobject_cast<GluonCore::GluonObject*>( obj )->objectName() ) exportFromThisNode( qobject_cast<GluonCore::GluonObject*>( obj ), file );
00249 }
00250 }
00251 }
00252 *file << "}\n";
00253 }
00254
00255 else if( _graph->node( o->objectName() )->type() == "base" )
00256 {
00257 *file << "function " + o->objectName() + "start()\n{\n";
00258 foreach( QObject * obj, o->children() )
00259 {
00260 if( _graph->node( o->objectName() )->out_edges().first()->toNode() == qobject_cast<GluonCore::GluonObject*>( obj )->objectName() ) exportFromThisNode( qobject_cast<GluonCore::GluonObject*>( obj ), file );
00261 }
00262 *file << "}\n";
00263 }
00264 else
00265 {
00266 *file << o->objectName() + "();\n";
00267 foreach( QObject * obj, o->children() )
00268 {
00269 if( _graph->node( o->objectName() )->out_edges().first()->toNode() == qobject_cast<GluonCore::GluonObject*>( obj )->objectName() ) exportFromThisNode( qobject_cast<GluonCore::GluonObject*>( obj ), file );
00270 }
00271 }
00272 }
00273
00274 void MainWindow::exportCode( bool checked )
00275 {
00276 Q_UNUSED( checked )
00277 if( GluonEngine::Game::instance()->gameProject()->findItemByName( "vn-" + GluonEngine::Game::instance()->currentScene()->name() ) == NULL )
00278 {
00279 GluonEngine::Asset* script = new GluonEngine::Asset();
00280 script->setName( "vn-" + GluonEngine::Game::instance()->currentScene()->name() );
00281 script->setFile( QUrl( "Assets/" + script->name() + ".js" ) );
00282 GluonEngine::Game::instance()->gameProject()->addChild( script );
00283 QFile codeFile( script->file().toLocalFile() );
00284 if( !codeFile.open( QIODevice::WriteOnly ) ) return;
00285 QTextStream filewrite( &codeFile );
00286 foreach( QObject * o, surfNodesIntoTree()->children() )
00287 {
00288 exportFromThisNode( qobject_cast<GluonCore::GluonObject*>( o ), &filewrite );
00289 }
00290 codeFile.close();
00291 }
00292 else
00293 {
00294 GluonEngine::Asset* scriptE = GluonEngine::Game::instance()->gameProject()->findChild<GluonEngine::Asset*>( "vn-" + GluonEngine::Game::instance()->currentScene()->name() );
00295 if( !scriptE ) return;
00296 QFile codeFileE( scriptE->file().toLocalFile() );
00297 if( !codeFileE.open( QIODevice::WriteOnly ) ) return;
00298 QTextStream filewriteE( &codeFileE );
00299 foreach( QObject * o, surfNodesIntoTree()->children() )
00300 {
00301 exportFromThisNode( qobject_cast<GluonCore::GluonObject*>( o ), &filewriteE );
00302 }
00303 codeFileE.close();
00304 }
00305 }
00306
00307 void MainWindow::saveStateGDL()
00308 {
00309 if( !_skipSaving )
00310 {
00311 QFile stateFile( QFileInfo( GluonEngine::Game::instance()->gameProject()->filename().toLocalFile() ).dir().absolutePath() + "/Assets/visualnodes-" + GluonEngine::Game::instance()->currentScene()->name() + ".gdl" );
00312 QList<const GluonCore::GluonObject*> objects;
00313 GluonCore::GluonObject* nodelist = new GluonCore::GluonObject( "Nodes" );
00314 GluonCore::GluonObject* edgelist = new GluonCore::GluonObject( "Edges" );
00315 objects.append( nodelist );
00316 objects.append( edgelist );
00317 foreach( Node * n, _graph->nodes() )
00318 {
00319 GluonCore::GluonObject* node = new GluonCore::GluonObject( n->name(), nodelist );
00320 node->setProperty( "NodeType", n->type() );
00321 node->setProperty( "NodeValue", n->value() );
00322 node->setProperty( "NodeValueHeader", n->valueHeader() );
00323 node->setProperty( "parentObject", n->property( "parentObject" ) );
00324 node->setProperty( "Nodex", n->x() );
00325 node->setProperty( "Nodey", n->y() );
00326 }
00327 foreach( Edge * e, _graph->edges() )
00328 {
00329 GluonCore::GluonObject* edge = new GluonCore::GluonObject( e->name(), edgelist );
00330 edge->setProperty( "value", e->value() );
00331 edge->setProperty( "fromConnector", e->fromConnector() );
00332 edge->setProperty( "toConnector", e->toConnector() );
00333 edge->setProperty( "fromNode", e->fromNode() );
00334 edge->setProperty( "toNode", e->toNode() );
00335 }
00336 if( !QDir( QFileInfo( GluonEngine::Game::instance()->gameProject()->filename().toLocalFile() ).dir().absolutePath() + "/Assets" ).exists() ) QDir( QFileInfo( GluonEngine::Game::instance()->gameProject()->filename().toLocalFile() ).dir().absolutePath() ).mkdir( "Assets" );
00337 if( !stateFile.open( QIODevice::WriteOnly ) ) return;
00338 QTextStream filewrite( &stateFile );
00339 filewrite << GluonCore::GDLHandler::instance()->serializeGDL( objects );
00340 stateFile.close();
00341 }
00342 }
00343
00344 void MainWindow::loadStateGDL()
00345 {
00346 QFile stateFile( QFileInfo( GluonEngine::Game::instance()->gameProject()->filename().toLocalFile() ).dir().absolutePath() + "/Assets/visualnodes-" + GluonEngine::Game::instance()->currentScene()->name() + ".gdl" );
00347 if( !stateFile.open( QIODevice::ReadOnly ) ) return;
00348 QTextStream stateread( &stateFile );
00349 QString statetext = stateread.readAll();
00350 if( statetext.isEmpty() ) return;
00351 QList<GluonCore::GluonObject*> rootlist = GluonCore::GDLHandler::instance()->parseGDL( statetext, this->parent() );
00352 foreach( QObject * n, rootlist.first()->children() )
00353 {
00354 _graph->addNode( n->objectName(), QPoint( n->property( "Nodex" ).toInt(), n->property( "Nodey" ).toInt() ), n->property( "NodeType" ).toString() );
00355 _graph->node( n->objectName() )->setValue( n->property( "NodeValue" ).toString() );
00356 _graph->node( n->objectName() )->setValueHeader( n->property( "NodeValueHeader" ).toString() );
00357 _graph->node( n->objectName() )->setProperty( "parentObject", n->parent()->objectName() );
00358 if( _graph->node( n->objectName() )->valueHeader() != "Value" )_graph->node( n->objectName() )->hideValue( true );
00359 }
00360 foreach( QObject * e, rootlist.last()->children() )
00361 {
00362 _graph->addEdge( _graph->node( e->property( "fromNode" ).toString() ), _graph->node( e->property( "toNode" ).toString() ), qobject_cast<NodeItem*>( _graph->node( e->property( "fromNode" ).toString() )->nodeItem() )->connectors().value( e->property( "fromConnector" ).toString() ), qobject_cast<NodeItem*>( _graph->node( e->property( "toNode" ).toString() )->nodeItem() )->connectors().value( e->property( "toConnector" ).toString() ) );
00363 }
00364 stateFile.close();
00365 }
00366
00367 void MainWindow::readTheScene()
00368 {
00369 QDir path = QDir( QFileInfo( GluonEngine::Game::instance()->gameProject()->filename().toLocalFile() ).dir().absolutePath() + "/Assets" );
00370 if( GluonEngine::Game::instance()->currentScene()->name() == _lastScene ) return;
00371 _skipSaving = true;
00372 foreach( Edge * e, _graph->edges() )
00373 {
00374 e->remove();
00375 }
00376 foreach( Node * n, _graph->nodes() )
00377 {
00378 n->remove();
00379 }
00380 _skipSaving = false;
00381 if( path.exists() && QFileInfo( path.absolutePath() + "/visualnodes-" + GluonEngine::Game::instance()->currentScene()->name() + ".gdl" ).exists() )
00382 {
00383 loadStateGDL();
00384 }
00385 else
00386 {
00387 eatChildren( GluonEngine::Game::instance()->currentScene()->sceneContents() );
00388 }
00389 _lastScene = GluonEngine::Game::instance()->currentScene()->name();
00390 }
00391
00392 void MainWindow::setupWidgets()
00393 {
00394 _layout = new QVBoxLayout( this );
00395 _graphVisualEditor = new GraphVisualEditor( this );
00396 _actionButtons = new KToolBar( _graphVisualEditor, false );
00397 _widgetType = new KComboBox( _actionButtons );
00398 _exportCode = new KPushButton( _actionButtons );
00399 _exportCode->setText( "Export Code" );
00400 _exportCode->setIcon( KIcon( "arrow-up-double" ) );
00401
00402 addCustomTypes( _widgetType );
00403 _layout->addWidget( _actionButtons );
00404 _layout->addWidget( _graphVisualEditor );
00405 }
00406
00407 void MainWindow::setupLists()
00408 {
00409 QHash<QString, const QMetaObject*> objectTypes = GluonCore::GluonObjectFactory::instance()->objectTypes();
00410 foreach( const QMetaObject * obj, objectTypes )
00411 {
00412 GluonEngine::Component* comp = qobject_cast<GluonEngine::Component*>( obj->newInstance() );
00413 if( comp )
00414 {
00415 _objectTypes.append( objectTypes.key( obj ) );
00416 }
00417 }
00418 }
00419
00420 void MainWindow::addCustomTypes( KComboBox* bigList )
00421 {
00422 QFile nodefile( KGlobal::dirs()->locate( "data", "nodetypes.gdl" ) );
00423 if( !nodefile.open( QIODevice::ReadOnly ) ) return;
00424 QTextStream noderead( &nodefile );
00425 QString nodetext = noderead.readAll();
00426 if( nodetext.isEmpty() ) return;
00427 QList<GluonCore::GluonObject*> noderootlist = GluonCore::GDLHandler::instance()->parseGDL( nodetext, this->parent() );
00428 QMap<QString, QVariant> propertlist;
00429 foreach( QObject * n, noderootlist.first()->children() )
00430 {
00431 propertlist.clear();
00432 foreach( QByteArray ba, n->dynamicPropertyNames() )
00433 {
00434 propertlist.insert( QString( ba.data() ), n->property( ba.data() ) );
00435 }
00436 bigList->addItem( qobject_cast<GluonCore::GluonObject*>( n )->name(), propertlist );
00437 }
00438 nodefile.close();
00439 }
00440
00441 void MainWindow::setupActions()
00442 {
00443 GraphScene* gc = _graphVisualEditor->scene();
00444 ac = new KActionCollection( this );
00445 QActionGroup* g = new QActionGroup( this );
00446 _actionButtons->addAction( g->addAction( ac->addAction( "add_typed_node", new AddTypedNodeAction( gc, this ) ) ) );
00447 _widgetTypeBar = _actionButtons->addWidget( _widgetType );
00448 _actionButtons->addAction( g->addAction( ac->addAction( "move_node", new MoveNodeAction( gc, this ) ) ) );
00449 _actionButtons->addAction( g->addAction( ac->addAction( "delete_action", new DeleteAction( gc, this ) ) ) );
00450 _actionButtons->addWidget( _exportCode );
00451 _widgetTypeBar->setVisible( false );
00452 qobject_cast<AddTypedNodeAction*>( ac->action( "add_typed_node" ) )->widgetTypeChanged( _widgetType->currentText() );
00453 connect( ac->action( "add_typed_node" ), SIGNAL( changed() ), this, SLOT( toggleWidgetTypeShown() ) );
00454 connect( ac->action( "delete_action" ), SIGNAL( deleteSceneItem( QString, QString ) ), this, SLOT( deleteThisSceneObject( QString, QString ) ) );
00455 connect( _widgetType, SIGNAL( currentIndexChanged( QString ) ), ac->action( "add_typed_node" ), SLOT( widgetTypeChanged( QString ) ) );
00456 connect( _exportCode, SIGNAL( clicked( bool ) ), this, SLOT( exportCode( bool ) ) );
00457 ac->action( "move_node" )->trigger();
00458 }
00459
00460 void MainWindow::toggleWidgetTypeShown()
00461 {
00462 if( _widgetTypeBar->isVisible() )
00463 {
00464 _widgetTypeBar->setVisible( false );
00465 }
00466 else
00467 {
00468 _widgetTypeBar->setVisible( true );
00469 }
00470 }
00471
00472 void MainWindow::setActiveGraphDocument( GraphDocument* d )
00473 {
00474 foreach( QAction * action, ac->actions() )
00475 {
00476 if( AbstractAction* absAction = qobject_cast<AbstractAction*> ( action ) )
00477 {
00478 absAction->setActiveGraphDocument( d );
00479 }
00480 }
00481
00482 _graphVisualEditor->setActiveGraphDocument( d );
00483 }
00484
00485 void MainWindow::setActiveGraph( Graph* g )
00486 {
00487 disconnect( SIGNAL( saveStateGDL() ) );
00488 foreach( QAction * action, ac->actions() )
00489 {
00490 if( AbstractAction* absAction = qobject_cast<AbstractAction*> ( action ) )
00491 absAction->setActiveGraph( g );
00492 }
00493 _graphVisualEditor->setActiveGraph( g );
00494 _graph = g;
00495 g->setKCB( _widgetType );
00496 connect( g, SIGNAL( changed() ), this, SLOT( saveStateGDL() ) );
00497 }
00498
00499 Graph* MainWindow::graph() const
00500 {
00501 return _graph;
00502 }
00503
00504 GraphScene* MainWindow::scene() const
00505 {
00506 return _graphVisualEditor->scene();
00507 }