CoreWidget.cc 37.8 KB
Newer Older
1
/*===========================================================================*\
Jan Möbius's avatar
Jan Möbius committed
2 3
*                                                                            *
*                              OpenFlipper                                   *
Jan Möbius's avatar
Jan Möbius committed
4
*      Copyright (C) 2001-2011 by Computer Graphics Group, RWTH Aachen       *
Jan Möbius's avatar
Jan Möbius committed
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
*                           www.openflipper.org                              *
*                                                                            *
*--------------------------------------------------------------------------- *
*  This file is part of OpenFlipper.                                         *
*                                                                            *
*  OpenFlipper is free software: you can redistribute it and/or modify       *
*  it under the terms of the GNU Lesser General Public License as            *
*  published by the Free Software Foundation, either version 3 of            *
*  the License, or (at your option) any later version with the               *
*  following exceptions:                                                     *
*                                                                            *
*  If other files instantiate templates or use macros                        *
*  or inline functions from this file, or you compile this file and          *
*  link it with other files to produce an executable, this file does         *
*  not by itself cause the resulting executable to be covered by the         *
*  GNU Lesser General Public License. This exception does not however        *
*  invalidate any other reasons why the executable file might be             *
*  covered by the GNU Lesser General Public License.                         *
*                                                                            *
*  OpenFlipper is distributed in the hope that it will be useful,            *
*  but WITHOUT ANY WARRANTY; without even the implied warranty of            *
*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             *
*  GNU Lesser General Public License for more details.                       *
*                                                                            *
*  You should have received a copy of the GNU LesserGeneral Public           *
*  License along with OpenFlipper. If not,                                   *
*  see <http://www.gnu.org/licenses/>.                                       *
*                                                                            *
33
\*===========================================================================*/
Jan Möbius's avatar
 
Jan Möbius committed
34

35
/*===========================================================================*\
Jan Möbius's avatar
Jan Möbius committed
36 37 38 39 40
*                                                                            *
*   $Revision$                                                       *
*   $LastChangedBy$                                                *
*   $Date$                     *
*                                                                            *
41
\*===========================================================================*/
Jan Möbius's avatar
 
Jan Möbius committed
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60



//=============================================================================
//
//  CLASS MViewWidget - IMPLEMENTATION
//
//=============================================================================


//== INCLUDES =================================================================

// -------------------- mview
#include "CoreWidget.hh"

// -------------------- OpenFlipper Includes
#include <OpenFlipper/common/GlobalOptions.hh>
#include <OpenFlipper/common/RecentFiles.hh>
#include <OpenFlipper/BasePlugin/PluginFunctions.hh>
Jan Möbius's avatar
 
Jan Möbius committed
61
#include <OpenFlipper/BasePlugin/PluginFunctionsCore.hh>
Dirk Wilden's avatar
Dirk Wilden committed
62 63
#include <OpenFlipper/BasePlugin/KeyInterface.hh>
#include <OpenFlipper/BasePlugin/LoggingInterface.hh>
Jan Möbius's avatar
 
Jan Möbius committed
64

Dirk Wilden's avatar
Dirk Wilden committed
65 66
#include <OpenFlipper/widgets/videoCaptureDialog/VideoCaptureDialog.hh>

Jan Möbius's avatar
Dennis:  
Jan Möbius committed
67 68
#include <OpenFlipper/widgets/glWidget/CursorPainter.hh>

Jan Möbius's avatar
Jan Möbius committed
69 70
#include <ACG/Scenegraph/SceneGraphAnalysis.hh>

Matthias Möller's avatar
doc  
Matthias Möller committed
71 72 73 74
// -------------------- Qt event Includes
#include <QEvent>
#include <QWhatsThisClickedEvent>

Jan Möbius's avatar
 
Jan Möbius committed
75 76 77
#define WIDGET_HEIGHT 800
#define WIDGET_WIDTH  800

Jan Möbius's avatar
Jan Möbius committed
78
//== IMPLEMENTATION ==========================================================
Jan Möbius's avatar
 
Jan Möbius committed
79

80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
PickMode::PickMode(const std::string& _n, const bool _t, const bool _v, QCursor _c, QToolBar *_tb ) :
      name_(_n),
      tracking_(_t),
      visible_(_v),
      cursor_(_c),
      toolbar_(_tb)
{

}

void PickMode::visible(const bool _visible) {
  visible_ = _visible;
}

bool PickMode::visible() const  {
  return visible_;
}

std::string PickMode::name() const {
  return name_;
}

void PickMode::tracking(bool _tracking) {
  tracking_ = _tracking;
}

bool PickMode::tracking() const {
  return tracking_;
}

110 111 112 113
void PickMode::cursor(const QCursor _cursor) {
  cursor_ = _cursor;
}

114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
QCursor PickMode::cursor() const{
  return cursor_;
}

void PickMode::toolbar(QToolBar* _toolbar) {
  toolbar_ = _toolbar;
}

QToolBar * PickMode::toolbar() const {
  return toolbar_;
}









134
/** \brief Constructor for the Core Widget
Jan Möbius's avatar
Jan Möbius committed
135
 *
Jan Möbius's avatar
 
Jan Möbius committed
136 137
*/
CoreWidget::
Dirk Wilden's avatar
Dirk Wilden committed
138
CoreWidget( QVector<ViewMode*>& _viewModes,
Dirk Wilden's avatar
Dirk Wilden committed
139 140
            std::vector<PluginInfo>& _plugins,
            QList< SlotInfo >& _coreSlots ) :
Jan Möbius's avatar
 
Jan Möbius committed
141
  QMainWindow(),
Dirk Wilden's avatar
Dirk Wilden committed
142
  coreSlots_(_coreSlots),
Dirk Wilden's avatar
Dirk Wilden committed
143
  shiftPressed_(false),
Dirk Wilden's avatar
Dirk Wilden committed
144
  fullscreenState_(0),
Jan Möbius's avatar
 
Jan Möbius committed
145 146
  viewModes_(_viewModes),
  viewModeButton_(0),
147
  viewModeMenu_(0),
Jan Möbius's avatar
 
