viewer.h
00001 #ifndef VVVIEWER_H
00002 #define VVVIEWER_H
00003
00004 #include <config.h>
00005 #include <QGLViewer/qglviewer.h>
00006 #include <model.h>
00007 #include <QPointer>
00008
00009 class QDomElement;
00010 class QShowEvent;
00011 class QToolBar;
00012 class QMainWindow;
00013 class QMenuBar;
00014 class QMenu;
00015 class QKeyEvent;
00016 class QGLViewer;
00017
00030 class Viewer : public QGLViewer
00031 {
00032 Q_OBJECT
00033
00034 public:
00035
00037
00038
00043 Viewer( QWidget* parent, const QGLWidget *shareWidget = 0, int idx = -1 );
00047 ~Viewer();
00049
00050 static void initFormat();
00051
00055 Model* model() { return _model; }
00056
00058
00059
00062 virtual QDomElement domElement(const QString & name, QDomDocument &document) const;
00063
00069 virtual QString helpString() const
00070 {
00071 if(_model) return _model->helpString();
00072 else return QString(tr("Generic VV model"));
00073 }
00074
00078 void setIndex(int idx) { _index = idx; }
00079
00081
00083
00084
00090 const QString & screenshotFileName() const
00091 { return QGLViewer::snapshotFileName(); }
00092
00097 const QString & screenshotFormat() const
00098 { return QGLViewer::snapshotFormat (); }
00099
00105 int screenshotCounter() const
00106 { return QGLViewer::snapshotCounter(); }
00107
00113 int screenshotQuality()
00114 { return QGLViewer::snapshotQuality(); }
00115
00121 virtual void drawLight(GLenum light, float scale = 1.0f) { QGLViewer::drawLight(light, scale); }
00122
00123
00129 QMenuBar* menuBar(bool clear = true);
00130
00138 QMenu* helpMenu();
00139
00143 bool wasInitialized() const { return initialized; }
00144
00151 int index() const { return _index; }
00152
00158 void newViewer(const QGLWidget* shareWidget = 0);
00159
00165 void addViewer(QLayout *l, const QGLWidget* shareWidget = 0);
00166
00172 void addViewer(QWidget *w, const QGLWidget* shareWidget = 0);
00173
00174 public slots:
00178 void startRecordingCameraAnimation();
00179
00183 void stopRecordingCameraAnimation();
00184
00188 void startRecordingModelAnimation();
00189
00193 void stopRecordingModelAnimation();
00194
00200 void saveScreenshot (bool automatic=true, bool overwrite=false)
00201 { QGLViewer::saveSnapshot(automatic, overwrite); }
00202
00208 void saveScreenshot (const QString &fileName, bool overwrite=false)
00209 { QGLViewer::saveSnapshot(fileName, overwrite); }
00210
00216 void setScreenshotFileName (const QString &name)
00217 { QGLViewer::setSnapshotFileName(name); }
00218
00224 void setScreenshotFormat (const QString &format)
00225 { QGLViewer::setSnapshotFormat(format); }
00226
00232 void setScreenshotCounter (int counter)
00233 { QGLViewer::setSnapshotCounter(counter); }
00234
00240 void setScreenshotQuality (int quality)
00241 { QGLViewer::setSnapshotQuality(quality); }
00242
00248 bool openScreenshotFormatDialog ()
00249 { return QGLViewer::openSnapshotFormatDialog(); }
00250
00252
00256 virtual void setModel( Model* model );
00257
00261 virtual void initFromDOMElement(const QDomElement &element );
00262
00264
00266
00267
00268 void blockDraw(bool block=true) { if(block) block_draw++; else block_draw--; }
00269
00271
00273 void configOpenGL();
00274
00276 void updateAll();
00277
00278 signals:
00280
00281
00284 void stepDrawFinished(bool);
00285
00289 void openOpenGLConfig();
00290
00294 void modelRecordingStart();
00295
00299 void cameraRecordingStop();
00300
00304 void cameraRecordingStart();
00305
00309 void modelRecordingStop();
00310
00314 void createViewer(const QGLWidget* shareWidget);
00315
00319 void createViewer(QLayout *l, const QGLWidget* shareWidget);
00320
00324 void createViewer(QWidget *w, const QGLWidget* shareWidget);
00325
00327
00328 public:
00329
00331
00332
00337 virtual void preDraw()
00338 { QGLViewer::preDraw(); if( _model and !block_draw ) _model->preDraw(this); }
00344 virtual void draw()
00345 { if( _model and !block_draw ) _model->draw(this); }
00351 virtual void postDraw();
00352
00358 virtual void init();
00359
00365 virtual void drawWithNames()
00366 { if (_model) _model->drawWithNames(this); }
00367
00371 virtual void postSelection(const QPoint& pos)
00372 { if(_model) _model->postSelection(pos, this); }
00373
00375
00379 void showEvent(QShowEvent* event);
00380
00384 QString statusMessage() const;
00385
00391 void setStatusMessage(const QString& msg);
00392
00396 QToolBar* addToolBar(const QString& title);
00397
00401 void addToolBar(Qt::ToolBarArea area, QToolBar* toolbar);
00402
00406 QMainWindow *mainWindow();
00407
00411 void keyPressEvent(QKeyEvent *e);
00412
00413 private:
00414 QString fullSnapshotFileName();
00415 void initObject();
00416 QPointer<Model> _model;
00417 bool animation;
00418 bool initialized;
00419 qglviewer::Camera *lastInitCamera;
00420
00421 size_t _index;
00422 void initCamera();
00423 int block_draw;
00424 int minFrameInterval;
00425
00429 QMainWindow *main_window;
00430 };
00431
00432 #endif // VVVIEWER_H
00433