optionsWidget.cc 33 KB
Newer Older
1
/*===========================================================================*\
Jan Möbius's avatar
Jan Möbius committed
2 3
*                                                                            *
*                              OpenFlipper                                   *
Jan Möbius's avatar
Jan Möbius committed
4
*      Copyright (C) 2001-2011 by Computer Graphics Group, RWTH Aachen       *
Jan Möbius's avatar
Jan Möbius committed
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
*                           www.openflipper.org                              *
*                                                                            *
*--------------------------------------------------------------------------- *
*  This file is part of OpenFlipper.                                         *
*                                                                            *
*  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 with the               *
*  following exceptions:                                                     *
*                                                                            *
*  If other files instantiate templates or use macros                        *
*  or inline functions from this file, or you compile this file and          *
*  link it with other files to produce an executable, this file does         *
*  not by itself cause the resulting executable to be covered by the         *
*  GNU Lesser General Public License. This exception does not however        *
*  invalidate any other reasons why the executable file might be             *
*  covered by the GNU Lesser General Public License.                         *
*                                                                            *
*  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.                       *
*                                                                            *
*  You should have received a copy of the GNU LesserGeneral Public           *
*  License along with OpenFlipper. If not,                                   *
*  see <http://www.gnu.org/licenses/>.                                       *
*                                                                            *
33 34 35
\*===========================================================================*/

/*===========================================================================*\
Jan Möbius's avatar
Jan Möbius committed
36 37 38 39 40
*                                                                            *
*   $Revision$                                                       *
*   $LastChangedBy$                                                *
*   $Date$                     *
*                                                                            *
41
\*===========================================================================*/
42 43 44 45 46 47 48




#include "optionsWidget.hh"
#include <iostream>
#include <OpenFlipper/common/GlobalOptions.hh>
Dirk Wilden's avatar
Dirk Wilden committed
49 50
#include <ACG/Scenegraph/DrawModes.hh>
#include <OpenFlipper/ACGHelper/DrawModeConverter.hh>
51
#include <OpenFlipper/INIFile/INIFile.hh>
52
#include <OpenFlipper/BasePlugin/PluginFunctions.hh>
Dirk Wilden's avatar
Dirk Wilden committed
53

54
#include <QColorDialog>
55
#include <QMessageBox>
56

Dirk Wilden's avatar
Dirk Wilden committed
57
OptionsWidget::OptionsWidget(std::vector<PluginInfo>& _plugins, std::vector<KeyBinding>& _core, InverseKeyMap& _invKeys, QWidget *parent)
Jan Möbius's avatar
Jan Möbius committed
58 59
  : QWidget(parent),
    plugins_(_plugins),
Dirk Wilden's avatar
Dirk Wilden committed
60
    coreKeys_(_core),
61
    keys_(_invKeys),
62
    restartRequired_(false),
63
    exitOnClose_(false)
64 65
{
  setupUi(this);
Dirk Wilden's avatar
Dirk Wilden committed
66

Dirk Wilden's avatar
Dirk Wilden committed
67
  connect(okButton,SIGNAL(clicked()),this,SLOT(slotOk()));
68 69
  connect(applyButton,SIGNAL(clicked()),this,SLOT(slotApply()));
  connect(cancelButton,SIGNAL(clicked()),this,SLOT(slotCancel()));
Jan Möbius's avatar
Jan Möbius committed
70
  connect(checkUpdateButton,SIGNAL(clicked()),this,SLOT(slotCheckUpdates()));
Jan Möbius's avatar
Jan Möbius committed
71 72
  connect(updateButton,SIGNAL(clicked()),this,SLOT(slotGetUpdates()));
  updateButton->setEnabled(false);
73 74

  // Viewer Settings
Dirk Wilden's avatar
Dirk Wilden committed
75
  connect( restrictFPS, SIGNAL(toggled(bool)), FPS, SLOT(setEnabled(bool)) );
76 77 78 79
  connect( viewerList, SIGNAL(currentRowChanged(int)), this, SLOT(updateViewerSettings(int)) );
  connect( availDrawModes, SIGNAL(itemChanged(QListWidgetItem*)), this, SLOT(viewerSettingsChanged(QListWidgetItem*)) );
  connect( projectionBox, SIGNAL(currentIndexChanged(int)), this, SLOT(viewerSettingsChanged(int)));
  connect( directionBox, SIGNAL(currentIndexChanged(int)), this, SLOT(viewerSettingsChanged(int)));
80
  connect( lockRotationBox, SIGNAL(stateChanged(int)), this, SLOT(viewerSettingsChanged(int)));
81

82 83 84 85 86 87 88
  // Switch stacked widget of stereo settings
  connect(stereoOpengl, SIGNAL(clicked()),
          this, SLOT(switchStackedWidget()));
  connect(stereoAnaglyph, SIGNAL(clicked()),
          this, SLOT(switchStackedWidget()));
  connect(stereoCustomAnaglyph, SIGNAL(clicked()),
          this, SLOT(switchStackedWidget()));
89 90 91 92 93 94
  
  connect(focalDistance, SIGNAL(sliderReleased()),
          this, SLOT(slotPreviewStereoSettings()));
  connect(eyeDistance, SIGNAL(editingFinished()),
          this, SLOT(slotPreviewStereoSettings()));

95
  ACG::SceneGraph::DrawModes::ModeFlagSet mode(2);
Dirk Wilden's avatar
Dirk Wilden committed
96
  for (uint i=1; i < 22; i++) {
97
    std::vector< QString > dm = drawModeToDescriptions( mode );
Jan Möbius's avatar
Jan Möbius committed
98

99
    if ( !dm.empty() && dm[0].trimmed() != ""){
Dirk Wilden's avatar
Dirk Wilden committed
100
      QListWidgetItem* item = new QListWidgetItem(dm[0]);
Jan Möbius's avatar
Jan Möbius committed
101

Dirk Wilden's avatar
Dirk Wilden committed
102
      item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsUserCheckable | Qt::ItemIsSelectable);
103

104
      item->setCheckState(Qt::Unchecked);
Dirk Wilden's avatar
Dirk Wilden committed
105 106 107

      availDrawModes->addItem( item );
    }
108

Dirk Wilden's avatar
Dirk Wilden committed
109
    mode = mode<<1;
110
  }
