MenuBar.cc 13.8 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
53



void CoreWidget::slotAddMenu( QMenu* _menu , MenuType _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
58
59
60
61
62
63
64
65
66
      // Add it to the menubar as a top level Menu
      menuBar()->insertMenu(helpMenu_->menuAction() ,_menu);
      break;
    case FILEMENU :
      fileMenu_->insertSeparator(fileMenuEnd_);
      fileMenu_->insertMenu( fileMenuEnd_ , _menu );
      break;
    case VIEWMENU :
      viewMenu_->addMenu( _menu );
      viewMenu_->addSeparator( );
67
68
      break;

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

Jan Möbius's avatar
 
Jan Möbius committed
85
86
  viewMenu_ = new QMenu(tr("&View"));
  menuBar()->addMenu(viewMenu_ );
Jan Möbius's avatar
Jan Möbius committed
87
88
89
90
91
92
  
  QIcon icon;
  QAction* setGlobalBackgroundColor = new QAction(tr("&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");
93
  setGlobalBackgroundColor->setIcon(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"BackgroundColor.png") );
Jan Möbius's avatar
Jan Möbius committed
94
95
96
  connect(setGlobalBackgroundColor, SIGNAL(triggered()), this, SLOT(slotSetGlobalBackgroundColor()));
  viewMenu_->addAction(setGlobalBackgroundColor);
  
Jan Möbius's avatar
Jan Möbius committed
97
98
  slotUpdateGlobalDrawMenu();
  
Jan Möbius's avatar
 
Jan Möbius committed
99
100
101
102
103
104
105
106
  //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");
  icon.addFile(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"edit-clear.png");
  AC_clear_all->setIcon(icon);
  connect(AC_clear_all, SIGNAL(triggered()), this, SIGNAL(clearAll()));
  fileMenu_->addAction(AC_clear_all);
107

Jan Möbius's avatar
 
Jan Möbius committed
108
  fileMenu_->addSeparator();
109
110

  //Load object
Jan Möbius's avatar
 
Jan Möbius committed
111
  QAction* AC_Load = new QAction(tr("&Load Object"), this);
Dirk Wilden's avatar
Dirk Wilden committed
112
//   AC_Load->setShortcut (Qt::CTRL + Qt::Key_O);
Jan Möbius's avatar
 
Jan Möbius committed
113
114
115
  AC_Load->setStatusTip(tr("Load an object"));
  AC_Load->setWhatsThis("Load a new object");
  icon.addFile(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"document-open.png");
116
117
  AC_Load->setIcon(icon);

Jan Möbius's avatar
 
Jan Möbius committed
118
119
  connect(AC_Load, SIGNAL(triggered()), this, SIGNAL(loadMenu()));
  fileMenu_->addAction(AC_Load);
120

Jan Möbius's avatar
 
Jan Möbius committed
121
122
123
124
  //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");
Jan Möbius's avatar
   
Jan Möbius committed
125
  icon.addFile(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"add-empty-object.png");
126
  AC_AddEmpty->setIcon(icon);
Jan Möbius's avatar
 
Jan Möbius committed
127
128
  connect(AC_AddEmpty, SIGNAL(triggered()), this, SIGNAL(addEmptyObjectMenu()));
  fileMenu_->addAction(AC_AddEmpty);
129

Jan Möbius's avatar
 
Jan Möbius committed
130
  fileMenu_->addSeparator();
131

Jan Möbius's avatar
 
Jan Möbius committed
132
133
  //Save object
  QAction* AC_Save = new QAction(tr("&Save Object"), this);
Dirk Wilden's avatar
Dirk Wilden committed
134
//   AC_Save->setShortcut (Qt::CTRL + Qt::Key_S);
Dirk Wilden's avatar
Dirk Wilden committed
135
  AC_Save->setStatusTip(tr("Save currently selected objects"));
Jan Möbius's avatar
 
Jan Möbius committed
136
137
138
139
140
  AC_Save->setWhatsThis("Saves all currently selected objects");
  icon.addFile(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"document-save.png");
  AC_Save->setIcon(icon);
  connect(AC_Save, SIGNAL(triggered()), this, SIGNAL(saveMenu()));
  fileMenu_->addAction(AC_Save);
141

Jan Möbius's avatar
 
Jan Möbius committed
142
143
144
145
146
147
148
149
  //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");
  icon.addFile(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"document-save-as.png");
  AC_Save_to->setIcon(icon);
  connect(AC_Save_to, SIGNAL(triggered()), this, SIGNAL(saveToMenu()));
  fileMenu_->addAction(AC_Save_to);
150

Jan Möbius's avatar
 
Jan Möbius committed
151
  fileMenu_->addSeparator();
152

Jan Möbius's avatar
 
Jan Möbius committed
153
154
155
156
  //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,...)");
Jan Möbius's avatar
   
Jan Möbius committed
157
  icon.addFile(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"load-settings.png");
Jan Möbius's avatar
 
Jan Möbius committed
158
159
160
  AC_load_ini->setIcon(icon);
  connect(AC_load_ini, SIGNAL(triggered()), this, SIGNAL(loadIniMenu()));
  fileMenu_->addAction(AC_load_ini);
161

Jan Möbius's avatar
 
Jan Möbius committed
162
163
164
165
  //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,...)");
Jan Möbius's avatar
   
Jan Möbius committed
166
  icon.addFile(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"save-settings.png");
Jan Möbius's avatar
 
Jan Möbius committed
167
168
169
  AC_save_ini->setIcon(icon);
  connect(AC_save_ini, SIGNAL(triggered()), this, SIGNAL(saveIniMenu()));
  fileMenu_->addAction(AC_save_ini);
170
171
172
173
174
175
176

  fileMenu_->addSeparator();

  //Options
  QAction* AC_Options = new QAction(tr("&Options"), this);
  AC_Options->setStatusTip(tr("Edit OpenFlipper Options"));
  AC_Options->setWhatsThis("Edit OpenFlipper Options");
Jan Möbius's avatar
Jan Möbius committed
177
  icon.addFile(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"options.png");
178
179
180
  AC_Options->setIcon(icon);
  connect(AC_Options, SIGNAL(triggered()), this, SLOT(showOptionsWidget()));
  fileMenu_->addAction(AC_Options);
181
182

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

Jan Möbius's avatar
 
Jan Möbius committed
185
186
187
188
189
190
191
  //Recent files
  recentFilesMenu_ = new QMenu(tr("&Recent Files"));
  icon.addFile(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"document-open-recent.png");
  recentFilesMenu_->setIcon(icon);
  recentFilesMenu_->setWhatsThis("Open recent files");
  connect(recentFilesMenu_,SIGNAL(triggered(QAction*)),this,SIGNAL(recentOpen(QAction*)));
  fileMenu_->addMenu(recentFilesMenu_);
192

Jan Möbius's avatar
 
Jan Möbius committed
193
  fileMenu_->addSeparator();
194

Jan Möbius's avatar
 
Jan Möbius committed
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
  //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");
  icon.addFile(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"application-exit.png");
  AC_exit->setIcon(icon);
  connect(AC_exit, SIGNAL(triggered()), this, SIGNAL(exit()));
  fileMenu_->addAction(AC_exit);

  // ======================================================================
  // help Menu
  // ======================================================================
  helpMenu_ = new QMenu(tr("&Help"));
  menuBar()->addMenu(helpMenu_);
210

Jan Möbius's avatar
 
Jan Möbius committed
211
212
213
214
215
216
217
218
  //Open Help Browser
  QAction* AC_HelpBrowser = new QAction(tr("&User Help"), this);
  AC_HelpBrowser->setStatusTip(tr("Open Help Browser with User Documentation"));
  icon.addFile(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"help-browser.png");
  AC_HelpBrowser->setIcon(icon);
  AC_HelpBrowser->setWhatsThis("Open the <b>Help Browser</b>");
  connect(AC_HelpBrowser, SIGNAL(triggered()), this, SLOT(showHelpBrowserUser()));
  helpMenu_->addAction(AC_HelpBrowser);
219

Jan Möbius's avatar
 
Jan Möbius committed
220
221
222
223
224
225
226
227
  //Open Help Browser
  AC_HelpBrowser = new QAction(tr("&Developer Help"), this);
  AC_HelpBrowser->setStatusTip(tr("Open Help Browser with Developer Documentation"));
  icon.addFile(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"help-browser.png");
  AC_HelpBrowser->setIcon(icon);
  AC_HelpBrowser->setWhatsThis("Open the <b>Help Browser</b>");
  connect(AC_HelpBrowser, SIGNAL(triggered()), this, SLOT(showHelpBrowserDeveloper()));
  helpMenu_->addAction(AC_HelpBrowser);
228

Jan Möbius's avatar
 
Jan Möbius committed
229
230
231
232
233
  //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);
234

Jan Möbius's avatar
 
Jan Möbius committed
235
  helpMenu_->addSeparator();
236

Dirk Wilden's avatar
Dirk Wilden committed
237
238
239
240
241
242
243
244
245
246
247
  //show plugins
  QAction* AC_Plugins = new QAction(tr("&Plugins"), this);
  AC_Plugins->setStatusTip(tr("Show loaded plugins"));
  AC_Plugins->setWhatsThis("Show loaded plugins");
  icon.addFile(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"network-connect.png");
  AC_Plugins->setIcon(icon);
  connect(AC_Plugins, SIGNAL(triggered()), this, SIGNAL(showPlugins()));
  helpMenu_->addAction(AC_Plugins);

  helpMenu_->addSeparator();

Jan Möbius's avatar
 
Jan Möbius committed
248
249
250
251
252
253
  //About Action
  QAction* AC_About = new QAction(tr("&About"), this);
  AC_About->setStatusTip(tr("About OpenFlipper"));
  icon.addFile(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"help-about.png");
  AC_About->setIcon(icon);
  AC_About->setWhatsThis("This entry shows information about <b>OpenFlipper</b>");
Jan Möbius's avatar
Jan Möbius committed
254
  connect(AC_About, SIGNAL(triggered()), this, SLOT(showAboutWidget()));
Jan Möbius's avatar
 
Jan Möbius committed
255
  helpMenu_->addAction(AC_About);
256

Jan Möbius's avatar
 
Jan Möbius committed
257
258
259
260
261
262
263
264
265
  // 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);
266

Jan Möbius's avatar
 
Jan Möbius committed
267
268
}

