ContextMenu.cc 21.6 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
//  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 CoreWidget - IMPLEMENTATION
//
//=============================================================================


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

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

#include <OpenFlipper/BasePlugin/PluginFunctions.hh>
#include <OpenFlipper/common/GlobalOptions.hh>

Jan Möbius's avatar
Jan Möbius committed
50
//== IMPLEMENTATION ==========================================================
Jan Möbius's avatar
 
Jan Möbius committed
51
52

void CoreWidget::slotCustomContextMenu( const QPoint& _point ) {
Jan Möbius's avatar
Jan Möbius committed
53

Jan Möbius's avatar
Jan Möbius committed
54
  QPoint   popupPosition;
Jan Möbius's avatar
Jan Möbius committed
55
  QPoint   scenePos;
Jan Möbius's avatar
Jan Möbius committed
56

Jan Möbius's avatar
Jan Möbius committed
57
58
59
60
  // Calculate popup position. Use the position from the viewer which was clicked on.
  popupPosition =  examiner_widgets_[PluginFunctions::activeExaminer()]->glMapToGlobal(_point);
  QPointF f = examiner_widgets_[PluginFunctions::activeExaminer()]->mapToScene(QPointF(_point.x(), _point.y()));
  scenePos = QPoint (f.x(), f.y());
61

Jan Möbius's avatar
Jan Möbius committed
62
  // Call function to adapt the menu to the currently used contex.
63
  updatePopupMenu(scenePos);
Jan Möbius's avatar
Jan Möbius committed
64

Jan Möbius's avatar
Jan Möbius committed
65
  // If the menu is not correctly initialized, dont try to show it.
Jan Möbius's avatar
 
Jan Möbius committed
66
  if ( !contextMenu_->isEmpty () )
Jan Möbius's avatar
Jan Möbius committed
67
    contextMenu_->popup( popupPosition );
Jan Möbius's avatar
Jan Möbius committed
68

Jan Möbius's avatar
 
Jan Möbius committed
69
70
}

71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/** \brief Update context Menu when an arbitrary node has been clicked on.
 *
 * This function is called when a node has been clicked on not belonging to an object.
 * This context menu will show all function relevant for the Node.
 *
 * @param _menu Pointer to the context Menu
 * @param _node node which has been clicked on.
 */
void CoreWidget::updatePopupMenuNode(QMenu* _menu , ACG::SceneGraph::BaseNode* _node) {

  QString nodeName = QString(_node->name().c_str());
  QAction* typeEntry = new QAction( nodeName ,_menu );
  _menu->addAction( typeEntry );

  _menu->addSeparator();

  emit updateContextMenuNode(_node->id());

89
  addContextMenus( _menu , CONTEXTNODEMENU, _node->id() ) ;
90
91
}

Jan Möbius's avatar
Jan Möbius committed
92
/** \brief Update context Menu when Coordsys node has been clicked on.
93
 *
Jan Möbius's avatar
Jan Möbius committed
94
95
96
 * This function is called when the coordinate system in a viewer has been clicked on.
 * This context menu will show all function relevant for the current view like the
 * projection/viewing direction...
97
 *
Jan Möbius's avatar
Jan Möbius committed
98
99
100
 * @param _menu Pointer to the context Menu
 * @param _part id of the coordsys part which has been clicked on.
 */
Jan Möbius's avatar
Jan Möbius committed
101
void CoreWidget::updatePopupMenuCoordsysNode(QMenu* _menu  , const int /*_part*/) {
Jan Möbius's avatar
Jan Möbius committed
102
//   std::cerr << "Coordsys part was : " << _part << std::endl;
Jan Möbius's avatar
Jan Möbius committed
103
104
  QAction* typeEntry = new QAction("Viewer Settings",_menu);
  _menu->addAction( typeEntry );
105
  _menu->addSeparator();
106

Jan Möbius's avatar
Jan Möbius committed
107
  //====================================================================================================
108
109
110
111
  // DrawModes
  //====================================================================================================
  slotUpdateViewerDrawMenu();
  _menu->addMenu( viewerDrawMenu_ );
112

113
114
115
  //====================================================================================================
  // RenderingOptions
  //====================================================================================================
116

117
118
119
  QMenu* renderingOptionsMenu = new QMenu("Rendering Options",_menu);
  renderingOptionsMenu->setIcon(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"renderingOptions.png"));
  _menu->addMenu(renderingOptionsMenu);
