00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "AddNode.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 AddNodeAction::AddNodeAction( GraphScene* scene, QObject* parent )
00031 : AbstractAction( scene, parent )
00032 {
00033 setText( i18n( "Add Node" ) );
00034 setToolTip( i18n( "Creates a new node at the click position on the drawing area." ) );
00035 setIcon( KIcon( "rocsaddnode" ) );
00036 _name = "add-node";
00037 }
00038
00039 AddNodeAction::~AddNodeAction()
00040 {
00041 qDebug() << "Destroyed";
00042 }
00043
00044 void AddNodeAction::executePress( QPointF pos )
00045 {
00046 if( _graph == 0 )
00047 {
00048 qDebug() << "Error, Graph == 0";
00049 return;
00050 }
00051 if( _graph->readOnly() ) return;
00052
00053 if( pos.x() < 0 ) return;
00054 else if( pos.y() < 0 ) return;
00055 else if( pos.x() > _graphDocument->width() ) return;
00056 else if( pos.y() > _graphDocument->height() ) return;
00057
00058 qDebug() << "Emitindo o addnode";
00059 emit addNode( i18n( "untitled" ), QPointF( pos.x(), pos.y() ) );
00060 }
00061
00062 void AddNodeAction::setActiveGraph( Graph* graph )
00063 {
00064 if( _graph ) disconnect( this, 0, _graph, 0 );
00065 _graph = graph;
00066 connect( this, SIGNAL( addNode( QString, QPointF ) ), _graph, SLOT( addNode( QString, QPointF ) ) );
00067 }
00068