60 #include "QtGLGraphicsScene.hh"
61 #include <QGraphicsSceneMouseEvent>
62 #include <QApplication>
72 QtGLGraphicsScene::QtGLGraphicsScene(QtBaseViewer* _w) :
79 void QtGLGraphicsScene::drawBackground(QPainter *_painter,
const QRectF &_rect)
82 #if QT_VERSION >= 0x040600
83 if (_painter->paintEngine()->type() != QPaintEngine::OpenGL && _painter->paintEngine()->type() != QPaintEngine::OpenGL2 ) {
84 std::cerr <<
"QtGLGraphicsScene: drawBackground needs a QGLWidget to be set as viewport on the graphics view\n";
88 if (_painter->paintEngine()->type() != QPaintEngine::OpenGL ) {
89 std::cerr <<
"QtGLGraphicsScene: drawBackground needs a QGLWidget to be set as viewport on the graphics view\n";
95 _painter->setBackground(QApplication::palette().window());
96 _painter->eraseRect(_rect);
99 #if QT_VERSION >= 0x040600
101 _painter->beginNativePainting();
105 glClear(GL_DEPTH_BUFFER_BIT);
109 #if QT_VERSION >= 0x040600
111 _painter->endNativePainting();
116 void QtGLGraphicsScene::mousePressEvent(QGraphicsSceneMouseEvent* _e)
118 QGraphicsScene::mousePressEvent(_e);
119 if (_e->isAccepted())
122 QPoint p (_e->scenePos().x(), _e->scenePos().y());
123 QMouseEvent me(QEvent::MouseButtonPress ,p, _e->screenPos(), _e->button(),
124 _e->buttons(), _e->modifiers());
125 w_->glMousePressEvent(&me);
129 void QtGLGraphicsScene::mouseDoubleClickEvent(QGraphicsSceneMouseEvent* _e)
131 QGraphicsScene::mouseDoubleClickEvent(_e);
132 if (_e->isAccepted())
135 QPoint p (_e->scenePos().x(), _e->scenePos().y());
136 QMouseEvent me(QEvent::MouseButtonDblClick ,p, _e->screenPos(), _e->button(),
137 _e->buttons(), _e->modifiers());
138 w_->glMouseDoubleClickEvent(&me);
142 void QtGLGraphicsScene::mouseReleaseEvent(QGraphicsSceneMouseEvent* _e)
144 QGraphicsScene::mouseReleaseEvent(_e);
145 if (_e->isAccepted())
148 QPoint p (_e->scenePos().x(), _e->scenePos().y());
149 QMouseEvent me(QEvent::MouseButtonRelease ,p, _e->screenPos(), _e->button(),
150 _e->buttons(), _e->modifiers());
151 w_->glMouseReleaseEvent(&me);
155 void QtGLGraphicsScene::mouseMoveEvent(QGraphicsSceneMouseEvent* _e)
157 QGraphicsScene::mouseMoveEvent(_e);
158 if (_e->isAccepted())
161 QPoint p (_e->scenePos().x(), _e->scenePos().y());
162 QMouseEvent me(QEvent::MouseMove ,p, _e->screenPos(), _e->button(),
163 _e->buttons(), _e->modifiers());
164 w_->glMouseMoveEvent(&me);
168 void QtGLGraphicsScene::wheelEvent(QGraphicsSceneWheelEvent* _e)
170 QGraphicsScene::wheelEvent(_e);
171 if (_e->isAccepted())
173 QPoint p (_e->scenePos().x(), _e->scenePos().y());
174 QWheelEvent we(p, _e->screenPos(), _e->delta(), _e->buttons(),
175 _e->modifiers(), _e->orientation());
176 w_->glMouseWheelEvent(&we);
180 void QtGLGraphicsScene::keyPressEvent(QKeyEvent* _e)
182 QGraphicsScene::keyPressEvent(_e);
183 if (_e->isAccepted())
185 w_->glKeyPressEvent (_e);
188 void QtGLGraphicsScene::keyReleaseEvent(QKeyEvent* _e)
190 QGraphicsScene::keyReleaseEvent(_e);
191 if (_e->isAccepted())
193 w_->glKeyReleaseEvent (_e);
196 void QtGLGraphicsScene::contextMenuEvent(QGraphicsSceneContextMenuEvent* _e)
198 QGraphicsScene::contextMenuEvent(_e);
199 if (_e->isAccepted())
202 QPoint p (_e->scenePos().x(), _e->scenePos().y());
203 QContextMenuEvent ce(static_cast<QContextMenuEvent::Reason> (_e->reason()),
204 p, _e->screenPos(), _e->modifiers());
205 w_->glContextMenuEvent(&ce);
209 void QtGLGraphicsScene::dragEnterEvent(QGraphicsSceneDragDropEvent* _e)
211 QGraphicsScene::dragEnterEvent(_e);
212 if (_e->isAccepted())
215 QPoint p (_e->scenePos().x(), _e->scenePos().y());
216 QDragEnterEvent de(p, _e->possibleActions(), _e->mimeData(), _e->buttons(),
218 w_->glDragEnterEvent(&de);
222 void QtGLGraphicsScene::dropEvent(QGraphicsSceneDragDropEvent* _e)
224 QGraphicsScene::dropEvent(_e);
225 if (_e->isAccepted())
227 QPoint p (_e->scenePos().x(), _e->scenePos().y());
228 QDropEvent de(p, _e->possibleActions(), _e->mimeData(), _e->buttons(),
230 w_->glDropEvent(&de);
Namespace providing different geometric functions concerning angles.