2016-03-21 07:54:14 +01:00
|
|
|
/*****************************************************************************
|
|
|
|
* gta5sync GRAND THEFT AUTO V SYNC
|
2016-03-27 09:52:23 +02:00
|
|
|
* Copyright (C) 2016 Syping
|
2016-03-21 07:54:14 +01:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*****************************************************************************/
|
|
|
|
|
2016-03-20 21:57:18 +01:00
|
|
|
#include "PictureDialog.h"
|
2016-04-12 21:53:21 +02:00
|
|
|
#include "PictureWidget.h"
|
2016-03-22 05:20:42 +01:00
|
|
|
#include "ProfileDatabase.h"
|
2016-03-20 21:57:18 +01:00
|
|
|
#include "ui_PictureDialog.h"
|
2016-03-29 15:14:49 +02:00
|
|
|
#include "SidebarGenerator.h"
|
2016-03-28 12:23:50 +02:00
|
|
|
#include "StandardPaths.h"
|
2016-04-03 02:27:24 +02:00
|
|
|
#include "PictureExport.h"
|
2016-04-23 20:15:59 +02:00
|
|
|
#include "GlobalString.h"
|
2016-04-03 02:27:24 +02:00
|
|
|
#include "PictureCopy.h"
|
2016-04-01 21:06:09 +02:00
|
|
|
#include "UiModLabel.h"
|
2016-03-20 21:57:18 +01:00
|
|
|
|
2016-04-01 21:06:09 +02:00
|
|
|
#include <QDesktopWidget>
|
2016-03-21 20:44:07 +01:00
|
|
|
#include <QJsonDocument>
|
2016-04-26 14:59:14 +02:00
|
|
|
#include <QApplication>
|
2016-03-22 05:20:42 +01:00
|
|
|
#include <QFileDialog>
|
2016-03-21 22:14:32 +01:00
|
|
|
#include <QMessageBox>
|
2016-03-21 20:44:07 +01:00
|
|
|
#include <QJsonObject>
|
|
|
|
#include <QVariantMap>
|
|
|
|
#include <QJsonArray>
|
2016-04-12 20:56:58 +02:00
|
|
|
#include <QKeyEvent>
|
2016-04-14 03:44:38 +02:00
|
|
|
#include <QMimeData>
|
|
|
|
#include <QBuffer>
|
2016-03-21 20:44:07 +01:00
|
|
|
#include <QDebug>
|
2016-03-23 03:33:46 +01:00
|
|
|
#include <QList>
|
2016-04-14 03:44:38 +02:00
|
|
|
#include <QDrag>
|
2016-03-23 03:33:46 +01:00
|
|
|
#include <QUrl>
|
|
|
|
#include <QDir>
|
|
|
|
|
2016-05-09 10:24:34 +02:00
|
|
|
PictureDialog::PictureDialog(ProfileDatabase *profileDB, CrewDatabase *crewDB, QWidget *parent) :
|
|
|
|
QDialog(parent), profileDB(profileDB), crewDB(crewDB),
|
2016-03-20 21:57:18 +01:00
|
|
|
ui(new Ui::PictureDialog)
|
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
2016-03-21 22:06:17 +01:00
|
|
|
windowTitleStr = this->windowTitle();
|
2016-03-21 20:44:07 +01:00
|
|
|
jsonDrawString = ui->labJSON->text();
|
2016-03-22 05:20:42 +01:00
|
|
|
ui->cmdExport->setEnabled(0);
|
2016-03-22 05:59:17 +01:00
|
|
|
plyrsList = QStringList();
|
2016-04-24 12:47:14 +02:00
|
|
|
fullscreenWidget = 0;
|
|
|
|
rqfullscreen = 0;
|
2016-04-12 20:56:58 +02:00
|
|
|
indexed = 0;
|
2016-04-23 20:15:59 +02:00
|
|
|
picArea = "";
|
2016-03-29 14:50:30 +02:00
|
|
|
picTitl = "";
|
2016-04-01 01:54:21 +02:00
|
|
|
picPath = "";
|
2016-05-09 10:24:34 +02:00
|
|
|
created = "";
|
2016-03-22 05:59:17 +01:00
|
|
|
crewID = "";
|
|
|
|
locX = "";
|
|
|
|
locY = "";
|
|
|
|
locZ = "";
|
2016-03-29 12:23:21 +02:00
|
|
|
smpic = 0;
|
2016-04-08 16:55:28 +02:00
|
|
|
|
|
|
|
// Export menu
|
|
|
|
exportMenu = new QMenu(this);
|
2016-04-24 14:44:41 +02:00
|
|
|
jpegExportAction = exportMenu->addAction(tr("Export as &JPG picture..."), this, SLOT(exportSnapmaticPicture()));
|
|
|
|
pgtaExportAction = exportMenu->addAction(tr("Export as >A Snapmatic..."), this, SLOT(copySnapmaticPicture()));
|
2016-04-08 16:55:28 +02:00
|
|
|
ui->cmdExport->setMenu(exportMenu);
|
2016-04-12 20:56:58 +02:00
|
|
|
|
2016-04-23 21:01:00 +02:00
|
|
|
// Global map
|
|
|
|
globalMap = GlobalString::getGlobalMap();
|
|
|
|
|
2016-04-12 20:56:58 +02:00
|
|
|
installEventFilter(this);
|
2016-04-14 03:51:48 +02:00
|
|
|
installEventFilter(ui->labPicture);
|
|
|
|
ui->labPicture->setFocusPolicy(Qt::StrongFocus);
|
2016-03-20 21:57:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
PictureDialog::~PictureDialog()
|
|
|
|
{
|
2016-04-24 14:44:41 +02:00
|
|
|
delete jpegExportAction;
|
|
|
|
delete pgtaExportAction;
|
2016-04-08 16:55:28 +02:00
|
|
|
delete exportMenu;
|
2016-03-20 21:57:18 +01:00
|
|
|
delete ui;
|
|
|
|
}
|
2016-03-21 03:10:28 +01:00
|
|
|
|
2016-04-12 20:56:58 +02:00
|
|
|
bool PictureDialog::eventFilter(QObject *obj, QEvent *ev)
|
|
|
|
{
|
2016-04-14 03:44:38 +02:00
|
|
|
bool returnValue = false;
|
2016-04-14 03:51:48 +02:00
|
|
|
if (obj == this || obj == ui->labPicture)
|
2016-04-12 20:56:58 +02:00
|
|
|
{
|
|
|
|
if (ev->type() == QEvent::KeyPress)
|
|
|
|
{
|
|
|
|
QKeyEvent *keyEvent = (QKeyEvent*)ev;
|
|
|
|
switch (keyEvent->key()){
|
|
|
|
case Qt::Key_Left:
|
|
|
|
emit previousPictureRequested();
|
2016-04-14 03:44:38 +02:00
|
|
|
returnValue = true;
|
2016-04-12 20:56:58 +02:00
|
|
|
break;
|
|
|
|
case Qt::Key_Right:
|
|
|
|
emit nextPictureRequested();
|
2016-04-14 03:44:38 +02:00
|
|
|
returnValue = true;
|
|
|
|
break;
|
|
|
|
case Qt::Key_E: case Qt::Key_S: case Qt::Key_Save:
|
|
|
|
ui->cmdExport->click();
|
|
|
|
returnValue = true;
|
|
|
|
break;
|
2016-04-18 07:23:19 +02:00
|
|
|
#if QT_VERSION >= 0x050000
|
2016-04-18 07:46:45 +02:00
|
|
|
case Qt::Key_Exit:
|
2016-04-14 03:44:38 +02:00
|
|
|
ui->cmdClose->click();
|
|
|
|
returnValue = true;
|
|
|
|
break;
|
2016-04-18 07:23:19 +02:00
|
|
|
#endif
|
2016-04-14 03:44:38 +02:00
|
|
|
case Qt::Key_Enter: case Qt::Key_Return:
|
2016-04-24 12:47:14 +02:00
|
|
|
on_labPicture_mouseDoubleClicked(Qt::LeftButton);
|
2016-04-14 03:44:38 +02:00
|
|
|
returnValue = true;
|
2016-04-12 20:56:58 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-04-14 03:44:38 +02:00
|
|
|
return returnValue;
|
|
|
|
}
|
|
|
|
|
2016-04-24 14:44:41 +02:00
|
|
|
void PictureDialog::triggerFullscreenDoubeClick()
|
|
|
|
{
|
|
|
|
on_labPicture_mouseDoubleClicked(Qt::LeftButton);
|
|
|
|
}
|
|
|
|
|
2016-04-24 12:47:14 +02:00
|
|
|
void PictureDialog::exportCustomContextMenuRequestedPrivate(const QPoint &pos, bool fullscreen)
|
|
|
|
{
|
|
|
|
rqfullscreen = fullscreen;
|
2016-04-24 14:44:41 +02:00
|
|
|
exportMenu->popup(pos);
|
2016-04-24 12:47:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void PictureDialog::exportCustomContextMenuRequested(const QPoint &pos)
|
|
|
|
{
|
|
|
|
exportCustomContextMenuRequestedPrivate(pos, true);
|
|
|
|
}
|
|
|
|
|
2016-04-14 03:44:38 +02:00
|
|
|
void PictureDialog::mousePressEvent(QMouseEvent *ev)
|
|
|
|
{
|
2016-04-24 12:47:14 +02:00
|
|
|
QDialog::mousePressEvent(ev);
|
2016-04-12 20:56:58 +02:00
|
|
|
}
|
|
|
|
|
2016-04-12 21:53:21 +02:00
|
|
|
void PictureDialog::dialogNextPictureRequested()
|
|
|
|
{
|
|
|
|
emit nextPictureRequested();
|
|
|
|
}
|
|
|
|
|
|
|
|
void PictureDialog::dialogPreviousPictureRequested()
|
|
|
|
{
|
|
|
|
emit previousPictureRequested();
|
|
|
|
}
|
|
|
|
|
2016-04-12 20:56:58 +02:00
|
|
|
void PictureDialog::setSnapmaticPicture(SnapmaticPicture *picture, QString picturePath, bool readOk, bool _indexed, int _index)
|
2016-03-21 20:44:07 +01:00
|
|
|
{
|
2016-04-12 21:53:21 +02:00
|
|
|
snapmaticPicture = QImage();
|
2016-04-12 20:56:58 +02:00
|
|
|
indexed = _indexed;
|
|
|
|
index = _index;
|
2016-04-01 01:54:21 +02:00
|
|
|
picPath = picturePath;
|
2016-03-29 12:23:21 +02:00
|
|
|
smpic = picture;
|
2016-03-21 22:40:03 +01:00
|
|
|
if (!readOk)
|
|
|
|
{
|
2016-03-23 02:08:16 +01:00
|
|
|
QMessageBox::warning(this, tr("Snapmatic Picture Viewer"), tr("Failed at %1").arg(picture->getLastStep()));
|
|
|
|
return;
|
2016-03-21 22:40:03 +01:00
|
|
|
}
|
|
|
|
if (picture->isPicOk())
|
|
|
|
{
|
2016-04-01 21:39:23 +02:00
|
|
|
snapmaticPicture = picture->getPicture();
|
|
|
|
ui->labPicture->setPixmap(QPixmap::fromImage(snapmaticPicture, Qt::AutoColor));
|
2016-03-22 05:20:42 +01:00
|
|
|
ui->cmdExport->setEnabled(true);
|
2016-03-21 22:40:03 +01:00
|
|
|
}
|
|
|
|
if (picture->isJsonOk())
|
2016-03-21 22:14:32 +01:00
|
|
|
{
|
2016-03-22 05:59:17 +01:00
|
|
|
locX = QString::number(picture->getLocationX());
|
|
|
|
locY = QString::number(picture->getLocationY());
|
|
|
|
locZ = QString::number(picture->getLocationZ());
|
2016-05-09 10:24:34 +02:00
|
|
|
crewID = crewDB->getCrewName(picture->getCrewNumber());
|
|
|
|
created = picture->getCreatedDateTime().toString(Qt::DefaultLocaleShortDate);
|
2016-03-22 05:59:17 +01:00
|
|
|
plyrsList = picture->getPlayers();
|
2016-03-29 14:50:30 +02:00
|
|
|
picTitl = picture->getPictureTitl();
|
2016-04-23 20:15:59 +02:00
|
|
|
picArea = picture->getArea();
|
2016-04-23 21:01:00 +02:00
|
|
|
if (globalMap.contains(picArea))
|
|
|
|
{
|
|
|
|
picAreaStr = globalMap[picArea];
|
|
|
|
}
|
2016-04-23 21:01:41 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
picAreaStr = picArea;
|
|
|
|
}
|
2016-03-21 22:14:32 +01:00
|
|
|
|
|
|
|
QString plyrsStr;
|
2016-03-21 22:40:03 +01:00
|
|
|
if (plyrsList.length() >= 1)
|
|
|
|
{
|
|
|
|
foreach (const QString &player, plyrsList)
|
|
|
|
{
|
2016-03-23 06:29:49 +01:00
|
|
|
QString playerName = profileDB->getPlayerName(player.toInt());
|
2016-04-07 17:36:15 +02:00
|
|
|
plyrsStr.append(", <a href=\"https://socialclub.rockstargames.com/member/");
|
2016-03-23 06:29:49 +01:00
|
|
|
plyrsStr.append(playerName);
|
|
|
|
plyrsStr.append("/");
|
|
|
|
plyrsStr.append(player);
|
|
|
|
plyrsStr.append("\">");
|
|
|
|
plyrsStr.append(playerName);
|
|
|
|
plyrsStr.append("</a>");
|
2016-03-21 22:40:03 +01:00
|
|
|
}
|
|
|
|
plyrsStr.remove(0,2);
|
|
|
|
}
|
|
|
|
else
|
2016-03-21 22:14:32 +01:00
|
|
|
{
|
2016-03-21 22:40:03 +01:00
|
|
|
plyrsStr = tr("No player");
|
2016-03-21 22:14:32 +01:00
|
|
|
}
|
2016-03-21 22:40:03 +01:00
|
|
|
|
|
|
|
if (crewID == "") { crewID = tr("No crew"); }
|
2016-03-21 20:44:07 +01:00
|
|
|
|
2016-05-09 10:24:34 +02:00
|
|
|
this->setWindowTitle(windowTitleStr.arg(picture->getPictureStr()));
|
|
|
|
ui->labJSON->setText(jsonDrawString.arg(locX, locY, locZ, plyrsStr, crewID, picTitl, picAreaStr, created));
|
2016-03-21 22:14:32 +01:00
|
|
|
}
|
|
|
|
else
|
2016-03-21 20:44:07 +01:00
|
|
|
{
|
2016-04-23 20:28:55 +02:00
|
|
|
ui->labJSON->setText(jsonDrawString.arg("0.0", "0.0", "0.0", tr("No player"), tr("No crew"), tr("Unknown Location")));
|
2016-03-21 22:14:32 +01:00
|
|
|
QMessageBox::warning(this,tr("Snapmatic Picture Viewer"),tr("Failed at %1").arg(picture->getLastStep()));
|
2016-03-21 20:44:07 +01:00
|
|
|
}
|
2016-04-12 21:53:21 +02:00
|
|
|
emit newPictureCommited(snapmaticPicture);
|
2016-03-21 20:44:07 +01:00
|
|
|
}
|
2016-03-21 21:54:46 +01:00
|
|
|
|
2016-04-12 20:56:58 +02:00
|
|
|
void PictureDialog::setSnapmaticPicture(SnapmaticPicture *picture, QString picPath, bool readOk)
|
|
|
|
{
|
|
|
|
setSnapmaticPicture(picture, picPath, readOk, false, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void PictureDialog::setSnapmaticPicture(SnapmaticPicture *picture, QString picPath)
|
|
|
|
{
|
|
|
|
setSnapmaticPicture(picture, picPath, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
void PictureDialog::setSnapmaticPicture(SnapmaticPicture *picture, bool readOk, int index)
|
|
|
|
{
|
|
|
|
setSnapmaticPicture(picture, picture->getPictureFileName(), readOk, true, index);
|
|
|
|
}
|
|
|
|
|
|
|
|
void PictureDialog::setSnapmaticPicture(SnapmaticPicture *picture, bool readOk)
|
|
|
|
{
|
|
|
|
setSnapmaticPicture(picture, picture->getPictureFileName(), readOk);
|
|
|
|
}
|
|
|
|
|
|
|
|
void PictureDialog::setSnapmaticPicture(SnapmaticPicture *picture, int index)
|
|
|
|
{
|
|
|
|
setSnapmaticPicture(picture, true, index);
|
|
|
|
}
|
|
|
|
|
|
|
|
void PictureDialog::setSnapmaticPicture(SnapmaticPicture *picture)
|
|
|
|
{
|
|
|
|
setSnapmaticPicture(picture, true);
|
|
|
|
}
|
|
|
|
|
2016-04-03 06:12:12 +02:00
|
|
|
void PictureDialog::playerNameUpdated()
|
2016-03-22 05:59:17 +01:00
|
|
|
{
|
|
|
|
if (plyrsList.count() >= 1)
|
|
|
|
{
|
|
|
|
QString plyrsStr;
|
|
|
|
foreach (const QString &player, plyrsList)
|
|
|
|
{
|
2016-03-23 06:29:49 +01:00
|
|
|
QString playerName = profileDB->getPlayerName(player.toInt());
|
2016-04-07 17:36:15 +02:00
|
|
|
plyrsStr.append(", <a href=\"https://socialclub.rockstargames.com/member/");
|
2016-03-23 06:29:49 +01:00
|
|
|
if (playerName != player)
|
|
|
|
{
|
|
|
|
plyrsStr.append(playerName);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
plyrsStr.append("id");
|
|
|
|
}
|
|
|
|
plyrsStr.append("/");
|
|
|
|
plyrsStr.append(player);
|
|
|
|
plyrsStr.append("\">");
|
|
|
|
plyrsStr.append(playerName);
|
|
|
|
plyrsStr.append("</a>");
|
2016-03-22 05:59:17 +01:00
|
|
|
}
|
|
|
|
plyrsStr.remove(0,2);
|
2016-05-09 10:24:34 +02:00
|
|
|
ui->labJSON->setText(jsonDrawString.arg(locX, locY, locZ, plyrsStr, crewID, picTitl, picAreaStr, created));
|
2016-03-22 05:59:17 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-08 16:55:28 +02:00
|
|
|
void PictureDialog::exportSnapmaticPicture()
|
2016-03-22 05:20:42 +01:00
|
|
|
{
|
2016-09-21 07:04:41 +02:00
|
|
|
if (rqfullscreen && fullscreenWidget)
|
2016-04-24 12:47:14 +02:00
|
|
|
{
|
|
|
|
PictureExport::exportPicture(fullscreenWidget, smpic);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
PictureExport::exportPicture(this, smpic);
|
|
|
|
}
|
2016-03-22 05:20:42 +01:00
|
|
|
}
|
2016-04-01 01:54:21 +02:00
|
|
|
|
2016-04-08 16:55:28 +02:00
|
|
|
void PictureDialog::copySnapmaticPicture()
|
2016-04-01 01:54:21 +02:00
|
|
|
{
|
2016-09-21 07:04:41 +02:00
|
|
|
if (rqfullscreen && fullscreenWidget)
|
2016-04-24 12:47:14 +02:00
|
|
|
{
|
|
|
|
PictureCopy::copyPicture(fullscreenWidget, picPath);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
PictureCopy::copyPicture(this, picPath);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void PictureDialog::on_labPicture_mouseDoubleClicked(Qt::MouseButton button)
|
|
|
|
{
|
|
|
|
if (button == Qt::LeftButton)
|
|
|
|
{
|
|
|
|
QRect desktopRect = QApplication::desktop()->screenGeometry();
|
|
|
|
PictureWidget *pictureWidget = new PictureWidget(this);
|
2016-04-24 13:34:03 +02:00
|
|
|
pictureWidget->setObjectName("PictureWidget");
|
2016-04-24 12:47:14 +02:00
|
|
|
pictureWidget->setWindowFlags(pictureWidget->windowFlags()^Qt::WindowContextHelpButtonHint);
|
|
|
|
pictureWidget->setWindowTitle(this->windowTitle());
|
|
|
|
pictureWidget->setStyleSheet("QLabel#pictureLabel{background-color: black;}");
|
|
|
|
pictureWidget->setImage(snapmaticPicture, desktopRect);
|
|
|
|
pictureWidget->setModal(true);
|
|
|
|
|
|
|
|
fullscreenWidget = pictureWidget;
|
|
|
|
QObject::connect(this, SIGNAL(newPictureCommited(QImage)), pictureWidget, SLOT(setImage(QImage)));
|
|
|
|
QObject::connect(pictureWidget, SIGNAL(nextPictureRequested()), this, SLOT(dialogNextPictureRequested()));
|
|
|
|
QObject::connect(pictureWidget, SIGNAL(previousPictureRequested()), this, SLOT(dialogPreviousPictureRequested()));
|
|
|
|
|
|
|
|
pictureWidget->showFullScreen();
|
|
|
|
pictureWidget->setFocus();
|
|
|
|
pictureWidget->exec();
|
|
|
|
|
2016-09-21 07:04:41 +02:00
|
|
|
fullscreenWidget = 0;
|
2016-04-24 12:47:14 +02:00
|
|
|
delete pictureWidget;
|
|
|
|
}
|
2016-04-01 01:54:21 +02:00
|
|
|
}
|
2016-04-01 21:06:09 +02:00
|
|
|
|
2016-04-24 12:47:14 +02:00
|
|
|
void PictureDialog::on_labPicture_customContextMenuRequested(const QPoint &pos)
|
2016-04-01 21:06:09 +02:00
|
|
|
{
|
2016-04-24 12:47:14 +02:00
|
|
|
exportCustomContextMenuRequestedPrivate(ui->labPicture->mapToGlobal(pos), false);
|
2016-04-01 21:06:09 +02:00
|
|
|
}
|
2016-04-12 20:56:58 +02:00
|
|
|
|
|
|
|
bool PictureDialog::isIndexed()
|
|
|
|
{
|
|
|
|
return indexed;
|
|
|
|
}
|
|
|
|
|
|
|
|
int PictureDialog::getIndex()
|
|
|
|
{
|
|
|
|
return index;
|
|
|
|
}
|