Commit 51974c4b authored by Sebastian Eichelbaum's avatar Sebastian Eichelbaum

[ADD #176] - the network editor now also accepts drops properly and forwards...

[ADD #176] - the network editor now also accepts drops properly and forwards the handling of these events to the main window.
parent 03e8b94f
......@@ -208,6 +208,10 @@ void WMainWindow::setupGUI()
{
m_networkEditor = new WQtNetworkEditor( this );
m_networkEditor->setFeatures( QDockWidget::AllDockWidgetFeatures );
// strangely, the QGraphics* objects do not properly forward drag/drop events. We need to explicitly handle them.
connect( m_networkEditor->getView(), SIGNAL( dragDrop( QDropEvent* ) ),
this, SLOT( handleDrop( QDropEvent* ) ) );
}
// the control panel instance is needed for the menu
......@@ -1154,9 +1158,7 @@ void WMainWindow::restoreMainGLWidgetSize()
m_mainGLWidget->setMaximumWidth( QWIDGETSIZE_MAX );
}
// Drag and drop functionality
void WMainWindow::dropEvent( QDropEvent *event )
void WMainWindow::handleDrop( QDropEvent* event )
{
if( event->mimeData()->hasUrls() )
{
......@@ -1218,14 +1220,19 @@ void WMainWindow::dropEvent( QDropEvent *event )
);
}
}
}
void WMainWindow::dropEvent( QDropEvent* event )
{
handleDrop( event );
QMainWindow::dropEvent( event );
}
void WMainWindow::dragMoveEvent( QDragMoveEvent *event )
bool WMainWindow::isDropAcceptable( const QMimeData* mimeData )
{
if( event->mimeData()->hasUrls() )
if( mimeData->hasUrls() )
{
foreach( QUrl url, event->mimeData()->urls() )
foreach( QUrl url, mimeData->urls() )
{
QString path = url.toLocalFile();
QFileInfo info( path );
......@@ -1240,36 +1247,28 @@ void WMainWindow::dragMoveEvent( QDragMoveEvent *event )
|| suffix == "owp"
|| suffix == "owproj" )
{
event->acceptProposedAction();
return;
return true;
}
}
}
return false;
}
void WMainWindow::dragMoveEvent( QDragMoveEvent* event )
{
if( WMainWindow::isDropAcceptable( event->mimeData() ) )
{
event->acceptProposedAction();
}
QMainWindow::dragMoveEvent( event );
}
void WMainWindow::dragEnterEvent( QDragEnterEvent *event )
void WMainWindow::dragEnterEvent( QDragEnterEvent* event )
{
if( event->mimeData()->hasUrls() )
if( WMainWindow::isDropAcceptable( event->mimeData() ) )
{
foreach( QUrl url, event->mimeData()->urls() )
{
QString path = url.toLocalFile();
QFileInfo info( path );
QString suffix = info.completeSuffix();
if( suffix == "cnt"
|| suffix == "edf"
|| suffix == "asc"
|| suffix == "nii"
|| suffix == "nii.gz"
|| suffix == "fib"
|| suffix == "owp"
|| suffix == "owproj" )
{
event->acceptProposedAction();
return;
}
}
event->acceptProposedAction();
}
QMainWindow::dragEnterEvent( event );
}
......
......@@ -177,6 +177,17 @@ public:
*/
void asyncProjectLoad( std::string filename );
/**
* This method checks whether a given drop event is acceptable.
* Several widgets in the GUI should support drag and drop. Unfortunately, not all widgets automatically push these events to the MainWindow.
* This is especially the case for QGraphics* based classes.
*
* \param mimeData the mime info of the dragged thing
*
* \return true if acceptable.
*/
static bool isDropAcceptable( const QMimeData* mimeData );
protected:
/**
* Setup the GUI by handling special modules. NavSlices for example setup several toolbar buttons.
......@@ -332,6 +343,13 @@ public slots:
*/
void handleLogLevelUpdate( unsigned int logLevel );
/**
* Handles the given drop. Use this in conjunction with \ref isDropAcceptable.
*
* \param event the event to handle
*/
void handleDrop( QDropEvent* event );
private:
/**
* The splash screen object opened on startup.
......
......@@ -209,7 +209,7 @@ void WQtControlPanel::connectSlots()
connect( m_roiTreeWidget, SIGNAL( itemClicked( QTreeWidgetItem*, int ) ), m_moduleTreeWidget, SLOT( clearSelection() ) );
connect( m_colormapper, SIGNAL( textureSelectionChanged( osg::ref_ptr< WGETexture3D > ) ),
this, SLOT( selectDataModule( osg::ref_ptr< WGETexture3D > ) ) );
connect( m_roiTreeWidget, SIGNAL( dragDrop() ), this, SLOT( handleDragDrop() ) );
connect( m_roiTreeWidget, SIGNAL( dragDrop() ), this, SLOT( handleRoiDragDrop() ) );
}
WQtSubjectTreeItem* WQtControlPanel::addSubject( std::string name )
......@@ -1251,7 +1251,7 @@ void WQtControlPanel::selectUpperMostEntry()
m_tiModules->setSelected( true );
}
void WQtControlPanel::handleDragDrop()
void WQtControlPanel::handleRoiDragDrop()
{
WLogger::getLogger()->addLogMessage( "Drag and drop handler not implemented yet!", "ControlPanel", LL_DEBUG );
}
......
......@@ -457,7 +457,7 @@ private slots:
/**
* function to notify the ROI manager of any drag&drop action in the ROI tree
*/
void handleDragDrop();
void handleRoiDragDrop();
};
#endif // WQTCONTROLPANEL_H
......@@ -59,11 +59,13 @@ WQtNetworkEditor::WQtNetworkEditor( WMainWindow* parent )
setObjectName( "Module Graph Dock" );
m_mainWindow = parent;
m_view = new WQtNetworkEditorView();
setAcceptDrops( true ); // enable drag and drop events
m_view = new WQtNetworkEditorView( this );
m_view->setMinimumSize( 20, 20 );
this->setFocusProxy( m_view );
m_scene = new WQtNetworkScene();
m_scene = new WQtNetworkScene( this );
m_scene->setSceneRect( m_scene->itemsBoundingRect() );
m_view->setScene( m_scene );
......@@ -469,3 +471,7 @@ WQtNetworkScene* WQtNetworkEditor::getScene()
return m_scene;
}
WQtNetworkEditorView* WQtNetworkEditor::getView()
{
return m_view;
}
......@@ -103,6 +103,13 @@ public:
* \return the scene
*/
WQtNetworkScene* getScene();
/**
* Get the view handling the scene.
*
* \return the view.
*/
WQtNetworkEditorView* getView();
protected:
/**
* Reference to the main window of the application.
......
......@@ -39,6 +39,7 @@ WQtNetworkEditorView::WQtNetworkEditorView( QWidget* parent ):
setCenter( QPointF( 0.0, 0.0 ) );
setResizeAnchor( QGraphicsView::AnchorUnderMouse );
setAcceptDrops( true );
}
void WQtNetworkEditorView::setCenter( const QPointF& centerPoint )
......@@ -180,3 +181,12 @@ void WQtNetworkEditorView::keyPressEvent( QKeyEvent *event )
}
QGraphicsView::keyPressEvent( event );
}
void WQtNetworkEditorView::dropEvent( QDropEvent* event )
{
// strangely this does not communicate down to WMainWindow although all parents are set properly. Even more strange is the fact that the
// dropEvent does not get fired inside the WQtNetworkScene.
emit dragDrop( event );
QGraphicsView::dropEvent( event );
}
......@@ -48,6 +48,13 @@ signals:
*/
void loadAction();
/**
* Emitted whenever the user drops something into the widget
*
* \param event event containing further info on the dropped item.
*/
void dragDrop( QDropEvent* event );
protected:
/**
* Sets the current centerpoint. Also updates the scene's center point.
......@@ -123,6 +130,13 @@ protected:
*/
void leaveEvent( QEvent* event );
/**
* Handles the drop event for a tree item.
*
* \param event the event.
*/
virtual void dropEvent( QDropEvent *event );
private:
/**
* The currently set centerpoint.
......
......@@ -33,14 +33,15 @@
#include <QtGui/QGraphicsItemGroup>
#include <QtGui/QGraphicsSceneMouseEvent>
#include "../WMainWindow.h"
#include "WQtNetworkItem.h"
#include "WQtNetworkPort.h"
#include "WQtNetworkScene.h"
#include "WQtNetworkScene.moc"
WQtNetworkScene::WQtNetworkScene()
: QGraphicsScene()
WQtNetworkScene::WQtNetworkScene( QObject* parent )
: QGraphicsScene( parent )
{
setItemIndexMethod( NoIndex );
// this takes care of the segfault: QGraphicsSceneFindItemBspTreeVisitor::visit
......@@ -51,3 +52,20 @@ WQtNetworkScene::~WQtNetworkScene()
{
}
void WQtNetworkScene::dragEnterEvent( QGraphicsSceneDragDropEvent* event )
{
// only ask the main window
if( WMainWindow::isDropAcceptable( event->mimeData() ) )
{
event->acceptProposedAction();
}
}
void WQtNetworkScene::dragMoveEvent( QGraphicsSceneDragDropEvent* event )
{
if( WMainWindow::isDropAcceptable( event->mimeData() ) )
{
event->acceptProposedAction();
}
}
......@@ -36,9 +36,11 @@ class WQtNetworkScene: public QGraphicsScene
Q_OBJECT
public:
/**
* Constructor
* Constructor.
*
* \param parent the parent which handles the scene
*/
explicit WQtNetworkScene();
explicit WQtNetworkScene( QObject* parent = NULL );
/**
* Destructor
......@@ -46,6 +48,20 @@ public:
virtual ~WQtNetworkScene();
protected:
/**
* Event handler when pulling something inside the scene.
*
* \param event the event.
*/
virtual void dragEnterEvent( QGraphicsSceneDragDropEvent* event );
/**
* Event handler when pulling something in the scene.
*
* \param event the event.
*/
virtual void dragMoveEvent( QGraphicsSceneDragDropEvent* event );
private:
};
#endif // WQTNETWORKSCENE_H
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment