mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 13:28:09 +02:00
"fixed" formatting issues and code cleanup
This commit is contained in:
parent
57004c61c7
commit
694272ffaa
4 changed files with 57 additions and 90 deletions
|
@ -1696,9 +1696,9 @@ bool Application::acceptSnapshot(const QString& urlString) {
|
||||||
|
|
||||||
SnapshotMetaData* snapshotData = Snapshot::parseSnapshotData(snapshotPath);
|
SnapshotMetaData* snapshotData = Snapshot::parseSnapshotData(snapshotPath);
|
||||||
if (snapshotData) {
|
if (snapshotData) {
|
||||||
if (!snapshotData->getURL().toString().isEmpty()) {
|
if (!snapshotData->getURL().toString().isEmpty()) {
|
||||||
DependencyManager::get<AddressManager>()->handleLookupString(snapshotData->getURL().toString());
|
DependencyManager::get<AddressManager>()->handleLookupString(snapshotData->getURL().toString());
|
||||||
}
|
}
|
||||||
} 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 "
|
||||||
|
|
|
@ -26,11 +26,11 @@
|
||||||
#include "Util.h"
|
#include "Util.h"
|
||||||
|
|
||||||
MainWindow::MainWindow(QWidget* parent) :
|
MainWindow::MainWindow(QWidget* parent) :
|
||||||
QMainWindow(parent),
|
QMainWindow(parent),
|
||||||
_windowGeometry("WindowGeometry"),
|
_windowGeometry("WindowGeometry"),
|
||||||
_windowState("WindowState", 0)
|
_windowState("WindowState", 0)
|
||||||
{
|
{
|
||||||
setAcceptDrops(true);
|
setAcceptDrops(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::restoreGeometry() {
|
void MainWindow::restoreGeometry() {
|
||||||
|
@ -91,20 +91,23 @@ void MainWindow::changeEvent(QEvent* event) {
|
||||||
if (event->type() == QEvent::WindowStateChange) {
|
if (event->type() == QEvent::WindowStateChange) {
|
||||||
QWindowStateChangeEvent* stateChangeEvent = static_cast<QWindowStateChangeEvent*>(event);
|
QWindowStateChangeEvent* stateChangeEvent = static_cast<QWindowStateChangeEvent*>(event);
|
||||||
if ((stateChangeEvent->oldState() == Qt::WindowNoState ||
|
if ((stateChangeEvent->oldState() == Qt::WindowNoState ||
|
||||||
stateChangeEvent->oldState() == Qt::WindowMaximized) &&
|
stateChangeEvent->oldState() == Qt::WindowMaximized) &&
|
||||||
windowState() == Qt::WindowMinimized) {
|
windowState() == Qt::WindowMinimized) {
|
||||||
emit windowShown(false);
|
emit windowShown(false);
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
emit windowShown(true);
|
emit windowShown(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isFullScreen() != Menu::getInstance()->isOptionChecked(MenuOption::Fullscreen)) {
|
if (isFullScreen() != Menu::getInstance()->isOptionChecked(MenuOption::Fullscreen)) {
|
||||||
Menu::getInstance()->setIsOptionChecked(MenuOption::Fullscreen, isFullScreen());
|
Menu::getInstance()->setIsOptionChecked(MenuOption::Fullscreen, isFullScreen());
|
||||||
}
|
}
|
||||||
} else if (event->type() == QEvent::ActivationChange) {
|
}
|
||||||
|
else if (event->type() == QEvent::ActivationChange) {
|
||||||
if (isActiveWindow()) {
|
if (isActiveWindow()) {
|
||||||
emit windowShown(true);
|
emit windowShown(true);
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
emit windowShown(false);
|
emit windowShown(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -113,17 +116,11 @@ void MainWindow::changeEvent(QEvent* event) {
|
||||||
|
|
||||||
void MainWindow::dragEnterEvent(QDragEnterEvent* event)
|
void MainWindow::dragEnterEvent(QDragEnterEvent* event)
|
||||||
{
|
{
|
||||||
if (event->mimeData())
|
if (event->mimeData())
|
||||||
event->acceptProposedAction();
|
event->acceptProposedAction();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::dropEvent(QDropEvent* event)
|
void MainWindow::dropEvent(QDropEvent* event)
|
||||||
{
|
{
|
||||||
/*QList<QUrl> urls = event->mimeData()->urls();
|
QCoreApplication::sendEvent(QCoreApplication::instance(), event);
|
||||||
foreach(QUrl url, urls)
|
|
||||||
{
|
|
||||||
qDebug() << "urlmessage" << url.toString();
|
|
||||||
}*/
|
|
||||||
|
|
||||||
QCoreApplication::sendEvent(QCoreApplication::instance(), event);
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,56 +35,43 @@ 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";
|
||||||
|
|
||||||
const QString LOCATION_X = "location-x";
|
const QString URL = "highfidelity_url";
|
||||||
const QString LOCATION_Y = "location-y";
|
|
||||||
const QString LOCATION_Z = "location-z";
|
|
||||||
|
|
||||||
const QString ORIENTATION_X = "orientation-x";
|
|
||||||
const QString ORIENTATION_Y = "orientation-y";
|
|
||||||
const QString ORIENTATION_Z = "orientation-z";
|
|
||||||
const QString ORIENTATION_W = "orientation-w";
|
|
||||||
|
|
||||||
const QString PATH = "path";
|
|
||||||
|
|
||||||
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));
|
||||||
|
|
||||||
SnapshotMetaData* Snapshot::parseSnapshotData(QString snapshotPath) {
|
SnapshotMetaData* Snapshot::parseSnapshotData(QString snapshotPath) {
|
||||||
|
|
||||||
if (!QFile(snapshotPath).exists()) {
|
if (!QFile(snapshotPath).exists()) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
QImage shot(snapshotPath);
|
QImage shot(snapshotPath);
|
||||||
|
|
||||||
// no location data stored
|
// no location data stored
|
||||||
if (shot.text(URL).isEmpty()) {
|
if (shot.text(URL).isEmpty()) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
// parsing URL
|
// parsing URL
|
||||||
QUrl url = QUrl(shot.text(URL), QUrl::ParsingMode::StrictMode);
|
QUrl url = QUrl(shot.text(URL), QUrl::ParsingMode::StrictMode);
|
||||||
|
|
||||||
SnapshotMetaData* data = new SnapshotMetaData();
|
SnapshotMetaData* data = new SnapshotMetaData();
|
||||||
data->setURL(url);
|
data->setURL(url);
|
||||||
|
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString Snapshot::saveSnapshot(QImage image) {
|
QString Snapshot::saveSnapshot(QImage image) {
|
||||||
QFile* snapshotFile = savedFileForSnapshot(image, false);
|
QFile* snapshotFile = savedFileForSnapshot(image, false);
|
||||||
|
|
||||||
// we don't need the snapshot file, so close it, grab its filename and delete it
|
// we don't need the snapshot file, so close it, grab its filename and delete it
|
||||||
snapshotFile->close();
|
snapshotFile->close();
|
||||||
|
|
||||||
QString snapshotPath = QFileInfo(*snapshotFile).absoluteFilePath();
|
QString snapshotPath = QFileInfo(*snapshotFile).absoluteFilePath();
|
||||||
|
|
||||||
delete snapshotFile;
|
delete snapshotFile;
|
||||||
|
|
||||||
return snapshotPath;
|
return snapshotPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -94,72 +81,55 @@ QTemporaryFile* Snapshot::saveTempSnapshot(QImage image) {
|
||||||
}
|
}
|
||||||
|
|
||||||
QFile* Snapshot::savedFileForSnapshot(QImage & shot, bool isTemporary) {
|
QFile* Snapshot::savedFileForSnapshot(QImage & shot, bool isTemporary) {
|
||||||
|
|
||||||
//Avatar* avatar = DependencyManager::get<AvatarManager>()->getMyAvatar();
|
|
||||||
//
|
|
||||||
//glm::vec3 location = avatar->getPosition();
|
|
||||||
//glm::quat orientation = avatar->getHead()->getOrientation();
|
|
||||||
//
|
|
||||||
//// 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));
|
|
||||||
//
|
|
||||||
//shot.setText(ORIENTATION_X, QString::number(orientation.x));
|
|
||||||
//shot.setText(ORIENTATION_Y, QString::number(orientation.y));
|
|
||||||
//shot.setText(ORIENTATION_Z, QString::number(orientation.z));
|
|
||||||
//shot.setText(ORIENTATION_W, QString::number(orientation.w));
|
|
||||||
//
|
|
||||||
//shot.setText(DOMAIN_KEY, DependencyManager::get<NodeList>()->getDomainHandler().getHostname());
|
|
||||||
//
|
|
||||||
//shot.setText(PATH, QString::number());
|
|
||||||
|
|
||||||
// adding URL to snapshot
|
// adding URL to snapshot
|
||||||
QUrl currentURL = DependencyManager::get<AddressManager>()->currentAddress();
|
QUrl currentURL = DependencyManager::get<AddressManager>()->currentAddress();
|
||||||
shot.setText(URL, currentURL.toString());
|
shot.setText(URL, currentURL.toString());
|
||||||
|
|
||||||
QString formattedLocation = QString(currentURL.toString());
|
QString formattedLocation = QString(currentURL.toString());
|
||||||
// replace decimal . with '-'
|
// replace decimal . with '-'
|
||||||
formattedLocation.replace('.', '-');
|
formattedLocation.replace('.', '-');
|
||||||
|
|
||||||
QString username = AccountManager::getInstance().getAccountInfo().getUsername();
|
QString username = AccountManager::getInstance().getAccountInfo().getUsername();
|
||||||
// normalize username, replace all non alphanumeric with '-'
|
// normalize username, replace all non alphanumeric with '-'
|
||||||
username.replace(QRegExp("[^A-Za-z0-9_]"), "-");
|
username.replace(QRegExp("[^A-Za-z0-9_]"), "-");
|
||||||
|
|
||||||
QDateTime now = QDateTime::currentDateTime();
|
QDateTime now = QDateTime::currentDateTime();
|
||||||
|
|
||||||
QString filename = FILENAME_PATH_FORMAT.arg(username, now.toString(DATETIME_FORMAT));
|
QString filename = FILENAME_PATH_FORMAT.arg(username, now.toString(DATETIME_FORMAT));
|
||||||
|
|
||||||
const int IMAGE_QUALITY = 100;
|
const int IMAGE_QUALITY = 100;
|
||||||
|
|
||||||
if (!isTemporary) {
|
if (!isTemporary) {
|
||||||
QString snapshotFullPath = snapshotsLocation.get();
|
QString snapshotFullPath = snapshotsLocation.get();
|
||||||
|
|
||||||
if (!snapshotFullPath.endsWith(QDir::separator())) {
|
if (!snapshotFullPath.endsWith(QDir::separator())) {
|
||||||
snapshotFullPath.append(QDir::separator());
|
snapshotFullPath.append(QDir::separator());
|
||||||
}
|
}
|
||||||
|
|
||||||
snapshotFullPath.append(filename);
|
snapshotFullPath.append(filename);
|
||||||
|
|
||||||
QFile* imageFile = new QFile(snapshotFullPath);
|
QFile* imageFile = new QFile(snapshotFullPath);
|
||||||
std::string str = snapshotFullPath.toStdString();
|
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);
|
||||||
imageFile->close();
|
imageFile->close();
|
||||||
|
|
||||||
return imageFile;
|
return imageFile;
|
||||||
} else {
|
|
||||||
|
}
|
||||||
|
else {
|
||||||
QTemporaryFile* imageTempFile = new QTemporaryFile(QDir::tempPath() + "/XXXXXX-" + filename);
|
QTemporaryFile* imageTempFile = new QTemporaryFile(QDir::tempPath() + "/XXXXXX-" + filename);
|
||||||
|
|
||||||
if (!imageTempFile->open()) {
|
if (!imageTempFile->open()) {
|
||||||
qDebug() << "Unable to open QTemporaryFile for temp snapshot. Will not save.";
|
qDebug() << "Unable to open QTemporaryFile for temp snapshot. Will not save.";
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
shot.save(imageTempFile, 0, IMAGE_QUALITY);
|
shot.save(imageTempFile, 0, IMAGE_QUALITY);
|
||||||
imageTempFile->close();
|
imageTempFile->close();
|
||||||
|
|
||||||
return imageTempFile;
|
return imageTempFile;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,12 +24,12 @@ class QTemporaryFile;
|
||||||
|
|
||||||
class SnapshotMetaData {
|
class SnapshotMetaData {
|
||||||
public:
|
public:
|
||||||
|
|
||||||
QUrl getURL() { return _URL; }
|
QUrl getURL() { return _URL; }
|
||||||
void setURL(QUrl URL) { _URL = URL; }
|
void setURL(QUrl URL) { _URL = URL; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QUrl _URL;
|
QUrl _URL;
|
||||||
};
|
};
|
||||||
|
|
||||||
class Snapshot {
|
class Snapshot {
|
||||||
|
@ -37,7 +37,7 @@ public:
|
||||||
static QString saveSnapshot(QImage image);
|
static QString saveSnapshot(QImage image);
|
||||||
static QTemporaryFile* saveTempSnapshot(QImage image);
|
static QTemporaryFile* saveTempSnapshot(QImage image);
|
||||||
static SnapshotMetaData* parseSnapshotData(QString snapshotPath);
|
static SnapshotMetaData* parseSnapshotData(QString snapshotPath);
|
||||||
|
|
||||||
static Setting::Handle<QString> snapshotsLocation;
|
static Setting::Handle<QString> snapshotsLocation;
|
||||||
private:
|
private:
|
||||||
static QFile* savedFileForSnapshot(QImage & image, bool isTemporary);
|
static QFile* savedFileForSnapshot(QImage & image, bool isTemporary);
|
||||||
|
|
Loading…
Reference in a new issue