CoreWidget.cc 19.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
            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
79
  QMainWindow(),
  viewModes_(_viewModes),
  dockViewMode_(0),
  viewModeButton_(0),
  viewModeMenu_(0),
  viewGroup_(0),
  examiner_widget_(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
80
  contextSelectionMenu_(0),
Jan Möbius's avatar
 
Jan Möbius committed
81
82
83
84
  stackMenu_(0),
  stackedWidget_(0),
  helpBrowserDeveloper_(0),
  helpBrowserUser_(0),
Jan Möbius's avatar
Jan Möbius committed
85
  aboutWidget_(0),
86
  optionsWidget_(0),
Jan Möbius's avatar
 
Jan Möbius committed
87
  plugins_(_plugins)
Jan Möbius's avatar
Jan Möbius committed
88

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

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

Jan Möbius's avatar
 
Jan Möbius committed
96
97
98
99
100
101
102
103
  // ======================================================================
  // 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
104

105
106
  originalLoggerSize_ = 0;

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

Jan Möbius's avatar
 
Jan Möbius committed
113
114
115
116
117
118
  // ======================================================================
  // Create examiner
  // ======================================================================
  QGLFormat format;
  QGLFormat::setDefaultFormat(format);
  format.setStereo( OpenFlipper::Options::stereo() );
Jan Möbius's avatar
Jan Möbius committed
119
120
121
  examiner_widget_ = new ACG::QtWidgets::QtExaminerViewer(stackedWidget_,
                                                          "Examiner Widget",
                                                          statusBar_ ,
Jan Möbius's avatar
 
Jan Möbius committed
122
                                                          &format);
Dirk Wilden's avatar
Dirk Wilden committed
123
  examiner_widget_->sceneGraph( PluginFunctions::getSceneGraphRootNode() );
Jan Möbius's avatar
 
Jan Möbius committed
124
125
  examiner_widget_->enablePopupMenu(false);
  stackedWidget_->addWidget(examiner_widget_);
Jan Möbius's avatar
Jan Möbius committed
126

Jan Möbius's avatar
 
Jan Möbius committed
127
128
129
130
131
132
133
134
135
  // ======================================================================
  // 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
136
137
           this, SLOT(dropEvent(QDropEvent* )));

Jan Möbius's avatar
 
Jan Möbius committed
138
139
140
  // ======================================================================
  // Create main Toolbar
  // ======================================================================
Jan Möbius's avatar
Jan Möbius committed
141

Jan Möbius's avatar
 
Jan Möbius committed
142
  mainToolbar_ = new QToolBar("Main Toolbar");
143
  mainToolbar_->setWindowTitle("Main Toolbar");
Dirk Wilden's avatar
Dirk Wilden committed
144
  mainToolbar_->setObjectName("MainToolbar");
145
  slotAddToolbar(mainToolbar_);
Jan Möbius's avatar
Jan Möbius committed
146

Jan Möbius's avatar
 
Jan Möbius committed
147
148
149
  // ======================================================================
  // Get Toolbar from examiner and integrate it into main window
  // ======================================================================
Jan Möbius's avatar
Jan Möbius committed
150

Jan Möbius's avatar
 
Jan Möbius committed
151
152
153
154
155
156
  // Take control over the toolbar
  viewerToolbar_ = examiner_widget_->removeToolBar();
  addToolBar(Qt::TopToolBarArea,viewerToolbar_);
  viewerToolbar_->setParent(this);
  viewerToolbar_->setAllowedAreas(Qt::AllToolBarAreas);
  viewerToolbar_->setIconSize(QSize(20,20));
Dirk Wilden's avatar
Dirk Wilden committed
157
  viewerToolbar_->setObjectName("ViewerToolbar");
Jan Möbius's avatar
Jan Möbius committed
158

Jan Möbius's avatar
 
Jan Möbius committed
159
160
161
162
163
164
  // Set our own Icons
  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
165

Jan Möbius's avatar
 
Jan Möbius committed
166
167
168
169
170
      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
171

Jan Möbius's avatar
 
Jan Möbius committed
172
173
174
175
176
      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
177

Jan Möbius's avatar
 
Jan Möbius committed
178
179
180
181
      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
182
      icon.addFile(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"light-mode.png");
Jan Möbius's avatar
Jan Möbius committed
183

Jan Möbius's avatar
 
Jan Möbius committed
184
185
186
187
188
      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
189

Jan Möbius's avatar
 
Jan Möbius committed
190
191
192
193
194
      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
195

Jan Möbius's avatar
 
Jan Möbius committed
196
197
198
199
200
      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
201
//
Jan Möbius's avatar
 
Jan Möbius committed
202
203
204
205
206
//       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
207
//
Jan Möbius's avatar
 
Jan Möbius committed
208
209
210
211
212
//       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
213
//
Jan Möbius's avatar
 
