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

#define WIDGET_HEIGHT 800
#define WIDGET_WIDTH  800

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

Jan Möbius's avatar
Jan Möbius committed
59
60
/** \brief Constuctor for the Core Widget
 *
Jan Möbius's avatar
 
Jan Möbius committed
61
62
*/
CoreWidget::
Dirk Wilden's avatar
Dirk Wilden committed
63
CoreWidget( QVector<ViewMode*>& _viewModes,
Dirk Wilden's avatar
Dirk Wilden committed
64
65
            std::vector<PluginInfo>& _plugins,
            QList< SlotInfo >& _coreSlots ) :
Jan Möbius's avatar
 
Jan Möbius committed
66
  QMainWindow(),
Dirk Wilden's avatar
Dirk Wilden committed
67
  coreSlots_(_coreSlots),
Jan Möbius's avatar
 
Jan Möbius committed
68
69
70
71
72
73
  viewModes_(_viewModes),
  dockViewMode_(0),
  viewModeButton_(0),
  viewModeMenu_(0),
  viewGroup_(0),
  splitter_(0),
74
  logWidget_(0),
Jan Möbius's avatar
 
Jan Möbius committed
75
76
77
78
79
80
  recentFilesMenu_(0),
  pluginsMenu_(0),
  fileMenu_(0),
  viewMenu_(0),
  fileMenuEnd_(0),
  contextMenu_(0),
Jan Möbius's avatar
Jan Möbius committed
81
  contextSelectionMenu_(0),
Jan Möbius's avatar
 
Jan Möbius committed
82
83
84
85
  stackMenu_(0),
  stackedWidget_(0),
  helpBrowserDeveloper_(0),
  helpBrowserUser_(0),
Jan Möbius's avatar
Jan Möbius committed
86
  aboutWidget_(0),
87
  optionsWidget_(0),
Jan Möbius's avatar
 
Jan Möbius committed
88
  plugins_(_plugins)
Jan Möbius's avatar
Jan Möbius committed
89

Jan Möbius's avatar
 
