CoreWidget.cc 39.4 KB
Newer Older
1
/*===========================================================================*\
Jan Möbius's avatar
Jan Möbius committed
2
3
*                                                                            *
*                              OpenFlipper                                   *
Martin Schultz's avatar
Martin Schultz committed
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
 *           Copyright (c) 2001-2015, RWTH-Aachen University                 *
 *           Department of Computer Graphics and Multimedia                  *
 *                          All rights reserved.                             *
 *                            www.openflipper.org                            *
 *                                                                           *
 *---------------------------------------------------------------------------*
 * This file is part of OpenFlipper.                                         *
 *---------------------------------------------------------------------------*
 *                                                                           *
 * Redistribution and use in source and binary forms, with or without        *
 * modification, are permitted provided that the following conditions        *
 * are met:                                                                  *
 *                                                                           *
 * 1. Redistributions of source code must retain the above copyright notice, *
 *    this list of conditions and the following disclaimer.                  *
 *                                                                           *
 * 2. Redistributions in binary form must reproduce the above copyright      *
 *    notice, this list of conditions and the following disclaimer in the    *
 *    documentation and/or other materials provided with the distribution.   *
 *                                                                           *
 * 3. Neither the name of the copyright holder nor the names of its          *
 *    contributors may be used to endorse or promote products derived from   *
 *    this software without specific prior written permission.               *
 *                                                                           *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS       *
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A           *
 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,  *
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,       *
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR        *
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF    *
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING      *
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS        *
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.              *
Jan Möbius's avatar
Jan Möbius committed
39
*                                                                            *
40
\*===========================================================================*/
Jan Möbius's avatar
 
Jan Möbius committed
41

42
/*===========================================================================*\
Jan Möbius's avatar
Jan Möbius committed
43
44
45
46
47
*                                                                            *
*   $Revision$                                                       *
*   $LastChangedBy$                                                *
*   $Date$                     *
*                                                                            *
48
\*===========================================================================*/
Jan Möbius's avatar
 
Jan Möbius committed
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65



//=============================================================================
//
//  CLASS MViewWidget - IMPLEMENTATION
//
//=============================================================================


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

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

// -------------------- OpenFlipper Includes
#include <OpenFlipper/common/RecentFiles.hh>
Jan Möbius's avatar
   
Jan Möbius committed
66
#include <OpenFlipper/BasePlugin/PluginFunctionsCore.hh>
Jan Möbius's avatar
 
Jan Möbius committed
67

Dirk Wilden's avatar
Dirk Wilden committed
68
69
#include <OpenFlipper/widgets/videoCaptureDialog/VideoCaptureDialog.hh>

Jan Möbius's avatar
Jan Möbius committed
70
#include <ACG/Scenegraph/SceneGraphAnalysis.hh>
71
#include <ACG/GL/ShaderCache.hh>
Jan Möbius's avatar
Jan Möbius committed
72

Matthias Möller's avatar
doc    
Matthias Möller committed
73
// -------------------- Qt event Includes
Hans-Christian Ebke's avatar
Hans-Christian Ebke committed
74
#include <QGLFormat>
Matthias Möller's avatar
doc    
Matthias Möller committed
75

Jan Möbius's avatar
 
Jan Möbius committed
76
77
78
#define WIDGET_HEIGHT 800
#define WIDGET_WIDTH  800

Jan Möbius's avatar
Jan Möbius committed
79
//== IMPLEMENTATION ==========================================================
Jan Möbius's avatar
 
Jan Möbius committed
80

81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
PickMode::PickMode(const std::string& _n, const bool _t, const bool _v, QCursor _c, QToolBar *_tb ) :
      name_(_n),
      tracking_(_t),
      visible_(_v),
      cursor_(_c),
      toolbar_(_tb)
{

}

void PickMode::visible(const bool _visible) {
  visible_ = _visible;
}

bool PickMode::visible() const  {
  return visible_;
}

std::string PickMode::name() const {
  return name_;
}

void PickMode::tracking(bool _tracking) {
  tracking_ = _tracking;
}

bool PickMode::tracking() const {
  return tracking_;
}

111
112
113
114
void PickMode::cursor(const QCursor _cursor) {
  cursor_ = _cursor;
}

115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
QCursor PickMode::cursor() const{
  return cursor_;
}

void PickMode::toolbar(QToolBar* _toolbar) {
  toolbar_ = _toolbar;
}

QToolBar * PickMode::toolbar() const {
  return toolbar_;
}








134
/** \brief Constructor for the Core Widget
Jan Möbius's avatar
Jan Möbius committed
135
 *
Jan Möbius's avatar
 
Jan Möbius committed
136
137
*/
CoreWidget::
Dirk Wilden's avatar
Dirk Wilden committed
138
CoreWidget( QVector<ViewMode*>& _viewModes,
Dirk Wilden's avatar
Dirk Wilden committed
139
140
            std::vector<PluginInfo>& _plugins,
            QList< SlotInfo >& _coreSlots ) :
Jan Möbius's avatar
 
Jan Möbius committed
141
  QMainWindow(),
Dirk Wilden's avatar
Dirk Wilden committed
142
  coreSlots_(_coreSlots),
Dirk Wilden's avatar
Dirk Wilden committed
143
  shiftPressed_(false),
Jan Möbius's avatar
 
Jan Möbius committed
144
145
  viewModes_(_viewModes),
  viewModeButton_(0),
146
  viewModeMenu_(0),
Jan Möbius's avatar
 
Jan Möbius committed
147
  splitter_(0),
148
  logWidget_(0),
Jan Möbius's avatar
 
Jan Möbius committed
149
  recentFilesMenu_(0),
150
  helpMenu_(0),
151
152
  windowMenu_(0),
  AC_ShowViewModeControls_(0),
153
  pickToolBarExternal_(0),
Jan Möbius's avatar
Dennis:    
Jan Möbius committed
154
  cursorPainter_(0),
155
  sceneGraphDialog_(0),
156
157
  viewModeChangePopupAction_(0),
  modeChangeWidget(0),
158
159
160
  fileMenu_(0),
  viewMenu_(0),
  toolsMenu_(0),
Jan Möbius's avatar
 
Jan Möbius committed
161
  fileMenuEnd_(0),
162
163
164
  stereoButton_(0),
  moveButton_(0),
  pickButton_(0),
Dirk Wilden's avatar
Dirk Wilden committed
165
  questionButton_(0),
166
  globalDrawMenu_(0),
167
  rendererMenu_(0),
168
  drawGroup_(0),
169
  rendererGroup_(0),
