CoreWidget.cc 23.5 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),
Jan Möbius's avatar
   
Jan Möbius committed
69
70
71
72
73
74
  viewModes_(_viewModes),
  dockViewMode_(0),
  viewModeButton_(0),
  viewModeMenu_(0),
  viewGroup_(0),
  splitter_(0),
75
  logWidget_(0),
Jan Möbius's avatar
   
Jan Möbius committed
76
77
  recentFilesMenu_(0),
  pluginsMenu_(0),
78
79
  helpMenu_(0),
  sceneGraphDialog_(0),
Jan Möbius's avatar
   
Jan Möbius committed
80
81
82
  fileMenu_(0),
  viewMenu_(0),
  fileMenuEnd_(0),
83
84
85
86
87
88
  stereoButton_(0),
  projectionButton_(0),
  moveButton_(0),
  lightButton_(0),
  pickButton_(0),
  questionButton_(0),
Jan Möbius's avatar
   
Jan Möbius committed
89
  contextMenu_(0),
90
  functionMenu_(0),
Jan Möbius's avatar
Jan Möbius committed
91
  contextSelectionMenu_(0),
Jan Möbius's avatar
   
Jan Möbius committed
92
93
94
95
  stackMenu_(0),
  stackedWidget_(0),
  helpBrowserDeveloper_(0),
  helpBrowserUser_(0),
Jan Möbius's avatar
Jan Möbius committed
96
  aboutWidget_(0),
97
  optionsWidget_(0),
98
99
  plugins_(_plugins),
  stereoActive_(false)
Jan Möbius's avatar
   
Jan Möbius committed
100
101
{
  setupStatusBar();
Jan Möbius's avatar
Jan Möbius committed
102

Jan Möbius's avatar
   
Jan Möbius committed
103
104
105
  splitter_ = new QSplitter(Qt::Vertical,this);
  setCentralWidget(splitter_);
  stackedWidget_ = new QStackedWidget(splitter_);
Jan Möbius's avatar
Jan Möbius committed
106

Jan Möbius's avatar
   
Jan Möbius committed
107
108
109
  // ======================================================================
  // Set up the logging window
  // ======================================================================
110
111
112
113
114
  logWidget_ = new LoggerWidget(splitter_);
  logWidget_->setReadOnly(true);
  logWidget_->setSizePolicy( QSizePolicy ( QSizePolicy::Preferred , QSizePolicy::Preferred ) );
  logWidget_->resize( splitter_->width() ,120);
  logWidget_->setLineWrapMode( QTextEdit::NoWrap );
Jan Möbius's avatar
Jan Möbius committed
115

116
117
  originalLoggerSize_ = 0;

Jan Möbius's avatar
   
Jan Möbius committed
118
119
120
121
122
  QList<int> wsizes( splitter_->sizes() );
  if (OpenFlipper::Options::hideLogger()) {
    wsizes[1] = 0;
    splitter_->setSizes(wsizes);
  }
Jan Möbius's avatar
Jan Möbius committed
123

Jan Möbius's avatar
   
Jan Möbius committed
124
125
126
127
128
129
  // ======================================================================
  // Create examiner
  // ======================================================================
  QGLFormat format;
  QGLFormat::setDefaultFormat(format);
  format.setStereo( OpenFlipper::Options::stereo() );
Jan Möbius's avatar
Jan Möbius committed
130
131
132
133
134

  QWidget* tmp = 0;

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

Jan Möbius's avatar
   
Jan Möbius committed
135
    glViewer* examinerWidget = new glViewer(stackedWidget_,
136
137
138
                                                    "Examiner Widget",
                                                    statusBar_ ,
                                                    &format);
Jan Möbius's avatar
Jan Möbius committed
139

Jan Möbius's avatar
Jan Möbius committed
140
141
142
    examiner_widgets_.push_back(examinerWidget);

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

Jan Möbius's avatar
Jan Möbius committed
144
    stackedWidget_->addWidget(examinerWidget);
Jan Möbius's avatar
Jan Möbius committed
145
146
147
148
149
150
151

  } else {

    // Create collector widget which holds all viewers
    tmp = new QWidget(stackedWidget_);

    // Create master examiner widget
Jan Möbius's avatar
   
Jan Möbius committed
152
    glViewer* examinerWidget = new glViewer(tmp,
Jan Möbius's avatar
   
Jan Möbius committed
153
154
155
                                                            "Examiner Widget",
                                                            statusBar_ ,
                                                            &format,
Jan Möbius's avatar
Jan Möbius committed
156
                                                            0);
157
    examiner_widgets_.push_back(examinerWidget);
Jan Möbius's avatar
Jan Möbius committed
158
159
160
161


    // Create all other examiners using the same gl context as the others
    for ( unsigned int i = 1 ; i < OpenFlipper::Options::examinerWidgets() ; ++i ) {
Jan Möbius's avatar
   
Jan Möbius committed
162
      glViewer* newWidget = new glViewer(tmp,
Jan Möbius's avatar
   
Jan Möbius committed
163
164
165
                                                         "Examiner Widget",
                                                         statusBar_ ,
                                                         &format,
Jan Möbius's avatar
Jan Möbius committed
166
                                                         examinerWidget);
Jan Möbius's avatar
Jan Möbius committed
167
168
169
170
171
172
173
174
175
176
177
178
179
180
      examiner_widgets_.push_back(newWidget);
    }

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

    QGridLayout* layout = new QGridLayout(tmp);
    layout->addWidget(examiner_widgets_[0],0,0);
    layout->addWidget(examiner_widgets_[1],0,1);
    layout->addWidget(examiner_widgets_[2],1,0);
    layout->addWidget(examiner_widgets_[3],1,1);

181
182
    for ( unsigned int i = 1 ; i < OpenFlipper::Options::examinerWidgets() ; ++i )
      examiner_widgets_[i]->hide();
Jan Möbius's avatar
Jan Möbius committed
183

184
    stackedWidget_->addWidget(tmp);
Jan Möbius's avatar
Jan Möbius committed
185
186
  }

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

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