Jan Möbius committed
90
91
{
  setupStatusBar();
Jan Möbius's avatar
Jan Möbius committed
92

Jan Möbius's avatar
 
Jan Möbius committed
93
94
95
  splitter_ = new QSplitter(Qt::Vertical,this);
  setCentralWidget(splitter_);
  stackedWidget_ = new QStackedWidget(splitter_);
Jan Möbius's avatar
Jan Möbius committed
96

Jan Möbius's avatar
 
Jan Möbius committed
97
98
99
  // ======================================================================
  // Set up the logging window
  // ======================================================================
100
101
102
103
104
  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
105

106
107
  originalLoggerSize_ = 0;

Jan Möbius's avatar
 
Jan Möbius committed
108
109
110
111
112
  QList<int> wsizes( splitter_->sizes() );
  if (OpenFlipper::Options::hideLogger()) {
    wsizes[1] = 0;
    splitter_->setSizes(wsizes);
  }
Jan Möbius's avatar
Jan Möbius committed
113

Jan Möbius's avatar
 
Jan Möbius committed
114
115
116
117
118
119
  // ======================================================================
  // Create examiner
  // ======================================================================
  QGLFormat format;
  QGLFormat::setDefaultFormat(format);
  format.setStereo( OpenFlipper::Options::stereo() );
Jan Möbius's avatar
Jan Möbius committed
120
121
122
123
124

  QWidget* tmp = 0;

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

Jan Möbius's avatar
Jan Möbius committed
125
126
127
128
    ACG::QtWidgets::QtExaminerViewer* examinerWidget = new ACG::QtWidgets::QtExaminerViewer(stackedWidget_,
                                                                                            "Examiner Widget",
                                                                                            statusBar_ ,
                                                                                            &format);
Jan Möbius's avatar
Jan Möbius committed
129

Jan Möbius's avatar
Jan Möbius committed
130
131
    examiner_widgets_.push_back(examinerWidget);

132
    examinerWidget->disableKeyHandling(true);
Jan Möbius's avatar
Jan Möbius committed
133
134
    examinerWidget->sceneGraph( PluginFunctions::getSceneGraphRootNode() );
    examinerWidget->enablePopupMenu(false);
Jan Möbius's avatar
Jan Möbius committed
135

Jan Möbius's avatar
Jan Möbius committed
136
    stackedWidget_->addWidget(examinerWidget);
Jan Möbius's avatar
Jan Möbius committed
137
138
139
140
141
142
143

  } else {

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

    // Create master examiner widget
144
145
146
147
148
149
150
    ACG::QtWidgets::QtExaminerViewer* examinerWidget = new ACG::QtWidgets::QtExaminerViewer(tmp,
                                                                                            "Examiner Widget",
                                                                                            statusBar_ ,
                                                                                            &format,
                                                                                            0,
                                                                                            ACG::QtWidgets::QtExaminerViewer::Nothing);
    examiner_widgets_.push_back(examinerWidget);
Jan Möbius's avatar
Jan Möbius committed
151
152
153
154
155
156
157
158


    // Create all other examiners using the same gl context as the others
    for ( unsigned int i = 1 ; i < OpenFlipper::Options::examinerWidgets() ; ++i ) {
      ACG::QtWidgets::QtExaminerViewer* newWidget = new ACG::QtWidgets::QtExaminerViewer(tmp,
                                                                                         "Examiner Widget",
                                                                                         statusBar_ ,
                                                                                         &format,
159
                                                                                         examinerWidget,
Jan Möbius's avatar
Jan Möbius committed
160
161
162
163
164
165
166
167
                                                                                         ACG::QtWidgets::QtExaminerViewer::Nothing);
      examiner_widgets_.push_back(newWidget);
    }

    // Initialize all examiners
    for ( unsigned int i = 0 ; i < OpenFlipper::Options::examinerWidgets() ; ++i ) {
      examiner_widgets_[i]->sceneGraph( PluginFunctions::getSceneGraphRootNode() );
      examiner_widgets_[i]->enablePopupMenu(false);
168
      examiner_widgets_[i]->disableKeyHandling(true);
Jan Möbius's avatar
Jan Möbius committed
169
170
171
172
173
174
175
176
    }

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

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

180
    stackedWidget_->addWidget(tmp);
Jan Möbius's avatar
Jan Möbius committed
181
182
  }

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

184
185


Jan Möbius's avatar
 
Jan Möbius committed
186
187
188
  // ======================================================================
  // Setup dragging for examiner widget
  // ======================================================================
189
190
191
192
193
194
195
196
197
  for ( uint i = 0 ; i < OpenFlipper::Options::examinerWidgets() ; ++i ) {
    examiner_widgets_[i]->setExternalDrag(true);

    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
198
199
200
  }


Jan Möbius's avatar
 
Jan Möbius committed
201
202
203
  // ======================================================================
  // Create main Toolbar
  // ======================================================================
Jan Möbius's avatar
Jan Möbius committed
204

Jan Möbius's avatar
 
Jan Möbius committed
205
  mainToolbar_ = new QToolBar("Main Toolbar");
206
  mainToolbar_->setWindowTitle("Main Toolbar");
Dirk Wilden's avatar
Dirk Wilden committed
207
  mainToolbar_->setObjectName("MainToolbar");
208
  slotAddToolbar(mainToolbar_);
Jan Möbius's avatar
Jan Möbius committed
209

Jan Möbius's avatar
 
Jan Möbius committed
210
211
212
  // ======================================================================
  // Get Toolbar from examiner and integrate it into main window
  // ======================================================================
Jan Möbius's avatar
Jan Möbius committed
213

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

Jan Möbius's avatar
 
Jan Möbius committed
215
  // Take control over the toolbar
Jan Möbius's avatar
Jan Möbius committed
216
217
218
219
220
221
  viewerToolbar_ = examiner_widgets_[0]->removeToolBar();

  for ( unsigned int i = 1 ; i < OpenFlipper::Options::examinerWidgets() ; ++i ) {
    examiner_widgets_[i]->removeToolBar();
  }

