VTK
QVTKWidget2.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: QVTKWidget2.h
5 
6  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7  All rights reserved.
8  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9 
10  This software is distributed WITHOUT ANY WARRANTY; without even
11  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12  PURPOSE. See the above copyright notice for more information.
13 
14 =========================================================================*/
15 // .NAME QVTKWidget2 - Display a vtkRenderWindow in a Qt's QGLWidget.
16 // .SECTION Description
17 // QVTKWidget2 provides a way to display VTK data in a Qt OpenGL widget.
18 
19 #ifndef Q_VTK_WIDGET2_H
20 #define Q_VTK_WIDGET2_H
21 
22 #include "vtkGUISupportQtOpenGLModule.h" // For export macro
23 #include <QtOpenGL/QGLWidget>
24 #include "vtkSetGet.h"
25 #include "vtkSmartPointer.h"
26 #include "QVTKWin32Header.h"
27 
28 
32 class QVTKInteractor;
33 class vtkObject;
34 
35 #include "vtkTDxConfigure.h" // defines VTK_USE_TDX
36 #ifdef VTK_USE_TDX
37 class vtkTDxDevice;
38 #endif
39 
50 class VTKGUISUPPORTQTOPENGL_EXPORT QVTKWidget2 : public QGLWidget
51 {
52  Q_OBJECT
53  typedef QGLWidget Superclass;
54 public:
56  VTK_LEGACY(QVTKWidget2(QWidget* parent = nullptr, const QGLWidget* shareWidget=0, Qt::WindowFlags f = 0));
57  VTK_LEGACY(QVTKWidget2(vtkGenericOpenGLRenderWindow* w, QWidget* parent = nullptr, const QGLWidget* shareWidget=0, Qt::WindowFlags f = 0));
58  VTK_LEGACY(QVTKWidget2(QGLContext* ctx, QWidget* parent = nullptr, const QGLWidget* shareWidget=0, Qt::WindowFlags f = 0));
59  VTK_LEGACY(QVTKWidget2(const QGLFormat& fmt, QWidget* parent = nullptr, const QGLWidget* shareWidget=0, Qt::WindowFlags f = 0));
61  virtual ~QVTKWidget2();
62 
63  // Description:
64  // Set the vtk render window, if you wish to use your own vtkRenderWindow
65  virtual void SetRenderWindow(vtkGenericOpenGLRenderWindow*);
66 
67  // Description:
68  // Get the vtk render window.
69  virtual vtkGenericOpenGLRenderWindow* GetRenderWindow();
70 
71  // Description:
72  // Get the Qt/vtk interactor that was either created by default or set by the user
73  virtual QVTKInteractor* GetInteractor();
74 
75  // Description:
76  // Get the number of multisamples used for antialiasing
77  virtual int GetMultiSamples() const;
78 
79  // Description:
80  // Use a 3DConnexion device. Initial value is false.
81  // If VTK is not build with the TDx option, this is no-op.
82  // If VTK is build with the TDx option, and a device is not connected,
83  // a warning is emitted.
84  // It is must be called before the first Render to be effective, otherwise
85  // it is ignored.
86  void SetUseTDx(bool useTDx);
87  bool GetUseTDx() const;
88 
89  // Description:
90  // Make the swap buffers functions public
91  void setAutoBufferSwap(bool);
92  bool autoBufferSwap() const;
93 
94  static QGLFormat GetDefaultVTKFormat(vtkGenericOpenGLRenderWindow* w = nullptr);
95 
96 signals:
97  void mouseEvent(QMouseEvent* e);
98 
99 public Q_SLOTS:
100 
101  // Description:
102  // Receive notification of the creation of the TDxDevice.
103  // Only relevant for Unix.
104 #ifdef VTK_USE_TDX
105  void setDevice(vtkTDxDevice *device);
106 #endif
107 
108 protected Q_SLOTS:
109  // slot to make this vtk render window current
110  virtual void MakeCurrent();
111  // slot called when vtk wants to know if the context is current
112  virtual void IsCurrent(vtkObject* caller, unsigned long vtk_event, void* client_data, void* call_data);
113  // slot called when vtk wants to frame the window
114  virtual void Frame();
115  // slot called when vtk wants to start the render
116  virtual void Start();
117  // slot called when vtk wants to end the render
118  virtual void End();
119  // slot called when vtk wants to know if a window is direct
120  virtual void IsDirect(vtkObject* caller, unsigned long vtk_event, void* client_data, void* call_data);
121  // slot called when vtk wants to know if a window supports OpenGL
122  virtual void SupportsOpenGL(vtkObject* caller, unsigned long vtk_event, void* client_data, void* call_data);
123 
124 protected:
125  // overloaded initialize handler
126  virtual void initializeGL();
127  // overloaded resize handler
128  virtual void resizeGL(int, int);
129  // overloaded paint handler
130  virtual void paintGL();
131  // overloaded move handler
132  virtual void moveEvent(QMoveEvent* event);
133 
134  // overloaded touch events
135  virtual bool event(QEvent* e);
136  // overloaded mouse press handler
137  virtual void mousePressEvent(QMouseEvent* event);
138  // overloaded mouse move handler
139  virtual void mouseMoveEvent(QMouseEvent* event);
140  // overloaded mouse release handler
141  virtual void mouseReleaseEvent(QMouseEvent* event);
142  // overloaded key press handler
143  virtual void keyPressEvent(QKeyEvent* event);
144  // overloaded key release handler
145  virtual void keyReleaseEvent(QKeyEvent* event);
146  // overloaded enter event
147  virtual void enterEvent(QEvent*);
148  // overloaded leave event
149  virtual void leaveEvent(QEvent*);
150  // overload wheel mouse event
151  virtual void wheelEvent(QWheelEvent*);
152 
153  // overload context menu event
154  virtual void contextMenuEvent(QContextMenuEvent*);
155  // overload drag enter event
156  virtual void dragEnterEvent(QDragEnterEvent*);
157  // overload drag move event
158  virtual void dragMoveEvent(QDragMoveEvent*);
159  // overload drag leave event
160  virtual void dragLeaveEvent(QDragLeaveEvent*);
161  // overload drop event
162  virtual void dropEvent(QDropEvent*);
163 
164  // overload focus handling so tab key is passed to VTK
165  virtual bool focusNextPrevChild(bool);
166 
167  // the vtk render window
169  bool UseTDx;
170 
173 
174 private:
175  QVTKWidget2 & operator=(QVTKWidget2 const&) = delete;
176  QVTKWidget2(const QVTKWidget2&) = delete;
177 
178 };
179 
180 #endif
vtkSmartPointer< vtkEventQtSlotConnect > mConnect
Definition: QVTKWidget2.h:172
abstract base class for most VTK objects
Definition: vtkObject.h:59
display a vtkRenderWindow in Qt&#39;s QGLWidget.
Definition: QVTKWidget2.h:50
QVTKInteractorAdapter * mIrenAdapter
Definition: QVTKWidget2.h:171
an interactor for QVTKOpenGLNativeWidget (and QVTKWiget).
Manage connections between VTK events and Qt slots.
platform independent render window
vtkSmartPointer< vtkGenericOpenGLRenderWindow > mRenWin
Definition: QVTKWidget2.h:168