CoreWidget.cc 28.9 KB
Newer Older
Jan Möbius's avatar
 
Jan Möbius committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
//=============================================================================
//
//                               OpenFlipper
//        Copyright (C) 2008 by Computer Graphics Group, RWTH Aachen
//                           www.openflipper.org
//
//-----------------------------------------------------------------------------
//
//                                License
//
//  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.
Jan Möbius's avatar
Jan Möbius committed
15
//
Jan Möbius's avatar
 
Jan Möbius committed
16
17
18
19
//  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.
Jan Möbius's avatar
Jan Möbius committed
20
//
Jan Möbius's avatar
 
Jan Möbius committed
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
//  You should have received a copy of the GNU Lesser General Public License
//  along with OpenFlipper.  If not, see <http://www.gnu.org/licenses/>.
//
//-----------------------------------------------------------------------------
//
//   $Revision$
//   $Author$
//   $Date$
//
//=============================================================================




//=============================================================================
//
//  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
51
#include <OpenFlipper/BasePlugin/PluginFunctionsCore.hh>
Dirk Wilden's avatar
Dirk Wilden committed
52
53
#include <OpenFlipper/BasePlugin/KeyInterface.hh>
#include <OpenFlipper/BasePlugin/LoggingInterface.hh>
Jan Möbius's avatar
 
Jan Möbius committed
54

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

Jan Möbius's avatar
 
Jan Möbius committed
57
58
59
#define WIDGET_HEIGHT 800
#define WIDGET_WIDTH  800

Jan Möbius's avatar
Jan Möbius committed
60
//== IMPLEMENTATION ==========================================================
Jan Möbius's avatar
 
Jan Möbius committed
61

Jan Möbius's avatar
Jan Möbius committed
62
63
/** \brief Constuctor for the Core Widget
 *
Jan Möbius's avatar
 
Jan Möbius committed
64
65
*/
CoreWidget::
Dirk Wilden's avatar
Dirk Wilden committed
66
CoreWidget( QVector<ViewMode*>& _viewModes,
Dirk Wilden's avatar
Dirk Wilden committed
67
68
            std::vector<PluginInfo>& _plugins,
            QList< SlotInfo >& _coreSlots ) :
Jan Möbius's avatar
 
Jan Möbius committed
69
  QMainWindow(),
Dirk Wilden's avatar
Dirk Wilden committed
70
  coreSlots_(_coreSlots),
Dirk Wilden's avatar
Dirk Wilden committed
71
  shiftPressed_(false),
Jan Möbius's avatar
 
Jan Möbius committed
72
73
  viewModes_(_viewModes),
  viewModeButton_(0),
74
  viewModeMenu_(0),
Jan Möbius's avatar
 
Jan Möbius committed
75
  splitter_(0),
76
  logWidget_(0),
Jan Möbius's avatar
 
Jan Möbius committed
77
  recentFilesMenu_(0),
78
79
  helpMenu_(0),
  sceneGraphDialog_(0),
80
81
82
  fileMenu_(0),
  viewMenu_(0),
  toolsMenu_(0),
Jan Möbius's avatar
 
Jan Möbius committed
83
  fileMenuEnd_(0),
84
85
86
87
  stereoButton_(0),
  moveButton_(0),
  lightButton_(0),
  pickButton_(0),
Dirk Wilden's avatar
Dirk Wilden committed
88
  questionButton_(0),
89
90
91
  globalDrawMenu_(0),
  drawGroup_(0),
  viewGroup_(0),
92
  perspectiveProjectionAction_(0),
93
94
  activeDrawModes_(0),
  availableGlobalDrawModes_(0),
Jan Möbius's avatar
 
Jan Möbius committed
95
  contextMenu_(0),
Jan Möbius's avatar
Jan Möbius committed
96
  contextSelectionMenu_(0),
97
98
  drawGroupViewer_(0),
  viewerDrawMenu_(0),
99
  coordSysMenu_(0),
Dirk Wilden's avatar
Dirk Wilden committed
100
101
  snapshotName_("snap.png"),
  snapshotCounter_(0),
Jan Möbius's avatar
 
Jan Möbius committed
102
  stackMenu_(0),
103
  helpWidget_(0),
Jan Möbius's avatar
Jan Möbius committed
104
  aboutWidget_(0),
105
  optionsWidget_(0),
106
  plugins_(_plugins),
107
108
109
110
111
112
  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
