23 #ifndef QGLVIEWER_QGLVIEWER_H 24 #define QGLVIEWER_QGLVIEWER_H 36 class ManipulatedFrame;
37 class ManipulatedCameraFrame;
70 explicit QGLViewer(QWidget* parent=NULL,
const char* name=0,
const QGLWidget* shareWidget=0, Qt::WindowFlags flags=0)
71 : QGLWidget(parent, name, shareWidget, flags)
72 { defaultConstructor(); }
74 explicit QGLViewer(
const QGLFormat& format, QWidget* parent=0,
const char* name=0,
const QGLWidget* shareWidget=0,Qt::WindowFlags flags=0)
75 : QGLWidget(format, parent, name, shareWidget, flags)
76 { defaultConstructor(); }
78 QGLViewer(QGLContext* context, QWidget* parent,
const char* name=0,
const QGLWidget* shareWidget=0, Qt::WindowFlags flags=0)
79 : QGLWidget(context, parent, name, shareWidget, flags) {
80 defaultConstructor(); }
84 explicit QGLViewer(QWidget* parent=0,
const QGLWidget* shareWidget=0, Qt::WindowFlags flags=0);
85 explicit QGLViewer(QGLContext *context, QWidget* parent=0,
const QGLWidget* shareWidget=0, Qt::WindowFlags flags=0);
86 explicit QGLViewer(
const QGLFormat& format, QWidget* parent=0,
const QGLWidget* shareWidget=0, Qt::WindowFlags flags=0);
128 void setAxisIsDrawn(
bool draw=
true) { axisIsDrawn_ = draw; Q_EMIT axisIsDrawnChanged(draw); update(); }
130 void setGridIsDrawn(
bool draw=
true) { gridIsDrawn_ = draw; Q_EMIT gridIsDrawnChanged(draw); update(); }
132 void setFPSIsDisplayed(
bool display=
true) { FPSIsDisplayed_ = display; Q_EMIT FPSIsDisplayedChanged(display); update(); }
134 void setTextIsEnabled(
bool enable=
true) { textIsEnabled_ = enable; Q_EMIT textIsEnabledChanged(enable); update(); }
135 void setCameraIsEdited(
bool edit=
true);
311 qreal
aspectRatio()
const {
return width() /
static_cast<qreal
>(height()); }
351 virtual QSize
sizeHint()
const {
return QSize(600, 400); }
354 void setFullScreen(
bool fullScreen=
true);
355 void setStereoDisplay(
bool stereo=
true);
360 void toggleCameraMode();
363 bool cameraIsInRotateMode()
const;
370 static void drawArrow(qreal length=1.0, qreal radius=-1.0,
int nbSubdivisions=12);
372 static void drawAxis(qreal length=1.0);
373 static void drawGrid(qreal size=1.0,
int nbSubdivisions=10);
375 virtual void startScreenCoordinatesSystem(
bool upward=
false)
const;
376 virtual void stopScreenCoordinatesSystem()
const;
378 void drawText(
int x,
int y,
const QString& text,
const QFont& fnt=QFont());
379 void displayMessage(
const QString& message,
int delay=2000);
383 virtual void drawLight(GLenum light, qreal scale = 1.0)
const;
405 virtual void updateGL();
408 static QImage convertToGLFormat(
const QImage & image);
410 void qglColor(
const QColor& color)
const;
412 void qglClearColor(
const QColor& color)
const;
415 bool isValid()
const;
418 bool isSharing()
const;
421 virtual void makeCurrent();
426 bool hasMouseTracking ()
const;
429 virtual void resize(
int width,
int height);
431 virtual void setMouseTracking(
bool enable);
435 bool autoBufferSwap()
const;
438 void setAutoBufferSwap(
bool on);
457 const QString& snapshotFilename()
const;
507 void saveSnapshot(
bool automatic=
true,
bool overwrite=
false);
510 void saveSnapshot(
const QString& fileName,
bool overwrite=
false);
511 void setSnapshotFileName(
const QString& name);
519 bool openSnapshotFormatDialog();
520 void snapshotToClipboard();
523 bool saveImageSnapshot(
const QString& fileName);
553 if (tileRegion_ == NULL)
557 if (f.pixelSize() == -1)
558 f.setPointSizeF(f.pointSizeF() * tileRegion_->textScale);
560 f.setPixelSize(
int(f.pixelSize() * tileRegion_->textScale));
570 GLuint bufferTextureId()
const;
583 void copyBufferToTexture(GLint internalFormat, GLenum format=GL_NONE);
617 virtual void startAnimation();
618 virtual void stopAnimation();
630 virtual void animate() { Q_EMIT animateNeeded(); }
632 void toggleAnimation() {
if (animationIsStarted()) stopAnimation();
else startAnimation(); }
640 void viewerInitialized();
659 void drawFinished(
bool automatic);
664 void animateNeeded();
672 void axisIsDrawnChanged(
bool drawn);
674 void gridIsDrawnChanged(
bool drawn);
676 void FPSIsDisplayedChanged(
bool displayed);
678 void textIsEnabledChanged(
bool enabled);
680 void cameraIsEditedChanged(
bool edited);
682 void stereoChanged(
bool on);
687 void pointSelected(
const QMouseEvent* e);
713 virtual QString
helpString()
const {
return tr(
"No help available."); }
715 virtual QString mouseString()
const;
716 virtual QString keyboardString()
const;
727 virtual void aboutQGLViewer();
742 virtual void resizeGL(
int width,
int height);
743 virtual void initializeGL();
762 virtual void init() { Q_EMIT viewerInitialized(); }
764 virtual void paintGL();
765 virtual void preDraw();
766 virtual void preDrawStereo(
bool leftBuffer=
true);
784 virtual void fastDraw();
785 virtual void postDraw();
791 virtual void mousePressEvent(QMouseEvent *);
792 virtual void mouseMoveEvent(QMouseEvent *);
793 virtual void mouseReleaseEvent(QMouseEvent *);
794 virtual void mouseDoubleClickEvent(QMouseEvent *);
795 virtual void wheelEvent(QWheelEvent *);
796 virtual void keyPressEvent(QKeyEvent *);
797 virtual void keyReleaseEvent(QKeyEvent *);
798 virtual void timerEvent(QTimerEvent *);
799 virtual void closeEvent(QCloseEvent *);
847 virtual void select(
const QMouseEvent* event);
848 virtual void select(
const QPoint& point);
850 void setSelectBufferSize(
int size);
862 virtual void beginSelection(
const QPoint& point);
886 virtual void endSelection(
const QPoint& point);
905 enum KeyboardAction { DRAW_AXIS, DRAW_GRID, DISPLAY_FPS, ENABLE_TEXT, EXIT_VIEWER,
906 SAVE_SCREENSHOT, CAMERA_MODE, FULL_SCREEN,
STEREO, ANIMATION, HELP, EDIT_CAMERA,
908 INCREASE_FLYSPEED, DECREASE_FLYSPEED, SNAPSHOT_TO_CLIPBOARD };
914 Qt::Key keyFrameKey(
unsigned int index)
const;
915 Qt::KeyboardModifiers playKeyFramePathStateKey()
const;
917 Qt::KeyboardModifiers addKeyFrameStateKey()
const;
918 Qt::KeyboardModifiers playPathStateKey()
const;
920 Qt::Key pathKey(
unsigned int index)
const;
921 Qt::KeyboardModifiers addKeyFrameKeyboardModifiers()
const;
922 Qt::KeyboardModifiers playPathKeyboardModifiers()
const;
927 void setKeyboardAccelerator(
KeyboardAction action,
unsigned int key);
929 void setKeyDescription(
unsigned int key, QString description);
930 void clearShortcuts();
935 virtual void setKeyFrameKey(
unsigned int index,
int key);
936 virtual void setPlayKeyFramePathStateKey(
unsigned int buttonState);
938 virtual void setPlayPathStateKey(
unsigned int buttonState);
939 virtual void setAddKeyFrameStateKey(
unsigned int buttonState);
941 virtual void setPathKey(
int key,
unsigned int index = 0);
942 virtual void setPlayPathKeyboardModifiers(Qt::KeyboardModifiers modifiers);
943 virtual void setAddKeyFrameKeyboardModifiers(Qt::KeyboardModifiers modifiers);
973 SCREEN_TRANSLATE, ZOOM_ON_REGION };
977 int mouseHandler(
unsigned int state)
const;
979 ClickAction clickAction(
unsigned int state,
bool doubleClick, Qt::MouseButtons buttonsBefore)
const;
980 void getClickButtonState(
ClickAction action,
unsigned int & state,
bool& doubleClick, Qt::MouseButtons& buttonsBefore)
const;
984 MouseAction mouseAction(Qt::Key key, Qt::KeyboardModifiers modifiers, Qt::MouseButton button)
const;
985 int mouseHandler(Qt::Key key, Qt::KeyboardModifiers modifiers, Qt::MouseButton button)
const;
988 Qt::Key& key, Qt::KeyboardModifiers& modifiers, Qt::MouseButton& button)
const;
990 ClickAction clickAction(Qt::Key key, Qt::KeyboardModifiers modifiers, Qt::MouseButton button,
991 bool doubleClick=
false, Qt::MouseButtons buttonsBefore=Qt::NoButton)
const;
993 void getClickActionBinding(
ClickAction action, Qt::Key& key, Qt::KeyboardModifiers& modifiers,
994 Qt::MouseButton& button,
bool& doubleClick, Qt::MouseButtons& buttonsBefore)
const;
996 MouseAction wheelAction(Qt::Key key, Qt::KeyboardModifiers modifiers)
const;
997 int wheelHandler(Qt::Key key, Qt::KeyboardModifiers modifiers)
const;
1000 Qt::Key& key, Qt::KeyboardModifiers& modifiers)
const;
1005 void setMouseBinding(
unsigned int state,
ClickAction action,
bool doubleClick=
false, Qt::MouseButtons buttonsBefore=Qt::NoButton);
1006 void setMouseBindingDescription(
unsigned int state, QString description,
bool doubleClick=
false, Qt::MouseButtons buttonsBefore=Qt::NoButton);
1009 void setMouseBinding(Qt::KeyboardModifiers modifiers, Qt::MouseButton buttons,
MouseHandler handler,
MouseAction action,
bool withConstraint=
true);
1010 void setMouseBinding(Qt::KeyboardModifiers modifiers, Qt::MouseButton button,
ClickAction action,
bool doubleClick=
false, Qt::MouseButtons buttonsBefore=Qt::NoButton);
1011 void setWheelBinding(Qt::KeyboardModifiers modifiers,
MouseHandler handler,
MouseAction action,
bool withConstraint=
true);
1012 void setMouseBindingDescription(Qt::KeyboardModifiers modifiers, Qt::MouseButton button, QString description,
bool doubleClick=
false, Qt::MouseButtons buttonsBefore=Qt::NoButton);
1014 void setMouseBinding(Qt::Key key, Qt::KeyboardModifiers modifiers, Qt::MouseButton buttons,
MouseHandler handler,
MouseAction action,
bool withConstraint=
true);
1015 void setMouseBinding(Qt::Key key, Qt::KeyboardModifiers modifiers, Qt::MouseButton button,
ClickAction action,
bool doubleClick=
false, Qt::MouseButtons buttonsBefore=Qt::NoButton);
1016 void setWheelBinding(Qt::Key key, Qt::KeyboardModifiers modifiers,
MouseHandler handler,
MouseAction action,
bool withConstraint=
true);
1017 void setMouseBindingDescription(Qt::Key key, Qt::KeyboardModifiers modifiers, Qt::MouseButton button, QString description,
bool doubleClick=
false, Qt::MouseButtons buttonsBefore=Qt::NoButton);
1019 void clearMouseBindings();
1022 MouseAction wheelAction(Qt::KeyboardModifiers modifiers)
const;
1023 int wheelHandler(Qt::KeyboardModifiers modifiers)
const;
1025 void setHandlerKeyboardModifiers(
MouseHandler handler, Qt::KeyboardModifiers modifiers);
1026 void setHandlerStateKey(
MouseHandler handler,
unsigned int buttonState);
1027 void setMouseStateKey(
MouseHandler handler,
unsigned int buttonState);
1039 QString stateFileName()
const;
1040 virtual QDomElement domElement(
const QString& name, QDomDocument& document)
const;
1043 virtual void initFromDOMElement(
const QDomElement& element);
1044 virtual void saveStateToFile();
1045 virtual bool restoreStateFromFile();
1062 void saveToFile(
const QString& fileName=QString::null);
1063 bool restoreFromFile(
const QString& fileName=QString::null);
1067 static void saveStateToFileForAllViewers();
1102 virtual void setVisualHintsMask(
int mask,
int delay = 2000);
1103 virtual void drawVisualHints();
1106 virtual void resetVisualHints();
1122 void defaultConstructor();
1131 void connectAllCameraKFIInterpolatedSignals(
bool connection=
true);
1181 void setDefaultShortcuts();
1182 QString cameraPathKeysString()
const;
1213 : modifiers(m), button(b), key(k) {}
1219 return key < mbp.
key;
1222 return button < mbp.
button;
1232 : modifiers(m), key(k) {}
1238 return key < wbp.
key;
1252 : modifiers(m), button(b), doubleClick(dc), buttonsBefore(bb), key(k) {}
1258 return key < cbp.
key;
1263 if (button != cbp.
button)
1264 return button < cbp.
button;
1270 static bool isValidShortcutKey(
int key);
1274 void setDefaultMouseBindings();
1275 void performClickAction(
ClickAction ca,
const QMouseEvent*
const e);
1282 void initializeSnapshotFormats();
1283 QImage frameBufferSnapshot();
1298 #endif // QGLVIEWER_QGLVIEWER_H
int selectRegionHeight() const
const Qt::MouseButton button
QMap< unsigned int, QString > keyDescription_
QTabWidget * helpWidget()
ClickBindingPrivate(Qt::KeyboardModifiers m, Qt::MouseButton b, bool dc, Qt::MouseButtons bb, Qt::Key k)
bool operator<(const ClickBindingPrivate &cbp) const
WheelBindingPrivate(Qt::KeyboardModifiers m, Qt::Key k)
void toggleFPSIsDisplayed()
A ManipulatedFrame is a Frame that can be rotated and translated using the mouse. ...
void drawVectorial(void *param)
bool operator<(const WheelBindingPrivate &wbp) const
void setSnapshotQuality(int quality)
Qt::KeyboardModifiers playPathKeyboardModifiers_
qreal sceneRadius() const
void setForegroundColor(const QColor &color)
virtual QString shortcutBindingsString() const
QMap< ClickBindingPrivate, ClickAction > clickBinding_
int previousBufferTextureInternalFormat_
qreal bufferTextureMaxV() const
qreal aspectRatio() const
virtual QString mouseBindingsString() const
QColor foregroundColor() const
virtual void setSceneRadius(qreal radius)
int selectBufferSize() const
QMap< KeyboardAction, QString > keyboardActionDescription_
static QList< QGLViewer * > QGLViewerPool_
unsigned int previousBufferTextureFormat_
int animationPeriod() const
void setSelectedName(int id)
void toggleCameraIsEdited()
qglviewer::MouseGrabber * mouseGrabber_
void setAnimationPeriod(int period)
qglviewer::Vec sceneCenter() const
Abstract class for objects that grab mouse focus in a QGLViewer.
static int QGLViewerIndex(const QGLViewer *const viewer)
unsigned int previousPathId_
void setGridIsDrawn(bool draw=true)
void setSnapshotFormat(const QString &format)
void setSelectRegionHeight(int height)
qglviewer::MouseGrabber * mouseGrabber() const
bool mouseGrabberIsAManipulatedCameraFrame_
void setTextIsEnabled(bool enable=true)
The Vec class represents 3D positions and 3D vectors.
Qt::Key currentlyPressedKey_
const Qt::KeyboardModifiers modifiers
QColor backgroundColor() const
QFont scaledFont(const QFont &font) const
bool cameraIsEdited() const
qglviewer::ManipulatedFrame * manipulatedFrame() const
bool manipulatedFrameIsACamera_
void setAxisIsDrawn(bool draw=true)
virtual QString helpString() const
virtual void drawWithNames()
void setFPSIsDisplayed(bool display=true)
qglviewer::ManipulatedFrame * manipulatedFrame_
qreal bufferTextureMaxU() const
void setSelectRegionWidth(int width)
bool displaysInStereo() const
QMap< WheelBindingPrivate, MouseActionPrivate > wheelBinding_
bool mouseGrabberIsAManipulatedFrame_
bool mouseGrabberIsEnabled(const qglviewer::MouseGrabber *const mouseGrabber)
void setStateFileName(const QString &name)
A versatile 3D OpenGL viewer based on QGLWidget.
const QString & snapshotFileName() const
QMap< MouseBindingPrivate, MouseActionPrivate > mouseBinding_
const Qt::KeyboardModifiers modifiers
void toggleTextIsEnabled()
void toggleStereoDisplay()
void setBackgroundColor(const QColor &color)
A perspective or orthographic camera.
int selectRegionWidth() const
QMap< size_t, bool > disabledMouseGrabbers_
int snapshotCounter() const
MouseBindingPrivate(Qt::KeyboardModifiers m, Qt::MouseButton b, Qt::Key k)
const Qt::MouseButton button
virtual QSize sizeHint() const
bool FPSIsDisplayed() const
QMap< Qt::Key, unsigned int > pathIndex_
virtual void setSceneCenter(const qglviewer::Vec ¢er)
bool isFullScreen() const
bool textIsEnabled() const
const QString & snapshotFormat() const
QMap< KeyboardAction, unsigned int > keyboardBinding_
bool operator<(const MouseBindingPrivate &mbp) const
qreal previousCameraZClippingCoefficient_
qglviewer::Camera * camera_
QMap< ClickBindingPrivate, QString > mouseDescription_
void setSceneBoundingBox(const qglviewer::Vec &min, const qglviewer::Vec &max)
virtual void postSelection(const QPoint &point)
static const QList< QGLViewer * > & QGLViewerPool()
void setSnapshotCounter(int counter)
const Qt::KeyboardModifiers modifiers
bool animationIsStarted() const
const Qt::MouseButtons buttonsBefore
qglviewer::Camera * camera() const