Dirk Wilden's avatar
Dirk Wilden committed
111

112 113 114 115
  defaultProjectionMode_.resize(4);
  defaultViewingDirections_.resize(4);
  defaultRotationLocks_.resize(4);

116 117
  for ( int i=0; i < PluginFunctions::viewers(); i++ ){
    viewerList->addItem("Viewer " + QString::number(i+1) );
118
    defaultDrawModes_.push_back( ACG::SceneGraph::DrawModes::DEFAULT );
119
  }
Jan Möbius's avatar
Jan Möbius committed
120

Dirk Wilden's avatar
Dirk Wilden committed
121 122 123
  pluginOptionsLayout = new QVBoxLayout;
  pluginOptions->setLayout( pluginOptionsLayout );

124
  networkMan_ = new QNetworkAccessManager(this);
Jan Möbius's avatar
Jan Möbius committed
125

Jan Möbius's avatar
Jan Möbius committed
126
  // http specific connections
127 128 129 130
  connect(networkMan_, SIGNAL(finished(QNetworkReply *)),
        this, SLOT(httpRequestFinished(QNetworkReply *)));
  connect(networkMan_,SIGNAL(authenticationRequired(QNetworkReply* , QAuthenticator *)),
        this,SLOT(authentication(QNetworkReply *, QAuthenticator*)));
Jan Möbius's avatar
Jan Möbius committed
131

Jan Möbius's avatar
Jan Möbius committed
132 133 134

  progressDialog = new QProgressDialog(this);
  connect(progressDialog, SIGNAL(canceled()), this, SLOT(cancelDownload()));
135 136 137

  //colordialog
  connect(backgroundButton, SIGNAL(clicked()), this, SLOT(getBackgroundColor()) );
138
  connect(defaultColorButton, SIGNAL(clicked()), this, SLOT(getDefaultColor()) );
139 140 141 142
  
  // Clear settings and ini buttons
  connect(clearSettingsButton, SIGNAL(clicked()), this, SLOT(slotClearSettings()));
  connect(clearINIButton,      SIGNAL(clicked()), this, SLOT(slotClearINI()));
143 144 145 146 147 148

  // Disable update tab if app store compliant build
  #ifdef OPENFLIPPER_BUILD_APP_STORE_COMPLIANT
    //tabWidget->setTabEnabled(tabWidget->count()-1,false);
    tabWidget->removeTab(tabWidget->count()-1);
  #endif
149 150 151
}

void OptionsWidget::getBackgroundColor(){
152
  QColor newColor = QColorDialog::getColor ( OpenFlipperSettings().value("Core/Gui/glViewer/defaultBackgroundColor").value<QColor>() );
Jan Möbius's avatar
Jan Möbius committed
153

154 155
  backgroundColor_ = newColor;
  
156
  QPixmap color(16,16);
157
  color.fill( newColor );
158
  backgroundButton->setIcon( QIcon(color) );
159 160
}

161 162
void OptionsWidget::getDefaultColor(){
  QColor newColor = QColorDialog::getColor ( OpenFlipper::Options::defaultColor() );
163

164
  OpenFlipper::Options::defaultColor( newColor) ;
165 166

  QPixmap color(16,16);
167 168
  color.fill( OpenFlipper::Options::defaultColor() );
  defaultColorButton->setIcon( QIcon(color) );
169 170
}

171 172 173 174 175 176 177 178 179 180 181 182
void OptionsWidget::viewerSettingsChanged(QListWidgetItem* /*_item*/){
  viewerSettingsChanged(0);
};

void OptionsWidget::viewerSettingsChanged(int /*_index*/){

  if ( !updatingViewerSettings_ ){
    //viewer defaults
    std::vector< QString > mode;

    for (int i=0; i < availDrawModes->count(); i++)
      if (availDrawModes->item(i)->checkState() == Qt::Checked)
183
        mode.push_back( availDrawModes->item(i)->text() );
184 185

    defaultDrawModes_[         viewerList->currentRow() ] = descriptionsToDrawMode(mode);
186
    defaultProjectionMode_[    viewerList->currentRow() ] = projectionBox->currentIndex() ;
187
    defaultViewingDirections_[ viewerList->currentRow() ] = directionBox->currentIndex();
188 189 190 191 192 193
    defaultRotationLocks_[ viewerList->currentRow() ]     = lockRotationBox->isChecked();

    if ( lockRotationBox->isChecked() )
      std::cerr << "locked" << std::endl;
    else
      std::cerr << "unlocked" << std::endl;
194 195 196
  }
};

197 198 199 200 201
void OptionsWidget::switchStackedWidget() {

    // Show right stacked widget of stereo settings
    if (stereoCustomAnaglyph->isChecked()) {
        stackedWidget->setCurrentIndex(0);
202
        customAnaGlyphSettings->setVisible(true);
Jan Möbius's avatar
Typo  
Jan Möbius committed
203
    } else {
204
        stackedWidget->setCurrentIndex(0);
205
        customAnaGlyphSettings->setVisible(false);
206
    }
207 208 209
    
    // Preview new settings
    slotPreviewStereoSettings();
210 211
}

212
void OptionsWidget::slotTranslationIndexChanged(int /*_index*/) {
213
  restartRequired_ = true;
214 215
}

216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233
void OptionsWidget::updateViewerSettings(int _row){

  updatingViewerSettings_ = true;

  for (int i = 0 ; i < availDrawModes->count(); ++i )
    availDrawModes->item( i )->setCheckState(Qt::Unchecked) ;

  //Check the drawModes from StandardDrawMode
  std::vector< QString > dm = drawModeToDescriptions( defaultDrawModes_[_row] );

  for (uint i=0; i < dm.size(); i++){
    if ( !dm.empty() ) {
      QList< QListWidgetItem* > found = availDrawModes->findItems(dm[i],Qt::MatchExactly);
      for(int k=0; k < found.count(); k++)
        (found[k])->setCheckState(Qt::Checked);
    }
  }

234 235 236 237 238
  if ( defaultProjectionMode_[_row] )
    projectionBox->setCurrentIndex( 1 );
  else
    projectionBox->setCurrentIndex( 0 );

239 240
  directionBox->setCurrentIndex(  defaultViewingDirections_[_row] );

241 242
  lockRotationBox->setChecked( defaultRotationLocks_[_row] );

243 244 245
  updatingViewerSettings_ = false;
}

