mirror of
https://port.numenaute.org/aleajactaest/khanat-opennel-code.git
synced 2024-11-23 07:36:16 +00:00
Support for adding nodes with different slot count.
This commit is contained in:
parent
624578c024
commit
892ca16ae3
4 changed files with 46 additions and 18 deletions
|
@ -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 );
|
||||
}
|
||||
|
||||
|
|
|
@ -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:
|
||||
|
||||
|
|
|
@ -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 );
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue