MenuBar.cc 22.7 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.
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.
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
//  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/common/GlobalOptions.hh>
Jan Möbius's avatar
Jan Möbius committed
47
#include <OpenFlipper/BasePlugin/PluginFunctions.hh>
Jan Möbius's avatar
 
Jan Möbius committed
48

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



Jan Möbius's avatar
 
Jan Möbius committed
53
void CoreWidget::slotAddMenubarAction( QAction* _action , MenuActionType _type ) {
54

Jan Möbius's avatar
 
Jan Möbius committed
55
  switch (_type) {
56
    case TOPLEVELMENU :
Jan Möbius's avatar
 
Jan Möbius committed
57
      // Add it to the menubar as a top level Menu
Jan Möbius's avatar
 
Jan Möbius committed
58
      menuBar()->insertAction(helpMenu_->menuAction() ,_action);
Jan Möbius's avatar
 
Jan Möbius committed
59 60 61
      break;
    case FILEMENU :
      fileMenu_->insertSeparator(fileMenuEnd_);
Jan Möbius's avatar
 
Jan Möbius committed
62
      fileMenu_->insertAction( fileMenuEnd_ , _action );
Jan Möbius's avatar
 
Jan Möbius committed
63 64
      break;
    case VIEWMENU :
Jan Möbius's avatar
 
Jan Möbius committed
65
      viewMenu_->addAction( _action );
66
      break;
Jan Möbius's avatar
 
Jan Möbius committed
67 68
    case TOOLSMENU:
      toolsMenu_->addAction( _action );
Jan Möbius's avatar
 
Jan Möbius committed
69
  }
70

Jan Möbius's avatar
 
Jan Möbius committed
71 72 73 74 75 76 77 78 79 80 81 82 83
}


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


void CoreWidget::setupMenuBar()
{
  // ======================================================================
  // File Menu
  // ======================================================================
  fileMenu_ = new QMenu(tr("&File"));
  menuBar()->addMenu(fileMenu_ );
Jan Möbius's avatar
 
Jan Möbius committed
84

Jan Möbius's avatar
 
Jan Möbius committed
85 86 87 88
  //Clear all
  QAction* AC_clear_all = new QAction(tr("&Clear All"), this);;
  AC_clear_all->setStatusTip(tr("Clear all Objects"));
  AC_clear_all->setWhatsThis("Close all open Objects");
89
  AC_clear_all->setIcon(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"edit-clear.png"));
Jan Möbius's avatar
 
Jan Möbius committed
90 91
  connect(AC_clear_all, SIGNAL(triggered()), this, SIGNAL(clearAll()));
  fileMenu_->addAction(AC_clear_all);
92

Jan Möbius's avatar
 
Jan Möbius committed
93
  fileMenu_->addSeparator();
94 95

  //Load object
Jan Möbius's avatar
 
Jan Möbius committed
96
  QAction* AC_Load = new QAction(tr("&Load Object"), this);
Dirk Wilden's avatar
Dirk Wilden committed
97
//   AC_Load->setShortcut (Qt::CTRL + Qt::Key_O);
Jan Möbius's avatar
 
Jan Möbius committed
98 99
  AC_Load->setStatusTip(tr("Load an object"));
  AC_Load->setWhatsThis("Load a new object");
100
  AC_Load->setIcon(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"document-open.png"));
101

Jan Möbius's avatar
 
Jan Möbius committed
102 103
  connect(AC_Load, SIGNAL(triggered()), this, SIGNAL(loadMenu()));
  fileMenu_->addAction(AC_Load);
104

Jan Möbius's avatar
 
Jan Möbius committed
105 106 107 108
  //Add empty object
  QAction* AC_AddEmpty = new QAction(tr("&Add Empty Object"), this);
  AC_AddEmpty->setStatusTip(tr("Add an empty object"));
  AC_AddEmpty->setWhatsThis("Creates a new empty object of a given type");
109
  AC_AddEmpty->setIcon(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"add-empty-object.png"));
