CustusX  18.04
An IGT application
cxQVTKWidget.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: QVTKWidget.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 
16 /*=========================================================================
17 
18  Copyright 2004 Sandia Corporation.
19  Under the terms of Contract DE-AC04-94AL85000, there is a non-exclusive
20  license for use of this work by or on behalf of the
21  U.S. Government. Redistribution and use in source and binary forms, with
22  or without modification, are permitted provided that this Notice and any
23  statement of authorship are reproduced on all copies.
24 
25 =========================================================================*/
26 
27 /*========================================================================
28  For general information about using VTK and Qt, see:
29  http://www.trolltech.com/products/3rdparty/vtksupport.html
30 =========================================================================*/
31 
32 // .NAME QVTKWidget - Display a vtkRenderWindow in a Qt's QWidget.
33 // .SECTION Description
34 // QVTKWidget provides a way to display VTK data in a Qt widget.
35 
36 #ifndef CX_Q_VTK_WIDGET_H
37 #define CX_Q_VTK_WIDGET_H
38 
39 #include "cxResourceVisualizationExport.h"
40 
41 #include "QVTKInteractor.h"
42 #include <QWidget>
43 
44 class QVTKInteractorAdapter;
45 
46 class vtkRenderWindow;
47 
48 #include "vtkTDxConfigure.h" // defines VTK_USE_TDX
49 #ifdef VTK_USE_TDX
50 class vtkTDxDevice;
51 #endif
52 
53 #include "QVTKWin32Header.h"
54 
56 class cxResourceVisualization_EXPORT CXQVTKWidget : public QWidget
57 {
58  Q_OBJECT
59 
60 public:
62  CXQVTKWidget(QWidget* parent = NULL, Qt::WindowFlags f = 0);
64  virtual ~CXQVTKWidget();
65 
66  // Description:
67  // Set the vtk render window, if you wish to use your own vtkRenderWindow
68  virtual void SetRenderWindow(vtkRenderWindow*);
69 
70  // Description:
71  // Get the vtk render window.
72  virtual vtkRenderWindow* GetRenderWindow();
73 
74  // Description:
75  // Get the Qt/vtk interactor that was either created by default or set by the user
76  virtual QVTKInteractor* GetInteractor();
77 
78  // Description:
79  // Enum for additional event types supported.
80  // These events can be picked up by command observers on the interactor
82  {
83  ContextMenuEvent = QVTKInteractor::ContextMenuEvent,
84  DragEnterEvent = QVTKInteractor::DragEnterEvent,
85  DragMoveEvent = QVTKInteractor::DragMoveEvent,
86  DragLeaveEvent = QVTKInteractor::DragLeaveEvent,
87  DropEvent = QVTKInteractor::DropEvent
88  };
89 
90  // Description:
91  // Handle showing of the Widget
92  virtual void showEvent(QShowEvent*);
93 
94 // virtual QPaintEngine* paintEngine() const;
95 
96  // Description:
97  // Use a 3DConnexion device. Initial value is false.
98  // If VTK is not build with the TDx option, this is no-op.
99  // If VTK is build with the TDx option, and a device is not connected,
100  // a warning is emitted.
101  // It is must be called before the first Render to be effective, otherwise
102  // it is ignored.
103  void SetUseTDx(bool useTDx);
104  bool GetUseTDx() const;
105 
106 
107 Q_SIGNALS:
108  // Description:
109  // This signal will be emitted whenever a mouse event occurs
110  // within the QVTK window
111  void mouseEvent(QMouseEvent* event);
112 
113 public Q_SLOTS:
114 
115  // Description:
116  // Receive notification of the creation of the TDxDevice.
117  // Only relevant for Unix.
118 #ifdef VTK_USE_TDX
119  void setDevice(vtkTDxDevice *device);
120 #endif
121 
122 protected:
123  QPaintEngine* paintEngine() { return NULL; }
124 
125  // overloaded resize handler
126  virtual void resizeEvent(QResizeEvent* event);
127  // overloaded move handler
128  virtual void moveEvent(QMoveEvent* event);
129 // // overloaded paint handler
130  virtual void paintEvent(QPaintEvent* event);
131 
132  // overloaded mouse press handler
133  virtual void mousePressEvent(QMouseEvent* event);
134  // overloaded mouse move handler
135  virtual void mouseMoveEvent(QMouseEvent* event);
136  // overloaded mouse release handler
137  virtual void mouseReleaseEvent(QMouseEvent* event);
138  // overloaded key press handler
139  virtual void keyPressEvent(QKeyEvent* event);
140  // overloaded key release handler
141  virtual void keyReleaseEvent(QKeyEvent* event);
142  // overloaded enter event
143  virtual void enterEvent(QEvent*);
144  // overloaded leave event
145  virtual void leaveEvent(QEvent*);
146 #ifndef QT_NO_WHEELEVENT
147  // overload wheel mouse event
148  virtual void wheelEvent(QWheelEvent*);
149 #endif
150  // overload focus event
151  virtual void focusInEvent(QFocusEvent*);
152  // overload focus event
153  virtual void focusOutEvent(QFocusEvent*);
154  // overload Qt's event() to capture more keys
155  bool event( QEvent* e );
156 
157  // overload context menu event
158  virtual void contextMenuEvent(QContextMenuEvent*);
159  // overload drag enter event
160  virtual void dragEnterEvent(QDragEnterEvent*);
161  // overload drag move event
162  virtual void dragMoveEvent(QDragMoveEvent*);
163  // overload drag leave event
164  virtual void dragLeaveEvent(QDragLeaveEvent*);
165  // overload drop event
166  virtual void dropEvent(QDropEvent*);
167 
168  // the vtk render window
169  vtkRenderWindow* mRenWin;
170  bool UseTDx;
171 
172  // set up an X11 window based on a visual and colormap
173  // that VTK chooses
174  void x11_setup_window();
175 
176 #if defined(Q_WS_WIN)
177  bool winEvent(MSG* msg, long* result);
178 #endif
179 
180 protected:
181 
182  QVTKInteractorAdapter* mIrenAdapter;
183 
184 private:
186  CXQVTKWidget const& operator=(CXQVTKWidget const&);
188  CXQVTKWidget(const CXQVTKWidget&);
189 };
190 
191 #endif
QPaintEngine * paintEngine()
Definition: cxQVTKWidget.h:123
QVTKWidget displays a VTK window in a Qt window.
Definition: cxQVTKWidget.h:56
QVTKInteractorAdapter * mIrenAdapter
Definition: cxQVTKWidget.h:182
vtkRenderWindow * mRenWin
Definition: cxQVTKWidget.h:169