mirror of
https://port.numenaute.org/aleajactaest/khanat-opennel-code.git
synced 2024-11-10 17:29:10 +00:00
Added link action.
This commit is contained in:
parent
dc76072a90
commit
d905a2f237
2 changed files with 24 additions and 8 deletions
|
@ -28,7 +28,7 @@ QWidget( parent )
|
||||||
{
|
{
|
||||||
m_ui.setupUi( this );
|
m_ui.setupUi( this );
|
||||||
|
|
||||||
m_hasSelection = false;
|
m_selectionCount = 0;
|
||||||
|
|
||||||
m_scene = new QGraphicsScene( this );
|
m_scene = new QGraphicsScene( this );
|
||||||
m_ui.view->setScene( m_scene );
|
m_ui.view->setScene( m_scene );
|
||||||
|
@ -51,10 +51,16 @@ void ExpressionEditor::contextMenuEvent( QContextMenuEvent *e )
|
||||||
a = menu.addAction( "Add rect" );
|
a = menu.addAction( "Add rect" );
|
||||||
connect( a, SIGNAL( triggered() ), this, SLOT( onAddRect() ) );
|
connect( a, SIGNAL( triggered() ), this, SLOT( onAddRect() ) );
|
||||||
|
|
||||||
if( m_hasSelection )
|
if( m_selectionCount > 0 )
|
||||||
{
|
{
|
||||||
a = menu.addAction( "Remove" );
|
a = menu.addAction( "Remove" );
|
||||||
connect( a, SIGNAL( triggered() ), this, SLOT( onDeleteSelection() ) );
|
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() );
|
menu.exec( e->globalPos() );
|
||||||
|
@ -78,11 +84,19 @@ void ExpressionEditor::onDeleteSelection()
|
||||||
void ExpressionEditor::onSelectionChanged()
|
void ExpressionEditor::onSelectionChanged()
|
||||||
{
|
{
|
||||||
QList< QGraphicsItem* > l = m_scene->selectedItems();
|
QList< QGraphicsItem* > l = m_scene->selectedItems();
|
||||||
if( l.isEmpty() )
|
m_selectionCount = l.count();
|
||||||
m_hasSelection = false;
|
}
|
||||||
else
|
|
||||||
m_hasSelection = true;
|
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 );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -38,12 +38,14 @@ private Q_SLOTS:
|
||||||
void onAddRect();
|
void onAddRect();
|
||||||
void onDeleteSelection();
|
void onDeleteSelection();
|
||||||
void onSelectionChanged();
|
void onSelectionChanged();
|
||||||
|
void onLinkItems();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
Ui::ExpressionEditor m_ui;
|
Ui::ExpressionEditor m_ui;
|
||||||
QGraphicsScene *m_scene;
|
QGraphicsScene *m_scene;
|
||||||
|
|
||||||
bool m_hasSelection;
|
int m_selectionCount;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue