From 892ca16ae3c719419d6cf9ffd3440ba3e31859cd Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Sun, 14 Sep 2014 16:37:17 +0200 Subject: [PATCH] Support for adding nodes with different slot count. --- .../plugins/gui_editor/expression_editor.cpp | 39 ++++++++++++++----- .../plugins/gui_editor/expression_editor.h | 4 +- .../plugins/gui_editor/expression_node.cpp | 19 +++++---- .../src/plugins/gui_editor/expression_node.h | 2 +- 4 files changed, 46 insertions(+), 18 deletions(-) diff --git a/code/studio/src/plugins/gui_editor/expression_editor.cpp b/code/studio/src/plugins/gui_editor/expression_editor.cpp index 1c4a1ecda..14bf69600 100644 --- a/code/studio/src/plugins/gui_editor/expression_editor.cpp +++ b/code/studio/src/plugins/gui_editor/expression_editor.cpp @@ -52,8 +52,15 @@ void ExpressionEditor::contextMenuEvent( QContextMenuEvent *e ) QMenu menu; QAction *a = NULL; - a = menu.addAction( "Add rect" ); - connect( a, SIGNAL( triggered() ), this, SLOT( onAddRect() ) ); + QMenu *mm = menu.addMenu( "Add node" ); + a = mm->addAction( "1 slot" ); + connect( a, SIGNAL( triggered() ), this, SLOT( onAddNode1() ) ); + + a = mm->addAction( "2 slots" ); + connect( a, SIGNAL( triggered() ), this, SLOT( onAddNode2() ) ); + + a = mm->addAction( "3 slots" ); + connect( a, SIGNAL( triggered() ), this, SLOT( onAddNode3() ) ); if( m_selectionCount > 0 ) { @@ -73,13 +80,6 @@ void ExpressionEditor::contextMenuEvent( QContextMenuEvent *e ) menu.exec( e->globalPos() ); } -void ExpressionEditor::onAddRect() -{ - QGraphicsItem *item = new ExpressionNode(); - item->setFlags( QGraphicsItem::ItemIsSelectable | QGraphicsItem::ItemIsMovable ); - m_scene->addItem( item ); -} - void ExpressionEditor::onDeleteSelection() { QList< QGraphicsItem* > l = m_scene->selectedItems(); @@ -168,3 +168,24 @@ void ExpressionEditor::onUnLinkItems() } +void ExpressionEditor::onAddNode1() +{ + QGraphicsItem *item = new ExpressionNode( 1 ); + item->setFlags( QGraphicsItem::ItemIsSelectable | QGraphicsItem::ItemIsMovable ); + m_scene->addItem( item ); +} + +void ExpressionEditor::onAddNode2() +{ + QGraphicsItem *item = new ExpressionNode( 2 ); + item->setFlags( QGraphicsItem::ItemIsSelectable | QGraphicsItem::ItemIsMovable ); + m_scene->addItem( item ); +} + +void ExpressionEditor::onAddNode3() +{ + QGraphicsItem *item = new ExpressionNode( 3 ); + item->setFlags( QGraphicsItem::ItemIsSelectable | QGraphicsItem::ItemIsMovable ); + m_scene->addItem( item ); +} + diff --git a/code/studio/src/plugins/gui_editor/expression_editor.h b/code/studio/src/plugins/gui_editor/expression_editor.h index 00d347993..2346f42cf 100644 --- a/code/studio/src/plugins/gui_editor/expression_editor.h +++ b/code/studio/src/plugins/gui_editor/expression_editor.h @@ -35,11 +35,13 @@ protected: void contextMenuEvent( QContextMenuEvent *e ); private Q_SLOTS: - void onAddRect(); void onDeleteSelection(); void onSelectionChanged(); void onLinkItems(); void onUnLinkItems(); + void onAddNode1(); + void onAddNode2(); + void onAddNode3(); private: diff --git a/code/studio/src/plugins/gui_editor/expression_node.cpp b/code/studio/src/plugins/gui_editor/expression_node.cpp index 90d132d91..049acfbb9 100644 --- a/code/studio/src/plugins/gui_editor/expression_node.cpp +++ b/code/studio/src/plugins/gui_editor/expression_node.cpp @@ -97,16 +97,19 @@ private: -ExpressionNode::ExpressionNode( QGraphicsItem *parent ) : +ExpressionNode::ExpressionNode( int nodes, QGraphicsItem *parent ) : QGraphicsItem( parent ) { m_w = 100; m_h = 100; - createSlots(); + // Out nodes + m_links.push_back( NULL ); - for( int i = 0; i < 4; i++ ) + for( int i = 0; i < nodes; i++ ) m_links.push_back( NULL ); + + createSlots(); } ExpressionNode::~ExpressionNode() @@ -208,7 +211,7 @@ ExpressionLink* ExpressionNode::link( int slot ) const void ExpressionNode::mouseMoveEvent( QGraphicsSceneMouseEvent *e ) { - for( int i = 0; i < 4; i++ ) + for( int i = 0; i < m_links.count(); i++ ) { ExpressionLink *link = m_links[ i ]; if( link == NULL ) @@ -222,8 +225,9 @@ void ExpressionNode::mouseMoveEvent( QGraphicsSceneMouseEvent *e ) void ExpressionNode::createSlots() { - // First create the "Out" slot + int nodes = m_links.count(); + // First create the "Out" slot NodeSlotInfo info; info.tw = 25.0; info.th = 12.0; @@ -239,9 +243,10 @@ void ExpressionNode::createSlots() info.text = "Out"; m_slots.push_back( new NodeSlot( info ) ); + nodes--; // Then the rest of them - for( int i = 0; i < 3; i++ ) + for( int i = 0; i < nodes; i++ ) { x = m_w - info.wh; y = 30 + i * 20.0; @@ -258,7 +263,7 @@ void ExpressionNode::createSlots() void ExpressionNode::paintSlots( QPainter *painter ) { - for( int i = 0; i < 4; i++ ) + for( int i = 0; i < m_slots.count(); i++ ) { NodeSlot *slot = m_slots[ i ]; slot->paint( painter ); diff --git a/code/studio/src/plugins/gui_editor/expression_node.h b/code/studio/src/plugins/gui_editor/expression_node.h index 4fb92cbf4..efecea818 100644 --- a/code/studio/src/plugins/gui_editor/expression_node.h +++ b/code/studio/src/plugins/gui_editor/expression_node.h @@ -30,7 +30,7 @@ class NodeSlot; class ExpressionNode : public QGraphicsItem { public: - ExpressionNode( QGraphicsItem *parent = NULL ); + ExpressionNode( int nodes = 3, QGraphicsItem *parent = NULL ); ~ExpressionNode(); QRectF boundingRect() const;