Jan Möbius's avatar
 
Jan Möbius committed
222
223
224
225
  addToolBar(Qt::TopToolBarArea,viewerToolbar_);
  viewerToolbar_->setParent(this);
  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

Jan Möbius's avatar
Jan Möbius committed
228
  // Set our own Icons and connect to additional examiner widgets
Jan Möbius's avatar
 
Jan Möbius committed
229
230
231
232
233
  QList<QAction *> actions = viewerToolbar_->actions();
  for ( int i = 0 ; i < actions.size(); ++i ) {
    if ( actions[i]->text() == "Move" ) {
      QIcon icon;
      icon.addFile(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"transform-move.png");
Jan Möbius's avatar
Jan Möbius committed
234

Jan Möbius's avatar
 
Jan Möbius committed
235
236
      QToolButton * button = qobject_cast<QToolButton *>( viewerToolbar_->widgetForAction ( actions[i] ) );
      button->setIcon(icon);
237
238
239
240
241

      // Connect action to all other widgets ( First widget provides the toolbar so dont connect twice!)
      for ( unsigned int i = 1 ; i < OpenFlipper::Options::examinerWidgets() ; ++i )
        connect( button,SIGNAL( clicked() ), examiner_widgets_[i], SLOT( examineMode() ) );

Jan Möbius's avatar
 
Jan Möbius committed
242
243
244
    } else if ( actions[i]->text() == "Home" ) {
      QIcon icon;
      icon.addFile(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"go-home.png");
Jan Möbius's avatar
Jan Möbius committed
245

Jan Möbius's avatar
 
Jan Möbius committed
246
247
      QToolButton * button = qobject_cast<QToolButton *>( viewerToolbar_->widgetForAction ( actions[i] ) );
      button->setIcon(icon);
248
249
250
251
252

      // Connect action to all other widgets ( First widget provides the toolbar so dont connect twice!)
      for ( unsigned int i = 1 ; i < OpenFlipper::Options::examinerWidgets() ; ++i )
        connect( button,SIGNAL( clicked() ), examiner_widgets_[i], SLOT( home() ) );

Jan Möbius's avatar
 
Jan Möbius committed
253
254
255
    } else if ( actions[i]->text() == "Set Home" ) {
      QIcon icon;
      icon.addFile(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"set-home.png");
Jan Möbius's avatar
Jan Möbius committed
256

Jan Möbius's avatar
 
Jan Möbius committed
257
258
      QToolButton * button = qobject_cast<QToolButton *>( viewerToolbar_->widgetForAction ( actions[i] ) );
      button->setIcon(icon);
259
260
261
262
263

      // Connect action to all other widgets ( First widget provides the toolbar so dont connect twice!)
      for ( unsigned int i = 1 ; i < OpenFlipper::Options::examinerWidgets() ; ++i )
        connect( button,SIGNAL( clicked() ), examiner_widgets_[i], SLOT( setHome() ) );

Jan Möbius's avatar
 
Jan Möbius committed
264
265
    } else if ( actions[i]->text() == "Light" ) {
      QIcon icon;
Jan Möbius's avatar
   
Jan Möbius committed
266
      icon.addFile(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"light-mode.png");
Jan Möbius's avatar
Jan Möbius committed
267

Jan Möbius's avatar
 
Jan Möbius committed
268
269
      QToolButton * button = qobject_cast<QToolButton *>( viewerToolbar_->widgetForAction ( actions[i] ) );
      button->setIcon(icon);
270
271
272
273
274

      // Connect action to all other widgets ( First widget provides the toolbar so dont connect twice!)
      for ( unsigned int i = 1 ; i < OpenFlipper::Options::examinerWidgets() ; ++i )
        connect( button,SIGNAL( clicked() ), examiner_widgets_[i], SLOT( lightMode() ) );

Jan Möbius's avatar
 
Jan Möbius committed
275
276
277
    } else if ( actions[i]->text() == "Question" ) {
      QIcon icon;
      icon.addFile(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"help-about.png");
Jan Möbius's avatar
Jan Möbius committed
278

Jan Möbius's avatar
 
Jan Möbius committed
279
280
      QToolButton * button = qobject_cast<QToolButton *>( viewerToolbar_->widgetForAction ( actions[i] ) );
      button->setIcon(icon);
281
282
283
284
285

      // Connect action to all other widgets ( First widget provides the toolbar so dont connect twice!)
      for ( unsigned int i = 1 ; i < OpenFlipper::Options::examinerWidgets() ; ++i )
        connect( button,SIGNAL( clicked() ), examiner_widgets_[i], SLOT( questionMode() ) );

Jan Möbius's avatar
 
Jan Möbius committed
286
    } else if ( actions[i]->text() == "SceneGraph" ) {
287

Jan Möbius's avatar
 
Jan Möbius committed
288
289
      QIcon icon;
      icon.addFile(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"scenegraph.png");
Jan Möbius's avatar
Jan Möbius committed
290

Jan Möbius's avatar
 
Jan Möbius committed
291
292
      QToolButton * button = qobject_cast<QToolButton *>( viewerToolbar_->widgetForAction ( actions[i] ) );
      button->setIcon(icon);
293
294
295
296
297

      // Connect action to all other widgets ( First widget provides the toolbar so dont connect twice!)
      for ( unsigned int i = 1 ; i < OpenFlipper::Options::examinerWidgets() ; ++i )
        connect( button,SIGNAL( clicked() ), examiner_widgets_[i], SLOT( showSceneGraphDialog() ) );

Jan Möbius's avatar
 
Jan Möbius committed
298
    } else if ( actions[i]->text() == "Pick" ) {
299
300
301
302
303
304
305

      QToolButton * button = qobject_cast<QToolButton *>( viewerToolbar_->widgetForAction ( actions[i] ) );

      // Connect action to all other widgets ( First widget provides the toolbar so dont connect twice!)
      for ( unsigned int i = 1 ; i < OpenFlipper::Options::examinerWidgets() ; ++i )
        connect( button,SIGNAL( clicked() ), examiner_widgets_[i], SLOT( pickingMode() ) );

Jan Möbius's avatar
 
Jan Möbius committed
306
    } else if ( actions[i]->text() == "View All" ) {
307
308
309
310
311
312
313

      QToolButton * button = qobject_cast<QToolButton *>( viewerToolbar_->widgetForAction ( actions[i] ) );

      // Connect action to all other widgets ( First widget provides the toolbar so dont connect twice!)
      for ( unsigned int i = 1 ; i < OpenFlipper::Options::examinerWidgets() ; ++i )
        connect( button,SIGNAL( clicked() ), examiner_widgets_[i], SLOT( viewAll() ) );

Jan Möbius's avatar
 
Jan Möbius committed
314
    } else if ( actions[i]->text() == "Projection" ) {
315
316
317
318
319
320
321

      QToolButton * button = qobject_cast<QToolButton *>( viewerToolbar_->widgetForAction ( actions[i] ) );

      // Connect action to all other widgets ( First widget provides the toolbar so dont connect twice!)
      for ( unsigned int i = 1 ; i < OpenFlipper::Options::examinerWidgets() ; ++i )
        connect( button,SIGNAL( clicked() ), examiner_widgets_[i], SLOT( toggleProjectionMode() ) );

Jan Möbius's avatar
 
Jan Möbius committed
322
    } else if ( actions[i]->text() == "Stereo" ) {
323
324
325
326
327
328
329

      QToolButton * button = qobject_cast<QToolButton *>( viewerToolbar_->widgetForAction ( actions[i] ) );

      // Connect action to all other widgets ( First widget provides the toolbar so dont connect twice!)
      for ( unsigned int i = 1 ; i < OpenFlipper::Options::examinerWidgets() ; ++i )
        connect( button,SIGNAL( clicked() ), examiner_widgets_[i], SLOT( toggleStereoMode() ) );

Jan Möbius's avatar
 
Jan Möbius committed
330
    }
Jan Möbius's avatar
Jan Möbius committed
331

Jan Möbius's avatar
 
Jan Möbius committed
332
  }