Jan Möbius committed
148
  splitter_(0),
149
  logWidget_(0),
Jan Möbius's avatar
 
Jan Möbius committed
150
  recentFilesMenu_(0),
151
  helpMenu_(0),
152 153
  windowMenu_(0),
  AC_ShowViewModeControls_(0),
154
  pickToolBarExternal_(0),
Jan Möbius's avatar
Dennis:  
Jan Möbius committed
155
  cursorPainter_(0),
156
  sceneGraphDialog_(0),
157 158 159
  fileMenu_(0),
  viewMenu_(0),
  toolsMenu_(0),
Jan Möbius's avatar
 
Jan Möbius committed
160
  fileMenuEnd_(0),
161 162 163
  stereoButton_(0),
  moveButton_(0),
  pickButton_(0),
Dirk Wilden's avatar
Dirk Wilden committed
164
  questionButton_(0),
165
  globalDrawMenu_(0),
166 167
  rendererMenu_(0),
  postprocessorMenu_(0),
168
  drawGroup_(0),
169 170
  rendererGroup_(0),
  postProcessorGroup_(0),
171
  viewGroup_(0),
172
  perspectiveProjectionAction_(0),
173 174
  activeDrawModes_(0),
  availableGlobalDrawModes_(0),
Jan Möbius's avatar
 
Jan Möbius committed
175
  contextMenu_(0),
Jan Möbius's avatar
Jan Möbius committed
176
  contextSelectionMenu_(0),
177 178
  drawGroupViewer_(0),
  viewerDrawMenu_(0),
179
  coordSysMenu_(0),
180
  snapshotName_(""),
Dirk Wilden's avatar
Dirk Wilden committed
181
  snapshotCounter_(0),
Jan Möbius's avatar
 
Jan Möbius committed
182
  stackMenu_(0),
183
  helpWidget_(0),
184
  stereoSettingsWidget_(0),
Jan Möbius's avatar
Jan Möbius committed
185
  aboutWidget_(0),
186
  optionsWidget_(0),
187
  plugins_(_plugins),
188 189 190 191 192 193
  stereoActive_(false),
  actionMode_(Viewer::PickingMode),
  lastActionMode_(Viewer::ExamineMode),
  pickMenu_(0),
  pick_mode_name_(""),
  pick_mode_idx_(-1)
Jan Möbius's avatar
 