113
114
{
  setupStatusBar();
Jan Möbius's avatar
Jan Möbius committed
115

Jan Möbius's avatar
Dennis:    
Jan Möbius committed
116
117
118
119
120
  toolSplitter_ = new QSplitter(Qt::Horizontal,this);

  setCentralWidget(toolSplitter_);

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

123
124
  QGLFormat format = QGLFormat::defaultFormat();

125
126
127
  #ifdef ARCH_DARWIN
  format.setStereo(false);
  #else
Jan Möbius's avatar
   
Jan Möbius committed
128
  format.setStereo( OpenFlipper::Options::stereo() );
129
  #endif
Jan Möbius's avatar
   
Jan Möbius committed
130
  format.setAlpha(true);
131
  format.setStencil(true);
132
133
  format.setSampleBuffers(true);
  QGLFormat::setDefaultFormat(format);
Jan Möbius's avatar
   
Jan Möbius committed
134
135

  // Construct GL context & widget
136
137
138
  baseLayout_ = new QtMultiViewLayout;
  baseLayout_->setContentsMargins(0,0,0,0);

139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
  // ===============================================================================
  // Test context capabilities ...
  // If we get stereo buffers, we use them .. which might disable multisampling
  // If we dont have stereo, we disable it to not interfere with multisampling
  // ===============================================================================
  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);
156
  PluginFunctions::shareGLWidget (glWidget_);
157

Jan Möbius's avatar
   
Jan Möbius committed
158
  glView_ = new QtGLGraphicsView(stackedWidget_);
159
  glScene_ = new QtGLGraphicsScene (&examiner_widgets_, baseLayout_);
Jan Möbius's avatar
   
Jan Möbius committed
160

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

Jan Möbius's avatar
   
Jan Möbius committed
164
165
166
167
  glView_->setViewport(glWidget_);
  glView_->setViewportUpdateMode(QGraphicsView::FullViewportUpdate);
  glView_->setScene(glScene_);

168

169

Jan Möbius's avatar
   
Jan Möbius committed
170
171
172
173
174
175
176
177
178
179
  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
180
181
182
  // ======================================================================
  // Set up the logging window
  // ======================================================================
183
184
185
186

  slidingLogger_ = new QtSlideWindow ("Log Viewer", centerWidget_);
  tempLogWidget = new QWidget;

187
188
189
  logWidget_ = new LoggerWidget(splitter_);
  logWidget_->setReadOnly(true);
  logWidget_->setSizePolicy( QSizePolicy ( QSizePolicy::Preferred , QSizePolicy::Preferred ) );
190
  logWidget_->resize( splitter_->width() ,240);
191
  logWidget_->setLineWrapMode( QTextEdit::NoWrap );
Jan Möbius's avatar
Jan Möbius committed
192

193
  originalLoggerSize_ = 0;
Jan Möbius's avatar
Jan Möbius committed
194
  loggerState_ = OpenFlipper::Options::Normal;
195

Jan Möbius's avatar
 
Jan Möbius committed
196
  QList<int> wsizes( splitter_->sizes() );
197

Jan Möbius's avatar
Jan Möbius committed
198
  if (OpenFlipper::Options::loggerState() == OpenFlipper::Options::InScene) {
199
200
    slidingLogger_->attachWidget (logWidget_);
    splitter_->insertWidget (1, tempLogWidget);
201
    wsizes[0] = 1;
Jan Möbius's avatar
 
Jan Möbius committed
202
203
    wsizes[1] = 0;
    splitter_->setSizes(wsizes);
Jan Möbius's avatar
Jan Möbius committed
204
    loggerState_ = OpenFlipper::Options::InScene;
205
    baseLayout_->setContentsMargins (0, 0, 0, 16);
Jan Möbius's avatar
Jan Möbius committed
206
207
208
209
210
211
212
213
214
215
216
  } else if (OpenFlipper::Options::loggerState() == OpenFlipper::Options::Hidden) {
    splitter_->insertWidget (1, tempLogWidget);
    wsizes[0] = 1;
    wsizes[1] = 0;
    splitter_->setSizes(wsizes);
    loggerState_ = OpenFlipper::Options::Hidden;
  } else {
    // Set initial values to have a usable state
    wsizes[0] = 480;
    wsizes[1] = 240;
    splitter_->setSizes(wsizes);
Jan Möbius's avatar
 
Jan Möbius committed
217
  }
Jan Möbius's avatar
Jan Möbius committed
218

219

Jan Möbius's avatar
 
Jan Möbius committed
220
221
222
  // ======================================================================
  // Create examiner
  // ======================================================================