Dirk Wilden's avatar
Dirk Wilden committed
246
void OptionsWidget::showEvent ( QShowEvent * /*event*/ ) {
Dirk Wilden's avatar
Dirk Wilden committed
247

Jan Möbius's avatar
Jan Möbius committed
248
  //general
Jan Möbius's avatar
Jan Möbius committed
249
  fullscreen->setChecked( OpenFlipperSettings().value("Core/Gui/fullscreen",false).toBool() );
250
  splash->setChecked( OpenFlipperSettings().value("Core/Gui/splash",true).toBool() );
Jan Möbius's avatar
Jan Möbius committed
251 252
  toolbox->setChecked( !OpenFlipperSettings().value("Core/Gui/ToolBoxes/hidden",false).toBool() );
  
Dirk Wilden's avatar
Dirk Wilden committed
253 254 255 256 257 258 259
  iconSmall->setChecked(false);
  iconNormal->setChecked(false);
  iconDefault->setChecked(false);
  
  switch ( OpenFlipperSettings().value("Core/Toolbar/iconSize",0).toInt() ){
    case 1  : iconSmall->setChecked(true); break;
    case 2  : iconNormal->setChecked(true); break;
Jan Möbius's avatar
Jan Möbius committed
260
    default : iconDefault->setChecked(true); break;
Dirk Wilden's avatar
Dirk Wilden committed
261 262
  }
  
Jan Möbius's avatar
Dennis:  
Jan Möbius committed
263 264 265
  loggerHidden->setChecked( OpenFlipper::Options::loggerState() == OpenFlipper::Options::Hidden);
  loggerNormal->setChecked( OpenFlipper::Options::loggerState() == OpenFlipper::Options::Normal);
  loggerInScene->setChecked( OpenFlipper::Options::loggerState() == OpenFlipper::Options::InScene);
Jan Möbius's avatar
Jan Möbius committed
266
  enableLogFile->setChecked( OpenFlipperSettings().value("Core/Log/logFileEnabled",true).toBool() );
Jan Möbius's avatar
Jan Möbius committed
267

Jan Möbius's avatar
Jan Möbius committed
268
  //Files
Jan Möbius's avatar
Jan Möbius committed
269
  logFile->setText( OpenFlipperSettings().value("Core/Log/logFile").toString()  );
Jan Möbius's avatar
Jan Möbius committed
270
  maxRecentBox->setValue( OpenFlipperSettings().value("Core/File/MaxRecent",15).toInt() );
Dirk Wilden's avatar
Dirk Wilden committed
271

272
  // UI settings
273
  toolBoxOrientation->setCurrentIndex((OpenFlipperSettings().value("Core/Gui/ToolBoxes/ToolBoxOnTheRight",true).toBool() ? 0 : 1));
274
  
275
  pickToolbarInScene->setChecked(OpenFlipperSettings().value("Core/Gui/ToolBars/PickToolbarInScene",true).toBool());
276

Jan Möbius's avatar
Dennis:  
Jan Möbius committed
277
  //stereo
278 279 280 281 282 283 284 285

  // Grey out OpenGL stereo mode option if not available
  if(!OpenFlipper::Options::glStereo()) {
      stereoOpengl->setDisabled(true);
  } else {
      stereoOpengl->setChecked(OpenFlipper::Options::stereoMode() == OpenFlipper::Options::OpenGL);
  }

Jan Möbius's avatar
Dennis:  
Jan Möbius committed
286 287 288
  stereoAnaglyph->setChecked (OpenFlipper::Options::stereoMode() == OpenFlipper::Options::AnaglyphRedCyan);
  stereoCustomAnaglyph->setChecked (OpenFlipper::Options::stereoMode() == OpenFlipper::Options::AnaglyphCustom);

289
  eyeDistance->setValue ( OpenFlipperSettings().value("Core/Stereo/EyeDistance").toDouble() );
290
  focalDistance->setValue ( OpenFlipperSettings().value("Core/Stereo/FocalDistance").toDouble()  * 1000);
Jan Möbius's avatar
Dennis:  
Jan Möbius committed
291

292
  // Show right stacked widget
293
  customAnaGlyphSettings->setVisible(false);
294 295 296 297 298

  stackedWidget->setCurrentIndex(0);

  if (stereoCustomAnaglyph->isChecked())
    customAnaGlyphSettings->setVisible(true);
299

Jan Möbius's avatar
Dennis:  
Jan Möbius committed
300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321
  std::vector<float> mat = OpenFlipper::Options::anaglyphLeftEyeColorMatrix ();
  lcm0->setValue (mat[0]);
  lcm1->setValue (mat[1]);
  lcm2->setValue (mat[2]);
  lcm3->setValue (mat[3]);
  lcm4->setValue (mat[4]);
  lcm5->setValue (mat[5]);
  lcm6->setValue (mat[6]);
  lcm7->setValue (mat[7]);
  lcm8->setValue (mat[8]);

  mat = OpenFlipper::Options::anaglyphRightEyeColorMatrix ();
  rcm0->setValue (mat[0]);
  rcm1->setValue (mat[1]);
  rcm2->setValue (mat[2]);
  rcm3->setValue (mat[3]);
  rcm4->setValue (mat[4]);
  rcm5->setValue (mat[5]);
  rcm6->setValue (mat[6]);
  rcm7->setValue (mat[7]);
  rcm8->setValue (mat[8]);

322
  noMousePick->setChecked ( !OpenFlipperSettings().value("Core/Gui/glViewer/stereoMousePick",true).toBool() );
Jan Möbius's avatar
Jan Möbius committed
323
  nativeMouse->setChecked ( OpenFlipperSettings().value("Core/Gui/glViewer/nativeMouse",false).toBool() );
Jan Möbius's avatar
Dennis:  
Jan Möbius committed
324

Dirk Wilden's avatar
Dirk Wilden committed
325 326 327
  // plugin options
  initPluginOptions();

328
  // updates
329 330 331
  updateUser->setText( OpenFlipperSettings().value("Core/Update/UserName","anonymous").toString() );
  updatePass->setText( OpenFlipperSettings().value("Core/Update/Pass","anonymous").toString() );
  updateURL->setText( OpenFlipperSettings().value("Core/Update/URL","http://").toString() );
332

Jan Möbius's avatar
Jan Möbius committed
333 334 335
  // debugging
  slotDebugging->setChecked(OpenFlipper::Options::doSlotDebugging());

Dirk Wilden's avatar
Dirk Wilden committed
336
  //keyBindings
Dirk Wilden's avatar
Dirk Wilden committed
337
  initKeyTree();
338

Dirk Wilden's avatar
Dirk Wilden committed
339
  keyTree->disconnect(); //to be sure..disconnect every slot
Dirk Wilden's avatar
Dirk Wilden committed
340

Dirk Wilden's avatar
Dirk Wilden committed
341 342
  connect(keyTree, SIGNAL(currentItemChanged(QTreeWidgetItem*, QTreeWidgetItem*)),
          this,    SLOT(keyTreeItemChanged( QTreeWidgetItem*, QTreeWidgetItem*)) );
Dirk Wilden's avatar
Dirk Wilden committed
343

Dirk Wilden's avatar
Dirk Wilden committed
344 345
  connect(keyTree, SIGNAL(itemDoubleClicked (QTreeWidgetItem*, int)),
          this,    SLOT(keyTreeDoubleClicked( QTreeWidgetItem*, int)) );
Dirk Wilden's avatar
Dirk Wilden committed
346 347


Dirk Wilden's avatar
Dirk Wilden committed
348
  connect(shortcutButton, SIGNAL(keyChanged()), this, SLOT(updateShortcut()) );
349
  connect(presetsButton, SIGNAL(clicked()), this, SLOT(restoreKeyPresets()) );
350 351


352
  //Init Viewer Settings
353 354
  wZoomFactor->setValue( OpenFlipperSettings().value("Core/Mouse/Wheel/ZoomFactor").toDouble() );
  wZoomFactorShift->setValue( OpenFlipperSettings().value("Core/Mouse/Wheel/ZoomFactorShift").toDouble() );
355
  invertMouseWheelBox->setChecked( OpenFlipperSettings().value("Core/Mouse/Wheel/Invert").toBool() );
356

Jan Möbius's avatar
Jan Möbius committed
357
  wheelBox->setChecked( OpenFlipperSettings().value("Core/Gui/glViewer/showControlWheels").toBool() );
358 359
  
  // Projection settings
360
  fieldOfView->setValue(OpenFlipperSettings().value("Core/Projection/FOVY", 45.0).toDouble() );
361

362 363
  restrictFPS->setChecked( OpenFlipperSettings().value("Core/Gui/glViewer/restrictFrameRate",false).toBool() );
  FPS->setValue( OpenFlipperSettings().value("Core/Gui/glViewer/maxFrameRate",35).toInt() );
364 365
  
  minimalSceneSize->setValue( OpenFlipperSettings().value("Core/Gui/glViewer/minimalSceneSize",0.1).toDouble());
366 367

  QPixmap color(16,16);
368
  color.fill( OpenFlipperSettings().value("Core/Gui/glViewer/defaultBackgroundColor").value<QColor>() );
369
  backgroundColor_ = OpenFlipperSettings().value("Core/Gui/glViewer/defaultBackgroundColor").value<QColor>();
370 371
  backgroundButton->setIcon( QIcon(color) );

372 373
  color.fill( OpenFlipper::Options::defaultColor() );
  defaultColorButton->setIcon( QIcon(color) );
374

375
  randomDefaultColor->setChecked( OpenFlipper::Options::randomDefaultColor() );
376

377 378 379 380
  viewerList->setCurrentRow(0);

  for ( int i=0; i < PluginFunctions::viewers(); i++ ){
    defaultDrawModes_[i] = OpenFlipper::Options::defaultDrawMode(i);
381
    defaultProjectionMode_[i] = OpenFlipper::Options::defaultPerspectiveProjectionMode(i);
382
    defaultViewingDirections_[i] = OpenFlipper::Options::defaultViewingDirection(i);
383
    defaultRotationLocks_[i] = OpenFlipper::Options::defaultLockRotation(i);
384
  }
Jan Möbius's avatar
Jan Möbius committed
385

386 387
  updateViewerSettings(0);

388
  viewerLayout->setCurrentIndex( OpenFlipper::Options::defaultViewerLayout() );
389

390
  if (OpenFlipperSettings().value("Core/Language/Translation","en_US").toString() == "en_US")
391
    translation->setCurrentIndex(0);
392
  else if (OpenFlipperSettings().value("Core/Language/Translation","en_US").toString() == "de_DE")
393 394 395
    translation->setCurrentIndex(1);
  else
    translation->setCurrentIndex(2);
396 397 398
  
  // Listen to changes...
  connect(translation, SIGNAL(currentIndexChanged(int)), this, SLOT(slotTranslationIndexChanged(int)));
399

Jan Möbius's avatar
Jan Möbius committed
400 401 402 403 404 405
  updateVersionsTable();

}