170
  viewGroup_(0),
171
  perspectiveProjectionAction_(0),
172
173
  activeDrawModes_(0),
  availableGlobalDrawModes_(0),
Jan Möbius's avatar
 
Jan Möbius committed
174
  contextMenu_(0),
Jan Möbius's avatar
Jan Möbius committed
175
  contextSelectionMenu_(0),
176
177
  drawGroupViewer_(0),
  viewerDrawMenu_(0),
Matthias Möller's avatar
Matthias Möller committed
178
  viewerDrawMenuWidget_(0),
179
  coordSysMenu_(0),
180
  snapshotName_(""),
Dirk Wilden's avatar
Dirk Wilden committed
181
  snapshotCounter_(0),
Jan Möbius's avatar
 
Jan Möbius committed
182
  stackMenu_(0),
183
  helpWidget_(0),
184
  postProcessorDialog_(0),
Jan Möbius's avatar
Jan Möbius committed
185
  rendererDialog_(0),
Jan Möbius's avatar
Jan Möbius committed
186
  rendererObjectWidget_(0),
187
  stereoSettingsWidget_(0),
Jan Möbius's avatar
Jan Möbius committed
188
  aboutWidget_(0),
189
  optionsWidget_(0),
190
  plugins_(_plugins),
191
192
193
194
195
196
  stereoActive_(false),
  actionMode_(Viewer::PickingMode),
  lastActionMode_(Viewer::ExamineMode),
  pickMenu_(0),
  pick_mode_name_(""),
  pick_mode_idx_(-1)
Jan Möbius's avatar
 