Jan Möbius's avatar
Jan Möbius committed
223
224
225

  if ( !OpenFlipper::Options::multiView() ) {

Jan Möbius's avatar
   
Jan Möbius committed
226
227
    glViewer* examinerWidget = new glViewer(glScene_,
					    glWidget_,
228
                                            PluginFunctions::viewerProperties(0),
229
					    centerWidget_);
Jan Möbius's avatar
Jan Möbius committed
230

Jan Möbius's avatar
Jan Möbius committed
231
232
233
    examiner_widgets_.push_back(examinerWidget);

    examinerWidget->sceneGraph( PluginFunctions::getSceneGraphRootNode() );
Jan Möbius's avatar
Jan Möbius committed
234

Jan Möbius's avatar
Jan Möbius committed
235
    baseLayout_->addItem(examinerWidget, 0);
Jan Möbius's avatar
Jan Möbius committed
236
237
238
239

  } else {


Jan Möbius's avatar
   
Jan Möbius committed
240
241
242
243
    // Create examiners
    for ( unsigned int i = 0 ; i < OpenFlipper::Options::examinerWidgets() ; ++i ) {
      glViewer* newWidget = new glViewer(glScene_,
					 glWidget_,
244
                                         PluginFunctions::viewerProperties(i),
245
					 centerWidget_);
Dirk Wilden's avatar
Dirk Wilden committed
246

Jan Möbius's avatar
Jan Möbius committed
247
      examiner_widgets_.push_back(newWidget);
248
249
250
251
252
253
254
255
256
257

      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 );

Jan Möbius's avatar
Jan Möbius committed
258
259
260
261
262
263
264
    }

    // Initialize all examiners
    for ( unsigned int i = 0 ; i < OpenFlipper::Options::examinerWidgets() ; ++i ) {
      examiner_widgets_[i]->sceneGraph( PluginFunctions::getSceneGraphRootNode() );
    }

Jan Möbius's avatar
Jan Möbius committed
265
266
267
268
    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
269
270
  }

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

Jan Möbius's avatar
   
Jan Möbius committed
274
  centerWidget_->setLayout(baseLayout_);
275
276


Jan Möbius's avatar
 
Jan Möbius committed
277
278
279
  // ======================================================================
  // Setup dragging for examiner widget
  // ======================================================================
280
281
282
283
284
285
286
287
  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* )));
288
289
    connect (examiner_widgets_[i], SIGNAL(signalMakeActive ()),
             this, SLOT(slotActivateExaminer()));
290
291
292

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


Jan Möbius's avatar
 
Jan Möbius committed
296
297
298
  // ======================================================================
  // Create main Toolbar
  // ======================================================================
Jan Möbius's avatar
Jan Möbius committed
299

Jan Möbius's avatar
Jan Möbius committed
300
301
302
  mainToolbar_ = new QToolBar(tr("Main Toolbar"));
  mainToolbar_->setWindowTitle(tr("Main Toolbar"));
  mainToolbar_->setObjectName(tr("MainToolbar"));
303
  slotAddToolbar(mainToolbar_);
Jan Möbius's avatar
Jan Möbius committed
304

Jan Möbius's avatar
 
Jan Möbius committed
305
306
307
  // ======================================================================
  // Get Toolbar from examiner and integrate it into main window
  // ======================================================================
Jan Möbius's avatar
Jan Möbius committed
308

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

310
  // Create the toolbar
Jan Möbius's avatar
Jan Möbius committed
311
  viewerToolbar_ = new QToolBar( tr("Viewer Toolbar" ), this );
312
  viewerToolbar_->setOrientation(Qt::Vertical);
Jan Möbius's avatar
 
Jan Möbius committed
313
314
  viewerToolbar_->setAllowedAreas(Qt::AllToolBarAreas);
  viewerToolbar_->setIconSize(QSize(20,20));
Jan Möbius's avatar
Jan Möbius committed
315
  viewerToolbar_->setObjectName(tr("ViewerToolbar"));
Jan Möbius's avatar
Jan Möbius committed
316

317
318
319
320
  moveButton_ = new QToolButton( viewerToolbar_ );
  moveButton_->setIcon( QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"transform-move.png") );
  moveButton_->setMinimumSize( 16, 16 );
  moveButton_->setMaximumSize( 32, 32 );
Jan Möbius's avatar
Jan Möbius committed
321
322
  moveButton_->setToolTip( tr("Switch to <b>move</b> mode.") );
  moveButton_->setWhatsThis(tr(
323
324
325
                  "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
326
                  "<li><b>Zoom</b> using <b>left+middle</b> mouse buttons.</li></ul>" ));
327
328

  connect( moveButton_,SIGNAL( clicked() ), this, SLOT( setExamineMode() ) );
329
/*
330
  connect( this, SIGNAL( actionModeChanged( Viewer::ActionMode ) ),
331
            this, SLOT(   slotActionModeChanged(Viewer::ActionMode) ) );*/
332

Jan Möbius's avatar
Jan Möbius committed
333
  viewerToolbar_->addWidget( moveButton_ )->setText(tr("Move"));
334
335
336
337
338
339
340
  moveButton_->setDown(true);


  lightButton_ = new QToolButton( viewerToolbar_ );
  lightButton_->setIcon( QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"light-mode.png") );
  lightButton_->setMinimumSize( 16, 16 );
  lightButton_->setMaximumSize( 32, 32 );
Jan Möbius's avatar
Jan Möbius committed
341
342
  lightButton_->setToolTip(tr("Switch to <b>light</b> mode."));
  lightButton_->setWhatsThis(tr(
343
                  "Switch to <b>light</b> mode.<br>"
Jan Möbius's avatar
Jan Möbius committed
344
                  "Rotate lights using left mouse button."));