191
192


Jan Möbius's avatar
   
Jan Möbius committed
193
194
195
  // ======================================================================
  // Setup dragging for examiner widget
  // ======================================================================
196
197
198
199
200
201
202
203
  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
204
205
206
  }


Jan Möbius's avatar
   
Jan Möbius committed
207
208
209
  // ======================================================================
  // Create main Toolbar
  // ======================================================================
Jan Möbius's avatar
Jan Möbius committed
210

Jan Möbius's avatar
   
Jan Möbius committed
211
  mainToolbar_ = new QToolBar("Main Toolbar");
212
  mainToolbar_->setWindowTitle("Main Toolbar");
Dirk Wilden's avatar
Dirk Wilden committed
213
  mainToolbar_->setObjectName("MainToolbar");
214
  slotAddToolbar(mainToolbar_);
Jan Möbius's avatar
Jan Möbius committed
215

Jan Möbius's avatar
   
Jan Möbius committed
216
217
218
  // ======================================================================
  // Get Toolbar from examiner and integrate it into main window
  // ======================================================================
Jan Möbius's avatar
Jan Möbius committed
219

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

221
222
223
  // Create the toolbar
  viewerToolbar_ = new QToolBar( "Viewer Toolbar", this );
  viewerToolbar_->setOrientation(Qt::Vertical);
Jan Möbius's avatar
   
Jan Möbius committed
224
225
  viewerToolbar_->setAllowedAreas(Qt::AllToolBarAreas);
  viewerToolbar_->setIconSize(QSize(20,20));
Dirk Wilden's avatar
Dirk Wilden committed
226
  viewerToolbar_->setObjectName("ViewerToolbar");
Jan Möbius's avatar
Jan Möbius committed
227

228
229
230
231
232
233
234
235
236
237
238
  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>" );
  for ( unsigned int i = 0 ; i < OpenFlipper::Options::examinerWidgets() ; ++i ) {
Jan Möbius's avatar
   
Jan Möbius committed
239
    connect( moveButton_,SIGNAL( clicked() ), &PluginFunctions::viewerProperties(i), SLOT( setExamineMode() ) );
Jan Möbius's avatar
Jan Möbius committed
240
    connect( &PluginFunctions::viewerProperties(i) , SIGNAL( actionModeChanged( Viewer::ActionMode ) ),
Jan Möbius's avatar
Jan Möbius committed
241
             this                                  , SLOT(   slotActionModeChanged(Viewer::ActionMode) ) );
242
  }