Jan Möbius committed
214
215
216
217
218
//       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
219
//
Jan Möbius's avatar
 
Jan Möbius committed
220
221
222
//       QToolButton * button = qobject_cast<QToolButton *>( viewerToolbar_->widgetForAction ( actions[i] ) );
//       button->setIcon(icon);
    }
Jan Möbius's avatar
Jan Möbius committed
223
224
225

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

Jan Möbius's avatar
 
Jan Möbius committed
228
  stackWidgetList_.push_back( StackWidgetInfo( false, "3D Examiner Widget", examiner_widget_ ) );
Jan Möbius's avatar
Jan Möbius committed
229

Jan Möbius's avatar
 
Jan Möbius committed
230
231
232
  // Remember logger size
  wsizes = splitter_->sizes();
  originalLoggerSize_  = wsizes[1];
Jan Möbius's avatar
Jan Möbius committed
233

Jan Möbius's avatar
 
Jan Möbius committed
234
235
  // ======================================================================
  // Create Upper DockWidget for ToolWidget control
Jan Möbius's avatar
Jan Möbius committed
236
  // ======================================================================
Jan Möbius's avatar
 
Jan Möbius committed
237
  dockViewMode_ = new QDockWidget("ViewMode" , this );
Dirk Wilden's avatar
Dirk Wilden committed
238
  dockViewMode_->setObjectName("DockViewMode");
Jan Möbius's avatar
 
Jan Möbius committed
239
240
241
242
243
244
245
246
  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
247

Jan Möbius's avatar
 
Jan Möbius committed
248
249
250
  // ======================================================================
  // Context menu setup
  // ======================================================================
Jan Möbius's avatar
Jan Möbius committed
251
252

  connect( examiner_widget_ , SIGNAL(signalCustomContextMenuRequested( const QPoint&) ) ,
Jan Möbius's avatar
 
Jan Möbius committed
253
           this             , SLOT( slotCustomContextMenu( const QPoint&) ) );
Jan Möbius's avatar
Jan Möbius committed
254

Jan Möbius's avatar
 
Jan Möbius committed
255
256
  contextMenu_ = new QMenu(0);
  contextSelectionMenu_ = new QMenu("Selection",0);
Jan Möbius's avatar
Jan Möbius committed
257

Jan Möbius's avatar
 
Jan Möbius committed
258
  setupMenuBar();
Jan Möbius's avatar
Jan Möbius committed
259

Jan Möbius's avatar
 
Jan Möbius committed
260
  updateRecent();
Jan Möbius's avatar
Jan Möbius committed
261

Jan Möbius's avatar
 
Jan Möbius committed
262
  statusBar_->showMessage("Ready", 5000);
Dirk Wilden's avatar
Dirk Wilden committed
263
264
265
266
267
268
269

  //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
270
  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
271
272
273
274
275
276
277
}


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


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

Jan Möbius's avatar
 
Jan Möbius committed
279
280
281
282
283
284
285
286
}

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

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

288
289
290
291
  setWindowState( windowState() ^  Qt::WindowFullScreen);

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

Jan Möbius's avatar
 
Jan Möbius committed
292
293
294
295
296
297
298
299
300
301
302
  show();
}

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

/** Hide or show logger
  */
void
CoreWidget::toggleLogger() {
  // toggle
  OpenFlipper::Options::hideLogger( !OpenFlipper::Options::hideLogger() );
Jan Möbius's avatar
Jan Möbius committed
303

304
305
306
307
308
309
310
311
  // Hide/Show Logger
  hideLogger( OpenFlipper::Options::hideLogger() );
}

/** Hide or show logger
  */
