From 2e6a5bb1d6f706610bd9da172b4891f9d708fa29 Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Sat, 13 Sep 2014 23:54:25 +0200 Subject: [PATCH] There are more than 1 slots available now. --HG-- branch : dfighter-tools --- .../plugins/gui_editor/expression_editor.cpp | 20 +++++++++------ .../plugins/gui_editor/expression_link.cpp | 13 ++++++---- .../src/plugins/gui_editor/expression_link.h | 4 ++- .../plugins/gui_editor/expression_node.cpp | 25 ++++++++++++++++--- .../src/plugins/gui_editor/expression_node.h | 9 ++++--- 5 files changed, 50 insertions(+), 21 deletions(-) diff --git a/code/studio/src/plugins/gui_editor/expression_editor.cpp b/code/studio/src/plugins/gui_editor/expression_editor.cpp index 313af23b5..cca3b29ae 100644 --- a/code/studio/src/plugins/gui_editor/expression_editor.cpp +++ b/code/studio/src/plugins/gui_editor/expression_editor.cpp @@ -87,12 +87,18 @@ void ExpressionEditor::onDeleteSelection() ExpressionNode *node = dynamic_cast< ExpressionNode* >( item ); if( node != NULL ) { - ExpressionLink *link = node->link(); - if( link != NULL ) + ExpressionLink *link = NULL; + + int c = node->slotCount(); + for( int i = 0; i < c; i++ ) { - link->unlink(); - m_scene->removeItem( link ); - delete link; + link = node->link( i ); + if( link != NULL ) + { + link->unlink(); + m_scene->removeItem( link ); + delete link; + } } } @@ -113,7 +119,7 @@ void ExpressionEditor::onLinkItems() ExpressionNode *from = static_cast< ExpressionNode* >( l[ 0 ] ); ExpressionNode *to = static_cast< ExpressionNode* >( l[ 1 ] ); - if( ( from->link() != NULL ) || ( to->link() != NULL ) ) + if( ( from->link( 0 ) != NULL ) || ( to->link( 0 ) != NULL ) ) { QMessageBox::information( this, tr( "Failed to link nodes" ), @@ -122,7 +128,7 @@ void ExpressionEditor::onLinkItems() } ExpressionLink *link = new ExpressionLink(); - link->link( from, to ); + link->link( from, to, 0, 0 ); m_scene->addItem( link ); } diff --git a/code/studio/src/plugins/gui_editor/expression_link.cpp b/code/studio/src/plugins/gui_editor/expression_link.cpp index 5050a9339..8e461960e 100644 --- a/code/studio/src/plugins/gui_editor/expression_link.cpp +++ b/code/studio/src/plugins/gui_editor/expression_link.cpp @@ -35,20 +35,23 @@ ExpressionLink::~ExpressionLink() unlink(); } -void ExpressionLink::link( ExpressionNode *from, ExpressionNode *to ) +void ExpressionLink::link( ExpressionNode *from, ExpressionNode *to, int fromSlot, int toSlot ) { m_from = from; m_to = to; - m_from->setLink( this ); - m_to->setLink( this ); + m_from->setLink( this, fromSlot ); + m_to->setLink( this, toSlot ); + + m_fromSlot = fromSlot; + m_toSlot = toSlot; nodeMoved(); } void ExpressionLink::unlink() { - m_from->setLink( NULL ); - m_to->setLink( NULL ); + m_from->setLink( NULL, m_fromSlot ); + m_to->setLink( NULL, m_toSlot ); } void ExpressionLink::nodeMoved() diff --git a/code/studio/src/plugins/gui_editor/expression_link.h b/code/studio/src/plugins/gui_editor/expression_link.h index 59644980a..a5235737c 100644 --- a/code/studio/src/plugins/gui_editor/expression_link.h +++ b/code/studio/src/plugins/gui_editor/expression_link.h @@ -29,7 +29,7 @@ public: ExpressionLink( QGraphicsItem *parent = NULL ); ~ExpressionLink(); - void link( ExpressionNode *from, ExpressionNode *to ); + void link( ExpressionNode *from, ExpressionNode *to, int fromSlot, int toSlot ); void unlink(); void nodeMoved(); @@ -40,6 +40,8 @@ private: ExpressionNode *m_from; ExpressionNode *m_to; + int m_fromSlot; + int m_toSlot; }; #endif diff --git a/code/studio/src/plugins/gui_editor/expression_node.cpp b/code/studio/src/plugins/gui_editor/expression_node.cpp index 95c2830f1..bcde92423 100644 --- a/code/studio/src/plugins/gui_editor/expression_node.cpp +++ b/code/studio/src/plugins/gui_editor/expression_node.cpp @@ -98,12 +98,13 @@ private: ExpressionNode::ExpressionNode( QGraphicsItem *parent ) : QGraphicsItem( parent ) { - m_link = NULL; - m_w = 100; m_h = 100; createSlots(); + + for( int i = 0; i < 4; i++ ) + m_links.push_back( NULL ); } ExpressionNode::~ExpressionNode() @@ -168,10 +169,26 @@ QPointF ExpressionNode::slotPos( int slot ) const return mp; } +void ExpressionNode::setLink( ExpressionLink *link, int slot ) +{ + m_links[ slot ] = link; +} + +ExpressionLink* ExpressionNode::link( int slot ) const +{ + return m_links[ slot ]; +} + void ExpressionNode::mouseMoveEvent( QGraphicsSceneMouseEvent *e ) { - if( m_link != NULL ) - m_link->nodeMoved(); + for( int i = 0; i < 4; i++ ) + { + ExpressionLink *link = m_links[ i ]; + if( link == NULL ) + continue; + + link->nodeMoved(); + } QGraphicsItem::mouseMoveEvent( e ); } diff --git a/code/studio/src/plugins/gui_editor/expression_node.h b/code/studio/src/plugins/gui_editor/expression_node.h index c189bd0fc..991057731 100644 --- a/code/studio/src/plugins/gui_editor/expression_node.h +++ b/code/studio/src/plugins/gui_editor/expression_node.h @@ -35,11 +35,13 @@ public: QRectF boundingRect() const; void paint( QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget ); - void setLink( ExpressionLink *link ){ m_link = link; } - ExpressionLink* link() const{ return m_link; } + void setLink( ExpressionLink *link, int slot ); + ExpressionLink* link( int slot ) const; QPointF slotPos( int slot ) const; + int slotCount() const{ return m_slots.count(); } + protected: void mouseMoveEvent( QGraphicsSceneMouseEvent *e ); @@ -47,12 +49,11 @@ private: void createSlots(); void paintSlots( QPainter *painter ); - ExpressionLink *m_link; - qreal m_w; qreal m_h; QList< NodeSlot* > m_slots; + QList< ExpressionLink* > m_links; }; #endif