CoreWidget.cc 24.7 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
55
56
57

#define WIDGET_HEIGHT 800
#define WIDGET_WIDTH  800

Jan Möbius's avatar
Jan Möbius committed
58
//== IMPLEMENTATION ==========================================================
Jan Möbius's avatar
 
Jan Möbius committed
59

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

Jan Möbius's avatar
Dennis:    
Jan Möbius committed
113
114
115
116
117
  toolSplitter_ = new QSplitter(Qt::Horizontal,this);

  setCentralWidget(toolSplitter_);

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

120
121
  QGLFormat format = QGLFormat::defaultFormat();

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

  // Construct GL context & widget
133
134
135
  baseLayout_ = new QtMultiViewLayout;
  baseLayout_->setContentsMargins(0,0,0,0);

136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
  // ===============================================================================
  // 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);


Jan Möbius's avatar
   
Jan Möbius committed
155
  glView_ = new QtGLGraphicsView(stackedWidget_);
156
  glScene_ = new QtGLGraphicsScene (&examiner_widgets_, baseLayout_);
Jan Möbius's avatar
   
Jan Möbius committed
157

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

Jan Möbius's avatar
   
Jan Möbius committed
161
162
163
164
  glView_->setViewport(glWidget_);
  glView_->setViewportUpdateMode(QGraphicsView::FullViewportUpdate);
  glView_->setScene(glScene_);

165

166

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

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

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

190
  originalLoggerSize_ = 0;
Jan Möbius's avatar
Jan Möbius committed
191
  loggerState_ = OpenFlipper::Options::Normal;
192

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

Jan Möbius's avatar
Jan Möbius committed
195
  if (OpenFlipper::Options::loggerState() == OpenFlipper::Options::InScene) {
196
197
    slidingLogger_->attachWidget (logWidget_);
    splitter_->insertWidget (1, tempLogWidget);
198
    wsizes[0] = 1;
Jan Möbius's avatar
 
Jan Möbius committed
199
200
    wsizes[1] = 0;
    splitter_->setSizes(wsizes);
Jan Möbius's avatar
Jan Möbius committed
201
    loggerState_ = OpenFlipper::Options::InScene;
202
    baseLayout_->setContentsMargins (0, 0, 0, 16);
Jan Möbius's avatar
Jan Möbius committed
203
204
205
206
207
208
209
210
211
212
213
  } 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
214
  }
Jan Möbius's avatar
Jan Möbius committed
215

216

Jan Möbius's avatar
 
Jan Möbius committed
217
218
219
  // ======================================================================
  // Create examiner
  // ======================================================================
Jan Möbius's avatar
Jan Möbius committed
220
221
222

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

Jan Möbius's avatar
   
Jan Möbius committed
223
224
    glViewer* examinerWidget = new glViewer(glScene_,
					    glWidget_,
225
                                            PluginFunctions::viewerProperties(0),
Jan Möbius's avatar
   
Jan Möbius committed
226
227
228
					    centerWidget_,
                                            "Examiner Widget",
                                            statusBar_);
Jan Möbius's avatar
Jan Möbius committed
229

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

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

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

  } else {


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

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

      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
259
260
261
262
263
264
265
    }

    // 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
266
267
268
269
    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
270
271
  }

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

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


Jan Möbius's avatar
 
Jan Möbius committed
278
279
280
  // ======================================================================
  // Setup dragging for examiner widget
  // ======================================================================
281
282
283
284
285
286
287
288
  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* )));
Jan Möbius's avatar
Jan Möbius committed
289
290
291
  }


Jan Möbius's avatar
 
Jan Möbius committed
292
293
294
  // ======================================================================
  // Create main Toolbar
  // ======================================================================
Jan Möbius's avatar
Jan Möbius committed
295

Jan Möbius's avatar
 
Jan Möbius committed
296
  mainToolbar_ = new QToolBar("Main Toolbar");
297
  mainToolbar_->setWindowTitle("Main Toolbar");
Dirk Wilden's avatar
Dirk Wilden committed
298
  mainToolbar_->setObjectName("MainToolbar");
299
  slotAddToolbar(mainToolbar_);
Jan Möbius's avatar
Jan Möbius committed
300

Jan Möbius's avatar
 
Jan Möbius committed
301
302
303
  // ======================================================================
  // Get Toolbar from examiner and integrate it into main window
  // ======================================================================
Jan Möbius's avatar
Jan Möbius committed
304

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

306
307
308
  // Create the toolbar
  viewerToolbar_ = new QToolBar( "Viewer Toolbar", this );
  viewerToolbar_->setOrientation(Qt::Vertical);
