CoreWidget.cc 22.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>
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
72
73
74
75
76
77
78
  QMainWindow(),
  viewModes_(_viewModes),
  dockViewMode_(0),
  viewModeButton_(0),
  viewModeMenu_(0),
  viewGroup_(0),
  splitter_(0),
  textedit_(0),
  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
98
99
100
101
102
  // ======================================================================
  // Set up the logging window
  // ======================================================================
  textedit_ = new QTextEdit(splitter_);
  textedit_->setReadOnly(true);
  textedit_->setSizePolicy( QSizePolicy ( QSizePolicy::Preferred , QSizePolicy::Preferred ) );
  textedit_->resize( splitter_->width() ,120);
  textedit_->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
130
131
    examiner_widgets_.push_back(examinerWidget);

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

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

Jan Möbius's avatar
Jan Möbius committed
135
    examiner_widget_ = examinerWidget;
Jan Möbius's avatar
Jan Möbius committed
136
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
168
169
170
171
172
173
174
175
176
177
178

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

    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
179

Jan Möbius's avatar
   
Jan Möbius committed
180
181
182
183
184
185
186
187
188
  // ======================================================================
  // 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
189
190
           this, SLOT(dropEvent(QDropEvent* )));

Jan Möbius's avatar
Jan Möbius committed
191
192
193
194
195
196
197
  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
198
199
200
  // ======================================================================
  // Create main Toolbar
  // ======================================================================
Jan Möbius's avatar
Jan Möbius committed
201

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

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

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

Jan Möbius's avatar
   
Jan Möbius committed
212
  // Take control over the toolbar
Jan Möbius's avatar
Jan Möbius committed
213
214
215
216
217
218
219
220
  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
221
222
223
224
  addToolBar(Qt::TopToolBarArea,viewerToolbar_);
  viewerToolbar_->setParent(this);
  viewerToolbar_->setAllowedAreas(Qt::AllToolBarAreas);
  viewerToolbar_->setIconSize(QSize(20,20));
Dirk Wilden's avatar
Dirk Wilden committed
225
  viewerToolbar_->setObjectName("ViewerToolbar");
Jan Möbius's avatar
Jan Möbius committed
226

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

Jan Möbius's avatar
   
Jan Möbius committed
234
235
236
237
238
      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
239

Jan Möbius's avatar
   
Jan Möbius committed
240
241
242
243
244
      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
245

Jan Möbius's avatar
   
Jan Möbius committed
246
247
248
249
      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
250
      icon.addFile(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"light-mode.png");
Jan Möbius's avatar
Jan Möbius committed
251

Jan Möbius's avatar
   
Jan Möbius committed
252
253
254
255
256
      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
257

Jan Möbius's avatar
   
Jan Möbius committed
258
259
260
261
262
      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
263

Jan Möbius's avatar
   
Jan Möbius committed
264
265
266
267
268
      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
269
//
Jan Möbius's avatar
   
Jan Möbius committed
270
271
272
273
274
//       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
275
//
Jan Möbius's avatar
   
Jan Möbius committed
276
277
278
279
280
//       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
281
//
Jan Möbius's avatar
   
Jan Möbius committed
282
283
284
285
286
//       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
287
//
Jan Möbius's avatar
   
Jan Möbius committed
288
289
290
//       QToolButton * button = qobject_cast<QToolButton *>( viewerToolbar_->widgetForAction ( actions[i] ) );
//       button->setIcon(icon);
    }
Jan Möbius's avatar
Jan Möbius committed
291
292
293

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

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

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

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

Jan Möbius's avatar
   
Jan Möbius committed
320
321
322
  // ======================================================================
  // Context menu setup
  // ======================================================================
Jan Möbius's avatar
Jan Möbius committed
323

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

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

Jan Möbius's avatar
   
Jan Möbius committed
332
  setupMenuBar();
Jan Möbius's avatar
Jan Möbius committed
333

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

Jan Möbius's avatar
   
Jan Möbius committed
336
  statusBar_->showMessage("Ready", 5000);