Jan Möbius committed
197
{
Matthias Möller's avatar
doc    
Matthias Möller committed
198

Jan Möbius's avatar
 
Jan Möbius committed
199
  setupStatusBar();
Jan Möbius's avatar
Jan Möbius committed
200

Dirk Wilden's avatar
Dirk Wilden committed
201
202
  defaultIconSize_ = iconSize();

Jan Möbius's avatar
Dennis:    
Jan Möbius committed
203
204
205
206
207
  toolSplitter_ = new QSplitter(Qt::Horizontal,this);

  setCentralWidget(toolSplitter_);

  splitter_ = new QSplitter(Qt::Vertical,toolSplitter_);
Jan Möbius's avatar
 
Jan Möbius committed
208
  stackedWidget_ = new QStackedWidget(splitter_);
Jan Möbius's avatar
Jan Möbius committed
209

210
211
  OFGLFormat format = OFGLFormat::defaultFormat();
#ifdef ARCH_DARWIN
212
  format.setStereo(false);
213
214
215
216
217
218
219
220
221
#else
  format.setStereo(OpenFlipper::Options::stereo());
#endif

#if (QT_VERSION >= QT_VERSION_CHECK(5,0,0))
  format.setAlphaBufferSize(8);
  format.setStencilBufferSize(8);
  format.setSamples(4); // todo: get sample count from settings
#else
Jan Möbius's avatar
   
Jan Möbius committed
222
  format.setAlpha(true);
223
  format.setStencil(true);
224
  format.setSampleBuffers(true);
225
#endif
Jan Möbius's avatar
   
Jan Möbius committed
226
227

  // Construct GL context & widget
228
229
230
  baseLayout_ = new QtMultiViewLayout;
  baseLayout_->setContentsMargins(0,0,0,0);

231
232
233
  // ===============================================================================
  // Test context capabilities ...
  // If we get stereo buffers, we use them .. which might disable multisampling
234
  // If we don't have stereo, we disable it to not interfere with multisampling
235
  // ===============================================================================
236
237
238
239
240
241
242
#if (QT_VERSION >= QT_VERSION_CHECK(5, 4, 0))
  OFGLWidget* test = new OFGLWidget();
  test->setFormat(format);
#else
  OFGLWidget* test = new OFGLWidget(format);
#endif

243
244
245
246
247
248
249
250
251
  if ( ! test->format().stereo() ) {
    //     std::cerr << "No stereo ... disabling stereo for real context!" << std::endl;
    format.setStereo(false);
  }/* else {
    std::cerr << "Stereo found ok" << std::endl;
  }*/

  delete test;

Martin Schultz's avatar
fixed a    
Martin Schultz committed
252
  if (OpenFlipper::Options::coreProfile()) {
253
#if QT_VERSION >= 0x050000
Martin Schultz's avatar
fixed a    
Martin Schultz committed
254
255
256
257
258
259
260
    // request the highest OpenGL version
    // QT 5 should gracefully provide the next highest available version
    format.setVersion(4, 0);
    format.setProfile(OFGLFormat::CoreProfile);
#else
    format.setProfile(OFGLFormat::CompatibilityProfile);
    format.setOption(QSurfaceFormat::DeprecatedFunctions);
261
#endif
Martin Schultz's avatar
fixed a    
Martin Schultz committed
262
263
264
265
266
  }
  else {
    format.setProfile(QSurfaceFormat::CompatibilityProfile);
    format.setOption(QSurfaceFormat::DeprecatedFunctions);
  }
267

268

269
270
271
  

#if (QT_VERSION >= QT_VERSION_CHECK(5, 4, 4))
272
273
  if (OpenFlipper::Options::debug())
	  format.setOption(format.options() | QSurfaceFormat::DebugContext);
274
275
276
277
278
279
  glWidget_ = new OFGLWidget();
  glWidget_->setFormat(format);
  glWidget_->makeCurrent();
#else
  glWidget_ = new OFGLWidget(format, 0);
#endif
280
  PluginFunctions::shareGLWidget (glWidget_);
281

Jan Möbius's avatar
   
Jan Möbius committed
282
  glView_ = new QtGLGraphicsView(stackedWidget_);
283
  glScene_ = new QtGLGraphicsScene (&examiner_widgets_, baseLayout_);
Jan Möbius's avatar
   
Jan Möbius committed
284

Jan Möbius's avatar
Jan Möbius committed
285
  // is stereo possible, use it?
Jan Möbius's avatar
Dennis:    
Jan Möbius committed
286
  OpenFlipper::Options::glStereo(glWidget_->format().stereo());
Jan Möbius's avatar
Jan Möbius committed
287

Jan Möbius's avatar
   
Jan Möbius committed
288
289
290
  glView_->setViewport(glWidget_);
  glView_->setViewportUpdateMode(QGraphicsView::FullViewportUpdate);
  glView_->setScene(glScene_);
291
  glView_->setFrameStyle(QFrame::NoFrame);
Jan Möbius's avatar
   
Jan Möbius committed
292

Jan Möbius's avatar
Dennis:    
Jan Möbius committed
293
294
  // gl widget as parent to make sure that the CursorPainter will be deleted before
  cursorPainter_ = new CursorPainter (glWidget_);
Jan Möbius's avatar
Jan Möbius committed
295
  cursorPainter_->setForceNative (OpenFlipperSettings().value("Core/Gui/glViewer/nativeMouse",false).toBool() );
296
  cursorPainter_->setEnabled (stereoActive_);
Jan Möbius's avatar
Dennis:    
Jan Möbius committed
297
  glScene_->setCursorPainter (cursorPainter_);
298

Jan Möbius's avatar
   
Jan Möbius committed
299
300
301
302
303
304
305
306
307
308
  centerWidget_ = new QGraphicsWidget;
  glScene_->addItem(centerWidget_);
  centerWidget_->setGeometry (glScene_->sceneRect ());

  connect ( glView_, SIGNAL( sceneRectChanged( const QRectF & ) ),
            this, SLOT( sceneRectChanged( const QRectF & ) ) );

  stackedWidget_->addWidget(glView_);
  stackWidgetList_.push_back( StackWidgetInfo( false, "3D Examiner Widget", glView_ ) );

Jan Möbius's avatar
 
Jan Möbius committed
309
310
311
  // ======================================================================
  // Set up the logging window
  // ======================================================================
312

313
  slidingLogger_ = new QtSlideWindow (tr("Log Viewer"), centerWidget_);
314

315
316
  logWidget_ = new LoggerWidget(splitter_);
  logWidget_->setSizePolicy( QSizePolicy ( QSizePolicy::Preferred , QSizePolicy::Preferred ) );
317
  logWidget_->resize( splitter_->width() ,240);
Jan Möbius's avatar
Jan Möbius committed
318

319
  originalLoggerSize_ = 0;
Jan Möbius's avatar
Jan Möbius committed
320
  loggerState_ = OpenFlipper::Options::Normal;
321

322
323
324
325
326
  QList<int> wsizes(splitter_->sizes());
  // Set initial values to have a usable state
  wsizes[0] = 480;
  wsizes[1] = 240;
  splitter_->setSizes(wsizes);
327

Jan Möbius's avatar
Jan Möbius committed
328
  if (OpenFlipper::Options::loggerState() == OpenFlipper::Options::InScene) {
329

330
    slidingLogger_->attachWidget (logWidget_);
331
    showLoggerInSplitView(false);
Jan Möbius's avatar
Jan Möbius committed
332
    loggerState_ = OpenFlipper::Options::InScene;
333

Jan Möbius's avatar
Jan Möbius committed
334
  } else if (OpenFlipper::Options::loggerState() == OpenFlipper::Options::Hidden) {
335

336
    showLoggerInSplitView(false);
Jan Möbius's avatar
Jan Möbius committed
337
338
    loggerState_ = OpenFlipper::Options::Hidden;
  } else {
339
340

    showLoggerInSplitView(true);
Jan Möbius's avatar
 
Jan Möbius committed
341
  }
Jan Möbius's avatar
Jan Möbius committed
342

343

Jan Möbius's avatar
 
Jan Möbius committed
344
345
346
  // ======================================================================
  // Create examiner
  // ======================================================================
Jan Möbius's avatar
Jan Möbius committed
347

Jan Möbius's avatar
Jan Möbius committed
348
349
350
351
352
  // First we analyze the scenegraph
  unsigned int maxPases = 1;
  ACG::Vec3d bbmin,bbmax;
  ACG::SceneGraph::analyzeSceneGraph(PluginFunctions::getSceneGraphRootNode(),maxPases,bbmin,bbmax);

Jan Möbius's avatar
Jan Möbius committed
353
  if ( !OpenFlipperSettings().value("Core/Gui/glViewer/useMultipleViewers",true).toBool() ) {
Jan Möbius's avatar
Jan Möbius committed
354

Jan Möbius's avatar
   
Jan Möbius committed
355
    glViewer* examinerWidget = new glViewer(glScene_,
Jan Möbius's avatar
Jan Möbius committed
356
357
358
					                                  glWidget_,
					                                  PluginFunctions::viewerProperties(0),
					                                  centerWidget_);
Jan Möbius's avatar
Jan Möbius committed
359

Jan Möbius's avatar
Jan Möbius committed
360
361
    examiner_widgets_.push_back(examinerWidget);

Jan Möbius's avatar
Jan Möbius committed
362
    examinerWidget->sceneGraph( PluginFunctions::getSceneGraphRootNode(), maxPases,bbmin,bbmax );
Jan Möbius's avatar
Jan Möbius committed
363

Jan Möbius's avatar
Jan Möbius committed
364
    baseLayout_->addItem(examinerWidget, 0);
Jan Möbius's avatar
Jan Möbius committed
365

Jan Möbius's avatar
Dennis:    
Jan Möbius committed
366
367
    cursorPainter_->registerViewer (examinerWidget);

Jan Möbius's avatar
Jan Möbius committed
368
369
370
  } else {


Jan Möbius's avatar
   
Jan Möbius committed
371
372
373
    // Create examiners
    for ( unsigned int i = 0 ; i < OpenFlipper::Options::examinerWidgets() ; ++i ) {
      glViewer* newWidget = new glViewer(glScene_,
Jan Möbius's avatar
Jan Möbius committed
374
					                               glWidget_,
375
                                         PluginFunctions::viewerProperties(i),
Jan Möbius's avatar
Jan Möbius committed
376
                                         centerWidget_);
Dirk Wilden's avatar
Dirk Wilden committed
377

Jan Möbius's avatar
Jan Möbius committed
378
      examiner_widgets_.push_back(newWidget);
379
380
381
382
383
384
385
386
387
388

      connect (&PluginFunctions::viewerProperties(i), SIGNAL( getPickMode(std::string&) ),
               this,                                   SLOT( getPickMode(std::string&) ),Qt::DirectConnection );
      connect (&PluginFunctions::viewerProperties(i), SIGNAL( setPickMode(const std::string) ),
               this,                                   SLOT( setPickMode(const std::string) ),Qt::DirectConnection );
      connect (&PluginFunctions::viewerProperties(i), SIGNAL( getActionMode(Viewer::ActionMode&) ),
               this,                                   SLOT( getActionMode(Viewer::ActionMode&) ),Qt::DirectConnection );
      connect (&PluginFunctions::viewerProperties(i), SIGNAL( setActionMode(const Viewer::ActionMode) ),
               this,                                   SLOT( setActionMode(const Viewer::ActionMode)), Qt::DirectConnection );

389
      connect (&PluginFunctions::viewerProperties(i), SIGNAL( drawModeChanged(int)), this, SIGNAL(drawModeChanged(int)));
Jan Möbius's avatar
Jan Möbius committed
390
391
392
393
    }

    // Initialize all examiners
    for ( unsigned int i = 0 ; i < OpenFlipper::Options::examinerWidgets() ; ++i ) {
Jan Möbius's avatar
Jan Möbius committed
394
      examiner_widgets_[i]->sceneGraph( PluginFunctions::getSceneGraphRootNode(), maxPases,bbmin,bbmax );
Jan Möbius's avatar
Dennis:    
Jan Möbius committed
395
      cursorPainter_->registerViewer (examiner_widgets_[i]);
Jan Möbius's avatar
Jan Möbius committed
396
397
    }

Jan Möbius's avatar
Jan Möbius committed
398
399
400
401
    baseLayout_->addItem(examiner_widgets_[0],0);
    baseLayout_->addItem(examiner_widgets_[1],1);
    baseLayout_->addItem(examiner_widgets_[2],2);
    baseLayout_->addItem(examiner_widgets_[3],3);
Jan Möbius's avatar
Jan Möbius committed
402
403
  }

Jan Möbius's avatar
   
Jan Möbius committed
404
405
406
  // Make examiner available to the plugins ( defined in PluginFunctions.hh)
  PluginFunctions::setViewers( examiner_widgets_ );

Jan Möbius's avatar
   
Jan Möbius committed
407
  centerWidget_->setLayout(baseLayout_);
408
409


410
  ACG::ShaderCache::getInstance()->setTimeCheck(OpenFlipperSettings().value("Core/File/ReloadShaders",false).toBool());
411
  ACG::ShaderCache::getInstance()->setDebugOutputDir(OpenFlipperSettings().value("Core/File/ShaderOutputDir","").toString().toUtf8());
412

Jan Möbius's avatar
 
Jan Möbius committed
413
414
415
  // ======================================================================
  // Setup dragging for examiner widget
  // ======================================================================
416
417
418
419
420
421
422
423
  for ( uint i = 0 ; i < OpenFlipper::Options::examinerWidgets() ; ++i ) {

    connect( examiner_widgets_[i], SIGNAL(startDragEvent( QMouseEvent*)),
             this, SLOT(startDrag(QMouseEvent* )));
    connect( examiner_widgets_[i], SIGNAL(dragEnterEvent( QDragEnterEvent*)),
            this, SLOT(dragEnterEvent(QDragEnterEvent* )));
    connect( examiner_widgets_[i], SIGNAL(dropEvent( QDropEvent*)),
            this, SLOT(dropEvent(QDropEvent* )));
424
425
    connect (examiner_widgets_[i], SIGNAL(signalMakeActive ()),
             this, SLOT(slotActivateExaminer()));
426
427
428

    connect (examiner_widgets_[i], SIGNAL(statusMessage(QString, int)),
             statusBar_, SLOT(showMessage(const QString&, int)));
Jan Möbius's avatar
Jan Möbius committed
429
430
431
  }


Jan Möbius's avatar
 
Jan Möbius committed
432
433
434
  // ======================================================================
  // Create main Toolbar
  // ======================================================================
Jan Möbius's avatar
Jan Möbius committed
435

Jan Möbius's avatar
Jan Möbius committed
436
437
438
  mainToolbar_ = new QToolBar(tr("Main Toolbar"));
  mainToolbar_->setWindowTitle(tr("Main Toolbar"));
  mainToolbar_->setObjectName(tr("MainToolbar"));
439
  slotAddToolbar(mainToolbar_);
Jan Möbius's avatar
Jan Möbius committed
440

Jan Möbius's avatar
 
Jan Möbius committed
441
442
443
  // ======================================================================
  // Get Toolbar from examiner and integrate it into main window
  // ======================================================================
Jan Möbius's avatar
Jan Möbius committed
444

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

446
  // Create the toolbar
Jan Möbius's avatar
Jan Möbius committed
447
  viewerToolbar_ = new QToolBar( tr("Viewer Toolbar" ), this );
448
  viewerToolbar_->setOrientation(Qt::Vertical);
Jan Möbius's avatar
 
Jan Möbius committed
449
450
  viewerToolbar_->setAllowedAreas(Qt::AllToolBarAreas);
  viewerToolbar_->setIconSize(QSize(20,20));
Jan Möbius's avatar
Jan Möbius committed
451
  viewerToolbar_->setObjectName(tr("ViewerToolbar"));
452

Jan Möbius's avatar
Jan Möbius committed
453
  slotAddToolbar(viewerToolbar_);
Jan Möbius's avatar
Jan Möbius committed
454

455
456
457
458
  moveButton_ = new QToolButton( viewerToolbar_ );
  moveButton_->setIcon( QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"transform-move.png") );
  moveButton_->setMinimumSize( 16, 16 );
  moveButton_->setMaximumSize( 32, 32 );