345
346

  connect( lightButton_,SIGNAL( clicked() ), this, SLOT( setLightMode() ) );
Jan Möbius's avatar
Jan Möbius committed
347
  viewerToolbar_->addWidget( lightButton_)->setText(tr("Light"));
348
349
350
351
352
353


  pickButton_ = new QToolButton( viewerToolbar_ );
  pickButton_->setIcon( QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"pick.png") );
  pickButton_->setMinimumSize( 16, 16 );
  pickButton_->setMaximumSize( 32, 32 );
Jan Möbius's avatar
Jan Möbius committed
354
355
  pickButton_->setToolTip(tr("Switch to <b>picking</b> mode."));
  pickButton_->setWhatsThis(tr(
356
357
358
                  "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
359
                  "context menu in the viewer."));
360
  connect( pickButton_,SIGNAL( clicked() ), this, SLOT( setPickingMode() ) );
Jan Möbius's avatar
Jan Möbius committed
361
  viewerToolbar_->addWidget( pickButton_)->setText(tr("Pick"));
362
363
364
365
366
367


  questionButton_ = new QToolButton( viewerToolbar_ );
  questionButton_->setIcon( QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"help-about.png") );
  questionButton_->setMinimumSize( 16, 16 );
  questionButton_->setMaximumSize( 32, 32 );
Jan Möbius's avatar
Jan Möbius committed
368
369
  questionButton_->setToolTip(tr("Switch to <b>identification</b> mode."));
  questionButton_->setWhatsThis(tr(
370
371
372
373
                  "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
374
                  "object."));
375
  connect( questionButton_,SIGNAL( clicked() ), this, SLOT( setQuestionMode() ) );
Jan Möbius's avatar
Jan Möbius committed
376
  viewerToolbar_->addWidget( questionButton_)->setText(tr("Question"));
377

378
379
380
  viewmodeBox_ = new QComboBox( viewerToolbar_ );
  viewmodeBox_->setMinimumSize( 32, 16 );
  viewmodeBox_->setMaximumSize( 64, 32 );
Jan Möbius's avatar
Jan Möbius committed
381
382
  viewmodeBox_->setToolTip(tr("Switch <b>view mode</b>."));
  viewmodeBox_->setWhatsThis(tr(
383
384
385
386
387
388
389
                  "Switch <b>view mode</b>.<br>"
                  "Select the desired view mode. "
                  "Possible modes are: "
                  "<ul> "
				  "<li>Single view mode</li>"
				  "<li>Multi view mode (grid)</li>"
				  "<li>Multi view mode (hsplit)</li>"
Jan Möbius's avatar
Jan Möbius committed
390
				  "</ul>"));
391
392
393
394
395

  viewmodeBox_->addItem(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"singleviewmode.png"), "");
  viewmodeBox_->addItem(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"multiviewmode1.png"), "");
  viewmodeBox_->addItem(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"multiviewmode2.png"), "");

396
  viewmodeBox_->setIconSize(QSize(22,22));
397
398
399
400
401

  connect( viewmodeBox_,SIGNAL( activated(int) ), this, SLOT( setViewMode(int) ) );

  viewerToolbar_->addWidget( viewmodeBox_ );

402
403
404
405
406
407
408
409
410
  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
411
412
    stereoButton_->setToolTip(tr( "Toggle stereo viewing"));
    stereoButton_->setWhatsThis(tr(
413
414
415
416
                  "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
417
                  "display/projection system."));
418
    connect( stereoButton_,SIGNAL( clicked() ), this , SLOT( slotToggleStereoMode() ) );
Jan Möbius's avatar
Jan Möbius committed
419
    viewerToolbar_->addWidget( stereoButton_ )->setText( tr("Stereo"));
420
  }
421
422


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

Jan Möbius's avatar
 
Jan Möbius committed
425
426
427
  // Remember logger size
  wsizes = splitter_->sizes();
  originalLoggerSize_  = wsizes[1];
Jan Möbius's avatar
Jan Möbius committed
428

Jan Möbius's avatar
 
Jan Möbius committed
429
  // ======================================================================
Jan Möbius's avatar
Dennis:    
Jan Möbius committed
430
  // Create ToolBox area
Jan Möbius's avatar
Jan Möbius committed
431
  // ======================================================================
Jan Möbius's avatar
Dennis:    
Jan Möbius committed
432
433
434

  toolBoxArea_ = new QWidget (toolSplitter_);

Jan Möbius's avatar
Jan Möbius committed
435
  QGroupBox *gb = new QGroupBox (tr("ViewMode"));
Jan Möbius's avatar
Dennis:    
Jan Möbius committed
436
437
438

  QHBoxLayout *hLayout = new QHBoxLayout;

Jan Möbius's avatar
Jan Möbius committed
439
  QPushButton* vmButton = new QPushButton(tr("Change View Mode"));