Jan Möbius's avatar
Jan Möbius committed
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
void CoreWidget::slotUpdateGlobalDrawMenu() {
  if ( drawGroup_ ) {
    
    disconnect( drawGroup_ , SIGNAL( triggered( QAction * ) ),
                this       , SLOT( slotGlobalDrawMenu( QAction * ) ) );
    delete( drawGroup_ );
    drawGroup_ = 0;
    
  }
  
  // Recreate drawGroup
  drawGroup_ = new QActionGroup( this );
  drawGroup_->setExclusive( false );
  
  connect( drawGroup_ , SIGNAL( triggered( QAction * ) ),
           this       , SLOT( slotGlobalDrawMenu( QAction * ) ) );  
  
  if ( !globalDrawMenu_ ) {
    
    QIcon icon;
    icon.addFile(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"drawModes.png");
    globalDrawMenu_  = new QMenu("Set Global DrawMode"); 
    globalDrawMenu_->setTearOffEnabled(true);
    globalDrawMenu_->setIcon(icon);
    
    connect(globalDrawMenu_,SIGNAL(aboutToShow () ) , this, SLOT(slotUpdateGlobalDrawMenu() ) );
    
    viewMenu_->addMenu(globalDrawMenu_);
  }
  
  // Collect available draw Modes 
  ACG::SceneGraph::CollectDrawModesAction actionAvailable;
  ACG::SceneGraph::traverse( PluginFunctions::getRootNode() , actionAvailable);
Jan Möbius's avatar
Jan Möbius committed
302
  availableGlobalDrawModes_ = actionAvailable.drawModes();
Jan Möbius's avatar
Jan Möbius committed
303
304
305
306
307
308
309
310
311
  
  // 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);
  
  // Convert to ids
  std::vector< unsigned int > availDrawModeIds;
Jan Möbius's avatar
Jan Möbius committed
312
  availDrawModeIds = ACG::SceneGraph::DrawModes::getDrawModeIDs( availableGlobalDrawModes_ );
Jan Möbius's avatar
Jan Möbius committed
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
  
  globalDrawMenu_->clear();
  
  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) {
  
  //======================================================================================
  // Get the mode toggled
  //======================================================================================
  unsigned int mode = 0;
  std::vector< unsigned int > availDrawModeIds;
Jan Möbius's avatar
Jan Möbius committed
337
  availDrawModeIds = ACG::SceneGraph::DrawModes::getDrawModeIDs( availableGlobalDrawModes_ );
Jan Möbius's avatar
Jan Möbius committed
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
  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;
    }
  }
  
  if ( qApp->keyboardModifiers() & Qt::ShiftModifier )
    activeDrawModes_ = ( activeDrawModes_ ^ mode);
  else
    activeDrawModes_ = mode ;
  
  PluginFunctions::setDrawMode( activeDrawModes_ );
  slotUpdateGlobalDrawMenu();
}

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