this->m_SelectedColor = Qt::darkYellow;
this->m_NotSelectedColor = Qt::darkGreen;
- QPainterPath p;
- p.addRoundedRect( -50, -50, 50, 50, 5, 5 );
-
- this->setPath( p );
- this->setPen( QPen( this->m_NotSelectedColor ) );
- this->setBrush( this->m_NotSelectedColor );
- this->setFlag( QGraphicsItem::ItemIsMovable );
- this->setFlag( QGraphicsItem::ItemIsSelectable );
+ /* TODO
+ QPainterPath p;
+ p.addRect( -50, -50, 50, 50 );
+
+ this->setPath( p );
+ this->setPen( QPen( this->m_NotSelectedColor ) );
+ this->setBrush( this->m_NotSelectedColor );
+ this->setFlag( QGraphicsItem::ItemIsMovable );
+ this->setFlag( QGraphicsItem::ItemIsSelectable );
+ */
}
// -------------------------------------------------------------------------
// @author Leonardo Florez-Valencia (florez-l@javeriana.edu.co)
// -------------------------------------------------------------------------
-
-#include <iostream>
-
-
-
-
-
#include <cpPipelineEditor/Canvas.h>
#include <cpPipelineEditor/FilterBlock.h>
#include <cpPipelineEditor/FunctorBlock.h>
// -------------------------------------------------------------------------
cpPipelineEditor::Canvas::
Canvas( QWidget* parent )
- : Superclass( parent )
+ : Superclass( parent ),
+ m_DraggedBlock( NULL )
{
this->m_Scene = new QGraphicsScene( this );
this->setScene( this->m_Scene );
new_block = new FunctorBlock( NULL, this->m_Scene );
else if( block_type == "Widgets" )
new_block = new WidgetBlock( NULL, this->m_Scene );
+ new_block->setPos( 0, 0 );
return( new_block );
}
{
const QMimeData* mime = event->mimeData( );
if( mime->hasFormat( "application/x-qabstractitemmodeldatalist" ) )
+ {
+ if( this->m_DraggedBlock == NULL )
+ {
+ QTreeWidget* tree = dynamic_cast< QTreeWidget* >( event->source( ) );
+ if( tree != NULL )
+ {
+ // Process dropped data
+ QList< QTreeWidgetItem* > items = tree->selectedItems( );
+ for( QTreeWidgetItem* item : items )
+ {
+ std::string name = "";
+ QTreeWidgetItem* p = item;
+ while( p != NULL )
+ {
+ name += p->text( 0 ).toStdString( ) + "@";
+ p = p->parent( );
+
+ } // elihw
+ name.resize( name.size( ) - 1 );
+
+ // Create block
+ this->m_DraggedBlock = this->createBlock( name );
+ QPoint drop_pos = event->pos( );
+ QPointF scene_pos = this->mapToScene( drop_pos );
+ this->m_DraggedBlock->setPos( scene_pos );
+
+ } // rof
+
+ } // fi
+
+ } // fi
event->acceptProposedAction( );
+ }
+ else
+ event->ignore( );
}
// -------------------------------------------------------------------------
void cpPipelineEditor::Canvas::
dragLeaveEvent( QDragLeaveEvent* event )
{
+ if( this->m_DraggedBlock != NULL )
+ {
+ delete this->m_DraggedBlock;
+ this->m_DraggedBlock = NULL;
+
+ } // fi
+ event->accept( );
}
// -------------------------------------------------------------------------
void cpPipelineEditor::Canvas::
dragMoveEvent( QDragMoveEvent* event )
{
+ const QMimeData* mime = event->mimeData( );
+ if( mime->hasFormat( "application/x-qabstractitemmodeldatalist" ) )
+ {
+ if( this->m_DraggedBlock != NULL )
+ {
+ QPoint drop_pos = event->pos( );
+ QPointF scene_pos = this->mapToScene( drop_pos );
+ this->m_DraggedBlock->setPos( scene_pos );
+
+ } // fi
+ event->acceptProposedAction( );
+ }
+ else
+ event->ignore( );
}
// -------------------------------------------------------------------------
void cpPipelineEditor::Canvas::
dropEvent( QDropEvent* event )
{
- // Get dropped data
const QMimeData* mime = event->mimeData( );
- if( !( mime->hasFormat( "application/x-qabstractitemmodeldatalist" ) ) )
- return;
- event->acceptProposedAction( );
- QTreeWidget* tree = dynamic_cast< QTreeWidget* >( event->source( ) );
- if( tree == NULL )
- return;
-
- // Process dropped data
- QList< QTreeWidgetItem* > items = tree->selectedItems( );
- for( QTreeWidgetItem* item : items )
+ if( mime->hasFormat( "application/x-qabstractitemmodeldatalist" ) )
{
- std::string name = "";
- QTreeWidgetItem* p = item;
- while( p != NULL )
- {
- name += p->text( 0 ).toStdString( ) + "@";
- p = p->parent( );
-
- } // elihw
- name.resize( name.size( ) - 1 );
-
- // Create block
- Block* b = this->createBlock( name );
-
- } // rof
+ this->m_DraggedBlock = NULL;
+ event->acceptProposedAction( );
+ }
+ else
+ event->ignore( );
}
// eof - $RCSfile$