243

244
245
246
247
248
249
250
251
252
253
254
255
256
  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.");
  for ( unsigned int i = 0 ; i < OpenFlipper::Options::examinerWidgets() ; ++i )
Jan Möbius's avatar
   
Jan Möbius committed
257
        connect( lightButton_,SIGNAL( clicked() ), &PluginFunctions::viewerProperties(i), SLOT( setLightMode() ) );
258
259
260
261
262
263
264
265
266
267
268
269
270
271
  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.");
  for ( unsigned int i = 0 ; i < OpenFlipper::Options::examinerWidgets() ; ++i )
Jan Möbius's avatar
   
Jan Möbius committed
272
    connect( pickButton_,SIGNAL( clicked() ), &PluginFunctions::viewerProperties(i), SLOT( setPickingMode() ) );
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
  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.");
  for ( unsigned int i = 0 ; i < OpenFlipper::Options::examinerWidgets() ; ++i )
Jan Möbius's avatar
   
Jan Möbius committed
288
    connect( questionButton_,SIGNAL( clicked() ), &PluginFunctions::viewerProperties(i), SLOT( setQuestionMode() ) );
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
  viewerToolbar_->addWidget( questionButton_)->setText("Question");

  viewerToolbar_->addSeparator();

  QToolButton* homeButton = new QToolButton( viewerToolbar_ );
  homeButton->setIcon( QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"go-home.png") );
  homeButton->setMinimumSize( 16, 16 );
  homeButton->setMaximumSize( 32, 32 );
  homeButton->setCheckable( false );
  homeButton->setToolTip("Restore <b>home</b> view.");
  homeButton->setWhatsThis(
                  "Restore home view<br><br>"
                  "Resets the view to the home view");
  for ( unsigned int i = 0 ; i < OpenFlipper::Options::examinerWidgets() ; ++i )
    connect( homeButton,SIGNAL( clicked() ), examiner_widgets_[i], SLOT( home() ) );
  viewerToolbar_->addWidget( homeButton)->setText("Home");


  QToolButton* setHomeButton = new QToolButton( viewerToolbar_ );
  setHomeButton->setIcon( QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"set-home.png") );
  setHomeButton->setMinimumSize( 16, 16 );
  setHomeButton->setMaximumSize( 32, 32 );
  setHomeButton->setCheckable( false );
  setHomeButton->setToolTip("Set <b>home</b> view");
  setHomeButton->setWhatsThis(
                  "Store home view<br><br>"
                  "Stores the current view as the home view");
  for ( unsigned int i = 0 ; i < OpenFlipper::Options::examinerWidgets() ; ++i )
    connect( setHomeButton,SIGNAL( clicked() ), examiner_widgets_[i], SLOT( setHome() ) );
  viewerToolbar_->addWidget( setHomeButton)->setText("Set Home");


  QToolButton* viewAllButton = new QToolButton( viewerToolbar_ );
  viewAllButton->setIcon( QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"viewall.png") );
  viewAllButton->setMinimumSize( 16, 16 );
  viewAllButton->setMaximumSize( 32, 32 );
  viewAllButton->setCheckable( false );
  viewAllButton->setToolTip("View all.");
  viewAllButton->setWhatsThis(
                  "View all<br><br>"
                  "Move the objects in the scene so that"
                  " the whole scene is visible.");
  for ( unsigned int i = 0 ; i < OpenFlipper::Options::examinerWidgets() ; ++i )
    connect( viewAllButton,SIGNAL( clicked() ), examiner_widgets_[i], SLOT( viewAll() ) );
  viewerToolbar_->addWidget( viewAllButton)->setText("View all");


  projectionButton_ = new QToolButton( viewerToolbar_ );
  projectionButton_->setIcon( QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"perspective.png") );
  projectionButton_->setMinimumSize( 16, 16 );
  projectionButton_->setMaximumSize( 32, 32 );
  projectionButton_->setCheckable( false );
  projectionButton_->setToolTip(
                "Switch between <b>perspective</b> and "
                "<b>parrallel</b> projection mode.");
  projectionButton_->setWhatsThis(
                "Switch projection modes<br><br>"
                "Switch between <b>perspective</b> and "
                "<b>parrallel</b> projection mode.");
  for ( unsigned int i = 0 ; i < OpenFlipper::Options::examinerWidgets() ; ++i ) {
    connect( projectionButton_,SIGNAL( clicked() ), examiner_widgets_[i], SLOT( toggleProjectionMode() ) );
    connect( examiner_widgets_[i],SIGNAL( projectionModeChanged( bool ) ), this , SLOT( slotProjectionModeChanged( bool ) ) );
  }
