mirror of
https://github.com/overte-org/overte.git
synced 2025-04-25 23:36:41 +02:00
Merge branch 'master' of https://github.com/worklist/hifi into particle_meshes
This commit is contained in:
commit
1681dbb57b
11 changed files with 192 additions and 52 deletions
BIN
interface/resources/sounds/snap.wav
Normal file
BIN
interface/resources/sounds/snap.wav
Normal file
Binary file not shown.
|
@ -47,6 +47,7 @@
|
||||||
#include <QDesktopServices>
|
#include <QDesktopServices>
|
||||||
#include <QXmlStreamReader>
|
#include <QXmlStreamReader>
|
||||||
#include <QXmlStreamAttributes>
|
#include <QXmlStreamAttributes>
|
||||||
|
#include <QMediaPlayer>
|
||||||
|
|
||||||
#include <AudioInjector.h>
|
#include <AudioInjector.h>
|
||||||
#include <NodeTypes.h>
|
#include <NodeTypes.h>
|
||||||
|
@ -70,6 +71,7 @@
|
||||||
#include "renderer/ProgramObject.h"
|
#include "renderer/ProgramObject.h"
|
||||||
#include "ui/TextRenderer.h"
|
#include "ui/TextRenderer.h"
|
||||||
#include "InfoView.h"
|
#include "InfoView.h"
|
||||||
|
#include "ui/Snapshot.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
|
@ -775,6 +777,8 @@ void Application::keyPressEvent(QKeyEvent* event) {
|
||||||
_voxels.collectStatsForTreesAndVBOs();
|
_voxels.collectStatsForTreesAndVBOs();
|
||||||
} else if (isShifted && isMeta) {
|
} else if (isShifted && isMeta) {
|
||||||
Menu::getInstance()->triggerOption(MenuOption::SuppressShortTimings);
|
Menu::getInstance()->triggerOption(MenuOption::SuppressShortTimings);
|
||||||
|
} else if (!isShifted && isMeta) {
|
||||||
|
takeSnapshot();
|
||||||
} else if (_nudgeStarted) {
|
} else if (_nudgeStarted) {
|
||||||
if (_lookingAlongX) {
|
if (_lookingAlongX) {
|
||||||
if (_lookingAwayFromOrigin) {
|
if (_lookingAwayFromOrigin) {
|
||||||
|
@ -4343,3 +4347,14 @@ void Application::skipVersion(QString latestVersion) {
|
||||||
skipFile.seek(0);
|
skipFile.seek(0);
|
||||||
skipFile.write(latestVersion.toStdString().c_str());
|
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());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -505,6 +505,7 @@ private:
|
||||||
void checkVersion();
|
void checkVersion();
|
||||||
void displayUpdateDialog();
|
void displayUpdateDialog();
|
||||||
bool shouldSkipVersion(QString latestVersion);
|
bool shouldSkipVersion(QString latestVersion);
|
||||||
|
void takeSnapshot();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* defined(__interface__Application__) */
|
#endif /* defined(__interface__Application__) */
|
||||||
|
|
|
@ -14,17 +14,17 @@
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include <QDesktopServices>
|
#include <QDesktopServices>
|
||||||
|
|
||||||
|
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) {
|
FileLogger::FileLogger() : _logData(NULL) {
|
||||||
setExtraDebugging(false);
|
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());
|
QHostAddress clientAddress = QHostAddress(getHostOrderLocalAddress());
|
||||||
QDateTime now = QDateTime::currentDateTime();
|
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) {
|
void FileLogger::addMessage(QString message) {
|
||||||
|
@ -40,5 +40,5 @@ void FileLogger::addMessage(QString message) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void FileLogger::locateLog() {
|
void FileLogger::locateLog() {
|
||||||
FileUtils::LocateFile(_fileName);
|
FileUtils::locateFile(_fileName);
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,6 @@
|
||||||
#include <QStandardPaths>
|
#include <QStandardPaths>
|
||||||
#include <QGridLayout>
|
#include <QGridLayout>
|
||||||
#include <QSplitter>
|
#include <QSplitter>
|
||||||
#include <QApplication>
|
|
||||||
#include <QJsonDocument>
|
#include <QJsonDocument>
|
||||||
#include <QJsonArray>
|
#include <QJsonArray>
|
||||||
#include <QJsonObject>
|
#include <QJsonObject>
|
||||||
|
@ -20,38 +19,38 @@ const QString IMPORT_BUTTON_NAME = QObject::tr("Import");
|
||||||
const QString IMPORT_INFO = QObject::tr("<b>Import</b> %1 as voxels");
|
const QString IMPORT_INFO = QObject::tr("<b>Import</b> %1 as voxels");
|
||||||
const QString CANCEL_BUTTON_NAME = QObject::tr("Cancel");
|
const QString CANCEL_BUTTON_NAME = QObject::tr("Cancel");
|
||||||
const QString INFO_LABEL_TEXT = QObject::tr("<div style='line-height:20px;'>"
|
const QString INFO_LABEL_TEXT = QObject::tr("<div style='line-height:20px;'>"
|
||||||
"This will load the selected file into Hifi and allow you<br/>"
|
"This will load the selected file into Hifi and allow you<br/>"
|
||||||
"to place it with %1-V; you must be in select or<br/>"
|
"to place it with %1-V; you must be in select or<br/>"
|
||||||
"add mode (S or V keys will toggle mode) to place.</div>");
|
"add mode (S or V keys will toggle mode) to place.</div>");
|
||||||
|
|
||||||
const QString DESKTOP_LOCATION = QStandardPaths::writableLocation(QStandardPaths::DesktopLocation);
|
const QString DESKTOP_LOCATION = QStandardPaths::writableLocation(QStandardPaths::DesktopLocation);
|
||||||
const int SHORT_FILE_EXTENSION = 4;
|
const int SHORT_FILE_EXTENSION = 4;
|
||||||
const int SECOND_INDEX_LETTER = 1;
|
const int SECOND_INDEX_LETTER = 1;
|
||||||
|
|
||||||
QIcon HiFiIconProvider::icon(QFileIconProvider::IconType type) const {
|
QIcon HiFiIconProvider::icon(QFileIconProvider::IconType type) const {
|
||||||
|
|
||||||
switchToResourcesParentIfRequired();
|
switchToResourcesParentIfRequired();
|
||||||
|
|
||||||
// types
|
// types
|
||||||
// Computer, Desktop, Trashcan, Network, Drive, Folder, File
|
// Computer, Desktop, Trashcan, Network, Drive, Folder, File
|
||||||
QString typeString;
|
QString typeString;
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case QFileIconProvider::Computer:
|
case QFileIconProvider::Computer:
|
||||||
typeString = "computer";
|
typeString = "computer";
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case QFileIconProvider::Desktop:
|
case QFileIconProvider::Desktop:
|
||||||
typeString = "desktop";
|
typeString = "desktop";
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case QFileIconProvider::Trashcan:
|
case QFileIconProvider::Trashcan:
|
||||||
case QFileIconProvider::Network:
|
case QFileIconProvider::Network:
|
||||||
case QFileIconProvider::Drive:
|
case QFileIconProvider::Drive:
|
||||||
case QFileIconProvider::Folder:
|
case QFileIconProvider::Folder:
|
||||||
typeString = "folder";
|
typeString = "folder";
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
typeString = "file";
|
typeString = "file";
|
||||||
break;
|
break;
|
||||||
|
@ -63,7 +62,7 @@ QIcon HiFiIconProvider::icon(QFileIconProvider::IconType type) const {
|
||||||
QIcon HiFiIconProvider::icon(const QFileInfo &info) const {
|
QIcon HiFiIconProvider::icon(const QFileInfo &info) const {
|
||||||
switchToResourcesParentIfRequired();
|
switchToResourcesParentIfRequired();
|
||||||
const QString ext = info.suffix().toLower();
|
const QString ext = info.suffix().toLower();
|
||||||
|
|
||||||
if (info.isDir()) {
|
if (info.isDir()) {
|
||||||
if (info.absoluteFilePath() == QDir::homePath()) {
|
if (info.absoluteFilePath() == QDir::homePath()) {
|
||||||
return QIcon("resources/icons/home.svg");
|
return QIcon("resources/icons/home.svg");
|
||||||
|
@ -74,12 +73,12 @@ QIcon HiFiIconProvider::icon(const QFileInfo &info) const {
|
||||||
}
|
}
|
||||||
return QIcon("resources/icons/folder.svg");
|
return QIcon("resources/icons/folder.svg");
|
||||||
}
|
}
|
||||||
|
|
||||||
QFileInfo iconFile("resources/icons/" + iconsMap[ext]);
|
QFileInfo iconFile("resources/icons/" + iconsMap[ext]);
|
||||||
if (iconFile.exists() && iconFile.isFile()) {
|
if (iconFile.exists() && iconFile.isFile()) {
|
||||||
return QIcon(iconFile.filePath());
|
return QIcon(iconFile.filePath());
|
||||||
}
|
}
|
||||||
|
|
||||||
return QIcon("resources/icons/file.svg");
|
return QIcon("resources/icons/file.svg");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -98,8 +97,9 @@ QString HiFiIconProvider::type(const QFileInfo &info) const {
|
||||||
ImportDialog::ImportDialog(QWidget* parent) :
|
ImportDialog::ImportDialog(QWidget* parent) :
|
||||||
QFileDialog(parent, WINDOW_NAME, DESKTOP_LOCATION, NULL),
|
QFileDialog(parent, WINDOW_NAME, DESKTOP_LOCATION, NULL),
|
||||||
_importButton(IMPORT_BUTTON_NAME, this),
|
_importButton(IMPORT_BUTTON_NAME, this),
|
||||||
_cancelButton(CANCEL_BUTTON_NAME, this) {
|
_cancelButton(CANCEL_BUTTON_NAME, this),
|
||||||
|
fileAccepted(false) {
|
||||||
|
|
||||||
setOption(QFileDialog::DontUseNativeDialog, true);
|
setOption(QFileDialog::DontUseNativeDialog, true);
|
||||||
setFileMode(QFileDialog::ExistingFile);
|
setFileMode(QFileDialog::ExistingFile);
|
||||||
setViewMode(QFileDialog::Detail);
|
setViewMode(QFileDialog::Detail);
|
||||||
|
@ -111,16 +111,18 @@ ImportDialog::ImportDialog(QWidget* parent) :
|
||||||
#endif
|
#endif
|
||||||
QLabel* infoLabel = new QLabel(QString(INFO_LABEL_TEXT).arg(cmdString));
|
QLabel* infoLabel = new QLabel(QString(INFO_LABEL_TEXT).arg(cmdString));
|
||||||
infoLabel->setObjectName("infoLabel");
|
infoLabel->setObjectName("infoLabel");
|
||||||
|
|
||||||
QGridLayout* gridLayout = (QGridLayout*) layout();
|
QGridLayout* gridLayout = (QGridLayout*) layout();
|
||||||
gridLayout->addWidget(infoLabel, 2, 0, 2, 1);
|
gridLayout->addWidget(infoLabel, 2, 0, 2, 1);
|
||||||
gridLayout->addWidget(&_cancelButton, 2, 1, 2, 1);
|
gridLayout->addWidget(&_cancelButton, 2, 1, 2, 1);
|
||||||
gridLayout->addWidget(&_importButton, 2, 2, 2, 1);
|
gridLayout->addWidget(&_importButton, 2, 2, 2, 1);
|
||||||
|
|
||||||
setImportTypes();
|
setImportTypes();
|
||||||
setLayout();
|
setLayout();
|
||||||
|
|
||||||
connect(&_importButton, SIGNAL(pressed()), SLOT(import()));
|
connect(&_importButton, SIGNAL(pressed()), SLOT(import()));
|
||||||
|
connect(this, SIGNAL(currentChanged(QString)), SLOT(saveCurrentFile(QString)));
|
||||||
|
|
||||||
connect(&_cancelButton, SIGNAL(pressed()), SLOT(close()));
|
connect(&_cancelButton, SIGNAL(pressed()), SLOT(close()));
|
||||||
connect(this, SIGNAL(currentChanged(QString)), SLOT(saveCurrentFile(QString)));
|
connect(this, SIGNAL(currentChanged(QString)), SLOT(saveCurrentFile(QString)));
|
||||||
}
|
}
|
||||||
|
@ -130,12 +132,22 @@ ImportDialog::~ImportDialog() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void ImportDialog::import() {
|
void ImportDialog::import() {
|
||||||
|
fileAccepted = true;
|
||||||
emit accepted();
|
emit accepted();
|
||||||
close();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ImportDialog::accept() {
|
void ImportDialog::accept() {
|
||||||
QFileDialog::accept();
|
// do nothing if import is not enable
|
||||||
|
if (!_importButton.isEnabled()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!fileAccepted) {
|
||||||
|
fileAccepted = true;
|
||||||
|
emit accepted();
|
||||||
|
} else {
|
||||||
|
QFileDialog::accept();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ImportDialog::reject() {
|
void ImportDialog::reject() {
|
||||||
|
@ -163,72 +175,72 @@ void ImportDialog::saveCurrentFile(QString filename) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void ImportDialog::setLayout() {
|
void ImportDialog::setLayout() {
|
||||||
|
|
||||||
// set ObjectName used in qss for styling
|
// set ObjectName used in qss for styling
|
||||||
_importButton.setObjectName("importButton");
|
_importButton.setObjectName("importButton");
|
||||||
_cancelButton.setObjectName("cancelButton");
|
_cancelButton.setObjectName("cancelButton");
|
||||||
|
|
||||||
// set fixed size
|
// set fixed size
|
||||||
_importButton.setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
|
_importButton.setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
|
||||||
_cancelButton.setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
|
_cancelButton.setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
|
||||||
|
|
||||||
// hide unused embedded widgets in QFileDialog
|
// hide unused embedded widgets in QFileDialog
|
||||||
QWidget* widget = findChild<QWidget*>("lookInCombo");
|
QWidget* widget = findChild<QWidget*>("lookInCombo");
|
||||||
widget->hide();
|
widget->hide();
|
||||||
|
|
||||||
widget = findChild<QWidget*>("backButton");
|
widget = findChild<QWidget*>("backButton");
|
||||||
widget->hide();
|
widget->hide();
|
||||||
|
|
||||||
widget = findChild<QWidget*>("forwardButton");
|
widget = findChild<QWidget*>("forwardButton");
|
||||||
widget->hide();
|
widget->hide();
|
||||||
|
|
||||||
widget = findChild<QWidget*>("toParentButton");
|
widget = findChild<QWidget*>("toParentButton");
|
||||||
widget->hide();
|
widget->hide();
|
||||||
|
|
||||||
widget = findChild<QWidget*>("newFolderButton");
|
widget = findChild<QWidget*>("newFolderButton");
|
||||||
widget->hide();
|
widget->hide();
|
||||||
|
|
||||||
widget = findChild<QWidget*>("listModeButton");
|
widget = findChild<QWidget*>("listModeButton");
|
||||||
widget->hide();
|
widget->hide();
|
||||||
|
|
||||||
widget = findChild<QWidget*>("detailModeButton");
|
widget = findChild<QWidget*>("detailModeButton");
|
||||||
widget->hide();
|
widget->hide();
|
||||||
|
|
||||||
widget = findChild<QWidget*>("fileNameEdit");
|
widget = findChild<QWidget*>("fileNameEdit");
|
||||||
widget->hide();
|
widget->hide();
|
||||||
|
|
||||||
widget = findChild<QWidget*>("fileTypeCombo");
|
widget = findChild<QWidget*>("fileTypeCombo");
|
||||||
widget->hide();
|
widget->hide();
|
||||||
|
|
||||||
widget = findChild<QWidget*>("fileTypeLabel");
|
widget = findChild<QWidget*>("fileTypeLabel");
|
||||||
widget->hide();
|
widget->hide();
|
||||||
|
|
||||||
widget = findChild<QWidget*>("fileNameLabel");
|
widget = findChild<QWidget*>("fileNameLabel");
|
||||||
widget->hide();
|
widget->hide();
|
||||||
|
|
||||||
widget = findChild<QWidget*>("buttonBox");
|
widget = findChild<QWidget*>("buttonBox");
|
||||||
widget->hide();
|
widget->hide();
|
||||||
|
|
||||||
QSplitter* splitter = findChild<QSplitter*>("splitter");
|
QSplitter* splitter = findChild<QSplitter*>("splitter");
|
||||||
splitter->setHandleWidth(0);
|
splitter->setHandleWidth(0);
|
||||||
|
|
||||||
// remove blue outline on Mac
|
// remove blue outline on Mac
|
||||||
widget = findChild<QWidget*>("sidebar");
|
widget = findChild<QWidget*>("sidebar");
|
||||||
widget->setAttribute(Qt::WA_MacShowFocusRect, false);
|
widget->setAttribute(Qt::WA_MacShowFocusRect, false);
|
||||||
|
|
||||||
widget = findChild<QWidget*>("treeView");
|
widget = findChild<QWidget*>("treeView");
|
||||||
widget->setAttribute(Qt::WA_MacShowFocusRect, false);
|
widget->setAttribute(Qt::WA_MacShowFocusRect, false);
|
||||||
|
|
||||||
// remove reference to treeView
|
// remove reference to treeView
|
||||||
widget = NULL;
|
widget = NULL;
|
||||||
widget->deleteLater();
|
widget->deleteLater();
|
||||||
|
|
||||||
switchToResourcesParentIfRequired();
|
switchToResourcesParentIfRequired();
|
||||||
QFile styleSheet("resources/styles/import_dialog.qss");
|
QFile styleSheet("resources/styles/import_dialog.qss");
|
||||||
if (styleSheet.open(QIODevice::ReadOnly)) {
|
if (styleSheet.open(QIODevice::ReadOnly)) {
|
||||||
setStyleSheet(styleSheet.readAll());
|
setStyleSheet(styleSheet.readAll());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ImportDialog::setImportTypes() {
|
void ImportDialog::setImportTypes() {
|
||||||
|
@ -251,7 +263,6 @@ void ImportDialog::setImportTypes() {
|
||||||
QJsonObject fileFormatObject = fileFormat.toObject();
|
QJsonObject fileFormatObject = fileFormat.toObject();
|
||||||
|
|
||||||
QString ext(fileFormatObject["extension"].toString());
|
QString ext(fileFormatObject["extension"].toString());
|
||||||
QString description(fileFormatObject.value("description").toString());
|
|
||||||
QString icon(fileFormatObject.value("icon").toString());
|
QString icon(fileFormatObject.value("icon").toString());
|
||||||
|
|
||||||
if (formatsCounter > 0) {
|
if (formatsCounter > 0) {
|
||||||
|
@ -273,7 +284,7 @@ void ImportDialog::setImportTypes() {
|
||||||
// set custom file icons
|
// set custom file icons
|
||||||
setIconProvider(new HiFiIconProvider(iconsMap));
|
setIconProvider(new HiFiIconProvider(iconsMap));
|
||||||
setNameFilter(importFormatsFilterList);
|
setNameFilter(importFormatsFilterList);
|
||||||
|
|
||||||
#ifdef Q_OS_MAC
|
#ifdef Q_OS_MAC
|
||||||
QString cmdString = ("Command");
|
QString cmdString = ("Command");
|
||||||
#else
|
#else
|
||||||
|
|
|
@ -56,6 +56,7 @@ private:
|
||||||
|
|
||||||
void setLayout();
|
void setLayout();
|
||||||
void setImportTypes();
|
void setImportTypes();
|
||||||
|
bool fileAccepted;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* defined(__hifi__ImportDialog__) */
|
#endif /* defined(__hifi__ImportDialog__) */
|
||||||
|
|
|
@ -102,7 +102,22 @@ int VoxelImporter::preImport() {
|
||||||
if (!QFileInfo(filename).isFile()) {
|
if (!QFileInfo(filename).isFile()) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_filename = filename;
|
||||||
|
|
||||||
|
if (_nextTask) {
|
||||||
|
delete _nextTask;
|
||||||
|
}
|
||||||
|
|
||||||
|
_nextTask = new ImportTask(_filename);
|
||||||
|
connect(_nextTask, SIGNAL(destroyed()), SLOT(launchTask()));
|
||||||
|
|
||||||
|
if (_currentTask != NULL) {
|
||||||
|
_voxelTree.cancelImport();
|
||||||
|
} else {
|
||||||
|
launchTask();
|
||||||
|
}
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
46
interface/src/ui/Snapshot.cpp
Normal file
46
interface/src/ui/Snapshot.cpp
Normal file
|
@ -0,0 +1,46 @@
|
||||||
|
//
|
||||||
|
// Snapshot.cpp
|
||||||
|
// hifi
|
||||||
|
//
|
||||||
|
// Created by Stojce Slavkovski on 1/26/14.
|
||||||
|
//
|
||||||
|
//
|
||||||
|
|
||||||
|
#include "Snapshot.h"
|
||||||
|
|
||||||
|
#include <FileUtils.h>
|
||||||
|
|
||||||
|
#include <QDateTime>
|
||||||
|
#include <QFileInfo>
|
||||||
|
#include <QDebug>
|
||||||
|
|
||||||
|
// filename format: hifi-snap-by-%username%-on-%date%_%time%_@-%location%.jpg
|
||||||
|
// %1 <= username, %2 <= date and time, %3 <= current location
|
||||||
|
const QString FILENAME_PATH_FORMAT = "hifi-snap-by-%1-on-%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);
|
||||||
|
// replace decimal . with '-'
|
||||||
|
formattedLocation.replace('.', '-');
|
||||||
|
|
||||||
|
// normalize username, replace all non alphanumeric with '-'
|
||||||
|
username.replace(QRegExp("[^A-Za-z0-9_]"), "-");
|
||||||
|
|
||||||
|
QDateTime now = QDateTime::currentDateTime();
|
||||||
|
|
||||||
|
QString fileName = FileUtils::standardPath(SNAPSHOTS_DIRECTORY);
|
||||||
|
fileName.append(QString(FILENAME_PATH_FORMAT.arg(username, now.toString(DATETIME_FORMAT), formattedLocation)));
|
||||||
|
shot.save(fileName, 0, 100);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
27
interface/src/ui/Snapshot.h
Normal file
27
interface/src/ui/Snapshot.h
Normal file
|
@ -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 <QString>
|
||||||
|
#import <QImage>
|
||||||
|
#import <QGLWidget>
|
||||||
|
|
||||||
|
#include <glm/glm.hpp>
|
||||||
|
|
||||||
|
class Snapshot {
|
||||||
|
|
||||||
|
public:
|
||||||
|
static void saveSnapshot(QGLWidget* widget, QString username, glm::vec3 location);
|
||||||
|
|
||||||
|
private:
|
||||||
|
QString _username;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif /* defined(__hifi__Snapshot__) */
|
|
@ -10,9 +10,9 @@
|
||||||
#include <QtCore>
|
#include <QtCore>
|
||||||
#include <QDesktopServices>
|
#include <QDesktopServices>
|
||||||
|
|
||||||
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
|
// http://stackoverflow.com/questions/3490336/how-to-reveal-in-finder-or-show-in-explorer-with-qt
|
||||||
// and
|
// and
|
||||||
// http://lynxline.com/show-in-finder-show-in-explorer/
|
// http://lynxline.com/show-in-finder-show-in-explorer/
|
||||||
|
@ -54,3 +54,26 @@ void FileUtils::LocateFile(QString filePath) {
|
||||||
QDesktopServices::openUrl(QUrl::fromLocalFile(folder));
|
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;
|
||||||
|
}
|
||||||
|
|
|
@ -14,7 +14,8 @@
|
||||||
class FileUtils {
|
class FileUtils {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static void LocateFile(QString);
|
static void locateFile(QString fileName);
|
||||||
|
static QString standardPath(QString subfolder);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue