New lua versions
[ryzomcore.git] / studio / src / plugins / gui_editor / expression_link.cpp
blob77aeb15f6741288a5b379d7b25d1595c6900855e
1 // Ryzom Core Studio - GUI Editor Plugin
2 //
3 // Copyright (C) 2010-2014 Laszlo KIS-ADAM (dfighter) <dfighter1985@gmail.com>
4 //
5 // This program is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU Affero General Public License as
7 // published by the Free Software Foundation, either version 3 of the
8 // License, or (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU Affero General Public License for more details.
15 // You should have received a copy of the GNU Affero General Public License
16 // along with this program. If not, see <http://www.gnu.org/licenses/>.
18 #include "expression_link.h"
19 #include "expression_node.h"
20 #include <QGraphicsItem>
21 #include <QPen>
23 ExpressionLink::ExpressionLink( QGraphicsItem *parent ) :
24 QGraphicsLineItem( parent )
26 m_from = NULL;
27 m_to = NULL;
30 ExpressionLink::~ExpressionLink()
32 unlink();
35 void ExpressionLink::link( ExpressionNode *from, ExpressionNode *to, int fromSlot, int toSlot )
37 m_from = from;
38 m_to = to;
39 m_from->setLink( this, fromSlot );
40 m_to->setLink( this, toSlot );
42 m_fromSlot = fromSlot;
43 m_toSlot = toSlot;
45 nodeMoved();
48 void ExpressionLink::unlink()
50 if( m_from == NULL )
51 return;
53 m_from->setLink( NULL, m_fromSlot );
54 m_to->setLink( NULL, m_toSlot );
56 m_from = NULL;
57 m_to = NULL;
59 delete this;
62 void ExpressionLink::nodeMoved()
64 setLine( QLineF( m_from->slotPos( m_fromSlot ), m_to->slotPos( m_toSlot ) ) );
67 void ExpressionLink::paint( QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget )
69 QPen p;
70 p.setColor( Qt::black );
71 p.setWidth( 5 );
72 setPen( p );
74 QGraphicsLineItem::paint( painter, option, widget );