120

121
122
123
124
125
126
127
128
129
130
  QAction* projectionAction = 0;
  if ( examiner_widgets_[PluginFunctions::activeExaminer() ]->projectionMode() == glViewer::PERSPECTIVE_PROJECTION ) {
    projectionAction = new QAction( "Switch to Orthogonal Projection", renderingOptionsMenu );
    projectionAction->setIcon( QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"orthogonal.png") );
    projectionAction->setToolTip(   "Switch to perspective orthogonal mode.");
  } else {
    projectionAction = new QAction( "Switch to Perspective Projection", renderingOptionsMenu );
    projectionAction->setIcon( QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"perspective.png") );
    projectionAction->setToolTip(   "Switch to perspective projection mode.");
  }
131

132
133
134
135
136
137
138
139
  projectionAction->setCheckable( false );
  projectionAction->setToolTip(   "Switch between <b>perspective</b> and "
      "<b>parrallel</b> projection mode.");
  projectionAction->setWhatsThis( "Switch projection modes<br><br>"
      "Switch between <b>perspective</b> and "
      "<b>parrallel</b> projection mode.");
  connect( projectionAction,SIGNAL( triggered() ), this, SLOT( slotContextSwitchProjection() ) );
  renderingOptionsMenu->addAction( projectionAction );
140
141


142
  QAction* animation = renderingOptionsMenu->addAction("Animation");
143

144
145
146
147
148
  animation->setToolTip("Animate rotation of objects");
  animation->setCheckable( true );
  animation->setIcon( QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"animation.png") );
  animation->setChecked( PluginFunctions::viewerProperties(PluginFunctions::activeExaminer()).animation() );
  connect(animation, SIGNAL(triggered(bool)), this , SLOT( slotLocalChangeAnimation(bool) ) );
149
150


151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
  //====================================================================================================

  QAction* backfaceCulling = renderingOptionsMenu->addAction("Backface Culling");
  backfaceCulling->setToolTip("Enable backface culling");
  backfaceCulling->setCheckable( true );
  backfaceCulling->setIcon( QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"backFaceCulling.png") );
  backfaceCulling->setChecked( PluginFunctions::viewerProperties().backFaceCulling() );
  connect(backfaceCulling, SIGNAL(triggered(bool)), this , SLOT( slotLocalChangeBackFaceCulling(bool) ) );

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

  QAction* twoSidedLighting = renderingOptionsMenu->addAction("Two-sided Lighting");
  twoSidedLighting->setToolTip("Enable two-sided lighting");
  twoSidedLighting->setCheckable( true );
  twoSidedLighting->setIcon( QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"twosidedLighting.png") );
  twoSidedLighting->setChecked( PluginFunctions::viewerProperties().twoSidedLighting() );
  connect(twoSidedLighting, SIGNAL(triggered(bool)), this , SLOT( slotLocalChangeTwoSidedLighting(bool) ) );
168

169
170
171
  //====================================================================================================
  // Other Toplevel Action
  //====================================================================================================
172

173
  _menu->addSeparator();
174

175
  //====================================================================================================
176

177
178
179
180
181
182
183
184
  QAction* homeAction = new QAction("Restore home view",_menu);
  homeAction->setIcon( QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"go-home.png") );
  homeAction->setCheckable( false );
  homeAction->setToolTip("Restore <b>home</b> view.");
  homeAction->setWhatsThis( "Restore home view<br><br>"
                            "Resets the view to the home view");
  _menu->addAction( homeAction );
  connect( homeAction,SIGNAL( triggered() ), this, SLOT( slotContextHomeView() ) );
185

186
187
188
189
190
191
192
  QAction* setHomeAction = new QAction( "Set Home View" , _menu );
  setHomeAction->setIcon( QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"set-home.png") );
  setHomeAction->setCheckable( false );
  setHomeAction->setToolTip("Set <b>home</b> view");
  setHomeAction->setWhatsThis( "Store home view<br><br>"
                               "Stores the current view as the home view");
  _menu->addAction( setHomeAction);
193
194
  connect( setHomeAction,SIGNAL( triggered() ), this, SLOT( slotContextSetHomeView() ) );

