VTK  9.1.0
QQuickVTKInteractorAdapter.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: QQuickVTKInteractorAdapter.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 #ifndef QQuickVTKInteractorAdapter_h
16 #define QQuickVTKInteractorAdapter_h
17 
18 // VTK includes
19 #include "QVTKInteractorAdapter.h"
20 #include "vtkGUISupportQtQuickModule.h" // for export macro
21 
22 // Qt includes
23 #include <QList> // for QList
24 #include <QPointer> // for QPointer
25 
26 // Forward declarations
27 class QEnterEvent;
28 class QEvent;
29 class QFocusEvent;
30 class QHoverEvent;
31 class QKeyEvent;
32 class QMouseEvent;
33 class QQuickItem;
34 class QQuickWindow;
35 class QWheelEvent;
37 class vtkRenderer;
38 
43 class VTKGUISUPPORTQTQUICK_EXPORT QQuickVTKInteractorAdapter : public QVTKInteractorAdapter
44 {
45  Q_OBJECT
47 
48 public:
49  QQuickVTKInteractorAdapter(QObject* parent = nullptr);
50 
51  void setQQuickWindow(QQuickWindow* win);
52 
53  void QueueHoverEvent(QQuickItem* item, QHoverEvent* e);
54  void QueueKeyEvent(QQuickItem* item, QKeyEvent* e);
55  void QueueFocusEvent(QQuickItem* item, QFocusEvent* e);
56  void QueueMouseEvent(QQuickItem* item, QMouseEvent* e);
57  void QueueGeometryChanged(const QRectF& newGeometry, const QRectF& oldGeometry);
58  void QueueWheelEvent(QQuickItem* item, QWheelEvent* e);
59 
61 
62  /*
63  * Map the event position to VTK display coordinates
64  * The mapping considers the following:
65  * - VTK widgets expect display coordinates, not viewport/local coordinates
66  * - vtkRenderWindowInteractor flips Y before processing the event.
67  * Because of the inherent flip in the superclass, the mapping does not flip Y implicitly.
68  * To map and flip Y, use mapEventPositionFlipY.
69  *
70  * \sa mapEventPositionFlipY
71  */
72  static QPointF mapEventPosition(QQuickItem* item, const QPointF& localPos);
73 
74  /*
75  * Map the event position to VTK display coordinates and flip the Y axis to switch the point from
76  * the Qt coordinate reference system to VTK's.
77  *
78  * \sa mapEventPosition
79  */
80  static QPointF mapEventPositionFlipY(QQuickItem* item, const QPointF& localPos);
81 
82 protected:
83  void QueueEvent(QEvent* e);
84 
85 private:
86  QPointer<QQuickWindow> m_qwindow;
87  QList<QEvent*> m_queuedEvents;
88 
89  Q_DISABLE_COPY(QQuickVTKInteractorAdapter)
90 };
91 
92 #endif // QQuickVTKInteractorAdapter_h
Intermediate class that handles relaying Qt events to VTK.
void setQQuickWindow(QQuickWindow *win)
void QueueWheelEvent(QQuickItem *item, QWheelEvent *e)
void ProcessEvents(vtkRenderWindowInteractor *interactor)
QQuickVTKInteractorAdapter(QObject *parent=nullptr)
static QPointF mapEventPosition(QQuickItem *item, const QPointF &localPos)
void QueueEvent(QEvent *e)
void QueueGeometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry)
void QueueHoverEvent(QQuickItem *item, QHoverEvent *e)
static QPointF mapEventPositionFlipY(QQuickItem *item, const QPointF &localPos)
void QueueKeyEvent(QQuickItem *item, QKeyEvent *e)
void QueueMouseEvent(QQuickItem *item, QMouseEvent *e)
void QueueFocusEvent(QQuickItem *item, QFocusEvent *e)
platform-independent render window interaction including picking and frame rate control.
abstract specification for renderers
Definition: vtkRenderer.h:73