Commit a9af5ea2 authored by Sankhesh Jhaveri's avatar Sankhesh Jhaveri 💬
Browse files

Allow widgets to change cursor when using QVTKOpenGLNativeWidget

parent f1324f7b
......@@ -102,7 +102,7 @@ public:
void SetTarget(QVTKOpenGLNativeWidget* target) { this->Target = target; }
void Execute(vtkObject*, unsigned long eventId, void* callData) override
void Execute(vtkObject* object, unsigned long eventId, void* callData) override
{
if (this->Target)
{
......@@ -144,6 +144,9 @@ public:
case vtkCommand::StartPickEvent:
this->Target->startEventCallback();
break;
case vtkCommand::CursorChangedEvent:
this->Target->cursorChangedCallback(object, eventId, nullptr, callData);
break;
}
}
}
......@@ -246,6 +249,8 @@ void QVTKOpenGLNativeWidget::SetRenderWindow(vtkGenericOpenGLRenderWindow* win)
this->RenderWindow->AddObserver(vtkCommand::WindowFrameEvent, this->Observer);
this->RenderWindow->AddObserver(vtkCommand::StartEvent, this->Observer);
this->RenderWindow->AddObserver(vtkCommand::StartPickEvent, this->Observer);
this->RenderWindow->AddObserver(vtkCommand::StartPickEvent, this->Observer);
this->RenderWindow->AddObserver(vtkCommand::CursorChangedEvent, this->Observer);
if (this->FBO)
{
......@@ -742,3 +747,54 @@ void QVTKOpenGLNativeWidget::mouseDoubleClickEvent(QMouseEvent* event)
this->RenderWindow->GetInteractor());
}
}
//-----------------------------------------------------------------------------
void QVTKOpenGLNativeWidget::cursorChangedCallback(vtkObject*, unsigned long,
void*, void* call_data)
{
if (!this->RenderWindow)
{
return;
}
int* cShape = reinterpret_cast<int*> (call_data);
if (!cShape)
{
return;
}
switch (*cShape)
{
case VTK_CURSOR_CROSSHAIR:
this->setCursor(QCursor(Qt::CrossCursor));
break;
case VTK_CURSOR_SIZEALL:
this->setCursor(QCursor(Qt::SizeAllCursor));
break;
case VTK_CURSOR_SIZENS:
this->setCursor(QCursor(Qt::SizeVerCursor));
break;
case VTK_CURSOR_SIZEWE:
this->setCursor(QCursor(Qt::SizeHorCursor));
break;
case VTK_CURSOR_SIZENE:
this->setCursor(QCursor(Qt::SizeBDiagCursor));
break;
case VTK_CURSOR_SIZENW:
this->setCursor(QCursor(Qt::SizeFDiagCursor));
break;
case VTK_CURSOR_SIZESE:
this->setCursor(QCursor(Qt::SizeFDiagCursor));
break;
case VTK_CURSOR_SIZESW:
this->setCursor(QCursor(Qt::SizeBDiagCursor));
break;
case VTK_CURSOR_HAND:
this->setCursor(QCursor(Qt::PointingHandCursor));
break;
case VTK_CURSOR_ARROW:
default:
this->setCursor(QCursor(Qt::ArrowCursor));
break;
}
}
......@@ -204,6 +204,13 @@ private slots:
*/
void startEventCallback();
/**
* callback for changing the cursor. Called when vtkGenericOpenGLRenderWindow
* fires the CursorChangedEvent.
*/
void cursorChangedCallback(vtkObject* caller, unsigned long vtk_event,
void* client_data, void* call_data);
protected:
bool event(QEvent* evt) Q_DECL_OVERRIDE;
void initializeGL() Q_DECL_OVERRIDE;
......
......@@ -593,9 +593,6 @@ void QVTKOpenGLWindow::ChangeCursor(vtkObject*, unsigned long, void*,
case VTK_CURSOR_CROSSHAIR:
this->setCursor(QCursor(Qt::CrossCursor));
break;
case VTK_CURSOR_ARROW:
this->setCursor(QCursor(Qt::ArrowCursor));
break;
case VTK_CURSOR_SIZEALL:
this->setCursor(QCursor(Qt::SizeAllCursor));
break;
......@@ -620,6 +617,7 @@ void QVTKOpenGLWindow::ChangeCursor(vtkObject*, unsigned long, void*,
case VTK_CURSOR_HAND:
this->setCursor(QCursor(Qt::PointingHandCursor));
break;
case VTK_CURSOR_ARROW:
default:
this->setCursor(QCursor(Qt::ArrowCursor));
break;
......
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