195
196
197
198
199
200
201
202
203
  QAction* viewAllAction = new QAction( "View all", _menu );
  viewAllAction->setIcon( QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"viewall.png") );
  viewAllAction->setCheckable( false );
  viewAllAction->setToolTip("View all.");
  viewAllAction->setWhatsThis( "View all<br><br>"
                               "Move the objects in the scene so that"
                               " the whole scene is visible.");
  connect( viewAllAction,SIGNAL( triggered() ), this, SLOT( slotContextViewAll() ) );
  _menu->addAction( viewAllAction);
204
205


206
  _menu->addSeparator();
207

208
  //====================================================================================================
209

210
211
  QAction* copyView = _menu->addAction("Copy View");
  copyView->setToolTip("Copy current view to clipboard");
Dirk Wilden's avatar
Dirk Wilden committed
212
  copyView->setIcon( QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"edit-copy.png") );
213
214
215
216
217
218
  connect(copyView, SIGNAL(triggered()), this, SLOT(slotCopyView()) );

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

  QAction* pasteView = _menu->addAction("Paste View");
  pasteView->setToolTip("Paste current view from clipboard");
Dirk Wilden's avatar
Dirk Wilden committed
219
  pasteView->setIcon( QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"edit-paste.png") );
220
  connect(pasteView, SIGNAL(triggered()), this , SLOT( slotPasteView( ) ) );
221

222
  //====================================================================================================
223

224
225
226
227
  QAction* snapshot = _menu->addAction("Snapshot");
  snapshot->setToolTip("Make a snapshot");
  snapshot->setIcon( QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"snapshot.png") );
  connect(snapshot, SIGNAL(triggered()), this, SLOT( slotSnapshot() ) );
228

229
230
}

Jan Möbius's avatar
Jan Möbius committed
231
/** \brief Update context Menu when background has been clicked on.
232
 *
Jan Möbius's avatar
Jan Möbius committed
233
 * This function is called when the background in a viewer has been clicked on.
234
 * This context menu will show functions which are related to the background of the
Jan Möbius's avatar
Jan Möbius committed
235
 * viewer.
236
 *
Jan Möbius's avatar
Jan Möbius committed
237
238
239
 * @param _menu Pointer to the context Menu
 * @param _point position in the viewer where the user clicked.
 */
Jan Möbius's avatar
Jan Möbius committed
240
void CoreWidget::updatePopupMenuBackground(QMenu* _menu , const QPoint& /*_point*/) {
241

242
243
244
245
246
247
248
249
  //====================================================================================================
  // DrawModes
  //====================================================================================================
  slotUpdateViewerDrawMenu();
  _menu->addMenu( viewerDrawMenu_ );

  _menu->addSeparator();

Jan Möbius's avatar
Jan Möbius committed
250
251
252
  QAction* action = _menu->addAction("Set Background Color");
  action->setToolTip("Set the background color for the current viewer");
  action->setStatusTip(tr("Set the background color for the current viewer"));
253
  action->setWhatsThis(tr("Set the background color for the current viewer"));
254
  action->setIcon(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"BackgroundColor.png") );
255
  connect(action, SIGNAL(triggered()), this, SLOT(slotSetContextBackgroundColor()) );
256

257
  /*
Mike Kremer's avatar
Mike Kremer committed
258
   * Show coordsys context menu of coordsys if
259
260
261
262
263
264
265
   * invisible...
   */

  ACG::SceneGraph::BaseNode* root = PluginFunctions::getSceneGraphRootNode();
  ACG::SceneGraph::BaseNode* coordSys = root->find("Core Coordsys Node");

  if(!coordSys->visible()) {
266
267

	  if(!coordSysMenu_) {
268
		  coordSysMenu_ = new QMenu("Viewer Settings", _menu);
269
270
		  updatePopupMenuCoordsysNode(coordSysMenu_, 0);
	  }
271
	  _menu->addSeparator();
272
	  _menu->addMenu(coordSysMenu_);
273
274
  }

275
276
277
278
279
  // Tell Plugins to update their context Menu
  emit updateContextMenuBackground();

  addContextMenus( _menu , CONTEXTBACKGROUNDMENU ) ;

Jan Möbius's avatar
Jan Möbius committed
280
}
Jan Möbius's avatar
Jan Möbius committed
281

