Fixed snapshot bug. Snapshots now save and load ok

This commit is contained in:
Niraj Venkat 2015-06-03 14:29:39 -07:00
parent faf9120b10
commit 57004c61c7
5 changed files with 73 additions and 50 deletions

View file

@ -1696,12 +1696,9 @@ bool Application::acceptSnapshot(const QString& urlString) {
SnapshotMetaData* snapshotData = Snapshot::parseSnapshotData(snapshotPath); SnapshotMetaData* snapshotData = Snapshot::parseSnapshotData(snapshotPath);
if (snapshotData) { if (snapshotData) {
if (!snapshotData->getDomain().isEmpty()) { if (!snapshotData->getURL().toString().isEmpty()) {
DependencyManager::get<NodeList>()->getDomainHandler().setHostnameAndPort(snapshotData->getDomain()); DependencyManager::get<AddressManager>()->handleLookupString(snapshotData->getURL().toString());
} }
_myAvatar->setPosition(snapshotData->getLocation());
_myAvatar->setOrientation(snapshotData->getOrientation());
} else { } else {
QMessageBox msgBox; QMessageBox msgBox;
msgBox.setText("No location details were found in the file " msgBox.setText("No location details were found in the file "
@ -3452,6 +3449,10 @@ void Application::displaySide(Camera& theCamera, bool selfAvatarOnly, bool billb
Glower glower; // Sets alpha to 1.0 Glower glower; // Sets alpha to 1.0
_overlays.renderWorld(true); _overlays.renderWorld(true);
} }
activeRenderingThread = nullptr; activeRenderingThread = nullptr;
} }

View file

@ -17,6 +17,9 @@
#include <QShowEvent> #include <QShowEvent>
#include <QHideEvent> #include <QHideEvent>
#include <QWindowStateChangeEvent> #include <QWindowStateChangeEvent>
#include <QDragEnterEvent>
#include <QDropEvent>
#include <QMimeData>
#include "MainWindow.h" #include "MainWindow.h"
#include "Menu.h" #include "Menu.h"
@ -27,6 +30,7 @@ MainWindow::MainWindow(QWidget* parent) :
_windowGeometry("WindowGeometry"), _windowGeometry("WindowGeometry"),
_windowState("WindowState", 0) _windowState("WindowState", 0)
{ {
setAcceptDrops(true);
} }
void MainWindow::restoreGeometry() { void MainWindow::restoreGeometry() {
@ -106,3 +110,20 @@ void MainWindow::changeEvent(QEvent* event) {
} }
QMainWindow::changeEvent(event); QMainWindow::changeEvent(event);
} }
void MainWindow::dragEnterEvent(QDragEnterEvent* event)
{
if (event->mimeData())
event->acceptProposedAction();
}
void MainWindow::dropEvent(QDropEvent* event)
{
/*QList<QUrl> urls = event->mimeData()->urls();
foreach(QUrl url, urls)
{
qDebug() << "urlmessage" << url.toString();
}*/
QCoreApplication::sendEvent(QCoreApplication::instance(), event);
}

View file

@ -36,6 +36,8 @@ protected:
virtual void showEvent(QShowEvent* event); virtual void showEvent(QShowEvent* event);
virtual void hideEvent(QHideEvent* event); virtual void hideEvent(QHideEvent* event);
virtual void changeEvent(QEvent* event); virtual void changeEvent(QEvent* event);
virtual void dragEnterEvent(QDragEnterEvent *e);
virtual void dropEvent(QDropEvent *e);
private: private:
Setting::Handle<QRect> _windowGeometry; Setting::Handle<QRect> _windowGeometry;

View file

@ -15,8 +15,10 @@
#include <QFileInfo> #include <QFileInfo>
#include <QImage> #include <QImage>
#include <QTemporaryFile> #include <QTemporaryFile>
#include <QUrl>
#include <AccountManager.h> #include <AccountManager.h>
#include <AddressManager.h>
#include <avatar/AvatarManager.h> #include <avatar/AvatarManager.h>
#include <avatar/MyAvatar.h> #include <avatar/MyAvatar.h>
#include <FileUtils.h> #include <FileUtils.h>
@ -28,7 +30,7 @@
// filename format: hifi-snap-by-%username%-on-%date%_%time%_@-%location%.jpg // filename format: hifi-snap-by-%username%-on-%date%_%time%_@-%location%.jpg
// %1 <= username, %2 <= date and time, %3 <= current location // %1 <= username, %2 <= date and time, %3 <= current location
const QString FILENAME_PATH_FORMAT = "hifi-snap-by-%1-on-%2@%3.jpg"; const QString FILENAME_PATH_FORMAT = "hifi-snap-by-%1-on-%2.jpg";
const QString DATETIME_FORMAT = "yyyy-MM-dd_hh-mm-ss"; const QString DATETIME_FORMAT = "yyyy-MM-dd_hh-mm-ss";
const QString SNAPSHOTS_DIRECTORY = "Snapshots"; const QString SNAPSHOTS_DIRECTORY = "Snapshots";
@ -42,8 +44,12 @@ const QString ORIENTATION_Y = "orientation-y";
const QString ORIENTATION_Z = "orientation-z"; const QString ORIENTATION_Z = "orientation-z";
const QString ORIENTATION_W = "orientation-w"; const QString ORIENTATION_W = "orientation-w";
const QString PATH = "path";
const QString DOMAIN_KEY = "domain"; const QString DOMAIN_KEY = "domain";
const QString URL = "url";
Setting::Handle<QString> Snapshot::snapshotsLocation("snapshotsLocation", Setting::Handle<QString> Snapshot::snapshotsLocation("snapshotsLocation",
QStandardPaths::writableLocation(QStandardPaths::DesktopLocation)); QStandardPaths::writableLocation(QStandardPaths::DesktopLocation));
@ -56,22 +62,16 @@ SnapshotMetaData* Snapshot::parseSnapshotData(QString snapshotPath) {
QImage shot(snapshotPath); QImage shot(snapshotPath);
// no location data stored // no location data stored
if (shot.text(LOCATION_X).isEmpty() || shot.text(LOCATION_Y).isEmpty() || shot.text(LOCATION_Z).isEmpty()) { if (shot.text(URL).isEmpty()) {
return NULL; return NULL;
} }
// parsing URL
QUrl url = QUrl(shot.text(URL), QUrl::ParsingMode::StrictMode);
SnapshotMetaData* data = new SnapshotMetaData(); SnapshotMetaData* data = new SnapshotMetaData();
data->setLocation(glm::vec3(shot.text(LOCATION_X).toFloat(), data->setURL(url);
shot.text(LOCATION_Y).toFloat(),
shot.text(LOCATION_Z).toFloat()));
data->setOrientation(glm::quat(shot.text(ORIENTATION_W).toFloat(),
shot.text(ORIENTATION_X).toFloat(),
shot.text(ORIENTATION_Y).toFloat(),
shot.text(ORIENTATION_Z).toFloat()));
data->setDomain(shot.text(DOMAIN_KEY));
return data; return data;
} }
@ -82,7 +82,7 @@ QString Snapshot::saveSnapshot(QImage image) {
snapshotFile->close(); snapshotFile->close();
QString snapshotPath = QFileInfo(*snapshotFile).absoluteFilePath(); QString snapshotPath = QFileInfo(*snapshotFile).absoluteFilePath();
delete snapshotFile; delete snapshotFile;
return snapshotPath; return snapshotPath;
@ -90,29 +90,35 @@ QString Snapshot::saveSnapshot(QImage image) {
QTemporaryFile* Snapshot::saveTempSnapshot(QImage image) { QTemporaryFile* Snapshot::saveTempSnapshot(QImage image) {
// return whatever we get back from saved file for snapshot // return whatever we get back from saved file for snapshot
return static_cast<QTemporaryFile*>(savedFileForSnapshot(image, true));; return static_cast<QTemporaryFile*>(savedFileForSnapshot(image, true));
} }
QFile* Snapshot::savedFileForSnapshot(QImage & shot, bool isTemporary) { QFile* Snapshot::savedFileForSnapshot(QImage & shot, bool isTemporary) {
Avatar* avatar = DependencyManager::get<AvatarManager>()->getMyAvatar(); //Avatar* avatar = DependencyManager::get<AvatarManager>()->getMyAvatar();
//
glm::vec3 location = avatar->getPosition(); //glm::vec3 location = avatar->getPosition();
glm::quat orientation = avatar->getHead()->getOrientation(); //glm::quat orientation = avatar->getHead()->getOrientation();
//
// add metadata //// add metadata
shot.setText(LOCATION_X, QString::number(location.x)); //shot.setText(LOCATION_X, QString::number(location.x));
shot.setText(LOCATION_Y, QString::number(location.y)); //shot.setText(LOCATION_Y, QString::number(location.y));
shot.setText(LOCATION_Z, QString::number(location.z)); //shot.setText(LOCATION_Z, QString::number(location.z));
//
shot.setText(ORIENTATION_X, QString::number(orientation.x)); //shot.setText(ORIENTATION_X, QString::number(orientation.x));
shot.setText(ORIENTATION_Y, QString::number(orientation.y)); //shot.setText(ORIENTATION_Y, QString::number(orientation.y));
shot.setText(ORIENTATION_Z, QString::number(orientation.z)); //shot.setText(ORIENTATION_Z, QString::number(orientation.z));
shot.setText(ORIENTATION_W, QString::number(orientation.w)); //shot.setText(ORIENTATION_W, QString::number(orientation.w));
//
shot.setText(DOMAIN_KEY, DependencyManager::get<NodeList>()->getDomainHandler().getHostname()); //shot.setText(DOMAIN_KEY, DependencyManager::get<NodeList>()->getDomainHandler().getHostname());
//
//shot.setText(PATH, QString::number());
QString formattedLocation = QString("%1_%2_%3").arg(location.x).arg(location.y).arg(location.z); // adding URL to snapshot
QUrl currentURL = DependencyManager::get<AddressManager>()->currentAddress();
shot.setText(URL, currentURL.toString());
QString formattedLocation = QString(currentURL.toString());
// replace decimal . with '-' // replace decimal . with '-'
formattedLocation.replace('.', '-'); formattedLocation.replace('.', '-');
@ -122,7 +128,7 @@ QFile* Snapshot::savedFileForSnapshot(QImage & shot, bool isTemporary) {
QDateTime now = QDateTime::currentDateTime(); QDateTime now = QDateTime::currentDateTime();
QString filename = FILENAME_PATH_FORMAT.arg(username, now.toString(DATETIME_FORMAT), formattedLocation); QString filename = FILENAME_PATH_FORMAT.arg(username, now.toString(DATETIME_FORMAT));
const int IMAGE_QUALITY = 100; const int IMAGE_QUALITY = 100;
@ -136,6 +142,7 @@ QFile* Snapshot::savedFileForSnapshot(QImage & shot, bool isTemporary) {
snapshotFullPath.append(filename); snapshotFullPath.append(filename);
QFile* imageFile = new QFile(snapshotFullPath); QFile* imageFile = new QFile(snapshotFullPath);
std::string str = snapshotFullPath.toStdString();
imageFile->open(QIODevice::WriteOnly); imageFile->open(QIODevice::WriteOnly);
shot.save(imageFile, 0, IMAGE_QUALITY); shot.save(imageFile, 0, IMAGE_QUALITY);

View file

@ -25,19 +25,11 @@ class QTemporaryFile;
class SnapshotMetaData { class SnapshotMetaData {
public: public:
QString getDomain() { return _domain; } QUrl getURL() { return _URL; }
void setDomain(QString domain) { _domain = domain; } void setURL(QUrl URL) { _URL = URL; }
glm::vec3 getLocation() { return _location; }
void setLocation(glm::vec3 location) { _location = location; }
glm::quat getOrientation() { return _orientation; }
void setOrientation(glm::quat orientation) { _orientation = orientation; }
private: private:
QString _domain; QUrl _URL;
glm::vec3 _location;
glm::quat _orientation;;
}; };
class Snapshot { class Snapshot {