Jan Möbius's avatar
 
Jan Möbius committed
110 111
  connect(AC_AddEmpty, SIGNAL(triggered()), this, SIGNAL(addEmptyObjectMenu()));
  fileMenu_->addAction(AC_AddEmpty);
112

Jan Möbius's avatar
 
Jan Möbius committed
113
  fileMenu_->addSeparator();
114

Jan Möbius's avatar
 
Jan Möbius committed
115 116
  //Save object
  QAction* AC_Save = new QAction(tr("&Save Object"), this);
Dirk Wilden's avatar
Dirk Wilden committed
117
//   AC_Save->setShortcut (Qt::CTRL + Qt::Key_S);
Dirk Wilden's avatar
Dirk Wilden committed
118
  AC_Save->setStatusTip(tr("Save currently selected objects"));
Jan Möbius's avatar
 
Jan Möbius committed
119
  AC_Save->setWhatsThis("Saves all currently selected objects");
120
  AC_Save->setIcon(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"document-save.png"));
Jan Möbius's avatar
 
Jan Möbius committed
121 122
  connect(AC_Save, SIGNAL(triggered()), this, SIGNAL(saveMenu()));
  fileMenu_->addAction(AC_Save);
123

Jan Möbius's avatar
 
Jan Möbius committed
124 125 126 127
  //Save object to
  QAction* AC_Save_to = new QAction(tr("&Save Object To"), this);
  AC_Save_to->setStatusTip(tr("Save current Object(s) To"));
  AC_Save_to->setWhatsThis("Saves all currently selected objects under a new name");
128
  AC_Save_to->setIcon(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"document-save-as.png"));
Jan Möbius's avatar
 
Jan Möbius committed
129 130
  connect(AC_Save_to, SIGNAL(triggered()), this, SIGNAL(saveToMenu()));
  fileMenu_->addAction(AC_Save_to);
131

Jan Möbius's avatar
 
Jan Möbius committed
132
  fileMenu_->addSeparator();
133

Jan Möbius's avatar
 
Jan Möbius committed
134 135 136 137
  //Load ini
  QAction* AC_load_ini = new QAction(tr("&Load Settings"), this);
  AC_load_ini->setStatusTip(tr("Load Settings from INI file"));
  AC_load_ini->setWhatsThis("Load a previous settings from file (objects,colors,...)");
138
  AC_load_ini->setIcon(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"load-settings.png"));
Jan Möbius's avatar
 
Jan Möbius committed
139 140
  connect(AC_load_ini, SIGNAL(triggered()), this, SIGNAL(loadIniMenu()));
  fileMenu_->addAction(AC_load_ini);
141

Jan Möbius's avatar
 
Jan Möbius committed
142 143 144 145
  //Save ini
  QAction* AC_save_ini = new QAction(tr("&Save Settings"), this);
  AC_save_ini->setStatusTip(tr("Save current settings to INI file"));
  AC_save_ini->setWhatsThis("Save settings to file (objects,colors,...)");
146
  AC_save_ini->setIcon(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"save-settings.png"));
Jan Möbius's avatar
 
Jan Möbius committed
147 148
  connect(AC_save_ini, SIGNAL(triggered()), this, SIGNAL(saveIniMenu()));
  fileMenu_->addAction(AC_save_ini);
149 150 151 152 153 154 155

  fileMenu_->addSeparator();

  //Options
  QAction* AC_Options = new QAction(tr("&Options"), this);
  AC_Options->setStatusTip(tr("Edit OpenFlipper Options"));
  AC_Options->setWhatsThis("Edit OpenFlipper Options");
156
  AC_Options->setIcon(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"options.png"));
157 158
  connect(AC_Options, SIGNAL(triggered()), this, SLOT(showOptionsWidget()));
  fileMenu_->addAction(AC_Options);
159 160

  //Remember entry of menu (required for adding File Menu entries from plugins)
Jan Möbius's avatar
 