Jan Möbius committed
194
{
Matthias Möller's avatar
doc  
Matthias Möller committed
195

Jan Möbius's avatar
 
Jan Möbius committed
196
  setupStatusBar();
Jan Möbius's avatar
Jan Möbius committed
197

Dirk Wilden's avatar
Dirk Wilden committed
198 199
  defaultIconSize_ = iconSize();

Jan Möbius's avatar
Dennis:  
Jan Möbius committed
200 201 202 203 204
  toolSplitter_ = new QSplitter(Qt::Horizontal,this);

  setCentralWidget(toolSplitter_);

  splitter_ = new QSplitter(Qt::Vertical,toolSplitter_);
Jan Möbius's avatar
 
Jan Möbius committed
205
  stackedWidget_ = new QStackedWidget(splitter_);
Jan Möbius's avatar
Jan Möbius committed
206

207 208
  QGLFormat format = QGLFormat::defaultFormat();

209 210 211
  #ifdef ARCH_DARWIN
  format.setStereo(false);
  #else
Jan Möbius's avatar
 
Jan Möbius committed
212
  format.setStereo( OpenFlipper::Options::stereo() );
213
  #endif
Jan Möbius's avatar
 
Jan Möbius committed
214
  format.setAlpha(true);
215
  format.setStencil(true);
216 217
  format.setSampleBuffers(true);
  QGLFormat::setDefaultFormat(format);
Jan Möbius's avatar
 
Jan Möbius committed
218 219

  // Construct GL context & widget
220 221 222
  baseLayout_ = new QtMultiViewLayout;
  baseLayout_->setContentsMargins(0,0,0,0);

223 224 225
  // ===============================================================================
  // Test context capabilities ...
  // If we get stereo buffers, we use them .. which might disable multisampling
226
  // If we don't have stereo, we disable it to not interfere with multisampling
227 228 229 230 231 232 233 234 235 236 237 238 239
  // ===============================================================================
  QGLWidget* test = new QGLWidget(format);
  if ( ! test->format().stereo() ) {
    //     std::cerr << "No stereo ... disabling stereo for real context!" << std::endl;
    format.setStereo(false);
    QGLFormat::setDefaultFormat(format);
  }/* else {
    std::cerr << "Stereo found ok" << std::endl;
  }*/

  delete test;

  glWidget_ = new QGLWidget(format,0);
240
  PluginFunctions::shareGLWidget (glWidget_);
241

Jan Möbius's avatar
 
Jan Möbius committed
242
  glView_ = new QtGLGraphicsView(stackedWidget_);
243
  glScene_ = new QtGLGraphicsScene (&examiner_widgets_, baseLayout_);
Jan Möbius's avatar
 
Jan Möbius committed
244

Jan Möbius's avatar
Jan Möbius committed
245
  // is stereo possible, use it?
Jan Möbius's avatar
Dennis:  
Jan Möbius committed
246
  OpenFlipper::Options::glStereo(glWidget_->format().stereo());
Jan Möbius's avatar
Jan Möbius committed
247

Jan Möbius's avatar
 
Jan Möbius committed
248 249 250
  glView_->setViewport(glWidget_);
  glView_->setViewportUpdateMode(QGraphicsView::FullViewportUpdate);
  glView_->setScene(glScene_);
251
  glView_->setFrameStyle(QFrame::NoFrame);
Jan Möbius's avatar
 
Jan Möbius committed
252

Jan Möbius's avatar
Dennis:  
Jan Möbius committed
253 254
  // gl widget as parent to make sure that the CursorPainter will be deleted before
  cursorPainter_ = new CursorPainter (glWidget_);
Jan Möbius's avatar
Jan Möbius committed
255
  cursorPainter_->setForceNative (OpenFlipperSettings().value("Core/Gui/glViewer/nativeMouse",false).toBool() );
256
  cursorPainter_->setEnabled (stereoActive_);
Jan Möbius's avatar
Dennis:  
Jan Möbius committed
257
  glScene_->setCursorPainter (cursorPainter_);
258

Jan Möbius's avatar
 
Jan Möbius committed
259 260 261 262 263 264 265 266 267 268
  centerWidget_ = new QGraphicsWidget;
  glScene_->addItem(centerWidget_);
  centerWidget_->setGeometry (glScene_->sceneRect ());

  connect ( glView_, SIGNAL( sceneRectChanged( const QRectF & ) ),
            this, SLOT( sceneRectChanged( const QRectF & ) ) );

  stackedWidget_->addWidget(glView_);
  stackWidgetList_.push_back( StackWidgetInfo( false, "3D Examiner Widget", glView_ ) );

Jan Möbius's avatar
 
Jan Möbius committed
269 270 271
  // ======================================================================
  // Set up the logging window
  // ======================================================================
272

273
  slidingLogger_ = new QtSlideWindow (tr("Log Viewer"), centerWidget_);
274

275 276
  logWidget_ = new LoggerWidget(splitter_);
  logWidget_->setSizePolicy( QSizePolicy ( QSizePolicy::Preferred , QSizePolicy::Preferred ) );
277
  logWidget_->resize( splitter_->width() ,240);
Jan Möbius's avatar
Jan Möbius committed
278

279
  originalLoggerSize_ = 0;
Jan Möbius's avatar
Jan Möbius committed
280
  loggerState_ = OpenFlipper::Options::Normal;
281

282 283 284 285 286
  QList<int> wsizes(splitter_->sizes());
  // Set initial values to have a usable state
  wsizes[0] = 480;
  wsizes[1] = 240;
  splitter_->setSizes(wsizes);
287

Jan Möbius's avatar
Jan Möbius committed
288
  if (OpenFlipper::Options::loggerState() == OpenFlipper::Options::InScene) {
289

290
    slidingLogger_->attachWidget (logWidget_);
291
    showLoggerInSplitView(false);
Jan Möbius's avatar
Jan Möbius committed
292
    loggerState_ = OpenFlipper::Options::InScene;
293

Jan Möbius's avatar
Jan Möbius committed
294
  } else if (OpenFlipper::Options::loggerState() == OpenFlipper::Options::Hidden) {
295

296
    showLoggerInSplitView(false);
Jan Möbius's avatar
Jan Möbius committed
297 298
    loggerState_ = OpenFlipper::Options::Hidden;
  } else {
299 300

    showLoggerInSplitView(true);
Jan Möbius's avatar
 
Jan Möbius committed
301
  }
Jan Möbius's avatar
Jan Möbius committed
302

303

Jan Möbius's avatar
 
Jan Möbius committed
304 305 306
  // ======================================================================
  // Create examiner
  // ======================================================================
Jan Möbius's avatar
Jan Möbius committed
307

Jan Möbius's avatar
Jan Möbius committed
308 309 310 311 312
  // First we analyze the scenegraph
  unsigned int maxPases = 1;
  ACG::Vec3d bbmin,bbmax;
  ACG::SceneGraph::analyzeSceneGraph(PluginFunctions::getSceneGraphRootNode(),maxPases,bbmin,bbmax);

Jan Möbius's avatar
Jan Möbius committed
313
  if ( !OpenFlipperSettings().value("Core/Gui/glViewer/useMultipleViewers",true).toBool() ) {
Jan Möbius's avatar
Jan Möbius committed
314

Jan Möbius's avatar
 
Jan Möbius committed
315
    glViewer* examinerWidget = new glViewer(glScene_,
Jan Möbius's avatar
Jan Möbius committed
316 317 318
					                                  glWidget_,
					                                  PluginFunctions::viewerProperties(0),
					                                  centerWidget_);
Jan Möbius's avatar
Jan Möbius committed
319

Jan Möbius's avatar
Jan Möbius committed
320 321
    examiner_widgets_.push_back(examinerWidget);

Jan Möbius's avatar
Jan Möbius committed
322
    examinerWidget->sceneGraph( PluginFunctions::getSceneGraphRootNode(), maxPases,bbmin,bbmax );
Jan Möbius's avatar
Jan Möbius committed
323

Jan Möbius's avatar
Jan Möbius committed
324
    baseLayout_->addItem(examinerWidget, 0);
Jan Möbius's avatar
Jan Möbius committed
325

Jan Möbius's avatar
Dennis:  
Jan Möbius committed
326 327
    cursorPainter_->registerViewer (examinerWidget);

Jan Möbius's avatar
Jan Möbius committed
328 329 330
  } else {


Jan Möbius's avatar
 
Jan Möbius committed
331 332 333
    // Create examiners
    for ( unsigned int i = 0 ; i < OpenFlipper::Options::examinerWidgets() ; ++i ) {
      glViewer* newWidget = new glViewer(glScene_,
Jan Möbius's avatar
Jan Möbius committed
334
					                               glWidget_,
335
                                         PluginFunctions::viewerProperties(i),
Jan Möbius's avatar
Jan Möbius committed
336
                                         centerWidget_);
Dirk Wilden's avatar
Dirk Wilden committed
337

Jan Möbius's avatar
Jan Möbius committed
338
      examiner_widgets_.push_back(newWidget);
339 340 341 342 343 344 345 346 347 348

      connect (&PluginFunctions::viewerProperties(i), SIGNAL( getPickMode(std::string&) ),
               this,                                   SLOT( getPickMode(std::string&) ),Qt::DirectConnection );
      connect (&PluginFunctions::viewerProperties(i), SIGNAL( setPickMode(const std::string) ),
               this,                                   SLOT( setPickMode(const std::string) ),Qt::DirectConnection );
      connect (&PluginFunctions::viewerProperties(i), SIGNAL( getActionMode(Viewer::ActionMode&) ),
               this,                                   SLOT( getActionMode(Viewer::ActionMode&) ),Qt::DirectConnection );
      connect (&PluginFunctions::viewerProperties(i), SIGNAL( setActionMode(const Viewer::ActionMode) ),
               this,                                   SLOT( setActionMode(const Viewer::ActionMode)), Qt::DirectConnection );

349
      connect (&PluginFunctions::viewerProperties(i), SIGNAL( drawModeChanged(int)), this, SIGNAL(drawModeChanged(int)));
Jan Möbius's avatar
Jan Möbius committed
350 351 352 353
    }

    // Initialize all examiners
    for ( unsigned int i = 0 ; i < OpenFlipper::Options::examinerWidgets() ; ++i ) {
Jan Möbius's avatar
Jan Möbius committed
354
      examiner_widgets_[i]->sceneGraph( PluginFunctions::getSceneGraphRootNode(), maxPases,bbmin,bbmax );
Jan Möbius's avatar
Dennis:  
Jan Möbius committed
355
      cursorPainter_->registerViewer (examiner_widgets_[i]);
Jan Möbius's avatar
Jan Möbius committed
356 357
    }

Jan Möbius's avatar
Jan Möbius committed
358 359 360 361
    baseLayout_->addItem(examiner_widgets_[0],0);
    baseLayout_->addItem(examiner_widgets_[1],1);
    baseLayout_->addItem(examiner_widgets_[2],2);
    baseLayout_->addItem(examiner_widgets_[3],3);
Jan Möbius's avatar
Jan Möbius committed
362 363
  }

Jan Möbius's avatar
 
Jan Möbius committed
364 365 366
  // Make examiner available to the plugins ( defined in PluginFunctions.hh)
  PluginFunctions::setViewers( examiner_widgets_ );

Jan Möbius's avatar
 
Jan Möbius committed
367
  centerWidget_->setLayout(baseLayout_);
368 369


Jan Möbius's avatar
 
Jan Möbius committed
370 371 372
  // ======================================================================
  // Setup dragging for examiner widget
  // ======================================================================
373 374 375 376 377 378 379 380
  for ( uint i = 0 ; i < OpenFlipper::Options::examinerWidgets() ; ++i ) {

    connect( examiner_widgets_[i], SIGNAL(startDragEvent( QMouseEvent*)),
             this, SLOT(startDrag(QMouseEvent* )));
    connect( examiner_widgets_[i], SIGNAL(dragEnterEvent( QDragEnterEvent*)),
            this, SLOT(dragEnterEvent(QDragEnterEvent* )));
    connect( examiner_widgets_[i], SIGNAL(dropEvent( QDropEvent*)),
            this, SLOT(dropEvent(QDropEvent* )));
381 382
    connect (examiner_widgets_[i], SIGNAL(signalMakeActive ()),
             this, SLOT(slotActivateExaminer()));
383 384 385

    connect (examiner_widgets_[i], SIGNAL(statusMessage(QString, int)),
             statusBar_, SLOT(showMessage(const QString&, int)));
Jan Möbius's avatar
Jan Möbius committed
386 387 388
  }


Jan Möbius's avatar
 
Jan Möbius committed
389 390 391
  // ======================================================================
  // Create main Toolbar
  // ======================================================================
Jan Möbius's avatar
Jan Möbius committed
392

Jan Möbius's avatar
Jan Möbius committed
393 394 395
  mainToolbar_ = new QToolBar(tr("Main Toolbar"));
  mainToolbar_->setWindowTitle(tr("Main Toolbar"));
  mainToolbar_->setObjectName(tr("MainToolbar"));
396
  slotAddToolbar(mainToolbar_);
Jan Möbius's avatar
Jan Möbius committed
397

Jan Möbius's avatar
 
Jan Möbius committed
398 399 400
  // ======================================================================
  // Get Toolbar from examiner and integrate it into main window
  // ======================================================================
Jan Möbius's avatar
Jan Möbius committed
401

Jan Möbius's avatar
Jan Möbius committed
402

403
  // Create the toolbar
Jan Möbius's avatar
Jan Möbius committed
404
  viewerToolbar_ = new QToolBar( tr("Viewer Toolbar" ), this );
405
  viewerToolbar_->setOrientation(Qt::Vertical);
Jan Möbius's avatar
 
Jan Möbius committed
406 407
  viewerToolbar_->setAllowedAreas(Qt::AllToolBarAreas);
  viewerToolbar_->setIconSize(QSize(20,20));
Jan Möbius's avatar
Jan Möbius committed
408
  viewerToolbar_->setObjectName(tr("ViewerToolbar"));
409

Jan Möbius's avatar
Jan Möbius committed
410
  slotAddToolbar(viewerToolbar_);
Jan Möbius's avatar
Jan Möbius committed
411

412 413 414 415
  moveButton_ = new QToolButton( viewerToolbar_ );
  moveButton_->setIcon( QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"transform-move.png") );
  moveButton_->setMinimumSize( 16, 16 );
  moveButton_->setMaximumSize( 32, 32 );
