4 #include "Connection.h"
7 #include <QDragEnterEvent>
11 // -------------------------------------------------------------------------
12 cpPipelineEditor::Canvas::
13 Canvas( QWidget* parent )
14 : QGraphicsView( parent )
16 QGraphicsScene* scene = new QGraphicsScene( this );
17 this->setScene( scene );
18 this->setRenderHint( QPainter::Antialiasing );
19 this->setAcceptDrops( true );
21 this->m_Editor = new Editor( this );
22 this->m_Editor->install( scene );
25 // -------------------------------------------------------------------------
26 cpPipelineEditor::Canvas::
31 // -------------------------------------------------------------------------
33 Editor* cpPipelineEditor::Canvas::
36 return( this->m_Editor );
39 // -------------------------------------------------------------------------
40 const cpPipelineEditor::
41 Editor* cpPipelineEditor::Canvas::
44 return( this->m_Editor );
47 // -------------------------------------------------------------------------
48 void cpPipelineEditor::Canvas::
49 wheelEvent( QWheelEvent* event )
52 std::pow( double( 2 ), event->delta( ) / double( 240 ) )
56 // -------------------------------------------------------------------------
57 void cpPipelineEditor::Canvas::
58 dragEnterEvent( QDragEnterEvent* event )
60 const QMimeData* mime = event->mimeData( );
61 if( mime->hasFormat( "application/x-qabstractitemmodeldatalist" ) )
62 event->acceptProposedAction( );
65 // -------------------------------------------------------------------------
66 void cpPipelineEditor::Canvas::
67 dragLeaveEvent( QDragLeaveEvent* event )
71 // -------------------------------------------------------------------------
72 void cpPipelineEditor::Canvas::
73 dragMoveEvent( QDragMoveEvent* event )
77 // -------------------------------------------------------------------------
78 void cpPipelineEditor::Canvas::
79 dropEvent( QDropEvent* event )
81 const QMimeData* mime = event->mimeData( );
82 if( !( mime->hasFormat( "application/x-qabstractitemmodeldatalist" ) ) )
85 event->acceptProposedAction( );
86 auto tree = dynamic_cast< QTreeWidget* >( event->source( ) );
90 QList< QTreeWidgetItem* > items = tree->selectedItems( );
91 for( auto iIt = items.begin( ); iIt != items.end( ); ++iIt )
92 this->m_Editor->createFilter(
93 ( *iIt )->text( 0 ).toStdString( ), this->mapToScene( event->pos( ) )
97 // -------------------------------------------------------------------------
98 void cpPipelineEditor::Canvas::
99 _scaleView( qreal scaleFactor )
101 qreal factor = this->transform( ).
102 scale( scaleFactor, scaleFactor ).
103 mapRect( QRectF( 0, 0, 1, 1 ) ).
105 if( factor < qreal( 0.07 ) || factor > qreal( 100 ) )
107 this->scale( scaleFactor, scaleFactor );