61 #include <ACG/GL/acg_glew.hh> 63 #include "QtGLGraphicsScene.hh" 64 #include "QtMultiViewLayout.hh" 65 #include <QApplication> 67 #include <QPaintEngine> 68 #include <QGraphicsSceneMouseEvent> 74 QtGLGraphicsScene::QtGLGraphicsScene(std::vector< glViewer *> *_views,
85 void QtGLGraphicsScene::drawBackground(QPainter *_painter,
const QRectF &_rect)
88 #if QT_VERSION >= 0x040600 89 if (_painter->paintEngine()->type() != QPaintEngine::OpenGL && _painter->paintEngine()->type() != QPaintEngine::OpenGL2 ) {
90 std::cerr <<
"QtGLGraphicsScene: drawBackground needs a QGLWidget to be set as viewport on the graphics view\n";
94 if (_painter->paintEngine()->type() != QPaintEngine::OpenGL ) {
95 std::cerr <<
"QtGLGraphicsScene: drawBackground needs a QGLWidget to be set as viewport on the graphics view\n";
101 _painter->setBackground(QApplication::palette().window());
102 _painter->eraseRect(_rect);
105 #if QT_VERSION >= 0x040600 107 _painter->beginNativePainting();
110 static bool initialized =
false;
116 for (
unsigned int i = 0; i < views_->size (); i++)
118 views_->at(i)->initializeGL ();
121 cursorPainter_->initializeGL ();
126 if (cursorPainter_ && cursorPainter_->enabled())
130 glGetDoublev(GL_PROJECTION_MATRIX, mat);
132 glMatrixMode(GL_MODELVIEW);
135 glPushAttrib (GL_ALL_ATTRIB_BITS);
136 for (
unsigned int i = 0; i < views_->size (); i++)
138 if (views_->at(i)->isVisible())
139 views_->at(i)->updateCursorPosition(cursorPainter_->cursorPosition ());
143 glMatrixMode(GL_PROJECTION);
145 glMatrixMode(GL_MODELVIEW);
150 glClear(GL_DEPTH_BUFFER_BIT);
153 for (
unsigned int i = 0; i < views_->size (); i++)
155 if (views_->at(i)->isVisible())
156 views_->at(i)->paintGL();
159 #if QT_VERSION >= 0x040600 161 _painter->endNativePainting();
165 if (layout_->mode() != QtMultiViewLayout::SingleView)
171 _painter->setPen(pen);
172 _painter->drawLine(v->scenePos().x(), v->scenePos().y(),
174 v->scenePos().y() + v->size().height() - 1);
175 _painter->drawLine(v->scenePos().x() + v->size().width(), v->scenePos().y(),
176 v->scenePos().x() + v->size().width(),
177 v->scenePos().y() + v->size().height() - 1);
178 _painter->drawLine(v->scenePos().x(), v->scenePos().y() - 1,
179 v->scenePos().x() + v->size().width(),
180 v->scenePos().y() - 1);
181 _painter->drawLine(v->scenePos().x(),
182 v->scenePos().y() + v->size().height() - 1,
183 v->scenePos().x() + v->size().width(),
184 v->scenePos().y() + v->size().height() - 1);
190 glViewer* QtGLGraphicsScene::findView (
const QPointF &_p,
bool _setActive)
192 for (
unsigned int i = 0; i < views_->size (); i++)
194 if (views_->at(i)->contains(views_->at(i)->mapFromScene (_p)))
201 return views_->at(i);
209 void QtGLGraphicsScene::mouseMoveEvent(QGraphicsSceneMouseEvent* _e)
211 QGraphicsScene::mouseMoveEvent(_e);
212 if (_e->isAccepted())
215 glViewer *v = findView (_e->scenePos());
224 void QtGLGraphicsScene::setCursorPainter(
CursorPainter * _cursorPainter)
226 cursorPainter_ = _cursorPainter;
231 bool QtGLGraphicsScene::event(QEvent *_event)
233 if (cursorPainter_ && _event->type() == QEvent::Enter)
235 cursorPainter_->setMouseIn (
true);
237 else if (cursorPainter_ && _event->type() == QEvent::Leave)
239 cursorPainter_->setMouseIn (
false);
242 else if (cursorPainter_ && _event->type() == QEvent::GraphicsSceneMouseMove)
244 QGraphicsSceneMouseEvent *e =
static_cast<QGraphicsSceneMouseEvent*
>(_event);
245 cursorPainter_->updateCursorPosition (e->scenePos ());
249 return QGraphicsScene::event (_event);
void setActiveExaminer(const unsigned int _id)
Set the active id of the examiner which got the last mouse events.
virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *_event)
handle mouse move events
unsigned int activeExaminer()
Get the id of the examiner which got the last mouse events.