void OptionsWidget::updateVersionsTable() {

Jan Möbius's avatar
Jan Möbius committed
406 407
  updatedPlugins_.clear();

Jan Möbius's avatar
Jan Möbius committed
408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426
  QString fileName = QDir::home().absolutePath() + OpenFlipper::Options::dirSeparator() +
                     ".OpenFlipper" + OpenFlipper::Options::dirSeparator() + "Versions.ini" ;

  INIFile ini;

  ini.connect(fileName,false);

  QString systemString = "";

  if ( OpenFlipper::Options::isWindows() ) {
    systemString = "VersionWindows";
  } else if (OpenFlipper::Options::isLinux()) {
    systemString = "VersionLinux";
  } else {
    std::cerr << "Unsupported platform for update" << std::endl;
    return;
  }

  updateList->clear();
427
  updateList->setRowCount( int(1 + plugins_.size()) );
Jan Möbius's avatar
Jan Möbius committed
428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443
  updateList->setColumnCount(3);

  QStringList header;

  header << "Component" << "current Version" << "latest Version" ;
  updateList->setHorizontalHeaderLabels(header);

  QBrush currentBrush(Qt::white);

  QTableWidgetItem * newItem = 0;

  QString coreVersion;

  if ( ini.is_connected() && ini.get_entry(coreVersion, "Core" , systemString ) ) {

    // Newer Version available
Jan Möbius's avatar
Jan Möbius committed
444
    if ( isNewer(OpenFlipper::Options::coreVersion(),coreVersion) ) {
Jan Möbius's avatar
Jan Möbius committed
445
      currentBrush.setColor(Qt::red);
Jan Möbius's avatar
Jan Möbius committed
446 447
      updatedPlugins_ << "Core";
    } else if ( isNewer(coreVersion , OpenFlipper::Options::coreVersion()) )
448
      currentBrush.setColor(Qt::blue);
Jan Möbius's avatar
Jan Möbius committed
449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480
    else
      currentBrush.setColor(Qt::green);

    newItem = new QTableWidgetItem( coreVersion );

  } else {

    // No local Information available
    currentBrush.setColor(Qt::yellow);

    newItem = new QTableWidgetItem( "Not Available" );
  }

  newItem->setBackground(currentBrush);
  updateList->setItem(0, 2, newItem);

  newItem = new QTableWidgetItem( OpenFlipper::Options::coreVersion() );
  newItem->setBackground(currentBrush);
  updateList->setItem(0, 1, newItem);

  newItem = new QTableWidgetItem( "Core" );
  newItem->setBackground(currentBrush);
  updateList->setItem(0, 0, newItem);


  for ( uint i = 0 ; i < plugins_.size(); ++i ) {
    QString latestVersion;

    if ( ini.is_connected() && ini.get_entry(latestVersion, plugins_[i].name , systemString ) ) {


      // Newer Version available
Jan Möbius's avatar
Jan Möbius committed
481
      if ( isNewer(plugins_[i].version,latestVersion) ) {
482
         currentBrush.setColor(Qt::red);
Jan Möbius's avatar
Jan Möbius committed
483 484 485
         QFileInfo pluginFile(plugins_[i].path );
         updatedPlugins_ << pluginFile.fileName();
      } else if ( isNewer(latestVersion,plugins_[i].version) )
486
         currentBrush.setColor(Qt::blue);
Jan Möbius's avatar
Jan Möbius committed
487
      else
488
         currentBrush.setColor(Qt::green);
Jan Möbius's avatar
Jan Möbius committed
489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513

      newItem = new QTableWidgetItem( latestVersion );

    } else {

      // No local Information available
      currentBrush.setColor(Qt::yellow);

      newItem = new QTableWidgetItem( "Not Available" );
    }

    newItem->setBackground(currentBrush);
    updateList->setItem( i + 1 , 2, newItem);

    newItem = new QTableWidgetItem( plugins_[i].version );
    newItem->setBackground(currentBrush);
    updateList->setItem( i + 1 , 1, newItem);

    newItem = new QTableWidgetItem( plugins_[i].name );
    newItem->setBackground(currentBrush);
    updateList->setItem( i + 1 , 0, newItem);
  }

  updateList->resizeColumnsToContents();

Jan Möbius's avatar
Jan Möbius committed
514 515
  updateButton->setEnabled(!updatedPlugins_.empty());

516 517
}

