QtGLGraphicsScene.cc

00001 /*===========================================================================*\
00002  *                                                                           *
00003  *                              OpenFlipper                                  *
00004  *      Copyright (C) 2001-2009 by Computer Graphics Group, RWTH Aachen      *
00005  *                           www.openflipper.org                             *
00006  *                                                                           *
00007  *---------------------------------------------------------------------------*
00008  *  This file is part of OpenFlipper.                                        *
00009  *                                                                           *
00010  *  OpenFlipper is free software: you can redistribute it and/or modify      *
00011  *  it under the terms of the GNU Lesser General Public License as           *
00012  *  published by the Free Software Foundation, either version 3 of           *
00013  *  the License, or (at your option) any later version with the              *
00014  *  following exceptions:                                                    *
00015  *                                                                           *
00016  *  If other files instantiate templates or use macros                       *
00017  *  or inline functions from this file, or you compile this file and         *
00018  *  link it with other files to produce an executable, this file does        *
00019  *  not by itself cause the resulting executable to be covered by the        *
00020  *  GNU Lesser General Public License. This exception does not however       *
00021  *  invalidate any other reasons why the executable file might be            *
00022  *  covered by the GNU Lesser General Public License.                        *
00023  *                                                                           *
00024  *  OpenFlipper is distributed in the hope that it will be useful,           *
00025  *  but WITHOUT ANY WARRANTY; without even the implied warranty of           *
00026  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            *
00027  *  GNU Lesser General Public License for more details.                      *
00028  *                                                                           *
00029  *  You should have received a copy of the GNU LesserGeneral Public          *
00030  *  License along with OpenFlipper. If not,                                  *
00031  *  see <http://www.gnu.org/licenses/>.                                      *
00032  *                                                                           *
00033 \*===========================================================================*/
00034 
00035 /*===========================================================================*\
00036  *                                                                           *
00037  *   $Revision: 6743 $                                                       *
00038  *   $Author: moebius $                                                      *
00039  *   $Date: 2009-08-05 11:03:10 +0200 (Mi, 05. Aug 2009) $                   *
00040  *                                                                           *
00041 \*===========================================================================*/
00042 
00043 
00044 
00045 //=============================================================================
00046 //
00047 //  CLASS QtGLGraphicsScene - IMPLEMENTATION
00048 //
00049 //=============================================================================
00050 
00051 //== INCLUDES =================================================================
00052 
00053 #include "QtGLGraphicsScene.hh"
00054 #include <QPainter>
00055 #include <QPaintEngine>
00056 #include <QGraphicsSceneMouseEvent>
00057 #include <QGraphicsSceneDragDropEvent>
00058 
00059 //== NAMESPACES ===============================================================
00060 
00061 namespace ACG {
00062 namespace QtWidgets {
00063 
00064 
00065 //== IMPLEMENTATION ===========================================================
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 } // namespace QtWidgets
00206 } // namespace ACG
00207 //=============================================================================

acg pic Project OpenFlipper, ©  Computer Graphics Group, RWTH Aachen. Documentation generated using doxygen .