416
  moveButton_->setCheckable(true);
Jan Möbius's avatar
Jan Möbius committed
417 418
  moveButton_->setToolTip( tr("Switch to <b>move</b> mode.") );
  moveButton_->setWhatsThis(tr(
419 420 421
                  "Switch to <b>move</b> mode.<br>"
                  "<ul><li><b>Rotate</b> using <b>left</b> mouse button.</li>"
                  "<li><b>Translate</b> using <b>middle</b> mouse button.</li>"
Jan Möbius's avatar
Jan Möbius committed
422
                  "<li><b>Zoom</b> using <b>left+middle</b> mouse buttons.</li></ul>" ));
423 424

  connect( moveButton_,SIGNAL( clicked() ), this, SLOT( setExamineMode() ) );
425
/*
426
  connect( this, SIGNAL( actionModeChanged( Viewer::ActionMode ) ),
427
            this, SLOT(   slotActionModeChanged(Viewer::ActionMode) ) );*/
428

Jan Möbius's avatar
Jan Möbius committed
429
  viewerToolbar_->addWidget( moveButton_ )->setText(tr("Move"));
430
  moveButton_->setChecked(true);
431

432
  
433 434 435 436
  pickButton_ = new QToolButton( viewerToolbar_ );
  pickButton_->setIcon( QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"pick.png") );
  pickButton_->setMinimumSize( 16, 16 );
  pickButton_->setMaximumSize( 32, 32 );
