00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "AddTypedNode.h"
00022 #include "GraphScene.h"
00023 #include "graph.h"
00024 #include "NodeItem.h"
00025 #include "node.h"
00026 #include <KLocale>
00027 #include "graphDocument.h"
00028 #include <KDebug>
00029
00030 AddTypedNodeAction::AddTypedNodeAction( GraphScene* scene, QObject* parent )
00031 : AbstractAction( scene, parent )
00032 {
00033 setText( i18n( "Add Node" ) );
00034 setToolTip( i18n( "Creates a new node of selected type at the click position on the drawing area." ) );
00035 setIcon( KIcon( "gluonaddnode" ) );
00036 _name = "add-typed-node";
00037 _type = "";
00038 }
00039
00040 AddTypedNodeAction::~AddTypedNodeAction()
00041 {
00042 qDebug() << "Destroyed";
00043 }
00044
00045 void AddTypedNodeAction::executePress( QPointF pos )
00046 {
00047 if( _graph == 0 )
00048 {
00049 qDebug() << "Error, Graph == 0";
00050 return;
00051 }
00052 if( _graph->readOnly() ) return;
00053
00054 if( pos.x() < 0 ) return;
00055 else if( pos.y() < 0 ) return;
00056 else if( pos.x() > _graphDocument->width() ) return;
00057 else if( pos.y() > _graphDocument->height() ) return;
00058
00059 qDebug() << "Emitindo o addnode";
00060 if( _type != "base" && _type != "others" )
00061 {
00062 emit addNode( i18n( "untitled" ), QPointF( pos.x(), pos.y() ), _type );
00063 }
00064 else
00065 {
00066 emit iAmDisappoint();
00067 }
00068 }
00069
00070 void AddTypedNodeAction::widgetTypeChanged( QString type )
00071 {
00072 _type = type;
00073 }
00074
00075 void AddTypedNodeAction::setActiveGraph( Graph* graph )
00076 {
00077 if( _graph ) disconnect( this, 0, _graph, 0 );
00078 _graph = graph;
00079 connect( this, SIGNAL( addNode( QString, QPointF, QString ) ), _graph, SLOT( addNode( QString, QPointF, QString ) ) );
00080 connect( this, SIGNAL( iAmDisappoint() ), _graph, SIGNAL( iAmDisappoint() ) );
00081 }
00082