diff --git a/Modules/Qmitk/QmitkRenderWindow.cpp b/Modules/Qmitk/QmitkRenderWindow.cpp index 4d1d1ae195..f3d1a8910b 100644 --- a/Modules/Qmitk/QmitkRenderWindow.cpp +++ b/Modules/Qmitk/QmitkRenderWindow.cpp @@ -1,276 +1,305 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Language: C++ Date: $Date$ Version: $Revision$ Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ #include "QmitkRenderWindow.h" #include #include #include #include #include #include - +#include +#include #include "QmitkEventAdapter.h" #include "QmitkRenderWindowMenu.h" QmitkRenderWindow::QmitkRenderWindow(QWidget *parent, QString name, mitk::VtkPropRenderer* /*renderer*/, mitk::RenderingManager* renderingManager ) : QVTKWidget(parent) , m_ResendQtEvents(true) , m_MenuWidget(NULL) , m_MenuWidgetActivated(false) , m_LayoutIndex(0) { Initialize( renderingManager, name.toStdString().c_str() ); // Initialize mitkRenderWindowBase setFocusPolicy(Qt::StrongFocus); setMouseTracking(true); } QmitkRenderWindow::~QmitkRenderWindow() { Destroy(); // Destroy mitkRenderWindowBase } void QmitkRenderWindow::SetResendQtEvents(bool resend) { m_ResendQtEvents = resend; } void QmitkRenderWindow::SetLayoutIndex( unsigned int layoutIndex ) { m_LayoutIndex = layoutIndex; if( m_MenuWidget ) m_MenuWidget->SetLayoutIndex(layoutIndex); } unsigned int QmitkRenderWindow::GetLayoutIndex() { if( m_MenuWidget ) return m_MenuWidget->GetLayoutIndex(); else return 0; } void QmitkRenderWindow::LayoutDesignListChanged( int layoutDesignIndex ) { if( m_MenuWidget ) m_MenuWidget->UpdateLayoutDesignList( layoutDesignIndex ); } void QmitkRenderWindow::mousePressEvent(QMouseEvent *me) { mitk::MouseEvent myevent(QmitkEventAdapter::AdaptMouseEvent(m_Renderer, me)); this->mousePressMitkEvent(&myevent); QVTKWidget::mousePressEvent(me); if (m_ResendQtEvents) me->ignore(); } void QmitkRenderWindow::mouseReleaseEvent(QMouseEvent *me) { mitk::MouseEvent myevent(QmitkEventAdapter::AdaptMouseEvent(m_Renderer, me)); this->mouseReleaseMitkEvent(&myevent); QVTKWidget::mouseReleaseEvent(me); if (m_ResendQtEvents) me->ignore(); } void QmitkRenderWindow::mouseMoveEvent(QMouseEvent *me) { this->AdjustRenderWindowMenuVisibility( me->pos() ); mitk::MouseEvent myevent(QmitkEventAdapter::AdaptMouseEvent(m_Renderer, me)); this->mouseMoveMitkEvent(&myevent); QVTKWidget::mouseMoveEvent(me); //if (m_ResendQtEvents) me->ignore(); ////Show/Hide Menu Widget //if( m_MenuWidgetActivated ) //{ // //Show Menu Widget when mouse is inside of the define region of the top right corner // if( m_MenuWidget->GetLayoutIndex() <= QmitkRenderWindowMenu::CORONAL // && me->pos().x() >= 0 // && me->pos().y() <= m_MenuWidget->height() + 20 ) // { // m_MenuWidget->MoveWidgetToCorrectPos(1.0); // m_MenuWidget->show(); // m_MenuWidget->update(); // } // else if( m_MenuWidget->GetLayoutIndex() == QmitkRenderWindowMenu::THREE_D // && me->pos().x() >= this->width() - m_MenuWidget->width() - 20 // && me->pos().y() <= m_MenuWidget->height() + 20 ) // { // m_MenuWidget->MoveWidgetToCorrectPos(1.0); // m_MenuWidget->show(); // m_MenuWidget->update(); // } // //Hide Menu Widget when mouse is outside of the define region of the the right corner // else if( !m_MenuWidget->GetSettingsMenuVisibilty() ) // { // m_MenuWidget->hide(); // } //} } void QmitkRenderWindow::wheelEvent(QWheelEvent *we) { mitk::WheelEvent myevent(QmitkEventAdapter::AdaptWheelEvent(m_Renderer, we)); this->wheelMitkEvent(&myevent); QVTKWidget::wheelEvent(we); if (m_ResendQtEvents) we->ignore(); } void QmitkRenderWindow::keyPressEvent(QKeyEvent *ke) { QPoint cp = mapFromGlobal(QCursor::pos()); mitk::KeyEvent mke(QmitkEventAdapter::AdaptKeyEvent(m_Renderer, ke, cp)); this->keyPressMitkEvent(&mke); ke->accept(); QVTKWidget::keyPressEvent(ke); if (m_ResendQtEvents) ke->ignore(); } void QmitkRenderWindow::enterEvent( QEvent *e ) { MITK_DEBUG << "rw enter Event"; QVTKWidget::enterEvent(e); } void QmitkRenderWindow::DeferredHideMenu( ) { MITK_DEBUG << "QmitkRenderWindow::DeferredHideMenu"; if( m_MenuWidget ) m_MenuWidget->HideMenu(); } void QmitkRenderWindow::leaveEvent( QEvent *e ) { MITK_DEBUG << "QmitkRenderWindow::leaveEvent"; if( m_MenuWidget ) m_MenuWidget->smoothHide(); QVTKWidget::leaveEvent(e); } void QmitkRenderWindow::paintEvent(QPaintEvent* /*event*/) { //We are using our own interaction and thus have to call the rendering manually. this->GetRenderer()->GetRenderingManager()->RequestUpdate(GetRenderWindow()); } void QmitkRenderWindow::resizeEvent(QResizeEvent* event) { this->resizeMitkEvent(event->size().width(), event->size().height()); QVTKWidget::resizeEvent(event); emit resized(); } void QmitkRenderWindow::moveEvent( QMoveEvent* event ) { QVTKWidget::moveEvent( event ); // after a move the overlays need to be positioned emit moved(); } void QmitkRenderWindow::showEvent( QShowEvent* event ) { QVTKWidget::showEvent( event ); // this singleshot is necessary to have the overlays positioned correctly after initial show // simple call of moved() is no use here!! QTimer::singleShot(0, this ,SIGNAL( moved() ) ); } void QmitkRenderWindow::ActivateMenuWidget( bool state ) { m_MenuWidgetActivated = state; if(!m_MenuWidgetActivated && m_MenuWidget) { //disconnect Signal/Slot Connection disconnect( m_MenuWidget, SIGNAL( SignalChangeLayoutDesign(int) ), this, SLOT(OnChangeLayoutDesign(int)) ); disconnect( m_MenuWidget, SIGNAL( ResetView() ), this, SIGNAL( ResetView()) ); disconnect( m_MenuWidget, SIGNAL( ChangeCrosshairRotationMode(int) ), this, SIGNAL( ChangeCrosshairRotationMode(int)) ); delete m_MenuWidget; m_MenuWidget = 0; } else if(m_MenuWidgetActivated && !m_MenuWidget ) { //create render window MenuBar for split, close Window or set new setting. m_MenuWidget = new QmitkRenderWindowMenu(this,0,m_Renderer); m_MenuWidget->SetLayoutIndex( m_LayoutIndex ); //create Signal/Slot Connection connect( m_MenuWidget, SIGNAL( SignalChangeLayoutDesign(int) ), this, SLOT(OnChangeLayoutDesign(int)) ); connect( m_MenuWidget, SIGNAL( ResetView() ), this, SIGNAL( ResetView()) ); connect( m_MenuWidget, SIGNAL( ChangeCrosshairRotationMode(int) ), this, SIGNAL( ChangeCrosshairRotationMode(int)) ); } } void QmitkRenderWindow::AdjustRenderWindowMenuVisibility( const QPoint& /*pos*/ ) { if( m_MenuWidget ) { m_MenuWidget->ShowMenu(); m_MenuWidget->MoveWidgetToCorrectPos(1.0f); } } void QmitkRenderWindow::HideRenderWindowMenu( ) { // DEPRECATED METHOD } void QmitkRenderWindow::OnChangeLayoutDesign( int layoutDesignIndex ) { emit SignalLayoutDesignChanged( layoutDesignIndex ); } void QmitkRenderWindow::OnWidgetPlaneModeChanged( int mode ) { if( m_MenuWidget ) m_MenuWidget->NotifyNewWidgetPlanesMode( mode ); } void QmitkRenderWindow::FullScreenMode(bool state) { if( m_MenuWidget ) m_MenuWidget->ChangeFullScreenMode( state ); } + + +void QmitkRenderWindow::dragEnterEvent( QDragEnterEvent *event ) +{ + if (event->mimeData()->hasFormat("application/x-mitk-datanodes")) + { + event->accept(); + } +} + +void QmitkRenderWindow::dropEvent( QDropEvent * event ) +{ + if (event->mimeData()->hasFormat("application/x-mitk-datanodes")) + { + QString arg = QString(event->mimeData()->data("application/x-mitk-datanodes").data()); + QStringList listOfDataNodes = arg.split(","); + std::vector vectorOfDataNodePointers; + + for (int i = 0; i < listOfDataNodes.size(); i++) + { + long val = listOfDataNodes[i].toLong(); + mitk::DataNode* node = static_cast((void*)val); + vectorOfDataNodePointers.push_back(node); + } + + emit NodesDropped(this, vectorOfDataNodePointers); + } +} diff --git a/Modules/Qmitk/QmitkRenderWindow.h b/Modules/Qmitk/QmitkRenderWindow.h index fbca94c031..eccbcf833f 100644 --- a/Modules/Qmitk/QmitkRenderWindow.h +++ b/Modules/Qmitk/QmitkRenderWindow.h @@ -1,148 +1,160 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Language: C++ Date: $Date$ Version: $Revision$ Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ #ifndef QMITKRENDERWINDOW_H_HEADER_INCLUDED_C1C40D66 #define QMITKRENDERWINDOW_H_HEADER_INCLUDED_C1C40D66 #include #include "mitkRenderWindowBase.h" #include "QVTKWidget.h" #include "QmitkRenderWindowMenu.h" +class QDragEnterEvent; +class QDropEvent; + /** * \brief MITK implementation of the QVTKWidget * \ingroup Renderer */ class QMITK_EXPORT QmitkRenderWindow : public QVTKWidget , public mitk::RenderWindowBase { Q_OBJECT public: QmitkRenderWindow(QWidget *parent = 0, QString name = "unnamed renderwindow", mitk::VtkPropRenderer* renderer = NULL, mitk::RenderingManager* renderingManager = NULL); virtual ~QmitkRenderWindow(); /** * \brief Whether Qt events should be passed to parent (default: true) * * With introduction of the QVTKWidget the behaviour regarding Qt events changed. * QVTKWidget "accepts" Qt events like mouse clicks (i.e. set an "accepted" flag). * When this flag is set, Qt fininshed handling of this event -- otherwise it is * reached through to the widget's parent. * * This reaching through to the parent was implicitly required by QmitkMaterialWidget / QmitkMaterialShowCase. * * The default behaviour of QmitkRenderWindow is now to clear the "accepted" flag * of Qt events after they were handled by QVTKWidget. This way parents can also * handle events. * * If you don't want this behaviour, call SetResendQtEvents(true) on your render window. */ virtual void SetResendQtEvents(bool resend); // Set Layout Index to define the Layout Type void SetLayoutIndex( unsigned int layoutIndex ); // Get Layout Index to define the Layout Type unsigned int GetLayoutIndex(); //MenuWidget need to update the Layout Design List when Layout had changed void LayoutDesignListChanged( int layoutDesignIndex ); void HideRenderWindowMenu( ); //Activate or Deactivate MenuWidget. void ActivateMenuWidget( bool state ); bool GetActivateMenuWidgetFlag() { return m_MenuWidgetActivated; } // Get it from the QVTKWidget parent virtual vtkRenderWindow* GetVtkRenderWindow() { return GetRenderWindow();} virtual vtkRenderWindowInteractor* GetVtkRenderWindowInteractor() { return NULL;} void FullScreenMode( bool state ); protected: // overloaded move handler virtual void moveEvent( QMoveEvent* event ); // overloaded show handler void showEvent( QShowEvent* event ); // overloaded resize handler virtual void resizeEvent(QResizeEvent* event); // overloaded paint handler virtual void paintEvent(QPaintEvent* event); // overloaded mouse press handler virtual void mousePressEvent(QMouseEvent* event); // overloaded mouse move handler virtual void mouseMoveEvent(QMouseEvent* event); // overloaded mouse release handler virtual void mouseReleaseEvent(QMouseEvent* event); // overloaded key press handler virtual void keyPressEvent(QKeyEvent* event); // overloaded enter handler virtual void enterEvent(QEvent*); // overloaded leave handler virtual void leaveEvent(QEvent*); + /// \brief Simply says we accept the event type. + virtual void dragEnterEvent( QDragEnterEvent *event ); + + /// \brief If the dropped type is application/x-mitk-datanodes we process the request by converting to mitk::DataNode pointers and emitting the NodesDropped signal. + virtual void dropEvent( QDropEvent * event ); + #ifndef QT_NO_WHEELEVENT // overload wheel mouse event virtual void wheelEvent(QWheelEvent*); #endif void AdjustRenderWindowMenuVisibility( const QPoint& pos ); signals: void ResetView(); // \brief int parameters are enum from QmitkStdMultiWidget void ChangeCrosshairRotationMode(int); void SignalLayoutDesignChanged( int layoutDesignIndex ); void moved(); void resized(); + /// \brief Emits a signal to say that this window has had the following nodes dropped on it. + void NodesDropped(QmitkRenderWindow *thisWindow, std::vector nodes); + protected slots: void OnChangeLayoutDesign(int layoutDesignIndex); void OnWidgetPlaneModeChanged( int ); void DeferredHideMenu(); private: bool m_ResendQtEvents; QmitkRenderWindowMenu* m_MenuWidget; bool m_MenuWidgetActivated; unsigned int m_LayoutIndex; }; #endif