459
  moveButton_->setCheckable(true);
Jan Möbius's avatar
Jan Möbius committed
460
461
  moveButton_->setToolTip( tr("Switch to <b>move</b> mode.") );
  moveButton_->setWhatsThis(tr(
462
463
464
                  "Switch to <b>move</b> mode.<br>"
                  "<ul><li><b>Rotate</b> using <b>left</b> mouse button.</li>"
                  "<li><b>Translate</b> using <b>middle</b> mouse button.</li>"
Jan Möbius's avatar
Jan Möbius committed
465
                  "<li><b>Zoom</b> using <b>left+middle</b> mouse buttons.</li></ul>" ));
466
467

  connect( moveButton_,SIGNAL( clicked() ), this, SLOT( setExamineMode() ) );
468
/*
469
  connect( this, SIGNAL( actionModeChanged( Viewer::ActionMode ) ),
470
            this, SLOT(   slotActionModeChanged(Viewer::ActionMode) ) );*/
471

Jan Möbius's avatar
Jan Möbius committed
472
  viewerToolbar_->addWidget( moveButton_ )->setText(tr("Move"));
473
  moveButton_->setChecked(true);
474

475
  
476
477
478
479
  pickButton_ = new QToolButton( viewerToolbar_ );
  pickButton_->setIcon( QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"pick.png") );
  pickButton_->setMinimumSize( 16, 16 );
  pickButton_->setMaximumSize( 32, 32 );
480
  pickButton_->setCheckable(true);