Jan Möbius's avatar
Dennis:    
Jan Möbius committed
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
  hLayout->addWidget (vmButton);
  gb->setLayout (hLayout);

  connect(vmButton, SIGNAL(clicked()), this, SLOT(slotViewModeDialog()));

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

  QVBoxLayout *vLayout = new QVBoxLayout;
  vLayout->addWidget(gb);
  vLayout->addWidget(toolBoxScroll_);

  toolBoxArea_->setLayout (vLayout);

  wsizes = toolSplitter_->sizes();

  wsizes[0] = 480;
  wsizes[1] = 240;
  toolSplitter_->setSizes(wsizes);

Jan Möbius's avatar
Dennis:    
Jan Möbius committed
463
464
465
466
467
  // ======================================================================
  // Create pick ToolBar
  // ======================================================================

  pickToolbar_ = new QtPickToolbar (this, centerWidget_);
Jan Möbius's avatar
Jan Möbius committed
468

Jan Möbius's avatar
 
Jan Möbius committed
469
470
471
  // ======================================================================
  // Context menu setup
  // ======================================================================
Jan Möbius's avatar
Jan Möbius committed
472

Jan Möbius's avatar
Jan Möbius committed
473
474
475
476
  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
477

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

Jan Möbius's avatar
 
Jan Möbius committed
481
  setupMenuBar();
Jan Möbius's avatar
Jan Möbius committed
482

Jan Möbius's avatar
 
Jan Möbius committed
483
  updateRecent();
Jan Möbius's avatar
Jan Möbius committed
484

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

487
  registerCoreKeys();
Dirk Wilden's avatar
Dirk Wilden committed
488

489
  setExamineMode();
490
491
492

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

Jan Möbius's avatar
 
Jan Möbius committed
493
494
495
496
497
498
499
}


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


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

Jan Möbius's avatar
 
Jan Möbius committed
501
502
503
504
505
506
507
508
}

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

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

510
511
512
513
  setWindowState( windowState() ^  Qt::WindowFullScreen);

  OpenFlipper::Options::fullScreen( bool( windowState() & Qt::WindowFullScreen) );

Jan Möbius's avatar
 
Jan Möbius committed
514
515
516
517
518
  show();
}

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

519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
/** 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);
  }

  OpenFlipper::Options::fullScreen( bool( windowState() & Qt::WindowFullScreen) );

  show();
}

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

Jan Möbius's avatar
 
Jan Möbius committed
537
538
539
540
/** Hide or show logger
  */
void
CoreWidget::toggleLogger() {
Jan Möbius's avatar
Jan Möbius committed
541
542
543
544
545
546
547
548
549
550
551
552
553

  switch (OpenFlipper::Options::loggerState ())
  {
    case OpenFlipper::Options::InScene:
      OpenFlipper::Options::loggerState(OpenFlipper::Options::Normal);
      break;
    case OpenFlipper::Options::Normal:
      OpenFlipper::Options::loggerState(OpenFlipper::Options::Hidden);
      break;
    case OpenFlipper::Options::Hidden:
      OpenFlipper::Options::loggerState(OpenFlipper::Options::InScene);
      break;
  }
Jan Möbius's avatar
Jan Möbius committed
554

555
  // Hide/Show Logger
Jan Möbius's avatar
Jan Möbius committed
556
  showLogger( OpenFlipper::Options::loggerState() );
557
558
559
560
561
}

/** Hide or show logger
  */