Jan Möbius's avatar
 
Jan Möbius committed
309
310
  viewerToolbar_->setAllowedAreas(Qt::AllToolBarAreas);
  viewerToolbar_->setIconSize(QSize(20,20));
Dirk Wilden's avatar
Dirk Wilden committed
311
  viewerToolbar_->setObjectName("ViewerToolbar");
Jan Möbius's avatar
Jan Möbius committed
312

313
314
315
316
317
318
319
320
321
322
  moveButton_ = new QToolButton( viewerToolbar_ );
  moveButton_->setIcon( QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"transform-move.png") );
  moveButton_->setMinimumSize( 16, 16 );
  moveButton_->setMaximumSize( 32, 32 );
  moveButton_->setToolTip( "Switch to <b>move</b> mode." );
  moveButton_->setWhatsThis(
                  "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>"
                  "<li><b>Zoom</b> using <b>left+middle</b> mouse buttons.</li></ul>" );
323
324

  connect( moveButton_,SIGNAL( clicked() ), this, SLOT( setExamineMode() ) );
325
/*
326
  connect( this, SIGNAL( actionModeChanged( Viewer::ActionMode ) ),
327
            this, SLOT(   slotActionModeChanged(Viewer::ActionMode) ) );*/
328

329
330
331
332
333
334
335
336
337
338
339
340
  viewerToolbar_->addWidget( moveButton_ )->setText("Move");
  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 );
  lightButton_->setToolTip("Switch to <b>light</b> mode.");
  lightButton_->setWhatsThis(
                  "Switch to <b>light</b> mode.<br>"
                  "Rotate lights using left mouse button.");
341
342

  connect( lightButton_,SIGNAL( clicked() ), this, SLOT( setLightMode() ) );
343
344
345
346
347
348
349
350
351
352
353
354
355
  viewerToolbar_->addWidget( lightButton_)->setText("Light");


  pickButton_ = new QToolButton( viewerToolbar_ );
  pickButton_->setIcon( QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"pick.png") );
  pickButton_->setMinimumSize( 16, 16 );
  pickButton_->setMaximumSize( 32, 32 );
  pickButton_->setToolTip("Switch to <b>picking</b> mode.");
  pickButton_->setWhatsThis(
                  "Switch to <b>picking</b> mode.<br>"
                  "Use picking functions like flipping edges.<br>"
                  "To change the mode use the right click<br>"
                  "context menu in the viewer.");
356
  connect( pickButton_,SIGNAL( clicked() ), this, SLOT( setPickingMode() ) );
357
358
359
360
361
362
363
364
365
366
367
368
369
370
  viewerToolbar_->addWidget( pickButton_)->setText("Pick");


  questionButton_ = new QToolButton( viewerToolbar_ );
  questionButton_->setIcon( QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"help-about.png") );
  questionButton_->setMinimumSize( 16, 16 );
  questionButton_->setMaximumSize( 32, 32 );
  questionButton_->setToolTip("Switch to <b>identification</b> mode.");
  questionButton_->setWhatsThis(
                  "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 "
                  "object.");
371
  connect( questionButton_,SIGNAL( clicked() ), this, SLOT( setQuestionMode() ) );
372
  viewerToolbar_->addWidget( questionButton_)->setText("Question");
373

374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
  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 );
    stereoButton_->setToolTip( "Toggle stereo viewing");
    stereoButton_->setWhatsThis(
                  "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 "
                  "display/projection system.");
    connect( stereoButton_,SIGNAL( clicked() ), this , SLOT( slotToggleStereoMode() ) );
    viewerToolbar_->addWidget( stereoButton_ )->setText( "Stereo");
  }
393
394


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

Jan Möbius's avatar
 
Jan Möbius committed
397
398
399
  // Remember logger size
  wsizes = splitter_->sizes();
  originalLoggerSize_  = wsizes[1];
Jan Möbius's avatar
Jan Möbius committed
400

Jan Möbius's avatar
 
Jan Möbius committed
401
  // ======================================================================
Jan Möbius's avatar
Dennis:    
Jan Möbius committed
402
  // Create ToolBox area
Jan Möbius's avatar
Jan Möbius committed
403
  // ======================================================================
Jan Möbius's avatar
Dennis:    
Jan Möbius committed
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434

  toolBoxArea_ = new QWidget (toolSplitter_);

  QGroupBox *gb = new QGroupBox ("ViewMode");

  QHBoxLayout *hLayout = new QHBoxLayout;

  QPushButton* vmButton = new QPushButton("Change View Mode");
  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
