00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053 #include "QtGLGraphicsScene.hh"
00054 #include <QPainter>
00055 #include <QPaintEngine>
00056 #include <QGraphicsSceneMouseEvent>
00057 #include <QGraphicsSceneDragDropEvent>
00058
00059
00060
00061 namespace ACG {
00062 namespace QtWidgets {
00063
00064
00065
00066
00067 QtGLGraphicsScene::QtGLGraphicsScene(QtBaseViewer* _w) :
00068 QGraphicsScene (),
00069 w_(_w)
00070 {
00071 }
00072
00073
00074 void QtGLGraphicsScene::drawBackground(QPainter *_painter, const QRectF &)
00075 {
00076 if (_painter->paintEngine()->type() != QPaintEngine::OpenGL) {
00077 std::cerr << "QtGLGraphicsScene: drawBackground needs a QGLWidget to be set as viewport on the graphics view\n";
00078 return;
00079 }
00080
00081 w_->paintGL();
00082
00083 }
00084
00085
00086 void QtGLGraphicsScene::mousePressEvent(QGraphicsSceneMouseEvent* _e)
00087 {
00088 QGraphicsScene::mousePressEvent(_e);
00089 if (_e->isAccepted())
00090 return;
00091
00092 QPoint p (_e->scenePos().x(), _e->scenePos().y());
00093 QMouseEvent me(QEvent::MouseButtonPress ,p, _e->screenPos(), _e->button(),
00094 _e->buttons(), _e->modifiers());
00095 w_->glMousePressEvent(&me);
00096 _e->accept();
00097 }
00098
00099 void QtGLGraphicsScene::mouseDoubleClickEvent(QGraphicsSceneMouseEvent* _e)
00100 {
00101 QGraphicsScene::mouseDoubleClickEvent(_e);
00102 if (_e->isAccepted())
00103 return;
00104
00105 QPoint p (_e->scenePos().x(), _e->scenePos().y());
00106 QMouseEvent me(QEvent::MouseButtonDblClick ,p, _e->screenPos(), _e->button(),
00107 _e->buttons(), _e->modifiers());
00108 w_->glMouseDoubleClickEvent(&me);
00109 _e->accept();
00110 }
00111
00112 void QtGLGraphicsScene::mouseReleaseEvent(QGraphicsSceneMouseEvent* _e)
00113 {
00114 QGraphicsScene::mouseReleaseEvent(_e);
00115 if (_e->isAccepted())
00116 return;
00117
00118 QPoint p (_e->scenePos().x(), _e->scenePos().y());
00119 QMouseEvent me(QEvent::MouseButtonRelease ,p, _e->screenPos(), _e->button(),
00120 _e->buttons(), _e->modifiers());
00121 w_->glMouseReleaseEvent(&me);
00122 _e->accept();
00123 }
00124
00125 void QtGLGraphicsScene::mouseMoveEvent(QGraphicsSceneMouseEvent* _e)
00126 {
00127 QGraphicsScene::mouseMoveEvent(_e);
00128 if (_e->isAccepted())
00129 return;
00130
00131 QPoint p (_e->scenePos().x(), _e->scenePos().y());
00132 QMouseEvent me(QEvent::MouseMove ,p, _e->screenPos(), _e->button(),
00133 _e->buttons(), _e->modifiers());
00134 w_->glMouseMoveEvent(&me);
00135 _e->accept();
00136 }
00137
00138 void QtGLGraphicsScene::wheelEvent(QGraphicsSceneWheelEvent* _e)
00139 {
00140 QGraphicsScene::wheelEvent(_e);
00141 if (_e->isAccepted())
00142 return;
00143 QPoint p (_e->scenePos().x(), _e->scenePos().y());
00144 QWheelEvent we(p, _e->screenPos(), _e->delta(), _e->buttons(),
00145 _e->modifiers(), _e->orientation());
00146 w_->glMouseWheelEvent(&we);
00147 _e->accept();
00148 }
00149
00150 void QtGLGraphicsScene::keyPressEvent(QKeyEvent* _e)
00151 {
00152 QGraphicsScene::keyPressEvent(_e);
00153 if (_e->isAccepted())
00154 return;
00155 w_->glKeyPressEvent (_e);
00156 }
00157
00158 void QtGLGraphicsScene::keyReleaseEvent(QKeyEvent* _e)
00159 {
00160 QGraphicsScene::keyReleaseEvent(_e);
00161 if (_e->isAccepted())
00162 return;
00163 w_->glKeyReleaseEvent (_e);
00164 }
00165
00166 void QtGLGraphicsScene::contextMenuEvent(QGraphicsSceneContextMenuEvent* _e)
00167 {
00168 QGraphicsScene::contextMenuEvent(_e);
00169 if (_e->isAccepted())
00170 return;
00171
00172 QPoint p (_e->scenePos().x(), _e->scenePos().y());
00173 QContextMenuEvent ce(static_cast<QContextMenuEvent::Reason> (_e->reason()),
00174 p, _e->screenPos(), _e->modifiers());
00175 w_->glContextMenuEvent(&ce);
00176 _e->accept();
00177 }
00178
00179 void QtGLGraphicsScene::dragEnterEvent(QGraphicsSceneDragDropEvent* _e)
00180 {
00181 QGraphicsScene::dragEnterEvent(_e);
00182 if (_e->isAccepted())
00183 return;
00184
00185 QPoint p (_e->scenePos().x(), _e->scenePos().y());
00186 QDragEnterEvent de(p, _e->possibleActions(), _e->mimeData(), _e->buttons(),
00187 _e->modifiers ());
00188 w_->glDragEnterEvent(&de);
00189 _e->accept();
00190 }
00191
00192 void QtGLGraphicsScene::dropEvent(QGraphicsSceneDragDropEvent* _e)
00193 {
00194 QGraphicsScene::dropEvent(_e);
00195 if (_e->isAccepted())
00196 return;
00197 QPoint p (_e->scenePos().x(), _e->scenePos().y());
00198 QDropEvent de(p, _e->possibleActions(), _e->mimeData(), _e->buttons(),
00199 _e->modifiers ());
00200 w_->glDropEvent(&de);
00201 _e->accept();
00202 }
00203
00204
00205 }
00206 }
00207