Jan Möbius's avatar
Jan Möbius committed
333

Jan Möbius's avatar
Jan Möbius committed
334
335
336
337
338
  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
339

Jan Möbius's avatar
 
Jan Möbius committed
340
341
342
  // Remember logger size
  wsizes = splitter_->sizes();
  originalLoggerSize_  = wsizes[1];
Jan Möbius's avatar
Jan Möbius committed
343

Jan Möbius's avatar
 
Jan Möbius committed
344
345
  // ======================================================================
  // Create Upper DockWidget for ToolWidget control
Jan Möbius's avatar
Jan Möbius committed
346
  // ======================================================================
Jan Möbius's avatar
 
Jan Möbius committed
347
  dockViewMode_ = new QDockWidget("ViewMode" , this );
Dirk Wilden's avatar
Dirk Wilden committed
348
  dockViewMode_->setObjectName("DockViewMode");
Jan Möbius's avatar
 
Jan Möbius committed
349
350
351
352
353
354
355
356
  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
357

Jan Möbius's avatar
 
Jan Möbius committed
358
359
360
  // ======================================================================
  // Context menu setup
  // ======================================================================
Jan Möbius's avatar
Jan Möbius committed
361

Jan Möbius's avatar
Jan Möbius committed
362
363
364
365
  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
