From 1a3e6595c50507551864cc28545a225fffb094f2 Mon Sep 17 00:00:00 2001 From: Stojce Slavkovski Date: Tue, 15 Apr 2014 19:36:02 +0200 Subject: [PATCH 1/3] Allow users to set the destination of Snapshots --- interface/resources/styles/preferences.qss | 3 +- interface/src/Menu.cpp | 7 +- interface/src/Menu.h | 11 ++ interface/src/ui/PreferencesDialog.cpp | 18 +++ interface/src/ui/PreferencesDialog.h | 1 + interface/src/ui/Snapshot.cpp | 9 +- interface/ui/preferencesDialog.ui | 143 ++++++++++++++++++++- libraries/shared/src/FileUtils.cpp | 3 +- 8 files changed, 186 insertions(+), 9 deletions(-) diff --git a/interface/resources/styles/preferences.qss b/interface/resources/styles/preferences.qss index 643fd13a77..e678acd0c9 100644 --- a/interface/resources/styles/preferences.qss +++ b/interface/resources/styles/preferences.qss @@ -11,7 +11,8 @@ QLabel#advancedTuningLabel { } QPushButton#buttonBrowseHead, -QPushButton#buttonBrowseBody { +QPushButton#buttonBrowseBody, +QPushButton#buttonBrowseLocation { background-image: url(styles/search.svg); background-repeat: no-repeat; background-position: center center; diff --git a/interface/src/Menu.cpp b/interface/src/Menu.cpp index 272dc39eb3..c9a1087618 100644 --- a/interface/src/Menu.cpp +++ b/interface/src/Menu.cpp @@ -25,7 +25,6 @@ #include #include #include -#include #include #include @@ -87,7 +86,8 @@ Menu::Menu() : _fpsAverage(FIVE_SECONDS_OF_FRAMES), _fastFPSAverage(ONE_SECOND_OF_FRAMES), _loginAction(NULL), - _preferencesDialog(NULL) + _preferencesDialog(NULL), + _snapshotsLocation() { Application *appInstance = Application::getInstance(); @@ -416,6 +416,8 @@ void Menu::loadSettings(QSettings* settings) { _maxVoxelPacketsPerSecond = loadSetting(settings, "maxVoxelsPPS", DEFAULT_MAX_VOXEL_PPS); _voxelSizeScale = loadSetting(settings, "voxelSizeScale", DEFAULT_OCTREE_SIZE_SCALE); _boundaryLevelAdjust = loadSetting(settings, "boundaryLevelAdjust", 0); + _snapshotsLocation = settings->value("snapshotsLocation", + QStandardPaths::writableLocation(QStandardPaths::DesktopLocation)).toString(); settings->beginGroup("View Frustum Offset Camera"); // in case settings is corrupt or missing loadSetting() will check for NaN @@ -455,6 +457,7 @@ void Menu::saveSettings(QSettings* settings) { settings->setValue("maxVoxelsPPS", _maxVoxelPacketsPerSecond); settings->setValue("voxelSizeScale", _voxelSizeScale); settings->setValue("boundaryLevelAdjust", _boundaryLevelAdjust); + settings->setValue("snapshotsLocation", _snapshotsLocation); settings->beginGroup("View Frustum Offset Camera"); settings->setValue("viewFrustumOffsetYaw", _viewFrustumOffset.yaw); settings->setValue("viewFrustumOffsetPitch", _viewFrustumOffset.pitch); diff --git a/interface/src/Menu.h b/interface/src/Menu.h index e827e43014..2c39ea3b99 100644 --- a/interface/src/Menu.h +++ b/interface/src/Menu.h @@ -12,10 +12,12 @@ #ifndef hifi_Menu_h #define hifi_Menu_h +#include #include #include #include #include +#include #include #include @@ -79,6 +81,14 @@ public: void setFieldOfView(float fieldOfView) { _fieldOfView = fieldOfView; } float getFaceshiftEyeDeflection() const { return _faceshiftEyeDeflection; } void setFaceshiftEyeDeflection(float faceshiftEyeDeflection) { _faceshiftEyeDeflection = faceshiftEyeDeflection; } + QString getSnapshotsLocation() const { + if (_snapshotsLocation.isNull() || _snapshotsLocation.isEmpty() || QDir(_snapshotsLocation).exists() == false) { + return QStandardPaths::writableLocation(QStandardPaths::DesktopLocation); + } + return _snapshotsLocation; + } + void setSnapshotsLocation(QString snapshotsLocation) { _snapshotsLocation = snapshotsLocation; } + BandwidthDialog* getBandwidthDialog() const { return _bandwidthDialog; } FrustumDrawMode getFrustumDrawMode() const { return _frustumDrawMode; } ViewFrustumOffset getViewFrustumOffset() const { return _viewFrustumOffset; } @@ -229,6 +239,7 @@ private: QAction* _loginAction; QPointer _preferencesDialog; QAction* _chatAction; + QString _snapshotsLocation; }; namespace MenuOption { diff --git a/interface/src/ui/PreferencesDialog.cpp b/interface/src/ui/PreferencesDialog.cpp index a14e80e62f..36508e94d1 100644 --- a/interface/src/ui/PreferencesDialog.cpp +++ b/interface/src/ui/PreferencesDialog.cpp @@ -28,6 +28,7 @@ PreferencesDialog::PreferencesDialog(QWidget* parent, Qt::WindowFlags flags) : F connect(ui.buttonBrowseHead, &QPushButton::clicked, this, &PreferencesDialog::openHeadModelBrowser); connect(ui.buttonBrowseBody, &QPushButton::clicked, this, &PreferencesDialog::openBodyModelBrowser); + connect(ui.buttonBrowseLocation, &QPushButton::clicked, this, &PreferencesDialog::openSnapshotLocationBrowser); } void PreferencesDialog::accept() { @@ -59,6 +60,17 @@ void PreferencesDialog::openBodyModelBrowser() { modelBrowser.browse(); } +void PreferencesDialog::openSnapshotLocationBrowser() { + setWindowFlags(windowFlags() & ~Qt::WindowStaysOnTopHint); + QString dir = QFileDialog::getExistingDirectory(this, tr("Snapshots Location"), + QStandardPaths::writableLocation(QStandardPaths::DesktopLocation), + QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks); + if (!dir.isNull() && !dir.isEmpty()) { + ui.snapshotLocationEdit->setText(dir); + } + setWindowFlags(windowFlags() | Qt::WindowStaysOnTopHint); +} + void PreferencesDialog::resizeEvent(QResizeEvent *resizeEvent) { // keep buttons panel at the bottom @@ -94,6 +106,8 @@ void PreferencesDialog::loadPreferences() { _skeletonURLString = myAvatar->getSkeletonModel().getURL().toString(); ui.skeletonURLEdit->setText(_skeletonURLString); + ui.snapshotLocationEdit->setText(menuInstance->getSnapshotsLocation()); + ui.pupilDilationSlider->setValue(myAvatar->getHead()->getPupilDilation() * ui.pupilDilationSlider->maximum()); @@ -143,6 +157,10 @@ void PreferencesDialog::savePreferences() { Application::getInstance()->bumpSettings(); } + if (!ui.snapshotLocationEdit->text().isEmpty() && QDir(ui.snapshotLocationEdit->text()).exists()) { + Menu::getInstance()->setSnapshotsLocation(ui.snapshotLocationEdit->text()); + } + myAvatar->getHead()->setPupilDilation(ui.pupilDilationSlider->value() / (float)ui.pupilDilationSlider->maximum()); myAvatar->setLeanScale(ui.leanScaleSpin->value()); myAvatar->setClampedTargetScale(ui.avatarScaleSpin->value()); diff --git a/interface/src/ui/PreferencesDialog.h b/interface/src/ui/PreferencesDialog.h index c9514e584a..c52986cc5c 100644 --- a/interface/src/ui/PreferencesDialog.h +++ b/interface/src/ui/PreferencesDialog.h @@ -41,6 +41,7 @@ private slots: void accept(); void setHeadUrl(QString modelUrl); void setSkeletonUrl(QString modelUrl); + void openSnapshotLocationBrowser(); }; diff --git a/interface/src/ui/Snapshot.cpp b/interface/src/ui/Snapshot.cpp index 77b19373f4..29c2d3c90f 100644 --- a/interface/src/ui/Snapshot.cpp +++ b/interface/src/ui/Snapshot.cpp @@ -16,6 +16,7 @@ #include #include "Snapshot.h" +#include "Menu.h" // filename format: hifi-snap-by-%username%-on-%date%_%time%_@-%location%.jpg // %1 <= username, %2 <= date and time, %3 <= current location @@ -90,8 +91,12 @@ void Snapshot::saveSnapshot(QGLWidget* widget, Avatar* avatar) { username.replace(QRegExp("[^A-Za-z0-9_]"), "-"); QDateTime now = QDateTime::currentDateTime(); - - QString fileName = FileUtils::standardPath(SNAPSHOTS_DIRECTORY); + QString fileName = Menu::getInstance()->getSnapshotsLocation(); + + if (!fileName.endsWith(QDir::separator())) { + fileName.append(QDir::separator()); + } + fileName.append(QString(FILENAME_PATH_FORMAT.arg(username, now.toString(DATETIME_FORMAT), formattedLocation))); shot.save(fileName, 0, 100); } diff --git a/interface/ui/preferencesDialog.ui b/interface/ui/preferencesDialog.ui index a151a499c6..3ad824a35e 100644 --- a/interface/ui/preferencesDialog.ui +++ b/interface/ui/preferencesDialog.ui @@ -156,7 +156,7 @@ color: #0e7077 0 0 615 - 833 + 936 @@ -300,7 +300,7 @@ color: #0e7077 0 - faceURLEdit + snapshotLocationEdit @@ -476,6 +476,145 @@ color: #0e7077 + + + + + 0 + 0 + + + + + 0 + 40 + + + + + Arial + 20 + 50 + false + + + + color: #0e7077 + + + Snapshots + + + Qt::AlignBottom|Qt::AlignLeading|Qt::AlignLeft + + + + + + + + 0 + 0 + + + + + 0 + 30 + + + + + Arial + 16 + + + + color: #0e7077 + + + Snapshots location + + + Qt::AlignBottom|Qt::AlignLeading|Qt::AlignLeft + + + 0 + + + snapshotLocationEdit + + + + + + + + + + 0 + 0 + + + + + Arial + + + + + + + + Qt::Horizontal + + + QSizePolicy::Fixed + + + + 20 + 20 + + + + + + + + + 0 + 0 + + + + + 30 + 30 + + + + + 30 + 30 + + + + + + + + + + + 30 + 30 + + + + + + diff --git a/libraries/shared/src/FileUtils.cpp b/libraries/shared/src/FileUtils.cpp index b890717a66..fe79f6c527 100644 --- a/libraries/shared/src/FileUtils.cpp +++ b/libraries/shared/src/FileUtils.cpp @@ -61,8 +61,7 @@ void FileUtils::locateFile(QString filePath) { QString FileUtils::standardPath(QString subfolder) { // standard path // Mac: ~/Library/Application Support/Interface - QString path = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation); - path.append("/Interface"); + QString path = QStandardPaths::writableLocation(QStandardPaths::DataLocation); if (!subfolder.startsWith("/")) { subfolder.prepend("/"); From 05023a2585fbcab011065e6db8474d63a6c8d1b0 Mon Sep 17 00:00:00 2001 From: Stojce Slavkovski Date: Tue, 15 Apr 2014 23:29:28 +0200 Subject: [PATCH 2/3] Snapshot preferences title --- interface/ui/preferencesDialog.ui | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interface/ui/preferencesDialog.ui b/interface/ui/preferencesDialog.ui index 3ad824a35e..278e3c5dab 100644 --- a/interface/ui/preferencesDialog.ui +++ b/interface/ui/preferencesDialog.ui @@ -533,7 +533,7 @@ color: #0e7077 color: #0e7077 - Snapshots location + Place my Snapshots here: Qt::AlignBottom|Qt::AlignLeading|Qt::AlignLeft From c67e42be5e0087e9d142b2c19fc5bcdb56bdd403 Mon Sep 17 00:00:00 2001 From: Stojce Slavkovski Date: Wed, 16 Apr 2014 07:46:15 +0200 Subject: [PATCH 3/3] Moved function into .cpp --- interface/src/Menu.cpp | 7 +++++++ interface/src/Menu.h | 7 +------ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/interface/src/Menu.cpp b/interface/src/Menu.cpp index c9a1087618..e4de93c9bf 100644 --- a/interface/src/Menu.cpp +++ b/interface/src/Menu.cpp @@ -1505,3 +1505,10 @@ void Menu::removeMenuItem(const QString& menu, const QString& menuitem) { QMenuBar::repaint(); }; +QString Menu::getSnapshotsLocation() const { + if (_snapshotsLocation.isNull() || _snapshotsLocation.isEmpty() || QDir(_snapshotsLocation).exists() == false) { + return QStandardPaths::writableLocation(QStandardPaths::DesktopLocation); + } + return _snapshotsLocation; +} + diff --git a/interface/src/Menu.h b/interface/src/Menu.h index 2c39ea3b99..45291802cb 100644 --- a/interface/src/Menu.h +++ b/interface/src/Menu.h @@ -81,12 +81,7 @@ public: void setFieldOfView(float fieldOfView) { _fieldOfView = fieldOfView; } float getFaceshiftEyeDeflection() const { return _faceshiftEyeDeflection; } void setFaceshiftEyeDeflection(float faceshiftEyeDeflection) { _faceshiftEyeDeflection = faceshiftEyeDeflection; } - QString getSnapshotsLocation() const { - if (_snapshotsLocation.isNull() || _snapshotsLocation.isEmpty() || QDir(_snapshotsLocation).exists() == false) { - return QStandardPaths::writableLocation(QStandardPaths::DesktopLocation); - } - return _snapshotsLocation; - } + QString getSnapshotsLocation() const; void setSnapshotsLocation(QString snapshotsLocation) { _snapshotsLocation = snapshotsLocation; } BandwidthDialog* getBandwidthDialog() const { return _bandwidthDialog; }