From 5e5fb49f122ef42b3dccfe46fda711aa7c348c11 Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Mon, 15 Sep 2014 01:25:01 +0200 Subject: [PATCH] Slot count can now be changed. --HG-- branch : dfighter-tools --- .../plugins/gui_editor/expression_editor.cpp | 25 ++++++++++++++++++ .../plugins/gui_editor/expression_editor.h | 1 + .../plugins/gui_editor/expression_node.cpp | 26 ++++++++++++++++--- .../src/plugins/gui_editor/expression_node.h | 2 ++ 4 files changed, 51 insertions(+), 3 deletions(-) diff --git a/code/studio/src/plugins/gui_editor/expression_editor.cpp b/code/studio/src/plugins/gui_editor/expression_editor.cpp index 54f878afa..45cd9c2d6 100644 --- a/code/studio/src/plugins/gui_editor/expression_editor.cpp +++ b/code/studio/src/plugins/gui_editor/expression_editor.cpp @@ -28,6 +28,7 @@ #include "expr_link_dlg.h" #include +#include ExpressionEditor::ExpressionEditor( QWidget *parent ) : QMainWindow( parent ) @@ -70,6 +71,12 @@ void ExpressionEditor::contextMenuEvent( QContextMenuEvent *e ) a = menu.addAction( "Remove" ); connect( a, SIGNAL( triggered() ), this, SLOT( onDeleteSelection() ) ); + if( m_selectionCount == 1 ) + { + a = menu.addAction( "Change slot count" ); + connect( a, SIGNAL( triggered() ), this, SLOT( onChangeSlotCount() ) ); + } + else if( m_selectionCount == 2 ) { a = menu.addAction( "Link" ); @@ -203,4 +210,22 @@ void ExpressionEditor::onItemDblClicked( QTreeWidgetItem *item ) addNode( name, 3 ); } +void ExpressionEditor::onChangeSlotCount() +{ + QList< QGraphicsItem* > l = m_scene->selectedItems(); + ExpressionNode *node = static_cast< ExpressionNode* >( l[ 0 ] ); + int oldc = node->slotCount(); + + int c = QInputDialog::getInt( this, + tr( "Change slot count" ), + tr( "Enter new slot count" ), + oldc, + 1, + 26 ); + + if( oldc == c ) + return; + + node->changeSlotCount( c ); +} diff --git a/code/studio/src/plugins/gui_editor/expression_editor.h b/code/studio/src/plugins/gui_editor/expression_editor.h index 5b17d091d..26493b8a0 100644 --- a/code/studio/src/plugins/gui_editor/expression_editor.h +++ b/code/studio/src/plugins/gui_editor/expression_editor.h @@ -44,6 +44,7 @@ private Q_SLOTS: void onAddNode2(); void onAddNode3(); void onItemDblClicked( QTreeWidgetItem *item ); + void onChangeSlotCount(); private: diff --git a/code/studio/src/plugins/gui_editor/expression_node.cpp b/code/studio/src/plugins/gui_editor/expression_node.cpp index 3098c6290..026857ee3 100644 --- a/code/studio/src/plugins/gui_editor/expression_node.cpp +++ b/code/studio/src/plugins/gui_editor/expression_node.cpp @@ -115,9 +115,7 @@ QGraphicsItem( parent ) ExpressionNode::~ExpressionNode() { clearLinks(); - - qDeleteAll( m_slots ); - m_slots.clear(); + clearSlots(); } QRectF ExpressionNode::boundingRect() const @@ -176,6 +174,28 @@ QPointF ExpressionNode::slotPos( int slot ) const return mp; } +void ExpressionNode::changeSlotCount( int count ) +{ + clearSlots(); + clearLinks(); + m_links.clear(); + + if( count <= 3 ) + m_h = 100.0; + else + m_h = 100.0 + 20.0 * ( count - 3 ); + + createSlots( count ); + + update(); +} + +void ExpressionNode::clearSlots() +{ + qDeleteAll( m_slots ); + m_slots.clear(); +} + bool ExpressionNode::slotEmpty( int slot ) const { if( m_links[ 0 ] == NULL ) diff --git a/code/studio/src/plugins/gui_editor/expression_node.h b/code/studio/src/plugins/gui_editor/expression_node.h index 7d236475a..cf49c212f 100644 --- a/code/studio/src/plugins/gui_editor/expression_node.h +++ b/code/studio/src/plugins/gui_editor/expression_node.h @@ -42,6 +42,8 @@ public: QPointF slotPos( int slot ) const; int slotCount() const{ return m_slots.count(); } + void changeSlotCount( int count ); + void clearSlots(); bool slotEmpty( int slot ) const;