Jan Möbius committed
161
  fileMenuEnd_ = fileMenu_->addSeparator();
162

Jan Möbius's avatar
 
Jan Möbius committed
163 164
  //Recent files
  recentFilesMenu_ = new QMenu(tr("&Recent Files"));
165
  recentFilesMenu_->setIcon(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"document-open-recent.png"));
Jan Möbius's avatar
 
Jan Möbius committed
166 167 168
  recentFilesMenu_->setWhatsThis("Open recent files");
  connect(recentFilesMenu_,SIGNAL(triggered(QAction*)),this,SIGNAL(recentOpen(QAction*)));
  fileMenu_->addMenu(recentFilesMenu_);
169

Jan Möbius's avatar
 
Jan Möbius committed
170
  fileMenu_->addSeparator();
171

Jan Möbius's avatar
 
Jan Möbius committed
172 173 174 175 176
  //Main Application exit menu entry
  QAction* AC_exit = new QAction(tr("&Exit"), this);;
  AC_exit->setShortcut (Qt::CTRL + Qt::Key_Q);
  AC_exit->setStatusTip(tr("Exit Application"));
  recentFilesMenu_->setWhatsThis("Close OpenFlipper");
177
  AC_exit->setIcon(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"application-exit.png"));
Jan Möbius's avatar
 
Jan Möbius committed
178 179 180
  connect(AC_exit, SIGNAL(triggered()), this, SIGNAL(exit()));
  fileMenu_->addAction(AC_exit);

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

182 183 184 185 186
  // ======================================================================
  // View Menu
  // ======================================================================
  viewMenu_ = new QMenu(tr("&View"));
  menuBar()->addMenu(viewMenu_ );
Jan Möbius's avatar
 
Jan Möbius committed
187

188 189
  slotUpdateGlobalDrawMenu();
  viewMenu_->addMenu(globalDrawMenu_);
Jan Möbius's avatar
 
Jan Möbius committed
190

191 192 193
  //============================================================================================================
  // Rendering options Menu
  //============================================================================================================
Jan Möbius's avatar
 
Jan Möbius committed
194

195 196 197
  QMenu* renderingOptionsMenu = new QMenu("Rendering Options",viewMenu_);
  renderingOptionsMenu->setIcon(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"renderingOptions.png"));
  viewMenu_->addMenu(renderingOptionsMenu);
Jan Möbius's avatar
 
Jan Möbius committed
198

199 200 201 202 203
  orthogonalProjectionAction_ = new QAction( "Switch Viewers to Orthogonal Projection", renderingOptionsMenu );;
  orthogonalProjectionAction_->setIcon( QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"orthogonal.png") );
  orthogonalProjectionAction_->setCheckable( false );
  orthogonalProjectionAction_->setToolTip(   "Switch to orthogonal projection mode.");
  orthogonalProjectionAction_->setWhatsThis( "Switch projection mode<br><br>"
Jan Möbius's avatar
 
Jan Möbius committed
204
      "Switch to <b>orthogonal</b> projection mode.");
205 206
  connect( orthogonalProjectionAction_,SIGNAL( triggered() ), this, SLOT( slotGlobalOrthographicProjection() ) );
  renderingOptionsMenu->addAction( orthogonalProjectionAction_);
Jan Möbius's avatar
 
Jan Möbius committed
207

208
  QAction* animation = renderingOptionsMenu->addAction("Animation");
Jan Möbius's avatar
 
Jan Möbius committed
209

210 211 212 213 214
  uint enabledCount = 0;
  uint disabledCount = 0;
  for ( int i = 0 ; i< PluginFunctions::viewers(); ++i ) {
    if ( PluginFunctions::viewerProperties(i).animation() )
      enabledCount++;
Jan Möbius's avatar
 
Jan Möbius committed
215
    else
216 217
      disabledCount++;
  }
Jan Möbius's avatar
 
Jan Möbius committed
218

219
  if ( enabledCount != 0 && disabledCount != 0 )
