55 #include <ACG/GL/acg_glew.hh> 58 #include "QtGLGraphicsScene.hh" 59 #include "QtMultiViewLayout.hh" 60 #include <QApplication> 62 #include <QPaintEngine> 63 #include <QGraphicsSceneMouseEvent> 69 QtGLGraphicsScene::QtGLGraphicsScene(std::vector< glViewer *> *_views,
80 void QtGLGraphicsScene::drawBackground(QPainter *_painter,
const QRectF &_rect)
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";
89 _painter->setBackground(QApplication::palette().window());
92 if(!OpenFlipper::Options::coreProfile())
94 _painter->eraseRect(_rect);
98 _painter->beginNativePainting();
100 static bool initialized =
false;
108 for (
unsigned int i = 0; i < views_->size (); i++)
110 views_->at(i)->initializeGL ();
113 cursorPainter_->initializeGL ();
118 if (cursorPainter_ && cursorPainter_->enabled())
122 glGetDoublev(GL_PROJECTION_MATRIX, mat);
124 glMatrixMode(GL_MODELVIEW);
127 glPushAttrib (GL_ALL_ATTRIB_BITS);
128 for (
unsigned int i = 0; i < views_->size (); i++)
130 if (views_->at(i)->isVisible())
131 views_->at(i)->updateCursorPosition(cursorPainter_->cursorPosition ());
135 glMatrixMode(GL_PROJECTION);
137 glMatrixMode(GL_MODELVIEW);
142 glClear(GL_DEPTH_BUFFER_BIT);
145 for (
unsigned int i = 0; i < views_->size (); i++)
147 if (views_->at(i)->isVisible())
148 views_->at(i)->paintGL();
152 _painter->endNativePainting();
155 if (layout_->mode() != QtMultiViewLayout::SingleView)
161 _painter->setPen(pen);
162 _painter->drawLine(v->scenePos().x(), v->scenePos().y(),
164 v->scenePos().y() + v->size().height() - 1);
165 _painter->drawLine(v->scenePos().x() + v->size().width(), v->scenePos().y(),
166 v->scenePos().x() + v->size().width(),
167 v->scenePos().y() + v->size().height() - 1);
168 _painter->drawLine(v->scenePos().x(), v->scenePos().y() - 1,
169 v->scenePos().x() + v->size().width(),
170 v->scenePos().y() - 1);
171 _painter->drawLine(v->scenePos().x(),
172 v->scenePos().y() + v->size().height() - 1,
173 v->scenePos().x() + v->size().width(),
174 v->scenePos().y() + v->size().height() - 1);
180 glViewer* QtGLGraphicsScene::findView (
const QPointF &_p,
bool _setActive)
182 for (
unsigned int i = 0; i < views_->size (); i++)
184 if (views_->at(i)->contains(views_->at(i)->mapFromScene (_p)))
191 return views_->at(i);
199 void QtGLGraphicsScene::mouseMoveEvent(QGraphicsSceneMouseEvent* _e)
201 QGraphicsScene::mouseMoveEvent(_e);
202 if (_e->isAccepted())
205 glViewer *v = findView (_e->scenePos());
214 void QtGLGraphicsScene::setCursorPainter(
CursorPainter * _cursorPainter)
216 cursorPainter_ = _cursorPainter;
221 bool QtGLGraphicsScene::event(QEvent *_event)
223 if (cursorPainter_ && _event->type() == QEvent::Enter)
225 cursorPainter_->setMouseIn (
true);
227 else if (cursorPainter_ && _event->type() == QEvent::Leave)
229 cursorPainter_->setMouseIn (
false);
232 else if (cursorPainter_ && _event->type() == QEvent::GraphicsSceneMouseMove)
234 QGraphicsSceneMouseEvent *e =
static_cast<QGraphicsSceneMouseEvent*
>(_event);
235 cursorPainter_->updateCursorPosition (e->scenePos ());
239 return QGraphicsScene::event (_event);
unsigned int activeExaminer()
Get the id of the examiner which got the last mouse events.
virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *_event)
handle mouse move events
void setActiveExaminer(const unsigned int _id)
Set the active id of the examiner which got the last mouse events.