28 #if QT_VERSION >= 0x040000 29 # include <QtAlgorithms> 31 # include <QApplication> 34 # include <QMessageBox> 35 # include <QPushButton> 36 # include <QTabWidget> 37 # include <QTextStream> 38 # include <QMouseEvent> 44 # include <qapplication.h> 45 # include <qfileinfo.h> 46 # include <qdatetime.h> 47 # include <qmessagebox.h> 48 # include <qpushbutton.h> 49 # include <qtabwidget.h> 50 # include <qtextstream.h> 53 # include <qtextedit.h> 54 # include <qkeysequence.h> 57 # define KeyboardModifierMask KeyButtonMask 66 #if QT_VERSION >= 0x040000 103 #if QT_VERSION >= 0x040000 105 setFocusPolicy(Qt::StrongFocus);
108 setFocusPolicy(QWidget::StrongFocus);
119 setDefaultShortcuts();
120 setDefaultMouseBindings();
122 setSnapshotFileName(tr(
"snapshot",
"Default snapshot file name"));
123 initializeSnapshotFormats();
124 setSnapshotCounter(0);
125 setSnapshotQuality(95);
130 fpsString_ = tr(
"%1Hz",
"Frames per seconds, in Hertz").arg(
"?");
136 manipulatedFrame_ = NULL;
137 manipulatedFrameIsACamera_ =
false;
138 mouseGrabberIsAManipulatedFrame_ =
false;
139 mouseGrabberIsAManipulatedCameraFrame_ =
false;
140 displayMessage_ =
false;
141 connect(&messageTimer_, SIGNAL(timeout()), SLOT(hideMessage()));
142 #if QT_VERSION >= 0x040000 143 messageTimer_.setSingleShot(
true);
146 setMouseGrabber(NULL);
150 setStateFileName(
".qglviewer.xml");
153 setAxisIsDrawn(
false);
154 setGridIsDrawn(
false);
155 setFPSIsDisplayed(
false);
156 setCameraIsEdited(
false);
157 setTextIsEnabled(
true);
158 setStereoDisplay(
false);
159 setFullScreen(
false);
161 animationTimerId_ = 0;
163 setAnimationPeriod(40);
165 selectBuffer_ = NULL;
166 setSelectBufferSize(4*1000);
167 setSelectRegionWidth(3);
168 setSelectRegionHeight(3);
171 bufferTextureId_ = 0;
172 bufferTextureMaxU_ = 0.0;
173 bufferTextureMaxV_ = 0.0;
174 bufferTextureWidth_ = 0;
175 bufferTextureHeight_ = 0;
176 previousBufferTextureFormat_ = 0;
177 previousBufferTextureInternalFormat_ = 0;
179 #if QT_VERSION >= 0x040000 180 setAttribute(Qt::WA_NoSystemBackground);
186 #if QT_VERSION >= 0x040000 && !defined QT3_SUPPORT 195 : QGLWidget(parent, shareWidget, flags)
196 { defaultConstructor(); }
203 QGLViewer::QGLViewer(QGLContext *context, QWidget* parent,
const QGLWidget* shareWidget, Qt::WindowFlags flags)
204 : QGLWidget(context, parent, shareWidget, flags)
205 { defaultConstructor(); }
211 QGLViewer::QGLViewer(
const QGLFormat& format, QWidget* parent,
const QGLWidget* shareWidget, Qt::WindowFlags flags)
212 : QGLWidget(format, parent, shareWidget, flags)
213 { defaultConstructor(); }
227 #if QT_VERSION >= 0x040000 234 delete[] selectBuffer_;
238 helpWidget()->close();
253 #if QT_VERSION < 0x040000 256 if (state & Qt::MODIFIER_MASK)
258 if (state & Qt::CTRL) { state &= ~
Qt::CTRL; state |= Qt::ControlButton; }
259 if (state & Qt::SHIFT) { state &= ~
Qt::SHIFT; state |= Qt::ShiftButton; }
260 if (state & Qt::ALT) { state &= ~
Qt::ALT; state |= Qt::AltButton; }
261 # if QT_VERSION >= 0x030100 262 if (state & Qt::META) { state &= ~
Qt::META; state |= Qt::MetaButton; }
271 #if QT_VERSION < 0x040000 282 #if QT_VERSION < 0x040000 283 if (state & Qt::KeyButtonMask)
285 if (state & Qt::ControlButton) { state &= ~
Qt::ControlButton; state |= Qt::CTRL; }
286 if (state & Qt::ShiftButton) { state &= ~
Qt::ShiftButton; state |= Qt::SHIFT; }
287 if (state & Qt::AltButton) { state &= ~
Qt::AltButton; state |= Qt::ALT; }
288 # if QT_VERSION >= 0x030100 289 if (state & Qt::MetaButton) { state &= ~
Qt::MetaButton; state |= Qt::META; }
317 qWarning(
"Internal debug: initializeGL() is called in QGLViewer constructor.");
320 glEnable(GL_LIGHTING);
321 glEnable(GL_DEPTH_TEST);
322 glEnable(GL_COLOR_MATERIAL);
325 setForegroundColor(QColor(180, 180, 180));
326 setBackgroundColor(QColor(51, 51, 51));
329 if (format().stereo())
331 glDrawBuffer(GL_BACK_RIGHT);
332 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
333 glDrawBuffer(GL_BACK_LEFT);
334 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
337 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
344 QTimer::singleShot( 100,
this, SLOT(delayedFullScreen()) );
358 if (displaysInStereo())
360 for (
int view=1; view>=0; --view)
365 if (camera()->frame()->isManipulated())
377 if (camera()->frame()->isManipulated())
385 Q_EMIT drawFinished(
true);
401 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
404 camera()->loadProjectionMatrix();
406 camera()->loadModelViewMatrix();
424 glMatrixMode(GL_MODELVIEW);
426 camera()->loadModelViewMatrix();
430 glPushAttrib(GL_ALL_ATTRIB_BITS);
433 glDisable(GL_TEXTURE_1D);
434 glDisable(GL_TEXTURE_2D);
435 #ifdef GL_TEXTURE_3D // OpenGL 1.2 Only... 436 glDisable(GL_TEXTURE_3D);
439 glDisable(GL_TEXTURE_GEN_Q);
440 glDisable(GL_TEXTURE_GEN_R);
441 glDisable(GL_TEXTURE_GEN_S);
442 glDisable(GL_TEXTURE_GEN_T);
444 #ifdef GL_RESCALE_NORMAL // OpenGL 1.2 Only... 445 glEnable(GL_RESCALE_NORMAL);
448 glDisable(GL_COLOR_MATERIAL);
449 qglColor(foregroundColor());
451 if (cameraIsEdited())
452 camera()->drawAllPaths();
457 if (gridIsDrawn()) { glLineWidth(1.0); drawGrid(camera()->sceneRadius()); }
458 if (axisIsDrawn()) { glLineWidth(2.0); drawAxis(camera()->sceneRadius()); }
461 const unsigned int maxCounter = 20;
462 if (++fpsCounter_ == maxCounter)
464 f_p_s_ = 1000.0 * maxCounter / fpsTime_.restart();
465 fpsString_ = tr(
"%1Hz",
"Frames per seconds, in Hertz").arg(f_p_s_, 0,
'f', ((f_p_s_ < 10.0)?1:0));
471 color[0] = foregroundColor().red() / 255.0;
472 color[1] = foregroundColor().green() / 255.0;
473 color[2] = foregroundColor().blue() / 255.0;
475 glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, color);
476 glDisable(GL_LIGHTING);
477 glDisable(GL_DEPTH_TEST);
479 if (FPSIsDisplayed()) displayFPS();
480 if (displayMessage_) drawText(10, height()-10, message_);
498 glDrawBuffer(GL_BACK_LEFT);
500 glDrawBuffer(GL_BACK_RIGHT);
503 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
505 camera()->loadProjectionMatrixStereo(leftBuffer);
507 camera()->loadModelViewMatrixStereo(leftBuffer);
533 cameraIsEdited_ = edit;
536 previousCameraZClippingCoefficient_ = camera()->zClippingCoefficient();
538 camera()->setZClippingCoefficient(5.0);
541 camera()->setZClippingCoefficient(previousCameraZClippingCoefficient_);
543 Q_EMIT cameraIsEditedChanged(edit);
553 setShortcut(DRAW_AXIS, Qt::Key_A);
554 setShortcut(DRAW_GRID, Qt::Key_G);
555 setShortcut(DISPLAY_FPS, Qt::Key_F);
556 setShortcut(ENABLE_TEXT, Qt::SHIFT+Qt::Key_Question);
557 setShortcut(EXIT_VIEWER, Qt::Key_Escape);
558 setShortcut(SAVE_SCREENSHOT, Qt::CTRL+Qt::Key_S);
559 setShortcut(CAMERA_MODE, Qt::Key_Space);
560 setShortcut(FULL_SCREEN, Qt::ALT+Qt::Key_Return);
561 setShortcut(STEREO, Qt::Key_S);
562 setShortcut(ANIMATION, Qt::Key_Return);
563 setShortcut(HELP, Qt::Key_H);
564 setShortcut(EDIT_CAMERA, Qt::Key_C);
565 setShortcut(MOVE_CAMERA_LEFT, Qt::Key_Left);
566 setShortcut(MOVE_CAMERA_RIGHT,Qt::Key_Right);
567 setShortcut(MOVE_CAMERA_UP, Qt::Key_Up);
568 setShortcut(MOVE_CAMERA_DOWN, Qt::Key_Down);
569 setShortcut(INCREASE_FLYSPEED,Qt::Key_Plus);
570 setShortcut(DECREASE_FLYSPEED,Qt::Key_Minus);
571 setShortcut(SNAPSHOT_TO_CLIPBOARD,Qt::CTRL+Qt::Key_C);
573 keyboardActionDescription_[DISPLAY_FPS] = tr(
"Toggles the display of the FPS",
"DISPLAY_FPS action description");
574 keyboardActionDescription_[SAVE_SCREENSHOT] = tr(
"Saves a screenshot",
"SAVE_SCREENSHOT action description");
575 keyboardActionDescription_[FULL_SCREEN] = tr(
"Toggles full screen display",
"FULL_SCREEN action description");
576 keyboardActionDescription_[DRAW_AXIS] = tr(
"Toggles the display of the world axis",
"DRAW_AXIS action description");
577 keyboardActionDescription_[DRAW_GRID] = tr(
"Toggles the display of the XY grid",
"DRAW_GRID action description");
578 keyboardActionDescription_[CAMERA_MODE] = tr(
"Changes camera mode (revolve or fly)",
"CAMERA_MODE action description");
579 keyboardActionDescription_[STEREO] = tr(
"Toggles stereo display",
"STEREO action description");
580 keyboardActionDescription_[HELP] = tr(
"Opens this help window",
"HELP action description");
581 keyboardActionDescription_[ANIMATION] = tr(
"Starts/stops the animation",
"ANIMATION action description");
582 keyboardActionDescription_[EDIT_CAMERA] = tr(
"Toggles camera paths display",
"EDIT_CAMERA action description");
583 keyboardActionDescription_[ENABLE_TEXT] = tr(
"Toggles the display of the text",
"ENABLE_TEXT action description");
584 keyboardActionDescription_[EXIT_VIEWER] = tr(
"Exits program",
"EXIT_VIEWER action description");
585 keyboardActionDescription_[MOVE_CAMERA_LEFT] = tr(
"Moves camera left",
"MOVE_CAMERA_LEFT action description");
586 keyboardActionDescription_[MOVE_CAMERA_RIGHT] = tr(
"Moves camera right",
"MOVE_CAMERA_RIGHT action description");
587 keyboardActionDescription_[MOVE_CAMERA_UP] = tr(
"Moves camera up",
"MOVE_CAMERA_UP action description");
588 keyboardActionDescription_[MOVE_CAMERA_DOWN] = tr(
"Moves camera down",
"MOVE_CAMERA_DOWN action description");
589 keyboardActionDescription_[INCREASE_FLYSPEED] = tr(
"Increases fly speed",
"INCREASE_FLYSPEED action description");
590 keyboardActionDescription_[DECREASE_FLYSPEED] = tr(
"Decreases fly speed",
"DECREASE_FLYSPEED action description");
591 keyboardActionDescription_[SNAPSHOT_TO_CLIPBOARD] = tr(
"Copies a snapshot to clipboard",
"SNAPSHOT_TO_CLIPBOARD action description");
594 setPathKey(Qt::Key_F1, 1);
595 setPathKey(Qt::Key_F2, 2);
596 setPathKey(Qt::Key_F3, 3);
597 setPathKey(Qt::Key_F4, 4);
598 setPathKey(Qt::Key_F5, 5);
599 setPathKey(Qt::Key_F6, 6);
600 setPathKey(Qt::Key_F7, 7);
601 setPathKey(Qt::Key_F8, 8);
602 setPathKey(Qt::Key_F9, 9);
603 setPathKey(Qt::Key_F10, 10);
604 setPathKey(Qt::Key_F11, 11);
605 setPathKey(Qt::Key_F12, 12);
607 #if QT_VERSION >= 0x040000 608 setAddKeyFrameKeyboardModifiers(Qt::AltModifier);
609 setPlayPathKeyboardModifiers(Qt::NoModifier);
611 setAddKeyFrameKeyboardModifiers(Qt::AltButton);
612 setPlayPathKeyboardModifiers(Qt::NoButton);
619 #if QT_VERSION >= 0x040000 620 const Qt::KeyboardModifiers cameraKeyboardModifiers = Qt::NoModifier;
621 const Qt::KeyboardModifiers frameKeyboardModifiers = Qt::ControlModifier;
623 const Qt::KeyboardModifiers cameraKeyboardModifiers = Qt::NoButton;
624 const Qt::KeyboardModifiers frameKeyboardModifiers = Qt::ControlButton;
627 for (
int handler=0; handler<2; ++handler)
630 Qt::KeyboardModifiers modifiers = (mh == FRAME) ? frameKeyboardModifiers : cameraKeyboardModifiers;
632 setMouseBinding(modifiers | Qt::LeftButton, mh, ROTATE);
633 setMouseBinding(modifiers | Qt::MidButton, mh, ZOOM);
634 setMouseBinding(modifiers | Qt::RightButton, mh, TRANSLATE);
636 setMouseBinding(modifiers | Qt::LeftButton | Qt::MidButton, mh, SCREEN_ROTATE);
639 setWheelBinding(modifiers, mh, ZOOM);
642 #if QT_VERSION >= 0x040000 644 setMouseBinding(Qt::SHIFT + Qt::MidButton, CAMERA, ZOOM_ON_REGION);
646 setMouseBinding(Qt::SHIFT + Qt::LeftButton, SELECT);
648 setMouseBinding(Qt::SHIFT + Qt::MidButton, CAMERA, ZOOM_ON_REGION);
649 setMouseBinding(Qt::SHIFT + Qt::LeftButton, SELECT);
653 setMouseBinding(Qt::LeftButton, ALIGN_CAMERA,
true);
654 setMouseBinding(Qt::MidButton, SHOW_ENTIRE_SCENE,
true);
655 setMouseBinding(Qt::RightButton, CENTER_SCENE,
true);
657 setMouseBinding(frameKeyboardModifiers | Qt::LeftButton, ALIGN_FRAME,
true);
658 setMouseBinding(frameKeyboardModifiers | Qt::RightButton, CENTER_FRAME,
true);
661 setMouseBinding(Qt::LeftButton, RAP_FROM_PIXEL,
true, Qt::RightButton);
662 setMouseBinding(Qt::RightButton, RAP_IS_CENTER,
true, Qt::LeftButton);
663 setMouseBinding(Qt::LeftButton, ZOOM_ON_PIXEL,
true, Qt::MidButton);
664 setMouseBinding(Qt::RightButton, ZOOM_TO_FIT,
true, Qt::MidButton);
670 # if QT_VERSION >= 0x040000 671 const Qt::KeyboardModifiers macKeyboardModifiers = Qt::AltModifier;
673 const Qt::KeyboardModifiers macKeyboardModifiers = Qt::AltButton;
676 setMouseBinding(macKeyboardModifiers | Qt::LeftButton, CAMERA, TRANSLATE);
677 setMouseBinding(macKeyboardModifiers | Qt::LeftButton, CENTER_SCENE,
true);
678 setMouseBinding(frameKeyboardModifiers | macKeyboardModifiers | Qt::LeftButton, CENTER_FRAME,
true);
679 setMouseBinding(frameKeyboardModifiers | macKeyboardModifiers | Qt::LeftButton, FRAME, TRANSLATE);
683 setMouseBinding(Qt::META + Qt::RightButton, RAP_FROM_PIXEL,
true, Qt::LeftButton);
684 setMouseBinding(Qt::SHIFT + Qt::META + Qt::RightButton, RAP_IS_CENTER,
true, Qt::LeftButton);
686 setMouseBinding(Qt::META + Qt::RightButton, ZOOM_ON_PIXEL,
false);
687 setMouseBinding(Qt::SHIFT + Qt::MetaModifier | Qt::RightButton, ZOOM_TO_FIT,
false);
717 disconnect(this->camera()->frame(), SIGNAL(manipulated()),
this, SLOT(updateGL()));
718 disconnect(this->camera()->frame(), SIGNAL(spun()),
this, SLOT(updateGL()));
721 connect(camera->
frame(), SIGNAL(manipulated()), SLOT(updateGL()));
722 connect(camera->
frame(), SIGNAL(spun()), SLOT(updateGL()));
724 connectAllCameraKFIInterpolatedSignals(
false);
726 connectAllCameraKFIInterpolatedSignals();
733 for (QMap<int, KeyFrameInterpolator*>::ConstIterator it = camera()->kfi_.begin(), end=camera()->kfi_.end(); it != end; ++it)
736 connect(camera()->keyFrameInterpolator(it.key()), SIGNAL(interpolated()), SLOT(updateGL()));
738 disconnect(camera()->keyFrameInterpolator(it.key()), SIGNAL(interpolated()),
this, SLOT(updateGL()));
742 connect(camera()->interpolationKfi_, SIGNAL(interpolated()), SLOT(updateGL()));
744 disconnect(camera()->interpolationKfi_, SIGNAL(interpolated()),
this, SLOT(updateGL()));
765 static GLUquadric* quadric = gluNewQuadric();
767 const float length = sceneRadius() / 5.0 * scale;
770 glGetBooleanv(light, &lightIsOn);
779 glGetLightfv(light, GL_DIFFUSE, color);
783 glGetLightfv(light, GL_POSITION, pos);
787 glTranslatef(pos[0]/pos[3], pos[1]/pos[3], pos[2]/pos[3]);
790 glGetLightfv(light, GL_SPOT_CUTOFF, &cutOff);
794 glGetLightfv(light, GL_SPOT_DIRECTION, dir);
797 gluCylinder(quadric, 0.0, 0.7 * length * sin(cutOff *
M_PI / 180.0), 0.7 * length * cos(cutOff *
M_PI / 180.0), 12, 1);
800 gluSphere(quadric, 0.2*length, 10, 10);
805 Vec dir(pos[0], pos[1], pos[2]);
807 Frame fr=
Frame(camera()->cameraCoordinatesOf(4.0 * length * camera()->frame()->inverseTransformOf(dir)),
809 glMultMatrixd(fr.
matrix());
862 if (!textIsEnabled())
865 #if QT_VERSION < QGLVIEWER_QT_VERSION_WITHOUT_GLUT 866 const GLfloat font_scale = 119.05f - 33.33f;
868 startScreenCoordinatesSystem();
871 glPushAttrib(GL_ALL_ATTRIB_BITS);
872 glDisable(GL_LIGHTING);
873 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
875 glDisable(GL_DEPTH_TEST);
876 glEnable(GL_LINE_SMOOTH);
879 glTranslatef((GLfloat)x, (GLfloat)y, 0.0);
880 const GLfloat scale = ((fnt.pixelSize()>0)?fnt.pixelSize():fnt.pointSize()) / font_scale;
881 glScalef(scale, -scale, scale);
883 for (uint i=0; i<text.length(); ++i)
884 glutStrokeCharacter(GLUT_STROKE_ROMAN, text.at(i));
888 stopScreenCoordinatesSystem();
891 # if QT_VERSION < 0x030300 && defined Q_OS_UNIX 894 newFont.setFamily(
"fixed");
895 newFont.setRawMode(
true);
896 newFont.setPixelSize(10);
897 newFont.setFixedPitch(
true);
898 # if QT_VERSION >= 0x030200 899 newFont.setStyleStrategy(QFont::OpenGLCompatible);
901 newFont.setStyleHint(QFont::AnyStyle, QFont::PreferBitmap);
902 renderText(x, y, text, newFont);
904 if (tileRegion_ != NULL) {
905 renderText((x-tileRegion_->xMin) * width() / (tileRegion_->xMax - tileRegion_->xMin),
906 (y-tileRegion_->yMin) * height() / (tileRegion_->yMax - tileRegion_->yMin), text, scaledFont(fnt));
908 renderText(x, y, text, fnt);
995 displayMessage_ =
true;
996 #if QT_VERSION >= 0x040000 998 messageTimer_.start(delay);
1000 if (messageTimer_.isActive())
1001 messageTimer_.changeInterval(delay);
1003 messageTimer_.start(delay,
true);
1005 if (textIsEnabled() && updateGLOK_)
1011 displayMessage_ =
false;
1012 if (textIsEnabled())
1028 drawText(10,
int(1.5*((QApplication::font().pixelSize()>0)?QApplication::font().pixelSize():QApplication::font().pointSize())), fpsString_);
1064 glMatrixMode(GL_PROJECTION);
1067 if (tileRegion_ != NULL)
1069 glOrtho(tileRegion_->xMin, tileRegion_->xMax, tileRegion_->yMin, tileRegion_->yMax, 0.0, -1.0);
1071 glOrtho(tileRegion_->xMin, tileRegion_->xMax, tileRegion_->yMax, tileRegion_->yMin, 0.0, -1.0);
1074 glOrtho(0, width(), 0, height(), 0.0, -1.0);
1076 glOrtho(0, width(), height(), 0, 0.0, -1.0);
1078 glMatrixMode(GL_MODELVIEW);
1089 glMatrixMode(GL_PROJECTION);
1092 glMatrixMode(GL_MODELVIEW);
1101 if (animationIsStarted())
1111 animationTimerId_ = startTimer(animationPeriod());
1112 animationStarted_ =
true;
1118 animationStarted_ =
false;
1119 if (animationTimerId_ != 0)
1120 killTimer(animationTimerId_);
1159 QGLWidget::closeEvent(e);
1174 Q_EMIT pointSelected(event);
1175 select(event->pos());
1230 beginSelection(point);
1232 endSelection(point);
1233 postSelection(point);
1253 glSelectBuffer(selectBufferSize(), selectBuffer());
1254 glRenderMode(GL_SELECT);
1258 glMatrixMode(GL_PROJECTION);
1260 static GLint viewport[4];
1261 camera()->getViewport(viewport);
1262 gluPickMatrix(point.x(), point.y(), selectRegionWidth(), selectRegionHeight(), viewport);
1266 camera()->loadProjectionMatrix(
false);
1268 camera()->loadModelViewMatrix();
1315 GLint nbHits = glRenderMode(GL_RENDER);
1318 setSelectedName(-1);
1325 GLuint zMin = (selectBuffer())[1];
1326 setSelectedName((selectBuffer())[3]);
1327 for (
int i=1; i<nbHits; ++i)
1328 if ((selectBuffer())[4*i+1] < zMin)
1330 zMin = (selectBuffer())[4*i+1];
1331 setSelectedName((selectBuffer())[4*i+3]);
1342 delete[] selectBuffer_;
1343 selectBufferSize_ = size;
1344 selectBuffer_ =
new GLuint[selectBufferSize()];
1354 case NO_CLICK_ACTION :
1356 case ZOOM_ON_PIXEL :
1357 camera()->interpolateToZoomOnPixel(e->pos());
1360 camera()->interpolateToFitScene();
1366 case RAP_FROM_PIXEL :
1367 if (camera()->setRevolveAroundPointFromPixel(e->pos()))
1369 setVisualHintsMask(1);
1373 case RAP_IS_CENTER :
1374 camera()->setRevolveAroundPoint(sceneCenter());
1375 setVisualHintsMask(1);
1379 if (manipulatedFrame())
1380 manipulatedFrame()->projectOnLine(camera()->position(), camera()->viewDirection());
1383 camera()->centerScene();
1385 case SHOW_ENTIRE_SCENE :
1386 camera()->showEntireScene();
1389 if (manipulatedFrame())
1390 manipulatedFrame()->alignWithFrame(camera()->frame());
1393 camera()->frame()->alignWithFrame(NULL,
true);
1420 #if QT_VERSION >= 0x040000 1422 cap.
button = e->button();
1423 cap.
buttonsBefore = (Qt::MouseButtons)(e->buttons() & ~(e->button()));
1426 cap.
button = (Qt::MouseButtons)((e->stateAfter() & Qt::MouseButtonMask) & (~(e->state() & Qt::MouseButtonMask)));
1427 cap.
buttonsBefore = (Qt::MouseButtons)(e->state() & Qt::MouseButtonMask);
1430 if (clickBinding_.contains(cap))
1431 performClickAction(clickBinding_[cap], e);
1435 if (mouseGrabberIsAManipulatedFrame_)
1437 for (QMap<int, MouseActionPrivate>::ConstIterator it=mouseBinding_.begin(), end=mouseBinding_.end(); it!=end; ++it)
1438 #
if QT_VERSION >= 0x040000
1439 if ((it.value().handler == FRAME) && ((it.key() & Qt::MouseButtonMask) == e->buttons()))
1441 if ((it.data().handler == FRAME) && ((it.key() & Qt::MouseButtonMask) == (e->stateAfter() & Qt::MouseButtonMask)))
1445 if (mouseGrabberIsAManipulatedCameraFrame_)
1447 mf->ManipulatedFrame::startAction(it.value().action, it.value().withConstraint);
1448 mf->ManipulatedFrame::mousePressEvent(e, camera());
1452 mf->
startAction(it.value().action, it.value().withConstraint);
1459 mouseGrabber()->mousePressEvent(e, camera());
1465 #if QT_VERSION >= 0x040000 1466 const int state = e->modifiers() | e->buttons();
1468 const int state = e->stateAfter();
1471 if (mouseBinding_.contains(state))
1478 camera()->frame()->mousePressEvent(e, camera());
1481 if (manipulatedFrame())
1483 if (manipulatedFrameIsACamera_)
1486 manipulatedFrame()->ManipulatedFrame::mousePressEvent(e, camera());
1491 manipulatedFrame()->mousePressEvent(e, camera());
1496 if (map.
action == SCREEN_ROTATE)
1500 #if QT_VERSION >= 0x030000 1550 mouseGrabber()->checkIfGrabsMouse(e->x(), e->y(), camera());
1551 if (mouseGrabber()->grabsMouse())
1552 if (mouseGrabberIsAManipulatedCameraFrame_)
1553 (
dynamic_cast<ManipulatedFrame*
>(mouseGrabber()))->ManipulatedFrame::mouseMoveEvent(e, camera());
1555 mouseGrabber()->mouseMoveEvent(e, camera());
1557 setMouseGrabber(NULL);
1561 if (!mouseGrabber())
1564 if (camera()->frame()->isManipulated())
1566 camera()->frame()->mouseMoveEvent(e, camera());
1568 if (camera()->frame()->action_ == ZOOM_ON_REGION)
1572 if ((manipulatedFrame()) && (manipulatedFrame()->isManipulated()))
1573 if (manipulatedFrameIsACamera_)
1574 manipulatedFrame()->ManipulatedFrame::mouseMoveEvent(e, camera());
1576 manipulatedFrame()->mouseMoveEvent(e, camera());
1578 if (hasMouseTracking())
1580 #if QT_VERSION >= 0x040000 1581 Q_FOREACH (
MouseGrabber* mg, MouseGrabber::MouseGrabberPool())
1584 QPtrListIterator<MouseGrabber> it(MouseGrabber::MouseGrabberPool());
1591 setMouseGrabber(mg);
1593 if (mouseGrabber() == mg)
1613 if (mouseGrabberIsAManipulatedCameraFrame_)
1614 (
dynamic_cast<ManipulatedFrame*
>(mouseGrabber()))->ManipulatedFrame::mouseReleaseEvent(e, camera());
1616 mouseGrabber()->mouseReleaseEvent(e, camera());
1617 mouseGrabber()->checkIfGrabsMouse(e->x(), e->y(), camera());
1618 if (!(mouseGrabber()->grabsMouse()))
1619 setMouseGrabber(NULL);
1624 if (camera()->frame()->isManipulated())
1628 camera()->frame()->mouseReleaseEvent(e, camera());
1634 if ((manipulatedFrame()) && (manipulatedFrame()->isManipulated()))
1637 if (manipulatedFrameIsACamera_)
1638 manipulatedFrame()->ManipulatedFrame::mouseReleaseEvent(e, camera());
1640 manipulatedFrame()->mouseReleaseEvent(e, camera());
1644 #if QT_VERSION >= 0x030000 1662 if (mouseGrabberIsAManipulatedFrame_)
1664 for (QMap<Qt::KeyboardModifiers, MouseActionPrivate>::ConstIterator it=wheelBinding_.begin(), end=wheelBinding_.end(); it!=end; ++it)
1665 if (it.value().handler == FRAME)
1668 if (mouseGrabberIsAManipulatedCameraFrame_)
1670 mf->ManipulatedFrame::startAction(it.value().action, it.value().withConstraint);
1671 mf->ManipulatedFrame::wheelEvent(e, camera());
1675 mf->
startAction(it.value().action, it.value().withConstraint);
1682 mouseGrabber()->wheelEvent(e, camera());
1688 #if QT_VERSION >= 0x040000 1689 const Qt::KeyboardModifiers modifiers = e->modifiers();
1691 const Qt::KeyboardModifiers modifiers = e->state();
1693 if (wheelBinding_.contains(modifiers))
1700 camera()->frame()->wheelEvent(e, camera());
1703 if (manipulatedFrame()) {
1704 if (manipulatedFrameIsACamera_)
1707 manipulatedFrame()->ManipulatedFrame::wheelEvent(e, camera());
1712 manipulatedFrame()->wheelEvent(e, camera());
1718 #if QT_VERSION >= 0x030000 1734 #if QT_VERSION >= 0x040000 1736 cap.
button = e->button();
1737 cap.
buttonsBefore = (Qt::MouseButtons)(e->buttons() & ~(e->button()));
1740 cap.
button = (Qt::MouseButtons)((e->stateAfter() & Qt::MouseButtonMask) & (~(e->state() & Qt::MouseButtonMask)));
1741 cap.
buttonsBefore = (Qt::MouseButtons)(e->state() & Qt::MouseButtonMask);
1743 if (clickBinding_.contains(cap))
1744 performClickAction(clickBinding_[cap], e);
1747 mouseGrabber()->mouseDoubleClickEvent(e, camera());
1748 #if QT_VERSION >= 0x030000 1760 if (format().stereo())
1763 if (!displaysInStereo())
1765 glDrawBuffer(GL_BACK_LEFT);
1766 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
1767 glDrawBuffer(GL_BACK_RIGHT);
1768 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
1771 Q_EMIT stereoChanged(stereo_);
1778 QMessageBox::warning(
this, tr(
"Stereo not supported",
"Message box window title"), tr(
"Stereo is not supported on this display."));
1789 fullScreen_ = fullScreen;
1795 QWidget* tlw = topLevelWidget();
1799 prevPos_ = topLevelWidget()->pos();
1800 tlw->showFullScreen();
1806 tlw->move(prevPos_);
1818 if (!mouseGrabberIsEnabled(mouseGrabber))
1821 mouseGrabber_ = mouseGrabber;
1823 mouseGrabberIsAManipulatedFrame_ = (
dynamic_cast<ManipulatedFrame*
>(mouseGrabber) != NULL);
1824 mouseGrabberIsAManipulatedCameraFrame_ = ((
dynamic_cast<ManipulatedCameraFrame*
>(mouseGrabber) != NULL) &&
1825 (mouseGrabber != camera()->frame()));
1826 Q_EMIT mouseGrabberChanged(mouseGrabber);
1833 disabledMouseGrabbers_.remove(reinterpret_cast<size_t>(mouseGrabber));
1835 disabledMouseGrabbers_[
reinterpret_cast<size_t>(mouseGrabber)];
1840 #if QT_VERSION >= 0x040000 1841 if (noButton && (m==Qt::NoModifier))
1843 if (noButton && (m==Qt::NoButton))
1845 return QGLViewer::tr(
"(no button)");
1847 QString keySequence =
"";
1849 #if QT_VERSION >= 0x040000 1850 if (m & Qt::ControlModifier) keySequence +=
"Ctrl+";
1851 if (m & Qt::AltModifier) keySequence +=
"Alt+";
1852 if (m & Qt::ShiftModifier) keySequence +=
"Shift+";
1853 if (m & Qt::MetaModifier) keySequence +=
"Meta+";
1855 if (m & Qt::ControlButton) keySequence +=
"Ctrl+";
1856 if (m & Qt::AltButton) keySequence +=
"Alt+";
1857 if (m & Qt::ShiftButton) keySequence +=
"Shift+";
1858 # if QT_VERSION >= 0x030000 1859 if (m & Qt::MetaButton) keySequence +=
"Meta+";
1863 if (keySequence.length() > 0)
1864 #
if QT_VERSION >= 0x040000
1865 return QKeySequence(keySequence+
"X").toString(QKeySequence::NativeText).replace(
"X",
"");
1867 return QString(QKeySequence(keySequence+
"X")).replace(
"X",
"");
1876 bool addAmpersand =
false;
1877 if (b & Qt::LeftButton) { result += QGLViewer::tr(
"Left",
"left mouse button"); addAmpersand=
true; }
1878 if (b & Qt::MidButton) {
if (addAmpersand) result +=
" & "; result += QGLViewer::tr(
"Middle",
"middle mouse button"); addAmpersand=
true; }
1879 if (b & Qt::RightButton) {
if (addAmpersand) result +=
" & "; result += QGLViewer::tr(
"Right",
"right mouse button"); }
1888 case QGLViewer::ROTATE :
return QGLViewer::tr(
"Rotates",
"ROTATE mouse action");
1889 case QGLViewer::ZOOM :
return QGLViewer::tr(
"Zooms",
"ZOOM mouse action");
1895 case QGLViewer::ROLL :
return QGLViewer::tr(
"Rolls",
"ROLL mouse action");
1896 case QGLViewer::DRIVE :
return QGLViewer::tr(
"Drives",
"DRIVE mouse action");
1900 return QString::null;
1910 case QGLViewer::SELECT :
return QGLViewer::tr(
"Selects",
"SELECT click action");
1919 return QString::null;
1925 return tr(
"%1%2%3%4%5%6",
"Modifier / button or wheel / double click / with / button / pressed")
1928 .arg(cap.
doubleClick ? tr(
" double click",
"Suffix after mouse button") :
"")
1929 .arg(buttonsBefore ? tr(
" with ",
"As in : Left button with Ctrl pressed") :
"")
1931 .arg(buttonsBefore ? tr(
" pressed",
"As in : Left button with Ctrl pressed") :
"");
1972 cap.
button = Qt::MouseButtons(state & Qt::MouseButtonMask);
1976 if (description.isEmpty())
1977 mouseDescription_.remove(cap);
1979 mouseDescription_[cap] = description;
1982 static QString
tableLine(
const QString& left,
const QString& right)
1984 static bool even =
false;
1985 const QString tdtd(
"</b></td><td>");
1986 const QString tdtr(
"</td></tr>\n");
1988 QString res(
"<tr bgcolor=\"");
1991 res +=
"#eeeeff\">";
1993 res +=
"#ffffff\">";
1994 res +=
"<td><b>" + left + tdtd + right + tdtr;
2011 QString text(
"<center><table border=\"1\" cellspacing=\"0\" cellpadding=\"4\">\n");
2012 const QString trtd(
"<tr><td>");
2013 const QString tdtr(
"</td></tr>\n");
2014 const QString tdtd(
"</td><td>");
2016 text += QString(
"<tr bgcolor=\"#aaaacc\"><th align=\"center\">%1</th><th align=\"center\">%2</th></tr>\n").
2017 arg(tr(
"Button(s)",
"Buttons column header in help window mouse tab")).arg(tr(
"Description",
"Description column header in help window mouse tab"));
2019 QMap<ClickActionPrivate, QString> mouseBinding;
2022 for (QMap<ClickActionPrivate, QString>::ConstIterator itm=mouseDescription_.begin(), endm=mouseDescription_.end(); itm!=endm; ++itm)
2023 mouseBinding[itm.key()] = itm.value();
2025 for (QMap<ClickActionPrivate, QString>::ConstIterator it=mouseBinding.begin(), end=mouseBinding.end(); it != end; ++it)
2028 if (it.value().isNull())
2031 text +=
tableLine(formatClickActionPrivate(it.key()), it.value());
2035 if (!mouseBinding.isEmpty())
2037 mouseBinding.clear();
2038 text += QString(
"<tr bgcolor=\"#aaaacc\"><td colspan=2>%1</td></tr>\n").arg(tr(
"Standard mouse bindings",
"In help window mouse tab"));
2044 for (QMap<Qt::KeyboardModifiers, MouseActionPrivate>::ConstIterator itw=wheelBinding_.begin(), endw=wheelBinding_.end(); itw != endw; ++itw)
2049 cap.
button = Qt::NoButton;
2052 QString text = mouseActionString(itw.value().action);
2056 switch (itw.value().handler)
2058 case CAMERA: text +=
" " + tr(
"camera",
"Suffix after action");
break;
2059 case FRAME: text +=
" " + tr(
"manipulated frame",
"Suffix after action");
break;
2061 if (!(itw.value().withConstraint))
2065 mouseBinding[cap] = text;
2068 for (QMap<int, MouseActionPrivate>::ConstIterator itmb=mouseBinding_.begin(), endmb=mouseBinding_.end();
2069 itmb != endmb; ++itmb)
2074 cap.
button = Qt::MouseButtons(itmb.key() & Qt::MouseButtonMask);
2077 QString text = mouseActionString(itmb.value().action);
2081 switch (itmb.value().handler)
2083 case CAMERA: text +=
" " + tr(
"camera",
"Suffix after action");
break;
2084 case FRAME: text +=
" " + tr(
"manipulated frame",
"Suffix after action");
break;
2086 if (!(itmb.value().withConstraint))
2089 mouseBinding[cap] = text;
2092 for (QMap<ClickActionPrivate, ClickAction>::ConstIterator itcb=clickBinding_.begin(), endcb=clickBinding_.end(); itcb!=endcb; ++itcb)
2093 mouseBinding[itcb.key()] = clickActionString(itcb.value());
2095 for (QMap<ClickActionPrivate, QString>::ConstIterator it2=mouseBinding.begin(), end2=mouseBinding.end(); it2 != end2; ++it2)
2097 if (it2.value().isNull())
2100 text +=
tableLine(formatClickActionPrivate(it2.key()), it2.value());
2103 text +=
"</table></center>";
2124 #if QT_VERSION >= 0x030000 2128 if (description.isEmpty())
2129 keyDescription_.remove(key);
2131 keyDescription_[key] = description;
2136 #if QT_VERSION >= 0x030000 2137 # if QT_VERSION >= 0x040100 2144 return QString(QKeySequence(key));
2150 if (pathIndex_.isEmpty())
2151 return QString::null;
2153 #if QT_VERSION >= 0x040000 || QT_VERSION < 0x030000 2156 QValueVector<int> keys;
2158 keys.reserve(pathIndex_.count());
2159 for (QMap<Qt::Key, int>::ConstIterator i = pathIndex_.begin(), endi=pathIndex_.end(); i != endi; ++i)
2160 keys.push_back(i.key());
2161 #if QT_VERSION >= 0x040000 2164 # if QT_VERSION >= 0x030000 2167 sort(keys.begin(), keys.end());
2171 #if QT_VERSION >= 0x040000 || QT_VERSION < 0x030000 2172 QVector<int>::const_iterator it = keys.begin(), end = keys.end();
2174 QValueVector<int>::const_iterator it = keys.begin(), end = keys.end();
2178 const int maxDisplayedKeys = 6;
2179 int nbDisplayedKeys = 0;
2180 int previousKey = (*it);
2183 while ((it != end) && (nbDisplayedKeys < maxDisplayedKeys-1))
2188 if ((*it) == previousKey + 1)
2197 if ((*it) == previousKey + 1)
2203 nbDisplayedKeys += 2;
2208 if ((*it) != previousKey + 1)
2212 nbDisplayedKeys += 2;
2241 QString text(
"<center><table border=\"1\" cellspacing=\"0\" cellpadding=\"4\">\n");
2242 text += QString(
"<tr bgcolor=\"#aaaacc\"><th align=\"center\">%1</th><th align=\"center\">%2</th></tr>\n").
2243 arg(QGLViewer::tr(
"Key(s)",
"Keys column header in help window mouse tab")).arg(QGLViewer::tr(
"Description",
"Description column header in help window mouse tab"));
2245 QMap<int, QString> keyDescription;
2248 for (QMap<int, QString>::ConstIterator kd=keyDescription_.begin(), kdend=keyDescription_.end(); kd!=kdend; ++kd)
2249 keyDescription[kd.key()] = kd.value();
2252 for (QMap<int, QString>::ConstIterator kb=keyDescription.begin(), endb=keyDescription.end(); kb!=endb; ++kb)
2257 if (!keyDescription.isEmpty())
2259 keyDescription.clear();
2260 text += QString(
"<tr bgcolor=\"#aaaacc\"><td colspan=2>%1</td></tr>\n").arg(QGLViewer::tr(
"Standard viewer keys",
"In help window keys tab"));
2265 for (QMap<KeyboardAction, unsigned int>::ConstIterator it=keyboardBinding_.begin(), end=keyboardBinding_.end(); it != end; ++it)
2266 if ((it.value() != 0) && ((!cameraIsInRevolveMode()) || ((it.key() != INCREASE_FLYSPEED) && (it.key() != DECREASE_FLYSPEED))))
2267 keyDescription[it.value()] = keyboardActionDescription_[it.key()];
2270 for (QMap<int, QString>::ConstIterator kb2=keyDescription.begin(), endb2=keyDescription.end(); kb2!=endb2; ++kb2)
2275 const QString cpks = cameraPathKeysString();
2278 text +=
"<tr bgcolor=\"#ccccff\"><td colspan=2>\n";
2279 text += QGLViewer::tr(
"Camera paths are controlled using %1 (noted <i>Fx</i> below):",
"Help window key tab camera keys").arg(cpks) +
"</td></tr>\n";
2281 QGLViewer::tr(
"Plays path (or resets saved position)"));
2283 QGLViewer::tr(
"Adds a key frame to path (or defines a position)"));
2284 text +=
tableLine(
keyboardModifiersString(addKeyFrameKeyboardModifiers()) +
"<i>" + QGLViewer::tr(
"Fx",
"Generic function key (F1..F12)") +
"</i>+<i>" + QGLViewer::tr(
"Fx",
"Generic function key (F1..F12)") +
"</i>",
2285 QGLViewer::tr(
"Deletes path (or saved position)"));
2287 text +=
"</table></center>";
2295 #if QT_VERSION >= 0x040000 2296 helpWidget()->setCurrentIndex(3);
2298 helpWidget()->setCurrentPage(3);
2316 bool resize =
false;
2320 static QString label[] = {tr(
"&Help",
"Help window tab title"), tr(
"&Keyboard",
"Help window tab title"), tr(
"&Mouse",
"Help window tab title"), tr(
"&About",
"Help window about title")};
2325 helpWidget_ =
new QTabWidget(NULL);
2326 #if QT_VERSION >= 0x040000 2327 helpWidget()->setWindowTitle(tr(
"Help",
"Help window title"));
2329 helpWidget()->setCaption(tr(
"Help",
"Help window title"));
2333 for (
int i=0; i<4; ++i)
2335 QTextEdit* tab =
new QTextEdit(NULL);
2336 #if QT_VERSION >= 0x030000 2337 tab->setReadOnly(
true);
2340 #if QT_VERSION >= 0x040000 2341 helpWidget()->insertTab(i, tab, label[i]);
2343 # include "qglviewer-icon.xpm" 2344 QPixmap pixmap(qglviewer_icon);
2345 tab->document()->addResource(QTextDocument::ImageResource,
2346 QUrl(
"mydata://qglviewer-icon.xpm"), QVariant(pixmap));
2349 tab->setTextFormat(Qt::RichText);
2350 helpWidget()->insertTab(tab, label[i]);
2356 #if QT_VERSION < 0x030000 2357 const int currentPageIndex = helpWidget()->currentPageIndex();
2360 for (
int i=0; i<4; ++i)
2365 case 0 : text = helpString();
break;
2366 case 1 : text = keyboardString();
break;
2367 case 2 : text = mouseString();
break;
2368 case 3 : text = QString(
"<center><br><img src=\"mydata://qglviewer-icon.xpm\">") + tr(
2369 "<h1>libQGLViewer</h1>" 2370 "<h3>Version %1</h3><br>" 2371 "A versatile 3D viewer based on OpenGL and Qt<br>" 2372 "Copyright 2002-%2 Gilles Debunne<br>" 2374 QString(
"</center>");
2379 #if QT_VERSION >= 0x040000 2380 QTextEdit* textEdit = (QTextEdit*)(helpWidget()->widget(i));
2381 textEdit->setHtml(text);
2383 # if QT_VERSION < 0x030000 2384 helpWidget()->setCurrentPage(i);
2385 QTextEdit* textEdit = (QTextEdit*)(helpWidget()->currentPage());
2387 QTextEdit* textEdit = (QTextEdit*)(helpWidget()->page(i));
2389 textEdit->setText(text);
2392 #if QT_VERSION < 0x040000 2393 if (resize && (textEdit->heightForWidth(width) > height))
2394 height = textEdit->heightForWidth(width);
2396 if (resize && (textEdit->height() > height))
2397 height = textEdit->height();
2401 #if QT_VERSION < 0x030000 2402 helpWidget()->setCurrentPage(currentPageIndex);
2406 helpWidget()->resize(width, height+40);
2407 helpWidget()->show();
2408 helpWidget()->raise();
2445 const Qt::Key key = Qt::Key(e->key());
2446 #if QT_VERSION >= 0x040000 2447 const Qt::KeyboardModifiers modifiers = e->modifiers();
2452 QMap<KeyboardAction, unsigned int>::ConstIterator it=keyboardBinding_.begin(), end=keyboardBinding_.end();
2453 const unsigned int target = key | modifiers;
2454 while ((it != end) && (it.value() != target))
2458 handleKeyboardAction(it.key());
2460 if (pathIndex_.contains(Qt::Key(key)))
2463 int index = pathIndex_[Qt::Key(key)];
2465 static QTime doublePress;
2467 if (modifiers == playPathKeyboardModifiers())
2469 int elapsed = doublePress.restart();
2470 if ((elapsed < 250) && (index==previousPathId_))
2471 camera()->resetPath(index);
2475 if (index != previousPathId_)
2481 camera()->playPath(index);
2483 previousPathId_ = index;
2485 else if (modifiers == addKeyFrameKeyboardModifiers())
2487 int elapsed = doublePress.restart();
2488 if ((elapsed < 250) && (index==previousPathId_))
2490 if (camera()->keyFrameInterpolator(index))
2492 disconnect(camera()->keyFrameInterpolator(index), SIGNAL(interpolated()),
this, SLOT(updateGL()));
2493 if (camera()->keyFrameInterpolator(index)->numberOfKeyFrames() > 1)
2494 displayMessage(tr(
"Path %1 deleted",
"Feedback message").arg(index));
2496 displayMessage(tr(
"Position %1 deleted",
"Feedback message").arg(index));
2497 camera()->deletePath(index);
2502 bool nullBefore = (camera()->keyFrameInterpolator(index) == NULL);
2503 camera()->addKeyFrameToPath(index);
2505 connect(camera()->keyFrameInterpolator(index), SIGNAL(interpolated()), SLOT(updateGL()));
2506 int nbKF = camera()->keyFrameInterpolator(index)->numberOfKeyFrames();
2508 displayMessage(tr(
"Path %1, position %2 added",
"Feedback message").arg(index).arg(nbKF));
2510 displayMessage(tr(
"Position %1 saved",
"Feedback message").arg(index));
2512 previousPathId_ = index;
2524 case DRAW_AXIS : toggleAxisIsDrawn();
break;
2525 case DRAW_GRID : toggleGridIsDrawn();
break;
2526 case DISPLAY_FPS : toggleFPSIsDisplayed();
break;
2527 case ENABLE_TEXT : toggleTextIsEnabled();
break;
2528 case EXIT_VIEWER : saveStateToFileForAllViewers(); qApp->closeAllWindows();
break;
2529 case SAVE_SCREENSHOT : saveSnapshot(
false,
false);
break;
2530 case FULL_SCREEN : toggleFullScreen();
break;
2531 case STEREO : toggleStereoDisplay();
break;
2532 case ANIMATION : toggleAnimation();
break;
2533 case HELP : help();
break;
2534 case EDIT_CAMERA : toggleCameraIsEdited();
break;
2535 case SNAPSHOT_TO_CLIPBOARD : snapshotToClipboard();
break;
2538 displayMessage(cameraIsInRevolveMode()?tr(
"Camera in revolve around mode",
"Feedback message"):tr(
"Camera in fly mode",
"Feedback message"));
2541 case MOVE_CAMERA_LEFT :
2542 camera()->frame()->translate(camera()->frame()->inverseTransformOf(
Vec(-10.0*camera()->flySpeed(), 0.0, 0.0)));
2545 case MOVE_CAMERA_RIGHT :
2546 camera()->frame()->translate(camera()->frame()->inverseTransformOf(
Vec( 10.0*camera()->flySpeed(), 0.0, 0.0)));
2549 case MOVE_CAMERA_UP :
2550 camera()->frame()->translate(camera()->frame()->inverseTransformOf(
Vec(0.0, 10.0*camera()->flySpeed(), 0.0)));
2553 case MOVE_CAMERA_DOWN :
2554 camera()->frame()->translate(camera()->frame()->inverseTransformOf(
Vec(0.0, -10.0*camera()->flySpeed(), 0.0)));
2558 case INCREASE_FLYSPEED : camera()->setFlySpeed(camera()->flySpeed() * 1.5);
break;
2559 case DECREASE_FLYSPEED : camera()->setFlySpeed(camera()->flySpeed() / 1.5);
break;
2569 QGLWidget::resizeGL(width, height);
2570 glViewport( 0, 0, GLint(width), GLint(height) );
2571 camera()->setScreenWidthAndHeight(this->width(), this->height());
2617 if (keyboardBinding_.contains(action))
2626 qWarning(
"setKeyboardAccelerator is deprecated. Use setShortcut instead.");
2627 setShortcut(action, key);
2632 qWarning(
"keyboardAccelerator is deprecated. Use shortcut instead.");
2633 return shortcut(action);
2656 for (QMap<Qt::Key, int>::ConstIterator it = pathIndex_.begin(), end=pathIndex_.end(); it != end; ++it)
2657 if (it.value() == index)
2676 pathIndex_.remove(Qt::Key(-key));
2678 pathIndex_[Qt::Key(key)] = index;
2708 return addKeyFrameKeyboardModifiers_;
2725 return playPathKeyboardModifiers_;
2732 qWarning(
"addKeyFrameStateKey has been renamed addKeyFrameKeyboardModifiers");
2733 return addKeyFrameKeyboardModifiers(); }
2737 qWarning(
"playPathStateKey has been renamed playPathKeyboardModifiers");
2738 return playPathKeyboardModifiers();
2743 qWarning(
"setAddKeyFrameStateKey has been renamed setAddKeyFrameKeyboardModifiers");
2749 qWarning(
"setPlayPathStateKey has been renamed setPlayPathKeyboardModifiers");
2755 qWarning(
"keyFrameKey has been renamed pathKey.");
2756 return pathKey(index);
2761 qWarning(
"playKeyFramePathStateKey has been renamed playPathKeyboardModifiers.");
2762 return playPathKeyboardModifiers();
2767 qWarning(
"setKeyFrameKey is deprecated, use setPathKey instead, with swapped parameters.");
2768 setPathKey(key, index);
2773 qWarning(
"setPlayKeyFramePathStateKey has been renamed setPlayPathKeyboardModifiers.");
2824 QMap<int, MouseActionPrivate> newMouseBinding;
2825 QMap<Qt::KeyboardModifiers, MouseActionPrivate> newWheelBinding;
2826 QMap<ClickActionPrivate, ClickAction> newClickBinding_;
2828 QMap<int, MouseActionPrivate>::Iterator mit;
2829 QMap<Qt::KeyboardModifiers, MouseActionPrivate>::Iterator wit;
2832 for (mit = mouseBinding_.begin(); mit != mouseBinding_.end(); ++mit)
2833 if ((mit.value().handler != handler) || (mit.value().action == ZOOM_ON_REGION))
2834 newMouseBinding[mit.key()] = mit.value();
2836 for (wit = wheelBinding_.begin(); wit != wheelBinding_.end(); ++wit)
2837 if (wit.value().handler != handler)
2838 newWheelBinding[wit.key()] = wit.value();
2842 for (mit = mouseBinding_.begin(); mit != mouseBinding_.end(); ++mit)
2843 if ((mit.value().handler == handler) && (mit.value().action != ZOOM_ON_REGION))
2845 int newState = modifiers | (mit.key() & Qt::MouseButtonMask);
2846 newMouseBinding[newState] = mit.value();
2849 for (wit = wheelBinding_.begin(); wit != wheelBinding_.end(); ++wit)
2850 if (wit.value().handler == handler)
2852 Qt::KeyboardModifiers newState = modifiers;
2853 newWheelBinding[newState] = wit.value();
2857 for (QMap<ClickActionPrivate, ClickAction>::ConstIterator cb=clickBinding_.begin(), end=clickBinding_.end(); cb != end; ++cb)
2858 if (((handler==CAMERA) && ((cb.value() == CENTER_SCENE) || (cb.value() == ALIGN_CAMERA))) ||
2859 ((handler==FRAME) && ((cb.value() == CENTER_FRAME) || (cb.value() == ALIGN_FRAME))))
2863 cap.
button = cb.key().button;
2866 newClickBinding_[cap] = cb.value();
2869 newClickBinding_[cb.key()] = cb.value();
2871 mouseBinding_ = newMouseBinding;
2872 wheelBinding_ = newWheelBinding;
2873 clickBinding_ = newClickBinding_;
2880 qWarning(
"setHandlerStateKey has been renamed setHandlerKeyboardModifiers");
2886 qWarning(
"setMouseStateKey has been renamed setHandlerKeyboardModifiers.");
2924 if ((handler == FRAME) && ((action == MOVE_FORWARD) || (action == MOVE_BACKWARD) ||
2925 (action == ROLL) || (action == LOOK_AROUND) ||
2926 (action == ZOOM_ON_REGION)))
2928 #if QT_VERSION >= 0x040000 2929 qWarning(
"Cannot bind %s to FRAME", mouseActionString(action).toLatin1().constData());
2931 qWarning(
"Cannot bind %s to FRAME", mouseActionString(action).latin1());
2935 if ((state & Qt::MouseButtonMask) == 0)
2936 qWarning(
"No mouse button specified in setMouseBinding");
2945 mouseBinding_.remove(state);
2947 if (action != NO_MOUSE_ACTION)
2948 mouseBinding_.insert(state, map);
2952 cap.
button = Qt::MouseButtons(state & Qt::MouseButtonMask);
2955 clickBinding_.remove(cap);
2986 if ((buttonsBefore != Qt::NoButton) && !doubleClick)
2987 qWarning(
"Buttons before is only meaningful when doubleClick is true in setMouseBinding().");
2989 if ((state & Qt::MouseButtonMask) == 0)
2990 qWarning(
"No mouse button specified in setMouseBinding");
2996 cap.
button = Qt::MouseButtons(state & Qt::MouseButtonMask);
2999 clickBinding_.remove(cap);
3002 if (action != NO_CLICK_ACTION)
3003 clickBinding_.insert(cap, action);
3005 if ((!doubleClick) && (buttonsBefore == Qt::NoButton))
3006 mouseBinding_.remove(state);
3023 if ((action != ZOOM) && (action != MOVE_FORWARD) && (action != MOVE_BACKWARD) && (action != NO_MOUSE_ACTION))
3024 #if QT_VERSION >= 0x040000 3025 qWarning(
"Cannot bind %s to wheel", mouseActionString(action).toLatin1().constData());
3027 qWarning(
"Cannot bind %s to wheel", + mouseActionString(action).latin1());
3030 if ((handler == FRAME) && (action != ZOOM) && (action != NO_MOUSE_ACTION))
3031 #if QT_VERSION >= 0x040000 3032 qWarning(
"Cannot bind %s to FRAME wheel", mouseActionString(action).toLatin1().constData());
3034 qWarning(
"Cannot bind %s to FRAME wheel", mouseActionString(action).latin1());
3043 wheelBinding_.remove(modifiers);
3045 if (action != NO_MOUSE_ACTION)
3046 wheelBinding_.insert(modifiers, map);
3064 if (mouseBinding_.contains(state))
3065 return mouseBinding_[state].action;
3067 return NO_MOUSE_ACTION;
3083 if (mouseBinding_.contains(state))
3084 return mouseBinding_[state].handler;
3108 for (QMap<int, MouseActionPrivate>::ConstIterator it=mouseBinding_.begin(), end=mouseBinding_.end(); it != end; ++it)
3109 if ( (it.value().handler == handler) && (it.value().action == action) && (it.value().withConstraint == withConstraint) )
3112 return Qt::NoButton;
3123 if (wheelBinding_.contains(modifiers))
3124 return wheelBinding_[modifiers].action;
3126 return NO_MOUSE_ACTION;
3133 if (wheelBinding_.contains(modifiers))
3134 return wheelBinding_[modifiers].handler;
3145 for (QMap<Qt::KeyboardModifiers, MouseActionPrivate>::ConstIterator it=wheelBinding_.begin(), end=wheelBinding_.end(); it!=end; ++it)
3146 if ( (it.value().handler == handler) && (it.value().action == action) && (it.value().withConstraint == withConstraint) )
3157 cap.
button = Qt::MouseButtons(state & Qt::MouseButtonMask);
3160 if (clickBinding_.contains(cap))
3161 return clickBinding_[cap];
3163 return NO_CLICK_ACTION;
3173 for (QMap<ClickActionPrivate, ClickAction>::ConstIterator it=clickBinding_.begin(), end=clickBinding_.end(); it != end; ++it)
3174 if (it.value() == ca)
3176 state = it.key().modifiers | it.key().button;
3177 doubleClick = it.key().doubleClick;
3178 buttonsBefore = it.key().buttonsBefore;
3182 state = Qt::NoButton;
3191 return mouseButtonState(CAMERA, ROTATE) != Qt::NoButton;
3209 bool revolveMode = cameraIsInRevolveMode();
3212 bs = mouseButtonState(CAMERA, ROTATE);
3214 bs = mouseButtonState(CAMERA, MOVE_FORWARD);
3220 camera()->frame()->updateFlyUpVector();
3221 camera()->frame()->stopSpinning();
3223 setMouseBinding(modifiers | Qt::LeftButton, CAMERA, MOVE_FORWARD);
3224 setMouseBinding(modifiers | Qt::MidButton, CAMERA, LOOK_AROUND);
3225 setMouseBinding(modifiers | Qt::RightButton, CAMERA, MOVE_BACKWARD);
3227 setMouseBinding(modifiers | Qt::LeftButton | Qt::MidButton, CAMERA, ROLL);
3230 setMouseBinding(Qt::LeftButton, NO_CLICK_ACTION,
true);
3231 setMouseBinding(Qt::MidButton, NO_CLICK_ACTION,
true);
3232 setMouseBinding(Qt::RightButton, NO_CLICK_ACTION,
true);
3234 setWheelBinding(modifiers, CAMERA, MOVE_FORWARD);
3239 setMouseBinding(modifiers | Qt::LeftButton, CAMERA, ROTATE);
3240 setMouseBinding(modifiers | Qt::MidButton, CAMERA, ZOOM);
3241 setMouseBinding(modifiers | Qt::RightButton, CAMERA, TRANSLATE);
3243 setMouseBinding(modifiers | Qt::LeftButton | Qt::MidButton, CAMERA, SCREEN_ROTATE);
3246 setMouseBinding(Qt::LeftButton, ALIGN_CAMERA,
true);
3247 setMouseBinding(Qt::MidButton, SHOW_ENTIRE_SCENE,
true);
3248 setMouseBinding(Qt::RightButton, CENTER_SCENE,
true);
3250 setWheelBinding(modifiers, CAMERA, ZOOM);
3271 if (manipulatedFrame())
3273 manipulatedFrame()->stopSpinning();
3275 if (manipulatedFrame() != camera()->frame())
3277 disconnect(manipulatedFrame(), SIGNAL(manipulated()),
this, SLOT(updateGL()));
3278 disconnect(manipulatedFrame(), SIGNAL(spun()),
this, SLOT(updateGL()));
3282 manipulatedFrame_ = frame;
3284 manipulatedFrameIsACamera_ = ((manipulatedFrame() != camera()->frame()) &&
3285 (dynamic_cast<ManipulatedCameraFrame*>(manipulatedFrame()) != NULL));
3287 if (manipulatedFrame())
3290 if (manipulatedFrame() != camera()->frame())
3292 connect(manipulatedFrame(), SIGNAL(manipulated()), SLOT(updateGL()));
3293 connect(manipulatedFrame(), SIGNAL(spun()), SLOT(updateGL()));
3320 if (visualHint_ & 1)
3322 const float size = 15.0;
3323 Vec proj = camera()->projectedCoordinatesOf(camera()->revolveAroundPoint());
3324 startScreenCoordinatesSystem();
3325 glDisable(GL_LIGHTING);
3326 glDisable(GL_DEPTH_TEST);
3329 glVertex2f(proj.
x - size, proj.
y);
3330 glVertex2f(proj.
x + size, proj.
y);
3331 glVertex2f(proj.
x, proj.
y - size);
3332 glVertex2f(proj.
x, proj.
y + size);
3334 glEnable(GL_DEPTH_TEST);
3335 stopScreenCoordinatesSystem();
3344 if (camera()->frame()->action_ == SCREEN_ROTATE)
3346 mf = camera()->frame();
3347 pnt = camera()->revolveAroundPoint();
3349 if (manipulatedFrame() && (manipulatedFrame()->action_ == SCREEN_ROTATE))
3351 mf = manipulatedFrame();
3354 pnt = manipulatedFrame()->position();
3359 pnt = camera()->projectedCoordinatesOf(pnt);
3360 startScreenCoordinatesSystem();
3361 glDisable(GL_LIGHTING);
3362 glDisable(GL_DEPTH_TEST);
3365 glVertex2f(pnt.
x, pnt.
y);
3368 glEnable(GL_DEPTH_TEST);
3369 stopScreenCoordinatesSystem();
3373 if (camera()->frame()->action_ == ZOOM_ON_REGION)
3375 startScreenCoordinatesSystem();
3376 glDisable(GL_LIGHTING);
3377 glDisable(GL_DEPTH_TEST);
3379 glBegin(GL_LINE_LOOP);
3380 glVertex2i(camera()->frame()->pressPos_.x(), camera()->frame()->pressPos_.y());
3381 glVertex2i(camera()->frame()->prevPos_.x(), camera()->frame()->pressPos_.y());
3382 glVertex2i(camera()->frame()->prevPos_.x(), camera()->frame()->prevPos_.y());
3383 glVertex2i(camera()->frame()->pressPos_.x(), camera()->frame()->prevPos_.y());
3385 glEnable(GL_DEPTH_TEST);
3386 stopScreenCoordinatesSystem();
3395 visualHint_ = visualHint_ | mask;
3396 QTimer::singleShot(delay,
this, SLOT(resetVisualHints()));
3421 static GLUquadric* quadric = gluNewQuadric();
3424 radius = 0.05 * length;
3426 const float head = 2.5*(radius / length) + 0.1;
3427 const float coneRadiusCoef = 4.0 - 5.0 * head;
3429 gluCylinder(quadric, radius, radius, length * (1.0 - head/coneRadiusCoef), nbSubdivisions, 1);
3430 glTranslatef(0.0, 0.0, length * (1.0 - head));
3431 gluCylinder(quadric, coneRadiusCoef * radius, 0.0, head * length, nbSubdivisions, 1);
3432 glTranslatef(0.0, 0.0, -length * (1.0 - head));
3442 glTranslatef(from[0],from[1],from[2]);
3443 const Vec dir = to-from;
3469 const float charWidth = length / 40.0;
3470 const float charHeight = length / 30.0;
3471 const float charShift = 1.04 * length;
3473 GLboolean lighting, colorMaterial;
3474 glGetBooleanv(GL_LIGHTING, &lighting);
3475 glGetBooleanv(GL_COLOR_MATERIAL, &colorMaterial);
3477 glDisable(GL_LIGHTING);
3481 glVertex3f(charShift, charWidth, -charHeight);
3482 glVertex3f(charShift, -charWidth, charHeight);
3483 glVertex3f(charShift, -charWidth, -charHeight);
3484 glVertex3f(charShift, charWidth, charHeight);
3486 glVertex3f( charWidth, charShift, charHeight);
3487 glVertex3f(0.0, charShift, 0.0);
3488 glVertex3f(-charWidth, charShift, charHeight);
3489 glVertex3f(0.0, charShift, 0.0);
3490 glVertex3f(0.0, charShift, 0.0);
3491 glVertex3f(0.0, charShift, -charHeight);
3493 glVertex3f(-charWidth, charHeight, charShift);
3494 glVertex3f( charWidth, charHeight, charShift);
3495 glVertex3f( charWidth, charHeight, charShift);
3496 glVertex3f(-charWidth, -charHeight, charShift);
3497 glVertex3f(-charWidth, -charHeight, charShift);
3498 glVertex3f( charWidth, -charHeight, charShift);
3501 glEnable(GL_LIGHTING);
3502 glDisable(GL_COLOR_MATERIAL);
3505 color[0] = 0.7f; color[1] = 0.7f; color[2] = 1.0f; color[3] = 1.0f;
3506 glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, color);
3509 color[0] = 1.0f; color[1] = 0.7f; color[2] = 0.7f; color[3] = 1.0f;
3510 glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, color);
3512 glRotatef(90.0, 0.0, 1.0, 0.0);
3516 color[0] = 0.7f; color[1] = 1.0f; color[2] = 0.7f; color[3] = 1.0f;
3517 glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, color);
3519 glRotatef(-90.0, 1.0, 0.0, 0.0);
3524 glEnable(GL_COLOR_MATERIAL);
3526 glDisable(GL_LIGHTING);
3538 glGetBooleanv(GL_LIGHTING, &lighting);
3540 glDisable(GL_LIGHTING);
3543 for (
int i=0; i<=nbSubdivisions; ++i)
3545 const float pos = size*(2.0*i/nbSubdivisions-1.0);
3546 glVertex2f(pos, -size);
3547 glVertex2f(pos, +size);
3548 glVertex2f(-size, pos);
3549 glVertex2f( size, pos);
3554 glEnable(GL_LIGHTING);
3564 #if QT_VERSION >= 0x040000 3569 for (
QGLViewer* viewer; (viewer = it.current()) != 0; ++it)
3596 QString name = stateFileName_;
3601 #if QT_VERSION >= 0x040000 3602 if (fi.suffix().isEmpty())
3604 if (fi.extension(
false).isEmpty())
3608 #if QT_VERSION >= 0x040000 3609 name = fi.absolutePath() +
'/' + fi.completeBaseName() + QString::number(
QGLViewer::QGLViewerIndex(
this)) +
"." + fi.suffix();
3611 # if QT_VERSION >= 0x030000 3612 name = fi.dirPath() +
'/' + fi.baseName(
true) + QString::number(
QGLViewer::QGLViewerIndex(
this)) +
"." + fi.extension(
false);
3631 QString name = stateFileName();
3636 QFileInfo fileInfo(name);
3638 if (fileInfo.isDir())
3640 QMessageBox::warning(
this, tr(
"Save to file error",
"Message box window title"), tr(
"State file name (%1) references a directory instead of a file.").arg(name));
3644 #if QT_VERSION >= 0x040000 3645 const QString dirName = fileInfo.absolutePath();
3647 const QString dirName = fileInfo.dirPath();
3649 if (!QFileInfo(dirName).exists())
3652 #if QT_VERSION >= 0x040000 3653 if (!(dir.mkdir(dirName)))
3655 if (!(dir.mkdir(dirName,
true)))
3658 QMessageBox::warning(
this, tr(
"Save to file error",
"Message box window title"), tr(
"Unable to create directory %1").arg(dirName));
3665 #if QT_VERSION >= 0x040000 3666 if (f.open(QIODevice::WriteOnly))
3668 if (f.open(IO_WriteOnly))
3671 QTextStream out(&f);
3672 QDomDocument doc(
"QGLVIEWER");
3673 doc.appendChild(domElement(
"QGLViewer", doc));
3679 #if QT_VERSION < 0x030200 3680 QMessageBox::warning(
this, tr(
"Save to file error",
"Message box window title"), tr(
"Unable to save to file %1").arg(name));
3682 QMessageBox::warning(
this, tr(
"Save to file error",
"Message box window title"), tr(
"Unable to save to file %1").arg(name) +
":\n" + f.errorString());
3708 QString name = stateFileName();
3713 QFileInfo fileInfo(name);
3715 if (!fileInfo.isFile())
3719 if (!fileInfo.isReadable())
3721 QMessageBox::warning(
this, tr(
"Problem in state restoration",
"Message box window title"), tr(
"File %1 is not readable.").arg(name));
3727 #if QT_VERSION >= 0x040000 3728 if (f.open(QIODevice::ReadOnly) ==
true)
3730 if (f.open(IO_ReadOnly) ==
true)
3736 QDomElement
main = doc.documentElement();
3737 initFromDOMElement(main);
3741 #if QT_VERSION < 0x030200 3742 QMessageBox::warning(
this, tr(
"Open file error",
"Message box window title"), tr(
"Unable to open file %1").arg(name));
3744 QMessageBox::warning(
this, tr(
"Open file error",
"Message box window title"), tr(
"Unable to open file %1").arg(name) +
":\n" + f.errorString());
3786 QDomElement de = document.createElement(name);
3789 QDomElement stateNode = document.createElement(
"State");
3793 stateNode.setAttribute(
"stereo", (displaysInStereo()?
"true":
"false"));
3794 stateNode.setAttribute(
"cameraMode", (cameraIsInRevolveMode()?
"revolve":
"fly"));
3795 de.appendChild(stateNode);
3797 QDomElement displayNode = document.createElement(
"Display");
3798 displayNode.setAttribute(
"axisIsDrawn", (axisIsDrawn()?
"true":
"false"));
3799 displayNode.setAttribute(
"gridIsDrawn", (gridIsDrawn()?
"true":
"false"));
3800 displayNode.setAttribute(
"FPSIsDisplayed", (FPSIsDisplayed()?
"true":
"false"));
3801 displayNode.setAttribute(
"cameraIsEdited", (cameraIsEdited()?
"true":
"false"));
3803 de.appendChild(displayNode);
3805 QDomElement geometryNode = document.createElement(
"Geometry");
3806 geometryNode.setAttribute(
"fullScreen", (isFullScreen()?
"true":
"false"));
3809 geometryNode.setAttribute(
"prevPosX", QString::number(prevPos_.x()));
3810 geometryNode.setAttribute(
"prevPosY", QString::number(prevPos_.y()));
3814 QWidget* tlw = topLevelWidget();
3815 geometryNode.setAttribute(
"width", QString::number(tlw->width()));
3816 geometryNode.setAttribute(
"height", QString::number(tlw->height()));
3817 geometryNode.setAttribute(
"posX", QString::number(tlw->pos().x()));
3818 geometryNode.setAttribute(
"posY", QString::number(tlw->pos().y()));
3820 de.appendChild(geometryNode);
3823 if (cameraIsEdited())
3824 camera()->setZClippingCoefficient(previousCameraZClippingCoefficient_);
3825 de.appendChild(camera()->domElement(
"Camera", document));
3826 if (cameraIsEdited())
3828 camera()->setZClippingCoefficient(5.0);
3830 if (manipulatedFrame())
3831 de.appendChild(manipulatedFrame()->domElement(
"ManipulatedFrame", document));
3872 const QString version = element.attribute(
"version");
3874 if (version[0] !=
'2')
3876 #if QT_VERSION >= 0x040000 3877 qWarning(
"State file created using QGLViewer version %s may not be correctly read.", version.toLatin1().constData());
3879 qWarning(
"State file created using QGLViewer version %s may not be correctly read.", version.latin1());
3882 QDomElement child=element.firstChild().toElement();
3883 bool tmpCameraIsEdited = cameraIsEdited();
3884 while (!child.isNull())
3886 if (child.tagName() ==
"State")
3891 if ((child.attribute(
"cameraMode",
"revolve") ==
"fly") && (cameraIsInRevolveMode()))
3894 QDomElement ch=child.firstChild().toElement();
3895 while (!ch.isNull())
3897 if (ch.tagName() ==
"foregroundColor")
3899 if (ch.tagName() ==
"backgroundColor")
3901 ch = ch.nextSibling().toElement();
3905 if (child.tagName() ==
"Display")
3916 if (child.tagName() ==
"Geometry")
3929 topLevelWidget()->resize(width, height);
3930 camera()->setScreenWidthAndHeight(this->width(), this->height());
3935 topLevelWidget()->move(pos);
3939 if (child.tagName() ==
"Camera")
3941 connectAllCameraKFIInterpolatedSignals(
false);
3942 camera()->initFromDOMElement(child);
3943 connectAllCameraKFIInterpolatedSignals();
3946 if ((child.tagName() ==
"ManipulatedFrame") && (manipulatedFrame()))
3947 manipulatedFrame()->initFromDOMElement(child);
3949 child = child.nextSibling().toElement();
3956 cameraIsEdited_ = tmpCameraIsEdited;
3957 if (cameraIsEdited_)
3959 previousCameraZClippingCoefficient_ = camera()->zClippingCoefficient();
3961 camera()->setZClippingCoefficient(5.0);
3970 if (!fileName.isEmpty())
3971 setStateFileName(fileName);
3973 qWarning(
"saveToFile() is deprecated, use saveStateToFile() instead.");
3981 if (!fileName.isEmpty())
3982 setStateFileName(fileName);
3984 qWarning(
"restoreFromFile() is deprecated, use restoreStateFromFile() instead.");
3985 return restoreStateFromFile();
4049 while (h < height())
4054 if ((w != bufferTextureWidth_) || (h != bufferTextureHeight_))
4056 bufferTextureWidth_ = w;
4057 bufferTextureHeight_ = h;
4058 bufferTextureMaxU_ = width() / float(bufferTextureWidth_);
4059 bufferTextureMaxV_ = height() / float(bufferTextureHeight_);
4063 if (bufferTextureId() == 0)
4065 glGenTextures(1, &bufferTextureId_);
4066 glBindTexture(GL_TEXTURE_2D, bufferTextureId_);
4067 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
4068 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
4072 glBindTexture(GL_TEXTURE_2D, bufferTextureId_);
4074 if ((format != previousBufferTextureFormat_) ||
4075 (internalFormat != previousBufferTextureInternalFormat_))
4077 previousBufferTextureFormat_ = format;
4078 previousBufferTextureInternalFormat_ = internalFormat;
4084 if (format == GL_NONE)
4085 format = internalFormat;
4087 glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, bufferTextureWidth_, bufferTextureHeight_, 0, format, GL_UNSIGNED_BYTE, NULL);
4090 glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, width(), height());
4101 if (glIsTexture(bufferTextureId_))
4102 return bufferTextureId_;
virtual QString mouseString() const
virtual void aboutQGLViewer()
Qt::KeyboardModifiers playPathKeyboardModifiers() const
virtual void wheelEvent(QWheelEvent *)
void setScreenWidthAndHeight(int width, int height)
static QPtrList< QGLViewer > QGLViewerPool_
void setDefaultMouseBindings()
A keyFrame Catmull-Rom Frame interpolator.
virtual void timerEvent(QTimerEvent *)
void setCamera(qglviewer::Camera *const camera)
Qt::KeyboardModifiers addKeyFrameStateKey() const
ClickAction clickAction(int state, bool doubleClick, Qt::MouseButtons buttonsBefore) const
static QDomElement QColorDomElement(const QColor &color, const QString &name, QDomDocument &doc)
The ManipulatedCameraFrame class represents a ManipulatedFrame with Camera specific mouse bindings...
void resetInterpolation()
virtual void resetVisualHints()
float zClippingCoefficient() const
static QString mouseActionString(QGLViewer::MouseAction ma)
static void drawArrow(float length=1.0f, float radius=-1.0f, int nbSubdivisions=12)
virtual void setKeyFrameKey(int index, int key)
A ManipulatedFrame is a Frame that can be rotated and translated using the mouse. ...
QString stateFileName() const
void setMouseBindingDescription(int state, QString description, bool doubleClick=false, Qt::MouseButtons buttonsBefore=Qt::NoButton)
virtual void setPlayPathKeyboardModifiers(Qt::KeyboardModifiers modifiers)
virtual void checkIfGrabsMouse(int x, int y, const Camera *const camera)=0
static int convertToShortModifier(int state)
Qt::MouseButtons buttonsBefore
virtual void stopAnimation()
virtual void stopScreenCoordinatesSystem() const
static QString keyString(int key)
int wheelHandler(Qt::KeyboardModifiers modifiers) const
void setSceneCenter(const Vec ¢er)
virtual void saveStateToFile()
void defaultConstructor()
void setHandlerStateKey(MouseHandler handler, int buttonState)
QGLViewer(QWidget *parent=NULL, const char *name=0, const QGLWidget *shareWidget=0, Qt::WindowFlags flags=0)
void setMouseGrabberIsEnabled(const qglviewer::MouseGrabber *const mouseGrabber, bool enabled=true)
void drawText(int x, int y, const QString &text, const QFont &fnt=QFont())
#define QGLVIEWER_VERSION
virtual void closeEvent(QCloseEvent *)
int mouseButtonState(MouseHandler handler, MouseAction action, bool withConstraint=true) const
void setStereoDisplay(bool stereo=true)
Qt::KeyboardModifiers playKeyFramePathStateKey() const
bool restoreFromFile(const QString &fileName=QString::null)
static QString clickActionString(QGLViewer::ClickAction ca)
Qt::KeyboardModifiers playPathStateKey() const
Abstract class for objects that grab mouse focus in a QGLViewer.
static int QGLViewerIndex(const QGLViewer *const viewer)
virtual void endSelection(const QPoint &point)
static QString QGLViewerVersionString()
void setHandlerKeyboardModifiers(MouseHandler handler, Qt::KeyboardModifiers modifiers)
ManipulatedCameraFrame * frame() const
virtual void mouseMoveEvent(QMouseEvent *)
virtual void select(const QMouseEvent *event)
virtual void mousePressEvent(QMouseEvent *const event, Camera *const camera)
virtual void setPlayKeyFramePathStateKey(int buttonState)
void setKeyDescription(int key, QString description)
void setShortcut(KeyboardAction action, unsigned int key)
The Vec class represents 3D positions and 3D vectors.
const GLdouble * matrix() const
virtual void startScreenCoordinatesSystem(bool upward=false) const
virtual void wheelEvent(QWheelEvent *const event, Camera *const camera)
virtual void setAddKeyFrameKeyboardModifiers(Qt::KeyboardModifiers modifiers)
void setWheelBinding(Qt::KeyboardModifiers modifiers, MouseHandler handler, MouseAction action, bool withConstraint=true)
Qt::KeyboardModifiers addKeyFrameKeyboardModifiers() const
virtual void setPathKey(int key, int index=0)
void setKeyboardAccelerator(KeyboardAction action, int key)
bool cameraIsInRevolveMode() const
void connectAllCameraKFIInterpolatedSignals(bool connection=true)
void copyBufferToTexture(GLint internalFormat, GLenum format=GL_NONE)
virtual void initFromDOMElement(const QDomElement &element)
static void saveStateToFileForAllViewers()
void setManipulatedFrame(qglviewer::ManipulatedFrame *frame)
int keyboardAccelerator(KeyboardAction action) const
void setDefaultShortcuts()
static QString formatClickActionPrivate(ClickActionPrivate cap)
GLuint bufferTextureId() const
void setSelectBufferSize(int size)
virtual QString keyboardString() const
static Qt::KeyboardModifiers convertKeyboardModifiers(Qt::KeyboardModifiers modifiers)
static QString mouseButtonsString(Qt::MouseButtons b)
bool interpolationIsStarted() const
void setFullScreen(bool fullScreen=true)
virtual void startAnimation()
static void drawGrid(float size=1.0f, int nbSubdivisions=10)
virtual void setAddKeyFrameStateKey(int buttonState)
int wheelButtonState(MouseHandler handler, MouseAction action, bool withConstraint=true) const
static const QPtrList< QGLViewer > & QGLViewerPool()
void setMouseGrabber(qglviewer::MouseGrabber *mouseGrabber)
void setMouseBinding(int state, MouseHandler handler, MouseAction action, bool withConstraint=true)
virtual void mouseDoubleClickEvent(QMouseEvent *)
#define KeyboardModifierMask
static QColor QColorFromDom(const QDomElement &e)
A versatile 3D OpenGL viewer based on QGLWidget.
void setCameraIsEdited(bool edit=true)
MouseAction wheelAction(Qt::KeyboardModifiers modifiers) const
virtual void preDrawStereo(bool leftBuffer=true)
QString cameraPathKeysString() const
static void drawAxis(float length=1.0f)
A perspective or orthographic camera.
static int convertToKeyboardModifiers(int state)
The Quaternion class represents 3D rotations and orientations.
Qt::KeyboardModifiers modifiers
virtual QDomElement domElement(const QString &name, QDomDocument &document) const
virtual bool restoreStateFromFile()
void performClickAction(ClickAction ca, const QMouseEvent *const e)
virtual void drawVisualHints()
virtual void keyPressEvent(QKeyEvent *)
Qt::Key keyFrameKey(int index) const
MouseAction mouseAction(int state) const
static bool boolFromDom(const QDomElement &e, const QString &attribute, bool defValue)
void setSceneRadius(float radius)
The Frame class represents a coordinate system, defined by a position and an orientation.
void setMouseStateKey(MouseHandler handler, int buttonState)
static int intFromDom(const QDomElement &e, const QString &attribute, int defValue)
void getClickButtonState(ClickAction action, int &state, bool &doubleClick, Qt::MouseButtons &buttonsBefore) const
static QString keyboardModifiersString(Qt::KeyboardModifiers m, bool noButton=false)
virtual void setVisualHintsMask(int mask, int delay=2000)
static QString tableLine(const QString &left, const QString &right)
int main(int argc, char *argv[])
void handleKeyboardAction(KeyboardAction id)
virtual void drawLight(GLenum light, float scale=1.0f) const
virtual void resizeGL(int width, int height)
unsigned int shortcut(KeyboardAction action) const
int mouseHandler(int state) const
Qt::Key pathKey(int index) const
virtual void initializeGL()
void saveToFile(const QString &fileName=QString::null)
virtual void mouseReleaseEvent(QMouseEvent *)
virtual void setPlayPathStateKey(int buttonState)
virtual void beginSelection(const QPoint &point)
virtual void startAction(int ma, bool withConstraint=true)
virtual void mousePressEvent(QMouseEvent *)
void displayMessage(const QString &message, int delay=2000)