CoreWidget.cc 17.9 KB
Newer Older
Jan Möbius's avatar
   
Jan Möbius committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
//=============================================================================
//
//                               OpenFlipper
//        Copyright (C) 2008 by Computer Graphics Group, RWTH Aachen
//                           www.openflipper.org
//
//-----------------------------------------------------------------------------
//
//                                License
//
//  OpenFlipper is free software: you can redistribute it and/or modify
//  it under the terms of the GNU Lesser General Public License as published by
//  the Free Software Foundation, either version 3 of the License, or
//  (at your option) any later version.
Jan Möbius's avatar
Jan Möbius committed
15
//
Jan Möbius's avatar
   
Jan Möbius committed
16
17
18
19
//  OpenFlipper is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU Lesser General Public License for more details.
Jan Möbius's avatar
Jan Möbius committed
20
//
Jan Möbius's avatar
   
Jan Möbius committed
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
//  You should have received a copy of the GNU Lesser General Public License
//  along with OpenFlipper.  If not, see <http://www.gnu.org/licenses/>.
//
//-----------------------------------------------------------------------------
//
//   $Revision$
//   $Author$
//   $Date$
//
//=============================================================================




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


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

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

// -------------------- OpenFlipper Includes
#include <OpenFlipper/common/GlobalOptions.hh>
#include <OpenFlipper/common/RecentFiles.hh>
#include <OpenFlipper/BasePlugin/PluginFunctions.hh>
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
            std::vector<PluginInfo>& _plugins ) :
Jan Möbius's avatar
   
Jan Möbius committed
65
66
67
68
69
70
71
  QMainWindow(),
  viewModes_(_viewModes),
  dockViewMode_(0),
  viewModeButton_(0),
  viewModeMenu_(0),
  viewGroup_(0),
  splitter_(0),
72
  logWidget_(0),
Jan Möbius's avatar
   
Jan Möbius committed
73
74
75
76
77
78
  recentFilesMenu_(0),
  pluginsMenu_(0),
  fileMenu_(0),
  viewMenu_(0),
  fileMenuEnd_(0),
  contextMenu_(0),
Jan Möbius's avatar
Jan Möbius committed
79
  contextSelectionMenu_(0),
Jan Möbius's avatar
   
Jan Möbius committed
80
81
82
83
  stackMenu_(0),
  stackedWidget_(0),
  helpBrowserDeveloper_(0),
  helpBrowserUser_(0),
Jan Möbius's avatar
Jan Möbius committed
84
  aboutWidget_(0),
85
  optionsWidget_(0),
Jan Möbius's avatar
   
Jan Möbius committed
86
  plugins_(_plugins)
Jan Möbius's avatar
Jan Möbius committed
87

Jan Möbius's avatar
   
Jan Möbius committed
88
89
{
  setupStatusBar();
Jan Möbius's avatar
Jan Möbius committed
90

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

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

104
105
  originalLoggerSize_ = 0;

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

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

  QWidget* tmp = 0;

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

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

Jan Möbius's avatar
Jan Möbius committed
128
129
    examiner_widgets_.push_back(examinerWidget);

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

Jan Möbius's avatar
Jan Möbius committed
134
    stackedWidget_->addWidget(examinerWidget);
Jan Möbius's avatar
Jan Möbius committed
135

Jan Möbius's avatar
Jan Möbius committed
136
    examiner_widget_ = examinerWidget;
Jan Möbius's avatar
Jan Möbius committed
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167

  } else {

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

    // Create master examiner widget
    examiner_widget_ = new ACG::QtWidgets::QtExaminerViewer(tmp,
                                                            "Examiner Widget",
                                                            statusBar_ ,
                                                            &format,
                                                            0,
                                                            ACG::QtWidgets::QtExaminerViewer::Nothing);
    examiner_widgets_.push_back(examiner_widget_);


    // 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,
                                                                                         examiner_widget_,
                                                                                         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
177
178
179
180
    }

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

    stackedWidget_->addWidget(tmp);

  }

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

Jan Möbius's avatar
   