Jan Möbius's avatar
 
Jan Möbius committed
220
    animation->setChecked(Qt::PartiallyChecked);
221 222 223 224
  else if ( enabledCount == 4 )
    animation->setChecked( Qt::Checked );
  else
    animation->setChecked( Qt::Unchecked );
Jan Möbius's avatar
 
Jan Möbius committed
225

226 227 228 229
  animation->setToolTip("Animate rotation of objects");
  animation->setCheckable( true );
  animation->setIcon( QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"animation.png") );
  connect(animation, SIGNAL(triggered(bool)), this , SLOT( slotGlobalChangeAnimation(bool) ) );
Jan Möbius's avatar
 
Jan Möbius committed
230 231


232
  //======================
Jan Möbius's avatar
 
Jan Möbius committed
233

234
  QAction* backfaceCulling = renderingOptionsMenu->addAction("Backface Culling");
Jan Möbius's avatar
 
Jan Möbius committed
235

236 237 238 239 240
  enabledCount  = 0;
  disabledCount = 0;
  for ( int i = 0 ; i< PluginFunctions::viewers(); ++i ) {
    if ( PluginFunctions::viewerProperties(i).backFaceCulling() )
      enabledCount++;
Jan Möbius's avatar
 
Jan Möbius committed
241
    else
242 243
      disabledCount++;
  }
Jan Möbius's avatar
 
Jan Möbius committed
244

245
  if ( enabledCount != 0 && disabledCount != 0 )
Jan Möbius's avatar
 
Jan Möbius committed
246
    backfaceCulling->setChecked(Qt::PartiallyChecked);
247 248 249 250
  else if ( enabledCount == 4 )
    backfaceCulling->setChecked( Qt::Checked );
  else
    backfaceCulling->setChecked( Qt::Unchecked );
Jan Möbius's avatar
 
Jan Möbius committed
251

252 253 254 255 256 257 258 259
  backfaceCulling->setToolTip("Enable backface culling");
  backfaceCulling->setCheckable( true );
  backfaceCulling->setIcon( QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"backFaceCulling.png") );
  connect(backfaceCulling, SIGNAL(triggered(bool)), this , SLOT( slotGlobalChangeBackFaceCulling(bool) ) );

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

  QAction* twoSidedLighting = renderingOptionsMenu->addAction("Two-sided Lighting");
Jan Möbius's avatar
 
Jan Möbius committed
260

261
  enabledCount  = 0;
Jan Möbius's avatar
 
Jan Möbius committed
262
  disabledCount = 0;
263 264 265
  for ( int i = 0 ; i< PluginFunctions::viewers(); ++i ) {
    if ( PluginFunctions::viewerProperties(i).twoSidedLighting() )
      enabledCount++;
Jan Möbius's avatar
 
Jan Möbius committed
266
    else
267 268
      disabledCount++;
  }
Jan Möbius's avatar
 
Jan Möbius committed
269

270
  if ( enabledCount != 0 && disabledCount != 0 )
Jan Möbius's avatar
 
Jan Möbius committed
271
    twoSidedLighting->setChecked(Qt::PartiallyChecked);
272 273 274 275
  else if ( enabledCount == 4 )
    twoSidedLighting->setChecked( Qt::Checked );
  else
    twoSidedLighting->setChecked( Qt::Unchecked );
Jan Möbius's avatar
 
Jan Möbius committed
276

277 278 279 280 281
  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( slotGlobalChangeTwoSidedLighting(bool) ) );
Jan Möbius's avatar
 
Jan Möbius committed
282

283 284 285
  //============================================================================================================
  // Other toplevel actions
  //============================================================================================================
Jan Möbius's avatar
 
Jan Möbius committed
286

287
  viewMenu_->addSeparator();
Jan Möbius's avatar
 
Jan Möbius committed
288

289
  connect( viewMenu_,SIGNAL( aboutToShow() ), this, SLOT( slotViewMenuAboutToShow() ) );
