Commit c6eb8803 authored by Sankhesh Jhaveri's avatar Sankhesh Jhaveri 💬 Committed by Kitware Robot
Browse files

Merge topic 'qvtkopenglwidget_cursor'

a9af5ea2 Allow widgets to change cursor when using QVTKOpenGLNativeWidget
f1324f7b Allow widgets to change cursor when using QVTKOpenGLWindow
67efbc03

 Invoke CursorChangedEvent to from vtkGenericOpenGLRenderWindow
Acked-by: Kitware Robot's avatarKitware Robot <kwrobot@kitware.com>
Acked-by: Mathieu Westphal's avatarMathieu Westphal <mathieu.westphal@kitware.com>
Merge-request: !4795
parents ea4183d8 a9af5ea2
......@@ -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;
......
......@@ -156,6 +156,7 @@ void QVTKOpenGLWindow::SetRenderWindow(vtkGenericOpenGLRenderWindow* w)
this->EventSlotConnector->Connect(this->RenderWindow, vtkCommand::WindowSupportsOpenGLEvent, this, SLOT(SupportsOpenGL(vtkObject*, unsigned long, void*, void*)));
this->EventSlotConnector->Connect(this->RenderWindow, vtkCommand::WindowStereoTypeChangedEvent, this, SLOT(UpdateStereoType(vtkObject*, unsigned long, void*, void*)));
this->EventSlotConnector->Connect(this->RenderWindow, vtkCommand::WindowResizeEvent, this, SLOT(ResizeToVTKWindow()));
this->EventSlotConnector->Connect(this->RenderWindow, vtkCommand::CursorChangedEvent, this, SLOT(ChangeCursor(vtkObject*, unsigned long, void*, void*)));
}
//-----------------------------------------------------------------------------
......@@ -571,3 +572,54 @@ bool QVTKOpenGLWindow::isCurrent()
return QOpenGLContext::currentContext() == this->context();
}
//-----------------------------------------------------------------------------
void QVTKOpenGLWindow::ChangeCursor(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;
}
}
......@@ -188,6 +188,12 @@ public slots:
virtual void UpdateStereoType(vtkObject* caller, unsigned long vtk_event,
void* client_data, void* call_data);
/*
* slot to change the cursor
*/
virtual void ChangeCursor(vtkObject* caller, unsigned long vtk_event,
void* client_data, void* call_data);
/**
* slot to process events coming from the widget containing this window
*/
......
......@@ -12,14 +12,14 @@
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
#include "vtkGenericOpenGLRenderWindow.h"
#include "vtkObjectFactory.h"
#include "vtkRendererCollection.h"
#include "vtkOpenGLRenderer.h"
#include "vtkOpenGLRenderWindow.h"
#include "vtkCommand.h"
#include "vtkObjectFactory.h"
#include "vtkOpenGLError.h"
#include "vtkOpenGLRenderWindow.h"
#include "vtkOpenGLRenderer.h"
#include "vtkRendererCollection.h"
vtkStandardNewMacro(vtkGenericOpenGLRenderWindow);
......@@ -38,10 +38,10 @@ vtkGenericOpenGLRenderWindow::~vtkGenericOpenGLRenderWindow()
{
this->Finalize();
vtkRenderer *ren;
vtkRenderer* ren;
vtkCollectionSimpleIterator rit;
this->Renderers->InitTraversal(rit);
while ( (ren = this->Renderers->GetNextRenderer(rit)) )
while ((ren = this->Renderers->GetNextRenderer(rit)))
{
ren->SetRenderWindow(nullptr);
}
......@@ -54,8 +54,9 @@ void vtkGenericOpenGLRenderWindow::PrintSelf(ostream& os, vtkIndent indent)
float vtkGenericOpenGLRenderWindow::GetMaximumHardwareLineWidth()
{
return this->ForceMaximumHardwareLineWidth > 0 ? this->ForceMaximumHardwareLineWidth
: this->Superclass::GetMaximumHardwareLineWidth();
return this->ForceMaximumHardwareLineWidth > 0
? this->ForceMaximumHardwareLineWidth
: this->Superclass::GetMaximumHardwareLineWidth();
}
void vtkGenericOpenGLRenderWindow::SetFrontBuffer(unsigned int b)
......@@ -114,7 +115,8 @@ bool vtkGenericOpenGLRenderWindow::IsCurrent()
int vtkGenericOpenGLRenderWindow::SupportsOpenGL()
{
this->InvokeEvent(vtkCommand::WindowSupportsOpenGLEvent, &this->SupportsOpenGLStatus);
this->InvokeEvent(vtkCommand::WindowSupportsOpenGLEvent,
&this->SupportsOpenGLStatus);
return this->SupportsOpenGLStatus;
}
......@@ -133,7 +135,6 @@ void* vtkGenericOpenGLRenderWindow::GetGenericWindowId()
return nullptr;
}
void vtkGenericOpenGLRenderWindow::SetDisplayId(void*)
{
}
......@@ -247,11 +248,26 @@ void vtkGenericOpenGLRenderWindow::Render()
void vtkGenericOpenGLRenderWindow::SetIsPicking(vtkTypeBool isPicking)
{
vtkDebugMacro(<< this->GetClassName() << " (" << this << "): setting IsPicking to " << isPicking); \
vtkDebugMacro(<< this->GetClassName() << " (" << this
<< "): setting IsPicking to " << isPicking);
if (this->IsPicking != isPicking)
{
this->IsPicking = isPicking;
this->Modified();
this->InvokeEvent(this->IsPicking ? vtkCommand::StartPickEvent : vtkCommand::EndPickEvent, nullptr);
this->InvokeEvent(this->IsPicking ? vtkCommand::StartPickEvent
: vtkCommand::EndPickEvent,
nullptr);
}
}
void vtkGenericOpenGLRenderWindow::SetCurrentCursor(int cShape)
{
vtkDebugMacro(<< this->GetClassName() << " (" << this
<< "): setting current Cursor to " << cShape);
if (this->GetCurrentCursor() != cShape)
{
this->CurrentCursor = cShape;
this->Modified();
this->InvokeEvent(vtkCommand::CursorChangedEvent, &cShape);
}
}
......@@ -162,6 +162,11 @@ public:
*/
void SetIsPicking(vtkTypeBool isPicking) override;
/**
* Overriden to invoke vtkCommand::CursorChangedEvent
*/
void SetCurrentCursor(int cShape) override;
protected:
int DirectStatus;
int SupportsOpenGLStatus;
......
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