Jan Möbius committed
182
183
184
185
186
187
188
189
190
  // ======================================================================
  // Setup dragging for examiner widget
  // ======================================================================
  examiner_widget_->setExternalDrag(true);
  connect( examiner_widget_, SIGNAL(startDragEvent( QMouseEvent*)),
           this, SLOT(startDrag(QMouseEvent* )));
  connect( examiner_widget_, SIGNAL(dragEnterEvent( QDragEnterEvent*)),
           this, SLOT(dragEnterEvent(QDragEnterEvent* )));
  connect( examiner_widget_, SIGNAL(dropEvent( QDropEvent*)),
Jan Möbius's avatar
Jan Möbius committed
191
192
           this, SLOT(dropEvent(QDropEvent* )));

Jan Möbius's avatar
Jan Möbius committed
193
194
195
196
197
198
199
  if ( OpenFlipper::Options::multiView() ) {
    // TODO: Check drag and drop for multiview
    std::cerr << "Todo : Check drag and drop for multiview" << std::endl;

  }


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

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

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

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

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

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

Jan Möbius's avatar
   
Jan Möbius committed
223
224
225
226
  addToolBar(Qt::TopToolBarArea,viewerToolbar_);
  viewerToolbar_->setParent(this);
  viewerToolbar_->setAllowedAreas(Qt::AllToolBarAreas);
  viewerToolbar_->setIconSize(QSize(20,20));
Dirk Wilden's avatar
Dirk Wilden committed
227
  viewerToolbar_->setObjectName("ViewerToolbar");
Jan Möbius's avatar
Jan Möbius committed
228

Jan Möbius's avatar
Jan Möbius committed
229
  // Set our own Icons and connect to additional examiner widgets
Jan Möbius's avatar
   
Jan Möbius committed
230
231
232
233
234
  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
235

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

Jan Möbius's avatar
   
Jan Möbius committed
242
243
244
245
246
      QToolButton * button = qobject_cast<QToolButton *>( viewerToolbar_->widgetForAction ( actions[i] ) );
      button->setIcon(icon);
    } 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
247

Jan Möbius's avatar
   
Jan Möbius committed
248
249
250
251
      QToolButton * button = qobject_cast<QToolButton *>( viewerToolbar_->widgetForAction ( actions[i] ) );
      button->setIcon(icon);
    } else if ( actions[i]->text() == "Light" ) {
      QIcon icon;
Jan Möbius's avatar
   
Jan Möbius committed
252
      icon.addFile(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"light-mode.png");
Jan Möbius's avatar
Jan Möbius committed
253

Jan Möbius's avatar
   
Jan Möbius committed
254
255
256
257
258
      QToolButton * button = qobject_cast<QToolButton *>( viewerToolbar_->widgetForAction ( actions[i] ) );
      button->setIcon(icon);
    } 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
259

Jan Möbius's avatar
   
Jan Möbius committed
260
261
262
263
264
      QToolButton * button = qobject_cast<QToolButton *>( viewerToolbar_->widgetForAction ( actions[i] ) );
      button->setIcon(icon);
    } else if ( actions[i]->text() == "SceneGraph" ) {
      QIcon icon;
      icon.addFile(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"scenegraph.png");
Jan Möbius's avatar
Jan Möbius committed
265

Jan Möbius's avatar
   
Jan Möbius committed
266
267
268
269
270
      QToolButton * button = qobject_cast<QToolButton *>( viewerToolbar_->widgetForAction ( actions[i] ) );
      button->setIcon(icon);
    } else if ( actions[i]->text() == "Pick" ) {
//       QIcon icon;
//       icon.addFile(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"scenegraph.png");
Jan Möbius's avatar
Jan Möbius committed
271
//
Jan Möbius's avatar
   
Jan Möbius committed
272
273
274
275
276
//       QToolButton * button = qobject_cast<QToolButton *>( viewerToolbar_->widgetForAction ( actions[i] ) );
//       button->setIcon(icon);
    } else if ( actions[i]->text() == "View All" ) {
//       QIcon icon;
//       icon.addFile(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"scenegraph.png");
Jan Möbius's avatar
Jan Möbius committed
277
//
Jan Möbius's avatar
   
Jan Möbius committed
278
279
280
281
282
//       QToolButton * button = qobject_cast<QToolButton *>( viewerToolbar_->widgetForAction ( actions[i] ) );
//       button->setIcon(icon);
    } else if ( actions[i]->text() == "Projection" ) {
//       QIcon icon;
//       icon.addFile(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"scenegraph.png");
Jan Möbius's avatar
Jan Möbius committed
283
//
Jan Möbius's avatar
   
Jan Möbius committed
284
285
286
287
288
//       QToolButton * button = qobject_cast<QToolButton *>( viewerToolbar_->widgetForAction ( actions[i] ) );
//       button->setIcon(icon);
    } else if ( actions[i]->text() == "Stereo" ) {
//       QIcon icon;
//       icon.addFile(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"scenegraph.png");
Jan Möbius's avatar
Jan Möbius committed
289
//
Jan Möbius's avatar
   
Jan Möbius committed
290
291
292
//       QToolButton * button = qobject_cast<QToolButton *>( viewerToolbar_->widgetForAction ( actions[i] ) );
//       button->setIcon(icon);
    }