Jan Möbius's avatar
 
Jan Möbius committed
290

291 292 293 294 295 296 297 298
  QAction* homeAction = new QAction("Restore Home View",viewMenu_);
  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");
  viewMenu_->addAction( homeAction );
  connect( homeAction,SIGNAL( triggered() ), this, SLOT( slotGlobalHomeView() ) );
Jan Möbius's avatar
 
Jan Möbius committed
299 300


301 302 303 304 305 306 307 308
  QAction* setHomeAction = new QAction( "Set Home View" , viewMenu_ );
  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");
  viewMenu_->addAction( setHomeAction);
  connect( setHomeAction,SIGNAL( triggered() ), this, SLOT( slotGlobalSetHomeView() ) );
Jan Möbius's avatar
 
Jan Möbius committed
309

310 311 312 313 314 315 316 317 318
  QAction* viewAllAction = new QAction( "View all", viewMenu_ );
  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( slotGlobalViewAll() ) );
  viewMenu_->addAction( viewAllAction);
Jan Möbius's avatar
 
Jan Möbius committed
319

Dirk Wilden's avatar
Dirk Wilden committed
320
  viewMenu_->addSeparator();
Dirk Wilden's avatar
Dirk Wilden committed
321

Dirk Wilden's avatar
Dirk Wilden committed
322 323 324 325 326 327 328 329
  QAction* snapShotAction = new QAction( "Viewer Snapshot", viewMenu_ );
  snapShotAction->setIcon( QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"viewerSnapshot.png") );
  snapShotAction->setCheckable( false );
  snapShotAction->setToolTip("Take a snapshot from all viewers.");
  snapShotAction->setWhatsThis( "Viewer Snapshot<br><br>"
                               "Take a snapshot of all viewers at once.");
  connect( snapShotAction,SIGNAL( triggered() ), this, SLOT( viewerSnapshotDialog() ) );
  viewMenu_->addAction( snapShotAction);
Dirk Wilden's avatar
Dirk Wilden committed
330

Dirk Wilden's avatar
Dirk Wilden committed
331
  QAction* appSnapShotAction = new QAction( "Application Snapshot", viewMenu_ );
Dirk Wilden's avatar
Dirk Wilden committed
332 333 334 335 336 337 338 339
  appSnapShotAction->setIcon( QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"snapshot.png") );
  appSnapShotAction->setCheckable( false );
  appSnapShotAction->setToolTip("Take a snapshot from OpenFlipper.");
  appSnapShotAction->setWhatsThis( "Snapshot<br><br>"
                               "Take a snapshot from OpenFlipper.");
  connect( appSnapShotAction,SIGNAL( triggered() ), this, SLOT( applicationSnapshotDialog() ) );
  viewMenu_->addAction( appSnapShotAction);

340 341 342 343 344 345 346 347
  perspectiveProjectionAction_ = new QAction( "Switch Viewers to Perspective Projection", viewMenu_ );;
  perspectiveProjectionAction_->setIcon( QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"perspective.png") );
  perspectiveProjectionAction_->setCheckable( false );
  perspectiveProjectionAction_->setToolTip(   "Switch to perspective projection mode.");
  perspectiveProjectionAction_->setWhatsThis( "Switch projection mode<br><br>"
                                              "Switch to <b>perspective</b> projection mode.");
  connect( perspectiveProjectionAction_,SIGNAL( triggered() ), this, SLOT( slotGlobalPerspectiveProjection() ) );
  viewMenu_->addAction( perspectiveProjectionAction_);
Jan Möbius's avatar
 
Jan Möbius committed
348 349 350



351
  viewMenu_->addSeparator();
Jan Möbius's avatar
 
Jan Möbius committed
352