Jan Möbius's avatar
Jan Möbius committed
481
482
  pickButton_->setToolTip(tr("Switch to <b>picking</b> mode."));
  pickButton_->setWhatsThis(tr(
483
484
485
                  "Switch to <b>picking</b> mode.<br>"
                  "Use picking functions like flipping edges.<br>"
                  "To change the mode use the right click<br>"
Jan Möbius's avatar
Jan Möbius committed
486
                  "context menu in the viewer."));
487
  connect( pickButton_,SIGNAL( clicked() ), this, SLOT( setPickingMode() ) );
Jan Möbius's avatar
Jan Möbius committed
488
  viewerToolbar_->addWidget( pickButton_)->setText(tr("Pick"));
489
490
491
492
493
494


  questionButton_ = new QToolButton( viewerToolbar_ );
  questionButton_->setIcon( QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"help-about.png") );
  questionButton_->setMinimumSize( 16, 16 );
  questionButton_->setMaximumSize( 32, 32 );
495
  questionButton_->setCheckable(true);
Jan Möbius's avatar
Jan Möbius committed
496
497
  questionButton_->setToolTip(tr("Switch to <b>identification</b> mode."));
  questionButton_->setWhatsThis(tr(
498
499
500
501
                  "Switch to <b>identification</b> mode.<br>"
                  "Use identification mode to get information "
                  "about objects. Click on an object and see "
                  "the log output for information about the "
Jan Möbius's avatar
Jan Möbius committed
502
                  "object."));
503
  connect( questionButton_,SIGNAL( clicked() ), this, SLOT( setQuestionMode() ) );
Jan Möbius's avatar
Jan Möbius committed
504
  viewerToolbar_->addWidget( questionButton_)->setText(tr("Question"));
505

506
507
508
509
510
511
512
513
  viewerLayoutBox_ = new QComboBox( viewerToolbar_ );
  viewerLayoutBox_->setMinimumSize( 32, 16 );
  viewerLayoutBox_->setMaximumSize( 64, 32 );
  viewerLayoutBox_->setToolTip(tr("Switch <b>viewer layout</b>."));
  viewerLayoutBox_->setWhatsThis(tr(
                  "Switch <b>viewer layout</b>.<br>"
                  "Select the desired viewer layout. "
                  "Possible layouts are: "
514
                  "<ul> "
515
				  "<li>Single viewer</li>"
Jan Möbius's avatar
Jan Möbius committed
516
          "<li>Double viewer</li>"
517
518
				  "<li>Multiple viewers (grid)</li>"
				  "<li>Multiple viewers (hsplit)</li>"
Jan Möbius's avatar
Jan Möbius committed
519
				  "</ul>"));
520

521
  viewerLayoutBox_->addItem(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"singleviewmode.png"), "");
Jan Möbius's avatar
Jan Möbius committed
522
  viewerLayoutBox_->addItem(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"doubleviewmode.png"), "");
523
524
  viewerLayoutBox_->addItem(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"multiviewmode1.png"), "");
  viewerLayoutBox_->addItem(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"multiviewmode2.png"), "");
525

526
  viewerLayoutBox_->setIconSize(QSize(22,22));
527

528
  connect( viewerLayoutBox_,SIGNAL( activated(int) ), this, SLOT( setViewerLayout(int) ) );
529

Jan Möbius's avatar
Jan Möbius committed
530
  extended_actions.push_back(viewerToolbar_->addWidget( viewerLayoutBox_ ));
531

Jan Möbius's avatar
Jan Möbius committed
532
  extended_actions.push_back(viewerToolbar_->addSeparator());
533
534
535
536
537
538
539
540

  if (OpenFlipper::Options::stereo())
  {
    stereoButton_ = new QToolButton( viewerToolbar_ );
    stereoButton_->setIcon(  QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"mono.png")  );
    stereoButton_->setMinimumSize( 16, 16 );
    stereoButton_->setMaximumSize( 32, 32 );
    stereoButton_->setCheckable( true );
Jan Möbius's avatar
Jan Möbius committed
541
    stereoButton_->setToolTip(tr( "Toggle stereo viewing"));
542
543
    // We want a custom context menu
    stereoButton_->setContextMenuPolicy(Qt::CustomContextMenu);
Jan Möbius's avatar
Jan Möbius committed
544
    stereoButton_->setWhatsThis(tr(
545
546
547
548
                  "Toggle stereo mode<br><br>"
                  "Use this button to switch between stereo "
                  "and mono view. To use this feature you need "
                  "a stereo capable graphics card and a stereo "
Jan Möbius's avatar
Jan Möbius committed
549
                  "display/projection system."));
550
551
552
    connect( stereoButton_, SIGNAL( clicked() ), this , SLOT( slotToggleStereoMode() ) );
    // Custom context menu
    connect( stereoButton_, SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(stereoButtonContextMenu(const QPoint &)));
Jan Möbius's avatar
Jan Möbius committed
553
554
555
    QAction *stereoAction = viewerToolbar_->addWidget( stereoButton_ );
    stereoAction->setText( tr("Stereo"));
    extended_actions.push_back(stereoAction);
556
  }
557
558


559
  addToolBar(Qt::TopToolBarArea,viewerToolbar_);
Jan Möbius's avatar
Jan Möbius committed
560

Jan Möbius's avatar
 
Jan Möbius committed
561
562
  // Remember logger size
  wsizes = splitter_->sizes();
563
564
565
566
567
568

  if(wsizes.size() > 1) {
    originalLoggerSize_  = wsizes[1];
  } else {
    originalLoggerSize_ = 240;
  }
Jan Möbius's avatar
Jan Möbius committed
569

Jan Möbius's avatar
 
Jan Möbius committed
570
  // ======================================================================
Jan Möbius's avatar
Dennis:    
Jan Möbius committed
571
  // Create ToolBox area
Jan Möbius's avatar
Jan Möbius committed
572
  // ======================================================================
Jan Möbius's avatar
Dennis:    
Jan Möbius committed
573
574
575

  toolBoxArea_ = new QWidget (toolSplitter_);

576
  viewModeControlBox_ = new QWidget();
Jan Möbius's avatar
Dennis:    
Jan Möbius committed
577
578
579

  QHBoxLayout *hLayout = new QHBoxLayout;