Jan Möbius's avatar
Jan Möbius committed
293
294
295

//     else
//       std::cerr << actions[i]->text().toStdString() << std::endl;
Jan Möbius's avatar
   
Jan Möbius committed
296
  }
Jan Möbius's avatar
Jan Möbius committed
297

Jan Möbius's avatar
Jan Möbius committed
298
299
300
301
302
  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
303

Jan Möbius's avatar
   
Jan Möbius committed
304
305
306
  // Remember logger size
  wsizes = splitter_->sizes();
  originalLoggerSize_  = wsizes[1];
Jan Möbius's avatar
Jan Möbius committed
307

Jan Möbius's avatar
   
Jan Möbius committed
308
309
  // ======================================================================
  // Create Upper DockWidget for ToolWidget control
Jan Möbius's avatar
Jan Möbius committed
310
  // ======================================================================
Jan Möbius's avatar
   
Jan Möbius committed
311
  dockViewMode_ = new QDockWidget("ViewMode" , this );
Dirk Wilden's avatar
Dirk Wilden committed
312
  dockViewMode_->setObjectName("DockViewMode");
Jan Möbius's avatar
   
Jan Möbius committed
313
314
315
316
317
318
319
320
  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
321

Jan Möbius's avatar
   
Jan Möbius committed
322
323
324
  // ======================================================================
  // Context menu setup
  // ======================================================================
Jan Möbius's avatar
Jan Möbius committed
325

Jan Möbius's avatar
Jan Möbius committed
326
327
328
329
  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
330

Dirk Wilden's avatar
   
Dirk Wilden committed
331
  contextMenu_ = new QMenu(this);
Jan Möbius's avatar
   
Jan Möbius committed
332
  contextSelectionMenu_ = new QMenu("Selection",0);
Jan Möbius's avatar
Jan Möbius committed
333

Jan Möbius's avatar
   
Jan Möbius committed
334
  setupMenuBar();
Jan Möbius's avatar
Jan Möbius committed
335

Jan Möbius's avatar
   
Jan Möbius committed
336
  updateRecent();
Jan Möbius's avatar
Jan Möbius committed
337

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

340
  registerCoreKeys();
Dirk Wilden's avatar
Dirk Wilden committed
341

Jan Möbius's avatar
   
Jan Möbius committed
342
343
344
345
346
347
348
}


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


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

Jan Möbius's avatar
   
Jan Möbius committed
350
351
352
353
354
355
356
357
}

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

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

359
360
361
362
  setWindowState( windowState() ^  Qt::WindowFullScreen);

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

Jan Möbius's avatar
   
Jan Möbius committed
363
364
365
366
367
  show();
}

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

368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
/** 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
386
387
388
389
390
391
/** Hide or show logger
  */
void
CoreWidget::toggleLogger() {
  // toggle
  OpenFlipper::Options::hideLogger( !OpenFlipper::Options::hideLogger() );
Jan Möbius's avatar
Jan Möbius committed
392

393
  // Hide/Show Logger
394
  showLogger( !OpenFlipper::Options::hideLogger() );
395
396
397
398
399
}

/** Hide or show logger
  */