437
  pickButton_->setCheckable(true);
Jan Möbius's avatar
Jan Möbius committed
438 439
  pickButton_->setToolTip(tr("Switch to <b>picking</b> mode."));
  pickButton_->setWhatsThis(tr(
440 441 442
                  "Switch to <b>picking</b> mode.<br>"
                  "Use picking functions like flipping edges.<br>"
                  "To change the mode use the right click<br>"
Jan Möbius's avatar
Jan Möbius committed
443
                  "context menu in the viewer."));
444
  connect( pickButton_,SIGNAL( clicked() ), this, SLOT( setPickingMode() ) );
Jan Möbius's avatar
Jan Möbius committed
445
  viewerToolbar_->addWidget( pickButton_)->setText(tr("Pick"));
446 447 448 449 450 451


  questionButton_ = new QToolButton( viewerToolbar_ );
  questionButton_->setIcon( QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"help-about.png") );
  questionButton_->setMinimumSize( 16, 16 );
  questionButton_->setMaximumSize( 32, 32 );
452
  questionButton_->setCheckable(true);
Jan Möbius's avatar
Jan Möbius committed
453 454
  questionButton_->setToolTip(tr("Switch to <b>identification</b> mode."));
  questionButton_->setWhatsThis(tr(
455 456 457 458
                  "Switch to <b>identification</b> mode.<br>"
                  "Use identification mode to get information "
                  "about objects. Click on an object and see "
                  "the log output for information about the "
Jan Möbius's avatar
Jan Möbius committed
459
                  "object."));
460
  connect( questionButton_,SIGNAL( clicked() ), this, SLOT( setQuestionMode() ) );
Jan Möbius's avatar
Jan Möbius committed
461
  viewerToolbar_->addWidget( questionButton_)->setText(tr("Question"));
462

463 464 465 466 467 468 469 470
  viewerLayoutBox_ = new QComboBox( viewerToolbar_ );
  viewerLayoutBox_->setMinimumSize( 32, 16 );
  viewerLayoutBox_->setMaximumSize( 64, 32 );
  viewerLayoutBox_->setToolTip(tr("Switch <b>viewer layout</b>."));
  viewerLayoutBox_->setWhatsThis(tr(
                  "Switch <b>viewer layout</b>.<br>"
                  "Select the desired viewer layout. "
                  "Possible layouts are: "
471
                  "<ul> "
472
				  "<li>Single viewer</li>"
Jan Möbius's avatar
Jan Möbius committed
473
          "<li>Double viewer</li>"
474 475
				  "<li>Multiple viewers (grid)</li>"
				  "<li>Multiple viewers (hsplit)</li>"
Jan Möbius's avatar
Jan Möbius committed
476
				  "</ul>"));
477

478
  viewerLayoutBox_->addItem(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"singleviewmode.png"), "");
Jan Möbius's avatar
Jan Möbius committed
479
  viewerLayoutBox_->addItem(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"doubleviewmode.png"), "");
480 481
  viewerLayoutBox_->addItem(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"multiviewmode1.png"), "");
  viewerLayoutBox_->addItem(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"multiviewmode2.png"), "");
482

483
  viewerLayoutBox_->setIconSize(QSize(22,22));
484

485
  connect( viewerLayoutBox_,SIGNAL( activated(int) ), this, SLOT( setViewerLayout(int) ) );
486

487
  viewerToolbar_->addWidget( viewerLayoutBox_ );
488

489 490 491 492 493 494 495 496 497
  viewerToolbar_->addSeparator();

  if (OpenFlipper::Options::stereo())
  {
    stereoButton_ = new QToolButton( viewerToolbar_ );
    stereoButton_->setIcon(  QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"mono.png")  );
    stereoButton_->setMinimumSize( 16, 16 );
    stereoButton_->setMaximumSize( 32, 32 );
    stereoButton_->setCheckable( true );
Jan Möbius's avatar
Jan Möbius committed
498
    stereoButton_->setToolTip(tr( "Toggle stereo viewing"));
499 500
    // We want a custom context menu
    stereoButton_->setContextMenuPolicy(Qt::CustomContextMenu);
Jan Möbius's avatar
Jan Möbius committed
501
    stereoButton_->setWhatsThis(tr(
502 503 504 505
                  "Toggle stereo mode<br><br>"
                  "Use this button to switch between stereo "
                  "and mono view. To use this feature you need "
                  "a stereo capable graphics card and a stereo "
Jan Möbius's avatar
Jan Möbius committed
506
                  "display/projection system."));
507 508 509
    connect( stereoButton_, SIGNAL( clicked() ), this , SLOT( slotToggleStereoMode() ) );
    // Custom context menu
    connect( stereoButton_, SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(stereoButtonContextMenu(const QPoint &)));
Jan Möbius's avatar
Jan Möbius committed
510
    viewerToolbar_->addWidget( stereoButton_ )->setText( tr("Stereo"));
511
  }
512 513


514
  addToolBar(Qt::TopToolBarArea,viewerToolbar_);
Jan Möbius's avatar
Jan Möbius committed
515

Jan Möbius's avatar
 
Jan Möbius committed
516 517
  // Remember logger size
  wsizes = splitter_->sizes();
518 519 520 521 522 523

  if(wsizes.size() > 1) {
    originalLoggerSize_  = wsizes[1];
  } else {
    originalLoggerSize_ = 240;
  }
Jan Möbius's avatar
Jan Möbius committed
524

Jan Möbius's avatar
 
Jan Möbius committed
525
  // ======================================================================
Jan Möbius's avatar
Dennis:  
Jan Möbius committed
526
  // Create ToolBox area
Jan Möbius's avatar
Jan Möbius committed
527
  // ======================================================================
Jan Möbius's avatar
Dennis:  
Jan Möbius committed
528 529 530

  toolBoxArea_ = new QWidget (toolSplitter_);

531
  viewModeControlBox_ = new QGroupBox (tr("ViewMode"));
