23 #ifndef QGLVIEWER_QGLVIEWER_H
24 #define QGLVIEWER_QGLVIEWER_H
28 #if QT_VERSION >= 0x040000
30 # include <QClipboard>
33 # include <qclipboard.h>
42 #if QT_VERSION >= 0x040000
44 # define QtKeyboardModifiers Qt::KeyboardModifiers
45 # define QtMouseButtons Qt::MouseButtons
47 # define QtKeyboardModifiers Qt::ButtonState
48 # define QtMouseButtons Qt::ButtonState
80 #if QT_VERSION < 0x040000 || defined QT3_SUPPORT
81 explicit QGLViewer(QWidget* parent=NULL,
const char* name=0,
const QGLWidget* shareWidget=0, Qt::WFlags flags=0)
82 : QGLWidget(parent, name, shareWidget, flags)
83 { defaultConstructor(); }
85 explicit QGLViewer(
const QGLFormat& format, QWidget* parent=0,
const char* name=0,
const QGLWidget* shareWidget=0,Qt::WFlags flags=0)
86 : QGLWidget(format, parent, name, shareWidget, flags)
87 { defaultConstructor(); }
89 QGLViewer(QGLContext* context, QWidget* parent,
const char* name=0,
const QGLWidget* shareWidget=0, Qt::WFlags flags=0)
90 # if QT_VERSION >= 0x030200
91 : QGLWidget(context, parent, name, shareWidget, flags) {
94 : QGLWidget(parent, name, shareWidget, flags) {
98 defaultConstructor(); }
102 explicit QGLViewer(QWidget* parent=0,
const QGLWidget* shareWidget=0, Qt::WFlags flags=0);
103 explicit QGLViewer(QGLContext *context, QWidget* parent=0,
const QGLWidget* shareWidget=0, Qt::WFlags flags=0);
104 explicit QGLViewer(
const QGLFormat& format, QWidget* parent=0,
const QGLWidget* shareWidget=0, Qt::WFlags flags=0);
146 void setAxisIsDrawn(
bool draw=
true) { axisIsDrawn_ = draw; Q_EMIT axisIsDrawnChanged(draw);
if (updateGLOK_) updateGL(); };
148 void setGridIsDrawn(
bool draw=
true) { gridIsDrawn_ = draw; Q_EMIT gridIsDrawnChanged(draw);
if (updateGLOK_) updateGL(); };
150 void setFPSIsDisplayed(
bool display=
true) { FPSIsDisplayed_ = display; Q_EMIT FPSIsDisplayedChanged(display);
if (updateGLOK_) updateGL(); };
152 void setTextIsEnabled(
bool enable=
true) { textIsEnabled_ = enable; Q_EMIT textIsEnabledChanged(enable);
if (updateGLOK_) updateGL(); };
153 void setCameraIsEdited(
bool edit=
true);
329 float aspectRatio()
const {
return static_cast<float>(width())/static_cast<float>(height()); };
370 virtual QSize
sizeHint()
const {
return QSize(600, 400); }
373 void setFullScreen(
bool fullScreen=
true);
374 void setStereoDisplay(
bool stereo=
true);
379 void toggleCameraMode();
382 bool cameraIsInRevolveMode()
const;
389 static void drawArrow(
float length=1.0f,
float radius=-1.0f,
int nbSubdivisions=12);
391 static void drawAxis(
float length=1.0f);
392 static void drawGrid(
float size=1.0f,
int nbSubdivisions=10);
394 virtual void startScreenCoordinatesSystem(
bool upward=
false)
const;
395 virtual void stopScreenCoordinatesSystem()
const;
397 void drawText(
int x,
int y,
const QString& text,
const QFont& fnt=QFont());
398 void displayMessage(
const QString& message,
int delay=2000);
402 virtual void drawLight(GLenum light,
float scale = 1.0f)
const;
407 void drawVectorial() { paintGL(); };
410 friend void drawVectorial(
void* param);
424 virtual void updateGL();
427 static QImage convertToGLFormat(
const QImage & image);
429 void qglColor(
const QColor& color)
const;
431 void qglClearColor(
const QColor& color)
const;
434 bool isValid()
const;
437 bool isSharing()
const;
440 virtual void makeCurrent();
445 bool hasMouseTracking ()
const;
448 virtual void resize(
int width,
int height);
450 virtual void setMouseTracking(
bool enable);
454 bool autoBufferSwap()
const;
457 void setAutoBufferSwap(
bool on);
465 #if QT_VERSION < 0x030000
466 virtual QImage grabFrameBuffer(
bool withAlpha=
false);
479 const QString& snapshotFilename()
const;
529 void saveSnapshot(
bool automatic=
true,
bool overwrite=
false);
532 void saveSnapshot(
const QString& fileName,
bool overwrite=
false);
533 void setSnapshotFileName(
const QString& name);
541 bool openSnapshotFormatDialog();
542 void snapshotToClipboard();
545 bool saveImageSnapshot(
const QString& fileName);
553 class TileRegion {
public :
double xMin, yMin, xMax, yMax, textScale; };
575 if (tileRegion_ == NULL)
579 if (f.pixelSize() == -1)
580 #
if QT_VERSION >= 0x040000
581 f.setPointSizeF(f.pointSizeF() * tileRegion_->textScale);
583 f.setPointSizeFloat(f.pointSizeFloat() * tileRegion_->textScale);
586 f.setPixelSize(f.pixelSize() * tileRegion_->textScale);
596 GLuint bufferTextureId()
const;
609 void copyBufferToTexture(GLint internalFormat, GLenum format=GL_NONE);
643 virtual void startAnimation();
644 virtual void stopAnimation();
656 virtual void animate() { Q_EMIT animateNeeded(); };
658 void toggleAnimation() {
if (animationIsStarted()) stopAnimation();
else startAnimation(); };
666 void viewerInitialized();
685 void drawFinished(
bool automatic);
690 void animateNeeded();
698 void axisIsDrawnChanged(
bool drawn);
700 void gridIsDrawnChanged(
bool drawn);
702 void FPSIsDisplayedChanged(
bool displayed);
704 void textIsEnabledChanged(
bool enabled);
706 void cameraIsEditedChanged(
bool edited);
708 void stereoChanged(
bool on);
713 void pointSelected(
const QMouseEvent* e);
739 virtual QString
helpString()
const {
return tr(
"No help available."); };
741 virtual QString mouseString()
const;
742 virtual QString keyboardString()
const;
753 virtual void aboutQGLViewer();
768 virtual void resizeGL(
int width,
int height);
769 virtual void initializeGL();
788 virtual void init() { Q_EMIT viewerInitialized(); };
790 virtual void paintGL();
791 virtual void preDraw();
792 virtual void preDrawStereo(
bool leftBuffer=
true);
810 virtual void fastDraw();
811 virtual void postDraw();
817 virtual void mousePressEvent(QMouseEvent *);
818 virtual void mouseMoveEvent(QMouseEvent *);
819 virtual void mouseReleaseEvent(QMouseEvent *);
820 virtual void mouseDoubleClickEvent(QMouseEvent *);
821 virtual void wheelEvent(QWheelEvent *);
822 virtual void keyPressEvent(QKeyEvent *);
823 virtual void timerEvent(QTimerEvent *);
824 virtual void closeEvent(QCloseEvent *);
872 virtual void select(
const QMouseEvent* event);
873 virtual void select(
const QPoint& point);
875 void setSelectBufferSize(
int size);
887 virtual void beginSelection(
const QPoint& point);
911 virtual void endSelection(
const QPoint& point);
930 enum KeyboardAction { DRAW_AXIS, DRAW_GRID, DISPLAY_FPS, ENABLE_TEXT, EXIT_VIEWER,
931 SAVE_SCREENSHOT, CAMERA_MODE, FULL_SCREEN, STEREO, ANIMATION, HELP, EDIT_CAMERA,
932 MOVE_CAMERA_LEFT, MOVE_CAMERA_RIGHT, MOVE_CAMERA_UP, MOVE_CAMERA_DOWN,
933 INCREASE_FLYSPEED, DECREASE_FLYSPEED, SNAPSHOT_TO_CLIPBOARD };
935 int shortcut(KeyboardAction action)
const;
938 int keyboardAccelerator(KeyboardAction action)
const;
939 Qt::Key keyFrameKey(
int index)
const;
940 QtKeyboardModifiers playKeyFramePathStateKey()
const;
942 QtKeyboardModifiers addKeyFrameStateKey()
const;
943 QtKeyboardModifiers playPathStateKey()
const;
945 Qt::Key pathKey(
int index)
const;
946 QtKeyboardModifiers addKeyFrameKeyboardModifiers()
const;
947 QtKeyboardModifiers playPathKeyboardModifiers()
const;
950 void setShortcut(KeyboardAction action,
int key);
952 void setKeyboardAccelerator(KeyboardAction action,
int key);
954 void setKeyDescription(
int key, QString description);
959 virtual void setKeyFrameKey(
int index,
int key);
960 virtual void setPlayKeyFramePathStateKey(
int buttonState);
962 virtual void setPlayPathStateKey(
int buttonState);
963 virtual void setAddKeyFrameStateKey(
int buttonState);
965 virtual void setPathKey(
int key,
int index = 0);
966 virtual void setPlayPathKeyboardModifiers(QtKeyboardModifiers modifiers);
967 virtual void setAddKeyFrameKeyboardModifiers(QtKeyboardModifiers modifiers);
984 enum ClickAction { NO_CLICK_ACTION, ZOOM_ON_PIXEL, ZOOM_TO_FIT, SELECT, RAP_FROM_PIXEL, RAP_IS_CENTER,
985 CENTER_FRAME, CENTER_SCENE, SHOW_ENTIRE_SCENE, ALIGN_FRAME, ALIGN_CAMERA };
998 ROTATE, ZOOM, TRANSLATE,
999 MOVE_FORWARD, LOOK_AROUND, MOVE_BACKWARD,
1000 SCREEN_ROTATE, ROLL, DRIVE,
1001 SCREEN_TRANSLATE, ZOOM_ON_REGION };
1007 MouseAction mouseAction(
int state)
const;
1008 int mouseHandler(
int state)
const;
1009 int mouseButtonState(MouseHandler handler, MouseAction action,
bool withConstraint=
true)
const;
1010 ClickAction clickAction(
int state,
bool doubleClick, QtMouseButtons buttonsBefore)
const;
1011 void getClickButtonState(ClickAction action,
int& state,
bool& doubleClick, QtMouseButtons& buttonsBefore)
const;
1013 MouseAction wheelAction(QtKeyboardModifiers modifiers)
const;
1014 int wheelHandler(QtKeyboardModifiers modifiers)
const;
1015 int wheelButtonState(MouseHandler handler, MouseAction action,
bool withConstraint=
true)
const;
1018 void setMouseBinding(
int state, MouseHandler handler, MouseAction action,
bool withConstraint=
true);
1019 #if QT_VERSION < 0x030000
1023 void setMouseBinding(
int state, ClickAction action,
bool doubleClick=
false, QtMouseButtons buttonsBefore=Qt::NoButton);
1024 void setMouseBindingDescription(
int state, QString description,
bool doubleClick=
false, QtMouseButtons buttonsBefore=Qt::NoButton);
1025 #if QT_VERSION < 0x030000
1028 void setWheelBinding(QtKeyboardModifiers modifiers, MouseHandler handler, MouseAction action,
bool withConstraint=
true);
1029 void setHandlerKeyboardModifiers(MouseHandler handler, QtKeyboardModifiers modifiers);
1031 void setHandlerStateKey(MouseHandler handler,
int buttonState);
1032 void setMouseStateKey(MouseHandler handler,
int buttonState);
1044 QString stateFileName()
const;
1045 virtual QDomElement domElement(
const QString& name, QDomDocument& document)
const;
1048 virtual void initFromDOMElement(
const QDomElement& element);
1049 virtual void saveStateToFile();
1050 virtual bool restoreStateFromFile();
1067 void saveToFile(
const QString& fileName=QString::null);
1068 bool restoreFromFile(
const QString& fileName=QString::null);
1072 static void saveStateToFileForAllViewers();
1090 #if QT_VERSION >= 0x040000
1091 static const QList<QGLViewer*>& QGLViewerPool() {
return QGLViewer::QGLViewerPool_; };
1093 static const QPtrList<QGLViewer>&
QGLViewerPool() {
return QGLViewer::QGLViewerPool_; };
1104 #if QT_VERSION >= 0x040000
1105 static int QGLViewerIndex(
const QGLViewer*
const viewer) {
return QGLViewer::QGLViewerPool_.indexOf(const_cast<QGLViewer*>(viewer)); };
1115 virtual void setVisualHintsMask(
int mask,
int delay = 2000);
1116 virtual void drawVisualHints();
1119 virtual void resetVisualHints();
1125 void delayedFullScreen() { move(prevPos_); setFullScreen(); };
1135 void defaultConstructor();
1137 void handleKeyboardAction(KeyboardAction
id);
1141 bool cameraIsEdited_;
1142 float previousCameraZClippingCoefficient_;
1143 int previousPathId_;
1144 void connectAllCameraKFIInterpolatedSignals(
bool connection=
true);
1147 QColor backgroundColor_, foregroundColor_;
1152 bool FPSIsDisplayed_;
1153 bool textIsEnabled_;
1159 bool animationStarted_;
1160 int animationPeriod_;
1161 int animationTimerId_;
1165 unsigned int fpsCounter_;
1171 bool displayMessage_;
1172 QTimer messageTimer_;
1176 bool manipulatedFrameIsACamera_;
1180 bool mouseGrabberIsAManipulatedFrame_;
1181 bool mouseGrabberIsAManipulatedCameraFrame_;
1182 QMap<size_t, bool> disabledMouseGrabbers_;
1185 int selectRegionWidth_, selectRegionHeight_;
1186 int selectBufferSize_;
1187 GLuint* selectBuffer_;
1188 int selectedObjectId_;
1194 void setDefaultShortcuts();
1195 QString cameraPathKeysString()
const;
1196 QMap<KeyboardAction, QString> keyboardActionDescription_;
1197 QMap<KeyboardAction, int> keyboardBinding_;
1198 QMap<int, QString> keyDescription_;
1201 QMap<Qt::Key, int> pathIndex_;
1202 QtKeyboardModifiers addKeyFrameKeyboardModifiers_, playPathKeyboardModifiers_;
1205 GLuint bufferTextureId_;
1206 float bufferTextureMaxU_, bufferTextureMaxV_;
1207 int bufferTextureWidth_, bufferTextureHeight_;
1208 unsigned int previousBufferTextureFormat_;
1209 int previousBufferTextureInternalFormat_;
1213 struct MouseActionPrivate {
1214 MouseHandler handler;
1216 bool withConstraint;
1220 struct ClickActionPrivate {
1221 QtKeyboardModifiers modifiers;
1222 QtMouseButtons button;
1224 QtMouseButtons buttonsBefore;
1227 bool operator<(
const ClickActionPrivate& cap)
const
1229 if (buttonsBefore != cap.buttonsBefore)
1230 return buttonsBefore < cap.buttonsBefore;
1232 if (modifiers != cap.modifiers)
1233 return modifiers < cap.modifiers;
1235 if (button != cap.button)
1236 return button < cap.button;
1238 return !doubleClick && cap.doubleClick;
1242 static QString formatClickActionPrivate(ClickActionPrivate cap);
1244 QMap<ClickActionPrivate, QString> mouseDescription_;
1246 void setDefaultMouseBindings();
1247 void performClickAction(ClickAction ca,
const QMouseEvent*
const e);
1248 QMap<int, MouseActionPrivate> mouseBinding_;
1249 QMap<QtKeyboardModifiers, MouseActionPrivate> wheelBinding_;
1250 QMap<ClickActionPrivate, ClickAction> clickBinding_;
1253 void initializeSnapshotFormats();
1254 QImage frameBufferSnapshot();
1255 QString snapshotFileName_, snapshotFormat_;
1256 int snapshotCounter_, snapshotQuality_;
1257 TileRegion* tileRegion_;
1260 #if QT_VERSION >= 0x040000
1261 static QList<QGLViewer*> QGLViewerPool_;
1263 static QPtrList<QGLViewer> QGLViewerPool_;
1267 QString stateFileName_;
1270 QTabWidget* helpWidget_;
1276 #endif // QGLVIEWER_QGLVIEWER_H