Jan Möbius's avatar
Jan Möbius committed
282
/** \brief Update context Menu an object has been clicked on.
283
 *
Jan Möbius's avatar
Jan Möbius committed
284
285
 * This function is called when an object has been clicked on.
 * This context menu will show all properties for the given object.
286
 *
Jan Möbius's avatar
Jan Möbius committed
287
288
289
 * @param _menu Pointer to the context Menu
 * @param _objectId Id of the object that has been clicked on.
 */
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
void CoreWidget::updatePopupMenuObject(QMenu* _menu , BaseObjectData* _object ) {

  QAction* typeEntry = new QAction( typeName(_object->dataType()) ,_menu);
  typeEntry->setIcon(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+ typeIcon(_object->dataType()) ));
  _menu->addAction( typeEntry );

  _menu->addSeparator( );

  // Tell Plugins to update their context Menu
  emit updateContextMenu(_object->id() );

  if ( addContextMenus( _menu , CONTEXTOBJECTMENU , _object->id() ) )
    _menu->addSeparator();

  // Add picking Menu
305
306
307
308
  if (pickMenu_ != 0 && pickMenu_->actions().size() > 0) {
    pickMenu_->setTitle("&Picking");
    contextMenu_->addMenu( pickMenu_ );
    pickMenu_->setTearOffEnabled(true);
309
310
311
312
313
314
315
  }
}

bool CoreWidget::addContextMenus( QMenu* _menu , ContextMenuType _type , int _id ) {

  bool added = false;

316
317
318
  QMap< QString , QAction* > menuMap; //QMap sorts by key
  QMap< QString , QAction* > actionMap;

319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
  // Add context menus from plugins
  for ( uint i = 0 ; i < contextMenus_.size(); ++i ) {

    if ( contextMenus_[i].type != _type )
      continue;

    switch (contextMenus_[i].type) {
      case CONTEXTBACKGROUNDMENU:
        break;
      case CONTEXTOBJECTMENU:
        BaseObjectData* object;
        if ( !PluginFunctions::getObject(_id, object) ) {
          emit log(LOGERR,"Cant get object for objectContextMenu");
          continue;
        }

        // Datatype does not match
        if ( ! object->dataType(  contextMenus_[i].contextType ) )
          continue;

        break;
      case CONTEXTNODEMENU:
        break;

    }

345
346
347
348
349
350
    QMenu* menu = contextMenus_[i].action->menu();

    if (menu == 0) //is it a menu
      actionMap[ contextMenus_[i].action->text() ] = contextMenus_[i].action;
    else
      menuMap[ contextMenus_[i].action->text() ] = contextMenus_[i].action;
351
352
353
354
355

    added = true;

    // Get all Actions in the menu and its submenus.
    // Set their data to the picked Object id
356

Jan Möbius's avatar
 
Jan Möbius committed
357
358
359
360
361
362
363
364

    QList< QAction *> allActions;
    if ( menu == 0) {
      allActions.push_back(contextMenus_[i].action);
    } else {
      allActions = menu->actions();
    }

365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
    while ( !allActions.empty() ) {
      QList< QAction *> tmpList;

      // Set userdata of all actions to the picked Object Id
      for ( int j = 0 ; j < allActions.size(); ++j ) {
        allActions[j]->setData( QVariant( _id ) );
        if ( allActions[j]->menu() != 0 )
          tmpList << allActions[j]->menu()->actions();
      }

      allActions = tmpList;
    }

  }

380
381
382
383
384
385
386
387
388
389
390
391
  //first add all menus
  QMapIterator<QString, QAction*> it(menuMap);

  while (it.hasNext()) {
     it.next();
    _menu->addAction( it.value() );
  }

  _menu->addSeparator();

  //then all actions
  QMapIterator<QString, QAction*> it2(actionMap);
392

393
394
395
396
397
398
  while (it2.hasNext()) {
     it2.next();
    _menu->addAction( it2.value() );
  }

  return added;
Jan Möbius's avatar
Jan Möbius committed
399
}
Jan Möbius's avatar
Jan Möbius committed
400
401
402



403
404
405
/** \brief check current context and initialize context menu according to this context.
 *
 * This function is called whenever a context menu for the corewidget is requested.
Jan Möbius's avatar
Jan Möbius committed
406
407
408
409
 * It will decide about the current context, collect all menus for plugins and
 * construct the final context menu.
 */