Jan Möbius committed
435

Jan Möbius's avatar
 
Jan Möbius committed
436
437
438
  // ======================================================================
  // Context menu setup
  // ======================================================================
Jan Möbius's avatar
Jan Möbius committed
439

Jan Möbius's avatar
Jan Möbius committed
440
441
442
443
  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
444

Dirk Wilden's avatar
   
Dirk Wilden committed
445
  contextMenu_ = new QMenu(this);
Jan Möbius's avatar
 
Jan Möbius committed
446
  contextSelectionMenu_ = new QMenu("Selection",0);
Jan Möbius's avatar
Jan Möbius committed
447

Jan Möbius's avatar
 
Jan Möbius committed
448
  setupMenuBar();
Jan Möbius's avatar
Jan Möbius committed
449

Jan Möbius's avatar
 
Jan Möbius committed
450
  updateRecent();
Jan Möbius's avatar
Jan Möbius committed
451

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

454
  registerCoreKeys();
Dirk Wilden's avatar
Dirk Wilden committed
455

456
  setExamineMode();
457
458
459

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

Jan Möbius's avatar
 
Jan Möbius committed
460
461
462
463
464
465
466
}


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


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

Jan Möbius's avatar
 
Jan Möbius committed
468
469
470
471
472
473
474
475
}

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

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

477
478
479
480
  setWindowState( windowState() ^  Qt::WindowFullScreen);

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

Jan Möbius's avatar
 
Jan Möbius committed
481
482
483
484
485
  show();
}

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

486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
/** 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
504
505
506
507
/** Hide or show logger
  */
void
CoreWidget::toggleLogger() {
Jan Möbius's avatar
Jan Möbius committed
508
509
510
511
512
513
514
515
516
517
518
519
520

  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
521

522
  // Hide/Show Logger
Jan Möbius's avatar
Jan Möbius committed
523
  showLogger( OpenFlipper::Options::loggerState() );
524
525
526
527
528
}

/** Hide or show logger
  */
void
Jan Möbius's avatar
Jan Möbius committed
529
CoreWidget::showLogger(OpenFlipper::Options::LoggerState _state) {
Jan Möbius's avatar
 
Jan Möbius committed
530
  //Hide Logger
Jan Möbius's avatar
Jan Möbius committed
531
532
533
  if (_state == loggerState_)
    return;

534
535
536
  qreal left, top, right, bottom;
  baseLayout_->getContentsMargins (&left, &top, &right, &bottom);

Jan Möbius's avatar
Jan Möbius committed
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
  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_);
556
        baseLayout_->setContentsMargins (left, top, right, 16);
Jan Möbius's avatar
Jan Möbius committed
557
558
559
560
561
562
563
564
565
566
567
568
569
570
      }
      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_);
571
        logWidget_->show ();
Jan Möbius's avatar
Jan Möbius committed
572
573
574
575

        wsizes[0] = wsizes[0]+wsizes[1] - originalLoggerSize_;
        wsizes[1] = originalLoggerSize_;
        splitter_->setSizes(wsizes);
576
        baseLayout_->setContentsMargins (left, top, right, 0);
Jan Möbius's avatar
Jan Möbius committed
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
      }
      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);
597
        baseLayout_->setContentsMargins (left, top, right, 0);
Jan Möbius's avatar
Jan Möbius committed
598
599
600
601
602
603
      }
      break;
  }
  loggerState_ = _state;

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

Jan Möbius's avatar
 
Jan Möbius committed
607
608
    // Remember old size
    originalLoggerSize_  = wsizes[1];
Jan Möbius's avatar
Jan Möbius committed
609

610
611
612
    int height = logWidget_->height ();

    splitter_->insertWidget (1, tempLogWidget);
Jan Möbius's avatar
 
Jan Möbius committed
613
614
615
    wsizes[0] = wsizes[0]+wsizes[1];
    wsizes[1] = 0;
    splitter_->setSizes(wsizes);
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
    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
632
  } else {
Jan Möbius's avatar
Jan Möbius committed
633

634
635
636
637
638
639
640
641
642
643
    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
644
  }
Jan Möbius's avatar
Jan Möbius committed
645
  */
Jan Möbius's avatar
 
Jan Möbius committed
646
647
648
649
650
651
652
653
}

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

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

Jan Möbius's avatar
 
Jan Möbius committed
655
  //toggle
656
657
658
659
660
661
662
663
664
665
666
667
  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
668