void
Jan Möbius's avatar
Jan Möbius committed
562
CoreWidget::showLogger(OpenFlipper::Options::LoggerState _state) {
Jan Möbius's avatar
 
Jan Möbius committed
563
  //Hide Logger
Jan Möbius's avatar
Jan Möbius committed
564
565
566
  if (_state == loggerState_)
    return;

567
568
569
  qreal left, top, right, bottom;
  baseLayout_->getContentsMargins (&left, &top, &right, &bottom);

Jan Möbius's avatar
Jan Möbius committed
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
  switch (_state)
  {
    case OpenFlipper::Options::InScene:
      {
        QList<int> wsizes( splitter_->sizes() );

        // Remember old size
        if (loggerState_ == OpenFlipper::Options::Normal)
          originalLoggerSize_  = wsizes[1];

	if ( originalLoggerSize_ == 0)
          originalLoggerSize_ = 240;

        splitter_->insertWidget (1, tempLogWidget);
        wsizes[0] = wsizes[0]+wsizes[1];
        wsizes[1] = 0;
        splitter_->setSizes(wsizes);
        logWidget_->resize (logWidget_->width (), originalLoggerSize_);
        slidingLogger_->attachWidget (logWidget_);
589
        baseLayout_->setContentsMargins (left, top, right, 16);
Jan Möbius's avatar
Jan Möbius committed
590
591
592
593
594
595
596
597
598
599
600
601
602
603
      }
      break;
    case OpenFlipper::Options::Normal:
      {
        if ( originalLoggerSize_ == 0)
          originalLoggerSize_ = 240;

        QList<int> wsizes( splitter_->sizes() );

        if (loggerState_ == OpenFlipper::Options::InScene)
          originalLoggerSize_ = logWidget_->height ();

        slidingLogger_->detachWidget ();
        splitter_->insertWidget (1, logWidget_);
604
        logWidget_->show ();
Jan Möbius's avatar
Jan Möbius committed
605
606
607
608

        wsizes[0] = wsizes[0]+wsizes[1] - originalLoggerSize_;
        wsizes[1] = originalLoggerSize_;
        splitter_->setSizes(wsizes);
609
        baseLayout_->setContentsMargins (left, top, right, 0);
Jan Möbius's avatar
Jan Möbius committed
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
      }
      break;
    case OpenFlipper::Options::Hidden:
      {
        QList<int> wsizes( splitter_->sizes() );

        // Remember old size
        if (loggerState_ == OpenFlipper::Options::Normal)
          originalLoggerSize_  = wsizes[1];

	if (loggerState_ == OpenFlipper::Options::InScene)
	{
	  slidingLogger_->detachWidget ();
	  originalLoggerSize_ = logWidget_->height ();
	}

        splitter_->insertWidget (1, tempLogWidget);
        wsizes[0] = wsizes[0]+wsizes[1];
        wsizes[1] = 0;
        splitter_->setSizes(wsizes);
630
        baseLayout_->setContentsMargins (left, top, right, 0);
Jan Möbius's avatar
Jan Möbius committed
631
632
633
634
635
636
      }
      break;
  }
  loggerState_ = _state;

/*
637
  if ( !_state ) {
Jan Möbius's avatar
 
Jan Möbius committed
638
    QList<int> wsizes( splitter_->sizes() );
Jan Möbius's avatar
Jan Möbius committed
639

Jan Möbius's avatar
 
Jan Möbius committed
640
641
    // Remember old size
    originalLoggerSize_  = wsizes[1];
Jan Möbius's avatar
Jan Möbius committed
642

643
644
645
    int height = logWidget_->height ();

    splitter_->insertWidget (1, tempLogWidget);
Jan Möbius's avatar
 
Jan Möbius committed
646
647
648
    wsizes[0] = wsizes[0]+wsizes[1];
    wsizes[1] = 0;
    splitter_->setSizes(wsizes);
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
    logWidget_->resize (logWidget_->width (), height);
    slidingLogger_->attachWidget (logWidget_);

  } else if (splitter_->widget (1) == logWidget_) {

    if ( originalLoggerSize_ == 0)
        originalLoggerSize_ = 240;

    QList<int> wsizes( splitter_->sizes() );

    if (wsizes[0] == 0)
      wsizes[0] = height();

    wsizes[0] = wsizes[0]+wsizes[1] - originalLoggerSize_;
    wsizes[1] = originalLoggerSize_;
    splitter_->setSizes(wsizes);
Jan Möbius's avatar
 
Jan Möbius committed
665
  } else {
Jan Möbius's avatar
Jan Möbius committed
666

667
668
669
670
671
672
673
674
675
676
    QList<int> wsizes( splitter_->sizes() );

    int height = logWidget_->height ();

    slidingLogger_->detachWidget ();
    splitter_->insertWidget (1, logWidget_);

    wsizes[0] = wsizes[0]+wsizes[1] - height;
    wsizes[1] = height;
    splitter_->setSizes(wsizes);
Jan Möbius's avatar
 
Jan Möbius committed
677
  }
Jan Möbius's avatar
Jan Möbius committed
678
  */
Jan Möbius's avatar
 
Jan Möbius committed
679
680
681
682
683
684
685
686
}

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

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

Jan Möbius's avatar
 
Jan Möbius committed
688
  //toggle
689
690
691
692
693
694
695
696
697
698
699
700
  showToolbox( OpenFlipper::Options::hideToolbox() );
}

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

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

  //toggle
  OpenFlipper::Options::hideToolbox( !_state );
Jan Möbius's avatar
 
Jan Möbius committed
701

Jan Möbius's avatar
Jan Möbius committed
702
  if ( OpenFlipper::Options::hideToolbox() ){
Jan Möbius's avatar
 
Jan Möbius committed
703
704

    //hide ViewMode Selection Widget
Jan Möbius's avatar
Dennis:    
Jan Möbius committed
705
    toolBoxArea_->setVisible(false);
Jan Möbius's avatar
 
Jan Möbius committed
706
707
708
709
710
711
712

  }else{
    //reset last ViewMode
    if (OpenFlipper::Options::defaultToolboxMode().trimmed() == "")
      setViewMode("All");
    else
      setViewMode( OpenFlipper::Options::defaultToolboxMode() );
Jan Möbius's avatar
Dennis:    
Jan Möbius committed
713
    toolBoxArea_->setVisible(true);
Jan Möbius's avatar
 
Jan Möbius committed
714
715
  }
}
Jan Möbius's avatar
Jan Möbius committed
716