Dirk Wilden's avatar
Dirk Wilden committed
518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558
void OptionsWidget::initPluginOptions(){

  pluginList->disconnect();

  connect(pluginList, SIGNAL( currentTextChanged(const QString&) ), this, SLOT( slotShowPluginOptions(const QString&) ) );

  //init list of plugins
  pluginList->clear();

  for ( uint i = 0 ; i < plugins_.size(); ++i )
    if (plugins_[i].optionsWidget != 0){

      pluginList->addItem( plugins_[i].name );
    }

  if ( pluginList->count() > 0)
    pluginList->setCurrentRow(0);
}

void OptionsWidget::slotShowPluginOptions(const QString& _pluginName ){

  //remove old children
  for (int i = 0; i < pluginOptionsLayout->count(); ++i){
    QWidget* w = pluginOptionsLayout->itemAt(i)->widget();

    if (w != 0)
      w->setParent(0);

    pluginOptionsLayout->removeItem( pluginOptionsLayout->itemAt(i) );
  }

  //find the new optionsWidget
  for ( uint i = 0 ; i < plugins_.size(); ++i )
    if (plugins_[i].optionsWidget != 0 && plugins_[i].name == _pluginName){

      pluginOptionsLayout->addWidget( plugins_[i].optionsWidget );
      pluginOptionsLayout->addStretch();
      return;
    }
}