Jan Möbius's avatar
Jan Möbius committed
669
  if ( OpenFlipper::Options::hideToolbox() ){
Jan Möbius's avatar
 
Jan Möbius committed
670
671

    //hide ViewMode Selection Widget
Jan Möbius's avatar
Dennis:    
Jan Möbius committed
672
    toolBoxArea_->setVisible(false);
Jan Möbius's avatar
 
Jan Möbius committed
673
674
675
676
677
678
679

  }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
680
    toolBoxArea_->setVisible(true);
Jan Möbius's avatar
 
Jan Möbius committed
681
682
  }
}
Jan Möbius's avatar
Jan Möbius committed
683

Jan Möbius's avatar
 
Jan Möbius committed
684
685
//=============================================================================

Jan Möbius's avatar
Jan Möbius committed
686
687
void
CoreWidget::addRecent(QString _filename, DataType _type)
Jan Möbius's avatar
 
Jan Möbius committed
688
{
689
690
  //dont add objects to recentMenu while loadind Settings
  if ( OpenFlipper::Options::loadingSettings() ) return;
Jan Möbius's avatar
Jan Möbius committed
691

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

Jan Möbius's avatar
 
Jan Möbius committed
694
  updateRecent();
Jan Möbius's avatar
Jan Möbius committed
695
696
697
698
699
700
701

}

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

void
CoreWidget::updateRecent()
Jan Möbius's avatar
 
Jan Möbius committed
702
703
704
{
  if ( recentFilesMenu_ == NULL)
    return;
Jan Möbius's avatar
Jan Möbius committed
705

Jan Möbius's avatar
 
Jan Möbius committed
706
707
708
709
710
  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();
711
712
    path += typeIcon( recentFiles[i].type );

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

Jan Möbius's avatar
Jan Möbius committed
716
717
718
}

void
Jan Möbius's avatar
 
Jan Möbius committed
719
720
721
CoreWidget::closeEvent ( QCloseEvent * /* event */ ) {
  emit exit();
}
722
723

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

725
726
  if ( OpenFlipper::Options::nogui() )
    return;
Jan Möbius's avatar
Jan Möbius committed
727

728
  if ( optionsWidget_ == 0 ) {
Dirk Wilden's avatar
Dirk Wilden committed
729
    optionsWidget_ = new OptionsWidget(plugins_, coreKeys_, invKeys_, 0);
730
    connect(optionsWidget_,SIGNAL(applyOptions()),this,SIGNAL(applyOptions()));
Dirk Wilden's avatar
Dirk Wilden committed
731
    connect(optionsWidget_,SIGNAL(saveOptions()),this,SIGNAL(saveOptions()));
Dirk Wilden's avatar
Dirk Wilden committed
732
733
    connect(optionsWidget_,SIGNAL(addKeyMapping(int,Qt::KeyboardModifiers,QObject*,int)),
            this,          SLOT(slotAddKeyMapping(int,Qt::KeyboardModifiers,QObject*,int)));
734
735

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

Jan Möbius's avatar
Jan Möbius committed
738
  //show the optionsWidget centered
Dirk Wilden's avatar
Dirk Wilden committed
739
  QPoint center;
Jan Möbius's avatar
Jan Möbius committed
740
  center.setX( x() + width() / 2 );
Dirk Wilden's avatar
Dirk Wilden committed
741
742
  center.setY( y() + height() / 2 );

Dirk Wilden's avatar
Dirk Wilden committed
743
744
  optionsWidget_->setGeometry(center.x() - optionsWidget_->width() / 2,
                              center.y() - optionsWidget_->height()/ 2, optionsWidget_->width(), optionsWidget_->height());
Dirk Wilden's avatar
Dirk Wilden committed
745

746
  optionsWidget_->show();
Jan Möbius's avatar
Jan Möbius committed
747

748
}
Jan Möbius's avatar
Jan Möbius committed
749

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

751
752
753
754
755
756
757
758
759
760
761
762
763
764
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*)),
765
                examiner_widgets_[i], SLOT(updateGL()));
766
767
768
769
770
771
772
773
      }

    }

    sceneGraphDialog_->show();
  }
}

Jan Möbius's avatar
   
Jan Möbius committed
774
775
776
777
778
779
//-----------------------------------------------------------------------------

void
CoreWidget::sceneRectChanged(const QRectF &rect)
{
  centerWidget_->setGeometry (rect);
780
  slidingLogger_->updateGeometry ();
Jan Möbius's avatar
   
Jan Möbius committed
781
782
783
}


784
785


Jan Möbius's avatar
 
Jan Möbius committed
786
//=============================================================================