352
353


354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
  viewerToolbar_->addWidget( projectionButton_)->setText( "Projection" );


  viewerToolbar_->addSeparator();

  QToolButton* sceneGraphButton = new QToolButton( viewerToolbar_ );
  sceneGraphButton->setIcon( QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"scenegraph.png") );
  sceneGraphButton->setMinimumSize( 16, 16 );
  sceneGraphButton->setMaximumSize( 32, 32 );
  sceneGraphButton->setCheckable( false );
  sceneGraphButton->setToolTip("Toggle scene graph viewer.");
  sceneGraphButton->setWhatsThis(
                  "Toggle scene graph viewer<br><br>"
                  "The scene graph viewer enables you to examine the "
                  "displayed scene graph and to modify certain nodes.<br><br>"
                  "There are three modi for the scene graph viewer:"
                  "<ul><li><b>hidden</b></li>"
                  "<li><b>split</b>: share space</li>"
                  "<li><b>dialog</b>: own dialog window</li></ul>"
                  "This button toggles between these modi.");
  QObject::connect( sceneGraphButton, SIGNAL( clicked() ),
375
                    this, SLOT( slotShowSceneGraphDialog() ) );
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
  viewerToolbar_->addWidget( sceneGraphButton)->setText( "SceneGraph" );


  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");
  }
396
397


398
  addToolBar(Qt::TopToolBarArea,viewerToolbar_);
Jan Möbius's avatar
Jan Möbius committed
399
400


Jan Möbius's avatar
Jan Möbius committed
401
402
403
404
405
  if ( !OpenFlipper::Options::multiView() ) {
    stackWidgetList_.push_back( StackWidgetInfo( false, "3D Examiner Widget", examiner_widgets_[0] ) );
  } else {
    stackWidgetList_.push_back( StackWidgetInfo( false, "3D Examiner Widget", tmp ) );
  }
Jan Möbius's avatar
Jan Möbius committed
406

Jan Möbius's avatar
   
Jan Möbius committed
407
408
409
  // Remember logger size
  wsizes = splitter_->sizes();
  originalLoggerSize_  = wsizes[1];
Jan Möbius's avatar
Jan Möbius committed
410

Jan Möbius's avatar
   
Jan Möbius committed
411
412
  // ======================================================================
  // Create Upper DockWidget for ToolWidget control
Jan Möbius's avatar
Jan Möbius committed
413
  // ======================================================================
Jan Möbius's avatar
   
Jan Möbius committed
414
  dockViewMode_ = new QDockWidget("ViewMode" , this );
Dirk Wilden's avatar
Dirk Wilden committed
415
  dockViewMode_->setObjectName("DockViewMode");
Jan Möbius's avatar
   
Jan Möbius committed
416
417
418
419
420
421
422
423
  QPushButton* button = new QPushButton("Change View Mode");
  dockViewMode_->setWidget(button);
  button->setParent(dockViewMode_);
  dockViewMode_->setFeatures( QDockWidget::NoDockWidgetFeatures );
  button->show();
  addDockWidget(Qt::RightDockWidgetArea,dockViewMode_);
  connect(button, SIGNAL(clicked()), this, SLOT(slotViewModeDialog()));
  dockViewMode_->setVisible(false);
Jan Möbius's avatar
Jan Möbius committed
424

