X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=lib%2FcpPipelineEditor%2FCanvas.cxx;fp=lib%2FcpPipelineEditor%2FCanvas.cxx;h=90f1285e3801e3479aab7eba9efd4621b8f76c32;hb=1b0022070ff3b5f80f6f8c8b87f73032f5685eaf;hp=0000000000000000000000000000000000000000;hpb=98390bcac544f7f3a6762ce812dda491213d6f13;p=cpPlugins.git diff --git a/lib/cpPipelineEditor/Canvas.cxx b/lib/cpPipelineEditor/Canvas.cxx new file mode 100644 index 0000000..90f1285 --- /dev/null +++ b/lib/cpPipelineEditor/Canvas.cxx @@ -0,0 +1,160 @@ +#include "Canvas.h" +#include "Editor.h" +#include "Block.h" +#include "Connection.h" +#include "Port.h" + +#include +#include +#include + +// ------------------------------------------------------------------------- +cpPipelineEditor::Canvas:: +Canvas( QWidget* parent ) + : QGraphicsView( parent ) +{ + QGraphicsScene* scene = new QGraphicsScene( this ); + this->setScene( scene ); + this->setRenderHint( QPainter::Antialiasing ); + this->setAcceptDrops( true ); + + this->m_Editor = new Editor( this ); + this->m_Editor->install( scene ); +} + +// ------------------------------------------------------------------------- +cpPipelineEditor::Canvas:: +~Canvas( ) +{ +} + +// ------------------------------------------------------------------------- +cpPipelineEditor:: +Editor* cpPipelineEditor::Canvas:: +editor( ) +{ + return( this->m_Editor ); +} + +// ------------------------------------------------------------------------- +const cpPipelineEditor:: +Editor* cpPipelineEditor::Canvas:: +editor( ) const +{ + return( this->m_Editor ); +} + +// ------------------------------------------------------------------------- +void cpPipelineEditor::Canvas:: +keyPressEvent( QKeyEvent* event ) +{ + static const int del_key = 16777223; + if( event->key( ) == del_key ) + { + auto _items = this->items( ); + auto i = _items.begin( ); + while( i != _items.end( ) ) + { + if( ( *i )->isSelected( ) ) + { + Block* b = dynamic_cast< Block* >( *i ); + Connection* c = dynamic_cast< Connection* >( *i ); + if( b != NULL ) + { + if( this->m_Editor->deleteFilter( b->namePort( ).toStdString( ) ) ) + delete b; + } + else if( c != NULL ) + { + if( + this->m_Editor->deleteConnection( + c->port1( )->block( )->namePort( ).toStdString( ), + c->port2( )->block( )->namePort( ).toStdString( ), + c->port1( )->name( ).toStdString( ), + c->port2( )->name( ).toStdString( ) + ) + ) + delete c; + + } // fi + i = _items.end( ); + } + else + i++; + + } // elihw + + } // fi +} + +// ------------------------------------------------------------------------- +void cpPipelineEditor::Canvas:: +wheelEvent( QWheelEvent* event ) +{ + this->_scaleView( + std::pow( double( 2 ), event->delta( ) / double( 240 ) ) + ); +} + +// ------------------------------------------------------------------------- +void cpPipelineEditor::Canvas:: +dragEnterEvent( QDragEnterEvent* event ) +{ + const QMimeData* mime = event->mimeData( ); + if( mime->hasFormat( "application/x-qabstractitemmodeldatalist" ) ) + event->acceptProposedAction( ); +} + +// ------------------------------------------------------------------------- +void cpPipelineEditor::Canvas:: +dragLeaveEvent( QDragLeaveEvent* event ) +{ +} + +// ------------------------------------------------------------------------- +void cpPipelineEditor::Canvas:: +dragMoveEvent( QDragMoveEvent* event ) +{ +} + +// ------------------------------------------------------------------------- +void cpPipelineEditor::Canvas:: +dropEvent( QDropEvent* event ) +{ + const QMimeData* mime = event->mimeData( ); + if( !( mime->hasFormat( "application/x-qabstractitemmodeldatalist" ) ) ) + return; + + event->acceptProposedAction( ); + auto tree = dynamic_cast< QTreeWidget* >( event->source( ) ); + if( tree == NULL ) + return; + + QList< QTreeWidgetItem* > items = tree->selectedItems( ); + for( auto iIt = items.begin( ); iIt != items.end( ); ++iIt ) + { + auto parent = ( *iIt )->parent( ); + if( parent != NULL ) + this->m_Editor->createFilter( + parent->text( 0 ).toStdString( ), + ( *iIt )->text( 0 ).toStdString( ), + this->mapToScene( event->pos( ) ) + ); + + } // rof +} + +// ------------------------------------------------------------------------- +void cpPipelineEditor::Canvas:: +_scaleView( qreal scaleFactor ) +{ + qreal factor = this->transform( ). + scale( scaleFactor, scaleFactor ). + mapRect( QRectF( 0, 0, 1, 1 ) ). + width( ); + if( factor < qreal( 0.07 ) || factor > qreal( 100 ) ) + return; + this->scale( scaleFactor, scaleFactor ); +} + +// eof - $RCSfile$