366

Dirk Wilden's avatar
   
Dirk Wilden committed
367
  contextMenu_ = new QMenu(this);
Jan Möbius's avatar
 
Jan Möbius committed
368
  contextSelectionMenu_ = new QMenu("Selection",0);
Jan Möbius's avatar
Jan Möbius committed
369

Jan Möbius's avatar
 
Jan Möbius committed
370
  setupMenuBar();
Jan Möbius's avatar
Jan Möbius committed
371

Jan Möbius's avatar
 
Jan Möbius committed
372
  updateRecent();
Jan Möbius's avatar
Jan Möbius committed
373

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

376
  registerCoreKeys();
Dirk Wilden's avatar
Dirk Wilden committed
377

Jan Möbius's avatar
 
Jan Möbius committed
378
379
380
381
382
383
384
}


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


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

Jan Möbius's avatar
 
Jan Möbius committed
386
387
388
389
390
391
392
393
}

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

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

395
396
397
398
  setWindowState( windowState() ^  Qt::WindowFullScreen);

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

Jan Möbius's avatar
 
Jan Möbius committed
399
400
401
402
403
  show();
}

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

404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
/** 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
422
423
424
425
426
427
/** Hide or show logger
  */
void
CoreWidget::toggleLogger() {
  // toggle
  OpenFlipper::Options::hideLogger( !OpenFlipper::Options::hideLogger() );
Jan Möbius's avatar
Jan Möbius committed
428

429
  // Hide/Show Logger
430
  showLogger( !OpenFlipper::Options::hideLogger() );
431
432
433
434
435
}

/** Hide or show logger
  */