Jan Möbius's avatar
Dennis:  
Jan Möbius committed
532 533 534

  QHBoxLayout *hLayout = new QHBoxLayout;

Jan Möbius's avatar
Jan Möbius committed
535 536
  vmChangeButton_ = new QPushButton(tr("Change View Mode"));
  QPushButton* vmEditButton   = new QPushButton(tr("Edit View Modes"));
537

Jan Möbius's avatar
Jan Möbius committed
538 539
  hLayout->addWidget(vmChangeButton_);
  hLayout->addWidget(vmEditButton);
540
  viewModeControlBox_->setLayout (hLayout);
Jan Möbius's avatar
Dennis:  
Jan Möbius committed
541

Jan Möbius's avatar
Jan Möbius committed
542 543
  connect(vmChangeButton_, SIGNAL(clicked()), this, SLOT(slotViewChangeDialog()));
  connect(vmEditButton, SIGNAL(clicked()), this, SLOT(slotViewModeDialog()));
Jan Möbius's avatar
Dennis:  
Jan Möbius committed
544 545 546 547 548 549 550 551

  toolBoxScroll_ = new QScrollArea ();
  toolBox_ = new SideArea ();
  toolBoxScroll_->setWidget (toolBox_);
  toolBoxScroll_->setWidgetResizable (true);
  toolBoxScroll_->setFrameStyle (QFrame::StyledPanel);

  QVBoxLayout *vLayout = new QVBoxLayout;
552
  vLayout->addWidget(viewModeControlBox_);
Jan Möbius's avatar
Dennis:  
Jan Möbius committed
553
  vLayout->addWidget(toolBoxScroll_);
554 555 556
  
  if ( OpenFlipperSettings().value("Core/Gui/TaskSwitcher/Hide",false).toBool() )
    viewModeControlBox_->hide();
Jan Möbius's avatar
Dennis:  
Jan Möbius committed
557 558 559 560 561

  toolBoxArea_->setLayout (vLayout);

  wsizes = toolSplitter_->sizes();

562
  // if the toolbox should be on the right, use the defaults. Otherwise, we have to reorder them.
Jan Möbius's avatar
Jan Möbius committed
563
  if ( OpenFlipperSettings().value("Core/Gui/ToolBoxes/ToolBoxOnTheRight", true).toBool() ) {
564

565 566 567 568 569
    // Set relative sizes of windows
    wsizes[0] = 480;
    wsizes[1] = 240;
    toolSplitter_->setSizes(wsizes);  
  } else {
570

571 572 573 574 575 576 577 578 579 580
    // Show tool box on the left side of the main window
    toolSplitter_->insertWidget(0, toolBoxArea_);
    toolSplitter_->insertWidget(1, splitter_);

    // Default sizes are swaped when toolbox is on the left.
    wsizes[0] = 240;
    wsizes[1] = 480;
    toolSplitter_->setSizes(wsizes);
  }
  
Jan Möbius's avatar
 
Jan Möbius committed
581 582 583
  // ======================================================================
  // Context menu setup
  // ======================================================================
Jan Möbius's avatar
Jan Möbius committed
584

Jan Möbius's avatar
Jan Möbius committed
585 586 587 588
  for ( unsigned int i = 0 ; i < OpenFlipper::Options::examinerWidgets() ; ++i ) {
    connect( examiner_widgets_[i] , SIGNAL(signalCustomContextMenuRequested( const QPoint&) ) ,
             this                 , SLOT( slotCustomContextMenu( const QPoint&) ) );
  }
Jan Möbius's avatar
Jan Möbius committed
589

Dirk Wilden's avatar
 
Dirk Wilden committed
590
  contextMenu_ = new QMenu(this);
Jan Möbius's avatar
Jan Möbius committed
591
  contextSelectionMenu_ = new QMenu(tr("Selection"),0);
Jan Möbius's avatar
Jan Möbius committed
592

Jan Möbius's avatar
 
Jan Möbius committed
593
  setupMenuBar();
Jan Möbius's avatar
Jan Möbius committed
594

Jan Möbius's avatar
Jan Möbius committed
595
  statusBar_->showMessage(tr("Ready"), 5000);
Dirk Wilden's avatar
Dirk Wilden committed
596

597
  registerCoreKeys();
Dirk Wilden's avatar
Dirk Wilden committed
598

599
  setExamineMode();
600 601 602

  setWindowIcon( OpenFlipper::Options::OpenFlipperIcon() );

603 604 605 606
  // Create stereo settings widget
  stereoSettingsWidget_ = new StereoSettingsWidget(this);
  // Make it look like a dialog
  stereoSettingsWidget_->setWindowFlags(Qt::Popup);
607 608
  // Connect combo boxes and sliders to local slots
  connect(stereoSettingsWidget_->stereoOpengl, SIGNAL(clicked()),
609
          this, SLOT(slotApplyStereoSettings()));
610 611 612 613 614
  connect(stereoSettingsWidget_->stereoAnaglyph, SIGNAL(clicked()),
          this, SLOT(slotApplyStereoSettings()));
  connect(stereoSettingsWidget_->stereoCustomAnaglyph, SIGNAL(clicked()),
          this, SLOT(slotApplyStereoSettings()));

615 616
  connect(stereoSettingsWidget_->focalDistance, SIGNAL(sliderReleased()),
          this, SLOT(slotApplyStereoSettings()));
617 618 619 620 621 622
  connect(stereoSettingsWidget_->eyeDistance, SIGNAL(editingFinished()),
          this, SLOT(slotApplyStereoSettings()));

  // Close button
  connect(stereoSettingsWidget_->closeButton, SIGNAL(clicked()),
          stereoSettingsWidget_, SLOT(hide()));
623 624 625 626 627 628


  // ======================================================================
  // Help Browser start up
  // ======================================================================

629
  helpWidget_ = new HelpWidget(this,homePage_,false);
Matthias Möller's avatar
doc  
Matthias Möller committed
630 631
  connect(this, SIGNAL(changeHelpSite(QUrl)), helpWidget_, SLOT(activateLink(QUrl)));
  helpWidget_->hide();
632

Jan Möbius's avatar
 
