diff --git a/interface/resources/sounds/snap.wav b/interface/resources/sounds/snap.wav new file mode 100644 index 0000000000..3e22124abf Binary files /dev/null and b/interface/resources/sounds/snap.wav differ diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 285a395c07..d4d9f5d949 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -47,6 +47,9 @@ #include #include #include +#include +#include + #include #include @@ -70,6 +73,7 @@ #include "renderer/ProgramObject.h" #include "ui/TextRenderer.h" #include "InfoView.h" +#include "ui/Snapshot.h" using namespace std; @@ -695,6 +699,7 @@ void Application::keyPressEvent(QKeyEvent* event) { bool isShifted = event->modifiers().testFlag(Qt::ShiftModifier); bool isMeta = event->modifiers().testFlag(Qt::ControlModifier); + bool isControl = event->modifiers().testFlag(Qt::MetaModifier); switch (event->key()) { break; case Qt::Key_Shift: @@ -773,6 +778,8 @@ void Application::keyPressEvent(QKeyEvent* event) { _voxels.collectStatsForTreesAndVBOs(); } else if (isShifted && isMeta) { Menu::getInstance()->triggerOption(MenuOption::SuppressShortTimings); + } else if (!isShifted && !isMeta && isControl) { + takeSnapshot(); } else if (_nudgeStarted) { if (_lookingAlongX) { if (_lookingAwayFromOrigin) { @@ -4341,3 +4348,14 @@ void Application::skipVersion(QString latestVersion) { skipFile.seek(0); skipFile.write(latestVersion.toStdString().c_str()); } + +void Application::takeSnapshot() { + switchToResourcesParentIfRequired(); + QMediaPlayer* player = new QMediaPlayer(); + QFileInfo inf = QFileInfo("resources/sounds/snap.wav"); + player->setMedia(QUrl::fromLocalFile(inf.absoluteFilePath())); + player->play(); + + Snapshot::saveSnapshot(_glWidget, _profile.getUsername(), _myAvatar.getPosition()); +} + diff --git a/interface/src/Application.h b/interface/src/Application.h index c3404b4035..21aa26bd47 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -505,6 +505,7 @@ private: void checkVersion(); void displayUpdateDialog(); bool shouldSkipVersion(QString latestVersion); + void takeSnapshot(); }; #endif /* defined(__interface__Application__) */ diff --git a/interface/src/FileLogger.cpp b/interface/src/FileLogger.cpp index 4c96dfcfa5..3c98b285a3 100644 --- a/interface/src/FileLogger.cpp +++ b/interface/src/FileLogger.cpp @@ -14,17 +14,17 @@ #include #include +const QString FILENAME_FORMAT = "hifi-log_%1_%2.txt"; +const QString DATETIME_FORMAT = "yyyy-MM-dd_hh.mm.ss"; +const QString LOGS_DIRECTORY = "Logs"; + FileLogger::FileLogger() : _logData(NULL) { setExtraDebugging(false); - _fileName = QStandardPaths::writableLocation(QStandardPaths::DataLocation); - QDir logDir(_fileName); - if (!logDir.exists(_fileName)) { - logDir.mkdir(_fileName); - } + _fileName = FileUtils::standardPath(LOGS_DIRECTORY); QHostAddress clientAddress = QHostAddress(getHostOrderLocalAddress()); QDateTime now = QDateTime::currentDateTime(); - _fileName.append(QString("/hifi-log_%1_%2.txt").arg(clientAddress.toString(), now.toString("yyyy-MM-dd_hh.mm.ss"))); + _fileName.append(QString(FILENAME_FORMAT).arg(clientAddress.toString(), now.toString(DATETIME_FORMAT))); } void FileLogger::addMessage(QString message) { @@ -40,5 +40,5 @@ void FileLogger::addMessage(QString message) { } void FileLogger::locateLog() { - FileUtils::LocateFile(_fileName); + FileUtils::locateFile(_fileName); } diff --git a/interface/src/ui/Snapshot.cpp b/interface/src/ui/Snapshot.cpp new file mode 100644 index 0000000000..b024890d12 --- /dev/null +++ b/interface/src/ui/Snapshot.cpp @@ -0,0 +1,38 @@ +// +// Snapshot.cpp +// hifi +// +// Created by Stojce Slavkovski on 1/26/14. +// +// + +#include "Snapshot.h" + +#include + +#include +#include + +// filename format: hifi-snap_username_current-coordinates_date_time-with-seconds.jpg +// %1 <= username, %2 <= current location, %3 <= date and time +const QString FILENAME_PATH_FORMAT = "hifi-snap_%1_%2_%3.jpg"; +const QString DATETIME_FORMAT = "yyyy-MM-dd_hh.mm.ss"; +const QString SNAPSHOTS_DIRECTORY = "Snapshots"; + +void Snapshot::saveSnapshot(QGLWidget* widget, QString username, glm::vec3 location) { + QImage shot = widget->grabFrameBuffer(); + + // add metadata + shot.setText("location-x", QString::number(location.x)); + shot.setText("location-y", QString::number(location.y)); + shot.setText("location-z", QString::number(location.z)); + + QString formattedLocation = QString("%1-%2-%3").arg(location.x).arg(location.y).arg(location.z); + QDateTime now = QDateTime::currentDateTime(); + + QString fileName = FileUtils::standardPath(SNAPSHOTS_DIRECTORY); + fileName.append(QString(FILENAME_PATH_FORMAT.arg(username, formattedLocation, now.toString(DATETIME_FORMAT)))); + shot.save(fileName); +} + + diff --git a/interface/src/ui/Snapshot.h b/interface/src/ui/Snapshot.h new file mode 100644 index 0000000000..39548cdff8 --- /dev/null +++ b/interface/src/ui/Snapshot.h @@ -0,0 +1,27 @@ +// +// Snapshot.h +// hifi +// +// Created by Stojce Slavkovski on 1/26/14. +// Copyright (c) 2014 High Fidelity, Inc. All rights reserved. +// + +#ifndef __hifi__Snapshot__ +#define __hifi__Snapshot__ + +#import +#import +#import + +#include + +class Snapshot { + +public: + static void saveSnapshot(QGLWidget* widget, QString username, glm::vec3 location); + +private: + QString _username; +}; + +#endif /* defined(__hifi__Snapshot__) */ diff --git a/libraries/shared/src/FileUtils.cpp b/libraries/shared/src/FileUtils.cpp index b58799104f..efbe1a189b 100644 --- a/libraries/shared/src/FileUtils.cpp +++ b/libraries/shared/src/FileUtils.cpp @@ -10,9 +10,9 @@ #include #include -void FileUtils::LocateFile(QString filePath) { +void FileUtils::locateFile(QString filePath) { - // adopted from + // adapted from // http://stackoverflow.com/questions/3490336/how-to-reveal-in-finder-or-show-in-explorer-with-qt // and // http://lynxline.com/show-in-finder-show-in-explorer/ @@ -54,3 +54,26 @@ void FileUtils::LocateFile(QString filePath) { QDesktopServices::openUrl(QUrl::fromLocalFile(folder)); } } + +QString FileUtils::standardPath(QString subfolder) { + // standard path + // Mac: ~/Library/Application Support/Interface + QString path = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation); + path.append("/Interface"); + + if (!subfolder.startsWith("/")) { + subfolder.prepend("/"); + } + + if (!subfolder.endsWith("/")) { + subfolder.append("/"); + } + + path.append(subfolder); + QDir logDir(path); + if (!logDir.exists(path)) { + logDir.mkpath(path); + } + + return path; +} diff --git a/libraries/shared/src/FileUtils.h b/libraries/shared/src/FileUtils.h index a725e72ca1..dd4605218e 100644 --- a/libraries/shared/src/FileUtils.h +++ b/libraries/shared/src/FileUtils.h @@ -14,7 +14,8 @@ class FileUtils { public: - static void LocateFile(QString); + static void locateFile(QString fileName); + static QString standardPath(QString subfolder); };