580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
  //vmChangeButton_ = new QPushButton(tr("Change View Mode"));
  //QPushButton* vmEditButton   = new QPushButton(tr("Edit View Modes"));

  /*
   * Set up view mode popup button.
   */
  viewModePopupBtn_ = new QToolButton();
  viewModePopupBtn_->setAutoRaise(true);
  //viewModePopupBtn->setText(QString::fromUtf8("⚙"));
  viewModePopupBtn_->setIcon(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"preferences.png"));
  viewModePopupBtn_->setIconSize(QSize(16, 16));
  viewModePopupBtn_->setPopupMode(QToolButton::InstantPopup);

  //init widget
  modeChangeWidget = new viewModeChangeWidget(viewModes_, this);
  modeChangeWidget->setWindowIcon(OpenFlipper::Options::OpenFlipperIcon());
  connect(modeChangeWidget,
          SIGNAL(changeView(QString, QStringList, QStringList, QStringList)),
          this,
          SLOT(slotChangeView(QString, QStringList, QStringList, QStringList)));

  viewModeChangePopupAction_ = new QWidgetAction(viewModePopupBtn_);
  viewModeChangePopupAction_->setDefaultWidget(modeChangeWidget);
  viewModePopupBtn_->addAction(viewModeChangePopupAction_);


  hLayout->setContentsMargins(0, 0, 0, 0);
  hLayout->addStretch(1);
  hLayout->addWidget(viewModePopupBtn_);
609
  viewModeControlBox_->setLayout (hLayout);
Jan Möbius's avatar
Dennis:    
Jan Möbius committed
610

611
612
613
614
615
  connect(modeChangeWidget->editViewModes_pb, SIGNAL(clicked()),
          this, SLOT(slotViewModeDialog()));
  connect(modeChangeWidget, SIGNAL(wantClose()),
          this, SLOT(closeChangeViewModePopup()));

Jan Möbius's avatar
Dennis:    
Jan Möbius committed
616
617
618

  toolBoxScroll_ = new QScrollArea ();
  toolBox_ = new SideArea ();
619
  toolBoxScroll_->setContentsMargins(0, 0, 0, 0);
Jan Möbius's avatar
Dennis:    
Jan Möbius committed
620
621
622
623
624
  toolBoxScroll_->setWidget (toolBox_);
  toolBoxScroll_->setWidgetResizable (true);
  toolBoxScroll_->setFrameStyle (QFrame::StyledPanel);

  QVBoxLayout *vLayout = new QVBoxLayout;
625
  vLayout->addWidget(viewModeControlBox_);
Jan Möbius's avatar
Dennis:    
Jan Möbius committed
626
  vLayout->addWidget(toolBoxScroll_);
627
628
  vLayout->setContentsMargins(0, 0, 0, 0);
  vLayout->setSpacing(0);
629
  
Jan Möbius's avatar
Jan Möbius committed
630
  if ( OpenFlipperSettings().value("Core/Gui/TaskSwitcher/Hide",false).toBool() ) {
631
    viewModeControlBox_->hide();
Jan Möbius's avatar
Jan Möbius committed
632
633
634
    if (viewModeButton_)
        viewModeButton_->setVisible(false);
  }
Jan Möbius's avatar
Dennis:    
Jan Möbius committed
635
636
637
638
639

  toolBoxArea_->setLayout (vLayout);

  wsizes = toolSplitter_->sizes();

640
  // if the toolbox should be on the right, use the defaults. Otherwise, we have to reorder them.
Jan Möbius's avatar
Jan Möbius committed
641
  if ( OpenFlipperSettings().value("Core/Gui/ToolBoxes/ToolBoxOnTheRight", true).toBool() ) {
642

643
644
645
646
647
    // Set relative sizes of windows
    wsizes[0] = 480;
    wsizes[1] = 240;
    toolSplitter_->setSizes(wsizes);  
  } else {
648

649
650
651
652
653
654
655
656
657
658
    // Show tool box on the left side of the main window
    toolSplitter_->insertWidget(0, toolBoxArea_);
    toolSplitter_->insertWidget(1, splitter_);

    // Default sizes are swaped when toolbox is on the left.
    wsizes[0] = 240;
    wsizes[1] = 480;
    toolSplitter_->setSizes(wsizes);
  }
  
Jan Möbius's avatar
 
Jan Möbius committed
659
660
661
  // ======================================================================
  // Context menu setup
  // ======================================================================
Jan Möbius's avatar
Jan Möbius committed
662

Jan Möbius's avatar
Jan Möbius committed
663
664
665
666
  for ( unsigned int i = 0 ; i < OpenFlipper::Options::examinerWidgets() ; ++i ) {
    connect( examiner_widgets_[i] , SIGNAL(signalCustomContextMenuRequested( const QPoint&) ) ,
             this                 , SLOT( slotCustomContextMenu( const QPoint&) ) );
  }
Jan Möbius's avatar
Jan Möbius committed
667

Dirk Wilden's avatar
   
Dirk Wilden committed
668
  contextMenu_ = new QMenu(this);
Jan Möbius's avatar
Jan Möbius committed
669
  contextSelectionMenu_ = new QMenu(tr("Selection"),0);
Jan Möbius's avatar
Jan Möbius committed
670

Jan Möbius's avatar
 
Jan Möbius committed
671
  setupMenuBar();
Jan Möbius's avatar
Jan Möbius committed
672

Jan Möbius's avatar
Jan Möbius committed
673
  statusBar_->showMessage(tr("Ready"), 5000);
Dirk Wilden's avatar
Dirk Wilden committed
674

675
  registerCoreKeys();
Dirk Wilden's avatar
Dirk Wilden committed
676

677
  setExamineMode();
678
679
680

  setWindowIcon( OpenFlipper::Options::OpenFlipperIcon() );

681
682
683
684
  // Create stereo settings widget
  stereoSettingsWidget_ = new StereoSettingsWidget(this);
  // Make it look like a dialog
  stereoSettingsWidget_->setWindowFlags(Qt::Popup);
685
686
  // Connect combo boxes and sliders to local slots
  connect(stereoSettingsWidget_->stereoOpengl, SIGNAL(clicked()),
687
          this, SLOT(slotApplyStereoSettings()));
688
689
690
691
692
  connect(stereoSettingsWidget_->stereoAnaglyph, SIGNAL(clicked()),
          this, SLOT(slotApplyStereoSettings()));
  connect(stereoSettingsWidget_->stereoCustomAnaglyph, SIGNAL(clicked()),
          this, SLOT(slotApplyStereoSettings()));

693
694
  connect(stereoSettingsWidget_->focalDistance, SIGNAL(sliderReleased()),
          this, SLOT(slotApplyStereoSettings()));
695
696
697
698
699
700
  connect(stereoSettingsWidget_->eyeDistance, SIGNAL(editingFinished()),
          this, SLOT(slotApplyStereoSettings()));

  // Close button
  connect(stereoSettingsWidget_->closeButton, SIGNAL(clicked()),
          stereoSettingsWidget_, SLOT(hide()));