Dirk Wilden's avatar
Dirk Wilden committed
337
338
339
340
341
342
343

  //register keys for coreWidget
  connect(this,SIGNAL( registerKey(int, Qt::KeyboardModifiers, QString) ),
                this,SLOT(slotRegisterKey(int, Qt::KeyboardModifiers, QString)) );

  emit registerKey(Qt::Key_S,Qt::ControlModifier, "Save Object");
  emit registerKey(Qt::Key_O,Qt::ControlModifier, "Open Object");
Jan Möbius's avatar
Jan Möbius committed
344
  emit registerKey(Qt::Key_Escape,Qt::NoModifier, "Switch to last action mode ( Move,Picking,Light or Info Mode)");
Jan Möbius's avatar
   
Jan Möbius committed
345
346
347
348
349
350
351
}


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


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

Jan Möbius's avatar
   
Jan Möbius committed
353
354
355
356
357
358
359
360
}

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

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

362
363
364
365
  setWindowState( windowState() ^  Qt::WindowFullScreen);

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

Jan Möbius's avatar
   
Jan Möbius committed
366
367
368
369
370
  show();
}

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

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

396
  // Hide/Show Logger
397
  showLogger( !OpenFlipper::Options::hideLogger() );
398
399
400
401
402
}

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

Jan Möbius's avatar
   
Jan Möbius committed
408
409
    // Remember old size
    originalLoggerSize_  = wsizes[1];
Jan Möbius's avatar
Jan Möbius committed
410

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

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

Jan Möbius's avatar
   
Jan Möbius committed
419
    QList<int> wsizes( splitter_->sizes() );
420
421
422

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

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

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

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

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

Jan Möbius's avatar
   
Jan Möbius committed
469
//-----------------------------------------------------------------------------
Jan Möbius's avatar
Jan Möbius committed
470

Jan Möbius's avatar
   
Jan Möbius committed
471
472
473
474
475
476
/** Handles keypress events or passes them to plugins
  */
void
CoreWidget::keyPressEvent(QKeyEvent* _e)
{
  if (_e->modifiers() == Qt::ControlModifier ) {
Jan Möbius's avatar
Jan Möbius committed
477
    switch (_e->key())
Jan Möbius's avatar
   
Jan Möbius committed
478
479
480
481
    {
        case Qt::Key_F :
            toggleFullscreen();
          return;
Jan Möbius's avatar
Jan Möbius committed
482

Jan Möbius's avatar
   
Jan Möbius committed
483
484
485
        case Qt::Key_L :
            toggleLogger();
          return;
Jan Möbius's avatar
Jan Möbius committed
486

Jan Möbius's avatar
   
Jan Möbius committed
487
488
489
        case Qt::Key_T :
            toggleToolbox();
          return;
Jan Möbius's avatar
Jan Möbius committed
490

Jan Möbius's avatar
   
Jan Möbius committed
491
        // Send remaining events to plugins
Jan Möbius's avatar
Jan Möbius committed
492
        default:
Dirk Wilden's avatar
Dirk Wilden committed
493
           mapKeyPressEvent(_e);
Jan Möbius's avatar
   
Jan Möbius committed
494
        return;
Jan Möbius's avatar
Jan Möbius committed
495
    }
Jan Möbius's avatar
   
Jan Möbius committed
496
  }
Jan Möbius's avatar
Jan Möbius committed
497
498

   switch (_e->key())
Jan Möbius's avatar
   
Jan Möbius committed
499
500
501
   {
      // Send remaining events to plugins
      default:
Dirk Wilden's avatar
Dirk Wilden committed
502
          mapKeyPressEvent(_e);
Jan Möbius's avatar
   
Jan Möbius committed
503
504
505
506
507
508
509
      break;
  }
}

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

/** Handle Key Release Events */
Jan Möbius's avatar
Jan Möbius committed
510
void
Jan Möbius's avatar
   
Jan Möbius committed
511
CoreWidget::keyReleaseEvent(QKeyEvent* _e) {
Dirk Wilden's avatar
Dirk Wilden committed
512
513
514
515
516
517
518
519
   mapKeyReleaseEvent(_e);
}

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

