Allow users to set the destination of Snapshots

This commit is contained in:
Stojce Slavkovski 2014-04-15 19:36:02 +02:00
parent f61d72fcf0
commit 1a3e6595c5
8 changed files with 186 additions and 9 deletions

View file

@ -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;

View file

@ -25,7 +25,6 @@
#include <QMessageBox>
#include <QShortcut>
#include <QSlider>
#include <QStandardPaths>
#include <QUuid>
#include <QHBoxLayout>
@ -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);

View file

@ -12,10 +12,12 @@
#ifndef hifi_Menu_h
#define hifi_Menu_h
#include <QDir>
#include <QMenuBar>
#include <QHash>
#include <QKeySequence>
#include <QPointer>
#include <QStandardPaths>
#include <EventTypes.h>
#include <MenuItemProperties.h>
@ -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> _preferencesDialog;
QAction* _chatAction;
QString _snapshotsLocation;
};
namespace MenuOption {

View file

@ -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());

View file

@ -41,6 +41,7 @@ private slots:
void accept();
void setHeadUrl(QString modelUrl);
void setSkeletonUrl(QString modelUrl);
void openSnapshotLocationBrowser();
};

View file

@ -16,6 +16,7 @@
#include <FileUtils.h>
#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);
}

View file

@ -156,7 +156,7 @@ color: #0e7077</string>
<x>0</x>
<y>0</y>
<width>615</width>
<height>833</height>
<height>936</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
@ -300,7 +300,7 @@ color: #0e7077</string>
<number>0</number>
</property>
<property name="buddy">
<cstring>faceURLEdit</cstring>
<cstring>snapshotLocationEdit</cstring>
</property>
</widget>
</item>
@ -476,6 +476,145 @@ color: #0e7077</string>
</item>
</layout>
</item>
<item>
<widget class="QLabel" name="avatarTitleLabel_2">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>40</height>
</size>
</property>
<property name="font">
<font>
<family>Arial</family>
<pointsize>20</pointsize>
<weight>50</weight>
<bold>false</bold>
</font>
</property>
<property name="styleSheet">
<string notr="true">color: #0e7077</string>
</property>
<property name="text">
<string>Snapshots</string>
</property>
<property name="alignment">
<set>Qt::AlignBottom|Qt::AlignLeading|Qt::AlignLeft</set>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="headLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>30</height>
</size>
</property>
<property name="font">
<font>
<family>Arial</family>
<pointsize>16</pointsize>
</font>
</property>
<property name="styleSheet">
<string notr="true">color: #0e7077</string>
</property>
<property name="text">
<string>Snapshots location</string>
</property>
<property name="alignment">
<set>Qt::AlignBottom|Qt::AlignLeading|Qt::AlignLeft</set>
</property>
<property name="margin">
<number>0</number>
</property>
<property name="buddy">
<cstring>snapshotLocationEdit</cstring>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLineEdit" name="snapshotLocationEdit">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="font">
<font>
<family>Arial</family>
</font>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="buttonBrowseLocation">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>30</width>
<height>30</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>30</width>
<height>30</height>
</size>
</property>
<property name="styleSheet">
<string notr="true"/>
</property>
<property name="text">
<string/>
</property>
<property name="iconSize">
<size>
<width>30</width>
<height>30</height>
</size>
</property>
</widget>
</item>
</layout>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">

View file

@ -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("/");