701
702
703
704
705
706


  // ======================================================================
  // Help Browser start up
  // ======================================================================

707
  helpWidget_ = new HelpWidget(this,homePage_,false);
Matthias Möller's avatar
doc    
Matthias Möller committed
708
709
  connect(this, SIGNAL(changeHelpSite(QUrl)), helpWidget_, SLOT(activateLink(QUrl)));
  helpWidget_->hide();
710

Jan Möbius's avatar
Jan Möbius committed
711
712
713
714

  // Add the core license information about used libraries
  addCoreLicenseInfo();

Jan Möbius's avatar
 
Jan Möbius committed
715
716
717
718
719
720
721
}


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


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

Jan Möbius's avatar
 
Jan Möbius committed
723
724
725
726
727
728
729
730
}

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

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

732
  bool fullScreen = OpenFlipperSettings().value("Core/Gui/fullscreen", false ).toBool();
Dirk Wilden's avatar
Dirk Wilden committed
733

734
  setFullscreen( !fullScreen );
Jan Möbius's avatar
 
Jan Möbius committed
735
736
737
738
}

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

739
740
741
742
743
744
745
746
747
748
749
/** Enable or disable Fullscreen Mode
  */
void
CoreWidget::setFullscreen(bool _state ) {
  if ( _state )
    setWindowState( windowState() | Qt::WindowFullScreen);
  else {
    if ( windowState() & Qt::WindowFullScreen )
      setWindowState( windowState() ^  Qt::WindowFullScreen);
  }

Jan Möbius's avatar
Jan Möbius committed
750
  OpenFlipperSettings().setValue("Core/Gui/fullscreen", bool( windowState() & Qt::WindowFullScreen) );
751
752

  show();
753
754

  emit fullScreenChanged( _state );
755
756
}

757
758
759
760
761
762
763
764
765
766
//-----------------------------------------------------------------------------

void 
CoreWidget::showViewModeControls(bool _show) {
  // Only change if the actual setting has changed!
  if ( OpenFlipper::Options::gui() && ( !_show != OpenFlipperSettings().value("Core/Gui/TaskSwitcher/Hide",false).toBool() ) ) {
  
    // Update setting in Conf storage
    OpenFlipperSettings().setValue("Core/Gui/TaskSwitcher/Hide",!_show);
    
767
768
769
770
771
    // Update The Checkbox in the Menu
    AC_ShowViewModeControls_->blockSignals(true);
    AC_ShowViewModeControls_->setChecked( _show  );
    AC_ShowViewModeControls_->blockSignals(false);
    
772
773
    if ( _show ) {
      viewModeControlBox_->show();
Jan Möbius's avatar
Jan Möbius committed
774
      viewModeButton_->setVisible(true);
775
776
    } else {
      viewModeControlBox_->hide();
Jan Möbius's avatar
Jan Möbius committed
777
      viewModeButton_->setVisible(false);
778
779
780
781
782
783
    }
    
  }
  
}

Jan Möbius's avatar
 
Jan Möbius committed
784
785
786
787
788
789
//-----------------------------------------------------------------------------

/** Hide or show toolbox
  */
void
CoreWidget::toggleToolbox() {
Jan Möbius's avatar
Jan Möbius committed
790

Jan Möbius's avatar
 
Jan Möbius committed
791
  //toggle
Jan Möbius's avatar
Jan Möbius committed
792
  showToolbox( OpenFlipperSettings().value("Core/Gui/ToolBoxes/hidden",false).toBool() );
793

794
795
796
797
798
799
800
801
802
803
}

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

/** Hide or show toolbox
  */
void
CoreWidget::showToolbox( bool _state ) {

  //toggle
Jan Möbius's avatar
Jan Möbius committed
804
  OpenFlipperSettings().setValue("Core/Gui/ToolBoxes/hidden",!_state);
Jan Möbius's avatar
 
Jan Möbius committed
805

Jan Möbius's avatar
Jan Möbius committed
806
  if ( OpenFlipperSettings().value("Core/Gui/ToolBoxes/hidden",false).toBool() ){
Jan Möbius's avatar
 
Jan Möbius committed
807
808

    //hide ViewMode Selection Widget
Jan Möbius's avatar
Dennis:    
Jan Möbius committed
809
    toolBoxArea_->setVisible(false);
Jan Möbius's avatar
 
Jan Möbius committed
810
811

  }else{
812
    //show last view mode
Jan Möbius's avatar
Dennis:    
Jan Möbius committed
813
    toolBoxArea_->setVisible(true);
Jan Möbius's avatar
 
Jan Möbius committed
814
  }
815
  emit toolBoxVisChanged(_state);
Jan Möbius's avatar
 
Jan Möbius committed
816
}
817
//-----------------------------------------------------------------------------
818
void CoreWidget::showMenuBar( bool _state )
819
{
820
821
822
823
824
  OpenFlipperSettings().setValue("Core/Gui/MenuBar/hidden",!_state);

  if ( _state ){

    //hide ViewMode Selection Widget
825
    menuBar()->show();
826
827
828

  }else{
    //show last view mode
829
    menuBar()->hide();
830
831
  }
  emit menuBarVisChanged(_state);
832
833
}
//-----------------------------------------------------------------------------
834
835
/// Show or hide toolbar
void CoreWidget::showToolBar( bool _state )
836
{
837
838
  OpenFlipperSettings().setValue("Core/Gui/Toolbar/hidden",!_state);
  if ( !_state )
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
  {
    //hide main toolbar
    if ( ! mainToolbar_->isFloating() )
      mainToolbar_->hide();

    //hide viewer toolbar
    if ( ! viewerToolbar_->isFloating() )
      viewerToolbar_->hide();

    for (uint p=0; p < plugins_.size(); p++)
      for ( uint j = 0 ; j < plugins_[p].toolbars.size(); ++j ) {
        if ( ! plugins_[p].toolbars[j].second->isFloating() )
          plugins_[p].toolbars[j].second->hide();
      }
  }
  else
  {
    //show toolbars
    setViewMode( OpenFlipper::Options::currentViewMode() );
  }
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
  emit toolBarVisChanged(_state);
}
//-----------------------------------------------------------------------------
/// Hide or show menubar
void CoreWidget::toggleMenuBar()
{
  bool hidden = OpenFlipperSettings().value("Core/Gui/MenuBar/hidden",false).toBool();
  showMenuBar( hidden );
}

