|
|
@ -22,19 +22,92 @@
|
|
|
|
#include <QPainter>
|
|
|
|
#include <QPainter>
|
|
|
|
#include <QStyleOption>
|
|
|
|
#include <QStyleOption>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class NodeSlot
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
NodeSlot( const QPoint &tl, const QPoint &ttl, const QString &text )
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
m_tl = tl;
|
|
|
|
|
|
|
|
m_ttl = ttl;
|
|
|
|
|
|
|
|
m_text = text;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
m_tw = 25.0;
|
|
|
|
|
|
|
|
m_th = 12.0;
|
|
|
|
|
|
|
|
m_wh = 10.0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
~NodeSlot()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
QPointF pos() const{
|
|
|
|
|
|
|
|
QPointF p;
|
|
|
|
|
|
|
|
p.setX( m_tl.x() + m_wh / 2.0 );
|
|
|
|
|
|
|
|
p.setY( m_tl.y() + m_wh / 2.0 );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return p;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void paint( QPainter *painter )
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
QBrush boxBrush;
|
|
|
|
|
|
|
|
QPen p;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
boxBrush.setColor( Qt::black );
|
|
|
|
|
|
|
|
boxBrush.setStyle( Qt::SolidPattern );
|
|
|
|
|
|
|
|
p.setColor( Qt::black );
|
|
|
|
|
|
|
|
painter->setPen( p );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
QRectF box;
|
|
|
|
|
|
|
|
QRectF tbox;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
box.setTopLeft( m_tl );
|
|
|
|
|
|
|
|
box.setHeight( m_wh );
|
|
|
|
|
|
|
|
box.setWidth( m_wh );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
painter->fillRect( box, boxBrush );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tbox.setTopLeft( m_ttl );
|
|
|
|
|
|
|
|
tbox.setHeight( m_th );
|
|
|
|
|
|
|
|
tbox.setWidth( m_tw );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
painter->drawText( tbox, Qt::AlignRight, m_text );
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
QPoint m_tl;
|
|
|
|
|
|
|
|
QPoint m_ttl;
|
|
|
|
|
|
|
|
QString m_text;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
qreal m_th;
|
|
|
|
|
|
|
|
qreal m_tw;
|
|
|
|
|
|
|
|
qreal m_wh;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ExpressionNode::ExpressionNode( QGraphicsItem *parent ) :
|
|
|
|
ExpressionNode::ExpressionNode( QGraphicsItem *parent ) :
|
|
|
|
QGraphicsItem( parent )
|
|
|
|
QGraphicsItem( parent )
|
|
|
|
{
|
|
|
|
{
|
|
|
|
m_link = NULL;
|
|
|
|
m_link = NULL;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
m_w = 100;
|
|
|
|
|
|
|
|
m_h = 100;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
createSlots();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ExpressionNode::~ExpressionNode()
|
|
|
|
ExpressionNode::~ExpressionNode()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
qDeleteAll( m_slots );
|
|
|
|
|
|
|
|
m_slots.clear();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QRectF ExpressionNode::boundingRect() const
|
|
|
|
QRectF ExpressionNode::boundingRect() const
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return QRectF( 0, 0, 100, 100 );
|
|
|
|
return QRectF( 0, 0, m_w, m_h );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ExpressionNode::paint( QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget )
|
|
|
|
void ExpressionNode::paint( QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget )
|
|
|
@ -74,10 +147,20 @@ void ExpressionNode::paint( QPainter *painter, const QStyleOptionGraphicsItem *o
|
|
|
|
painter->drawRect( rect );
|
|
|
|
painter->drawRect( rect );
|
|
|
|
painter->drawRect( header );
|
|
|
|
painter->drawRect( header );
|
|
|
|
|
|
|
|
|
|
|
|
paintConnections( painter );
|
|
|
|
paintSlots( painter );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
QPointF ExpressionNode::slotPos( int slot ) const
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
const NodeSlot *s = m_slots[ slot ];
|
|
|
|
|
|
|
|
QPointF sp = s->pos();
|
|
|
|
|
|
|
|
QPointF mp = pos();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mp += sp;
|
|
|
|
|
|
|
|
return mp;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ExpressionNode::mouseMoveEvent( QGraphicsSceneMouseEvent *e )
|
|
|
|
void ExpressionNode::mouseMoveEvent( QGraphicsSceneMouseEvent *e )
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if( m_link != NULL )
|
|
|
|
if( m_link != NULL )
|
|
|
@ -86,54 +169,33 @@ void ExpressionNode::mouseMoveEvent( QGraphicsSceneMouseEvent *e )
|
|
|
|
QGraphicsItem::mouseMoveEvent( e );
|
|
|
|
QGraphicsItem::mouseMoveEvent( e );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ExpressionNode::paintConnections( QPainter *painter )
|
|
|
|
void ExpressionNode::createSlots()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
QRectF rect = boundingRect();
|
|
|
|
// First create the "Out" slot
|
|
|
|
QBrush boxBrush;
|
|
|
|
qreal x = 0.0;
|
|
|
|
QPen p;
|
|
|
|
qreal y = m_h * 0.5;
|
|
|
|
|
|
|
|
qreal tx = 10;
|
|
|
|
boxBrush.setColor( Qt::black );
|
|
|
|
qreal ty = m_h * 0.5 - 2;
|
|
|
|
boxBrush.setStyle( Qt::SolidPattern );
|
|
|
|
m_slots.push_back( new NodeSlot( QPoint( x, y ), QPoint( tx, ty ), "Out" ) );
|
|
|
|
p.setColor( Qt::black );
|
|
|
|
|
|
|
|
|
|
|
|
// Then the rest of them
|
|
|
|
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++ )
|
|
|
|
for( int i = 0; i < 3; i++ )
|
|
|
|
{
|
|
|
|
{
|
|
|
|
qreal x = rect.width() - wh;
|
|
|
|
x = m_w - 10;
|
|
|
|
qreal y = 30 + i * 20;
|
|
|
|
y = 30 + i * 20.0;
|
|
|
|
qreal tx = x - 5 - tw;
|
|
|
|
tx = x - 5 - 25.0;
|
|
|
|
qreal ty = y - 2;
|
|
|
|
ty = y - 2;
|
|
|
|
|
|
|
|
|
|
|
|
box.setTopLeft( QPoint( x, y ) );
|
|
|
|
m_slots.push_back( new NodeSlot( QPoint( x, y ), QPoint( tx, ty ), QString( 'A' + i ) ) );
|
|
|
|
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;
|
|
|
|
void ExpressionNode::paintSlots( QPainter *painter )
|
|
|
|
painter->drawText( tbox, Qt::AlignRight, text );
|
|
|
|
{
|
|
|
|
|
|
|
|
for( int i = 0; i < 4; i++ )
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
NodeSlot *slot = m_slots[ i ];
|
|
|
|
|
|
|
|
slot->paint( painter );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|