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