void
400
CoreWidget::showLogger(bool _state) {
Jan Möbius's avatar
   
Jan Möbius committed
401
  //Hide Logger
402
  if ( !_state ) {
Jan Möbius's avatar
   
Jan Möbius committed
403
    QList<int> wsizes( splitter_->sizes() );
Jan Möbius's avatar
Jan Möbius committed
404

Jan Möbius's avatar
   
Jan Möbius committed
405
406
    // Remember old size
    originalLoggerSize_  = wsizes[1];
Jan Möbius's avatar
Jan Möbius committed
407

Jan Möbius's avatar
   
Jan Möbius committed
408
409
410
411
    wsizes[0] = wsizes[0]+wsizes[1];
    wsizes[1] = 0;
    splitter_->setSizes(wsizes);
  } else {
Jan Möbius's avatar
Jan Möbius committed
412
413

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

Jan Möbius's avatar
   
Jan Möbius committed
416
    QList<int> wsizes( splitter_->sizes() );
417
418
419

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

Jan Möbius's avatar
   
Jan Möbius committed
421
422
423
424
425
426
427
428
429
430
431
432
    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
433

Jan Möbius's avatar
   
Jan Möbius committed
434
  //toggle
435
436
437
438
439
440
441
442
443
444
445
446
  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
447

Jan Möbius's avatar
Jan Möbius committed
448
  if ( OpenFlipper::Options::hideToolbox() ){
Jan Möbius's avatar
   
Jan Möbius committed
449
450
451
452
453
454
    //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
455
    dockViewMode_->setVisible(false);
Jan Möbius's avatar
   
Jan Möbius committed
456
457
458
459
460
461
462
463
464

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

Jan Möbius's avatar
   
Jan Möbius committed
466
467
//=============================================================================

Jan Möbius's avatar
Jan Möbius committed
468
469
void
CoreWidget::addRecent(QString _filename, DataType _type)
Jan Möbius's avatar
   
Jan Möbius committed
470
{
471
472
  //dont add objects to recentMenu while loadind Settings
  if ( OpenFlipper::Options::loadingSettings() ) return;
Jan Möbius's avatar
Jan Möbius committed
473

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

Jan Möbius's avatar
   
Jan Möbius committed
476
  updateRecent();
Jan Möbius's avatar
Jan Möbius committed
477
478
479
480
481
482
483

}

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

void
CoreWidget::updateRecent()
Jan Möbius's avatar
   
Jan Möbius committed
484
485
486
{
  if ( recentFilesMenu_ == NULL)
    return;
Jan Möbius's avatar
Jan Möbius committed
487

Jan Möbius's avatar
   
Jan Möbius committed
488
489
490
491
492
  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();
493
494
    path += typeIcon( recentFiles[i].type );

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

Jan Möbius's avatar
Jan Möbius committed
498
499
500
}

void
Jan Möbius's avatar
   
Jan Möbius committed
501
502
503
CoreWidget::closeEvent ( QCloseEvent * /* event */ ) {
  emit exit();
}
504
505

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

507
508
  if ( OpenFlipper::Options::nogui() )
    return;
Jan Möbius's avatar
Jan Möbius committed
509

510
  if ( optionsWidget_ == 0 ) {
Dirk Wilden's avatar
Dirk Wilden committed
511
    optionsWidget_ = new OptionsWidget(plugins_, coreKeys_, invKeys_, 0);
512
    connect(optionsWidget_,SIGNAL(applyOptions()),this,SIGNAL(applyOptions()));
Dirk Wilden's avatar
Dirk Wilden committed
513
    connect(optionsWidget_,SIGNAL(saveOptions()),this,SIGNAL(saveOptions()));
Dirk Wilden's avatar
Dirk Wilden committed
514
515
    connect(optionsWidget_,SIGNAL(addKeyMapping(int,Qt::KeyboardModifiers,QObject*,int)),
            this,          SLOT(slotAddKeyMapping(int,Qt::KeyboardModifiers,QObject*,int)));
516
  }
Dirk Wilden's avatar
Dirk Wilden committed
517

Jan Möbius's avatar
Jan Möbius committed
518
  //show the optionsWidget centered
Dirk Wilden's avatar
Dirk Wilden committed
519
  QPoint center;
Jan Möbius's avatar
Jan Möbius committed
520
  center.setX( x() + width() / 2 );
Dirk Wilden's avatar
Dirk Wilden committed
521
522
  center.setY( y() + height() / 2 );

Dirk Wilden's avatar
Dirk Wilden committed
523
524
  optionsWidget_->setGeometry(center.x() - optionsWidget_->width() / 2,
                              center.y() - optionsWidget_->height()/ 2, optionsWidget_->width(), optionsWidget_->height());
Dirk Wilden's avatar
Dirk Wilden committed
525

526
  optionsWidget_->show();
Jan Möbius's avatar
Jan Möbius committed
527

528
}
Jan Möbius's avatar
Jan Möbius committed
529

Jan Möbius's avatar
   
Jan Möbius committed
530
531

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