void CoreWidget::updatePopupMenu(const QPoint& _point) {
Jan Möbius's avatar
Jan Möbius committed
410

Jan Möbius's avatar
Jan Möbius committed
411
412
  // Clear the complete context menu.
  contextMenu_->clear();
413

Jan Möbius's avatar
Jan Möbius committed
414
415
  // Clear the selection context menu part.
  contextSelectionMenu_->clear();
Jan Möbius's avatar
Jan Möbius committed
416

Jan Möbius's avatar
Jan Möbius committed
417
418
419
  // =============================================================================
  // First do a picking on the current position to check which context we are in.
  // =============================================================================
Jan Möbius's avatar
 
Jan Möbius committed
420
  int objectId = -1;
421

Jan Möbius's avatar
Jan Möbius committed
422
  enum CONTEXTTYPE {
423
    COORDSYSCONTEXT ,BACKGROUNDCONTEXT ,OBJECTCONTEXT, NODECONTEXT
Jan Möbius's avatar
Jan Möbius committed
424
  } context = BACKGROUNDCONTEXT;
Jan Möbius's avatar
Jan Möbius committed
425

Jan Möbius's avatar
 
Jan Möbius committed
426
  // Do picking in the gl area to find an object
427
428
429
430
431
  unsigned int               node_idx, target_idx;
  ACG::Vec3d                 hit_point;
  BaseObjectData*            object;
  ACG::SceneGraph::BaseNode* node = 0;

432
  if (examiner_widgets_[PluginFunctions::activeExaminer()]->pick( ACG::SceneGraph::PICK_ANYTHING,_point,node_idx, target_idx, &hit_point ) ) {
433

Jan Möbius's avatar
Jan Möbius committed
434
    if ( PluginFunctions::getPickedObject(node_idx, object) ) {
Jan Möbius's avatar
 
Jan Möbius committed
435
      objectId = object->id();
Jan Möbius's avatar
Jan Möbius committed
436
437
      context  = OBJECTCONTEXT;
    } else {
438
439
      node = ACG::SceneGraph::find_node( PluginFunctions::getSceneGraphRootNode() , node_idx );
      if ( node != 0 && ( node->name() == "Core Coordsys Node") )
Jan Möbius's avatar
Jan Möbius committed
440
        context = COORDSYSCONTEXT;
441
442
      else
        context = NODECONTEXT;
443
    }
444
445
  }

Jan Möbius's avatar
Jan Möbius committed
446
447
448
  // =============================================================================
  // Depending on the context create the basic context menu.
  // =============================================================================
449

Jan Möbius's avatar
Jan Möbius committed
450
  QIcon icon;
451

Jan Möbius's avatar
Jan Möbius committed
452
453
454
  switch (context) {
    case BACKGROUNDCONTEXT:
      updatePopupMenuBackground(contextMenu_,_point);
455
      return;
Jan Möbius's avatar
Jan Möbius committed
456
457
      break;
    case OBJECTCONTEXT:
458
459
      updatePopupMenuObject(contextMenu_ , object );
//       return;
Jan Möbius's avatar
Jan Möbius committed
460
461
462
      break;
    case COORDSYSCONTEXT:
      updatePopupMenuCoordsysNode(contextMenu_,target_idx);
463
      return;
Jan Möbius's avatar
Jan Möbius committed
464
      break;
465
466
467
468
    case NODECONTEXT:
      updatePopupMenuNode(contextMenu_,node);
      return;
      break;
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
void CoreWidget::slotSnapshotName() {
  std::cerr << "Todo : slotSnapShotName only sets name for current viewer" << std::endl;
476
477
478
479
480
481
482
483
484
485
486
487
488
489

  QString fname = PluginFunctions::viewerProperties().snapshotName();

  fname.replace('%', '$');
  fname = QFileDialog::getSaveFileName ( 0, "Save snapshot name" );
  if (!fname.isEmpty())
  {
    fname.replace('$', '%');

    PluginFunctions::viewerProperties().snapshotBaseFileName(fname);
    QString msg="next snapshot: ";
    statusBar()->showMessage(msg);
  }

490
491
}

Jan Möbius's avatar
 
Jan Möbius committed
492
void CoreWidget::slotAddContextItem(QAction* _entry, ContextMenuType _type) {
Jan Möbius's avatar
 
Jan Möbius committed
493
  MenuInfo info;
Jan Möbius's avatar
 
Jan Möbius committed
494
495
  info.action = _entry;
  info.type   = _type;
Jan Möbius's avatar
Jan Möbius committed
496

497
  contextMenus_.push_back(info);
Jan Möbius's avatar
 
Jan Möbius committed
498
499
}

Jan Möbius's avatar
 
Jan Möbius committed
500
void CoreWidget::slotAddContextItem( QAction* _entry , DataType _dataType ,ContextMenuType _type ) {
Jan Möbius's avatar
 
Jan Möbius committed
501
  MenuInfo info;
Jan Möbius's avatar
 
Jan Möbius committed
502
  info.action      = _entry;
Jan Möbius's avatar
 
Jan Möbius committed
503
  info.contextType = _dataType;
Jan Möbius's avatar
 
Jan Möbius committed
504
  info.type        = _type;
Jan Möbius's avatar
Jan Möbius committed
505

Jan Möbius's avatar
 
Jan Möbius committed
506
507
508
  contextMenus_.push_back(info);
}

509
510
void CoreWidget::slotUpdateViewerDrawMenu() {
  if ( drawGroupViewer_ ) {
511

512
513
514
515
    disconnect( drawGroupViewer_ , SIGNAL( triggered( QAction * ) ),
                this             , SLOT( slotViewerDrawMenu( QAction * ) ) );
    delete( drawGroupViewer_ );
    drawGroupViewer_ = 0;
516

517
  }
518

519
520
521
  // Recreate drawGroup
  drawGroupViewer_ = new QActionGroup( this );
  drawGroupViewer_->setExclusive( false );
522

523
  connect( drawGroupViewer_ , SIGNAL( triggered( QAction * ) ),
524
525
           this       , SLOT( slotViewerDrawMenu( QAction * ) ) );

526
  if ( !viewerDrawMenu_ ) {
527

528
529
    QIcon icon;
    icon.addFile(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"drawModes.png");
530
    viewerDrawMenu_  = new QMenu("Set Draw Mode");
531
532
    viewerDrawMenu_->setTearOffEnabled(true);
    viewerDrawMenu_->setIcon(icon);
533

534
535
    connect(viewerDrawMenu_,SIGNAL(aboutToShow () ) , this, SLOT(slotUpdateGlobalDrawMenu() ) );
  }
536
537

  // Collect available draw Modes
538
539
540
  ACG::SceneGraph::CollectDrawModesAction actionAvailable;
  ACG::SceneGraph::traverse( PluginFunctions::getRootNode() , actionAvailable);
  availableGlobalDrawModes_ = actionAvailable.drawModes();
541

542
543
544
  // Get currently active drawModes (first viewer only )
  // TODO: create combination from all viewers!
  int activeDrawModes = PluginFunctions::drawMode();
545

546
547
548
  // Convert to ids
  std::vector< unsigned int > availDrawModeIds;
  availDrawModeIds = ACG::SceneGraph::DrawModes::getDrawModeIDs( availableGlobalDrawModes_ );
549

550
  viewerDrawMenu_->clear();
551

552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
  for ( unsigned int i = 0; i < availDrawModeIds.size(); ++i )
  {
    unsigned int id    = availDrawModeIds[i];
    std::string  descr = ACG::SceneGraph::DrawModes::description( id );

    QAction * action = new QAction( descr.c_str(), drawGroupViewer_ );
    action->setCheckable( true );
    action->setChecked( ACG::SceneGraph::DrawModes::containsId( activeDrawModes, id ) );
  }

  viewerDrawMenu_->addActions( drawGroupViewer_->actions() );

}

void CoreWidget::slotViewerDrawMenu(QAction * _action) {
567

568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
  //======================================================================================
  // Get the mode toggled
  //======================================================================================
  unsigned int mode = 0;
  std::vector< unsigned int > availDrawModeIds;
  availDrawModeIds = ACG::SceneGraph::DrawModes::getDrawModeIDs( availableGlobalDrawModes_ );
  for ( unsigned int i = 0; i < availDrawModeIds.size(); ++i )
  {
    QString descr = QString( ACG::SceneGraph::DrawModes::description( availDrawModeIds[i] ).c_str() );

    if ( descr == _action->text() ) {
      mode = availDrawModeIds[i];
      break;
    }
  }
583

584
585
586
587
  if ( qApp->keyboardModifiers() & Qt::ShiftModifier )
    PluginFunctions::viewerProperties().drawMode(  PluginFunctions::viewerProperties().drawMode() ^ mode );
  else
    PluginFunctions::viewerProperties().drawMode(mode );
588

589
590
}

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