/** Map Key Press Events to Plugins */
void
CoreWidget::mapKeyPressEvent(QKeyEvent* _e){
Dirk Wilden's avatar
Dirk Wilden committed
520

Dirk Wilden's avatar
Dirk Wilden committed
521
522
523
  //find the first plugin which wants to handle that key
  for (uint i=0; i < plugins_.size(); i++)
    for (int k=0; k < plugins_[i].keys.count(); k++)
Jan Möbius's avatar
Jan Möbius committed
524
      if ( plugins_[i].keys[k].key == _e->key()
Dirk Wilden's avatar
Dirk Wilden committed
525
        && plugins_[i].keys[k].modifiers == _e->modifiers() ){
Dirk Wilden's avatar
Dirk Wilden committed
526

Dirk Wilden's avatar
Dirk Wilden committed
527
528
529
530
531
532
        KeyInterface* keyPlugin = qobject_cast< KeyInterface * >(plugins_[i].plugin);

        if (keyPlugin){
//           if ( checkSlot( plugins_[i].plugin , "slotKeyEvent(QKeyEvent*)" ) )
            keyPlugin->slotKeyEvent(_e);
        }
Dirk Wilden's avatar
Dirk Wilden committed
533
534
535
        //only inform further plugins if this is a multiUse key
        if (!plugins_[i].keys[k].multiUse)
          return;
Dirk Wilden's avatar
Dirk Wilden committed
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
      }
}

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

/** Map Key Release Events to Plugins */
void
CoreWidget::mapKeyReleaseEvent(QKeyEvent* _e){

  if (_e->isAutoRepeat()) return; //consider only "real" release events

  //find the first plugin which wants to handle that key
  for (uint i=0; i < plugins_.size(); i++)
    for (int k=0; k < plugins_[i].keys.count(); k++)
      if ( plugins_[i].keys[k].key == _e->key()
        && plugins_[i].keys[k].modifiers == _e->modifiers() ){

        KeyInterface* keyPlugin = qobject_cast< KeyInterface * >(plugins_[i].plugin);

        if (keyPlugin){
//           if ( checkSlot( plugins_[i].plugin , "slotKeyReleaseEvent(QKeyEvent*)" ) )
            keyPlugin->slotKeyReleaseEvent(_e);
        }
Dirk Wilden's avatar
Dirk Wilden committed
559
560
561
        //only inform further plugins if this is a multiUse key
        if (!plugins_[i].keys[k].multiUse)
          return;
Dirk Wilden's avatar
Dirk Wilden committed
562
563
564
565
566
567
568
      }
}

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

/** Register a key to a plugin */
void
Dirk Wilden's avatar
Dirk Wilden committed
569
CoreWidget::slotRegisterKey(int _key, Qt::KeyboardModifiers _modifiers, QString _description, bool _multiUse){
Dirk Wilden's avatar
Dirk Wilden committed
570
571
572

  //first check if the key is already registered by the coreWidget
  bool found = false;
Dirk Wilden's avatar
Dirk Wilden committed
573
  bool multi = false;
Dirk Wilden's avatar
Dirk Wilden committed
574
575
576
  for (uint i=0; i < coreKeys_.size(); i++)
    if (coreKeys_[i].key == _key && coreKeys_[i].modifiers == _modifiers){
      found = true;
Dirk Wilden's avatar
Dirk Wilden committed
577
      multi = coreKeys_[i].multiUse;
Dirk Wilden's avatar
Dirk Wilden committed
578
579
580
581
582
583
584
585
      break;
    }

  //then check if the key is already registered by a different plugin
  if (!found)
    for (uint i=0; i < plugins_.size(); i++)
      for (int k=0; k < plugins_[i].keys.count(); k++)
        if (plugins_[i].keys[k].key == _key
Dirk Wilden's avatar
Dirk Wilden committed
586
        && plugins_[i].keys[k].modifiers == _modifiers){
Dirk Wilden's avatar
Dirk Wilden committed
587
          found = true;
Dirk Wilden's avatar
Dirk Wilden committed
588
589
590
          multi = plugins_[i].keys[k].multiUse;
          break;
        }
Dirk Wilden's avatar
Dirk Wilden committed
591
592
593
594
595
596
597
598
599
600

  if (found)
    emit log(LOGERR, "Key already registered elsewhere.");

  //check if its a key for the core
  if (sender() == this){
    KeyBinding kb;
    kb.key = _key;
    kb.modifiers = _modifiers;
    kb.description = _description;
Dirk Wilden's avatar
Dirk Wilden committed
601
602
    kb.multiUse = multi || _multiUse;

603
604
605
    if (multi && !_multiUse)
      log(LOGWARN, "Key registered as multiUse key.");

Dirk Wilden's avatar
Dirk Wilden committed
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
    coreKeys_.push_back( kb );
    return;
  }

  //find plugin
 PluginInfo* pluginInfo = 0;

  for (uint i=0; i < plugins_.size(); i++)
    if (plugins_[i].plugin == sender())
      pluginInfo = &plugins_[i];

  if (pluginInfo == 0){
    emit log(LOGERR, "Unable to register key. Plugin not found!");
    return;
  }

  KeyBinding kb;
  kb.key = _key;
  kb.modifiers = _modifiers;
  kb.description = _description;
Dirk Wilden's avatar
Dirk Wilden committed
626
  kb.multiUse = multi || _multiUse;
Dirk Wilden's avatar
Dirk Wilden committed
627

628
629
630
  if (multi && !_multiUse)
    log(LOGWARN, "Key registered as multiUse key.");

Dirk Wilden's avatar
Dirk Wilden committed
631
  pluginInfo->keys.append( kb );
Jan Möbius's avatar
   
Jan Möbius committed
632
633
634
635
}

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