Jan Möbius's avatar
   
Jan Möbius committed
425
426
427
  // ======================================================================
  // Context menu setup
  // ======================================================================
Jan Möbius's avatar
Jan Möbius committed
428

Jan Möbius's avatar
Jan Möbius committed
429
430
431
432
  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
433

Dirk Wilden's avatar
   
Dirk Wilden committed
434
  contextMenu_ = new QMenu(this);
Jan Möbius's avatar
   
Jan Möbius committed
435
  contextSelectionMenu_ = new QMenu("Selection",0);
Jan Möbius's avatar
Jan Möbius committed
436

Jan Möbius's avatar
   
Jan Möbius committed
437
  setupMenuBar();
Jan Möbius's avatar
Jan Möbius committed
438

Jan Möbius's avatar
   
Jan Möbius committed
439
  updateRecent();
Jan Möbius's avatar
Jan Möbius committed
440

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

443
  registerCoreKeys();
Dirk Wilden's avatar
Dirk Wilden committed
444

Jan Möbius's avatar
   
Jan Möbius committed
445
446
447
448
449
450
451
}


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


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

Jan Möbius's avatar
   
Jan Möbius committed
453
454
455
456
457
458
459
460
}

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

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

462
463
464
465
  setWindowState( windowState() ^  Qt::WindowFullScreen);

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

Jan Möbius's avatar
   
Jan Möbius committed
466
467
468
469
470
  show();
}

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

471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
/** 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
489
490
491
492
493
494
/** Hide or show logger
  */
void
CoreWidget::toggleLogger() {
  // toggle
  OpenFlipper::Options::hideLogger( !OpenFlipper::Options::hideLogger() );
Jan Möbius's avatar
Jan Möbius committed
495

496
  // Hide/Show Logger
497
  showLogger( !OpenFlipper::Options::hideLogger() );
498
499
500
501
502
}

/** Hide or show logger
  */
void
503
CoreWidget::showLogger(bool _state) {
Jan Möbius's avatar
   
Jan Möbius committed
504
  //Hide Logger
505
  if ( !_state ) {
Jan Möbius's avatar
   
Jan Möbius committed
506
    QList<int> wsizes( splitter_->sizes() );
Jan Möbius's avatar
Jan Möbius committed
507

Jan Möbius's avatar
   
Jan Möbius committed
508
509
    // Remember old size
    originalLoggerSize_  = wsizes[1];
Jan Möbius's avatar
Jan Möbius committed
510

Jan Möbius's avatar
   
Jan Möbius committed
511
512
513
514
    wsizes[0] = wsizes[0]+wsizes[1];
    wsizes[1] = 0;
    splitter_->setSizes(wsizes);
  } else {
Jan Möbius's avatar
Jan Möbius committed
515
516

    if ( originalLoggerSize_ == 0)
Jan Möbius's avatar
   
Jan Möbius committed
517
        originalLoggerSize_ = 240;
Jan Möbius's avatar
Jan Möbius committed
518

Jan Möbius's avatar
   
Jan Möbius committed
519
    QList<int> wsizes( splitter_->sizes() );
520
521
522

    if (wsizes[0] == 0)
      wsizes[0] = height();
Jan Möbius's avatar
Jan Möbius committed
523

Jan Möbius's avatar
   
Jan Möbius committed
524
525
526
527
528
529
530
531
532
533
534
535
    wsizes[0] = wsizes[0]+wsizes[1] - originalLoggerSize_;
    wsizes[1] = originalLoggerSize_;
    splitter_->setSizes(wsizes);
  }
}

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

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

Jan Möbius's avatar
   
Jan Möbius committed
537
  //toggle
538
539
540
541
542
543
544
545
546
547
548
549
  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
550