Jan Möbius committed
633 634 635 636 637 638 639
}


//-----------------------------------------------------------------------------


CoreWidget::~CoreWidget() {
Jan Möbius's avatar
Jan Möbius committed
640

Jan Möbius's avatar
 
Jan Möbius committed
641 642 643 644 645 646 647 648
}

//-----------------------------------------------------------------------------

/** Set viewer to Fullscreen Mode and back
  */
void
CoreWidget::toggleFullscreen() {
Jan Möbius's avatar
Jan Möbius committed
649

Dirk Wilden's avatar
Dirk Wilden committed
650 651 652 653 654 655 656 657 658 659 660 661 662 663 664
  switch (fullscreenState_){

    case 0:
      //switch to fullscreen
      setWindowState( windowState() | Qt::WindowFullScreen);
      break;

    case 1:

      //fullscreen without toolbars
      if ( ! (windowState() & Qt::WindowFullScreen) )
        setWindowState( windowState() | Qt::WindowFullScreen);

      //hide plugin toolbars
      for (uint p=0; p < plugins_.size(); p++)
665 666 667 668
        for ( uint j = 0 ; j < plugins_[p].toolbars.size(); ++j ) {
          if ( ! plugins_[p].toolbars[j].second->isFloating() )
            plugins_[p].toolbars[j].second->hide();
        }
Dirk Wilden's avatar
Dirk Wilden committed
669 670

      //hide main toolbar
671 672
      if ( ! mainToolbar_->isFloating() )
        mainToolbar_->hide();
Dirk Wilden's avatar
Dirk Wilden committed
673 674

      //hide viewer toolbar
675 676
      if ( ! viewerToolbar_->isFloating() )
        viewerToolbar_->hide();
Dirk Wilden's avatar
Dirk Wilden committed
677 678 679 680

      //hide the menubar
      menuBar()->hide();

681 682
      // hide the statusbar but don't change its last state, as this is only the large fullscreen mode
      // that hides everything.
Dirk Wilden's avatar
Dirk Wilden committed
683 684 685 686 687 688 689 690 691 692
      statusBar()->hide();

      break;

    default:
      //disable fullscreen
      if ( windowState() & Qt::WindowFullScreen )
        setWindowState( windowState() ^  Qt::WindowFullScreen);

      //show toolbars
Jan Möbius's avatar
Marlin:  
Jan Möbius committed
693
      setViewMode( OpenFlipper::Options::currentViewMode() );
Dirk Wilden's avatar
Dirk Wilden committed
694 695

      //show the menubar
696 697
      if ( ! OpenFlipperSettings().value("Core/Gui/MenuBar/hidden",false).toBool())
        menuBar()->show();
Dirk Wilden's avatar
Dirk Wilden committed
698

699 700 701 702
      // show the statusbar if this is the requested state
      // stored in the properties
      if ( ! OpenFlipperSettings().value("Core/Gui/StatusBar/hidden",false).toBool() )
        statusBar()->show();
Dirk Wilden's avatar
Dirk Wilden committed
703

Jan Möbius's avatar
Jan Möbius committed
704 705
      break;

Dirk Wilden's avatar
Dirk Wilden committed
706 707 708
  }

  fullscreenState_ = (fullscreenState_ + 1) % 3;
Jan Möbius's avatar
Jan Möbius committed
709 710
  
  OpenFlipperSettings().setValue("Core/Gui/fullscreen", bool( windowState() & Qt::WindowFullScreen) );
711

Jan Möbius's avatar
 
Jan Möbius committed
712 713 714 715 716
  show();
}

//-----------------------------------------------------------------------------

717 718 719 720 721 722 723 724 725 726 727
/** Enable or disable Fullscreen Mode
  */
void
CoreWidget::setFullscreen(bool _state ) {
  if ( _state )
    setWindowState( windowState() | Qt::WindowFullScreen);
  else {
    if ( windowState() & Qt::WindowFullScreen )
      setWindowState( windowState() ^  Qt::WindowFullScreen);
  }

Dirk Wilden's avatar
Dirk Wilden committed
728 729
  fullscreenState_ = (uint) _state;

Jan Möbius's avatar
Jan Möbius committed
730
  OpenFlipperSettings().setValue("Core/Gui/fullscreen", bool( windowState() & Qt::WindowFullScreen) );
731 732 733 734

  show();
}

735 736 737 738 739 740 741 742 743 744
//-----------------------------------------------------------------------------

void 
CoreWidget::showViewModeControls(bool _show) {
  // Only change if the actual setting has changed!
  if ( OpenFlipper::Options::gui() && ( !_show != OpenFlipperSettings().value("Core/Gui/TaskSwitcher/Hide",false).toBool() ) ) {
  
    // Update setting in Conf storage
    OpenFlipperSettings().setValue("Core/Gui/TaskSwitcher/Hide",!_show);
    
745 746 747 748 749
    // Update The Checkbox in the Menu
    AC_ShowViewModeControls_->blockSignals(true);
    AC_ShowViewModeControls_->setChecked( _show  );
    AC_ShowViewModeControls_->blockSignals(false);
    
750 751 752 753 754 755 756 757 758 759
    if ( _show ) {
      viewModeControlBox_->show();
    } else {
      viewModeControlBox_->hide();
    }
    
  }
  
}

Jan Möbius's avatar
 
Jan Möbius committed
760 761 762 763 764 765
//-----------------------------------------------------------------------------

/** Hide or show toolbox
  */
void
CoreWidget::toggleToolbox() {
Jan Möbius's avatar
Jan Möbius committed
766

Jan Möbius's avatar
 
Jan Möbius committed
767
  //toggle
Jan Möbius's avatar
Jan Möbius committed
768
  showToolbox( OpenFlipperSettings().value("Core/Gui/ToolBoxes/hidden",false).toBool() );
769

770 771 772 773 774 775 776 777 778 779
}

//-----------------------------------------------------------------------------

/** Hide or show toolbox
  */