559
void OptionsWidget::slotApply() {
Dirk Wilden's avatar
Dirk Wilden committed
560

Jan Möbius's avatar
Jan Möbius committed
561
  //general
Jan Möbius's avatar
Jan Möbius committed
562
  OpenFlipperSettings().setValue("Core/Gui/fullscreen",fullscreen->isChecked());
563
  OpenFlipperSettings().setValue("Core/Gui/splash",splash->isChecked());
Jan Möbius's avatar
Jan Möbius committed
564 565
  OpenFlipperSettings().setValue("Core/Gui/ToolBoxes/hidden",!toolbox->isChecked());
  
Jan Möbius's avatar
Dennis:  
Jan Möbius committed
566
  if (loggerHidden->isChecked())
Jan Möbius's avatar
Jan Möbius committed
567
    OpenFlipper::Options::loggerState( OpenFlipper::Options::Hidden );
Jan Möbius's avatar
Dennis:  
Jan Möbius committed
568 569 570 571
  else if (loggerInScene->isChecked())
    OpenFlipper::Options::loggerState( OpenFlipper::Options::InScene );
  else
    OpenFlipper::Options::loggerState( OpenFlipper::Options::Normal );
Jan Möbius's avatar
Jan Möbius committed
572 573 574
  
  OpenFlipperSettings().setValue("Core/Log/logFileEnabled",enableLogFile->isChecked());
  OpenFlipperSettings().setValue("Core/Log/logFile",logFile->text());
Dirk Wilden's avatar
Dirk Wilden committed
575

Jan Möbius's avatar
Jan Möbius committed
576 577
  OpenFlipperSettings().setValue("Core/File/MaxRecent",maxRecentBox->value() ) ;

578 579
  
  // Toolbox orientation
Jan Möbius's avatar
Jan Möbius committed
580
  OpenFlipperSettings().setValue("Core/Gui/ToolBoxes/ToolBoxOnTheRight", (toolBoxOrientation->currentIndex() == 0));
581 582
  
  // Render picking toolbar into scene
583
  if ( OpenFlipperSettings().value("Core/Gui/ToolBars/PickToolbarInScene",true).toBool() != pickToolbarInScene->isChecked() )  {
584 585 586
    OpenFlipperSettings().setValue("Core/Gui/ToolBars/PickToolbarInScene", pickToolbarInScene->isChecked());
    restartRequired_ = true;
  }
587

Dirk Wilden's avatar
Dirk Wilden committed
588 589 590 591 592 593 594
  if ( iconDefault->isChecked() )
    OpenFlipperSettings().setValue("Core/Toolbar/iconSize", 0);
  else if ( iconSmall->isChecked() )
    OpenFlipperSettings().setValue("Core/Toolbar/iconSize", 1);
  else if ( iconNormal->isChecked() )
    OpenFlipperSettings().setValue("Core/Toolbar/iconSize", 2);
  
Dirk Wilden's avatar
Dirk Wilden committed
595
  //viewer
Jan Möbius's avatar
Jan Möbius committed
596 597
  OpenFlipperSettings().setValue("Core/Mouse/Wheel/ZoomFactor", wZoomFactor->text().toDouble());
  OpenFlipperSettings().setValue("Core/Mouse/Wheel/ZoomFactorShift", wZoomFactorShift->text().toDouble());
598 599
  OpenFlipperSettings().setValue("Core/Mouse/Wheel/Invert", invertMouseWheelBox->isChecked());

600
  // Projection settings
601 602
  OpenFlipperSettings().setValue("Core/Projection/FOVY", fieldOfView->value());
  OpenFlipperSettings().setValue("Core/Gui/glViewer/minimalSceneSize",minimalSceneSize->value());
Dirk Wilden's avatar
Dirk Wilden committed
603

Jan Möbius's avatar
Jan Möbius committed
604
  OpenFlipperSettings().setValue("Core/Gui/glViewer/showControlWheels", wheelBox->isChecked() );
605

606 607
  OpenFlipperSettings().setValue("Core/Gui/glViewer/restrictFrameRate", restrictFPS->isChecked());
  OpenFlipperSettings().setValue("Core/Gui/glViewer/maxFrameRate", FPS->value() );
608

609
  OpenFlipper::Options::randomDefaultColor( randomDefaultColor->isChecked() );
610

Jan Möbius's avatar
Dennis:  
Jan Möbius committed
611 612 613 614 615
  //stereo
  if (stereoCustomAnaglyph->isChecked ())
     OpenFlipper::Options::stereoMode(OpenFlipper::Options::AnaglyphCustom);
  else if (stereoAnaglyph->isChecked ())
    OpenFlipper::Options::stereoMode(OpenFlipper::Options::AnaglyphRedCyan);
616
  else
Jan Möbius's avatar
Dennis:  
Jan Möbius committed
617 618
    OpenFlipper::Options::stereoMode(OpenFlipper::Options::OpenGL);

619
  OpenFlipperSettings().setValue("Core/Stereo/EyeDistance",eyeDistance->value ());
620
  OpenFlipperSettings().setValue("Core/Stereo/FocalDistance",double(focalDistance->value() / 1000.0));
Jan Möbius's avatar
Dennis:  
Jan Möbius committed
621

Jan Möbius's avatar
Dennis:  
Jan Möbius committed
622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645
  std::vector<float> mat (9, 0);
  mat[0] = lcm0->value ();
  mat[1] = lcm1->value ();
  mat[2] = lcm2->value ();
  mat[3] = lcm3->value ();
  mat[4] = lcm4->value ();
  mat[5] = lcm5->value ();
  mat[6] = lcm6->value ();
  mat[7] = lcm7->value ();
  mat[8] = lcm8->value ();

  OpenFlipper::Options::anaglyphLeftEyeColorMatrix (mat);

  mat[0] = rcm0->value ();
  mat[1] = rcm1->value ();
  mat[2] = rcm2->value ();
  mat[3] = rcm3->value ();
  mat[4] = rcm4->value ();
  mat[5] = rcm5->value ();
  mat[6] = rcm6->value ();
  mat[7] = rcm7->value ();
  mat[8] = rcm8->value ();

  OpenFlipper::Options::anaglyphRightEyeColorMatrix (mat);
646 647
  
  OpenFlipperSettings().setValue("Core/Gui/glViewer/stereoMousePick",!noMousePick->isChecked ());
Jan Möbius's avatar
Jan Möbius committed
648
  OpenFlipperSettings().setValue("Core/Gui/glViewer/nativeMouse",nativeMouse->isChecked ());
649

650
  // updates
651 652 653
  OpenFlipperSettings().setValue("Core/Update/UserName", updateUser->text());
  OpenFlipperSettings().setValue("Core/Update/Pass",updatePass->text());
  OpenFlipperSettings().setValue("Core/Update/URL",updateURL->text());
654

Jan Möbius's avatar
Jan Möbius committed
655 656 657
  // Debugging
  OpenFlipper::Options::doSlotDebugging(slotDebugging->isChecked());

658 659 660
  //viewer defaults
  for (int i=0; i < PluginFunctions::viewers(); i++){
    OpenFlipper::Options::defaultDrawMode(         defaultDrawModes_[i],         i );
661
    OpenFlipper::Options::defaultPerspectiveProjectionMode(   defaultProjectionMode_[i],    i );
662
    OpenFlipper::Options::defaultViewingDirection( defaultViewingDirections_[i], i );
663
    OpenFlipper::Options::defaultLockRotation( defaultRotationLocks_[i], i );
664
  }
Dirk Wilden's avatar
Dirk Wilden committed
665

666
  OpenFlipper::Options::defaultViewerLayout( viewerLayout->currentIndex() );
667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683
  
  // Restrict fps if desired
  if(restrictFPS->isChecked()) {
      OpenFlipperSettings().setValue("Core/Gui/glViewer/restrictFrameRate", true);
      OpenFlipperSettings().setValue("Core/Gui/glViewer/maxFrameRate",FPS->value());
  } else {
      OpenFlipperSettings().setValue("Core/Gui/glViewer/restrictFrameRate", false);
  }
  
  // Set background color
  OpenFlipperSettings().setValue("Core/Gui/glViewer/defaultBackgroundColor", backgroundColor_);
  
  for ( uint i = 0 ; i < OpenFlipper::Options::examinerWidgets(); ++i )
      PluginFunctions::viewerProperties(i).backgroundColor(ACG::Vec4f(((double) backgroundColor_.redF()),
                                                                      ((double) backgroundColor_.greenF()),
                                                                      ((double) backgroundColor_.blueF()),
                                                                        1.0));
684

685 686 687 688 689 690 691 692
  switch ( translation->currentIndex() ){
    case 0 : OpenFlipperSettings().setValue("Core/Language/Translation","en_US");  break;
    case 1 : OpenFlipperSettings().setValue("Core/Language/Translation","de_DE");  break;
    default: OpenFlipperSettings().setValue("Core/Language/Translation","locale"); break;
  }

  // Show warning message that restart is required if language or in scene toolbar has been changed...
  if(restartRequired_) {
693 694 695 696
    int restart = QMessageBox::information(this, tr("Restart required!"),
                      tr("The changes will take effect after next restart. Do you want to close OpenFlipper now?"),
                      QMessageBox::Yes | QMessageBox::No);
                    
697
    if(restart == QMessageBox::Yes) exitOnClose_ = true;
698
  }
699

Dirk Wilden's avatar
Dirk Wilden committed
700 701
  applyShortcuts();

702
  emit applyOptions();
Dirk Wilden's avatar
Dirk Wilden committed
703
  emit saveOptions();
704 705 706 707

  // Make sure all settings are written before we quit!
  OpenFlipperSettings().sync();

708
  // Close OpenFlipper if demanded
709
  if(exitOnClose_)  QCoreApplication::quit();
Dirk Wilden's avatar
Dirk Wilden committed
710
}
711

