History

Killing the old preferences dialog

Brad Davis committed 10 years ago

Commit 208d7c31 parent 71ae36f8 files · +17 −3435Browse files

Showing the changes to interface/src/ui/PreferencesDialog.cpp (1 of 8 files). Show all

Unified · Split

interface/src/ui/PreferencesDialog.cpp+3−308
@@ -1,16 +1,12 @@
11 //
2−// PreferencesDialog.cpp
3−// interface/src/ui
4−//
5−// Created by Stojce Slavkovski on 2/20/14.
6−// Copyright 2014 High Fidelity, Inc.
2+// Re-created Bradley Austin Davis on 2016/01/22
3+// Copyright 2016 High Fidelity, Inc.
74 //
85 // Distributed under the Apache License, Version 2.0.
96 // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
107 //
118
12−#include <QFileDialog>
13−#include <QFont>
9+#include "PreferencesDialog.h"
1410
1511 #include <AudioClient.h>
1612 #include <avatar/AvatarManager.h>
@@ -19,19 +15,14 @@ · 2 unmodified lines
1915 #include <NetworkingConstants.h>
2016 #include <ScriptEngines.h>
2117 #include <OffscreenUi.h>
22−#include <QtQml/QQmlContext>
2318 #include <Preferences.h>
2419
2520 #include "Application.h"
2621 #include "DialogsManager.h"
27−#include "MainWindow.h"
2822 #include "LODManager.h"
2923 #include "Menu.h"
30−#include "PreferencesDialog.h"
3124 #include "Snapshot.h"
3225 #include "UserActivityLogger.h"
33−#include "UIUtil.h"
34−#include "scripting/WebWindowClass.h"
3526
3627 void setupPreferences() {
3728 auto preferences = DependencyManager::get<Preferences>();
@@ -320,299 +311,3 @@ void setupPreferences() { · 282 unmodified lines
320311 preferences->addPreference(preference);
321312 }
322313 }
323−
324−const int PREFERENCES_HEIGHT_PADDING = 20;
325−
326−PreferencesDialog::PreferencesDialog(QWidget* parent) :
327− QDialog(parent)
328−{
329− setAttribute(Qt::WA_DeleteOnClose);
330−
331− ui.setupUi(this);
332− loadPreferences();
333−
334− ui.outputBufferSizeSpinner->setMinimum(MIN_AUDIO_OUTPUT_BUFFER_SIZE_FRAMES);
335− ui.outputBufferSizeSpinner->setMaximum(MAX_AUDIO_OUTPUT_BUFFER_SIZE_FRAMES);
336−
337− connect(ui.buttonBrowseLocation, &QPushButton::clicked, this, &PreferencesDialog::openSnapshotLocationBrowser);
338− connect(ui.buttonBrowseScriptsLocation, &QPushButton::clicked, this, &PreferencesDialog::openScriptsLocationBrowser);
339− connect(ui.buttonReloadDefaultScripts, &QPushButton::clicked, [] {
340− DependencyManager::get<ScriptEngines>()->loadDefaultScripts();
341− });
342−
343− connect(ui.buttonChangeAppearance, &QPushButton::clicked, this, &PreferencesDialog::openFullAvatarModelBrowser);
344− connect(ui.appearanceDescription, &QLineEdit::editingFinished, this, &PreferencesDialog::changeFullAvatarURL);
345− connect(ui.useAcuityCheckBox, &QCheckBox::clicked, this, &PreferencesDialog::changeUseAcuity);
346−
347− connect(qApp, &Application::fullAvatarURLChanged, this, &PreferencesDialog::fullAvatarURLChanged);
348−
349− // move dialog to left side
350− move(parentWidget()->geometry().topLeft());
351− resize(sizeHint().width(), parentWidget()->size().height() - PREFERENCES_HEIGHT_PADDING);
352−
353− UIUtil::scaleWidgetFontSizes(this);
354−}
355−
356−void PreferencesDialog::changeUseAcuity() {
357− bool useAcuity = ui.useAcuityCheckBox->isChecked();
358− ui.label_desktopMinimumFPSSpin->setEnabled(useAcuity);
359− ui.desktopMinimumFPSSpin->setEnabled(useAcuity);
360− ui.label_hmdMinimumFPSSpin->setEnabled(useAcuity);
361− ui.hmdMinimumFPSSpin->setEnabled(useAcuity);
362− ui.label_smallestReasonableRenderHorizon->setEnabled(!useAcuity);
363− ui.smallestReasonableRenderHorizon->setEnabled(!useAcuity);
364− Menu::getInstance()->getActionForOption(MenuOption::LodTools)->setEnabled(useAcuity);
365− Menu::getInstance()->getSubMenuFromName(MenuOption::RenderResolution, Menu::getInstance()->getSubMenuFromName("Render", Menu::getInstance()->getMenu("Developer")))->setEnabled(useAcuity);
366−}
367−void PreferencesDialog::changeFullAvatarURL() {
368− DependencyManager::get<AvatarManager>()->getMyAvatar()->useFullAvatarURL(ui.appearanceDescription->text(), "");
369− this->fullAvatarURLChanged(ui.appearanceDescription->text(), "");
370−}
371−
372−void PreferencesDialog::fullAvatarURLChanged(const QString& newValue, const QString& modelName) {
373− ui.appearanceDescription->setText(newValue);
374− const QString APPEARANCE_LABEL_TEXT("Appearance: ");
375− ui.appearanceLabel->setText(APPEARANCE_LABEL_TEXT + modelName);
376−}
377−
378−void PreferencesDialog::accept() {
379− MyAvatar* myAvatar = DependencyManager::get<AvatarManager>()->getMyAvatar();
380−
381− // if there is an attempted change to the full avatar URL, apply it now
382− if (QUrl(ui.appearanceDescription->text()) != myAvatar->getFullAvatarURLFromPreferences()) {
383− changeFullAvatarURL();
384− }
385−
386− _lastGoodAvatarURL = myAvatar->getFullAvatarURLFromPreferences();
387− _lastGoodAvatarName = myAvatar->getFullAvatarModelName();
388−
389− savePreferences();
390−
391− close();
392− delete _marketplaceWindow;
393− _marketplaceWindow = NULL;
394−}
395−
396−void PreferencesDialog::restoreLastGoodAvatar() {
397− const QString& url = _lastGoodAvatarURL.toString();
398− fullAvatarURLChanged(url, _lastGoodAvatarName);
399− DependencyManager::get<AvatarManager>()->getMyAvatar()->useFullAvatarURL(url, _lastGoodAvatarName);
400−}
401−
402−void PreferencesDialog::reject() {
403− restoreLastGoodAvatar();
404− QDialog::reject();
405−}
406−
407−void PreferencesDialog::openSnapshotLocationBrowser() {
408− QString dir = QFileDialog::getExistingDirectory(this, tr("Snapshots Location"),
409− QStandardPaths::writableLocation(QStandardPaths::DesktopLocation),
410− QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);
411− if (!dir.isNull() && !dir.isEmpty()) {
412− ui.snapshotLocationEdit->setText(dir);
413− }
414−}
415−
416−void PreferencesDialog::openScriptsLocationBrowser() {
417− QString dir = QFileDialog::getExistingDirectory(this, tr("Scripts Location"),
418− ui.scriptsLocationEdit->text(),
419− QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);
420− if (!dir.isNull() && !dir.isEmpty()) {
421− ui.scriptsLocationEdit->setText(dir);
422− }
423−}
424−void PreferencesDialog::openFullAvatarModelBrowser() {
425− const auto MARKETPLACE_URL = NetworkingConstants::METAVERSE_SERVER_URL.toString() + "/marketplace?category=avatars";
426− const auto WIDTH = 900;
427− const auto HEIGHT = 700;
428− if (!_marketplaceWindow) {
429− _marketplaceWindow = new WebWindowClass("Marketplace", MARKETPLACE_URL, WIDTH, HEIGHT);
430− }
431− _marketplaceWindow->setVisible(true);
432−
433−}
434−
435−void PreferencesDialog::resizeEvent(QResizeEvent *resizeEvent) {
436−
437− // keep buttons panel at the bottom
438− ui.buttonsPanel->setGeometry(0,
439− size().height() - ui.buttonsPanel->height(),
440− size().width(),
441− ui.buttonsPanel->height());
442−
443− // set width and height of srcollarea to match bottom panel and width
444− ui.scrollArea->setGeometry(ui.scrollArea->geometry().x(), ui.scrollArea->geometry().y(),
445− size().width(),
446− size().height() - ui.buttonsPanel->height() - ui.scrollArea->geometry().y());
447−
448−}
449−
450−void PreferencesDialog::loadPreferences() {
451−
452− MyAvatar* myAvatar = DependencyManager::get<AvatarManager>()->getMyAvatar();
453− Menu* menuInstance = Menu::getInstance();
454−
455− _displayNameString = myAvatar->getDisplayName();
456− ui.displayNameEdit->setText(_displayNameString);
457−
458− ui.collisionSoundURLEdit->setText(myAvatar->getCollisionSoundURL());
459−
460− _lastGoodAvatarURL = myAvatar->getFullAvatarURLFromPreferences();
461− _lastGoodAvatarName = myAvatar->getFullAvatarModelName();
462− fullAvatarURLChanged(_lastGoodAvatarURL.toString(), _lastGoodAvatarName);
463−
464− ui.sendDataCheckBox->setChecked(!menuInstance->isOptionChecked(MenuOption::DisableActivityLogger));
465−
466− ui.snapshotLocationEdit->setText(Snapshot::snapshotsLocation.get());
467−
468− ui.scriptsLocationEdit->setText(DependencyManager::get<ScriptEngines>()->getScriptsLocation());
469−
470− ui.pupilDilationSlider->setValue(myAvatar->getHead()->getPupilDilation() *
471− ui.pupilDilationSlider->maximum());
472−
473− auto dde = DependencyManager::get<DdeFaceTracker>();
474− ui.ddeEyeClosingThresholdSlider->setValue(dde->getEyeClosingThreshold() *
475− ui.ddeEyeClosingThresholdSlider->maximum());
476−
477− ui.faceTrackerEyeDeflectionSider->setValue(FaceTracker::getEyeDeflection() *
478− ui.faceTrackerEyeDeflectionSider->maximum());
479−
480− auto faceshift = DependencyManager::get<Faceshift>();
481− ui.faceshiftHostnameEdit->setText(faceshift->getHostname());
482−
483− auto audio = DependencyManager::get<AudioClient>();
484− MixedProcessedAudioStream& stream = audio->getReceivedAudioStream();
485−
486− ui.dynamicJitterBuffersCheckBox->setChecked(stream.getDynamicJitterBuffers());
487− ui.staticDesiredJitterBufferFramesSpin->setValue(stream.getDesiredJitterBufferFrames());
488− ui.maxFramesOverDesiredSpin->setValue(stream.getMaxFramesOverDesired());
489− ui.useStdevForJitterCalcCheckBox->setChecked(stream.getUseStDevForJitterCalc());
490− ui.windowStarveThresholdSpin->setValue(stream.getWindowStarveThreshold());
491− ui.windowSecondsForDesiredCalcOnTooManyStarvesSpin->setValue(
492− stream.getWindowSecondsForDesiredCalcOnTooManyStarves());
493− ui.windowSecondsForDesiredReductionSpin->setValue(stream.getWindowSecondsForDesiredReduction());
494− ui.repetitionWithFadeCheckBox->setChecked(stream.getRepetitionWithFade());
495−
496− ui.outputBufferSizeSpinner->setValue(audio->getOutputBufferSize());
497−
498− ui.outputStarveDetectionCheckBox->setChecked(audio->getOutputStarveDetectionEnabled());
499− ui.outputStarveDetectionThresholdSpinner->setValue(audio->getOutputStarveDetectionThreshold());
500− ui.outputStarveDetectionPeriodSpinner->setValue(audio->getOutputStarveDetectionPeriod());
501−
502− ui.realWorldFieldOfViewSpin->setValue(myAvatar->getRealWorldFieldOfView());
503−
504− ui.fieldOfViewSpin->setValue(qApp->getFieldOfView());
505−
506− ui.leanScaleSpin->setValue(myAvatar->getLeanScale());
507−
508− ui.avatarScaleSpin->setValue(myAvatar->getUniformScale());
509− ui.avatarAnimationEdit->setText(myAvatar->getAnimGraphUrl().toString());
510−
511− ui.maxOctreePPSSpin->setValue(qApp->getMaxOctreePacketsPerSecond());
512−
513−#if 0
514− ui.oculusUIAngularSizeSpin->setValue(qApp->getApplicationCompositor().getHmdUIAngularSize());
515−#endif
516−
517− ui.sixenseReticleMoveSpeedSpin->setValue(controller::InputDevice::getReticleMoveSpeed());
518−
519− // LOD items
520− auto lodManager = DependencyManager::get<LODManager>();
521− ui.useAcuityCheckBox->setChecked(lodManager->getUseAcuity());
522− ui.desktopMinimumFPSSpin->setValue(lodManager->getDesktopLODDecreaseFPS());
523− ui.hmdMinimumFPSSpin->setValue(lodManager->getHMDLODDecreaseFPS());
524− ui.smallestReasonableRenderHorizon->setValue(1.0f / lodManager->getRenderDistanceInverseHighLimit());
525− changeUseAcuity();
526−}
527−
528−void PreferencesDialog::savePreferences() {
529−
530− MyAvatar* myAvatar = DependencyManager::get<AvatarManager>()->getMyAvatar();
531−
532− bool shouldDispatchIdentityPacket = false;
533−
534− QString displayNameStr(ui.displayNameEdit->text());
535− if (displayNameStr != _displayNameString) {
536− myAvatar->setDisplayName(displayNameStr);
537− UserActivityLogger::getInstance().changedDisplayName(displayNameStr);
538− shouldDispatchIdentityPacket = true;
539− }
540−
541− if (shouldDispatchIdentityPacket) {
542− myAvatar->sendIdentityPacket();
543− }
544−
545− myAvatar->setCollisionSoundURL(ui.collisionSoundURLEdit->text());
546−
547− // MyAvatar persists its own data. If it doesn't agree with what the user has explicitly accepted, set it back to old values.
548− if (_lastGoodAvatarURL != myAvatar->getFullAvatarURLFromPreferences()) {
549− restoreLastGoodAvatar();
550− }
551−
552− if (!Menu::getInstance()->isOptionChecked(MenuOption::DisableActivityLogger)
553− != ui.sendDataCheckBox->isChecked()) {
554− Menu::getInstance()->triggerOption(MenuOption::DisableActivityLogger);
555− }
556−
557− if (!ui.snapshotLocationEdit->text().isEmpty() && QDir(ui.snapshotLocationEdit->text()).exists()) {
558− Snapshot::snapshotsLocation.set(ui.snapshotLocationEdit->text());
559− }
560−
561− if (!ui.scriptsLocationEdit->text().isEmpty() && QDir(ui.scriptsLocationEdit->text()).exists()) {
562− DependencyManager::get<ScriptEngines>()->setScriptsLocation(ui.scriptsLocationEdit->text());
563− }
564−
565− myAvatar->getHead()->setPupilDilation(ui.pupilDilationSlider->value() / (float)ui.pupilDilationSlider->maximum());
566− myAvatar->setLeanScale(ui.leanScaleSpin->value());
567− myAvatar->setTargetScaleVerbose(ui.avatarScaleSpin->value());
568− if (myAvatar->getAnimGraphUrl() != ui.avatarAnimationEdit->text()) { // If changed, destroy the old and start with the new
569− myAvatar->setAnimGraphUrl(ui.avatarAnimationEdit->text());
570− }
571−
572− myAvatar->setRealWorldFieldOfView(ui.realWorldFieldOfViewSpin->value());
573−
574− qApp->setFieldOfView(ui.fieldOfViewSpin->value());
575−
576− auto dde = DependencyManager::get<DdeFaceTracker>();
577− dde->setEyeClosingThreshold(ui.ddeEyeClosingThresholdSlider->value() /
578− (float)ui.ddeEyeClosingThresholdSlider->maximum());
579−
580− FaceTracker::setEyeDeflection(ui.faceTrackerEyeDeflectionSider->value() /
581− (float)ui.faceTrackerEyeDeflectionSider->maximum());
582−
583− auto faceshift = DependencyManager::get<Faceshift>();
584− faceshift->setHostname(ui.faceshiftHostnameEdit->text());
585−
586− qApp->setMaxOctreePacketsPerSecond(ui.maxOctreePPSSpin->value());
587−
588− qApp->getApplicationCompositor().setHmdUIAngularSize(ui.oculusUIAngularSizeSpin->value());
589−
590− controller::InputDevice::setReticleMoveSpeed(ui.sixenseReticleMoveSpeedSpin->value());
591−
592− auto audio = DependencyManager::get<AudioClient>();
593− MixedProcessedAudioStream& stream = audio->getReceivedAudioStream();
594−
595− stream.setDynamicJitterBuffers(ui.dynamicJitterBuffersCheckBox->isChecked());
596− stream.setStaticDesiredJitterBufferFrames(ui.staticDesiredJitterBufferFramesSpin->value());
597− stream.setMaxFramesOverDesired(ui.maxFramesOverDesiredSpin->value());
598− stream.setUseStDevForJitterCalc(ui.useStdevForJitterCalcCheckBox->isChecked());
599− stream.setWindowStarveThreshold(ui.windowStarveThresholdSpin->value());
600− stream.setWindowSecondsForDesiredCalcOnTooManyStarves(ui.windowSecondsForDesiredCalcOnTooManyStarvesSpin->value());
601− stream.setWindowSecondsForDesiredReduction(ui.windowSecondsForDesiredReductionSpin->value());
602− stream.setRepetitionWithFade(ui.repetitionWithFadeCheckBox->isChecked());
603−
604− QMetaObject::invokeMethod(audio.data(), "setOutputBufferSize", Q_ARG(int, ui.outputBufferSizeSpinner->value()));
605−
606− audio->setOutputStarveDetectionEnabled(ui.outputStarveDetectionCheckBox->isChecked());
607− audio->setOutputStarveDetectionThreshold(ui.outputStarveDetectionThresholdSpinner->value());
608− audio->setOutputStarveDetectionPeriod(ui.outputStarveDetectionPeriodSpinner->value());
609−
610− qApp->resizeGL();
611−
612− // LOD items
613− auto lodManager = DependencyManager::get<LODManager>();
614− lodManager->setUseAcuity(ui.useAcuityCheckBox->isChecked());
615− lodManager->setDesktopLODDecreaseFPS(ui.desktopMinimumFPSSpin->value());
616− lodManager->setHMDLODDecreaseFPS(ui.hmdMinimumFPSSpin->value());
617− lodManager->setRenderDistanceInverseHighLimit(1.0f / ui.smallestReasonableRenderHorizon->value());
618−}

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t