Jan Möbius's avatar
Jan Möbius committed
636
637
void
CoreWidget::addRecent(QString _filename, DataType _type)
Jan Möbius's avatar
   
Jan Möbius committed
638
{
639
640
  //dont add objects to recentMenu while loadind Settings
  if ( OpenFlipper::Options::loadingSettings() ) return;
Jan Möbius's avatar
Jan Möbius committed
641

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

Jan Möbius's avatar
   
Jan Möbius committed
644
  updateRecent();
Jan Möbius's avatar
Jan Möbius committed
645
646
647
648
649
650
651

}

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

void
CoreWidget::updateRecent()
Jan Möbius's avatar
   
Jan Möbius committed
652
653
654
{
  if ( recentFilesMenu_ == NULL)
    return;
Jan Möbius's avatar
Jan Möbius committed
655

Jan Möbius's avatar
   
Jan Möbius committed
656
657
658
659
660
  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();
661
662
    path += typeIcon( recentFiles[i].type );

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

Jan Möbius's avatar
Jan Möbius committed
666
667
668
}

void
Jan Möbius's avatar
   
Jan Möbius committed
669
670
671
CoreWidget::closeEvent ( QCloseEvent * /* event */ ) {
  emit exit();
}
672
673

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

675
676
  if ( OpenFlipper::Options::nogui() )
    return;
Jan Möbius's avatar
Jan Möbius committed
677

678
  if ( optionsWidget_ == 0 ) {
Dirk Wilden's avatar
Dirk Wilden committed
679
    optionsWidget_ = new OptionsWidget(plugins_, coreKeys_, 0);
680
    connect(optionsWidget_,SIGNAL(applyOptions()),this,SIGNAL(applyOptions()));
Dirk Wilden's avatar
Dirk Wilden committed
681
    connect(optionsWidget_,SIGNAL(saveOptions()),this,SIGNAL(saveOptions()));
682
  }
Dirk Wilden's avatar
Dirk Wilden committed
683

Jan Möbius's avatar
Jan Möbius committed
684
  //show the optionsWidget centered
Dirk Wilden's avatar
Dirk Wilden committed
685
  QPoint center;
Jan Möbius's avatar
Jan Möbius committed
686
  center.setX( x() + width() / 2 );
Dirk Wilden's avatar
Dirk Wilden committed
687
688
  center.setY( y() + height() / 2 );

Dirk Wilden's avatar
Dirk Wilden committed
689
690
  optionsWidget_->setGeometry(center.x() - optionsWidget_->width() / 2,
                              center.y() - optionsWidget_->height()/ 2, optionsWidget_->width(), optionsWidget_->height());
Dirk Wilden's avatar
Dirk Wilden committed
691

692
  optionsWidget_->show();
Jan Möbius's avatar
Jan Möbius committed
693

694
}
Jan Möbius's avatar
Jan Möbius committed
695

Jan Möbius's avatar
   
Jan Möbius committed
696
697

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