void
436
CoreWidget::showLogger(bool _state) {
Jan Möbius's avatar
 
Jan Möbius committed
437
  //Hide Logger
438
  if ( !_state ) {
Jan Möbius's avatar
 
Jan Möbius committed
439
    QList<int> wsizes( splitter_->sizes() );
Jan Möbius's avatar
Jan Möbius committed
440

Jan Möbius's avatar
 
Jan Möbius committed
441
442
    // Remember old size
    originalLoggerSize_  = wsizes[1];
Jan Möbius's avatar
Jan Möbius committed
443

Jan Möbius's avatar
 
Jan Möbius committed
444
445
446
447
    wsizes[0] = wsizes[0]+wsizes[1];
    wsizes[1] = 0;
    splitter_->setSizes(wsizes);
  } else {
Jan Möbius's avatar
Jan Möbius committed
448
449

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

Jan Möbius's avatar
 
Jan Möbius committed
452
    QList<int> wsizes( splitter_->sizes() );
453
454
455

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

Jan Möbius's avatar
 
Jan Möbius committed
457
458
459
460
461
462
463
464
465
466
467
468
    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
469

Jan Möbius's avatar
 
Jan Möbius committed
470
  //toggle
471
472
473
474
475
476
477
478
479
480
481
482
  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
483

Jan Möbius's avatar
Jan Möbius committed
484
  if ( OpenFlipper::Options::hideToolbox() ){
Jan Möbius's avatar
 
Jan Möbius committed
485
486
487
488
489
490
    //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
491
    dockViewMode_->setVisible(false);
Jan Möbius's avatar
 
Jan Möbius committed
492
493
494
495
496
497
498
499
500

  }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
501

Jan Möbius's avatar
 
Jan Möbius committed
502
503
//=============================================================================

Jan Möbius's avatar
Jan Möbius committed
504
505
void
CoreWidget::addRecent(QString _filename, DataType _type)
Jan Möbius's avatar
 
Jan Möbius committed
506
{
507
508
  //dont add objects to recentMenu while loadind Settings
  if ( OpenFlipper::Options::loadingSettings() ) return;
Jan Möbius's avatar
Jan Möbius committed
509

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

Jan Möbius's avatar
 
Jan Möbius committed
512
  updateRecent();
Jan Möbius's avatar
Jan Möbius committed
513
514
515
516
517
518
519

}

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

void
CoreWidget::updateRecent()
Jan Möbius's avatar
 
Jan Möbius committed
520
521
522
{
  if ( recentFilesMenu_ == NULL)
    return;
Jan Möbius's avatar
Jan Möbius committed
523

Jan Möbius's avatar
 
Jan Möbius committed
524
525
526
527
528
  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();
529
530
    path += typeIcon( recentFiles[i].type );

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

Jan Möbius's avatar
Jan Möbius committed
534
535
536
}

void
Jan Möbius's avatar
 
Jan Möbius committed
537
538
539
CoreWidget::closeEvent ( QCloseEvent * /* event */ ) {
  emit exit();
}
540
541

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

543
544
  if ( OpenFlipper::Options::nogui() )
    return;
Jan Möbius's avatar
Jan Möbius committed
545

546
  if ( optionsWidget_ == 0 ) {
Dirk Wilden's avatar
Dirk Wilden committed
547
    optionsWidget_ = new OptionsWidget(plugins_, coreKeys_, invKeys_, 0);
548
    connect(optionsWidget_,SIGNAL(applyOptions()),this,SIGNAL(applyOptions()));
Dirk Wilden's avatar
Dirk Wilden committed
549
    connect(optionsWidget_,SIGNAL(saveOptions()),this,SIGNAL(saveOptions()));
Dirk Wilden's avatar
Dirk Wilden committed
550
551
    connect(optionsWidget_,SIGNAL(addKeyMapping(int,Qt::KeyboardModifiers,QObject*,int)),
            this,          SLOT(slotAddKeyMapping(int,Qt::KeyboardModifiers,QObject*,int)));
552
  }
Dirk Wilden's avatar
Dirk Wilden committed
553

Jan Möbius's avatar
Jan Möbius committed
554
  //show the optionsWidget centered
Dirk Wilden's avatar
Dirk Wilden committed
555
  QPoint center;
Jan Möbius's avatar
Jan Möbius committed
556
  center.setX( x() + width() / 2 );
Dirk Wilden's avatar
Dirk Wilden committed
557
558
  center.setY( y() + height() / 2 );

Dirk Wilden's avatar
Dirk Wilden committed
559
560
  optionsWidget_->setGeometry(center.x() - optionsWidget_->width() / 2,
                              center.y() - optionsWidget_->height()/ 2, optionsWidget_->width(), optionsWidget_->height());
Dirk Wilden's avatar
Dirk Wilden committed
561

562
  optionsWidget_->show();
Jan Möbius's avatar
Jan Möbius committed
563

564
}
Jan Möbius's avatar
Jan Möbius committed
565

Jan Möbius's avatar
 
Jan Möbius committed
566
567

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