From ec73edb8d88f80195d6b9708d6b6847db00c4cf4 Mon Sep 17 00:00:00 2001 From: stojce Date: Sun, 23 Feb 2014 13:54:22 +0100 Subject: [PATCH] restyled preferences dialog - Frameless dialog super class --- interface/resources/styles/global.qss | 35 ++ interface/src/Menu.cpp | 139 +----- interface/src/Menu.h | 2 + interface/src/ui/FramelessDialog.cpp | 23 + interface/src/ui/FramelessDialog.h | 27 ++ interface/src/ui/PreferencesDialog.cpp | 96 ++++ interface/src/ui/PreferencesDialog.h | 37 ++ interface/ui/preferencesDialog.ui | 646 +++++++++++++++++++++++++ 8 files changed, 871 insertions(+), 134 deletions(-) create mode 100644 interface/resources/styles/global.qss create mode 100644 interface/src/ui/FramelessDialog.cpp create mode 100644 interface/src/ui/FramelessDialog.h create mode 100644 interface/src/ui/PreferencesDialog.cpp create mode 100644 interface/src/ui/PreferencesDialog.h create mode 100644 interface/ui/preferencesDialog.ui diff --git a/interface/resources/styles/global.qss b/interface/resources/styles/global.qss new file mode 100644 index 0000000000..3ecb96fa8c --- /dev/null +++ b/interface/resources/styles/global.qss @@ -0,0 +1,35 @@ +* { + padding: 0; + margin: 0; +} + +FramelessDialog { + background-color: rgb(255, 255, 255); + font-family: Helvetica, Arial, sans-serif; + font-size: 16px; +} + +QLineEdit { + background-color: rgba(255, 255, 255, 1); + border-style: solid; + border-width: 1px; + border-color: #ccc; + padding: 7px; + opacity: 1; +} + +QLabel p { + color: #0e7077; + font-size: 23px; +} + +QPushButton { + border-width: 0; + border-radius: 9px; + border-radius: 9px; + font-family: Arial; + font-size: 18px; + font-weight: 100; + color: #ffffff; + padding: 10px 15px; +} diff --git a/interface/src/Menu.cpp b/interface/src/Menu.cpp index 327f905194..e3fd698ecf 100644 --- a/interface/src/Menu.cpp +++ b/interface/src/Menu.cpp @@ -71,7 +71,8 @@ Menu::Menu() : _voxelSizeScale(DEFAULT_OCTREE_SIZE_SCALE), _boundaryLevelAdjust(0), _maxVoxelPacketsPerSecond(DEFAULT_MAX_VOXEL_PPS), - _lastAdjust(usecTimestampNow()) + _lastAdjust(usecTimestampNow()), + _preferencesDialog() { Application *appInstance = Application::getInstance(); @@ -763,140 +764,10 @@ void Menu::login() { } void Menu::editPreferences() { - Application* applicationInstance = Application::getInstance(); - - QDialog dialog(applicationInstance->getWindow()); - dialog.setWindowTitle("Interface Preferences"); - QBoxLayout* layout = new QBoxLayout(QBoxLayout::TopToBottom); - dialog.setLayout(layout); - - QFormLayout* form = new QFormLayout(); - layout->addLayout(form, 1); - - QString faceURLString = applicationInstance->getAvatar()->getHead()->getFaceModel().getURL().toString(); - QLineEdit* faceURLEdit = new QLineEdit(faceURLString); - faceURLEdit->setMinimumWidth(QLINE_MINIMUM_WIDTH); - faceURLEdit->setPlaceholderText(DEFAULT_HEAD_MODEL_URL.toString()); - form->addRow("Face URL:", faceURLEdit); - - QString skeletonURLString = applicationInstance->getAvatar()->getSkeletonModel().getURL().toString(); - QLineEdit* skeletonURLEdit = new QLineEdit(skeletonURLString); - skeletonURLEdit->setMinimumWidth(QLINE_MINIMUM_WIDTH); - skeletonURLEdit->setPlaceholderText(DEFAULT_BODY_MODEL_URL.toString()); - form->addRow("Skeleton URL:", skeletonURLEdit); - - QString displayNameString = applicationInstance->getAvatar()->getDisplayName(); - QLineEdit* displayNameEdit = new QLineEdit(displayNameString); - displayNameEdit->setMinimumWidth(QLINE_MINIMUM_WIDTH); - form->addRow("Display name:", displayNameEdit); - - QSlider* pupilDilation = new QSlider(Qt::Horizontal); - pupilDilation->setValue(applicationInstance->getAvatar()->getHead()->getPupilDilation() * pupilDilation->maximum()); - form->addRow("Pupil Dilation:", pupilDilation); - - QSlider* faceshiftEyeDeflection = new QSlider(Qt::Horizontal); - faceshiftEyeDeflection->setValue(_faceshiftEyeDeflection * faceshiftEyeDeflection->maximum()); - form->addRow("Faceshift Eye Deflection:", faceshiftEyeDeflection); - - QSpinBox* fieldOfView = new QSpinBox(); - fieldOfView->setMaximum(180); - fieldOfView->setMinimum(1); - fieldOfView->setValue(_fieldOfView); - form->addRow("Vertical Field of View (Degrees):", fieldOfView); - - QDoubleSpinBox* leanScale = new QDoubleSpinBox(); - leanScale->setValue(applicationInstance->getAvatar()->getLeanScale()); - form->addRow("Lean Scale:", leanScale); - - QDoubleSpinBox* avatarScale = new QDoubleSpinBox(); - avatarScale->setValue(applicationInstance->getAvatar()->getScale()); - form->addRow("Avatar Scale:", avatarScale); - - QSpinBox* audioJitterBufferSamples = new QSpinBox(); - audioJitterBufferSamples->setMaximum(10000); - audioJitterBufferSamples->setMinimum(-10000); - audioJitterBufferSamples->setValue(_audioJitterBufferSamples); - form->addRow("Audio Jitter Buffer Samples (0 for automatic):", audioJitterBufferSamples); - - QSpinBox* maxVoxels = new QSpinBox(); - const int MAX_MAX_VOXELS = 5000000; - const int MIN_MAX_VOXELS = 0; - const int STEP_MAX_VOXELS = 50000; - maxVoxels->setMaximum(MAX_MAX_VOXELS); - maxVoxels->setMinimum(MIN_MAX_VOXELS); - maxVoxels->setSingleStep(STEP_MAX_VOXELS); - maxVoxels->setValue(_maxVoxels); - form->addRow("Maximum Voxels:", maxVoxels); - - QSpinBox* maxVoxelsPPS = new QSpinBox(); - const int MAX_MAX_VOXELS_PPS = 6000; - const int MIN_MAX_VOXELS_PPS = 60; - const int STEP_MAX_VOXELS_PPS = 10; - maxVoxelsPPS->setMaximum(MAX_MAX_VOXELS_PPS); - maxVoxelsPPS->setMinimum(MIN_MAX_VOXELS_PPS); - maxVoxelsPPS->setSingleStep(STEP_MAX_VOXELS_PPS); - maxVoxelsPPS->setValue(_maxVoxelPacketsPerSecond); - form->addRow("Maximum Voxels Packets Per Second:", maxVoxelsPPS); - - QDialogButtonBox* buttons = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel); - dialog.connect(buttons, SIGNAL(accepted()), SLOT(accept())); - dialog.connect(buttons, SIGNAL(rejected()), SLOT(reject())); - layout->addWidget(buttons); - - int ret = dialog.exec(); - if (ret == QDialog::Accepted) { - QUrl faceModelURL(faceURLEdit->text()); - - bool shouldDispatchIdentityPacket = false; - - if (faceModelURL.toString() != faceURLString) { - // change the faceModelURL in the profile, it will also update this user's BlendFace - applicationInstance->getAvatar()->setFaceModelURL(faceModelURL); - shouldDispatchIdentityPacket = true; - } - - QUrl skeletonModelURL(skeletonURLEdit->text()); - - if (skeletonModelURL.toString() != skeletonURLString) { - // change the skeletonModelURL in the profile, it will also update this user's Body - applicationInstance->getAvatar()->setSkeletonModelURL(skeletonModelURL); - shouldDispatchIdentityPacket = true; - } - - QString displayNameStr(displayNameEdit->text()); - - if (displayNameStr != displayNameString) { - applicationInstance->getAvatar()->setDisplayName(displayNameStr); - shouldDispatchIdentityPacket = true; - } - - if (shouldDispatchIdentityPacket) { - applicationInstance->getAvatar()->sendIdentityPacket(); - } - - applicationInstance->getAvatar()->getHead()->setPupilDilation(pupilDilation->value() / (float)pupilDilation->maximum()); - - _maxVoxels = maxVoxels->value(); - applicationInstance->getVoxels()->setMaxVoxels(_maxVoxels); - - _maxVoxelPacketsPerSecond = maxVoxelsPPS->value(); - - applicationInstance->getAvatar()->setLeanScale(leanScale->value()); - applicationInstance->getAvatar()->setClampedTargetScale(avatarScale->value()); - - _audioJitterBufferSamples = audioJitterBufferSamples->value(); - - if (_audioJitterBufferSamples != 0) { - applicationInstance->getAudio()->setJitterBufferSamples(_audioJitterBufferSamples); - } - - _fieldOfView = fieldOfView->value(); - applicationInstance->resizeGL(applicationInstance->getGLWidget()->width(), applicationInstance->getGLWidget()->height()); - - _faceshiftEyeDeflection = faceshiftEyeDeflection->value() / (float)faceshiftEyeDeflection->maximum(); + if (! _preferencesDialog) { + _preferencesDialog = new PreferencesDialog(Application::getInstance()->getGLWidget()); } - - sendFakeEnterEvent(); + _preferencesDialog->show(); } void Menu::goToDomain(const QString newDomain) { diff --git a/interface/src/Menu.h b/interface/src/Menu.h index bd9cdc523e..4e75bc6fb9 100644 --- a/interface/src/Menu.h +++ b/interface/src/Menu.h @@ -15,6 +15,7 @@ #include #include +#include "ui/PreferencesDialog.h" const float ADJUST_LOD_DOWN_FPS = 40.0; const float ADJUST_LOD_UP_FPS = 55.0; @@ -173,6 +174,7 @@ private: QMenu* _activeScriptsMenu; QString replaceLastOccurrence(QChar search, QChar replace, QString string); quint64 _lastAdjust; + QPointer _preferencesDialog; }; namespace MenuOption { diff --git a/interface/src/ui/FramelessDialog.cpp b/interface/src/ui/FramelessDialog.cpp new file mode 100644 index 0000000000..ddd056fd32 --- /dev/null +++ b/interface/src/ui/FramelessDialog.cpp @@ -0,0 +1,23 @@ +// +// FramelessDialog.cpp +// hifi +// +// Created by Stojce Slavkovski on 2/20/14. +// +// + +#include "FramelessDialog.h" +#include +#include + +FramelessDialog::FramelessDialog(QWidget *parent, Qt::WindowFlags flags) : QDialog(parent, flags | Qt::FramelessWindowHint) { + QFile styleSheet("resources/styles/global.qss"); + if (styleSheet.open(QIODevice::ReadOnly)) { + setStyleSheet(styleSheet.readAll()); + } + setWindowOpacity(0.95); +} + +FramelessDialog::~FramelessDialog() { + +} diff --git a/interface/src/ui/FramelessDialog.h b/interface/src/ui/FramelessDialog.h new file mode 100644 index 0000000000..ca11c3eb2f --- /dev/null +++ b/interface/src/ui/FramelessDialog.h @@ -0,0 +1,27 @@ +// +// FramelessDialog.h +// hifi +// +// Created by Stojce Slavkovski on 2/20/14. +// +// + +#ifndef __hifi__FramelessDialog__ +#define __hifi__FramelessDialog__ + +#include +#include +#include +#include +#include + +class FramelessDialog : public QDialog { + Q_OBJECT + +public: + FramelessDialog(QWidget* parent = 0, Qt::WindowFlags flags = 0); + ~FramelessDialog(); + +}; + +#endif /* defined(__hifi__FramelessDialog__) */ diff --git a/interface/src/ui/PreferencesDialog.cpp b/interface/src/ui/PreferencesDialog.cpp new file mode 100644 index 0000000000..df3e94f31f --- /dev/null +++ b/interface/src/ui/PreferencesDialog.cpp @@ -0,0 +1,96 @@ +// +// PreferencesDialog.cpp +// hifi +// +// Created by Stojce Slavkovski on 2/22/14. +// +// + +#include "PreferencesDialog.h" +#include "Application.h" +#include "Menu.h" + +PreferencesDialog::PreferencesDialog(QWidget* parent, Qt::WindowFlags flags) : FramelessDialog(parent, flags) { + ui.setupUi(this); + setAttribute(Qt::WA_DeleteOnClose); + loadPreferences(); +} + +void PreferencesDialog::accept() { + savePreferences(); + close(); +} + +void PreferencesDialog::loadPreferences() { + + MyAvatar* myAvatar = Application::getInstance()->getAvatar(); + Menu* menuInstance = Menu::getInstance(); + + _displayNameString = myAvatar->getDisplayName(); + ui.displayNameEdit->setText(_displayNameString); + + _faceURLString = myAvatar->getHead()->getFaceModel().getURL().toString(); + ui.faceURLEdit->setText(_faceURLString); + + _skeletonURLString = myAvatar->getSkeletonModel().getURL().toString(); + ui.skeletonURLEdit->setText(_skeletonURLString); + + float pupilDilation = myAvatar->getHead()->getPupilDilation(); + ui.pupilDilationSlider->setValue(pupilDilation * ui.pupilDilationSlider->maximum()); + + ui.faceshiftEyeDeflectionSider->setValue(menuInstance->getFaceshiftEyeDeflection() * + ui.faceshiftEyeDeflectionSider->maximum()); + + ui.fieldOfViewSpin->setValue(menuInstance->getFieldOfView() * ui.fieldOfViewSpin->maximum()); + + ui.leanScaleSpin->setValue(myAvatar->getLeanScale()); + + ui.avatarScaleSpin->setValue(myAvatar->getScale()); + + ui.maxVoxelsSpin->setValue(menuInstance->getMaxVoxels()); + + ui.maxVoxelsPPSSpin->setValue(menuInstance->getMaxVoxelPacketsPerSecond()); +} + +void PreferencesDialog::savePreferences() { + + MyAvatar* myAvatar = Application::getInstance()->getAvatar(); + bool shouldDispatchIdentityPacket = false; + + QString displayNameStr(ui.displayNameEdit->text()); + if (displayNameStr != _displayNameString) { + myAvatar->setDisplayName(displayNameStr); + shouldDispatchIdentityPacket = true; + } + + QUrl faceModelURL(ui.faceURLEdit->text()); + if (faceModelURL.toString() != _faceURLString) { + // change the faceModelURL in the profile, it will also update this user's BlendFace + myAvatar->setFaceModelURL(faceModelURL); + shouldDispatchIdentityPacket = true; + } + + QUrl skeletonModelURL(ui.skeletonURLEdit->text()); + if (skeletonModelURL.toString() != _skeletonURLString) { + // change the skeletonModelURL in the profile, it will also update this user's Body + myAvatar->setSkeletonModelURL(skeletonModelURL); + shouldDispatchIdentityPacket = true; + } + + if (shouldDispatchIdentityPacket) { + myAvatar->sendIdentityPacket(); + } + + myAvatar->getHead()->setPupilDilation(ui.pupilDilationSlider->value() / (float)ui.pupilDilationSlider->maximum()); + Application::getInstance()->getVoxels()->setMaxVoxels(ui.maxVoxelsSpin->value()); + + + myAvatar->setLeanScale(ui.leanScaleSpin->value()); + myAvatar->setClampedTargetScale(ui.avatarScaleSpin->value()); + + Application::getInstance()->resizeGL(Application::getInstance()->getGLWidget()->width(), + Application::getInstance()->getGLWidget()->height()); + + // _maxVoxelPacketsPerSecond = maxVoxelsPPS->value(); + // _faceshiftEyeDeflection = faceshiftEyeDeflection->value() / (float)faceshiftEyeDeflection->maximum(); +} diff --git a/interface/src/ui/PreferencesDialog.h b/interface/src/ui/PreferencesDialog.h new file mode 100644 index 0000000000..d5cb41c7df --- /dev/null +++ b/interface/src/ui/PreferencesDialog.h @@ -0,0 +1,37 @@ +// +// PreferencesDialog.h +// hifi +// +// Created by Stojce Slavkovski on 2/22/14. +// +// + +#ifndef __hifi__PreferencesDialog__ +#define __hifi__PreferencesDialog__ + +#include "FramelessDialog.h" +#include "ui_preferencesDialog.h" + +#include + +class PreferencesDialog : public FramelessDialog { + Q_OBJECT + +public: + PreferencesDialog(QWidget* parent = 0, Qt::WindowFlags flags = 0); + +private: + Ui_PreferencesDialog ui; + void loadPreferences(); + void savePreferences(); + + QString _faceURLString; + QString _skeletonURLString; + QString _displayNameString; + +private slots: + void accept(); + +}; + +#endif /* defined(__hifi__PreferencesDialog__) */ diff --git a/interface/ui/preferencesDialog.ui b/interface/ui/preferencesDialog.ui new file mode 100644 index 0000000000..7c89eb15c9 --- /dev/null +++ b/interface/ui/preferencesDialog.ui @@ -0,0 +1,646 @@ + + + PreferencesDialog + + + + 0 + 0 + 611 + 745 + + + + + + 30 + 30 + 555 + 596 + + + + + + + + 23 + + + + color: #0e7077 + + + Avatar + + + faceURLEdit + + + + + + + + 0 + 0 + + + + color: #0e7077 + + + <html><head/><body><p>Avatar display name <span style=" color:#909090;">(optional)</span></p></body></html> + + + displayNameEdit + + + + + + + + 0 + 0 + + + + + 280 + 0 + + + + Qt::LeftToRight + + + + + + Not showing a name + + + + + + + color: #0e7077 + + + Head + + + faceURLEdit + + + + + + + + + + color: #0e7077 + + + Body + + + faceURLEdit + + + + + + + + + + + 23 + + + + color: #0e7077 + + + Advanced Tuning + + + + + + + It's not recomended that you play with these settings unless you've looked into exactly what they do. + + + false + + + true + + + + + + + + 20 + 50 + false + + + + color: #0e7077 + + + <p>Avatar</p> + + + + + + + + 0 + 0 + + + + background-color: #fff + + + + + 7 + 0 + 531 + 26 + + + + + + + Lean scale (applies to Faceshift users) + + + leanScaleSpin + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + + + + + + Vertical field of view + + + fieldOfViewSpin + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + 1 + + + 180 + + + + + + + + + + 0 + 0 + + + + background-color: #fff + + + + + 7 + 0 + 531 + 26 + + + + + + + Avatar scale (default is 1.0) + + + avatarScaleSpin + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + + + + + + Pupil dillation + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + 0 + 0 + + + + Qt::Horizontal + + + + + + + + + + 0 + 0 + + + + background-color: #fff + + + + + 7 + 0 + 531 + 26 + + + + + + + Faceshift eye detection + + + avatarScaleSpin + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + 0 + 0 + + + + Qt::Horizontal + + + + + + + + + + + + 20 + 50 + false + + + + color: #0e7077 + + + <html><head/><body><p>Voxels</p></body></html> + + + + + + + + 0 + 0 + + + + background-color: #fff + + + + + 7 + 0 + 531 + 26 + + + + + + + Maximum voxels + + + leanScaleSpin + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + 5000000 + + + 50000 + + + + + + + + + + + + 0 + 0 + + + + background-color: #fff + + + + + 7 + 0 + 531 + 26 + + + + + + + Max voxels sent each second + + + leanScaleSpin + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + 60 + + + 6000 + + + 10 + + + + + + + + + + + + + 0 + 665 + 616 + 80 + + + + background-color: #0e7077 + + + + + 0 + 20 + 591 + 41 + + + + + + + Qt::Horizontal + + + + 0 + 0 + + + + + + + + Cancel + + + + + + + background-color: #fff; +color: #0e7077 + + + Save all changes + + + true + + + + + + + + + + FramelessDialog + 1 + + + + displayNameEdit + faceURLEdit + leanScaleSpin + fieldOfViewSpin + avatarScaleSpin + pupilDilationSlider + + + + + cancelButton + clicked() + PreferencesDialog + close() + + + 372 + 700 + + + 528 + -9 + + + + + defaultButton + clicked() + PreferencesDialog + accept() + + + 20 + 20 + + + 20 + 20 + + + + +