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 keyPressEvent( QKeyEvent* event )
51 static const int del_key = 16777223;
52 if( event->key( ) == del_key )
54 auto _items = this->items( );
55 auto i = _items.begin( );
56 while( i != _items.end( ) )
58 if( ( *i )->isSelected( ) )
60 Block* b = dynamic_cast< Block* >( *i );
61 Connection* c = dynamic_cast< Connection* >( *i );
64 if( this->m_Editor->deleteFilter( b->namePort( ).toStdString( ) ) )
70 this->m_Editor->deleteConnection(
71 c->port1( )->block( )->namePort( ).toStdString( ),
72 c->port2( )->block( )->namePort( ).toStdString( ),
73 c->port1( )->name( ).toStdString( ),
74 c->port2( )->name( ).toStdString( )
90 // -------------------------------------------------------------------------
91 void cpPipelineEditor::Canvas::
92 wheelEvent( QWheelEvent* event )
95 std::pow( double( 2 ), event->delta( ) / double( 240 ) )
99 // -------------------------------------------------------------------------
100 void cpPipelineEditor::Canvas::
101 dragEnterEvent( QDragEnterEvent* event )
103 const QMimeData* mime = event->mimeData( );
104 if( mime->hasFormat( "application/x-qabstractitemmodeldatalist" ) )
105 event->acceptProposedAction( );
108 // -------------------------------------------------------------------------
109 void cpPipelineEditor::Canvas::
110 dragLeaveEvent( QDragLeaveEvent* event )
114 // -------------------------------------------------------------------------
115 void cpPipelineEditor::Canvas::
116 dragMoveEvent( QDragMoveEvent* event )
120 // -------------------------------------------------------------------------
121 void cpPipelineEditor::Canvas::
122 dropEvent( QDropEvent* event )
124 const QMimeData* mime = event->mimeData( );
125 if( !( mime->hasFormat( "application/x-qabstractitemmodeldatalist" ) ) )
128 event->acceptProposedAction( );
129 auto tree = dynamic_cast< QTreeWidget* >( event->source( ) );
133 QList< QTreeWidgetItem* > items = tree->selectedItems( );
134 for( auto iIt = items.begin( ); iIt != items.end( ); ++iIt )
135 this->m_Editor->createFilter(
136 ( *iIt )->text( 0 ).toStdString( ), this->mapToScene( event->pos( ) )
140 // -------------------------------------------------------------------------
141 void cpPipelineEditor::Canvas::
142 _scaleView( qreal scaleFactor )
144 qreal factor = this->transform( ).
145 scale( scaleFactor, scaleFactor ).
146 mapRect( QRectF( 0, 0, 1, 1 ) ).
148 if( factor < qreal( 0.07 ) || factor > qreal( 100 ) )
150 this->scale( scaleFactor, scaleFactor );