Jan Möbius's avatar
 
Jan Möbius committed
717
718
//=============================================================================

Jan Möbius's avatar
Jan Möbius committed
719
720
void
CoreWidget::addRecent(QString _filename, DataType _type)
Jan Möbius's avatar
 
Jan Möbius committed
721
{
722
723
  //dont add objects to recentMenu while loadind Settings
  if ( OpenFlipper::Options::loadingSettings() ) return;
Jan Möbius's avatar
Jan Möbius committed
724

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

Jan Möbius's avatar
 
Jan Möbius committed
727
  updateRecent();
Jan Möbius's avatar
Jan Möbius committed
728
729
730
731
732
733
734

}

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

void
CoreWidget::updateRecent()
Jan Möbius's avatar
 
Jan Möbius committed
735
736
737
{
  if ( recentFilesMenu_ == NULL)
    return;
Jan Möbius's avatar
Jan Möbius committed
738

Jan Möbius's avatar
 
Jan Möbius committed
739
740
741
742
743
  recentFilesMenu_->clear();

  QVector< OpenFlipper::Options::RecentFile > recentFiles = OpenFlipper::Options::recentFiles();
  for (int i = 0 ; i < recentFiles.size() ; ++i ) {
    QString path = OpenFlipper::Options::iconDirStr() + OpenFlipper::Options::dirSeparator();
744
745
746
747
748
749
750
    
    QFileInfo fi(recentFiles[i].filename); 

    if (fi.suffix() == "ini")
      path += "Settings-Icon.png";
    else
      path += typeIcon( recentFiles[i].type );
751

Jan Möbius's avatar
Jan Möbius committed
752
    recentFilesMenu_->addAction(QIcon(path), recentFiles[i].filename);
Jan Möbius's avatar
 
Jan Möbius committed
753
754
  }

Jan Möbius's avatar
Jan Möbius committed
755
756
757
}

void
Jan Möbius's avatar
 
Jan Möbius committed
758
759
760
CoreWidget::closeEvent ( QCloseEvent * /* event */ ) {
  emit exit();
}
761
762

void CoreWidget::showOptionsWidget() {
Jan Möbius's avatar
Jan Möbius committed
763

764
765
  if ( OpenFlipper::Options::nogui() )
    return;
Jan Möbius's avatar
Jan Möbius committed
766

767
  if ( optionsWidget_ == 0 ) {
Dirk Wilden's avatar
Dirk Wilden committed
768
    optionsWidget_ = new OptionsWidget(plugins_, coreKeys_, invKeys_, 0);
769
    connect(optionsWidget_,SIGNAL(applyOptions()),this,SIGNAL(applyOptions()));
Dirk Wilden's avatar
Dirk Wilden committed
770
    connect(optionsWidget_,SIGNAL(saveOptions()),this,SIGNAL(saveOptions()));
Dirk Wilden's avatar
Dirk Wilden committed
771
772
    connect(optionsWidget_,SIGNAL(addKeyMapping(int,Qt::KeyboardModifiers,QObject*,int)),
            this,          SLOT(slotAddKeyMapping(int,Qt::KeyboardModifiers,QObject*,int)));
773
774

    optionsWidget_->setWindowIcon( OpenFlipper::Options::OpenFlipperIcon() );
775
  }
Dirk Wilden's avatar
Dirk Wilden committed
776

Jan Möbius's avatar
Jan Möbius committed
777
  //show the optionsWidget centered
Dirk Wilden's avatar
Dirk Wilden committed
778
  QPoint center;
Jan Möbius's avatar
Jan Möbius committed
779
  center.setX( x() + width() / 2 );
Dirk Wilden's avatar
Dirk Wilden committed
780
781
  center.setY( y() + height() / 2 );

Dirk Wilden's avatar
Dirk Wilden committed
782
783
  optionsWidget_->setGeometry(center.x() - optionsWidget_->width() / 2,
                              center.y() - optionsWidget_->height()/ 2, optionsWidget_->width(), optionsWidget_->height());
Dirk Wilden's avatar
Dirk Wilden committed
784

785
  optionsWidget_->show();
Jan Möbius's avatar
Jan Möbius committed
786

787
}
Jan Möbius's avatar
Jan Möbius committed
788