Jan Möbius's avatar
Jan Möbius committed
551
  if ( OpenFlipper::Options::hideToolbox() ){
Jan Möbius's avatar
   
Jan Möbius committed
552
553
554
555
556
557
    //hide all toolWidgets
    for (uint p=0; p < plugins_.size(); p++)
      if (plugins_[p].widget)
        plugins_[p].widget->setVisible(false);

    //hide ViewMode Selection Widget
Jan Möbius's avatar
Jan Möbius committed
558
    dockViewMode_->setVisible(false);
Jan Möbius's avatar
   
Jan Möbius committed
559
560
561
562
563
564
565
566
567

  }else{
    //reset last ViewMode
    if (OpenFlipper::Options::defaultToolboxMode().trimmed() == "")
      setViewMode("All");
    else
      setViewMode( OpenFlipper::Options::defaultToolboxMode() );
  }
}
Jan Möbius's avatar
Jan Möbius committed
568

Jan Möbius's avatar
   
Jan Möbius committed
569
570
//=============================================================================

Jan Möbius's avatar
Jan Möbius committed
571
572
void
CoreWidget::addRecent(QString _filename, DataType _type)
Jan Möbius's avatar
   
Jan Möbius committed
573
{
574
575
  //dont add objects to recentMenu while loadind Settings
  if ( OpenFlipper::Options::loadingSettings() ) return;
Jan Möbius's avatar
Jan Möbius committed
576

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

Jan Möbius's avatar
   
Jan Möbius committed
579
  updateRecent();
Jan Möbius's avatar
Jan Möbius committed
580
581
582
583
584
585
586

}

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

void
CoreWidget::updateRecent()
Jan Möbius's avatar
   
Jan Möbius committed
587
588
589
{
  if ( recentFilesMenu_ == NULL)
    return;
Jan Möbius's avatar
Jan Möbius committed
590

Jan Möbius's avatar
   
Jan Möbius committed
591
592
593
594
595
  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();
596
597
    path += typeIcon( recentFiles[i].type );

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

Jan Möbius's avatar
Jan Möbius committed
601
602
603
}

void
Jan Möbius's avatar
   
Jan Möbius committed
604
605
606
CoreWidget::closeEvent ( QCloseEvent * /* event */ ) {
  emit exit();
}
607
608

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

610
611
  if ( OpenFlipper::Options::nogui() )
    return;
Jan Möbius's avatar
Jan Möbius committed
612

613
  if ( optionsWidget_ == 0 ) {
Dirk Wilden's avatar
Dirk Wilden committed
614
    optionsWidget_ = new OptionsWidget(plugins_, coreKeys_, invKeys_, 0);
615
    connect(optionsWidget_,SIGNAL(applyOptions()),this,SIGNAL(applyOptions()));
Dirk Wilden's avatar
Dirk Wilden committed
616
    connect(optionsWidget_,SIGNAL(saveOptions()),this,SIGNAL(saveOptions()));
Dirk Wilden's avatar
Dirk Wilden committed
617
618
    connect(optionsWidget_,SIGNAL(addKeyMapping(int,Qt::KeyboardModifiers,QObject*,int)),
            this,          SLOT(slotAddKeyMapping(int,Qt::KeyboardModifiers,QObject*,int)));
619
  }
Dirk Wilden's avatar
Dirk Wilden committed
620

Jan Möbius's avatar
Jan Möbius committed
621
  //show the optionsWidget centered
Dirk Wilden's avatar
Dirk Wilden committed
622
  QPoint center;
Jan Möbius's avatar
Jan Möbius committed
623
  center.setX( x() + width() / 2 );
Dirk Wilden's avatar
Dirk Wilden committed
624
625
  center.setY( y() + height() / 2 );

Dirk Wilden's avatar
Dirk Wilden committed
626
627
  optionsWidget_->setGeometry(center.x() - optionsWidget_->width() / 2,
                              center.y() - optionsWidget_->height()/ 2, optionsWidget_->width(), optionsWidget_->height());
Dirk Wilden's avatar
Dirk Wilden committed
628

629
  optionsWidget_->show();
Jan Möbius's avatar
Jan Möbius committed
630

631
}
Jan Möbius's avatar
Jan Möbius committed
632

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

634
635
636
637
638
639
640
641
642
643
644
645
646
647
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*)),
648
                examiner_widgets_[i], SLOT(updateGL()));
649
650
651
652
653
654
655
656
657
658
      }

    }

    sceneGraphDialog_->show();
  }
}



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