//-----------------------------------------------------------------------------
/// Hide or show current toolbar
void CoreWidget::toggleToolBar()
{
  bool hidden = OpenFlipperSettings().value("Core/Gui/Toolbar/hidden",false).toBool();
  showToolBar( hidden );
875
}
Jan Möbius's avatar
Jan Möbius committed
876

877

878
879
//=============================================================================

880
void CoreWidget::setToolBoxOrientationOnTheRight(bool _toolBoxRight) {
881
  QList<int> wsizes;
Jan Möbius's avatar
Jan Möbius committed
882
  
883
884
  // Is toolbox currently on the right hand side?
  bool currentstate = toolSplitter_->widget(1) == toolBoxArea_;
Jan Möbius's avatar
Jan Möbius committed
885
886
  
  if ( _toolBoxRight != currentstate ) {
887
    
Jan Möbius's avatar
Jan Möbius committed
888
889
890
891
892
893
894
895
896
897
898
    if(_toolBoxRight ) {
      
      // Show tool box on the right side of the main window
      toolSplitter_->insertWidget(0, splitter_);
      toolSplitter_->insertWidget(1, toolBoxArea_);
    } else {
      
      // Show tool box on the left side of the main window
      toolSplitter_->insertWidget(0, toolBoxArea_);
      toolSplitter_->insertWidget(1, splitter_);
    }
899
    
Jan Möbius's avatar
Jan Möbius committed
900
    // Store new setting
Jan Möbius's avatar
Jan Möbius committed
901
    OpenFlipperSettings().setValue("Core/Gui/ToolBoxes/ToolBoxOnTheRight",_toolBoxRight);
902
    
Jan Möbius's avatar
Jan Möbius committed
903
904
    // remove the windowstates definition for the toolboxes, as it changed anyway.
    QSettings windowStates(QDir::home().absolutePath() + OpenFlipper::Options::dirSeparator() + ".OpenFlipper" +
905
                            OpenFlipper::Options::dirSeparator() +  "WindowStates.dat", QSettings::IniFormat);
Jan Möbius's avatar
Jan Möbius committed
906
907
    
    windowStates.value("Core/ToolSplitter");
908
909
910
    
  }
  
Jan Möbius's avatar
Jan Möbius committed
911

912
913
914
915
916
    
  toolSplitter_->refresh();
}
      

Jan Möbius's avatar
 
Jan Möbius committed
917
918
//=============================================================================

Jan Möbius's avatar
Jan Möbius committed
919
920
void
CoreWidget::addRecent(QString _filename, DataType _type)
Jan Möbius's avatar
 
Jan Möbius committed
921
{
922
  //dont add objects to recentMenu while loadind Settings
923
  if ( OpenFlipper::Options::sceneGraphUpdatesBlocked() ) return;
Jan Möbius's avatar
Jan Möbius committed
924

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

Jan Möbius's avatar
 
Jan Möbius committed
927
  updateRecent();
Jan Möbius's avatar
Jan Möbius committed
928
929
930
931
932
933
934

}

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

void
CoreWidget::updateRecent()
Jan Möbius's avatar
 
Jan Möbius committed
935
936
937
{
  if ( recentFilesMenu_ == NULL)
    return;
Jan Möbius's avatar
Jan Möbius committed
938

Jan Möbius's avatar
 
Jan Möbius committed
939
940
  recentFilesMenu_->clear();

941
942
  QStringList recentFiles = OpenFlipperSettings().value("Core/File/RecentFiles", QStringList()).toStringList();
  QStringList recentTypes = OpenFlipperSettings().value("Core/File/RecentTypes", QStringList()).toStringList();
943

Jan Möbius's avatar
 
Jan Möbius committed
944
  for (int i = 0 ; i < recentFiles.size() ; ++i ) {
945

946
    QFileInfo fi(recentFiles[i]);
947

948
949
950
951
    QAction* newAction = 0;

    if (fi.suffix() == "ini") {
      newAction = recentFilesMenu_->addAction(QIcon(OpenFlipper::Options::iconDirStr() + OpenFlipper::Options::dirSeparator()+"Settings-Icon.png"), recentFiles[i]);
952
      newAction->setData( QVariant( QString("Unknown") ) );
953
954
955
956
    } else {
      newAction = recentFilesMenu_->addAction(typeIcon( typeId(recentTypes[i]) ), recentFiles[i]);
      newAction->setData( QVariant( recentTypes[i]) );
    }
957

Jan Möbius's avatar
 
Jan Möbius committed
958
959
  }

Jan Möbius's avatar
Jan Möbius committed
960
961
962
}

void
Jan Möbius's avatar
 
Jan Möbius committed
963
964
965
CoreWidget::closeEvent ( QCloseEvent * /* event */ ) {
  emit exit();
}
966
967

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

969
970
  if ( OpenFlipper::Options::nogui() )
    return;
Jan Möbius's avatar
Jan Möbius committed
971

972
  if ( optionsWidget_ == 0 ) {
Dirk Wilden's avatar
Dirk Wilden committed
973
    optionsWidget_ = new OptionsWidget(plugins_, coreKeys_, invKeys_, 0);
974
    connect(optionsWidget_,SIGNAL(applyOptions()),this,SIGNAL(applyOptions()));
Dirk Wilden's avatar
Dirk Wilden committed
975
    connect(optionsWidget_,SIGNAL(saveOptions()),this,SIGNAL(saveOptions()));
Dirk Wilden's avatar
Dirk Wilden committed
976
977
    connect(optionsWidget_,SIGNAL(addKeyMapping(int,Qt::KeyboardModifiers,QObject*,int)),
            this,          SLOT(slotAddKeyMapping(int,Qt::KeyboardModifiers,QObject*,int)));
978
979

    optionsWidget_->setWindowIcon( OpenFlipper::Options::OpenFlipperIcon() );
980
  }
Dirk Wilden's avatar
Dirk Wilden committed
981

Jan Möbius's avatar
Jan Möbius committed
982
  //show the optionsWidget centered
Dirk Wilden's avatar
Dirk Wilden committed
983
  QPoint center;
Jan Möbius's avatar
Jan Möbius committed
984
  center.setX( x() + width() / 2 );
Dirk Wilden's avatar
Dirk Wilden committed
985
986
  center.setY( y() + height() / 2 );

Dirk Wilden's avatar
Dirk Wilden committed
987
988
  optionsWidget_->setGeometry(center.x() - optionsWidget_->width() / 2,
                              center.y() - optionsWidget_->height()/ 2, optionsWidget_->width(), optionsWidget_->height());
Dirk Wilden's avatar
Dirk Wilden committed
989

990
  optionsWidget_->show();