Developer Documentation
optionsWidget.cc
1/*===========================================================================*\
2* *
3* OpenFlipper *
4 * Copyright (c) 2001-2015, RWTH-Aachen University *
5 * Department of Computer Graphics and Multimedia *
6 * All rights reserved. *
7 * www.openflipper.org *
8 * *
9 *---------------------------------------------------------------------------*
10 * This file is part of OpenFlipper. *
11 *---------------------------------------------------------------------------*
12 * *
13 * Redistribution and use in source and binary forms, with or without *
14 * modification, are permitted provided that the following conditions *
15 * are met: *
16 * *
17 * 1. Redistributions of source code must retain the above copyright notice, *
18 * this list of conditions and the following disclaimer. *
19 * *
20 * 2. Redistributions in binary form must reproduce the above copyright *
21 * notice, this list of conditions and the following disclaimer in the *
22 * documentation and/or other materials provided with the distribution. *
23 * *
24 * 3. Neither the name of the copyright holder nor the names of its *
25 * contributors may be used to endorse or promote products derived from *
26 * this software without specific prior written permission. *
27 * *
28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
29 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
30 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
31 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
32 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
33 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
34 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
35 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
36 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
37 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
38 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
39* *
40\*===========================================================================*/
41
42#ifdef _MSC_VER
43 #if (_MSC_VER <= 1916)
44 #define QT_NO_FLOAT16_OPERATORS
45 #endif
46#endif
47
48#include <OpenFlipper/ACGHelper/DrawModeConverter.hh>
49#include <OpenFlipper/INIFile/INIFile.hh>
52#include <ACG/GL/ShaderCache.hh>
53
54#include "optionsWidget.hh"
55#include <QColorDialog>
56#include <QOpenGLContext>
57#include <QMessageBox>
58
59OptionsWidget::OptionsWidget(std::vector<PluginInfo>& _plugins, std::vector<KeyBinding>& _core, InverseKeyMap& _invKeys, QWidget *parent)
60 : QWidget(parent),
61 plugins_(_plugins),
62 coreKeys_(_core),
63 keys_(_invKeys),
64 progressDialog_(NULL),
65 restartRequired_(false),
66 exitOnClose_(false)
67{
68 setupUi(this);
69
70 connect(okButton,SIGNAL(clicked()),this,SLOT(slotOk()));
71 connect(applyButton,SIGNAL(clicked()),this,SLOT(slotApply()));
72 connect(cancelButton,SIGNAL(clicked()),this,SLOT(slotCancel()));
73 connect(checkUpdateButton,SIGNAL(clicked()),this,SLOT(slotCheckUpdates()));
74 connect(updateButton,SIGNAL(clicked()),this,SLOT(slotGetUpdates()));
75 updateButton->setEnabled(false);
76
77 // Files
78 connect(pbReloadShaders,SIGNAL(clicked()),this,SLOT(slotReloadShaders()));
79
80 // OpenGL versions
81 VersionComboBox->clear();
82 VersionComboBox->addItem("4.6",QVariant::fromValue(QPair<int, int>(4,6)));
83 VersionComboBox->addItem("4.5",QVariant::fromValue(QPair<int, int>(4,5)));
84 VersionComboBox->addItem("4.4",QVariant::fromValue(QPair<int, int>(4,4)));
85 VersionComboBox->addItem("4.3",QVariant::fromValue(QPair<int, int>(4,3)));
86 VersionComboBox->addItem("4.2",QVariant::fromValue(QPair<int, int>(4,2)));
87 VersionComboBox->addItem("4.1",QVariant::fromValue(QPair<int, int>(4,1)));
88 VersionComboBox->addItem("4.0",QVariant::fromValue(QPair<int, int>(4,0)));
89 VersionComboBox->addItem("3.3",QVariant::fromValue(QPair<int, int>(3,3)));
90 VersionComboBox->addItem("3.2",QVariant::fromValue(QPair<int, int>(3,2)));
91 VersionComboBox->addItem("3.1",QVariant::fromValue(QPair<int, int>(3,1)));
92 VersionComboBox->addItem("3.0",QVariant::fromValue(QPair<int, int>(3,0)));
93 VersionComboBox->addItem("2.1",QVariant::fromValue(QPair<int, int>(2,1)));
94 VersionComboBox->addItem("2.0",QVariant::fromValue(QPair<int, int>(2,0)));
95 VersionComboBox->addItem("1.5",QVariant::fromValue(QPair<int, int>(1,5)));
96 VersionComboBox->addItem("1.4",QVariant::fromValue(QPair<int, int>(1,4)));
97 VersionComboBox->addItem("1.3",QVariant::fromValue(QPair<int, int>(1,3)));
98 VersionComboBox->addItem("1.2",QVariant::fromValue(QPair<int, int>(1,2)));
99 VersionComboBox->addItem("1.1",QVariant::fromValue(QPair<int, int>(1,1)));
100 VersionComboBox->addItem("1.0",QVariant::fromValue(QPair<int, int>(1,0)));
101
102 // Viewer Settings
103 connect( restrictFPS, SIGNAL(toggled(bool)), FPS, SLOT(setEnabled(bool)) );
104 connect( viewerList, SIGNAL(currentRowChanged(int)), this, SLOT(updateViewerSettings(int)) );
105 connect( availDrawModes, SIGNAL(itemChanged(QListWidgetItem*)), this, SLOT(viewerSettingsChanged(QListWidgetItem*)) );
106 connect( projectionBox, SIGNAL(currentIndexChanged(int)), this, SLOT(viewerSettingsChanged(int)));
107 connect( directionBox, SIGNAL(currentIndexChanged(int)), this, SLOT(viewerSettingsChanged(int)));
108 connect( lockRotationBox, SIGNAL(stateChanged(int)), this, SLOT(viewerSettingsChanged(int)));
109
110 // Switch stacked widget of stereo settings
111 connect(stereoOpengl, SIGNAL(clicked()),
112 this, SLOT(switchStackedWidget()));
113 connect(stereoAnaglyph, SIGNAL(clicked()),
114 this, SLOT(switchStackedWidget()));
115 connect(stereoCustomAnaglyph, SIGNAL(clicked()),
116 this, SLOT(switchStackedWidget()));
117
118 connect(focalDistance, SIGNAL(sliderReleased()),
119 this, SLOT(slotPreviewStereoSettings()));
120 connect(eyeDistance, SIGNAL(editingFinished()),
121 this, SLOT(slotPreviewStereoSettings()));
122
123 ACG::SceneGraph::DrawModes::ModeFlagSet mode(2);
124 for (uint i=1; i < 22; i++) {
125 std::vector< QString > dm = drawModeToDescriptions( ACG::SceneGraph::DrawModes::DrawMode(mode) );
126
127 if ( !dm.empty() && dm[0].trimmed() != ""){
128 QListWidgetItem* item = new QListWidgetItem(dm[0]);
129
130 item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsUserCheckable | Qt::ItemIsSelectable);
131
132 item->setCheckState(Qt::Unchecked);
133
134 availDrawModes->addItem( item );
135 }
136
137 mode = mode<<1;
138 }
139
140 defaultProjectionMode_.resize(4);
141 defaultViewingDirections_.resize(4);
142 defaultRotationLocks_.resize(4);
143
144 for ( int i=0; i < PluginFunctions::viewers(); i++ ){
145 viewerList->addItem("Viewer " + QString::number(i+1) );
146 defaultDrawModes_.push_back( ACG::SceneGraph::DrawModes::DEFAULT );
147 }
148
149 pluginOptionsLayout = new QVBoxLayout;
150 pluginOptions->setLayout( pluginOptionsLayout );
151
152 networkMan_ = new QNetworkAccessManager(this);
153
154 // http specific connections
155 connect(networkMan_, SIGNAL(finished(QNetworkReply *)),
156 this, SLOT(httpRequestFinished(QNetworkReply *)));
157 connect(networkMan_,SIGNAL(authenticationRequired(QNetworkReply* , QAuthenticator *)),
158 this,SLOT(authentication(QNetworkReply *, QAuthenticator*)));
159
160 //colordialog
161 connect(backgroundButton, SIGNAL(clicked()), this, SLOT(getBackgroundColor()) );
162 connect(defaultColorButton, SIGNAL(clicked()), this, SLOT(getDefaultColor()) );
163
164 // Clear settings and ini buttons
165 connect(clearSettingsButton, SIGNAL(clicked()), this, SLOT(slotClearSettings()));
166 connect(clearINIButton, SIGNAL(clicked()), this, SLOT(slotClearINI()));
167
168 // Disable update tab if app store compliant build
169 #ifdef OPENFLIPPER_BUILD_APP_STORE_COMPLIANT
170 //tabWidget->setTabEnabled(tabWidget->count()-1,false);
171 tabWidget->removeTab(tabWidget->count()-1);
172 #endif
173}
174
176 QColor newColor = QColorDialog::getColor ( OpenFlipperSettings().value("Core/Gui/glViewer/defaultBackgroundColor").value<QColor>() );
177
178 backgroundColor_ = newColor;
179
180 QPixmap color(16,16);
181 color.fill( newColor );
182 backgroundButton->setIcon( QIcon(color) );
183}
184
185void OptionsWidget::getDefaultColor(){
186 QColor newColor = QColorDialog::getColor ( OpenFlipper::Options::defaultColor() );
187
188 OpenFlipper::Options::defaultColor( newColor) ;
189
190 QPixmap color(16,16);
191 color.fill( OpenFlipper::Options::defaultColor() );
192 defaultColorButton->setIcon( QIcon(color) );
193}
194
195void OptionsWidget::viewerSettingsChanged(QListWidgetItem* /*_item*/){
197};
198
199void OptionsWidget::viewerSettingsChanged(int /*_index*/){
200
201 if ( !updatingViewerSettings_ ){
202 //viewer defaults
203 std::vector< QString > mode;
204
205 for (int i=0; i < availDrawModes->count(); i++)
206 if (availDrawModes->item(i)->checkState() == Qt::Checked)
207 mode.push_back( availDrawModes->item(i)->text() );
208
209 defaultDrawModes_[ viewerList->currentRow() ] = descriptionsToDrawMode(mode);
210 defaultProjectionMode_[ viewerList->currentRow() ] = projectionBox->currentIndex() ;
211 defaultViewingDirections_[ viewerList->currentRow() ] = directionBox->currentIndex();
212 defaultRotationLocks_[ viewerList->currentRow() ] = lockRotationBox->isChecked();
213
214 if ( lockRotationBox->isChecked() )
215 std::cerr << "locked" << std::endl;
216 else
217 std::cerr << "unlocked" << std::endl;
218 }
219};
220
222
223 // Show right stacked widget of stereo settings
224 if (stereoCustomAnaglyph->isChecked()) {
225 stackedWidget->setCurrentIndex(0);
226 customAnaGlyphSettings->setVisible(true);
227 } else {
228 stackedWidget->setCurrentIndex(0);
229 customAnaGlyphSettings->setVisible(false);
230 }
231
232 // Preview new settings
234}
235
236void OptionsWidget::slotTranslationIndexChanged(int /*_index*/) {
237 restartRequired_ = true;
238}
239
241
242 updatingViewerSettings_ = true;
243
244 for (int i = 0 ; i < availDrawModes->count(); ++i )
245 availDrawModes->item( i )->setCheckState(Qt::Unchecked) ;
246
247 //Check the drawModes from StandardDrawMode
248 std::vector< QString > dm = drawModeToDescriptions( defaultDrawModes_[_row] );
249
250 for (uint i=0; i < dm.size(); i++){
251 if ( !dm.empty() ) {
252 QList< QListWidgetItem* > found = availDrawModes->findItems(dm[i],Qt::MatchExactly);
253 for(int k=0; k < found.count(); k++)
254 (found[k])->setCheckState(Qt::Checked);
255 }
256 }
257
258 if ( defaultProjectionMode_[_row] )
259 projectionBox->setCurrentIndex( 1 );
260 else
261 projectionBox->setCurrentIndex( 0 );
262
263 directionBox->setCurrentIndex( defaultViewingDirections_[_row] );
264
265 lockRotationBox->setChecked( defaultRotationLocks_[_row] );
266
267 updatingViewerSettings_ = false;
268}
269
270void OptionsWidget::showEvent ( QShowEvent * /*event*/ ) {
271
272 //general
273 fullscreen->setChecked( OpenFlipperSettings().value("Core/Gui/fullscreen",false).toBool() );
274 splash->setChecked( OpenFlipperSettings().value("Core/Gui/splash",true).toBool() );
275 toolbox->setChecked( !OpenFlipperSettings().value("Core/Gui/ToolBoxes/hidden",false).toBool() );
276
277 iconSmall->setChecked(false);
278 iconNormal->setChecked(false);
279 iconDefault->setChecked(false);
280
281 switch ( OpenFlipperSettings().value("Core/Toolbar/iconSize",0).toInt() ){
282 case 1 : iconSmall->setChecked(true); break;
283 case 2 : iconNormal->setChecked(true); break;
284 default : iconDefault->setChecked(true); break;
285 }
286
287 loggerHidden->setChecked( OpenFlipper::Options::loggerState() == OpenFlipper::Options::Hidden);
288 loggerNormal->setChecked( OpenFlipper::Options::loggerState() == OpenFlipper::Options::Normal);
289 loggerInScene->setChecked( OpenFlipper::Options::loggerState() == OpenFlipper::Options::InScene);
290 enableLogFile->setChecked( OpenFlipperSettings().value("Core/Log/logFileEnabled",true).toBool() );
291
292 //OpenGL
293 samples_spinBox->setValue(OpenFlipper::Options::samples());
294 QPalette warning = samplesWarning->palette();
295 samplesWarning->setText(QString::number(QOpenGLContext::currentContext()->format().samples()));
296 if(OpenFlipper::Options::samples() != QOpenGLContext::currentContext()->format().samples())
297 warning.setColor(samplesWarning->foregroundRole(),Qt::red);
298 else
299 warning.setColor(samplesWarning->foregroundRole(),Qt::black);
300 samplesWarning->setPalette(warning);
301
302 stereoCheckBox->setChecked(OpenFlipper::Options::glStereoRequested());
303 QPalette stereoWarn = stereoWarning->palette();
304 QString stereoValue;
305 QOpenGLContext::currentContext()->format().stereo() ? stereoValue = "true" : stereoValue = "false";
306 stereoWarning->setText(stereoValue);
307 QOpenGLContext::currentContext()->format().stereo() == OpenFlipper::Options::glStereoRequested() ?
308 stereoWarn.setColor(stereoWarning->foregroundRole(), Qt::black) :
309 stereoWarn.setColor(stereoWarning->foregroundRole(), Qt::red);
310 stereoWarning->setPalette(stereoWarn);
311
312 VersionComboBox->setCurrentIndex( VersionComboBox->findData(QVariant::fromValue(OpenFlipper::Options::glVersion())));
313 QPalette version = versionWarning->palette();
314 versionWarning->setText(QString("%1.%2").arg(QOpenGLContext::currentContext()->format().version().first)
315 .arg(QOpenGLContext::currentContext()->format().version().second));
316 if(OpenFlipper::Options::glVersion() != QOpenGLContext::currentContext()->format().version())
317 version.setColor(versionWarning->foregroundRole(),Qt::red);
318 else
319 version.setColor(versionWarning->foregroundRole(),Qt::black);
320 versionWarning->setPalette(version);
321
322 QPalette profile = profileWarning->palette();
323 profileComboBox->setCurrentIndex(OpenFlipper::Options::coreProfile()?0:1);
324 if(QOpenGLContext::currentContext()->format().profile() == QSurfaceFormat::CoreProfile)
325 profileWarning->setText("Core");
326 if(QOpenGLContext::currentContext()->format().profile() == QSurfaceFormat::CompatibilityProfile)
327 profileWarning->setText("Compatibility");
328 if(QOpenGLContext::currentContext()->format().profile() == QSurfaceFormat::NoProfile)
329 profileWarning->setText("None");
330 if(OpenFlipper::Options::coreProfile() && QOpenGLContext::currentContext()->format().profile() != QSurfaceFormat::CoreProfile)
331 profile.setColor(profileWarning->foregroundRole(),Qt::red);
332 else
333 profile.setColor(profileWarning->foregroundRole(),Qt::black);
334 profileWarning->setPalette(profile);
335
336 //Files
337 logFile->setText( OpenFlipperSettings().value("Core/Log/logFile").toString() );
338 maxRecentBox->setValue( OpenFlipperSettings().value("Core/File/MaxRecent",15).toInt() );
339 rbReloadShaders->setChecked(OpenFlipperSettings().value("Core/File/ReloadShaders",false).toBool()) ;
340 leShaderOutputDir->setText(OpenFlipperSettings().value("Core/File/ShaderOutputDir","").toString());
341 allTarget->setChecked( OpenFlipperSettings().value("Core/File/AllTarget",false).toBool() );
342
343
344 // UI settings
345 toolBoxOrientation->setCurrentIndex((OpenFlipperSettings().value("Core/Gui/ToolBoxes/ToolBoxOnTheRight",true).toBool() ? 0 : 1));
346
347 pickToolbarInScene->setChecked(OpenFlipperSettings().value("Core/Gui/ToolBars/PickToolbarInScene",true).toBool());
348
349 //stereo
350
351 // Grey out OpenGL stereo mode option if not available
352 if(!OpenFlipper::Options::glStereo()) {
353 stereoOpengl->setDisabled(true);
354 } else {
355 stereoOpengl->setChecked(OpenFlipper::Options::stereoMode() == OpenFlipper::Options::OpenGL);
356 }
357
358 stereoAnaglyph->setChecked (OpenFlipper::Options::stereoMode() == OpenFlipper::Options::AnaglyphRedCyan);
359 stereoCustomAnaglyph->setChecked (OpenFlipper::Options::stereoMode() == OpenFlipper::Options::AnaglyphCustom);
360
361 eyeDistance->setValue ( OpenFlipperSettings().value("Core/Stereo/EyeDistance").toDouble() );
362 focalDistance->setValue ( OpenFlipperSettings().value("Core/Stereo/FocalDistance").toDouble() * 1000);
363
364 // Show right stacked widget
365 customAnaGlyphSettings->setVisible(false);
366
367 stackedWidget->setCurrentIndex(0);
368
369 if (stereoCustomAnaglyph->isChecked())
370 customAnaGlyphSettings->setVisible(true);
371
372 std::vector<float> mat = OpenFlipper::Options::anaglyphLeftEyeColorMatrix ();
373 lcm0->setValue (mat[0]);
374 lcm1->setValue (mat[1]);
375 lcm2->setValue (mat[2]);
376 lcm3->setValue (mat[3]);
377 lcm4->setValue (mat[4]);
378 lcm5->setValue (mat[5]);
379 lcm6->setValue (mat[6]);
380 lcm7->setValue (mat[7]);
381 lcm8->setValue (mat[8]);
382
383 mat = OpenFlipper::Options::anaglyphRightEyeColorMatrix ();
384 rcm0->setValue (mat[0]);
385 rcm1->setValue (mat[1]);
386 rcm2->setValue (mat[2]);
387 rcm3->setValue (mat[3]);
388 rcm4->setValue (mat[4]);
389 rcm5->setValue (mat[5]);
390 rcm6->setValue (mat[6]);
391 rcm7->setValue (mat[7]);
392 rcm8->setValue (mat[8]);
393
394 noMousePick->setChecked ( !OpenFlipperSettings().value("Core/Gui/glViewer/stereoMousePick",true).toBool() );
395 nativeMouse->setChecked ( OpenFlipperSettings().value("Core/Gui/glViewer/nativeMouse",false).toBool() );
396
397 // plugin options
398 initPluginOptions();
399
400 // updates
401 updateUser->setText( OpenFlipperSettings().value("Core/Update/UserName","anonymous").toString() );
402 updatePass->setText( OpenFlipperSettings().value("Core/Update/Pass","anonymous").toString() );
403 updateURL->setText( OpenFlipperSettings().value("Core/Update/URL","http://").toString() );
404
405 // debugging
406 slotDebugging->setChecked(OpenFlipper::Options::doSlotDebugging());
407
408 //keyBindings
409 initKeyTree();
410
411 keyTree->disconnect(); //to be sure..disconnect every slot
412
413 connect(keyTree, SIGNAL(currentItemChanged(QTreeWidgetItem*, QTreeWidgetItem*)),
414 this, SLOT(keyTreeItemChanged( QTreeWidgetItem*, QTreeWidgetItem*)) );
415
416 connect(keyTree, SIGNAL(itemDoubleClicked (QTreeWidgetItem*, int)),
417 this, SLOT(keyTreeDoubleClicked( QTreeWidgetItem*, int)) );
418
419
420 connect(shortcutButton, SIGNAL(keyChanged()), this, SLOT(updateShortcut()) );
421 connect(presetsButton, SIGNAL(clicked()), this, SLOT(restoreKeyPresets()) );
422
423
424 //Init Viewer Settings
425 wZoomFactor->setValue( OpenFlipperSettings().value("Core/Mouse/Wheel/ZoomFactor").toDouble() );
426 wZoomFactorShift->setValue( OpenFlipperSettings().value("Core/Mouse/Wheel/ZoomFactorShift").toDouble() );
427 invertMouseWheelBox->setChecked( OpenFlipperSettings().value("Core/Mouse/Wheel/Invert").toBool() );
428
429 wheelBox->setChecked( OpenFlipperSettings().value("Core/Gui/glViewer/showControlWheels").toBool() );
430
431 // Projection settings
432 fieldOfView->setValue(OpenFlipperSettings().value("Core/Projection/FOVY", 45.0).toDouble() );
433
434 restrictFPS->setChecked( OpenFlipperSettings().value("Core/Gui/glViewer/restrictFrameRate",false).toBool() );
435 FPS->setValue( OpenFlipperSettings().value("Core/Gui/glViewer/maxFrameRate",35).toInt() );
436
437 minimalSceneSize->setValue( OpenFlipperSettings().value("Core/Gui/glViewer/minimalSceneSize",0.1).toDouble());
438
439 QPixmap color(16,16);
440 color.fill( OpenFlipperSettings().value("Core/Gui/glViewer/defaultBackgroundColor").value<QColor>() );
441 backgroundColor_ = OpenFlipperSettings().value("Core/Gui/glViewer/defaultBackgroundColor").value<QColor>();
442 backgroundButton->setIcon( QIcon(color) );
443
444 color.fill( OpenFlipper::Options::defaultColor() );
445 defaultColorButton->setIcon( QIcon(color) );
446
447 randomDefaultColor->setChecked( OpenFlipper::Options::randomDefaultColor() );
448
449 viewerList->setCurrentRow(0);
450
451 for ( int i=0; i < PluginFunctions::viewers(); i++ ){
452 defaultDrawModes_[i] = OpenFlipper::Options::defaultDrawMode(i);
453 defaultProjectionMode_[i] = OpenFlipper::Options::defaultPerspectiveProjectionMode(i);
454 defaultViewingDirections_[i] = OpenFlipper::Options::defaultViewingDirection(i);
455 defaultRotationLocks_[i] = OpenFlipper::Options::defaultLockRotation(i);
456 }
457
459
460 viewerLayout->setCurrentIndex( OpenFlipper::Options::defaultViewerLayout() );
461
462 if (OpenFlipperSettings().value("Core/Language/Translation","en_US").toString() == "en_US")
463 translation->setCurrentIndex(0);
464 else if (OpenFlipperSettings().value("Core/Language/Translation","en_US").toString() == "de_DE")
465 translation->setCurrentIndex(1);
466 else
467 translation->setCurrentIndex(2);
468
469 // Listen to changes...
470 connect(translation, SIGNAL(currentIndexChanged(int)), this, SLOT(slotTranslationIndexChanged(int)));
471
473
474}
475
477
478 updatedPlugins_.clear();
479
480 QString fileName = QDir::home().absolutePath() + OpenFlipper::Options::dirSeparator() +
481 ".OpenFlipper" + OpenFlipper::Options::dirSeparator() + "Versions.ini" ;
482
483 INIFile ini;
484
485 ini.connect(fileName,false);
486
487 QString systemString = "";
488
489 if ( OpenFlipper::Options::isWindows() ) {
490 systemString = "VersionWindows";
491 } else if (OpenFlipper::Options::isLinux()) {
492 systemString = "VersionLinux";
493 } else {
494 std::cerr << "Unsupported platform for update" << std::endl;
495 return;
496 }
497
498 updateList->clear();
499 updateList->setRowCount( int(1 + plugins_.size()) );
500 updateList->setColumnCount(3);
501
502 QStringList header;
503
504 header << "Component" << "current Version" << "latest Version" ;
505 updateList->setHorizontalHeaderLabels(header);
506
507 QBrush currentBrush(Qt::white);
508
509 QTableWidgetItem * newItem = 0;
510
511 QString coreVersion;
512
513 if ( ini.is_connected() && ini.get_entry(coreVersion, "Core" , systemString ) ) {
514
515 // Newer Version available
516 if ( isNewer(OpenFlipper::Options::coreVersion(),coreVersion) ) {
517 currentBrush.setColor(Qt::red);
518 updatedPlugins_ << "Core";
519 } else if ( isNewer(coreVersion , OpenFlipper::Options::coreVersion()) )
520 currentBrush.setColor(Qt::blue);
521 else
522 currentBrush.setColor(Qt::green);
523
524 newItem = new QTableWidgetItem( coreVersion );
525
526 } else {
527
528 // No local Information available
529 currentBrush.setColor(Qt::yellow);
530
531 newItem = new QTableWidgetItem( "Not Available" );
532 }
533
534 newItem->setBackground(currentBrush);
535 updateList->setItem(0, 2, newItem);
536
537 newItem = new QTableWidgetItem( OpenFlipper::Options::coreVersion() );
538 newItem->setBackground(currentBrush);
539 updateList->setItem(0, 1, newItem);
540
541 newItem = new QTableWidgetItem( "Core" );
542 newItem->setBackground(currentBrush);
543 updateList->setItem(0, 0, newItem);
544
545
546 for ( uint i = 0 ; i < plugins_.size(); ++i ) {
547 QString latestVersion;
548
549 if ( ini.is_connected() && ini.get_entry(latestVersion, plugins_[i].name , systemString ) ) {
550
551
552 // Newer Version available
553 if ( isNewer(plugins_[i].version,latestVersion) ) {
554 currentBrush.setColor(Qt::red);
555 QFileInfo pluginFile(plugins_[i].path );
556 updatedPlugins_ << pluginFile.fileName();
557 } else if ( isNewer(latestVersion,plugins_[i].version) )
558 currentBrush.setColor(Qt::blue);
559 else
560 currentBrush.setColor(Qt::green);
561
562 newItem = new QTableWidgetItem( latestVersion );
563
564 } else {
565
566 // No local Information available
567 currentBrush.setColor(Qt::yellow);
568
569 newItem = new QTableWidgetItem( "Not Available" );
570 }
571
572 newItem->setBackground(currentBrush);
573 updateList->setItem( i + 1 , 2, newItem);
574
575 newItem = new QTableWidgetItem( plugins_[i].version );
576 newItem->setBackground(currentBrush);
577 updateList->setItem( i + 1 , 1, newItem);
578
579 newItem = new QTableWidgetItem( plugins_[i].name );
580 newItem->setBackground(currentBrush);
581 updateList->setItem( i + 1 , 0, newItem);
582 }
583
584 updateList->resizeColumnsToContents();
585
586 updateButton->setEnabled(!updatedPlugins_.empty());
587
588}
589
590void OptionsWidget::initPluginOptions(){
591
592 pluginList->disconnect();
593
594 connect(pluginList, SIGNAL( currentTextChanged(const QString&) ), this, SLOT( slotShowPluginOptions(const QString&) ) );
595
596 //init list of plugins
597 pluginList->clear();
598
599 for ( uint i = 0 ; i < plugins_.size(); ++i )
600 if (plugins_[i].optionsWidget != 0){
601
602 pluginList->addItem( plugins_[i].name );
603 }
604
605 if ( pluginList->count() > 0)
606 pluginList->setCurrentRow(0);
607}
608
609void OptionsWidget::slotShowPluginOptions(const QString& _pluginName ){
610
611 //remove old children
612 for (int i = 0; i < pluginOptionsLayout->count(); ++i){
613 QWidget* w = pluginOptionsLayout->itemAt(i)->widget();
614
615 if (w != 0)
616 w->setParent(0);
617
618 pluginOptionsLayout->removeItem( pluginOptionsLayout->itemAt(i) );
619 }
620
621 //find the new optionsWidget
622 for ( uint i = 0 ; i < plugins_.size(); ++i )
623 if (plugins_[i].optionsWidget != 0 && plugins_[i].name == _pluginName){
624
625 pluginOptionsLayout->addWidget( plugins_[i].optionsWidget );
626 pluginOptionsLayout->addStretch();
627 return;
628 }
629}
630
632
633 //general
634 OpenFlipperSettings().setValue("Core/Gui/fullscreen",fullscreen->isChecked());
635 OpenFlipperSettings().setValue("Core/Gui/splash",splash->isChecked());
636 OpenFlipperSettings().setValue("Core/Gui/ToolBoxes/hidden",!toolbox->isChecked());
637
638 if (loggerHidden->isChecked())
639 OpenFlipper::Options::loggerState( OpenFlipper::Options::Hidden );
640 else if (loggerInScene->isChecked())
641 OpenFlipper::Options::loggerState( OpenFlipper::Options::InScene );
642 else
643 OpenFlipper::Options::loggerState( OpenFlipper::Options::Normal );
644
645 OpenFlipperSettings().setValue("Core/Log/logFileEnabled",enableLogFile->isChecked());
646 OpenFlipperSettings().setValue("Core/Log/logFile",logFile->text());
647
648 //OpenGL settings
649 OpenFlipperSettings().setValue("Core/OpenGL/Samples",samples_spinBox->value());
650 OpenFlipper::Options::glVersion(VersionComboBox->currentData().value<QPair<int,int>>());
651 OpenFlipper::Options::coreProfile(profileComboBox->currentIndex() == 0);
652 OpenFlipper::Options::glStereo(stereoCheckBox->isChecked());
653
654 //Paths settings
655 OpenFlipperSettings().setValue("Core/File/MaxRecent",maxRecentBox->value() ) ;
656 OpenFlipperSettings().setValue("Core/File/ReloadShaders",rbReloadShaders->isChecked() ) ;
657 ACG::ShaderCache::getInstance()->setTimeCheck(rbReloadShaders->isChecked());
658 OpenFlipperSettings().setValue("Core/File/ShaderOutputDir",leShaderOutputDir->text() ) ;
659 ACG::ShaderCache::getInstance()->setDebugOutputDir(leShaderOutputDir->text().toUtf8());
660
661 OpenFlipperSettings().setValue("Core/File/AllTarget",allTarget->isChecked());
662
663
664 // Toolbox orientation
665 OpenFlipperSettings().setValue("Core/Gui/ToolBoxes/ToolBoxOnTheRight", (toolBoxOrientation->currentIndex() == 0));
666
667 // Render picking toolbar into scene
668 if ( OpenFlipperSettings().value("Core/Gui/ToolBars/PickToolbarInScene",true).toBool() != pickToolbarInScene->isChecked() ) {
669 OpenFlipperSettings().setValue("Core/Gui/ToolBars/PickToolbarInScene", pickToolbarInScene->isChecked());
670 restartRequired_ = true;
671 }
672
673 if ( iconDefault->isChecked() )
674 OpenFlipperSettings().setValue("Core/Toolbar/iconSize", 0);
675 else if ( iconSmall->isChecked() )
676 OpenFlipperSettings().setValue("Core/Toolbar/iconSize", 1);
677 else if ( iconNormal->isChecked() )
678 OpenFlipperSettings().setValue("Core/Toolbar/iconSize", 2);
679
680 //viewer
681 OpenFlipperSettings().setValue("Core/Mouse/Wheel/ZoomFactor", wZoomFactor->value());
682 OpenFlipperSettings().setValue("Core/Mouse/Wheel/ZoomFactorShift", wZoomFactorShift->value());
683 OpenFlipperSettings().setValue("Core/Mouse/Wheel/Invert", invertMouseWheelBox->isChecked());
684
685 // Projection settings
686 OpenFlipperSettings().setValue("Core/Projection/FOVY", fieldOfView->value());
687 OpenFlipperSettings().setValue("Core/Gui/glViewer/minimalSceneSize",minimalSceneSize->value());
688
689 OpenFlipperSettings().setValue("Core/Gui/glViewer/showControlWheels", wheelBox->isChecked() );
690
691 OpenFlipperSettings().setValue("Core/Gui/glViewer/restrictFrameRate", restrictFPS->isChecked());
692 OpenFlipperSettings().setValue("Core/Gui/glViewer/maxFrameRate", FPS->value() );
693
694 OpenFlipper::Options::randomDefaultColor( randomDefaultColor->isChecked() );
695
696 //stereo
697 if (stereoCustomAnaglyph->isChecked ())
698 OpenFlipper::Options::stereoMode(OpenFlipper::Options::AnaglyphCustom);
699 else if (stereoAnaglyph->isChecked ())
700 OpenFlipper::Options::stereoMode(OpenFlipper::Options::AnaglyphRedCyan);
701 else
702 OpenFlipper::Options::stereoMode(OpenFlipper::Options::OpenGL);
703
704 OpenFlipperSettings().setValue("Core/Stereo/EyeDistance",eyeDistance->value ());
705 OpenFlipperSettings().setValue("Core/Stereo/FocalDistance",double(focalDistance->value() / 1000.0));
706
707 std::vector<float> mat (9, 0);
708 mat[0] = lcm0->value ();
709 mat[1] = lcm1->value ();
710 mat[2] = lcm2->value ();
711 mat[3] = lcm3->value ();
712 mat[4] = lcm4->value ();
713 mat[5] = lcm5->value ();
714 mat[6] = lcm6->value ();
715 mat[7] = lcm7->value ();
716 mat[8] = lcm8->value ();
717
718 OpenFlipper::Options::anaglyphLeftEyeColorMatrix (mat);
719
720 mat[0] = rcm0->value ();
721 mat[1] = rcm1->value ();
722 mat[2] = rcm2->value ();
723 mat[3] = rcm3->value ();
724 mat[4] = rcm4->value ();
725 mat[5] = rcm5->value ();
726 mat[6] = rcm6->value ();
727 mat[7] = rcm7->value ();
728 mat[8] = rcm8->value ();
729
730 OpenFlipper::Options::anaglyphRightEyeColorMatrix (mat);
731
732 OpenFlipperSettings().setValue("Core/Gui/glViewer/stereoMousePick",!noMousePick->isChecked ());
733 OpenFlipperSettings().setValue("Core/Gui/glViewer/nativeMouse",nativeMouse->isChecked ());
734
735 // updates
736 OpenFlipperSettings().setValue("Core/Update/UserName", updateUser->text());
737 OpenFlipperSettings().setValue("Core/Update/Pass",updatePass->text());
738 OpenFlipperSettings().setValue("Core/Update/URL",updateURL->text());
739
740 // Debugging
741 OpenFlipper::Options::doSlotDebugging(slotDebugging->isChecked());
742
743 //viewer defaults
744 for (int i=0; i < PluginFunctions::viewers(); i++){
745 OpenFlipper::Options::defaultDrawMode( defaultDrawModes_[i], i );
746 OpenFlipper::Options::defaultPerspectiveProjectionMode( defaultProjectionMode_[i], i );
747 OpenFlipper::Options::defaultViewingDirection( defaultViewingDirections_[i], i );
748 OpenFlipper::Options::defaultLockRotation( defaultRotationLocks_[i], i );
749 }
750
751 OpenFlipper::Options::defaultViewerLayout( viewerLayout->currentIndex() );
752
753 // Restrict fps if desired
754 if(restrictFPS->isChecked()) {
755 OpenFlipperSettings().setValue("Core/Gui/glViewer/restrictFrameRate", true);
756 OpenFlipperSettings().setValue("Core/Gui/glViewer/maxFrameRate",FPS->value());
757 } else {
758 OpenFlipperSettings().setValue("Core/Gui/glViewer/restrictFrameRate", false);
759 }
760
761 // Set background color
762 OpenFlipperSettings().setValue("Core/Gui/glViewer/defaultBackgroundColor", backgroundColor_);
763
764 for ( uint i = 0 ; i < OpenFlipper::Options::examinerWidgets(); ++i )
765 PluginFunctions::viewerProperties(i).backgroundColor(ACG::Vec4f(((double) backgroundColor_.redF()),
766 ((double) backgroundColor_.greenF()),
767 ((double) backgroundColor_.blueF()),
768 1.0));
769
770 switch ( translation->currentIndex() ){
771 case 0 : OpenFlipperSettings().setValue("Core/Language/Translation","en_US"); break;
772 case 1 : OpenFlipperSettings().setValue("Core/Language/Translation","de_DE"); break;
773 default: OpenFlipperSettings().setValue("Core/Language/Translation","locale"); break;
774 }
775
776 // Show warning message that restart is required if language or in scene toolbar has been changed...
777 if(restartRequired_) {
778 int restart = QMessageBox::information(this, tr("Restart required!"),
779 tr("The changes will take effect after next restart. Do you want to close OpenFlipper now?"),
780 QMessageBox::Yes | QMessageBox::No);
781
782 if(restart == QMessageBox::Yes) exitOnClose_ = true;
783 }
784
786
787 emit applyOptions();
788 emit saveOptions();
789
790 // Make sure all settings are written before we quit!
791 OpenFlipperSettings().sync();
792
793 // Close OpenFlipper if demanded
794 if(exitOnClose_) QCoreApplication::quit();
795}
796
798 slotApply();
799 hide();
800}
801
803 hide();
804}
805
807
808 // http://www.graphics.rwth-aachen.de/restricted/OpenFlipper-SIL/
809
810 downloadType = VERSIONS_FILE;
811 QString ServerMainURL = updateURL->text();
812 if ( !ServerMainURL.endsWith("/") )
813 ServerMainURL += "/";
814
815 ServerMainURL += "Versions.ini";
816
817 startDownload(ServerMainURL);
818}
819
821 std::cerr << "Not implemented yet: Get updates" << std::endl;
822 QString url = updateURL->text();
823
824 if ( !url.endsWith("/") )
825 url += "/";
826
827
828 pluginPath_.clear();
829 pluginPath_ = "Plugins/";
830
831 if ( OpenFlipper::Options::isWindows() ) {
832 pluginPath_ += "Windows/";
833 } else if ( OpenFlipper::Options::isLinux() ) {
834 pluginPath_ += "Linux/";
835 } else {
836 std::cerr << "Unknown operating system type, aborting update" << std::endl;
837 return;
838 }
839
840 if ( OpenFlipper::Options::is64bit() ) {
841 pluginPath_ += "64/";
842 } else if ( OpenFlipper::Options::is32bit() ) {
843 pluginPath_ += "32/";
844 } else {
845 std::cerr << "Unknown architecture type, aborting update" << std::endl;
846 return;
847 }
848
849 pluginPath_ += "Release/";
850
851 if ( !updatedPlugins_.empty() && updatedPlugins_[0] == "Core" ) {
852 std::cerr << "Core update not supported!" << std::endl;
853 return;
854 }
855
856 if ( !updatedPlugins_.empty() ) {
858 std::cerr << "Downloading " << (url + pluginPath_ + currentUpdateName_).toStdString() << std::endl;
859 updatedPlugins_.pop_front();
860
861 downloadType = PLUGIN;
862
864 }
865
866}
867
868void OptionsWidget::updateComponent() {
869 std::cerr << "Todo : Update component" << std::endl;
870
871
872
873 QString sourceName = QDir::home().absolutePath() + OpenFlipper::Options::dirSeparator() +
874 ".OpenFlipper" + OpenFlipper::Options::dirSeparator() + currentUpdateName_ ;
875
876 QString targetName = OpenFlipper::Options::applicationDirStr() + "/" + pluginPath_ + currentUpdateName_;
877
878 QFileInfo sourceFileInfo(sourceName);
879 QFileInfo targetFileInfo(targetName);
880
881 std::cerr << sourceName.toStdString() << std::endl;
882 std::cerr << targetName.toStdString() << std::endl;
883
884 if ( ! sourceFileInfo.exists() ) {
885 statusLabel->setText(tr("Download failed!"));
887 return;
888 } else {
889 if ( ! targetFileInfo.exists() ) {
890 statusLabel->setText(tr("plugin target does not exist"));
892 return;
893 }
894
895 statusLabel->setText(tr("Installing new file"));
896
897 // Remove the old plugin
898 QFile targetFile(targetName);
899 targetFile.remove();
900
901 // copy new to old
902 QFile::copy(sourceName,targetName);
903
904 // remove downloaded file
905 QFile sourceFile(sourceName);
906 sourceFile.remove();
907
908 statusLabel->setText(tr("updated ") + currentUpdateName_);
909 }
910
912}
913
914bool OptionsWidget::isNewer(QString _current, QString _latest) {
915
916 QStringList latestVersionParts = _latest.split('.');
917 QStringList currentVersionParts = _current.split('.');
918
919 bool newer = false;
920
921 for ( int i = 0 ; i < latestVersionParts.size(); ++i ) {
922
923 if ( i+1 > currentVersionParts.size() ) {
924 // Versions are identical up to now. But latest version has additional version => updated
925 newer = true;
926 break;
927 }
928
929 bool ok = false;
930 double latest = latestVersionParts[i].toInt(&ok);
931 double current = currentVersionParts[i].toInt(&ok);
932
933 if ( !ok )
934 std::cerr << "Error when parsing version strings!" << std::endl;
935
936 if ( latest > current ) {
937 newer = true;
938 break;
939 }
940 }
941
942 return newer;
943
944}
945
947
948 QString fileName = QDir::home().absolutePath() + OpenFlipper::Options::dirSeparator() +
949 ".OpenFlipper" + OpenFlipper::Options::dirSeparator() + "Versions.ini" ;
950
951 INIFile ini;
952 if ( ! ini.connect(fileName,false) ) {
953 std::cerr << "Failed to connect to Versions ini file" << std::endl;
954 return;
955 }
956
957 statusLabel->setText(tr("Checking for new versions"));
958
959 bool newerVersionsAvailable = false;
960
961 QString systemString = "";
962 if ( OpenFlipper::Options::isWindows() ) {
963 systemString = "VersionWindows";
964 } else if (OpenFlipper::Options::isLinux()) {
965 systemString = "VersionLinux";
966 } else {
967 std::cerr << "Unsupported platform for update" << std::endl;
968 return;
969 }
970
971 QString coreVersion;
972
973 if ( ini.get_entry(coreVersion, "Core" , systemString )) {
974 if ( isNewer( OpenFlipper::Options::coreVersion(), coreVersion ) ) {
975 newerVersionsAvailable = true;
976 }
977 }
978
979 for ( uint i = 0 ; i < plugins_.size(); ++i ) {
980 QString latestVersion;
981 if ( ini.get_entry(latestVersion, plugins_[i].name , systemString )) {
982 if ( isNewer( plugins_[i].version, latestVersion ) )
983 newerVersionsAvailable = true;
984 }
985 }
986
987 if ( newerVersionsAvailable ) {
988 statusLabel->setText(tr("Updates found"));
989 } else {
990 statusLabel->setText(tr("No updates found"));
991 }
992
993 ini.disconnect();
994
996}
997
999
1000 if (stereoCustomAnaglyph->isChecked ())
1001 OpenFlipper::Options::stereoMode(OpenFlipper::Options::AnaglyphCustom);
1002 else if (stereoAnaglyph->isChecked ())
1003 OpenFlipper::Options::stereoMode(OpenFlipper::Options::AnaglyphRedCyan);
1004 else
1005 OpenFlipper::Options::stereoMode(OpenFlipper::Options::OpenGL);
1006
1007 OpenFlipperSettings().setValue("Core/Stereo/EyeDistance", eyeDistance->value());
1008 OpenFlipperSettings().setValue("Core/Stereo/FocalDistance", double(focalDistance->value() / 1000.0));
1009
1010
1011 // Update all views
1012 emit applyOptions();
1013}
1014
1016
1017 OpenFlipperSettings().clear();
1018}
1019
1021
1022 QMessageBox::information(this, tr("Restart required!"),
1023 tr("The changes will take effect after next restart."));
1024
1025 OpenFlipper::Options::deleteIniFile(true);
1026}
1027
1029{
1031}
DLLEXPORT OpenFlipperQSettings & OpenFlipperSettings()
QSettings object containing all program settings of OpenFlipper.
static ShaderCache * getInstance()
Return instance of the ShaderCache singleton.
Definition: ShaderCache.cc:84
void clearCache()
Delete all cached shaders.
Definition: ShaderCache.cc:595
void setTimeCheck(bool _on)
enable or disable checking of the time step of each file
Definition: ShaderCache.hh:171
void setDebugOutputDir(const char *_outputDir)
Enable debug output of generated shaders to specified directory.
Definition: ShaderCache.cc:602
Class for the handling of simple configuration files.
Definition: INIFile.hh:100
bool is_connected() const
Check if object is connected to file.
Definition: INIFile.hh:117
bool connect(const QString &name, const bool create)
Connect INIFile object with given filename.
Definition: INIFile.cc:70
bool get_entry(QString &_val, const QString &_section, const QString &_key) const
Access to a string entry.
Definition: INIFile.cc:433
void disconnect()
Remove connection of this object to a file.
Definition: INIFile.cc:122
QVariant value(const QString &key, const QVariant &defaultValue=QVariant()) const
void setValue(const QString &key, const QVariant &value)
Wrapper function which makes it possible to enable Debugging output with -DOPENFLIPPER_SETTINGS_DEBUG...
void updateViewerSettings(int _row)
update the dialog if the selected viewer changes
QString pluginPath_
void slotCheckUpdates()
Checks for updates.
void keyTreeDoubleClicked(QTreeWidgetItem *_item, int col)
doubleclick in the keyTree
Definition: keyBindings.cc:59
void slotClearINI()
Clear OpenFlipper INI.
void initKeyTree()
init the TreeWidget containing the keyBindings
Definition: keyBindings.cc:196
void switchStackedWidget()
Switch between the stacked widgets of the stereo settings.
void slotClearSettings()
Clear all OpenFlipper settings.
void restoreKeyPresets()
restore keyBinding Presets
Definition: keyBindings.cc:159
void updateVersionsTable()
Redraws the version table.
QStringList updatedPlugins_
void slotApply()
Update Options and tell others about changed Options.
void slotPreviewStereoSettings(int _tmpParam=0)
void slotReloadShaders()
Clear the Shader Cache.
void applyShortcuts()
check which of the shortcuts changed and inform the core about the change
Definition: keyBindings.cc:123
void slotOk()
call slotApply and hide widget
void slotGetUpdates()
Download updates.
void compareVersions()
Compares the versions from the downloaded Versions file with the current versions.
void keyTreeItemChanged(QTreeWidgetItem *current, QTreeWidgetItem *previous)
keyBinding TreeWidget-Item changed
Definition: keyBindings.cc:70
void viewerSettingsChanged(QListWidgetItem *_item)
remember user changes to viewer properties
QString currentUpdateName_
void startDownload(QString _url)
Starts the download of the given file.
Definition: downloader.cc:52
void updateShortcut()
check if the shortcut exists and add it if not
Definition: keyBindings.cc:86
void getBackgroundColor()
open a dialog to determine the color
bool isNewer(QString _current, QString _latest)
Compares two version strings and returns if a newer Version is available.
void slotCancel()
Only hide widget.
ACG::Vec4f backgroundColor()
Get current background color.
DrawMode DEFAULT
use the default (global) draw mode and not the node's own.
Definition: DrawModes.cc:72
Viewer::ViewerProperties & viewerProperties(int _id)
Get the viewer properties Use this functions to get basic viewer properties such as backgroundcolor o...
int viewers()
Get the number of viewers.