mirror of
https://port.numenaute.org/aleajactaest/khanat-opennel-code.git
synced 2024-11-10 09:19:01 +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;
|
QMenu menu;
|
||||||
|
|
||||||
QAction *a = NULL;
|
QAction *a = NULL;
|
||||||
a = menu.addAction( "Add rect" );
|
QMenu *mm = menu.addMenu( "Add node" );
|
||||||
connect( a, SIGNAL( triggered() ), this, SLOT( onAddRect() ) );
|
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 )
|
if( m_selectionCount > 0 )
|
||||||
{
|
{
|
||||||
|
@ -73,13 +80,6 @@ void ExpressionEditor::contextMenuEvent( QContextMenuEvent *e )
|
||||||
menu.exec( e->globalPos() );
|
menu.exec( e->globalPos() );
|
||||||
}
|
}
|
||||||
|
|
||||||
void ExpressionEditor::onAddRect()
|
|
||||||
{
|
|
||||||
QGraphicsItem *item = new ExpressionNode();
|
|
||||||
item->setFlags( QGraphicsItem::ItemIsSelectable | QGraphicsItem::ItemIsMovable );
|
|
||||||
m_scene->addItem( item );
|
|
||||||
}
|
|
||||||
|
|
||||||
void ExpressionEditor::onDeleteSelection()
|
void ExpressionEditor::onDeleteSelection()
|
||||||
{
|
{
|
||||||
QList< QGraphicsItem* > l = m_scene->selectedItems();
|
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 );
|
void contextMenuEvent( QContextMenuEvent *e );
|
||||||
|
|
||||||
private Q_SLOTS:
|
private Q_SLOTS:
|
||||||
void onAddRect();
|
|
||||||
void onDeleteSelection();
|
void onDeleteSelection();
|
||||||
void onSelectionChanged();
|
void onSelectionChanged();
|
||||||
void onLinkItems();
|
void onLinkItems();
|
||||||
void onUnLinkItems();
|
void onUnLinkItems();
|
||||||
|
void onAddNode1();
|
||||||
|
void onAddNode2();
|
||||||
|
void onAddNode3();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
|
|
@ -97,16 +97,19 @@ private:
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
ExpressionNode::ExpressionNode( QGraphicsItem *parent ) :
|
ExpressionNode::ExpressionNode( int nodes, QGraphicsItem *parent ) :
|
||||||
QGraphicsItem( parent )
|
QGraphicsItem( parent )
|
||||||
{
|
{
|
||||||
m_w = 100;
|
m_w = 100;
|
||||||
m_h = 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 );
|
m_links.push_back( NULL );
|
||||||
|
|
||||||
|
createSlots();
|
||||||
}
|
}
|
||||||
|
|
||||||
ExpressionNode::~ExpressionNode()
|
ExpressionNode::~ExpressionNode()
|
||||||
|
@ -208,7 +211,7 @@ ExpressionLink* ExpressionNode::link( int slot ) const
|
||||||
|
|
||||||
void ExpressionNode::mouseMoveEvent( QGraphicsSceneMouseEvent *e )
|
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 ];
|
ExpressionLink *link = m_links[ i ];
|
||||||
if( link == NULL )
|
if( link == NULL )
|
||||||
|
@ -222,8 +225,9 @@ void ExpressionNode::mouseMoveEvent( QGraphicsSceneMouseEvent *e )
|
||||||
|
|
||||||
void ExpressionNode::createSlots()
|
void ExpressionNode::createSlots()
|
||||||
{
|
{
|
||||||
// First create the "Out" slot
|
int nodes = m_links.count();
|
||||||
|
|
||||||
|
// First create the "Out" slot
|
||||||
NodeSlotInfo info;
|
NodeSlotInfo info;
|
||||||
info.tw = 25.0;
|
info.tw = 25.0;
|
||||||
info.th = 12.0;
|
info.th = 12.0;
|
||||||
|
@ -239,9 +243,10 @@ void ExpressionNode::createSlots()
|
||||||
info.text = "Out";
|
info.text = "Out";
|
||||||
|
|
||||||
m_slots.push_back( new NodeSlot( info ) );
|
m_slots.push_back( new NodeSlot( info ) );
|
||||||
|
nodes--;
|
||||||
|
|
||||||
// Then the rest of them
|
// Then the rest of them
|
||||||
for( int i = 0; i < 3; i++ )
|
for( int i = 0; i < nodes; i++ )
|
||||||
{
|
{
|
||||||
x = m_w - info.wh;
|
x = m_w - info.wh;
|
||||||
y = 30 + i * 20.0;
|
y = 30 + i * 20.0;
|
||||||
|
@ -258,7 +263,7 @@ void ExpressionNode::createSlots()
|
||||||
|
|
||||||
void ExpressionNode::paintSlots( QPainter *painter )
|
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 ];
|
NodeSlot *slot = m_slots[ i ];
|
||||||
slot->paint( painter );
|
slot->paint( painter );
|
||||||
|
|
|
@ -30,7 +30,7 @@ class NodeSlot;
|
||||||
class ExpressionNode : public QGraphicsItem
|
class ExpressionNode : public QGraphicsItem
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ExpressionNode( QGraphicsItem *parent = NULL );
|
ExpressionNode( int nodes = 3, QGraphicsItem *parent = NULL );
|
||||||
~ExpressionNode();
|
~ExpressionNode();
|
||||||
|
|
||||||
QRectF boundingRect() const;
|
QRectF boundingRect() const;
|
||||||
|
|
Loading…
Reference in a new issue