void
CoreWidget::hideLogger(bool _hide) {
Jan Möbius's avatar
 
Jan Möbius committed
312
  //Hide Logger
313
  if ( _hide ) {
Jan Möbius's avatar
 
Jan Möbius committed
314
    QList<int> wsizes( splitter_->sizes() );
Jan Möbius's avatar
Jan Möbius committed
315

Jan Möbius's avatar
 
Jan Möbius committed
316
317
    // Remember old size
    originalLoggerSize_  = wsizes[1];
Jan Möbius's avatar
Jan Möbius committed
318

Jan Möbius's avatar
 
Jan Möbius committed
319
320
321
322
    wsizes[0] = wsizes[0]+wsizes[1];
    wsizes[1] = 0;
    splitter_->setSizes(wsizes);
  } else {
Jan Möbius's avatar
Jan Möbius committed
323
324

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

Jan Möbius's avatar
 
Jan Möbius committed
327
    QList<int> wsizes( splitter_->sizes() );
328
329
330

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

Jan Möbius's avatar
 
Jan Möbius committed
332
333
334
335
336
337
338
339
340
341
342
343
    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
344

Jan Möbius's avatar
 
Jan Möbius committed
345
346
347
  //toggle
  OpenFlipper::Options::hideToolbox(!OpenFlipper::Options::hideToolbox());

Jan Möbius's avatar
Jan Möbius committed
348
  if ( OpenFlipper::Options::hideToolbox() ){
Jan Möbius's avatar
 
Jan Möbius committed
349
350
351
352
353
354
    //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
355
    dockViewMode_->setVisible(false);
Jan Möbius's avatar
 
Jan Möbius committed
356
357
358
359
360
361
362
363
364

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

Jan Möbius's avatar
 
Jan Möbius committed
366
//-----------------------------------------------------------------------------
Jan Möbius's avatar
Jan Möbius committed
367

Jan Möbius's avatar
 
Jan Möbius committed
368
369
370
371
372
373
/** 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
374
    switch (_e->key())
Jan Möbius's avatar
 
Jan Möbius committed
375
376
377
378
    {
        case Qt::Key_F :
            toggleFullscreen();
          return;
Jan Möbius's avatar
Jan Möbius committed
379

Jan Möbius's avatar
 
Jan Möbius committed
380
381
382
        case Qt::Key_L :
            toggleLogger();
          return;
Jan Möbius's avatar
Jan Möbius committed
383

Jan Möbius's avatar
 
Jan Möbius committed
384
385
386
        case Qt::Key_T :
            toggleToolbox();
          return;
Jan Möbius's avatar
Jan Möbius committed
387

Jan Möbius's avatar
 
Jan Möbius committed
388
        // Send remaining events to plugins
Jan Möbius's avatar
Jan Möbius committed
389
        default:
Dirk Wilden's avatar
Dirk Wilden committed
390
           mapKeyPressEvent(_e);
Jan Möbius's avatar
 
Jan Möbius committed
391
        return;
Jan Möbius's avatar
Jan Möbius committed
392
    }
Jan Möbius's avatar
 
Jan Möbius committed
393
  }
Jan Möbius's avatar
Jan Möbius committed
394
395

   switch (_e->key())
Jan Möbius's avatar
 
Jan Möbius committed
396
397
398
   {
      // Send remaining events to plugins
      default:
Dirk Wilden's avatar
Dirk Wilden committed
399
          mapKeyPressEvent(_e);
Jan Möbius's avatar
 
Jan Möbius committed
400
401
402
403
404
405
406
      break;
  }
}

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

/** Handle Key Release Events */
Jan Möbius's avatar
Jan Möbius committed
407
void
Jan Möbius's avatar
 
Jan Möbius committed
408
CoreWidget::keyReleaseEvent(QKeyEvent* _e) {
Dirk Wilden's avatar
Dirk Wilden committed
409
410
411
412
413
414
415
416
417
418
419
   mapKeyReleaseEvent(_e);
}

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

/** Map Key Press Events to Plugins */
void
CoreWidget::mapKeyPressEvent(QKeyEvent* _e){
  //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
420
      if ( plugins_[i].keys[k].key == _e->key()
Dirk Wilden's avatar
Dirk Wilden committed
421
422
423
424
425
426
427
428
        && plugins_[i].keys[k].modifiers == _e->modifiers() ){

        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
429
430
431
        //only inform further plugins if this is a multiUse key
        if (!plugins_[i].keys[k].multiUse)
          return;
Dirk Wilden's avatar
Dirk Wilden committed
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
      }
}

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

/** 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
455
456
457
        //only inform further plugins if this is a multiUse key
        if (!plugins_[i].keys[k].multiUse)
          return;
Dirk Wilden's avatar
Dirk Wilden committed
458
459
460
461
462
463
464
      }
}

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

/** Register a key to a plugin */
void
Dirk Wilden's avatar
Dirk Wilden committed
465
CoreWidget::slotRegisterKey(int _key, Qt::KeyboardModifiers _modifiers, QString _description, bool _multiUse){
Dirk Wilden's avatar
Dirk Wilden committed
466
467
468

  //first check if the key is already registered by the coreWidget
  bool found = false;
Dirk Wilden's avatar
Dirk Wilden committed
469
  bool multi = false;
Dirk Wilden's avatar
Dirk Wilden committed
470
471
472
  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
473
      multi = coreKeys_[i].multiUse;
Dirk Wilden's avatar
Dirk Wilden committed
474
475
476
477
478
479
480
481
      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
482
        && plugins_[i].keys[k].modifiers == _modifiers){
Dirk Wilden's avatar
Dirk Wilden committed
483
          found = true;
Dirk Wilden's avatar
Dirk Wilden committed
484
485
486
          multi = plugins_[i].keys[k].multiUse;
          break;
        }
Dirk Wilden's avatar
Dirk Wilden committed
487
488
489
490
491
492
493
494
495
496

  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
497
498
    kb.multiUse = multi || _multiUse;

499
500
501
    if (multi && !_multiUse)
      log(LOGWARN, "Key registered as multiUse key.");

Dirk Wilden's avatar
Dirk Wilden committed
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
    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
522
  kb.multiUse = multi || _multiUse;
Dirk Wilden's avatar
Dirk Wilden committed
523

524
525
526
  if (multi && !_multiUse)
    log(LOGWARN, "Key registered as multiUse key.");

Dirk Wilden's avatar
Dirk Wilden committed
527
  pluginInfo->keys.append( kb );
Jan Möbius's avatar
 
Jan Möbius committed
528
529
530
531
}

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

Jan Möbius's avatar
Jan Möbius committed
532
533
void
CoreWidget::addRecent(QString _filename, DataType _type)
Jan Möbius's avatar
 
Jan Möbius committed
534
{
535
536
  //dont add objects to recentMenu while loadind Settings
  if ( OpenFlipper::Options::loadingSettings() ) return;
Jan Möbius's avatar
Jan Möbius committed
537

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

Jan Möbius's avatar
 
Jan Möbius committed
540
  updateRecent();
Jan Möbius's avatar
Jan Möbius committed
541
542
543
544
545
546
547

}

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

void
CoreWidget::updateRecent()
Jan Möbius's avatar
 
Jan Möbius committed
548
549
550
{
  if ( recentFilesMenu_ == NULL)
    return;
Jan Möbius's avatar
Jan Möbius committed
551

Jan Möbius's avatar
 
Jan Möbius committed
552
553
554
555
556
557
  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();
    switch(recentFiles[i].type){
Jan Möbius's avatar
Jan Möbius committed
558
      case DATA_TRIANGLE_MESH:
Jan Möbius's avatar
   
Jan Möbius committed
559
        path += "TriangleType.png"; break;
Jan Möbius's avatar
Jan Möbius committed
560
      case DATA_POLY_MESH:
Jan Möbius's avatar
   
Jan Möbius committed
561
        path += "PolyType.png"; break;
Jan Möbius's avatar
Jan Möbius committed
562
      case DATA_POLY_LINE:
Jan Möbius's avatar
   
Jan Möbius committed
563
        path += "PolyLineType.png"; break;
Jan Möbius's avatar
Jan Möbius committed
564
      case DATA_BSPLINE_CURVE:
Jan Möbius's avatar
   
Jan Möbius committed
565
        path += "BSplineCurveType.png"; break;
Dirk Wilden's avatar
Dirk Wilden committed
566
567
      case DATA_NONE:
        path += "folder_grey.png"; break;
Jan Möbius's avatar
 
Jan Möbius committed
568
569
      default: path = "";
    }
Jan Möbius's avatar
Jan Möbius committed
570
    recentFilesMenu_->addAction(QIcon(path), recentFiles[i].filename);
Jan Möbius's avatar
 
Jan Möbius committed
571
572
  }

Jan Möbius's avatar
Jan Möbius committed
573
574
575
}

void
Jan Möbius's avatar
 
Jan Möbius committed
576
577
578
CoreWidget::closeEvent ( QCloseEvent * /* event */ ) {
  emit exit();
}
579
580

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

582
583
  if ( OpenFlipper::Options::nogui() )
    return;
Jan Möbius's avatar
Jan Möbius committed
584

585
  if ( optionsWidget_ == 0 ) {
Dirk Wilden's avatar
Dirk Wilden committed
586
    optionsWidget_ = new OptionsWidget(plugins_, coreKeys_, 0);
587
    connect(optionsWidget_,SIGNAL(applyOptions()),this,SIGNAL(applyOptions()));
Dirk Wilden's avatar
Dirk Wilden committed
588
    connect(optionsWidget_,SIGNAL(saveOptions()),this,SIGNAL(saveOptions()));
589
  }
Dirk Wilden's avatar
Dirk Wilden committed
590

Jan Möbius's avatar
Jan Möbius committed
591
  //show the optionsWidget centered
Dirk Wilden's avatar
Dirk Wilden committed
592
  QPoint center;
Jan Möbius's avatar
Jan Möbius committed
593
  center.setX( x() + width() / 2 );
Dirk Wilden's avatar
Dirk Wilden committed
594
595
  center.setY( y() + height() / 2 );

Dirk Wilden's avatar
Dirk Wilden committed
596
597
  optionsWidget_->setGeometry(center.x() - optionsWidget_->width() / 2,
                              center.y() - optionsWidget_->height()/ 2, optionsWidget_->width(), optionsWidget_->height());
Dirk Wilden's avatar
Dirk Wilden committed
598

599
  optionsWidget_->show();
Jan Möbius's avatar
Jan Möbius committed
600

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

Jan Möbius's avatar
 
Jan Möbius committed
603
604

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