353 354 355 356 357 358 359
  QAction* setGlobalBackgroundColor = new QAction(tr("&Set Background Color"), this);;
  setGlobalBackgroundColor->setToolTip(tr("Set Background Color for all viewers"));
  setGlobalBackgroundColor->setStatusTip(tr("Set Background Color for all viewers"));
  setGlobalBackgroundColor->setWhatsThis("Set Background Color for all viewers");
  setGlobalBackgroundColor->setIcon(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"BackgroundColor.png") );
  connect(setGlobalBackgroundColor, SIGNAL(triggered()), this, SLOT(slotSetGlobalBackgroundColor()));
  viewMenu_->addAction(setGlobalBackgroundColor);
Jan Möbius's avatar
 
Jan Möbius committed
360

361 362 363
  //===========================================================================================================================
  // Tools Menu
  //===========================================================================================================================
Jan Möbius's avatar
 
Jan Möbius committed
364

365 366
  toolsMenu_ = new QMenu(tr("&Tools"));
  menuBar()->addMenu(toolsMenu_ );
Jan Möbius's avatar
 
Jan Möbius committed
367

368 369 370 371 372 373 374 375 376 377
  QAction* sceneGraphAction = new QAction( "Show SceneGraph " ,toolsMenu_ );
  sceneGraphAction->setIcon( QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"scenegraph.png") );
  sceneGraphAction->setCheckable( false );
  sceneGraphAction->setToolTip("Show scene graph viewer.");
  sceneGraphAction->setWhatsThis( "Toggle scene graph viewer<br><br>"
                                  "The scene graph viewer enables you to examine the "
                                  "displayed scene graph and to modify certain nodes.<br><br>" );
  QObject::connect( sceneGraphAction, SIGNAL( triggered() ),
                    this,             SLOT( slotShowSceneGraphDialog() ) );
  toolsMenu_->addAction( sceneGraphAction);
Jan Möbius's avatar
 
Jan Möbius committed
378

Jan Möbius's avatar
 
Jan Möbius committed
379 380 381 382 383
  // ======================================================================
  // help Menu
  // ======================================================================
  helpMenu_ = new QMenu(tr("&Help"));
  menuBar()->addMenu(helpMenu_);
384

Jan Möbius's avatar
 
Jan Möbius committed
385
  //Open Help Browser
386 387
  QAction* AC_HelpBrowser = new QAction(tr("&Help"), this);
  AC_HelpBrowser->setStatusTip(tr("Open Help Browser with Documentation"));
388
  AC_HelpBrowser->setIcon(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"help-browser.png"));
Jan Möbius's avatar
 
Jan Möbius committed
389
  AC_HelpBrowser->setWhatsThis("Open the <b>Help Browser</b>");
390
  connect(AC_HelpBrowser, SIGNAL(triggered()), this, SLOT(showHelpBrowser()));
Jan Möbius's avatar
 
Jan Möbius committed
391
  helpMenu_->addAction(AC_HelpBrowser);
392

Jan Möbius's avatar
 
Jan Möbius committed
393 394 395 396 397
  //Switch to whats this mode
  QAction* AC_Whats_this = QWhatsThis::createAction ( this );
  AC_Whats_this->setStatusTip(tr("Enter What's this Mode"));
  AC_Whats_this->setWhatsThis("Get information about a specific Button/Widget/...");
  helpMenu_->addAction(AC_Whats_this);
398

Jan Möbius's avatar
 
Jan Möbius committed
399
  helpMenu_->addSeparator();
400

Dirk Wilden's avatar
Dirk Wilden committed
401 402 403 404
  //show plugins
  QAction* AC_Plugins = new QAction(tr("&Plugins"), this);
  AC_Plugins->setStatusTip(tr("Show loaded plugins"));
  AC_Plugins->setWhatsThis("Show loaded plugins");
405
  AC_Plugins->setIcon(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"network-connect.png"));
Dirk Wilden's avatar
Dirk Wilden committed
406 407 408 409 410
  connect(AC_Plugins, SIGNAL(triggered()), this, SIGNAL(showPlugins()));
  helpMenu_->addAction(AC_Plugins);

  helpMenu_->addSeparator();

Jan Möbius's avatar
 
