From cf42655519174dee2a2457f8962b23a444340d73 Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Sat, 13 Sep 2014 21:34:47 +0200 Subject: [PATCH] Paint the connection text, boxes separately. --- .../plugins/gui_editor/expression_editor.cpp | 2 - .../plugins/gui_editor/expression_link.cpp | 5 +- .../plugins/gui_editor/expression_node.cpp | 55 ++++++++++++++++++- .../src/plugins/gui_editor/expression_node.h | 2 + 4 files changed, 60 insertions(+), 4 deletions(-) diff --git a/code/studio/src/plugins/gui_editor/expression_editor.cpp b/code/studio/src/plugins/gui_editor/expression_editor.cpp index d942623ba..313af23b5 100644 --- a/code/studio/src/plugins/gui_editor/expression_editor.cpp +++ b/code/studio/src/plugins/gui_editor/expression_editor.cpp @@ -38,8 +38,6 @@ QWidget( parent ) m_scene = new QGraphicsScene( this ); m_ui.view->setScene( m_scene ); - m_scene->addSimpleText( "Hello" ); - connect( m_scene, SIGNAL( selectionChanged() ), this, SLOT( onSelectionChanged() ) ); } diff --git a/code/studio/src/plugins/gui_editor/expression_link.cpp b/code/studio/src/plugins/gui_editor/expression_link.cpp index c17ad8b30..1e7f7cf5f 100644 --- a/code/studio/src/plugins/gui_editor/expression_link.cpp +++ b/code/studio/src/plugins/gui_editor/expression_link.cpp @@ -58,7 +58,10 @@ void ExpressionLink::nodeMoved() void ExpressionLink::paint( QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget ) { - setPen( QPen( Qt::black ) ); + QPen p; + p.setColor( Qt::black ); + p.setWidth( 5 ); + setPen( p ); QGraphicsLineItem::paint( painter, option, widget ); } diff --git a/code/studio/src/plugins/gui_editor/expression_node.cpp b/code/studio/src/plugins/gui_editor/expression_node.cpp index 334fd3042..fae024096 100644 --- a/code/studio/src/plugins/gui_editor/expression_node.cpp +++ b/code/studio/src/plugins/gui_editor/expression_node.cpp @@ -40,6 +40,7 @@ QRectF ExpressionNode::boundingRect() const void ExpressionNode::paint( QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget ) { QBrush br; + QBrush boxBrush; QPen p; QColor c; @@ -62,7 +63,6 @@ void ExpressionNode::paint( QPainter *painter, const QStyleOptionGraphicsItem *o painter->setPen( p ); painter->drawText( header, Qt::AlignCenter, "Something" ); - if( option->state & QStyle::State_Selected ) { p.setStyle( Qt::DotLine ); @@ -73,6 +73,8 @@ void ExpressionNode::paint( QPainter *painter, const QStyleOptionGraphicsItem *o painter->setPen( p ); painter->drawRect( rect ); painter->drawRect( header ); + + paintConnections( painter ); } @@ -84,4 +86,55 @@ void ExpressionNode::mouseMoveEvent( QGraphicsSceneMouseEvent *e ) QGraphicsItem::mouseMoveEvent( e ); } +void ExpressionNode::paintConnections( QPainter *painter ) +{ + QRectF rect = boundingRect(); + QBrush boxBrush; + QPen p; + + boxBrush.setColor( Qt::black ); + boxBrush.setStyle( Qt::SolidPattern ); + p.setColor( Qt::black ); + + QRectF box = rect; + QRectF tbox = rect; + qreal wh = 10.0; + qreal tw = 25.0; + qreal th = 12.0; + + box.setTopLeft( QPoint( 0, rect.height() * 0.5 ) ); + box.setHeight( wh ); + box.setWidth( wh ); + + painter->fillRect( box, boxBrush ); + + tbox.setTopLeft( QPoint( 15, rect.height() * 0.50 ) ); + tbox.setHeight( th ); + tbox.setWidth( tw ); + painter->setPen( p ); + painter->drawText( tbox, Qt::AlignCenter, "Out" ); + + + for( int i = 0; i < 3; i++ ) + { + qreal x = rect.width() - wh; + qreal y = 30 + i * 20; + qreal tx = x - 5 - tw; + qreal ty = y - 2; + + box.setTopLeft( QPoint( x, y ) ); + box.setHeight( wh ); + box.setWidth( wh ); + + painter->fillRect( box, boxBrush ); + + tbox.setTopLeft( QPoint( tx, ty ) ); + tbox.setHeight( th ); + tbox.setWidth( tw ); + + QString text = 'A' + i; + painter->drawText( tbox, Qt::AlignRight, text ); + } +} + diff --git a/code/studio/src/plugins/gui_editor/expression_node.h b/code/studio/src/plugins/gui_editor/expression_node.h index a3bf701fd..6eebcb8a4 100644 --- a/code/studio/src/plugins/gui_editor/expression_node.h +++ b/code/studio/src/plugins/gui_editor/expression_node.h @@ -40,6 +40,8 @@ protected: void mouseMoveEvent( QGraphicsSceneMouseEvent *e ); private: + void paintConnections( QPainter *painter ); + ExpressionLink *m_link; };