54 #include "QtGLGraphicsScene.hh" 55 #include <QGraphicsSceneMouseEvent> 56 #include <QApplication> 58 #include <QPaintEngine> 68 QtGLGraphicsScene::QtGLGraphicsScene(QtBaseViewer* _w) :
75 void QtGLGraphicsScene::drawBackground(QPainter *_painter,
const QRectF &_rect)
78 if (_painter->paintEngine()->type() != QPaintEngine::OpenGL && _painter->paintEngine()->type() != QPaintEngine::OpenGL2 ) {
79 std::cerr <<
"QtGLGraphicsScene: drawBackground needs a QGLWidget to be set as viewport on the graphics view\n";
84 _painter->setBackground(QApplication::palette().window());
85 _painter->eraseRect(_rect);
89 _painter->beginNativePainting();
92 glClear(GL_DEPTH_BUFFER_BIT);
97 _painter->endNativePainting();
101 void QtGLGraphicsScene::mousePressEvent(QGraphicsSceneMouseEvent* _e)
103 QGraphicsScene::mousePressEvent(_e);
104 if (_e->isAccepted())
107 QPoint p (_e->scenePos().x(), _e->scenePos().y());
108 QMouseEvent me(QEvent::MouseButtonPress ,p, _e->screenPos(), _e->button(),
109 _e->buttons(), _e->modifiers());
110 w_->glMousePressEvent(&me);
114 void QtGLGraphicsScene::mouseDoubleClickEvent(QGraphicsSceneMouseEvent* _e)
116 QGraphicsScene::mouseDoubleClickEvent(_e);
117 if (_e->isAccepted())
120 QPoint p (_e->scenePos().x(), _e->scenePos().y());
121 QMouseEvent me(QEvent::MouseButtonDblClick ,p, _e->screenPos(), _e->button(),
122 _e->buttons(), _e->modifiers());
123 w_->glMouseDoubleClickEvent(&me);
127 void QtGLGraphicsScene::mouseReleaseEvent(QGraphicsSceneMouseEvent* _e)
129 QGraphicsScene::mouseReleaseEvent(_e);
130 if (_e->isAccepted())
133 QPoint p (_e->scenePos().x(), _e->scenePos().y());
134 QMouseEvent me(QEvent::MouseButtonRelease ,p, _e->screenPos(), _e->button(),
135 _e->buttons(), _e->modifiers());
136 w_->glMouseReleaseEvent(&me);
140 void QtGLGraphicsScene::mouseMoveEvent(QGraphicsSceneMouseEvent* _e)
142 QGraphicsScene::mouseMoveEvent(_e);
143 if (_e->isAccepted())
146 QPoint p (_e->scenePos().x(), _e->scenePos().y());
147 QMouseEvent me(QEvent::MouseMove ,p, _e->screenPos(), _e->button(),
148 _e->buttons(), _e->modifiers());
149 w_->glMouseMoveEvent(&me);
153 void QtGLGraphicsScene::wheelEvent(QGraphicsSceneWheelEvent* _e)
155 QGraphicsScene::wheelEvent(_e);
156 if (_e->isAccepted())
158 QPoint p (_e->scenePos().x(), _e->scenePos().y());
159 QWheelEvent we(p, _e->screenPos(), _e->delta(), _e->buttons(),
160 _e->modifiers(), _e->orientation());
161 w_->glMouseWheelEvent(&we);
165 void QtGLGraphicsScene::keyPressEvent(QKeyEvent* _e)
167 QGraphicsScene::keyPressEvent(_e);
168 if (_e->isAccepted())
170 w_->glKeyPressEvent (_e);
173 void QtGLGraphicsScene::keyReleaseEvent(QKeyEvent* _e)
175 QGraphicsScene::keyReleaseEvent(_e);
176 if (_e->isAccepted())
178 w_->glKeyReleaseEvent (_e);
181 void QtGLGraphicsScene::contextMenuEvent(QGraphicsSceneContextMenuEvent* _e)
183 QGraphicsScene::contextMenuEvent(_e);
184 if (_e->isAccepted())
187 QPoint p (_e->scenePos().x(), _e->scenePos().y());
188 QContextMenuEvent ce(static_cast<QContextMenuEvent::Reason> (_e->reason()),
189 p, _e->screenPos(), _e->modifiers());
190 w_->glContextMenuEvent(&ce);
194 void QtGLGraphicsScene::dragEnterEvent(QGraphicsSceneDragDropEvent* _e)
196 QGraphicsScene::dragEnterEvent(_e);
197 if (_e->isAccepted())
200 QPoint p (_e->scenePos().x(), _e->scenePos().y());
201 QDragEnterEvent de(p, _e->possibleActions(), _e->mimeData(), _e->buttons(),
203 w_->glDragEnterEvent(&de);
207 void QtGLGraphicsScene::dropEvent(QGraphicsSceneDragDropEvent* _e)
209 QGraphicsScene::dropEvent(_e);
210 if (_e->isAccepted())
212 QPoint p (_e->scenePos().x(), _e->scenePos().y());
213 QDropEvent de(p, _e->possibleActions(), _e->mimeData(), _e->buttons(),
215 w_->glDropEvent(&de);
Namespace providing different geometric functions concerning angles.