Jan Möbius committed
411 412 413
  //About Action
  QAction* AC_About = new QAction(tr("&About"), this);
  AC_About->setStatusTip(tr("About OpenFlipper"));
414
  AC_About->setIcon(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"help-about.png"));
Jan Möbius's avatar
 
Jan Möbius committed
415
  AC_About->setWhatsThis("This entry shows information about <b>OpenFlipper</b>");
Jan Möbius's avatar
Jan Möbius committed
416
  connect(AC_About, SIGNAL(triggered()), this, SLOT(showAboutWidget()));
Jan Möbius's avatar
 
Jan Möbius committed
417
  helpMenu_->addAction(AC_About);
418

Jan Möbius's avatar
 
Jan Möbius committed
419 420 421 422 423 424 425 426 427
  // Add Menu entries to the main Toolbar
  mainToolbar_->addAction(AC_Load);
  mainToolbar_->addAction(AC_AddEmpty);
  mainToolbar_->addSeparator();
  mainToolbar_->addAction(AC_Save);
  mainToolbar_->addAction(AC_Save_to);
  mainToolbar_->addSeparator();
  mainToolbar_->addAction(AC_load_ini);
  mainToolbar_->addAction(AC_save_ini);
428

Jan Möbius's avatar
 
Jan Möbius committed
429 430
}

431
void CoreWidget::slotViewMenuAboutToShow() {
Jan Möbius's avatar
 
Jan Möbius committed
432

433 434
  uint perspectiveCount = 0;
  uint orthogonalCount = 0;
Jan Möbius's avatar
 
Jan Möbius committed
435

436 437 438 439 440 441
  for ( int i = 0 ; i < PluginFunctions::viewers() ; ++i ) {
    if ( examiner_widgets_[ i ]->projectionMode() == glViewer::PERSPECTIVE_PROJECTION )
      perspectiveCount++;
    else
      orthogonalCount++;
  }
Jan Möbius's avatar
 
Jan Möbius committed
442 443

  if ( perspectiveCount == 4 )
444 445 446
    perspectiveProjectionAction_->setVisible(false);
  else
    perspectiveProjectionAction_->setVisible(true);
Jan Möbius's avatar
 
Jan Möbius committed
447

448 449 450 451
  if ( orthogonalCount == 4 )
    orthogonalProjectionAction_->setVisible(false);
  else
    orthogonalProjectionAction_->setVisible(true);
Jan Möbius's avatar
 
Jan Möbius committed
452

453 454
}

