15 #include <QMouseEvent> 20 CQtGlCanvasBase::CQtGlCanvasBase(QWidget* parent)
23 #if MRPT_HAS_OPENGL_GLUT 24 m_mainViewport = getOpenGLSceneRef()->getViewport(
"main");
25 setMouseTracking(
true);
27 std::cerr <<
"[mrpt::gui::CQtGlCanvasBase] *Warning*: MRPT built without " 33 void CQtGlCanvasBase::initializeGL()
35 #if MRPT_HAS_OPENGL_GLUT 38 QOpenGLWidget::initializeGL();
42 void CQtGlCanvasBase::paintGL() { renderCanvas(); }
43 void CQtGlCanvasBase::resizeGL(
int width,
int height)
45 #if MRPT_HAS_OPENGL_GLUT 46 if (height == 0) height = 1;
47 glViewport(0, 0, width, height);
49 QOpenGLWidget::resizeGL(width, height);
55 return m_mainViewport;
58 float CQtGlCanvasBase::getCameraZoomDistance()
const 64 void CQtGlCanvasBase::mousePressEvent(QMouseEvent* event)
66 setMousePos(event->pos().x(),
event->pos().y());
67 setMouseClicked(
true);
69 m_isPressLMouseButton = (
event->button() == Qt::LeftButton);
70 m_isPressRMouseButton = (
event->button() == Qt::RightButton);
72 QOpenGLWidget::mousePressEvent(event);
75 void CQtGlCanvasBase::mouseMoveEvent(QMouseEvent* event)
77 int X =
event->pos().x();
78 int Y =
event->pos().y();
81 if (m_isPressLMouseButton || m_isPressRMouseButton)
84 CamaraParams
params = cameraParams();
86 if (m_isPressLMouseButton)
88 if (event->modifiers() == Qt::ShiftModifier)
91 else if (event->modifiers() == Qt::ControlModifier)
92 updateRotate(
params, X, Y);
94 else if (event->modifiers() == Qt::NoModifier)
95 updateOrbitCamera(
params, X, Y);
103 updateCamerasParams();
107 QOpenGLWidget::mouseMoveEvent(event);
110 void CQtGlCanvasBase::mouseReleaseEvent(QMouseEvent* event)
112 setMouseClicked(
false);
113 m_isPressLMouseButton =
false;
114 m_isPressRMouseButton =
false;
115 QOpenGLWidget::mouseReleaseEvent(event);
118 void CQtGlCanvasBase::wheelEvent(QWheelEvent* event)
120 CamaraParams
params = cameraParams();
121 updateZoom(
params, event->delta());
124 updateCamerasParams();
127 QOpenGLWidget::wheelEvent(event);
130 void CQtGlCanvasBase::renderError(
const std::string& err_msg)
135 void CQtGlCanvasBase::updateCamerasParams()
138 updateCameraParams(cam);
143 assert(m_mainViewport);
144 m_mainViewport->insert(newObject);
149 assert(m_mainViewport);
150 m_mainViewport->removeObject(newObject);
153 bool CQtGlCanvasBase::isPressLMouseButton()
const 155 return m_isPressLMouseButton;
158 bool CQtGlCanvasBase::isPressRMouseButton()
const 160 return m_isPressRMouseButton;
163 void CQtGlCanvasBase::unpressMouseButtons()
165 m_isPressLMouseButton =
false;
166 m_isPressRMouseButton =
false;
169 #endif // MRPT_HAS_Qt5 mrpt::vision::TStereoCalibParams params
float getZoomDistance() const
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
Classes for creating GUI windows for 2D and 3D visualization.
This base class implements a working with opengl::Camera and a OpenGL canvas, and it's used in gui::C...
A camera: if added to a scene, the viewpoint defined by this camera will be used instead of the camer...