#include #include #include #include #include #include #include #include // ------------------------------------------------------------------------- cpBaseQtApplication::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 ); } // ------------------------------------------------------------------------- cpBaseQtApplication::Canvas:: ~Canvas( ) { } // ------------------------------------------------------------------------- cpBaseQtApplication:: Editor* cpBaseQtApplication::Canvas:: editor( ) { return( this->m_Editor ); } // ------------------------------------------------------------------------- const cpBaseQtApplication:: Editor* cpBaseQtApplication::Canvas:: editor( ) const { return( this->m_Editor ); } // ------------------------------------------------------------------------- void cpBaseQtApplication::Canvas:: keyPressEvent( QKeyEvent* event ) { static const int del_key = 16777223; switch( event->key( ) ) { case 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 } break; default: break; } // hctiws } // ------------------------------------------------------------------------- void cpBaseQtApplication::Canvas:: wheelEvent( QWheelEvent* event ) { this->_scaleView( std::pow( double( 2 ), event->delta( ) / double( 240 ) ) ); } // ------------------------------------------------------------------------- void cpBaseQtApplication::Canvas:: dragEnterEvent( QDragEnterEvent* event ) { const QMimeData* mime = event->mimeData( ); if( mime->hasFormat( "application/x-qabstractitemmodeldatalist" ) ) event->acceptProposedAction( ); } // ------------------------------------------------------------------------- void cpBaseQtApplication::Canvas:: dragLeaveEvent( QDragLeaveEvent* event ) { } // ------------------------------------------------------------------------- void cpBaseQtApplication::Canvas:: dragMoveEvent( QDragMoveEvent* event ) { } // ------------------------------------------------------------------------- void cpBaseQtApplication::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; QPointF p = this->mapToScene( event->pos( ) ); QList< QTreeWidgetItem* > items = tree->selectedItems( ); for( auto iIt = items.begin( ); iIt != items.end( ); ++iIt ) { auto parent = ( *iIt )->parent( ); if( parent != NULL ) { std::string category = parent->text( 0 ).toStdString( ); std::string filter = ( *iIt )->text( 0 ).toStdString( ); this->m_Editor->createFilter( category, filter, p ); } // fi } // rof } // ------------------------------------------------------------------------- void cpBaseQtApplication::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$