Dirk Wilden's avatar
Dirk Wilden committed
712 713
void OptionsWidget::slotOk(){
  slotApply();
714 715 716 717 718 719
  hide();
}

void OptionsWidget::slotCancel() {
  hide();
}
Jan Möbius's avatar
Jan Möbius committed
720

Jan Möbius's avatar
Jan Möbius committed
721 722 723 724 725
void OptionsWidget::slotCheckUpdates() {

   // http://www.graphics.rwth-aachen.de/restricted/OpenFlipper-SIL/

  downloadType = VERSIONS_FILE;
726 727 728
  QString ServerMainURL = updateURL->text();
  if ( !ServerMainURL.endsWith("/") )
     ServerMainURL += "/";
Jan Möbius's avatar
Jan Möbius committed
729

730
  ServerMainURL += "Versions.ini";
Jan Möbius's avatar
Jan Möbius committed
731

732
  startDownload(ServerMainURL);
Jan Möbius's avatar
Jan Möbius committed
733 734 735
}

void OptionsWidget::slotGetUpdates() {
Jan Möbius's avatar
Jan Möbius committed
736 737 738 739 740 741 742 743
   std::cerr << "Not implemented yet: Get updates" << std::endl;
   QString url = updateURL->text();

   if ( !url.endsWith("/") )
     url += "/";


   pluginPath_.clear();
Jan Möbius's avatar
Jan Möbius committed
744
   pluginPath_ = "Plugins/";
Jan Möbius's avatar
Jan Möbius committed
745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775

   if ( OpenFlipper::Options::isWindows() ) {
      pluginPath_ += "Windows/";
   } else if ( OpenFlipper::Options::isLinux() ) {
      pluginPath_ += "Linux/";
   } else {
      std::cerr << "Unknown operating system type, aborting update" << std::endl;
      return;
   }

   if ( OpenFlipper::Options::is64bit() ) {
      pluginPath_ += "64/";
   } else if ( OpenFlipper::Options::is32bit() ) {
      pluginPath_ += "32/";
   } else {
      std::cerr << "Unknown architecture type, aborting update" << std::endl;
      return;
   }

   pluginPath_ += "Release/";

   if ( !updatedPlugins_.empty() && updatedPlugins_[0] == "Core" ) {
      std::cerr << "Core update not supported!" << std::endl;
      return;
   }

   if ( !updatedPlugins_.empty() ) {
      currentUpdateName_ = updatedPlugins_[0];
      std::cerr << "Downloading " << (url + pluginPath_ + currentUpdateName_).toStdString() << std::endl;
      updatedPlugins_.pop_front();

Jan Möbius's avatar
Jan Möbius committed
776
      downloadType = PLUGIN;
Jan Möbius's avatar
Jan Möbius committed
777 778 779 780 781 782 783 784 785 786

      startDownload(url + pluginPath_ + currentUpdateName_);
   }

}