Jan Möbius's avatar
Jan Möbius committed
455 456
void CoreWidget::slotUpdateGlobalDrawMenu() {
  if ( drawGroup_ ) {
Jan Möbius's avatar
 
Jan Möbius committed
457

Jan Möbius's avatar
Jan Möbius committed
458 459 460 461
    disconnect( drawGroup_ , SIGNAL( triggered( QAction * ) ),
                this       , SLOT( slotGlobalDrawMenu( QAction * ) ) );
    delete( drawGroup_ );
    drawGroup_ = 0;
Jan Möbius's avatar
 
Jan Möbius committed
462

Jan Möbius's avatar
Jan Möbius committed
463
  }
Jan Möbius's avatar
 
Jan Möbius committed
464

Jan Möbius's avatar
Jan Möbius committed
465 466 467
  // Recreate drawGroup
  drawGroup_ = new QActionGroup( this );
  drawGroup_->setExclusive( false );
Jan Möbius's avatar
 
Jan Möbius committed
468

Jan Möbius's avatar
Jan Möbius committed
469
  connect( drawGroup_ , SIGNAL( triggered( QAction * ) ),
Jan Möbius's avatar
 
Jan Möbius committed
470 471
           this       , SLOT( slotGlobalDrawMenu( QAction * ) ) );

Jan Möbius's avatar
Jan Möbius committed
472
  if ( !globalDrawMenu_ ) {
Jan Möbius's avatar
 
Jan Möbius committed
473

Jan Möbius's avatar
Jan Möbius committed
474 475
    QIcon icon;
    icon.addFile(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"drawModes.png");
Jan Möbius's avatar
 
Jan Möbius committed
476
    globalDrawMenu_  = new QMenu("Set Global DrawMode");
Jan Möbius's avatar
Jan Möbius committed
477 478
    globalDrawMenu_->setTearOffEnabled(true);
    globalDrawMenu_->setIcon(icon);
Jan Möbius's avatar
 
Jan Möbius committed
479

Jan Möbius's avatar
Jan Möbius committed
480 481
    connect(globalDrawMenu_,SIGNAL(aboutToShow () ) , this, SLOT(slotUpdateGlobalDrawMenu() ) );
  }
Jan Möbius's avatar
 
Jan Möbius committed
482 483

  // Collect available draw Modes
Jan Möbius's avatar
Jan Möbius committed
484 485
  ACG::SceneGraph::CollectDrawModesAction actionAvailable;
  ACG::SceneGraph::traverse( PluginFunctions::getRootNode() , actionAvailable);
Jan Möbius's avatar
Jan Möbius committed
486
  availableGlobalDrawModes_ = actionAvailable.drawModes();
Jan Möbius's avatar
 
Jan Möbius committed
487

Jan Möbius's avatar
Jan Möbius committed
488 489 490 491 492
  // Get currently active drawModes (first viewer only )
  // TODO: create combination from all viewers!
  activeDrawModes_ = INT_MAX;
  for ( int i = 0 ; i < PluginFunctions::viewers(); ++i )
    activeDrawModes_ &= PluginFunctions::drawMode(i);
Jan Möbius's avatar
 
Jan Möbius committed
493

Jan Möbius's avatar
Jan Möbius committed
494 495
  // Convert to ids
  std::vector< unsigned int > availDrawModeIds;
Jan Möbius's avatar
Jan Möbius committed
496
  availDrawModeIds = ACG::SceneGraph::DrawModes::getDrawModeIDs( availableGlobalDrawModes_ );
Jan Möbius's avatar
 
Jan Möbius committed
497

Jan Möbius's avatar
Jan Möbius committed
498
  globalDrawMenu_->clear();
Jan Möbius's avatar
 
Jan Möbius committed
499

Jan Möbius's avatar
Jan Möbius committed
500 501 502 503 504 505 506 507 508 509 510 511 512 513 514
  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(), drawGroup_ );
    action->setCheckable( true );
    action->setChecked( ACG::SceneGraph::DrawModes::containsId( activeDrawModes_, id ) );
  }

  globalDrawMenu_->addActions( drawGroup_->actions() );

}

void CoreWidget::slotGlobalDrawMenu(QAction * _action) {
Jan Möbius's avatar
 
Jan Möbius committed
515

Jan Möbius's avatar
Jan Möbius committed
516 517 518 519 520
  //======================================================================================
  // Get the mode toggled
  //======================================================================================
  unsigned int mode = 0;
  std::vector< unsigned int > availDrawModeIds;
Jan Möbius's avatar
Jan Möbius committed
521
  availDrawModeIds = ACG::SceneGraph::DrawModes::getDrawModeIDs( availableGlobalDrawModes_ );
Jan Möbius's avatar
Jan Möbius committed
522 523 524 525 526 527 528 529 530
  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;
    }
  }
Jan Möbius's avatar
 
Jan Möbius committed
531

Jan Möbius's avatar
Jan Möbius committed
532 533 534 535
  if ( qApp->keyboardModifiers() & Qt::ShiftModifier )
    activeDrawModes_ = ( activeDrawModes_ ^ mode);
  else
    activeDrawModes_ = mode ;
Jan Möbius's avatar
 
Jan Möbius committed
536

Jan Möbius's avatar
Jan Möbius committed
537 538 539 540
  PluginFunctions::setDrawMode( activeDrawModes_ );
  slotUpdateGlobalDrawMenu();
}

541

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