From 475bd91a0c6e6fbcae538db21e2d35d2316c1311 Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Fri, 12 Sep 2014 21:01:29 +0200 Subject: [PATCH] Added link action. --- .../plugins/gui_editor/expression_editor.cpp | 28 ++++++++++++++----- .../plugins/gui_editor/expression_editor.h | 4 ++- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/code/studio/src/plugins/gui_editor/expression_editor.cpp b/code/studio/src/plugins/gui_editor/expression_editor.cpp index e4d749dcd..2909b0835 100644 --- a/code/studio/src/plugins/gui_editor/expression_editor.cpp +++ b/code/studio/src/plugins/gui_editor/expression_editor.cpp @@ -28,7 +28,7 @@ QWidget( parent ) { m_ui.setupUi( this ); - m_hasSelection = false; + m_selectionCount = 0; m_scene = new QGraphicsScene( this ); m_ui.view->setScene( m_scene ); @@ -51,10 +51,16 @@ void ExpressionEditor::contextMenuEvent( QContextMenuEvent *e ) a = menu.addAction( "Add rect" ); connect( a, SIGNAL( triggered() ), this, SLOT( onAddRect() ) ); - if( m_hasSelection ) + if( m_selectionCount > 0 ) { a = menu.addAction( "Remove" ); connect( a, SIGNAL( triggered() ), this, SLOT( onDeleteSelection() ) ); + + if( m_selectionCount == 2 ) + { + a = menu.addAction( "Link" ); + connect( a, SIGNAL( triggered() ), this, SLOT( onLinkItems() ) ); + } } menu.exec( e->globalPos() ); @@ -78,11 +84,19 @@ void ExpressionEditor::onDeleteSelection() void ExpressionEditor::onSelectionChanged() { QList< QGraphicsItem* > l = m_scene->selectedItems(); - if( l.isEmpty() ) - m_hasSelection = false; - else - m_hasSelection = true; + m_selectionCount = l.count(); +} + +void ExpressionEditor::onLinkItems() +{ + QList< QGraphicsItem* > l = m_scene->selectedItems(); + QGraphicsItem *from = l[ 0 ]; + QGraphicsItem *to = l[ 1 ]; + + QGraphicsLineItem *line = new QGraphicsLineItem(); + line->setLine( QLineF( from->pos(), to->pos() ) ); + line->setPen( QPen( Qt::darkRed, 1.0 ) ); + m_scene->addItem( line ); } - diff --git a/code/studio/src/plugins/gui_editor/expression_editor.h b/code/studio/src/plugins/gui_editor/expression_editor.h index b73f8029f..70d2ad572 100644 --- a/code/studio/src/plugins/gui_editor/expression_editor.h +++ b/code/studio/src/plugins/gui_editor/expression_editor.h @@ -38,12 +38,14 @@ private Q_SLOTS: void onAddRect(); void onDeleteSelection(); void onSelectionChanged(); + void onLinkItems(); private: + Ui::ExpressionEditor m_ui; QGraphicsScene *m_scene; - bool m_hasSelection; + int m_selectionCount; }; #endif