void
CoreWidget::showToolbox( bool _state ) {

  //toggle
Jan Möbius's avatar
Jan Möbius committed
780
  OpenFlipperSettings().setValue("Core/Gui/ToolBoxes/hidden",!_state);
Jan Möbius's avatar
 
Jan Möbius committed
781

Jan Möbius's avatar
Jan Möbius committed
782
  if ( OpenFlipperSettings().value("Core/Gui/ToolBoxes/hidden",false).toBool() ){
Jan Möbius's avatar
 
Jan Möbius committed
783 784

    //hide ViewMode Selection Widget
Jan Möbius's avatar
Dennis:  
Jan Möbius committed
785
    toolBoxArea_->setVisible(false);
Jan Möbius's avatar
 
Jan Möbius committed
786 787

  }else{
788
    //show last view mode
Jan Möbius's avatar
Dennis:  
Jan Möbius committed
789
    toolBoxArea_->setVisible(true);
Jan Möbius's avatar
 
Jan Möbius committed
790
  }
791
  emit toolBoxVisChanged(_state);
Jan Möbius's avatar
 
Jan Möbius committed
792
}
793
//-----------------------------------------------------------------------------
794
void CoreWidget::showMenuBar( bool _state )
795
{
796 797 798 799 800
  OpenFlipperSettings().setValue("Core/Gui/MenuBar/hidden",!_state);

  if ( _state ){

    //hide ViewMode Selection Widget
801
    menuBar()->show();
802 803 804

  }else{
    //show last view mode
805
    menuBar()->hide();
806 807
  }
  emit menuBarVisChanged(_state);
808 809
}
//-----------------------------------------------------------------------------
810 811
/// Show or hide toolbar
void CoreWidget::showToolBar( bool _state )
812
{
813 814
  OpenFlipperSettings().setValue("Core/Gui/Toolbar/hidden",!_state);
  if ( !_state )
815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834
  {
    //hide main toolbar
    if ( ! mainToolbar_->isFloating() )
      mainToolbar_->hide();

    //hide viewer toolbar
    if ( ! viewerToolbar_->isFloating() )
      viewerToolbar_->hide();

    for (uint p=0; p < plugins_.size(); p++)
      for ( uint j = 0 ; j < plugins_[p].toolbars.size(); ++j ) {
        if ( ! plugins_[p].toolbars[j].second->isFloating() )
          plugins_[p].toolbars[j].second->hide();
      }
  }
  else
  {
    //show toolbars
    setViewMode( OpenFlipper::Options::currentViewMode() );
  }
835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850
  emit toolBarVisChanged(_state);
}
//-----------------------------------------------------------------------------
/// Hide or show menubar
void CoreWidget::toggleMenuBar()
{
  bool hidden = OpenFlipperSettings().value("Core/Gui/MenuBar/hidden",false).toBool();
  showMenuBar( hidden );
}

//-----------------------------------------------------------------------------
/// Hide or show current toolbar
void CoreWidget::toggleToolBar()
{
  bool hidden = OpenFlipperSettings().value("Core/Gui/Toolbar/hidden",false).toBool();
  showToolBar( hidden );
851
}
Jan Möbius's avatar
Jan Möbius committed
852

853

854 855
//=============================================================================

856
void CoreWidget::setToolBoxOrientationOnTheRight(bool _toolBoxRight) {
857
  QList<int> wsizes;
Jan Möbius's avatar
Jan Möbius committed
858
  
859 860
  // Is toolbox currently on the right hand side?
  bool currentstate = toolSplitter_->widget(1) == toolBoxArea_;
Jan Möbius's avatar
Jan Möbius committed
861 862
  
  if ( _toolBoxRight != currentstate ) {
863
    
Jan Möbius's avatar
Jan Möbius committed
864 865 866 867 868 869 870 871 872 873 874
    if(_toolBoxRight ) {
      
      // Show tool box on the right side of the main window
      toolSplitter_->insertWidget(0, splitter_);
      toolSplitter_->insertWidget(1, toolBoxArea_);
    } else {
      
      // Show tool box on the left side of the main window
      toolSplitter_->insertWidget(0, toolBoxArea_);
      toolSplitter_->insertWidget(1, splitter_);
    }
875
    
Jan Möbius's avatar
Jan Möbius committed
876
    // Store new setting
Jan Möbius's avatar
Jan Möbius committed
877
    OpenFlipperSettings().setValue("Core/Gui/ToolBoxes/ToolBoxOnTheRight",_toolBoxRight);
878
    
Jan Möbius's avatar
Jan Möbius committed
879 880
    // remove the windowstates definition for the toolboxes, as it changed anyway.
    QSettings windowStates(QDir::home().absolutePath() + OpenFlipper::Options::dirSeparator() + ".OpenFlipper" +
881
                            OpenFlipper::Options::dirSeparator() +  "WindowStates.dat", QSettings::IniFormat);
Jan Möbius's avatar
Jan Möbius committed
882 883
    
    windowStates.value("Core/ToolSplitter");
884 885 886
    
  }
  
Jan Möbius's avatar
Jan Möbius committed
887

888 889 890 891 892
    
  toolSplitter_->refresh();
}
      

Jan Möbius's avatar
 
Jan Möbius committed
893 894
//=============================================================================

Jan Möbius's avatar
Jan Möbius committed
895 896
void
CoreWidget::addRecent(QString _filename, DataType _type)
Jan Möbius's avatar
 
Jan Möbius committed
897
{
898
  //dont add objects to recentMenu while loadind Settings
899
  if ( OpenFlipper::Options::sceneGraphUpdatesBlocked() ) return;
Jan Möbius's avatar
Jan Möbius committed
900

Jan Möbius's avatar
 
Jan Möbius committed
901
  OpenFlipper::Options::addRecentFile(_filename, _type);
Jan Möbius's avatar
Jan Möbius committed
902

Jan Möbius's avatar
 
Jan Möbius committed
903
  updateRecent();
Jan Möbius's avatar
Jan Möbius committed
904 905 906 907 908 909 910

}

//=============================================================================

void
CoreWidget::updateRecent()
Jan Möbius's avatar
 
Jan Möbius committed
911 912 913
{
  if ( recentFilesMenu_ == NULL)
    return;
Jan Möbius's avatar
Jan Möbius committed