Emdee
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
stereoviewport.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the Qt3D module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #ifndef VIEWPORT_H
43 #define VIEWPORT_H
44 
45 #include <QtQuick/qquickpainteditem.h>
46 
47 #include "qquickitem3d.h"
48 #include "qquickviewport.h"
49 
50 QT_BEGIN_NAMESPACE
51 
53 class QGLCamera;
54 class QGLLightModel;
55 class QGLLightParameters;
56 class QQuickEffect;
57 class PickEvent;
58 
59 class StereoViewport : public QQuickPaintedItem, public QQuickViewport
60 {
61  Q_OBJECT
62  Q_ENUMS(RenderMode)
63  Q_ENUMS(StereoType)
64  Q_PROPERTY(QColor fillColor READ fillColor WRITE setFillColor NOTIFY viewportChanged)
66  Q_PROPERTY(bool picking READ picking WRITE setPicking NOTIFY viewportChanged)
67  Q_PROPERTY(bool showPicking READ showPicking WRITE setShowPicking NOTIFY viewportChanged)
69  Q_PROPERTY(bool navigation READ navigation WRITE setNavigation NOTIFY viewportChanged)
70  Q_PROPERTY(bool fovzoom READ fovzoom WRITE setFovzoom NOTIFY viewportChanged)
71  Q_PROPERTY(bool blending READ blending WRITE setBlending NOTIFY viewportChanged)
72  Q_PROPERTY(QGLCamera *camera READ camera WRITE setCamera)
73  Q_PROPERTY(QGLLightParameters *light READ light WRITE setLight NOTIFY viewportChanged)
74  Q_PROPERTY(QGLLightModel *lightModel READ lightModel WRITE setLightModel NOTIFY viewportChanged)
75  Q_PROPERTY(bool antialiasing READ antialiasing WRITE setAntialiasing NOTIFY antialiasingChanged)
77 
78 public:
80  {
84  };
85 
87  {
98  };
99 
100  StereoViewport(QQuickItem *parent = 0);
101  ~StereoViewport();
102 
103  QColor fillColor() const;
104  void setFillColor(const QColor &);
105 
106  bool picking() const;
107  void setPicking(bool value);
108 
109  bool showPicking() const;
110  void setShowPicking(bool value);
111 
112  bool showSceneGraph() const;
113  void setShowSceneGraph(bool show);
114 
115  bool navigation() const;
116  void setNavigation(bool value);
117 
118  bool fovzoom() const;
119  void setFovzoom(bool value);
120 
121  bool blending() const;
122  void setBlending(bool value);
123 
124  bool antialiasing() const;
125  void setAntialiasing(bool value);
126 
127  QGLCamera *camera() const;
128  void setCamera(QGLCamera *value);
129 
130  QGLLightParameters *light() const;
131  void setLight(QGLLightParameters *value);
132 
133  QGLLightModel *lightModel() const;
134  void setLightModel(QGLLightModel *value);
135 
136  int registerPickableObject(QObject *obj);
137  virtual void registerEarlyDrawObject(QObject *obj, int order);
138 
139  void paint(QPainter *painter);
140 
141  RenderMode renderMode() const;
142  void setRenderMode(RenderMode mode);
143 
144  StereoType stereoType() const;
145 
146 Q_SIGNALS:
147  void viewportChanged();
148  void showSceneGraphChanged();
149  void antialiasingChanged();
150 
151  void stereoTypeChanged(StereoType arg);
152 
153 public Q_SLOTS:
154  void update3d();
155 
156  void setStereoType(StereoType arg);
157 
158 private Q_SLOTS:
159  void cameraChanged();
160  void beforeRendering();
161  void sceneGraphInitialized();
162  void objectForPoint();
163  void canvasDeleted();
164 
165 protected:
166  void mousePressEvent(QMouseEvent *event);
167  void mouseReleaseEvent(QMouseEvent *event);
168  void mouseDoubleClickEvent(QMouseEvent *event);
169  void mouseMoveEvent(QMouseEvent *event);
170  void hoverEnterEvent(QHoverEvent *event);
171  void hoverMoveEvent(QHoverEvent *event);
172  void hoverLeaveEvent(QHoverEvent *event);
173  void wheelEvent(QWheelEvent *event);
174  void keyPressEvent(QKeyEvent *event);
175 
176  // from QQuickItem
177  virtual QSGNode *updatePaintNode(QSGNode *, UpdatePaintNodeData *);
178  void itemChange(QQuickItem::ItemChange change, const ItemChangeData &value);
179 
180  void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry);
181 
182 private:
183  void render(QGLPainter *painter);
184  PickEvent *initiatePick(QMouseEvent *);
185  void setupPickPaint(QGLPainter *painter, const QPointF &pt);
186  bool mouseMoveOverflow(QMouseEvent *e) const;
187 
188  Q_INVOKABLE void processMousePress(PickEvent *event);
189  Q_INVOKABLE void processMouseRelease(PickEvent *event);
190  Q_INVOKABLE void processMouseDoubleClick(PickEvent *event);
191  Q_INVOKABLE void processMouseMove(PickEvent *event);
192  Q_INVOKABLE void processMouseHover(PickEvent *event);
193 
194  void processNavEvent(QMouseEvent *event);
195 
197 
198  void earlyDraw(QGLPainter *painter);
199  void draw(QGLPainter *painter);
200  void initializeGL(QGLPainter *painter);
201 
202  bool hoverEvent(QHoverEvent *event);
203 
204  void wheel(float delta);
205  void pan(float deltax, float deltay);
206  void rotate(float deltax, float deltay);
207  QPointF viewDelta(float deltax, float deltay);
208 
209  static const int FBO_SIZE;
210 };
211 
212 QT_END_NAMESPACE
213 
214 QML_DECLARE_TYPE(StereoViewport)
215 
216 #endif