void OptionsWidget::updateComponent() {
   std::cerr << "Todo : Update component" << std::endl;


Jan Möbius's avatar
Jan Möbius committed
787 788 789 790 791 792 793 794 795 796 797 798 799

   QString sourceName = QDir::home().absolutePath() + OpenFlipper::Options::dirSeparator() +
                                     ".OpenFlipper" + OpenFlipper::Options::dirSeparator() + currentUpdateName_ ;

   QString targetName = OpenFlipper::Options::applicationDirStr() + "/" + pluginPath_ + currentUpdateName_;

   QFileInfo sourceFileInfo(sourceName);
   QFileInfo targetFileInfo(targetName);

   std::cerr << sourceName.toStdString() << std::endl;
   std::cerr << targetName.toStdString() << std::endl;

   if ( ! sourceFileInfo.exists() ) {
800
      statusLabel->setText(tr("Download failed!"));
Jan Möbius's avatar
Jan Möbius committed
801
      slotGetUpdates();
Jan Möbius's avatar
Jan Möbius committed
802
      return;
Jan Möbius's avatar
Jan Möbius committed
803
   } else {
Jan Möbius's avatar
Jan Möbius committed
804
      if ( ! targetFileInfo.exists() ) {
805
         statusLabel->setText(tr("plugin target does not exist"));
Jan Möbius's avatar
Jan Möbius committed
806
         slotGetUpdates();
Jan Möbius's avatar
Jan Möbius committed
807 808 809
         return;
      }

810
      statusLabel->setText(tr("Installing new file"));
Jan Möbius's avatar
Jan Möbius committed
811

Jan Möbius's avatar
Jan Möbius committed
812
      // Remove the old plugin
Jan Möbius's avatar
Jan Möbius committed
813 814
      QFile targetFile(targetName);
      targetFile.remove();
Jan Möbius's avatar
Jan Möbius committed
815

Jan Möbius's avatar
Jan Möbius committed
816
      // copy new to old
Jan Möbius's avatar
Jan Möbius committed
817 818
      QFile::copy(sourceName,targetName);

Jan Möbius's avatar
Jan Möbius committed
819 820 821 822
      // remove downloaded file
      QFile sourceFile(sourceName);
      sourceFile.remove();

823
      statusLabel->setText(tr("updated ") + currentUpdateName_);
Jan Möbius's avatar
Jan Möbius committed
824
   }
Jan Möbius's avatar
Jan Möbius committed
825 826

   slotGetUpdates();
Jan Möbius's avatar
Jan Möbius committed
827 828
}

829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871
bool OptionsWidget::isNewer(QString _current, QString _latest) {

  QStringList latestVersionParts  = _latest.split('.');
  QStringList currentVersionParts = _current.split('.');

  bool newer = false;

  for ( int i = 0 ; i < latestVersionParts.size(); ++i ) {

    if ( i+1 > currentVersionParts.size() ) {
      // Versions are identical up to now. But latest version has additional version => updated
      newer = true;
      break;
    }

    bool ok = false;
    double latest  = latestVersionParts[i].toInt(&ok);
    double current = currentVersionParts[i].toInt(&ok);

    if ( !ok )
      std::cerr << "Error when parsing version strings!" << std::endl;

    if ( latest > current ) {
      newer = true;
      break;
    }
  }

  return newer;

}

void OptionsWidget::compareVersions() {

  QString fileName = QDir::home().absolutePath() + OpenFlipper::Options::dirSeparator() +
                     ".OpenFlipper" + OpenFlipper::Options::dirSeparator() + "Versions.ini" ;

  INIFile ini;
  if ( ! ini.connect(fileName,false) ) {
    std::cerr << "Failed to connect to Versions ini file" << std::endl;
    return;
  }

872
  statusLabel->setText(tr("Checking for new versions"));
873 874 875

  bool newerVersionsAvailable = false;

876
  QString systemString = "";
877
  if ( OpenFlipper::Options::isWindows() ) {
878 879 880 881 882 883 884 885 886 887 888 889 890
    systemString = "VersionWindows";
  } else if (OpenFlipper::Options::isLinux()) {
    systemString = "VersionLinux";
  } else {
    std::cerr << "Unsupported platform for update" << std::endl;
    return;
  }

  QString coreVersion;

  if ( ini.get_entry(coreVersion, "Core" , systemString )) {
    if ( isNewer( OpenFlipper::Options::coreVersion(), coreVersion ) ) {
      newerVersionsAvailable = true;
Jan Möbius's avatar
Jan Möbius committed
891
    }
892 893 894 895 896
  }

  for ( uint i = 0 ; i < plugins_.size(); ++i ) {
    QString latestVersion;
    if ( ini.get_entry(latestVersion, plugins_[i].name , systemString )) {
Jan Möbius's avatar
Jan Möbius committed
897
      if ( isNewer(  plugins_[i].version, latestVersion ) )
898
        newerVersionsAvailable = true;
899
    }
900 901 902
  }

  if ( newerVersionsAvailable ) {
903
    statusLabel->setText(tr("Updates found"));
904
  } else {
905
    statusLabel->setText(tr("No updates found"));
906 907 908
  }

  ini.disconnect();
Jan Möbius's avatar
Jan Möbius committed
909 910

  updateVersionsTable();
911
}
912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927

void OptionsWidget::slotPreviewStereoSettings(int /*_tmpParam*/) {
    
  if (stereoCustomAnaglyph->isChecked ())
     OpenFlipper::Options::stereoMode(OpenFlipper::Options::AnaglyphCustom);
  else if (stereoAnaglyph->isChecked ())
    OpenFlipper::Options::stereoMode(OpenFlipper::Options::AnaglyphRedCyan);
  else
    OpenFlipper::Options::stereoMode(OpenFlipper::Options::OpenGL);

  OpenFlipperSettings().setValue("Core/Stereo/EyeDistance", eyeDistance->value());
  OpenFlipperSettings().setValue("Core/Stereo/FocalDistance", double(focalDistance->value() / 1000.0));

  
  // Update all views
 emit applyOptions();
928 929 930 931 932 933 934 935 936
}

void OptionsWidget::slotClearSettings() {
    
    OpenFlipperSettings().clear();
}

void OptionsWidget::slotClearINI() {
    
937 938
    QMessageBox::information(this, tr("Restart required!"),
                             tr("The changes will take effect after next restart."));
939
    
940
    OpenFlipper::Options::deleteIniFile(true);
941
}