789
790
791
void CoreWidget::nextViewMode() {

	if (OpenFlipper::Options::multiView()) {
Jan Möbius's avatar
Jan Möbius committed
792
		emit log(tr("Switch MultiView mode"));
793
794
795

		switch (baseLayout_->mode()) {
		case QtMultiViewLayout::SingleView:
796
                        baseLayout_->setPrimary (PluginFunctions::activeExaminer ());
797
			baseLayout_->setMode(QtMultiViewLayout::Grid);
798
799
800

			// Update combo box in the toolbar
			viewmodeBox_->setCurrentIndex(1);
801
802
			break;
		case QtMultiViewLayout::Grid:
803
                        baseLayout_->setPrimary (PluginFunctions::activeExaminer ());
804
			baseLayout_->setMode(QtMultiViewLayout::HSplit);
805
806
807

			// Update combo box in the toolbar
			viewmodeBox_->setCurrentIndex(2);
808
809
			break;
		case QtMultiViewLayout::HSplit:
810
                        baseLayout_->setPrimary (PluginFunctions::activeExaminer ());
811
			baseLayout_->setMode(QtMultiViewLayout::SingleView);
812
813
814

			// Update combo box in the toolbar
			viewmodeBox_->setCurrentIndex(0);
815
816
817
818
819
820
821
822
823
824
			break;
		}
	}
}


void
CoreWidget::setViewMode(int _idx) {

	if (OpenFlipper::Options::multiView()) {
Jan Möbius's avatar
Jan Möbius committed
825
		emit log(tr("Switch MultiView mode"));
826
827
828

		switch (_idx) {
		case 0:
829
                        baseLayout_->setPrimary (PluginFunctions::activeExaminer ());
830
831
832
			baseLayout_->setMode(QtMultiViewLayout::SingleView);
			break;
		case 1:
833
                        baseLayout_->setPrimary (PluginFunctions::activeExaminer ());
834
835
836
			baseLayout_->setMode(QtMultiViewLayout::Grid);
			break;
		case 2:
837
                        baseLayout_->setPrimary (PluginFunctions::activeExaminer ());
838
839
840
841
842
			baseLayout_->setMode(QtMultiViewLayout::HSplit);
			break;
		}
	}
}
Jan Möbius's avatar
 
Jan Möbius committed
843

844
845
846
847
848
849
850
851
852
853
854
855
856
857
void
CoreWidget::slotShowSceneGraphDialog()
{
  if ( PluginFunctions::getSceneGraphRootNode() )
  {
    if (!sceneGraphDialog_)
    {
      sceneGraphDialog_ = new ACG::QtWidgets::QtSceneGraphDialog( this, PluginFunctions::getSceneGraphRootNode() );

      for ( unsigned int i = 0 ; i < OpenFlipper::Options::examinerWidgets() ; ++i ) {
        connect(examiner_widgets_[i], SIGNAL(signalSceneGraphChanged(ACG::SceneGraph::BaseNode*)),
                sceneGraphDialog_,    SLOT(update(ACG::SceneGraph::BaseNode*)));

        connect(sceneGraphDialog_, SIGNAL(signalNodeChanged(ACG::SceneGraph::BaseNode*)),
858
                examiner_widgets_[i], SLOT(updateGL()));
859
860
861
862
863
864
865
866
      }

    }

    sceneGraphDialog_->show();
  }
}

Jan Möbius's avatar
   
Jan Möbius committed
867
868
869
870
871
872
//-----------------------------------------------------------------------------

void
CoreWidget::sceneRectChanged(const QRectF &rect)
{
  centerWidget_->setGeometry (rect);
873
  slidingLogger_->updateGeometry ();
Jan Möbius's avatar
Dennis:    
Jan Möbius committed
874
  pickToolbar_->updateGeometry ();
Jan Möbius's avatar
   
Jan Möbius committed
875
876
}

Dirk Wilden's avatar
Dirk Wilden committed
877
878
879
880
881
882
//-----------------------------------------------------------------------------

void
CoreWidget::startVideoCaptureDialog(){

  VideoCaptureDialog* dialog = new VideoCaptureDialog();
883
  dialog->setModal(false);
Dirk Wilden's avatar
Dirk Wilden committed
884
885

  connect(dialog, SIGNAL(startVideoCapture(QString,int,bool)), this, SIGNAL(startVideoCapture(QString,int,bool)) );
886
887
888
  connect(dialog, SIGNAL(resizeViewers(int,int)), this, SIGNAL(resizeViewers(int,int)) );
  connect(dialog, SIGNAL(resizeApplication(int,int)), this, SIGNAL(resizeApplication(int,int)) );

Dirk Wilden's avatar
Dirk Wilden committed
889
890
  dialog->show();
}
Jan Möbius's avatar
   
Jan Möbius committed
891

892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
//-----------------------------------------------------------------------------

void CoreWidget::slotActivateExaminer()
{
  glViewer* examiner = dynamic_cast<glViewer*>(QObject::sender());

  if (!examiner)
    return;

  for ( uint i = 0 ; i < OpenFlipper::Options::examinerWidgets() ; ++i ) {

    if (examiner == examiner_widgets_[i])
    {
      PluginFunctions::setActiveExaminer (i);
      break;
    }
  }
}
910
911


Jan Möbius's avatar
 
Jan Möbius committed
912
//=============================================================================
913