6#include <QtGui/QOpenGLFunctions>
8#include <QtCore/QTimer>
9#include <QtCore/QVariantAnimation>
10#if QT_VERSION < 0x060000
11#include <QtWidgets/QOpenGLWidget>
13#include <QtOpenGLWidgets/QOpenGLWidget>
19#include <imt3dview/CScene3d.h>
25class ISceneEventHandler;
27class COpenGLWidget:
public QOpenGLWidget,
protected QOpenGLFunctions
72 RH_ANTIALIASING = 0x1,
77 I_DECLARE_FLAGS(RenderHints, RH_ANTIALIASING, RH_CULLFACE, RH_BLEND);
79 COpenGLWidget(QWidget* parentPtr =
nullptr);
83 void SetSceneEventHandler(ISceneEventHandler* handlerPtr);
84 void UnsetSceneEventHandler();
88 void ShowGrid(
bool show);
89 void ShowAxis(
bool show);
90 void ShowRuler(
bool show);
91 bool GetRenderHint(RenderHint renderHint)
const;
92 void SetRenderHint(RenderHint renderHint,
bool on =
true);
93 void SetCameraView(ViewDirection viewDirection,
bool animated =
true);
94 void SetViewMode(ViewMode viewMode);
95 void SetProjectionMode(ProjectionMode projectionMode);
96 void SetSelectionMode(SelectionMode selectionMode);
97 void SetRotationMode(RotationMode rotationMode);
98 void ClearSelection();
100 void InvertSelection();
101 void DeleteSelection();
102 void SetBackgroundColor(
const QColor& backgroundColor);
106 virtual void initializeGL()
override;
107 virtual void resizeGL(
int w,
int h)
override;
108 virtual void paintGL()
override;
111 virtual void mousePressEvent(QMouseEvent *e)
override;
112 virtual void mouseReleaseEvent(QMouseEvent* event)
override;
113 virtual void mouseMoveEvent(QMouseEvent *e)
override;
114 virtual void closeEvent(QCloseEvent* event)
override;
115 virtual void wheelEvent(QWheelEvent* event)
override;
116 virtual void keyPressEvent(QKeyEvent* e)
override;
121 void OnInternalTimer();
122 void OnCameraRotationAnimation(
const QVariant& value);
123 void OnCameraPositionAnimation(
const QVariant& value);
127 void Paint(QPainter& painter);
128 void PaintSelection(QPainter& painter);
129 void MousePressView(QMouseEvent& e);
130 void MousePressSelection(QMouseEvent& e);
131 void MouseMoveView(QMouseEvent& e);
132 void MouseMoveSelection(QMouseEvent& e);
134 void SetGlUniformValues();
135 QMatrix4x4 GetProjectionMatrix()
const;
136 static void GetFovRect(
float aspectRatio,
float nearPlane,
float& width,
float& height);
139 QPoint m_mouseClickPosition;
140 QPoint m_prevMousePosition;
141 QRect m_selectionRect;
145 QVariantAnimation m_cameraRotationAnimation;
146 QVariantAnimation m_cameraPositionAnimation;
149 SelectionMode m_selectionMode;
150 RotationMode m_rotationMode;
151 QOpenGLShaderProgram* m_programPtr;
153 QColor m_backgroundColor;
154 ProjectionMode m_projectionMode = PM_PERSPECTIVE;
156 static const float s_verticalAngle;
157 static const float s_nearPlane;
158 static const float s_farPlane;
159 static const QVector3D s_lightPosition;
160 static const QVector3D s_lightColor;