CoreWidget.cc

00001 /*===========================================================================*\
00002  *                                                                           *
00003  *                              OpenFlipper                                  *
00004  *      Copyright (C) 2001-2009 by Computer Graphics Group, RWTH Aachen      *
00005  *                           www.openflipper.org                             *
00006  *                                                                           *
00007  *---------------------------------------------------------------------------*
00008  *  This file is part of OpenFlipper.                                        *
00009  *                                                                           *
00010  *  OpenFlipper is free software: you can redistribute it and/or modify      *
00011  *  it under the terms of the GNU Lesser General Public License as           *
00012  *  published by the Free Software Foundation, either version 3 of           *
00013  *  the License, or (at your option) any later version with the              *
00014  *  following exceptions:                                                    *
00015  *                                                                           *
00016  *  If other files instantiate templates or use macros                       *
00017  *  or inline functions from this file, or you compile this file and         *
00018  *  link it with other files to produce an executable, this file does        *
00019  *  not by itself cause the resulting executable to be covered by the        *
00020  *  GNU Lesser General Public License. This exception does not however       *
00021  *  invalidate any other reasons why the executable file might be            *
00022  *  covered by the GNU Lesser General Public License.                        *
00023  *                                                                           *
00024  *  OpenFlipper is distributed in the hope that it will be useful,           *
00025  *  but WITHOUT ANY WARRANTY; without even the implied warranty of           *
00026  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            *
00027  *  GNU Lesser General Public License for more details.                      *
00028  *                                                                           *
00029  *  You should have received a copy of the GNU LesserGeneral Public          *
00030  *  License along with OpenFlipper. If not,                                  *
00031  *  see <http://www.gnu.org/licenses/>.                                      *
00032  *                                                                           *
00033 \*===========================================================================*/
00034 
00035 /*===========================================================================*\
00036  *                                                                           *
00037  *   $Revision: 8662 $                                                         *
00038  *   $Author: wilden $                                                      *
00039  *   $Date: 2010-03-03 16:54:58 +0100 (Mi, 03. Mär 2010) $                   *
00040  *                                                                           *
00041 \*===========================================================================*/
00042 
00043 
00044 
00045 //=============================================================================
00046 //
00047 //  CLASS MViewWidget - IMPLEMENTATION
00048 //
00049 //=============================================================================
00050 
00051 
00052 //== INCLUDES =================================================================
00053 
00054 // -------------------- mview
00055 #include "CoreWidget.hh"
00056 
00057 // -------------------- OpenFlipper Includes
00058 #include <OpenFlipper/common/GlobalOptions.hh>
00059 #include <OpenFlipper/common/RecentFiles.hh>
00060 #include <OpenFlipper/BasePlugin/PluginFunctions.hh>
00061 #include <OpenFlipper/BasePlugin/PluginFunctionsCore.hh>
00062 #include <OpenFlipper/BasePlugin/KeyInterface.hh>
00063 #include <OpenFlipper/BasePlugin/LoggingInterface.hh>
00064 
00065 #include <OpenFlipper/widgets/videoCaptureDialog/VideoCaptureDialog.hh>
00066 
00067 #include <OpenFlipper/widgets/glWidget/CursorPainter.hh>
00068 
00069 #define WIDGET_HEIGHT 800
00070 #define WIDGET_WIDTH  800
00071 
00072 //== IMPLEMENTATION ==========================================================
00073 
00077 CoreWidget::
00078 CoreWidget( QVector<ViewMode*>& _viewModes,
00079             std::vector<PluginInfo>& _plugins,
00080             QList< SlotInfo >& _coreSlots ) :
00081   QMainWindow(),
00082   coreSlots_(_coreSlots),
00083   shiftPressed_(false),
00084   fullscreenState_(0),
00085   viewModes_(_viewModes),
00086   viewModeButton_(0),
00087   viewModeMenu_(0),
00088   splitter_(0),
00089   logWidget_(0),
00090   recentFilesMenu_(0),
00091   helpMenu_(0),
00092   cursorPainter_(0),
00093   sceneGraphDialog_(0),
00094   fileMenu_(0),
00095   viewMenu_(0),
00096   toolsMenu_(0),
00097   fileMenuEnd_(0),
00098   stereoButton_(0),
00099   moveButton_(0),
00100   lightButton_(0),
00101   pickButton_(0),
00102   questionButton_(0),
00103   globalDrawMenu_(0),
00104   drawGroup_(0),
00105   viewGroup_(0),
00106   perspectiveProjectionAction_(0),
00107   activeDrawModes_(0),
00108   availableGlobalDrawModes_(0),
00109   contextMenu_(0),
00110   contextSelectionMenu_(0),
00111   drawGroupViewer_(0),
00112   viewerDrawMenu_(0),
00113   coordSysMenu_(0),
00114   snapshotName_(""),
00115   snapshotCounter_(0),
00116   stackMenu_(0),
00117   helpWidget_(0),
00118   stereoSettingsWidget_(0),
00119   aboutWidget_(0),
00120   optionsWidget_(0),
00121   plugins_(_plugins),
00122   stereoActive_(false),
00123   actionMode_(Viewer::PickingMode),
00124   lastActionMode_(Viewer::ExamineMode),
00125   pickMenu_(0),
00126   pick_mode_name_(""),
00127   pick_mode_idx_(-1)
00128 {
00129   setupStatusBar();
00130 
00131   defaultIconSize_ = iconSize();
00132 
00133   toolSplitter_ = new QSplitter(Qt::Horizontal,this);
00134 
00135   setCentralWidget(toolSplitter_);
00136 
00137   splitter_ = new QSplitter(Qt::Vertical,toolSplitter_);
00138   stackedWidget_ = new QStackedWidget(splitter_);
00139 
00140   QGLFormat format = QGLFormat::defaultFormat();
00141 
00142   #ifdef ARCH_DARWIN
00143   format.setStereo(false);
00144   #else
00145   format.setStereo( OpenFlipper::Options::stereo() );
00146   #endif
00147   format.setAlpha(true);
00148   format.setStencil(true);
00149   format.setSampleBuffers(true);
00150   QGLFormat::setDefaultFormat(format);
00151 
00152   // Construct GL context & widget
00153   baseLayout_ = new QtMultiViewLayout;
00154   baseLayout_->setContentsMargins(0,0,0,0);
00155 
00156   // ===============================================================================
00157   // Test context capabilities ...
00158   // If we get stereo buffers, we use them .. which might disable multisampling
00159   // If we dont have stereo, we disable it to not interfere with multisampling
00160   // ===============================================================================
00161   QGLWidget* test = new QGLWidget(format);
00162   if ( ! test->format().stereo() ) {
00163     //     std::cerr << "No stereo ... disabling stereo for real context!" << std::endl;
00164     format.setStereo(false);
00165     QGLFormat::setDefaultFormat(format);
00166   }/* else {
00167     std::cerr << "Stereo found ok" << std::endl;
00168   }*/
00169 
00170   delete test;
00171 
00172   glWidget_ = new QGLWidget(format,0);
00173   PluginFunctions::shareGLWidget (glWidget_);
00174 
00175   glView_ = new QtGLGraphicsView(stackedWidget_);
00176   glScene_ = new QtGLGraphicsScene (&examiner_widgets_, baseLayout_);
00177 
00178   // is stereo possible, use it?
00179   OpenFlipper::Options::glStereo(glWidget_->format().stereo());
00180 
00181   glView_->setViewport(glWidget_);
00182   glView_->setViewportUpdateMode(QGraphicsView::FullViewportUpdate);
00183   glView_->setScene(glScene_);
00184 
00185   // gl widget as parent to make sure that the CursorPainter will be deleted before
00186   cursorPainter_ = new CursorPainter (glWidget_);
00187   cursorPainter_->setForceNative (OpenFlipperSettings().value("Core/Gui/glViewer/nativeMouse",false).toBool() );
00188   cursorPainter_->setEnabled (stereoActive_);
00189   glScene_->setCursorPainter (cursorPainter_);
00190 
00191   centerWidget_ = new QGraphicsWidget;
00192   glScene_->addItem(centerWidget_);
00193   centerWidget_->setGeometry (glScene_->sceneRect ());
00194 
00195   connect ( glView_, SIGNAL( sceneRectChanged( const QRectF & ) ),
00196             this, SLOT( sceneRectChanged( const QRectF & ) ) );
00197 
00198   stackedWidget_->addWidget(glView_);
00199   stackWidgetList_.push_back( StackWidgetInfo( false, "3D Examiner Widget", glView_ ) );
00200 
00201   // ======================================================================
00202   // Set up the logging window
00203   // ======================================================================
00204 
00205   slidingLogger_ = new QtSlideWindow (tr("Log Viewer"), centerWidget_);
00206   tempLogWidget = new QWidget;
00207 
00208   logWidget_ = new LoggerWidget(splitter_);
00209   logWidget_->setSizePolicy( QSizePolicy ( QSizePolicy::Preferred , QSizePolicy::Preferred ) );
00210   logWidget_->resize( splitter_->width() ,240);
00211 
00212   originalLoggerSize_ = 0;
00213   loggerState_ = OpenFlipper::Options::Normal;
00214 
00215   QList<int> wsizes( splitter_->sizes() );
00216 
00217   if (OpenFlipper::Options::loggerState() == OpenFlipper::Options::InScene) {
00218     slidingLogger_->attachWidget (logWidget_);
00219     splitter_->insertWidget (1, tempLogWidget);
00220     wsizes[0] = 1;
00221     wsizes[1] = 0;
00222     splitter_->setSizes(wsizes);
00223     loggerState_ = OpenFlipper::Options::InScene;
00224     baseLayout_->setContentsMargins (0, 0, 0, 16);
00225   } else if (OpenFlipper::Options::loggerState() == OpenFlipper::Options::Hidden) {
00226     splitter_->insertWidget (1, tempLogWidget);
00227     wsizes[0] = 1;
00228     wsizes[1] = 0;
00229     splitter_->setSizes(wsizes);
00230     loggerState_ = OpenFlipper::Options::Hidden;
00231   } else {
00232     // Set initial values to have a usable state
00233     wsizes[0] = 480;
00234     wsizes[1] = 240;
00235     splitter_->setSizes(wsizes);
00236   }
00237 
00238 
00239   // ======================================================================
00240   // Create examiner
00241   // ======================================================================
00242 
00243   if ( !OpenFlipper::Options::multiView() ) {
00244 
00245     glViewer* examinerWidget = new glViewer(glScene_,
00246                                             glWidget_,
00247                                             PluginFunctions::viewerProperties(0),
00248                                             centerWidget_);
00249 
00250     examiner_widgets_.push_back(examinerWidget);
00251 
00252     examinerWidget->sceneGraph( PluginFunctions::getSceneGraphRootNode() );
00253 
00254     baseLayout_->addItem(examinerWidget, 0);
00255 
00256     cursorPainter_->registerViewer (examinerWidget);
00257 
00258   } else {
00259 
00260 
00261     // Create examiners
00262     for ( unsigned int i = 0 ; i < OpenFlipper::Options::examinerWidgets() ; ++i ) {
00263       glViewer* newWidget = new glViewer(glScene_,
00264                                          glWidget_,
00265                                          PluginFunctions::viewerProperties(i),
00266                                          centerWidget_);
00267 
00268       examiner_widgets_.push_back(newWidget);
00269 
00270       connect (&PluginFunctions::viewerProperties(i), SIGNAL( getPickMode(std::string&) ),
00271                this,                                   SLOT( getPickMode(std::string&) ),Qt::DirectConnection );
00272       connect (&PluginFunctions::viewerProperties(i), SIGNAL( setPickMode(const std::string) ),
00273                this,                                   SLOT( setPickMode(const std::string) ),Qt::DirectConnection );
00274       connect (&PluginFunctions::viewerProperties(i), SIGNAL( getActionMode(Viewer::ActionMode&) ),
00275                this,                                   SLOT( getActionMode(Viewer::ActionMode&) ),Qt::DirectConnection );
00276       connect (&PluginFunctions::viewerProperties(i), SIGNAL( setActionMode(const Viewer::ActionMode) ),
00277                this,                                   SLOT( setActionMode(const Viewer::ActionMode)), Qt::DirectConnection );
00278 
00279     }
00280 
00281     // Initialize all examiners
00282     for ( unsigned int i = 0 ; i < OpenFlipper::Options::examinerWidgets() ; ++i ) {
00283       examiner_widgets_[i]->sceneGraph( PluginFunctions::getSceneGraphRootNode() );
00284       cursorPainter_->registerViewer (examiner_widgets_[i]);
00285     }
00286 
00287     baseLayout_->addItem(examiner_widgets_[0],0);
00288     baseLayout_->addItem(examiner_widgets_[1],1);
00289     baseLayout_->addItem(examiner_widgets_[2],2);
00290     baseLayout_->addItem(examiner_widgets_[3],3);
00291   }
00292 
00293   // Make examiner available to the plugins ( defined in PluginFunctions.hh)
00294   PluginFunctions::setViewers( examiner_widgets_ );
00295 
00296   centerWidget_->setLayout(baseLayout_);
00297 
00298 
00299   // ======================================================================
00300   // Setup dragging for examiner widget
00301   // ======================================================================
00302   for ( uint i = 0 ; i < OpenFlipper::Options::examinerWidgets() ; ++i ) {
00303 
00304     connect( examiner_widgets_[i], SIGNAL(startDragEvent( QMouseEvent*)),
00305              this, SLOT(startDrag(QMouseEvent* )));
00306     connect( examiner_widgets_[i], SIGNAL(dragEnterEvent( QDragEnterEvent*)),
00307             this, SLOT(dragEnterEvent(QDragEnterEvent* )));
00308     connect( examiner_widgets_[i], SIGNAL(dropEvent( QDropEvent*)),
00309             this, SLOT(dropEvent(QDropEvent* )));
00310     connect (examiner_widgets_[i], SIGNAL(signalMakeActive ()),
00311              this, SLOT(slotActivateExaminer()));
00312 
00313     connect (examiner_widgets_[i], SIGNAL(statusMessage(QString, int)),
00314              statusBar_, SLOT(showMessage(const QString&, int)));
00315   }
00316 
00317 
00318   // ======================================================================
00319   // Create main Toolbar
00320   // ======================================================================
00321 
00322   mainToolbar_ = new QToolBar(tr("Main Toolbar"));
00323   mainToolbar_->setWindowTitle(tr("Main Toolbar"));
00324   mainToolbar_->setObjectName(tr("MainToolbar"));
00325   slotAddToolbar(mainToolbar_);
00326 
00327   // ======================================================================
00328   // Get Toolbar from examiner and integrate it into main window
00329   // ======================================================================
00330 
00331 
00332   // Create the toolbar
00333   viewerToolbar_ = new QToolBar( tr("Viewer Toolbar" ), this );
00334   viewerToolbar_->setOrientation(Qt::Vertical);
00335   viewerToolbar_->setAllowedAreas(Qt::AllToolBarAreas);
00336   viewerToolbar_->setIconSize(QSize(20,20));
00337   viewerToolbar_->setObjectName(tr("ViewerToolbar"));
00338 
00339   slotAddToolbar(viewerToolbar_);
00340 
00341   moveButton_ = new QToolButton( viewerToolbar_ );
00342   moveButton_->setIcon( QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"transform-move.png") );
00343   moveButton_->setMinimumSize( 16, 16 );
00344   moveButton_->setMaximumSize( 32, 32 );
00345   moveButton_->setToolTip( tr("Switch to <b>move</b> mode.") );
00346   moveButton_->setWhatsThis(tr(
00347                   "Switch to <b>move</b> mode.<br>"
00348                   "<ul><li><b>Rotate</b> using <b>left</b> mouse button.</li>"
00349                   "<li><b>Translate</b> using <b>middle</b> mouse button.</li>"
00350                   "<li><b>Zoom</b> using <b>left+middle</b> mouse buttons.</li></ul>" ));
00351 
00352   connect( moveButton_,SIGNAL( clicked() ), this, SLOT( setExamineMode() ) );
00353 /*
00354   connect( this, SIGNAL( actionModeChanged( Viewer::ActionMode ) ),
00355             this, SLOT(   slotActionModeChanged(Viewer::ActionMode) ) );*/
00356 
00357   viewerToolbar_->addWidget( moveButton_ )->setText(tr("Move"));
00358   moveButton_->setDown(true);
00359 
00360 
00361   lightButton_ = new QToolButton( viewerToolbar_ );
00362   lightButton_->setIcon( QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"light-mode.png") );
00363   lightButton_->setMinimumSize( 16, 16 );
00364   lightButton_->setMaximumSize( 32, 32 );
00365   lightButton_->setToolTip(tr("Switch to <b>light</b> mode."));
00366   lightButton_->setWhatsThis(tr(
00367                   "Switch to <b>light</b> mode.<br>"
00368                   "Rotate lights using left mouse button."));
00369 
00370   connect( lightButton_,SIGNAL( clicked() ), this, SLOT( setLightMode() ) );
00371   viewerToolbar_->addWidget( lightButton_)->setText(tr("Light"));
00372 
00373 
00374   pickButton_ = new QToolButton( viewerToolbar_ );
00375   pickButton_->setIcon( QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"pick.png") );
00376   pickButton_->setMinimumSize( 16, 16 );
00377   pickButton_->setMaximumSize( 32, 32 );
00378   pickButton_->setToolTip(tr("Switch to <b>picking</b> mode."));
00379   pickButton_->setWhatsThis(tr(
00380                   "Switch to <b>picking</b> mode.<br>"
00381                   "Use picking functions like flipping edges.<br>"
00382                   "To change the mode use the right click<br>"
00383                   "context menu in the viewer."));
00384   connect( pickButton_,SIGNAL( clicked() ), this, SLOT( setPickingMode() ) );
00385   viewerToolbar_->addWidget( pickButton_)->setText(tr("Pick"));
00386 
00387 
00388   questionButton_ = new QToolButton( viewerToolbar_ );
00389   questionButton_->setIcon( QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"help-about.png") );
00390   questionButton_->setMinimumSize( 16, 16 );
00391   questionButton_->setMaximumSize( 32, 32 );
00392   questionButton_->setToolTip(tr("Switch to <b>identification</b> mode."));
00393   questionButton_->setWhatsThis(tr(
00394                   "Switch to <b>identification</b> mode.<br>"
00395                   "Use identification mode to get information "
00396                   "about objects. Click on an object and see "
00397                   "the log output for information about the "
00398                   "object."));
00399   connect( questionButton_,SIGNAL( clicked() ), this, SLOT( setQuestionMode() ) );
00400   viewerToolbar_->addWidget( questionButton_)->setText(tr("Question"));
00401 
00402   viewerLayoutBox_ = new QComboBox( viewerToolbar_ );
00403   viewerLayoutBox_->setMinimumSize( 32, 16 );
00404   viewerLayoutBox_->setMaximumSize( 64, 32 );
00405   viewerLayoutBox_->setToolTip(tr("Switch <b>viewer layout</b>."));
00406   viewerLayoutBox_->setWhatsThis(tr(
00407                   "Switch <b>viewer layout</b>.<br>"
00408                   "Select the desired viewer layout. "
00409                   "Possible layouts are: "
00410                   "<ul> "
00411                                   "<li>Single viewer</li>"
00412                                   "<li>Multiple viewers (grid)</li>"
00413                                   "<li>Multiple viewers (hsplit)</li>"
00414                                   "</ul>"));
00415 
00416   viewerLayoutBox_->addItem(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"singleviewmode.png"), "");
00417   viewerLayoutBox_->addItem(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"multiviewmode1.png"), "");
00418   viewerLayoutBox_->addItem(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"multiviewmode2.png"), "");
00419 
00420   viewerLayoutBox_->setIconSize(QSize(22,22));
00421 
00422   connect( viewerLayoutBox_,SIGNAL( activated(int) ), this, SLOT( setViewerLayout(int) ) );
00423 
00424   viewerToolbar_->addWidget( viewerLayoutBox_ );
00425 
00426   viewerToolbar_->addSeparator();
00427 
00428   if (OpenFlipper::Options::stereo())
00429   {
00430     stereoButton_ = new QToolButton( viewerToolbar_ );
00431     stereoButton_->setIcon(  QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"mono.png")  );
00432     stereoButton_->setMinimumSize( 16, 16 );
00433     stereoButton_->setMaximumSize( 32, 32 );
00434     stereoButton_->setCheckable( true );
00435     stereoButton_->setToolTip(tr( "Toggle stereo viewing"));
00436     // We want a custom context menu
00437     stereoButton_->setContextMenuPolicy(Qt::CustomContextMenu);
00438     stereoButton_->setWhatsThis(tr(
00439                   "Toggle stereo mode<br><br>"
00440                   "Use this button to switch between stereo "
00441                   "and mono view. To use this feature you need "
00442                   "a stereo capable graphics card and a stereo "
00443                   "display/projection system."));
00444     connect( stereoButton_, SIGNAL( clicked() ), this , SLOT( slotToggleStereoMode() ) );
00445     // Custom context menu
00446     connect( stereoButton_, SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(stereoButtonContextMenu(const QPoint &)));
00447     viewerToolbar_->addWidget( stereoButton_ )->setText( tr("Stereo"));
00448   }
00449 
00450 
00451   addToolBar(Qt::TopToolBarArea,viewerToolbar_);
00452 
00453   // Remember logger size
00454   wsizes = splitter_->sizes();
00455   originalLoggerSize_  = wsizes[1];
00456 
00457   // ======================================================================
00458   // Create ToolBox area
00459   // ======================================================================
00460 
00461   toolBoxArea_ = new QWidget (toolSplitter_);
00462 
00463   QGroupBox *gb = new QGroupBox (tr("ViewMode"));
00464 
00465   QHBoxLayout *hLayout = new QHBoxLayout;
00466 
00467   vmChangeButton_ = new QPushButton(tr("Change View Mode"));
00468   QPushButton* vmEditButton   = new QPushButton(tr("Edit View Modes"));
00469 
00470   hLayout->addWidget(vmChangeButton_);
00471   hLayout->addWidget(vmEditButton);
00472   gb->setLayout (hLayout);
00473 
00474   connect(vmChangeButton_, SIGNAL(clicked()), this, SLOT(slotViewChangeDialog()));
00475   connect(vmEditButton, SIGNAL(clicked()), this, SLOT(slotViewModeDialog()));
00476 
00477   toolBoxScroll_ = new QScrollArea ();
00478   toolBox_ = new SideArea ();
00479   toolBoxScroll_->setWidget (toolBox_);
00480   toolBoxScroll_->setWidgetResizable (true);
00481   toolBoxScroll_->setFrameStyle (QFrame::StyledPanel);
00482 
00483   QVBoxLayout *vLayout = new QVBoxLayout;
00484   vLayout->addWidget(gb);
00485   vLayout->addWidget(toolBoxScroll_);
00486 
00487   toolBoxArea_->setLayout (vLayout);
00488 
00489   wsizes = toolSplitter_->sizes();
00490 
00491   wsizes[0] = 480;
00492   wsizes[1] = 240;
00493   toolSplitter_->setSizes(wsizes);
00494 
00495   // ======================================================================
00496   // Create pick ToolBar
00497   // ======================================================================
00498 
00499   pickToolbar_ = new QtPickToolbar (this, centerWidget_);
00500 
00501   // ======================================================================
00502   // Context menu setup
00503   // ======================================================================
00504 
00505   for ( unsigned int i = 0 ; i < OpenFlipper::Options::examinerWidgets() ; ++i ) {
00506     connect( examiner_widgets_[i] , SIGNAL(signalCustomContextMenuRequested( const QPoint&) ) ,
00507              this                 , SLOT( slotCustomContextMenu( const QPoint&) ) );
00508   }
00509 
00510   contextMenu_ = new QMenu(this);
00511   contextSelectionMenu_ = new QMenu(tr("Selection"),0);
00512 
00513   setupMenuBar();
00514 
00515   statusBar_->showMessage(tr("Ready"), 5000);
00516 
00517   registerCoreKeys();
00518 
00519   setExamineMode();
00520 
00521   setWindowIcon( OpenFlipper::Options::OpenFlipperIcon() );
00522 
00523   // Create stereo settings widget
00524   stereoSettingsWidget_ = new StereoSettingsWidget(this);
00525   // Make it look like a dialog
00526   stereoSettingsWidget_->setWindowFlags(Qt::Popup);
00527   // Connect combo boxes and sliders to local slots
00528   connect(stereoSettingsWidget_->stereoOpengl, SIGNAL(clicked()),
00529           this, SLOT(slotApplyStereoSettings()));
00530   connect(stereoSettingsWidget_->stereoAnaglyph, SIGNAL(clicked()),
00531           this, SLOT(slotApplyStereoSettings()));
00532   connect(stereoSettingsWidget_->stereoCustomAnaglyph, SIGNAL(clicked()),
00533           this, SLOT(slotApplyStereoSettings()));
00534   connect(stereoSettingsWidget_->stereoPhilips, SIGNAL(clicked()),
00535           this, SLOT(slotApplyStereoSettings()));
00536 
00537   connect(stereoSettingsWidget_->focalDistance, SIGNAL(sliderReleased()),
00538           this, SLOT(slotApplyStereoSettings()));
00539   connect(stereoSettingsWidget_->eyeDistance, SIGNAL(editingFinished()),
00540           this, SLOT(slotApplyStereoSettings()));
00541 
00542   connect(stereoSettingsWidget_->headerContentType, SIGNAL(currentIndexChanged(int)),
00543           this, SLOT(slotApplyStereoSettings(int)));
00544   connect(stereoSettingsWidget_->headerFactor, SIGNAL(sliderReleased()),
00545           this, SLOT(slotApplyStereoSettings()));
00546   connect(stereoSettingsWidget_->headerOffsetCC, SIGNAL(sliderReleased()),
00547           this, SLOT(slotApplyStereoSettings()));
00548   connect(stereoSettingsWidget_->headerSelect, SIGNAL(currentIndexChanged(int)),
00549           this, SLOT(slotApplyStereoSettings(int)));
00550 
00551   // Close button
00552   connect(stereoSettingsWidget_->closeButton, SIGNAL(clicked()),
00553           stereoSettingsWidget_, SLOT(hide()));
00554 }
00555 
00556 
00557 //-----------------------------------------------------------------------------
00558 
00559 
00560 CoreWidget::~CoreWidget() {
00561 
00562 }
00563 
00564 //-----------------------------------------------------------------------------
00565 
00568 void
00569 CoreWidget::toggleFullscreen() {
00570 
00571   switch (fullscreenState_){
00572 
00573     case 0:
00574       //switch to fullscreen
00575       setWindowState( windowState() | Qt::WindowFullScreen);
00576       break;
00577 
00578     case 1:
00579 
00580       //fullscreen without toolbars
00581       if ( ! (windowState() & Qt::WindowFullScreen) )
00582         setWindowState( windowState() | Qt::WindowFullScreen);
00583 
00584       //hide plugin toolbars
00585       for (uint p=0; p < plugins_.size(); p++)
00586         for ( uint j = 0 ; j < plugins_[p].toolbars.size(); ++j )
00587           plugins_[p].toolbars[j].second->hide();
00588 
00589       //hide main toolbar
00590       mainToolbar_->hide();
00591 
00592       //hide viewer toolbar
00593       viewerToolbar_->hide();
00594 
00595       //hide the menubar
00596       menuBar()->hide();
00597 
00598       //hide the statusbar
00599       statusBar()->hide();
00600 
00601       //remove viewer frame
00602       glView_->setFrameStyle(QFrame::NoFrame);
00603 
00604       break;
00605 
00606     default:
00607       //disable fullscreen
00608       if ( windowState() & Qt::WindowFullScreen )
00609         setWindowState( windowState() ^  Qt::WindowFullScreen);
00610 
00611       //show toolbars
00612       setViewMode( OpenFlipper::Options::defaultToolboxMode() );
00613 
00614       //show the menubar
00615       menuBar()->show();
00616 
00617       //show the statusbar
00618       statusBar()->show();
00619 
00620       //add viewer frame
00621       glView_->setFrameStyle(QFrame::StyledPanel | QFrame::Sunken);
00622   }
00623 
00624   fullscreenState_ = (fullscreenState_ + 1) % 3;
00625 
00626   OpenFlipper::Options::fullScreen( bool( windowState() & Qt::WindowFullScreen) );
00627 
00628   show();
00629 }
00630 
00631 //-----------------------------------------------------------------------------
00632 
00635 void
00636 CoreWidget::setFullscreen(bool _state ) {
00637   if ( _state )
00638     setWindowState( windowState() | Qt::WindowFullScreen);
00639   else {
00640     if ( windowState() & Qt::WindowFullScreen )
00641       setWindowState( windowState() ^  Qt::WindowFullScreen);
00642   }
00643 
00644   fullscreenState_ = (uint) _state;
00645 
00646   OpenFlipper::Options::fullScreen( bool( windowState() & Qt::WindowFullScreen) );
00647 
00648   show();
00649 }
00650 
00651 //-----------------------------------------------------------------------------
00652 
00655 void
00656 CoreWidget::toggleLogger() {
00657 
00658   switch (OpenFlipper::Options::loggerState ())
00659   {
00660     case OpenFlipper::Options::InScene:
00661       OpenFlipper::Options::loggerState(OpenFlipper::Options::Normal);
00662       break;
00663     case OpenFlipper::Options::Normal:
00664       OpenFlipper::Options::loggerState(OpenFlipper::Options::Hidden);
00665       break;
00666     case OpenFlipper::Options::Hidden:
00667       OpenFlipper::Options::loggerState(OpenFlipper::Options::InScene);
00668       break;
00669   }
00670 
00671   // Hide/Show Logger
00672   showLogger( OpenFlipper::Options::loggerState() );
00673 }
00674 
00677 void
00678 CoreWidget::showLogger(OpenFlipper::Options::LoggerState _state) {
00679   //Hide Logger
00680   if (_state == loggerState_)
00681     return;
00682 
00683   qreal left, top, right, bottom;
00684   baseLayout_->getContentsMargins (&left, &top, &right, &bottom);
00685 
00686   switch (_state)
00687   {
00688     case OpenFlipper::Options::InScene:
00689       {
00690         QList<int> wsizes( splitter_->sizes() );
00691 
00692         // Remember old size
00693         if (loggerState_ == OpenFlipper::Options::Normal)
00694           originalLoggerSize_  = wsizes[1];
00695 
00696         if ( originalLoggerSize_ == 0)
00697           originalLoggerSize_ = 240;
00698 
00699         splitter_->insertWidget (1, tempLogWidget);
00700         wsizes[0] = wsizes[0]+wsizes[1];
00701         wsizes[1] = 0;
00702         splitter_->setSizes(wsizes);
00703         logWidget_->resize (logWidget_->width (), originalLoggerSize_);
00704         slidingLogger_->attachWidget (logWidget_);
00705         baseLayout_->setContentsMargins (left, top, right, 16);
00706       }
00707       break;
00708     case OpenFlipper::Options::Normal:
00709       {
00710         if ( originalLoggerSize_ == 0)
00711           originalLoggerSize_ = 240;
00712 
00713         QList<int> wsizes( splitter_->sizes() );
00714 
00715         if (loggerState_ == OpenFlipper::Options::InScene)
00716           originalLoggerSize_ = logWidget_->height ();
00717 
00718         slidingLogger_->detachWidget ();
00719         splitter_->insertWidget (1, logWidget_);
00720         logWidget_->show ();
00721 
00722         wsizes[0] = wsizes[0]+wsizes[1] - originalLoggerSize_;
00723         wsizes[1] = originalLoggerSize_;
00724         splitter_->setSizes(wsizes);
00725         baseLayout_->setContentsMargins (left, top, right, 0);
00726       }
00727       break;
00728     case OpenFlipper::Options::Hidden:
00729       {
00730         QList<int> wsizes( splitter_->sizes() );
00731 
00732         // Remember old size
00733         if (loggerState_ == OpenFlipper::Options::Normal)
00734           originalLoggerSize_  = wsizes[1];
00735 
00736         if (loggerState_ == OpenFlipper::Options::InScene)
00737         {
00738           slidingLogger_->detachWidget ();
00739           originalLoggerSize_ = logWidget_->height ();
00740         }
00741 
00742         splitter_->insertWidget (1, tempLogWidget);
00743         wsizes[0] = wsizes[0]+wsizes[1];
00744         wsizes[1] = 0;
00745         splitter_->setSizes(wsizes);
00746         baseLayout_->setContentsMargins (left, top, right, 0);
00747       }
00748       break;
00749   }
00750   loggerState_ = _state;
00751 
00752 /*
00753   if ( !_state ) {
00754     QList<int> wsizes( splitter_->sizes() );
00755 
00756     // Remember old size
00757     originalLoggerSize_  = wsizes[1];
00758 
00759     int height = logWidget_->height ();
00760 
00761     splitter_->insertWidget (1, tempLogWidget);
00762     wsizes[0] = wsizes[0]+wsizes[1];
00763     wsizes[1] = 0;
00764     splitter_->setSizes(wsizes);
00765     logWidget_->resize (logWidget_->width (), height);
00766     slidingLogger_->attachWidget (logWidget_);
00767 
00768   } else if (splitter_->widget (1) == logWidget_) {
00769 
00770     if ( originalLoggerSize_ == 0)
00771         originalLoggerSize_ = 240;
00772 
00773     QList<int> wsizes( splitter_->sizes() );
00774 
00775     if (wsizes[0] == 0)
00776       wsizes[0] = height();
00777 
00778     wsizes[0] = wsizes[0]+wsizes[1] - originalLoggerSize_;
00779     wsizes[1] = originalLoggerSize_;
00780     splitter_->setSizes(wsizes);
00781   } else {
00782 
00783     QList<int> wsizes( splitter_->sizes() );
00784 
00785     int height = logWidget_->height ();
00786 
00787     slidingLogger_->detachWidget ();
00788     splitter_->insertWidget (1, logWidget_);
00789 
00790     wsizes[0] = wsizes[0]+wsizes[1] - height;
00791     wsizes[1] = height;
00792     splitter_->setSizes(wsizes);
00793   }
00794   */
00795 }
00796 
00797 //-----------------------------------------------------------------------------
00798 
00801 void
00802 CoreWidget::toggleToolbox() {
00803 
00804   //toggle
00805   showToolbox( OpenFlipper::Options::hideToolbox() );
00806 }
00807 
00808 //-----------------------------------------------------------------------------
00809 
00812 void
00813 CoreWidget::showToolbox( bool _state ) {
00814 
00815   //toggle
00816   OpenFlipper::Options::hideToolbox( !_state );
00817 
00818   if ( OpenFlipper::Options::hideToolbox() ){
00819 
00820     //hide ViewMode Selection Widget
00821     toolBoxArea_->setVisible(false);
00822 
00823   }else{
00824     //reset last ViewMode
00825     if (OpenFlipper::Options::defaultToolboxMode().trimmed() == "")
00826       setViewMode("All");
00827     else
00828       setViewMode( OpenFlipper::Options::defaultToolboxMode() );
00829     toolBoxArea_->setVisible(true);
00830   }
00831 }
00832 
00833 //=============================================================================
00834 
00835 void
00836 CoreWidget::addRecent(QString _filename, DataType _type)
00837 {
00838   //dont add objects to recentMenu while loadind Settings
00839   if ( OpenFlipper::Options::loadingSettings() ) return;
00840 
00841   OpenFlipper::Options::addRecentFile(_filename, _type);
00842 
00843   updateRecent();
00844 
00845 }
00846 
00847 //=============================================================================
00848 
00849 void
00850 CoreWidget::updateRecent()
00851 {
00852   if ( recentFilesMenu_ == NULL)
00853     return;
00854 
00855   recentFilesMenu_->clear();
00856 
00857   QStringList recentFiles = OpenFlipperSettings().value("Core/File/RecentFiles").toStringList();
00858   QStringList recentTypes = OpenFlipperSettings().value("Core/File/RecentTypes").toStringList();
00859 
00860   for (int i = 0 ; i < recentFiles.size() ; ++i ) {
00861 
00862     QFileInfo fi(recentFiles[i]);
00863 
00864     if (fi.suffix() == "ini")
00865       recentFilesMenu_->addAction(QIcon(OpenFlipper::Options::iconDirStr() + OpenFlipper::Options::dirSeparator()+"Settings-Icon.png"), recentFiles[i]);
00866     else
00867       recentFilesMenu_->addAction(typeIcon( typeId(recentTypes[i]) ), recentFiles[i]);
00868 
00869   }
00870 
00871 }
00872 
00873 void
00874 CoreWidget::closeEvent ( QCloseEvent * /* event */ ) {
00875   emit exit();
00876 }
00877 
00878 void CoreWidget::showOptionsWidget() {
00879 
00880   if ( OpenFlipper::Options::nogui() )
00881     return;
00882 
00883   if ( optionsWidget_ == 0 ) {
00884     optionsWidget_ = new OptionsWidget(plugins_, coreKeys_, invKeys_, 0);
00885     connect(optionsWidget_,SIGNAL(applyOptions()),this,SIGNAL(applyOptions()));
00886     connect(optionsWidget_,SIGNAL(saveOptions()),this,SIGNAL(saveOptions()));
00887     connect(optionsWidget_,SIGNAL(addKeyMapping(int,Qt::KeyboardModifiers,QObject*,int)),
00888             this,          SLOT(slotAddKeyMapping(int,Qt::KeyboardModifiers,QObject*,int)));
00889 
00890     optionsWidget_->setWindowIcon( OpenFlipper::Options::OpenFlipperIcon() );
00891   }
00892 
00893   //show the optionsWidget centered
00894   QPoint center;
00895   center.setX( x() + width() / 2 );
00896   center.setY( y() + height() / 2 );
00897 
00898   optionsWidget_->setGeometry(center.x() - optionsWidget_->width() / 2,
00899                               center.y() - optionsWidget_->height()/ 2, optionsWidget_->width(), optionsWidget_->height());
00900 
00901   optionsWidget_->show();
00902 
00903 }
00904 
00905 void CoreWidget::nextViewerLayout() {
00906 
00907         if (OpenFlipper::Options::multiView()) {
00908 
00909                 switch (baseLayout_->mode()) {
00910                 case QtMultiViewLayout::SingleView:
00911                         baseLayout_->setPrimary (PluginFunctions::activeExaminer ());
00912                         baseLayout_->setMode(QtMultiViewLayout::Grid);
00913 
00914                         // Update combo box in the toolbar
00915                         viewerLayoutBox_->setCurrentIndex(1);
00916                         break;
00917                 case QtMultiViewLayout::Grid:
00918                         baseLayout_->setPrimary (PluginFunctions::activeExaminer ());
00919                         baseLayout_->setMode(QtMultiViewLayout::HSplit);
00920 
00921                         // Update combo box in the toolbar
00922                         viewerLayoutBox_->setCurrentIndex(2);
00923                         break;
00924                 case QtMultiViewLayout::HSplit:
00925                         baseLayout_->setPrimary (PluginFunctions::activeExaminer ());
00926                         baseLayout_->setMode(QtMultiViewLayout::SingleView);
00927 
00928                         // Update combo box in the toolbar
00929                         viewerLayoutBox_->setCurrentIndex(0);
00930                         break;
00931                 }
00932         }
00933 }
00934 
00935 
00936 void
00937 CoreWidget::setViewerLayout(int _idx) {
00938 
00939         if (OpenFlipper::Options::multiView()) {
00940 
00941                 switch (_idx) {
00942                 case 0:
00943                         baseLayout_->setPrimary (PluginFunctions::activeExaminer ());
00944                         baseLayout_->setMode(QtMultiViewLayout::SingleView);
00945                         break;
00946                 case 1:
00947                         baseLayout_->setPrimary (PluginFunctions::activeExaminer ());
00948                         baseLayout_->setMode(QtMultiViewLayout::Grid);
00949                         break;
00950                 case 2:
00951                         baseLayout_->setPrimary (PluginFunctions::activeExaminer ());
00952                         baseLayout_->setMode(QtMultiViewLayout::HSplit);
00953                         break;
00954                 }
00955 
00956     viewerLayoutBox_->setCurrentIndex(_idx);
00957         }
00958 }
00959 
00960 void
00961 CoreWidget::slotShowSceneGraphDialog()
00962 {
00963   if ( PluginFunctions::getSceneGraphRootNode() )
00964   {
00965     if (!sceneGraphDialog_)
00966     {
00967       sceneGraphDialog_ = new ACG::QtWidgets::QtSceneGraphDialog( this, PluginFunctions::getSceneGraphRootNode() );
00968 
00969       for ( unsigned int i = 0 ; i < OpenFlipper::Options::examinerWidgets() ; ++i ) {
00970         connect(examiner_widgets_[i], SIGNAL(signalSceneGraphChanged(ACG::SceneGraph::BaseNode*)),
00971                 sceneGraphDialog_,    SLOT(update(ACG::SceneGraph::BaseNode*)));
00972 
00973         connect(sceneGraphDialog_, SIGNAL(signalNodeChanged(ACG::SceneGraph::BaseNode*)),
00974                 examiner_widgets_[i], SLOT(updateGL()));
00975       }
00976 
00977     }
00978 
00979     sceneGraphDialog_->show();
00980   }
00981 }
00982 
00983 //-----------------------------------------------------------------------------
00984 
00985 void
00986 CoreWidget::sceneRectChanged(const QRectF &rect)
00987 {
00988   centerWidget_->setGeometry (rect);
00989   slidingLogger_->updateGeometry ();
00990   pickToolbar_->updateGeometry ();
00991 }
00992 
00993 //-----------------------------------------------------------------------------
00994 
00995 void
00996 CoreWidget::startVideoCaptureDialog(){
00997 
00998   VideoCaptureDialog* dialog = new VideoCaptureDialog();
00999   dialog->setModal(false);
01000 
01001   connect(dialog, SIGNAL(startVideoCapture(QString,int,bool)), this, SIGNAL(startVideoCapture(QString,int,bool)) );
01002   connect(dialog, SIGNAL(resizeViewers(int,int)), this, SIGNAL(resizeViewers(int,int)) );
01003   connect(dialog, SIGNAL(resizeApplication(int,int)), this, SIGNAL(resizeApplication(int,int)) );
01004 
01005   dialog->show();
01006 }
01007 
01008 //-----------------------------------------------------------------------------
01009 
01010 void CoreWidget::slotActivateExaminer()
01011 {
01012   glViewer* examiner = dynamic_cast<glViewer*>(QObject::sender());
01013 
01014   if (!examiner)
01015     return;
01016 
01017   for ( uint i = 0 ; i < OpenFlipper::Options::examinerWidgets() ; ++i ) {
01018 
01019     if (examiner == examiner_widgets_[i])
01020     {
01021       PluginFunctions::setActiveExaminer (i);
01022       break;
01023     }
01024   }
01025 }
01026 
01027 //-----------------------------------------------------------------------------
01028 
01030 void CoreWidget::setForceNativeCursor ( bool _state )
01031 {
01032   cursorPainter_->setForceNative (_state);
01033 }
01034 
01035 //=============================================================================
01036 

acg pic Project OpenFlipper, ©  Computer Graphics Group, RWTH Aachen. Documentation generated using doxygen .