2017-10-09 08:35:48 +02:00
/*****************************************************************************
2018-05-24 22:32:00 +02:00
* gta5view Grand Theft Auto V Profile Viewer
2021-01-27 14:35:42 +01:00
* Copyright ( C ) 2016 - 2021 Syping
2017-10-09 08:35:48 +02: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/>.
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
# include "PictureDialog.h"
# include "PictureWidget.h"
# include "ProfileDatabase.h"
# include "ui_PictureDialog.h"
# include "SidebarGenerator.h"
2017-11-12 15:58:59 +01:00
# include "MapLocationDialog.h"
2017-11-22 14:59:40 +01:00
# include "JsonEditorDialog.h"
2017-10-09 08:35:48 +02:00
# include "SnapmaticEditor.h"
# include "StandardPaths.h"
# include "PictureExport.h"
2018-07-21 18:33:08 +02:00
# include "ImportDialog.h"
2017-10-09 08:35:48 +02:00
# include "StringParser.h"
# include "GlobalString.h"
# include "UiModLabel.h"
# include "AppEnv.h"
2018-07-28 04:55:55 +02:00
# include "config.h"
2017-10-09 08:35:48 +02:00
2020-09-28 05:33:04 +02:00
# if QT_VERSION < 0x060000
# include <QDesktopWidget>
# endif
2020-09-26 16:12:55 +02:00
# ifdef Q_OS_WIN
2021-02-11 23:09:49 +01:00
# if QT_VERSION >= 0x050000
2021-02-11 20:20:52 +01:00
# include "dwmapi.h"
2017-10-09 08:35:48 +02:00
# endif
2021-02-11 23:09:49 +01:00
# endif
2017-10-09 08:35:48 +02:00
2021-01-30 12:02:55 +01:00
# ifdef Q_OS_MAC
# include <QStyleFactory>
# endif
2017-10-09 08:35:48 +02:00
# include <QStringBuilder>
# include <QJsonDocument>
# include <QApplication>
2017-12-12 04:45:46 +01:00
# include <QFontMetrics>
2018-07-28 04:55:55 +02:00
# include <QJsonObject>
2017-12-12 04:45:46 +01:00
# include <QSizePolicy>
2017-10-09 08:35:48 +02:00
# include <QStaticText>
# include <QFileDialog>
# include <QMessageBox>
# include <QJsonObject>
# include <QVariantMap>
# include <QJsonArray>
# include <QKeyEvent>
# include <QMimeData>
# include <QToolBar>
# include <QPainter>
# include <QPicture>
# include <QBitmap>
# include <QBuffer>
2021-01-30 12:02:55 +01:00
# include <QTimer>
2017-10-09 08:35:48 +02:00
# include <QImage>
# include <QDebug>
# include <QList>
# include <QDrag>
# include <QIcon>
# include <QUrl>
# include <QDir>
2018-07-28 04:55:55 +02:00
# ifdef GTA5SYNC_TELEMETRY
# include "TelemetryClass.h"
# endif
2017-11-22 14:59:40 +01:00
// Macros for better Overview + RAM
# define locX QString::number(picture->getSnapmaticProperties().location.x)
# define locY QString::number(picture->getSnapmaticProperties().location.y)
# define locZ QString::number(picture->getSnapmaticProperties().location.z)
# define crewID QString::number(picture->getSnapmaticProperties().crewID)
# define picArea picture->getSnapmaticProperties().location.area
# define picPath picture->getPictureFilePath()
# define picTitl StringParser::escapeString(picture->getPictureTitle())
# define plyrsList picture->getSnapmaticProperties().playersList
2020-09-28 05:33:04 +02:00
# if QT_VERSION >= 0x060000
# define created QLocale().toString(picture->getSnapmaticProperties().createdDateTime, QLocale::ShortFormat)
# else
2017-11-22 14:59:40 +01:00
# define created picture->getSnapmaticProperties().createdDateTime.toString(Qt::DefaultLocaleShortDate)
2020-09-28 05:33:04 +02:00
# endif
2017-11-22 14:59:40 +01:00
2017-10-09 08:35:48 +02:00
PictureDialog : : PictureDialog ( ProfileDatabase * profileDB , CrewDatabase * crewDB , QWidget * parent ) :
QDialog ( parent ) , profileDB ( profileDB ) , crewDB ( crewDB ) ,
ui ( new Ui : : PictureDialog )
{
primaryWindow = false ;
2017-12-12 04:45:46 +01:00
setupPictureDialog ( ) ;
2017-10-09 08:35:48 +02:00
}
2017-12-17 13:03:43 +01:00
PictureDialog : : PictureDialog ( ProfileDatabase * profileDB , CrewDatabase * crewDB , QString profileName , QWidget * parent ) :
QDialog ( parent ) , profileDB ( profileDB ) , crewDB ( crewDB ) , profileName ( profileName ) ,
ui ( new Ui : : PictureDialog )
{
primaryWindow = false ;
setupPictureDialog ( ) ;
}
2017-10-09 08:35:48 +02:00
PictureDialog : : PictureDialog ( bool primaryWindow , ProfileDatabase * profileDB , CrewDatabase * crewDB , QWidget * parent ) :
QDialog ( parent ) , primaryWindow ( primaryWindow ) , profileDB ( profileDB ) , crewDB ( crewDB ) ,
ui ( new Ui : : PictureDialog )
{
2017-12-12 04:45:46 +01:00
setupPictureDialog ( ) ;
2017-10-09 08:35:48 +02:00
}
2017-12-17 13:03:43 +01:00
PictureDialog : : PictureDialog ( bool primaryWindow , ProfileDatabase * profileDB , CrewDatabase * crewDB , QString profileName , QWidget * parent ) :
QDialog ( parent ) , primaryWindow ( primaryWindow ) , profileDB ( profileDB ) , crewDB ( crewDB ) , profileName ( profileName ) ,
ui ( new Ui : : PictureDialog )
{
setupPictureDialog ( ) ;
}
2017-12-12 04:45:46 +01:00
void PictureDialog : : setupPictureDialog ( )
2017-10-09 08:35:48 +02:00
{
// Set Window Flags
2021-02-15 23:12:44 +01:00
# if QT_VERSION >= 0x050900
setWindowFlag ( Qt : : WindowContextHelpButtonHint , false ) ;
setWindowFlag ( Qt : : CustomizeWindowHint , true ) ;
# else
2017-12-12 04:45:46 +01:00
setWindowFlags ( windowFlags ( ) ^ Qt : : WindowContextHelpButtonHint ^ Qt : : CustomizeWindowHint ) ;
2021-02-15 23:12:44 +01:00
# endif
2017-12-12 04:45:46 +01:00
# ifdef Q_OS_LINUX
2021-02-15 23:12:44 +01:00
// for stupid Window Manager like GNOME
# if QT_VERSION >= 0x050900
setWindowFlag ( Qt : : Dialog , false ) ;
setWindowFlag ( Qt : : Window , true ) ;
# else
2017-12-12 04:45:46 +01:00
setWindowFlags ( windowFlags ( ) ^ Qt : : Dialog ^ Qt : : Window ) ;
2021-02-15 23:12:44 +01:00
# endif
2017-12-12 04:45:46 +01:00
# endif
2017-10-09 08:35:48 +02:00
// Setup User Interface
ui - > setupUi ( this ) ;
windowTitleStr = this - > windowTitle ( ) ;
jsonDrawString = ui - > labJSON - > text ( ) ;
ui - > cmdManage - > setEnabled ( false ) ;
fullscreenWidget = nullptr ;
rqFullscreen = false ;
previewMode = false ;
naviEnabled = false ;
indexed = false ;
smpic = nullptr ;
2017-11-22 14:59:40 +01:00
crewStr = " " ;
2017-10-09 08:35:48 +02:00
2020-08-25 17:29:41 +02:00
// Get Snapmatic Resolution
2021-01-30 12:02:55 +01:00
const QSize snapmaticResolution = SnapmaticPicture : : getSnapmaticResolution ( ) ;
2020-08-25 17:29:41 +02:00
2017-10-09 08:35:48 +02:00
// Avatar area
qreal screenRatio = AppEnv : : screenRatio ( ) ;
2019-01-13 14:32:12 +01:00
qreal screenRatioPR = AppEnv : : screenRatioPR ( ) ;
2021-01-27 14:35:42 +01:00
if ( screenRatio ! = 1 | | screenRatioPR ! = 1 ) {
2021-04-02 19:51:05 +02:00
avatarAreaPicture = QImage ( AppEnv : : getImagesFolder ( ) % " /avatararea.png " ) . scaledToHeight ( snapmaticResolution . height ( ) * screenRatio * screenRatioPR , Qt : : FastTransformation ) ;
2017-10-09 08:35:48 +02:00
}
2021-01-27 14:35:42 +01:00
else {
2021-04-02 19:51:05 +02:00
avatarAreaPicture = QImage ( AppEnv : : getImagesFolder ( ) % " /avatararea.png " ) ;
2017-10-09 08:35:48 +02:00
}
avatarLocX = 145 ;
avatarLocY = 66 ;
avatarSize = 470 ;
2019-01-13 14:32:12 +01:00
// DPI calculation (picture)
2020-08-25 17:29:41 +02:00
ui - > labPicture - > setFixedSize ( snapmaticResolution . width ( ) * screenRatio , snapmaticResolution . height ( ) * screenRatio ) ;
2019-01-13 14:32:12 +01:00
ui - > labPicture - > setFocusPolicy ( Qt : : StrongFocus ) ;
ui - > labPicture - > setScaledContents ( true ) ;
2017-10-09 08:35:48 +02:00
// Overlay area
renderOverlayPicture ( ) ;
overlayEnabled = true ;
// Manage menu
manageMenu = new QMenu ( this ) ;
2017-12-12 04:45:46 +01:00
manageMenu - > addAction ( tr ( " Export as &Picture... " ) , this , SLOT ( exportSnapmaticPicture ( ) ) ) ;
manageMenu - > addAction ( tr ( " Export as &Snapmatic... " ) , this , SLOT ( copySnapmaticPicture ( ) ) ) ;
manageMenu - > addSeparator ( ) ;
manageMenu - > addAction ( tr ( " &Edit Properties... " ) , this , SLOT ( editSnapmaticProperties ( ) ) ) ;
2017-12-17 13:03:43 +01:00
manageMenu - > addAction ( tr ( " &Overwrite Image... " ) , this , SLOT ( editSnapmaticImage ( ) ) ) ;
2017-12-12 04:45:46 +01:00
manageMenu - > addSeparator ( ) ;
QAction * openViewerAction = manageMenu - > addAction ( tr ( " Open &Map Viewer... " ) , this , SLOT ( openPreviewMap ( ) ) ) ;
2017-11-22 14:59:40 +01:00
openViewerAction - > setShortcut ( Qt : : Key_M ) ;
2017-12-12 04:45:46 +01:00
manageMenu - > addAction ( tr ( " Open &JSON Editor... " ) , this , SLOT ( editSnapmaticRawJson ( ) ) ) ;
2017-10-09 08:35:48 +02:00
ui - > cmdManage - > setMenu ( manageMenu ) ;
// Global map
globalMap = GlobalString : : getGlobalMap ( ) ;
2018-01-11 08:41:00 +01:00
// Set Icon for Close Button
2021-01-27 14:35:42 +01:00
if ( QIcon : : hasThemeIcon ( " dialog-close " ) ) {
2017-10-09 08:35:48 +02:00
ui - > cmdClose - > setIcon ( QIcon : : fromTheme ( " dialog-close " ) ) ;
}
2021-01-27 14:35:42 +01:00
else if ( QIcon : : hasThemeIcon ( " gtk-close " ) ) {
2018-01-11 08:41:00 +01:00
ui - > cmdClose - > setIcon ( QIcon : : fromTheme ( " gtk-close " ) ) ;
}
2017-10-09 08:35:48 +02:00
installEventFilter ( this ) ;
2018-12-25 21:05:09 +01:00
// DPI calculation
ui - > hlButtons - > setSpacing ( 6 * screenRatio ) ;
ui - > vlButtons - > setSpacing ( 6 * screenRatio ) ;
ui - > vlButtons - > setContentsMargins ( 0 , 0 , 5 * screenRatio , 5 * screenRatio ) ;
ui - > jsonLayout - > setContentsMargins ( 4 * screenRatio , 10 * screenRatio , 4 * screenRatio , 4 * screenRatio ) ;
2017-10-09 08:35:48 +02:00
// Pre-adapt window for DPI
2021-01-30 12:02:55 +01:00
const QSize windowSize ( snapmaticResolution . width ( ) * screenRatio , snapmaticResolution . height ( ) * screenRatio ) ;
setMinimumSize ( windowSize ) ;
setMaximumSize ( windowSize ) ;
2017-10-09 08:35:48 +02:00
}
PictureDialog : : ~ PictureDialog ( )
{
delete ui ;
}
void PictureDialog : : closeEvent ( QCloseEvent * ev )
{
Q_UNUSED ( ev )
2017-12-12 04:45:46 +01:00
if ( primaryWindow )
2017-10-09 08:35:48 +02:00
emit endDatabaseThread ( ) ;
}
void PictureDialog : : addPreviousNextButtons ( )
{
2020-08-24 16:35:52 +02:00
QToolBar * uiToolbar = new QToolBar ( " Picture Toolbar " , this ) ;
2020-08-25 12:53:21 +02:00
# if QT_VERSION < 0x050600
qreal screenRatio = AppEnv : : screenRatio ( ) ;
if ( screenRatio ! = 1 ) {
QSize iconSize = uiToolbar - > iconSize ( ) ;
uiToolbar - > setIconSize ( QSize ( iconSize . width ( ) * screenRatio , iconSize . height ( ) * screenRatio ) ) ;
}
# endif
2020-08-24 16:35:52 +02:00
uiToolbar - > setSizePolicy ( QSizePolicy : : Minimum , QSizePolicy : : Minimum ) ;
2020-08-25 12:53:21 +02:00
uiToolbar - > setObjectName ( " UiToolbar " ) ;
2021-04-02 19:51:05 +02:00
uiToolbar - > addAction ( QIcon ( AppEnv : : getImagesFolder ( ) % " /back.svgz " ) , " " , this , SLOT ( previousPictureRequestedSlot ( ) ) ) ;
uiToolbar - > addAction ( QIcon ( AppEnv : : getImagesFolder ( ) % " /next.svgz " ) , " " , this , SLOT ( nextPictureRequestedSlot ( ) ) ) ;
2021-01-30 12:02:55 +01:00
# ifdef Q_OS_MAC
# if QT_VERSION >= 0x050000
uiToolbar - > setStyle ( QStyleFactory : : create ( " Fusion " ) ) ;
# endif
# endif
2020-08-24 16:35:52 +02:00
layout ( ) - > setMenuBar ( uiToolbar ) ;
naviEnabled = true ;
2017-10-09 08:35:48 +02:00
}
2021-01-30 12:02:55 +01:00
void PictureDialog : : adaptDialogSize ( )
2017-10-09 08:35:48 +02:00
{
2021-01-30 12:02:55 +01:00
int newDialogHeight = ( SnapmaticPicture : : getSnapmaticResolution ( ) . height ( ) * AppEnv : : screenRatio ( ) ) + ui - > jsonFrame - > heightForWidth ( width ( ) ) ;
if ( naviEnabled )
newDialogHeight = newDialogHeight + layout ( ) - > menuBar ( ) - > height ( ) ;
const QSize windowSize ( width ( ) , newDialogHeight ) ;
setMinimumSize ( windowSize ) ;
setMaximumSize ( windowSize ) ;
2017-10-09 08:35:48 +02:00
}
2019-04-22 04:59:26 +02:00
void PictureDialog : : styliseDialog ( )
2017-10-09 08:35:48 +02:00
{
2020-09-26 16:12:55 +02:00
# ifdef Q_OS_WIN
2021-02-11 20:20:52 +01:00
BOOL isEnabled ;
DwmIsCompositionEnabled ( & isEnabled ) ;
if ( isEnabled = = TRUE ) {
MARGINS margins = { 0 , 0 , qRound ( layout ( ) - > menuBar ( ) - > height ( ) * AppEnv : : screenRatioPR ( ) ) , 0 } ;
HRESULT hr = S_OK ;
hr = DwmExtendFrameIntoClientArea ( reinterpret_cast < HWND > ( winId ( ) ) , & margins ) ;
if ( SUCCEEDED ( hr ) ) {
setStyleSheet ( " PictureDialog{background:transparent} " ) ;
}
2017-10-09 08:35:48 +02:00
}
2020-11-25 00:36:12 +01:00
else {
2021-02-11 20:20:52 +01:00
MARGINS margins = { 0 , 0 , 0 , 0 } ;
DwmExtendFrameIntoClientArea ( reinterpret_cast < HWND > ( winId ( ) ) , & margins ) ;
bool colorOk = false ;
QSettings dwmRegistry ( " HKEY_CURRENT_USER \\ Software \\ Microsoft \\ Windows \\ DWM " , QSettings : : NativeFormat ) ;
QRgb color = dwmRegistry . value ( " ColorizationColor " ) . toUInt ( & colorOk ) ;
if ( colorOk ) {
setStyleSheet ( QString ( " PictureDialog{background:%1} " ) . arg ( QColor : : fromRgba ( color ) . name ( ) ) ) ;
}
else {
HRESULT hr = S_OK ;
BOOL isOpaqueBlend ;
DWORD colorization ;
hr = DwmGetColorizationColor ( & colorization , & isOpaqueBlend ) ;
if ( SUCCEEDED ( hr ) & & isOpaqueBlend = = FALSE ) {
color = colorization ;
setStyleSheet ( QString ( " PictureDialog{background:%1} " ) . arg ( QColor : : fromRgba ( color ) . name ( ) ) ) ;
}
else {
setStyleSheet ( " PictureDialog{background:palette(window)} " ) ;
}
}
2017-10-09 08:35:48 +02:00
}
2021-02-11 20:20:52 +01:00
ui - > jsonFrame - > setStyleSheet ( " QFrame{background:palette(window)} " ) ;
2017-10-09 08:35:48 +02:00
# endif
}
2020-09-26 16:12:55 +02:00
# ifdef Q_OS_WIN
2021-02-26 19:59:05 +01:00
# if QT_VERSION >= 0x050000
2021-02-11 23:09:49 +01:00
# if QT_VERSION >= 0x060000
bool PictureDialog : : nativeEvent ( const QByteArray & eventType , void * message , qintptr * result )
2021-02-26 19:59:05 +01:00
# else
2021-02-11 20:20:52 +01:00
bool PictureDialog : : nativeEvent ( const QByteArray & eventType , void * message , long * result )
2021-02-26 19:59:05 +01:00
# endif
2021-02-11 20:20:52 +01:00
{
MSG * msg = reinterpret_cast < MSG * > ( message ) ;
2021-02-11 23:09:49 +01:00
if ( msg - > message = = 0x031e | | msg - > message = = 0x0320 ) {
2021-02-11 20:20:52 +01:00
styliseDialog ( ) ;
2017-10-09 08:35:48 +02:00
}
2021-02-11 20:20:52 +01:00
return QWidget : : nativeEvent ( eventType , message , result ) ;
}
2017-10-09 08:35:48 +02:00
# endif
# endif
void PictureDialog : : nextPictureRequestedSlot ( )
{
emit nextPictureRequested ( ) ;
}
void PictureDialog : : previousPictureRequestedSlot ( )
{
emit previousPictureRequested ( ) ;
}
bool PictureDialog : : eventFilter ( QObject * obj , QEvent * ev )
{
bool returnValue = false ;
2021-01-27 14:35:42 +01:00
if ( obj = = this | | obj = = ui - > labPicture ) {
if ( ev - > type ( ) = = QEvent : : KeyPress ) {
2017-12-12 04:45:46 +01:00
QKeyEvent * keyEvent = dynamic_cast < QKeyEvent * > ( ev ) ;
2021-01-27 14:35:42 +01:00
switch ( keyEvent - > key ( ) ) {
2017-10-09 08:35:48 +02:00
case Qt : : Key_Left :
emit previousPictureRequested ( ) ;
returnValue = true ;
break ;
case Qt : : Key_Right :
emit nextPictureRequested ( ) ;
returnValue = true ;
break ;
case Qt : : Key_1 :
2021-01-27 14:35:42 +01:00
if ( previewMode ) {
2017-10-09 08:35:48 +02:00
previewMode = false ;
renderPicture ( ) ;
}
2021-01-27 14:35:42 +01:00
else {
2017-10-09 08:35:48 +02:00
previewMode = true ;
renderPicture ( ) ;
}
break ;
case Qt : : Key_2 :
2021-01-27 14:35:42 +01:00
if ( overlayEnabled ) {
2017-10-09 08:35:48 +02:00
overlayEnabled = false ;
if ( ! previewMode ) renderPicture ( ) ;
}
2021-01-27 14:35:42 +01:00
else {
2017-10-09 08:35:48 +02:00
overlayEnabled = true ;
if ( ! previewMode ) renderPicture ( ) ;
}
break ;
case Qt : : Key_M :
openPreviewMap ( ) ;
returnValue = true ;
break ;
# if QT_VERSION >= 0x050300
case Qt : : Key_Exit :
ui - > cmdClose - > click ( ) ;
returnValue = true ;
break ;
# endif
case Qt : : Key_Enter : case Qt : : Key_Return :
on_labPicture_mouseDoubleClicked ( Qt : : LeftButton ) ;
returnValue = true ;
break ;
case Qt : : Key_Escape :
ui - > cmdClose - > click ( ) ;
returnValue = true ;
break ;
}
}
2020-09-26 16:12:55 +02:00
# ifdef Q_OS_WIN
2021-02-11 20:20:52 +01:00
# if QT_VERSION >= 0x050000
2021-01-27 14:35:42 +01:00
if ( obj ! = ui - > labPicture & & naviEnabled ) {
if ( ev - > type ( ) = = QEvent : : MouseButtonPress ) {
2017-12-12 04:45:46 +01:00
QMouseEvent * mouseEvent = dynamic_cast < QMouseEvent * > ( ev ) ;
2021-01-27 14:35:42 +01:00
if ( mouseEvent - > pos ( ) . y ( ) < = layout ( ) - > menuBar ( ) - > height ( ) ) {
if ( mouseEvent - > button ( ) = = Qt : : LeftButton ) {
2017-12-12 04:45:46 +01:00
dragPosition = mouseEvent - > pos ( ) ;
dragStart = true ;
}
}
}
2021-01-27 14:35:42 +01:00
if ( ev - > type ( ) = = QEvent : : MouseButtonRelease ) {
2017-12-12 04:45:46 +01:00
QMouseEvent * mouseEvent = dynamic_cast < QMouseEvent * > ( ev ) ;
2021-01-27 14:35:42 +01:00
if ( mouseEvent - > pos ( ) . y ( ) < = layout ( ) - > menuBar ( ) - > height ( ) ) {
if ( mouseEvent - > button ( ) = = Qt : : LeftButton ) {
2017-12-12 04:45:46 +01:00
dragStart = false ;
}
}
}
2021-02-26 19:59:05 +01:00
if ( dragStart & & ev - > type ( ) = = QEvent : : MouseMove ) {
2017-12-12 04:45:46 +01:00
QMouseEvent * mouseEvent = dynamic_cast < QMouseEvent * > ( ev ) ;
2021-01-27 14:35:42 +01:00
if ( mouseEvent - > pos ( ) . y ( ) < = layout ( ) - > menuBar ( ) - > height ( ) ) {
if ( mouseEvent - > buttons ( ) & Qt : : LeftButton ) {
2021-02-26 19:59:05 +01:00
const QPoint diff = mouseEvent - > pos ( ) - dragPosition ;
2017-12-12 04:45:46 +01:00
move ( QPoint ( pos ( ) + diff ) ) ;
updateGeometry ( ) ;
}
}
}
}
# endif
# endif
2017-10-09 08:35:48 +02:00
}
return returnValue ;
}
void PictureDialog : : triggerFullscreenDoubeClick ( )
{
on_labPicture_mouseDoubleClicked ( Qt : : LeftButton ) ;
}
void PictureDialog : : exportCustomContextMenuRequestedPrivate ( const QPoint & pos , bool fullscreen )
{
rqFullscreen = fullscreen ;
manageMenu - > popup ( pos ) ;
}
void PictureDialog : : exportCustomContextMenuRequested ( const QPoint & pos )
{
exportCustomContextMenuRequestedPrivate ( pos , true ) ;
}
void PictureDialog : : mousePressEvent ( QMouseEvent * ev )
{
QDialog : : mousePressEvent ( ev ) ;
}
void PictureDialog : : dialogNextPictureRequested ( )
{
emit nextPictureRequested ( ) ;
}
void PictureDialog : : dialogPreviousPictureRequested ( )
{
emit previousPictureRequested ( ) ;
}
void PictureDialog : : renderOverlayPicture ( )
{
// Generating Overlay Preview
qreal screenRatio = AppEnv : : screenRatio ( ) ;
2019-01-13 14:32:12 +01:00
qreal screenRatioPR = AppEnv : : screenRatioPR ( ) ;
QRect preferedRect = QRect ( 0 , 0 , 200 * screenRatio * screenRatioPR , 160 * screenRatio * screenRatioPR ) ;
2017-10-09 08:35:48 +02:00
QString overlayText = tr ( " Key 1 - Avatar Preview Mode \n Key 2 - Toggle Overlay \n Arrow Keys - Navigate " ) ;
QFont overlayPainterFont ;
2019-01-13 14:32:12 +01:00
overlayPainterFont . setPixelSize ( 12 * screenRatio * screenRatioPR ) ;
2017-12-12 04:45:46 +01:00
QFontMetrics fontMetrics ( overlayPainterFont ) ;
QRect overlaySpace = fontMetrics . boundingRect ( preferedRect , Qt : : AlignLeft | Qt : : AlignTop | Qt : : TextDontClip | Qt : : TextWordWrap , overlayText ) ;
2017-10-09 08:35:48 +02:00
int hOverlay = Qt : : AlignTop ;
2021-01-27 14:35:42 +01:00
if ( overlaySpace . height ( ) < 74 * screenRatio * screenRatioPR ) {
2017-10-09 08:35:48 +02:00
hOverlay = Qt : : AlignVCenter ;
2019-01-13 14:32:12 +01:00
preferedRect . setHeight ( 71 * screenRatio * screenRatioPR ) ;
overlaySpace . setHeight ( 80 * screenRatio * screenRatioPR ) ;
2017-10-09 08:35:48 +02:00
}
2021-01-27 14:35:42 +01:00
else {
2019-01-13 14:32:12 +01:00
overlaySpace . setHeight ( overlaySpace . height ( ) + 6 * screenRatio * screenRatioPR ) ;
2017-10-09 08:35:48 +02:00
}
2017-12-12 04:45:46 +01:00
QImage overlayImage ( overlaySpace . size ( ) , QImage : : Format_ARGB32_Premultiplied ) ;
overlayImage . fill ( Qt : : transparent ) ;
QPainter overlayPainter ( & overlayImage ) ;
2017-10-09 08:35:48 +02:00
overlayPainter . setPen ( QColor : : fromRgb ( 255 , 255 , 255 , 255 ) ) ;
overlayPainter . setFont ( overlayPainterFont ) ;
overlayPainter . drawText ( preferedRect , Qt : : AlignLeft | hOverlay | Qt : : TextDontClip | Qt : : TextWordWrap , overlayText ) ;
overlayPainter . end ( ) ;
2021-01-27 14:35:42 +01:00
if ( overlaySpace . width ( ) < 194 * screenRatio * screenRatioPR ) {
2019-01-13 14:32:12 +01:00
overlaySpace . setWidth ( 200 * screenRatio * screenRatioPR ) ;
2017-10-09 08:35:48 +02:00
}
2021-01-27 14:35:42 +01:00
else {
2019-01-13 14:32:12 +01:00
overlaySpace . setWidth ( overlaySpace . width ( ) + 6 * screenRatio * screenRatioPR ) ;
2017-10-09 08:35:48 +02:00
}
QImage overlayBorderImage ( overlaySpace . width ( ) , overlaySpace . height ( ) , QImage : : Format_ARGB6666_Premultiplied ) ;
overlayBorderImage . fill ( QColor ( 15 , 15 , 15 , 162 ) ) ;
overlayTempImage = QImage ( overlaySpace . width ( ) , overlaySpace . height ( ) , QImage : : Format_ARGB6666_Premultiplied ) ;
overlayTempImage . fill ( Qt : : transparent ) ;
QPainter overlayTempPainter ( & overlayTempImage ) ;
overlayTempPainter . drawImage ( 0 , 0 , overlayBorderImage ) ;
2019-01-13 14:32:12 +01:00
overlayTempPainter . drawImage ( 3 * screenRatio * screenRatioPR , 3 * screenRatio * screenRatioPR , overlayImage ) ;
2017-10-09 08:35:48 +02:00
overlayTempPainter . end ( ) ;
}
void PictureDialog : : setSnapmaticPicture ( SnapmaticPicture * picture , bool readOk , bool _indexed , int _index )
{
2020-11-25 00:36:12 +01:00
if ( smpic ! = nullptr ) {
2018-02-09 22:28:31 +01:00
QObject : : disconnect ( smpic , SIGNAL ( updated ( ) ) , this , SLOT ( updated ( ) ) ) ;
QObject : : disconnect ( smpic , SIGNAL ( customSignal ( QString ) ) , this , SLOT ( customSignal ( QString ) ) ) ;
}
2017-10-09 08:35:48 +02:00
snapmaticPicture = QImage ( ) ;
indexed = _indexed ;
index = _index ;
smpic = picture ;
2020-11-25 00:36:12 +01:00
if ( ! readOk ) {
2017-10-09 08:35:48 +02:00
QMessageBox : : warning ( this , tr ( " Snapmatic Picture Viewer " ) , tr ( " Failed at %1 " ) . arg ( picture - > getLastStep ( ) ) ) ;
return ;
}
2020-11-25 00:36:12 +01:00
if ( picture - > isPicOk ( ) ) {
2017-10-09 08:35:48 +02:00
snapmaticPicture = picture - > getImage ( ) ;
renderPicture ( ) ;
ui - > cmdManage - > setEnabled ( true ) ;
}
2020-11-25 00:36:12 +01:00
if ( picture - > isJsonOk ( ) ) {
2017-12-12 04:45:46 +01:00
crewStr = crewDB - > getCrewName ( crewID ) ;
2020-11-25 00:36:12 +01:00
if ( globalMap . contains ( picArea ) ) {
picAreaStr = globalMap . value ( picArea ) ;
2017-10-09 08:35:48 +02:00
}
2020-11-25 00:36:12 +01:00
else {
2017-10-09 08:35:48 +02:00
picAreaStr = picArea ;
}
2018-02-04 02:34:16 +01:00
setWindowTitle ( windowTitleStr . arg ( picTitl ) ) ;
2017-10-09 08:35:48 +02:00
ui - > labJSON - > setText ( jsonDrawString . arg ( locX , locY , locZ , generatePlayersString ( ) , generateCrewString ( ) , picTitl , picAreaStr , created ) ) ;
2021-01-30 12:02:55 +01:00
QTimer : : singleShot ( 0 , this , SLOT ( adaptDialogSize ( ) ) ) ;
2017-10-09 08:35:48 +02:00
}
2020-11-25 00:36:12 +01:00
else {
2017-10-09 08:35:48 +02:00
ui - > labJSON - > setText ( jsonDrawString . arg ( " 0 " , " 0 " , " 0 " , tr ( " No Players " ) , tr ( " No Crew " ) , tr ( " Unknown Location " ) ) ) ;
2021-01-30 12:02:55 +01:00
QTimer : : singleShot ( 0 , this , SLOT ( adaptDialogSize ( ) ) ) ;
2017-10-09 08:35:48 +02:00
}
QObject : : connect ( smpic , SIGNAL ( updated ( ) ) , this , SLOT ( updated ( ) ) ) ;
2017-12-17 13:03:43 +01:00
QObject : : connect ( smpic , SIGNAL ( customSignal ( QString ) ) , this , SLOT ( customSignal ( QString ) ) ) ;
2017-10-09 08:35:48 +02:00
emit newPictureCommited ( snapmaticPicture ) ;
}
void PictureDialog : : setSnapmaticPicture ( SnapmaticPicture * picture , bool readOk , int index )
{
setSnapmaticPicture ( picture , readOk , true , index ) ;
}
void PictureDialog : : setSnapmaticPicture ( SnapmaticPicture * picture , bool readOk )
{
setSnapmaticPicture ( picture , readOk , false , 0 ) ;
}
void PictureDialog : : setSnapmaticPicture ( SnapmaticPicture * picture , int index )
{
setSnapmaticPicture ( picture , true , index ) ;
}
void PictureDialog : : setSnapmaticPicture ( SnapmaticPicture * picture )
{
setSnapmaticPicture ( picture , true ) ;
}
void PictureDialog : : renderPicture ( )
{
2020-11-25 00:36:12 +01:00
const qreal screenRatio = AppEnv : : screenRatio ( ) ;
const qreal screenRatioPR = AppEnv : : screenRatioPR ( ) ;
const QSize snapmaticResolution ( SnapmaticPicture : : getSnapmaticResolution ( ) ) ;
const QSize renderResolution ( snapmaticResolution . width ( ) * screenRatio * screenRatioPR , snapmaticResolution . height ( ) * screenRatio * screenRatioPR ) ;
QPixmap shownImagePixmap ( renderResolution ) ;
shownImagePixmap . fill ( Qt : : black ) ;
QPainter shownImagePainter ( & shownImagePixmap ) ;
const QImage renderImage = snapmaticPicture . scaled ( renderResolution , Qt : : KeepAspectRatio , Qt : : SmoothTransformation ) ;
if ( renderImage . width ( ) < renderResolution . width ( ) ) {
shownImagePainter . drawImage ( ( renderResolution . width ( ) - renderImage . width ( ) ) / 2 , 0 , renderImage , Qt : : AutoColor ) ;
}
else if ( renderImage . height ( ) < renderResolution . height ( ) ) {
shownImagePainter . drawImage ( 0 , ( renderResolution . height ( ) - renderImage . height ( ) ) / 2 , renderImage , Qt : : AutoColor ) ;
}
else {
shownImagePainter . drawImage ( 0 , 0 , renderImage , Qt : : AutoColor ) ;
}
if ( previewMode ) {
QFont shownImagePainterFont ;
shownImagePainterFont . setPixelSize ( 12 * screenRatio * screenRatioPR ) ;
shownImagePainter . drawImage ( 0 , 0 , avatarAreaPicture ) ;
shownImagePainter . setPen ( QColor : : fromRgb ( 255 , 255 , 255 , 255 ) ) ;
shownImagePainter . setFont ( shownImagePainterFont ) ;
shownImagePainter . drawText ( QRect ( 3 * screenRatio * screenRatioPR , 3 * screenRatio * screenRatioPR , 140 * screenRatio * screenRatioPR , snapmaticResolution . height ( ) * screenRatio * screenRatioPR ) , Qt : : AlignLeft | Qt : : TextWordWrap , tr ( " Avatar Preview Mode \n Press 1 for Default View " ) ) ;
}
else if ( overlayEnabled ) {
shownImagePainter . drawImage ( 3 * screenRatio * screenRatioPR , 3 * screenRatio * screenRatioPR , overlayTempImage , Qt : : AutoColor ) ;
}
shownImagePainter . end ( ) ;
2019-01-13 14:32:12 +01:00
# if QT_VERSION >= 0x050600
2020-11-25 00:36:12 +01:00
shownImagePixmap . setDevicePixelRatio ( screenRatioPR ) ;
2019-01-13 14:32:12 +01:00
# endif
2020-11-25 00:36:12 +01:00
ui - > labPicture - > setPixmap ( shownImagePixmap ) ;
2017-10-09 08:35:48 +02:00
}
void PictureDialog : : crewNameUpdated ( )
{
2017-11-22 14:59:40 +01:00
SnapmaticPicture * picture = smpic ; // used by macro
QString crewIDStr = crewID ;
2021-01-27 14:35:42 +01:00
if ( crewIDStr = = crewStr ) {
2017-11-22 14:59:40 +01:00
crewStr = crewDB - > getCrewName ( crewIDStr ) ;
2017-10-09 08:35:48 +02:00
ui - > labJSON - > setText ( jsonDrawString . arg ( locX , locY , locZ , generatePlayersString ( ) , generateCrewString ( ) , picTitl , picAreaStr , created ) ) ;
2021-01-30 12:02:55 +01:00
QTimer : : singleShot ( 0 , this , SLOT ( adaptDialogSize ( ) ) ) ;
2017-10-09 08:35:48 +02:00
}
}
void PictureDialog : : playerNameUpdated ( )
{
2017-11-22 14:59:40 +01:00
SnapmaticPicture * picture = smpic ; // used by macro
2021-01-27 14:35:42 +01:00
if ( plyrsList . count ( ) > = 1 ) {
2017-10-09 08:35:48 +02:00
ui - > labJSON - > setText ( jsonDrawString . arg ( locX , locY , locZ , generatePlayersString ( ) , generateCrewString ( ) , picTitl , picAreaStr , created ) ) ;
2021-01-30 12:02:55 +01:00
QTimer : : singleShot ( 0 , this , SLOT ( adaptDialogSize ( ) ) ) ;
2017-10-09 08:35:48 +02:00
}
}
QString PictureDialog : : generateCrewString ( )
{
2017-11-22 14:59:40 +01:00
SnapmaticPicture * picture = smpic ; // used by macro
2019-07-24 20:05:34 +02:00
const QString crewIDStr = crewID ; // save operation time
2021-01-27 14:35:42 +01:00
if ( crewIDStr ! = " 0 " & & ! crewIDStr . isEmpty ( ) ) {
2019-07-24 20:05:34 +02:00
if ( crewIDStr ! = crewStr ) {
return QString ( " <a href= \" https://socialclub.rockstargames.com/crew/ " % QString ( crewStr ) . replace ( " " , " _ " ) % " / " % crewIDStr % " \" > " % crewStr % " </a> " ) ;
}
else {
return QString ( crewIDStr ) ;
}
2017-10-09 08:35:48 +02:00
}
return tr ( " No Crew " ) ;
}
QString PictureDialog : : generatePlayersString ( )
{
2017-11-22 14:59:40 +01:00
SnapmaticPicture * picture = smpic ; // used by macro
const QStringList playersList = plyrsList ; // save operation time
2017-10-09 08:35:48 +02:00
QString plyrsStr ;
2020-11-25 00:36:12 +01:00
if ( playersList . length ( ) > = 1 ) {
for ( const QString & player : playersList ) {
2019-07-24 20:05:34 +02:00
const QString playerName = profileDB - > getPlayerName ( player ) ;
if ( player ! = playerName ) {
plyrsStr + = " , <a href= \" https://socialclub.rockstargames.com/member/ " % playerName % " / " % player % " \" > " % playerName % " </a> " ;
}
else {
plyrsStr + = " , " % player ;
}
2017-10-09 08:35:48 +02:00
}
2017-12-12 04:45:46 +01:00
plyrsStr . remove ( 0 , 2 ) ;
2017-10-09 08:35:48 +02:00
}
2020-11-25 00:36:12 +01:00
else {
2017-10-09 08:35:48 +02:00
plyrsStr = tr ( " No Players " ) ;
}
return plyrsStr ;
}
void PictureDialog : : exportSnapmaticPicture ( )
{
2020-11-25 00:36:12 +01:00
if ( rqFullscreen & & fullscreenWidget ! = nullptr ) {
2017-10-09 08:35:48 +02:00
PictureExport : : exportAsPicture ( fullscreenWidget , smpic ) ;
}
2020-11-25 00:36:12 +01:00
else {
2017-10-09 08:35:48 +02:00
PictureExport : : exportAsPicture ( this , smpic ) ;
}
}
void PictureDialog : : copySnapmaticPicture ( )
{
2020-11-25 00:36:12 +01:00
if ( rqFullscreen & & fullscreenWidget ! = nullptr ) {
2017-10-09 08:35:48 +02:00
PictureExport : : exportAsSnapmatic ( fullscreenWidget , smpic ) ;
}
2020-11-25 00:36:12 +01:00
else {
2017-10-09 08:35:48 +02:00
PictureExport : : exportAsSnapmatic ( this , smpic ) ;
}
}
void PictureDialog : : on_labPicture_mouseDoubleClicked ( Qt : : MouseButton button )
{
2020-11-25 00:36:12 +01:00
if ( button = = Qt : : LeftButton ) {
2020-09-28 05:33:04 +02:00
# if QT_VERSION >= 0x060000
QRect desktopRect = QApplication : : screenAt ( pos ( ) ) - > geometry ( ) ;
# else
2017-10-09 08:35:48 +02:00
QRect desktopRect = QApplication : : desktop ( ) - > screenGeometry ( this ) ;
2020-09-28 05:33:04 +02:00
# endif
2017-10-09 08:35:48 +02:00
PictureWidget * pictureWidget = new PictureWidget ( this ) ; // Work!
pictureWidget - > setObjectName ( " PictureWidget " ) ;
2021-02-15 23:12:44 +01:00
# if QT_VERSION >= 0x050900
pictureWidget - > setWindowFlag ( Qt : : FramelessWindowHint , true ) ;
pictureWidget - > setWindowFlag ( Qt : : MaximizeUsingFullscreenGeometryHint , true ) ;
# elif QT_VERSION >= 0x050600
2020-09-26 16:12:55 +02:00
pictureWidget - > setWindowFlags ( pictureWidget - > windowFlags ( ) ^ Qt : : FramelessWindowHint ^ Qt : : MaximizeUsingFullscreenGeometryHint ) ;
2017-10-09 08:35:48 +02:00
# else
2020-09-26 16:12:55 +02:00
pictureWidget - > setWindowFlags ( pictureWidget - > windowFlags ( ) ^ Qt : : FramelessWindowHint ) ;
2017-10-09 08:35:48 +02:00
# endif
2018-02-04 02:34:16 +01:00
pictureWidget - > setWindowTitle ( windowTitle ( ) ) ;
2020-11-25 00:36:12 +01:00
pictureWidget - > setStyleSheet ( " QLabel#pictureLabel{background-color:black;} " ) ;
pictureWidget - > setImage ( smpic - > getImage ( ) , desktopRect ) ;
2017-10-09 08:35:48 +02:00
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 - > move ( desktopRect . x ( ) , desktopRect . y ( ) ) ;
pictureWidget - > resize ( desktopRect . width ( ) , desktopRect . height ( ) ) ;
pictureWidget - > showFullScreen ( ) ;
pictureWidget - > setFocus ( ) ;
pictureWidget - > raise ( ) ;
pictureWidget - > exec ( ) ;
fullscreenWidget = nullptr ; // Work!
delete pictureWidget ; // Work!
}
}
void PictureDialog : : on_labPicture_customContextMenuRequested ( const QPoint & pos )
{
exportCustomContextMenuRequestedPrivate ( ui - > labPicture - > mapToGlobal ( pos ) , false ) ;
}
bool PictureDialog : : isIndexed ( )
{
return indexed ;
}
int PictureDialog : : getIndex ( )
{
return index ;
}
void PictureDialog : : openPreviewMap ( )
{
2017-11-22 14:59:40 +01:00
SnapmaticPicture * picture = smpic ;
2021-02-15 23:12:44 +01:00
SnapmaticProperties currentProperties = picture - > getSnapmaticProperties ( ) ;
2017-11-12 15:58:59 +01:00
MapLocationDialog * mapLocDialog ;
2021-01-27 14:35:42 +01:00
if ( rqFullscreen & & fullscreenWidget ! = nullptr ) {
2021-02-15 23:12:44 +01:00
mapLocDialog = new MapLocationDialog ( currentProperties . location . x , currentProperties . location . y , fullscreenWidget ) ;
2017-10-09 08:35:48 +02:00
}
2021-01-27 14:35:42 +01:00
else {
2021-02-15 23:12:44 +01:00
mapLocDialog = new MapLocationDialog ( currentProperties . location . x , currentProperties . location . y , this ) ;
2017-11-12 15:58:59 +01:00
}
2021-02-15 23:12:44 +01:00
mapLocDialog - > setCayoPerico ( currentProperties . location . isCayoPerico ) ;
2017-11-12 15:58:59 +01:00
mapLocDialog - > setWindowIcon ( windowIcon ( ) ) ;
mapLocDialog - > setModal ( true ) ;
2017-12-17 13:03:43 +01:00
# ifndef Q_OS_ANDROID
2017-11-12 15:58:59 +01:00
mapLocDialog - > show ( ) ;
2017-12-17 13:03:43 +01:00
# else
mapLocDialog - > showMaximized ( ) ;
# endif
2017-11-12 15:58:59 +01:00
mapLocDialog - > exec ( ) ;
2021-01-27 14:35:42 +01:00
if ( mapLocDialog - > propUpdated ( ) ) {
2017-11-12 15:58:59 +01:00
// Update Snapmatic Properties
2021-02-15 23:12:44 +01:00
currentProperties . location . x = mapLocDialog - > getXpos ( ) ;
currentProperties . location . y = mapLocDialog - > getYpos ( ) ;
currentProperties . location . z = 0 ;
2017-11-12 15:58:59 +01:00
// Update Snapmatic Picture
2017-11-22 14:59:40 +01:00
QString currentFilePath = picture - > getPictureFilePath ( ) ;
QString originalFilePath = picture - > getOriginalPictureFilePath ( ) ;
2017-11-12 15:58:59 +01:00
QString backupFileName = originalFilePath % " .bak " ;
2021-01-27 14:35:42 +01:00
if ( ! QFile : : exists ( backupFileName ) ) {
2017-11-12 15:58:59 +01:00
QFile : : copy ( currentFilePath , backupFileName ) ;
}
2017-11-22 14:59:40 +01:00
SnapmaticProperties fallbackProperties = picture - > getSnapmaticProperties ( ) ;
2021-02-15 23:12:44 +01:00
picture - > setSnapmaticProperties ( currentProperties ) ;
2021-01-27 14:35:42 +01:00
if ( ! picture - > exportPicture ( currentFilePath ) ) {
2017-11-12 15:58:59 +01:00
QMessageBox : : warning ( this , SnapmaticEditor : : tr ( " Snapmatic Properties " ) , SnapmaticEditor : : tr ( " Patching of Snapmatic Properties failed because of I/O Error " ) ) ;
2017-11-22 14:59:40 +01:00
picture - > setSnapmaticProperties ( fallbackProperties ) ;
2017-11-12 15:58:59 +01:00
}
2021-01-27 14:35:42 +01:00
else {
2017-11-12 15:58:59 +01:00
updated ( ) ;
2018-07-28 04:55:55 +02:00
# ifdef GTA5SYNC_TELEMETRY
QSettings telemetrySettings ( GTA5SYNC_APPVENDOR , GTA5SYNC_APPSTR ) ;
telemetrySettings . beginGroup ( " Telemetry " ) ;
bool pushUsageData = telemetrySettings . value ( " PushUsageData " , false ) . toBool ( ) ;
telemetrySettings . endGroup ( ) ;
2021-01-27 14:35:42 +01:00
if ( pushUsageData & & Telemetry - > canPush ( ) ) {
2018-07-28 04:55:55 +02:00
QJsonDocument jsonDocument ;
QJsonObject jsonObject ;
jsonObject [ " Type " ] = " LocationEdited " ;
jsonObject [ " ExtraFlags " ] = " Viewer " ;
jsonObject [ " EditedSize " ] = QString : : number ( picture - > getContentMaxLength ( ) ) ;
2021-01-27 14:35:42 +01:00
# if QT_VERSION >= 0x060000
jsonObject [ " EditedTime " ] = QString : : number ( QDateTime : : currentDateTimeUtc ( ) . toSecsSinceEpoch ( ) ) ;
# else
2018-07-28 04:55:55 +02:00
jsonObject [ " EditedTime " ] = QString : : number ( QDateTime : : currentDateTimeUtc ( ) . toTime_t ( ) ) ;
2021-01-27 14:35:42 +01:00
# endif
2018-07-28 04:55:55 +02:00
jsonDocument . setObject ( jsonObject ) ;
Telemetry - > push ( TelemetryCategory : : PersonalData , jsonDocument ) ;
}
# endif
2017-11-12 15:58:59 +01:00
}
2017-10-09 08:35:48 +02:00
}
2017-11-12 15:58:59 +01:00
delete mapLocDialog ;
2017-10-09 08:35:48 +02:00
}
void PictureDialog : : editSnapmaticProperties ( )
{
2017-11-22 14:59:40 +01:00
SnapmaticPicture * picture = smpic ;
2017-10-09 08:35:48 +02:00
SnapmaticEditor * snapmaticEditor ;
2021-01-27 14:35:42 +01:00
if ( rqFullscreen & & fullscreenWidget ! = nullptr ) {
2017-12-12 04:45:46 +01:00
snapmaticEditor = new SnapmaticEditor ( crewDB , profileDB , fullscreenWidget ) ;
2017-10-09 08:35:48 +02:00
}
2021-01-27 14:35:42 +01:00
else {
2017-12-12 04:45:46 +01:00
snapmaticEditor = new SnapmaticEditor ( crewDB , profileDB , this ) ;
2017-10-09 08:35:48 +02:00
}
snapmaticEditor - > setWindowIcon ( windowIcon ( ) ) ;
2017-11-22 14:59:40 +01:00
snapmaticEditor - > setSnapmaticPicture ( picture ) ;
2017-10-09 08:35:48 +02:00
snapmaticEditor - > setModal ( true ) ;
2017-12-17 13:03:43 +01:00
# ifndef Q_OS_ANDROID
2017-11-22 14:59:40 +01:00
snapmaticEditor - > show ( ) ;
2017-12-17 13:03:43 +01:00
# else
snapmaticEditor - > showMaximized ( ) ;
# endif
2017-10-09 08:35:48 +02:00
snapmaticEditor - > exec ( ) ;
delete snapmaticEditor ;
}
2017-12-17 13:03:43 +01:00
void PictureDialog : : editSnapmaticImage ( )
{
2018-07-21 18:33:08 +02:00
QImage * currentImage = new QImage ( smpic - > getImage ( ) ) ;
ImportDialog * importDialog ;
2021-01-27 14:35:42 +01:00
if ( rqFullscreen & & fullscreenWidget ! = nullptr ) {
2018-07-21 18:33:08 +02:00
importDialog = new ImportDialog ( profileName , fullscreenWidget ) ;
2017-12-17 13:03:43 +01:00
}
2021-01-27 14:35:42 +01:00
else {
2018-07-21 18:33:08 +02:00
importDialog = new ImportDialog ( profileName , this ) ;
2017-12-17 13:03:43 +01:00
}
2018-07-21 18:33:08 +02:00
importDialog - > setWindowIcon ( windowIcon ( ) ) ;
importDialog - > setImage ( currentImage ) ;
importDialog - > enableOverwriteMode ( ) ;
importDialog - > setModal ( true ) ;
importDialog - > exec ( ) ;
2021-01-27 14:35:42 +01:00
if ( importDialog - > isImportAgreed ( ) ) {
2018-07-21 18:33:08 +02:00
const QByteArray previousPicture = smpic - > getPictureStream ( ) ;
2021-06-17 06:14:35 +02:00
bool success = smpic - > setImage ( importDialog - > image ( ) , importDialog - > isUnlimitedBuffer ( ) ) ;
2021-01-27 14:35:42 +01:00
if ( success ) {
2018-07-21 18:33:08 +02:00
QString currentFilePath = smpic - > getPictureFilePath ( ) ;
QString originalFilePath = smpic - > getOriginalPictureFilePath ( ) ;
QString backupFileName = originalFilePath % " .bak " ;
2021-01-27 14:35:42 +01:00
if ( ! QFile : : exists ( backupFileName ) ) {
2018-07-21 18:33:08 +02:00
QFile : : copy ( currentFilePath , backupFileName ) ;
}
2021-01-27 14:35:42 +01:00
if ( ! smpic - > exportPicture ( currentFilePath ) ) {
2018-07-21 18:33:08 +02:00
smpic - > setPictureStream ( previousPicture ) ;
QMessageBox : : warning ( this , QApplication : : translate ( " ImageEditorDialog " , " Snapmatic Image Editor " ) , QApplication : : translate ( " ImageEditorDialog " , " Patching of Snapmatic Image failed because of I/O Error " ) ) ;
return ;
}
smpic - > emitCustomSignal ( " PictureUpdated " ) ;
2018-07-28 04:55:55 +02:00
# ifdef GTA5SYNC_TELEMETRY
QSettings telemetrySettings ( GTA5SYNC_APPVENDOR , GTA5SYNC_APPSTR ) ;
telemetrySettings . beginGroup ( " Telemetry " ) ;
bool pushUsageData = telemetrySettings . value ( " PushUsageData " , false ) . toBool ( ) ;
telemetrySettings . endGroup ( ) ;
2021-01-27 14:35:42 +01:00
if ( pushUsageData & & Telemetry - > canPush ( ) ) {
2018-07-28 04:55:55 +02:00
QJsonDocument jsonDocument ;
QJsonObject jsonObject ;
jsonObject [ " Type " ] = " ImageEdited " ;
jsonObject [ " ExtraFlags " ] = " Viewer " ;
jsonObject [ " EditedSize " ] = QString : : number ( smpic - > getContentMaxLength ( ) ) ;
2021-01-27 14:35:42 +01:00
# if QT_VERSION >= 0x060000
jsonObject [ " EditedTime " ] = QString : : number ( QDateTime : : currentDateTimeUtc ( ) . toSecsSinceEpoch ( ) ) ;
# else
2018-07-28 04:55:55 +02:00
jsonObject [ " EditedTime " ] = QString : : number ( QDateTime : : currentDateTimeUtc ( ) . toTime_t ( ) ) ;
2021-01-27 14:35:42 +01:00
# endif
2018-07-28 04:55:55 +02:00
jsonDocument . setObject ( jsonObject ) ;
Telemetry - > push ( TelemetryCategory : : PersonalData , jsonDocument ) ;
}
# endif
2018-07-21 18:33:08 +02:00
}
2021-01-27 14:35:42 +01:00
else {
2018-07-21 18:33:08 +02:00
QMessageBox : : warning ( this , QApplication : : translate ( " ImageEditorDialog " , " Snapmatic Image Editor " ) , QApplication : : translate ( " ImageEditorDialog " , " Patching of Snapmatic Image failed because of Image Error " ) ) ;
return ;
}
}
delete importDialog ;
2017-12-17 13:03:43 +01:00
}
2017-11-22 14:59:40 +01:00
void PictureDialog : : editSnapmaticRawJson ( )
{
SnapmaticPicture * picture = smpic ;
2017-11-22 20:23:36 +01:00
JsonEditorDialog * jsonEditor ;
2021-01-27 14:35:42 +01:00
if ( rqFullscreen & & fullscreenWidget ! = nullptr ) {
2017-11-22 20:23:36 +01:00
jsonEditor = new JsonEditorDialog ( picture , fullscreenWidget ) ;
}
2021-01-27 14:35:42 +01:00
else {
2017-11-22 20:23:36 +01:00
jsonEditor = new JsonEditorDialog ( picture , this ) ;
}
jsonEditor - > setWindowIcon ( windowIcon ( ) ) ;
2017-11-22 14:59:40 +01:00
jsonEditor - > setModal ( true ) ;
2017-12-17 13:03:43 +01:00
# ifndef Q_OS_ANDROID
2017-11-22 14:59:40 +01:00
jsonEditor - > show ( ) ;
2017-12-17 13:03:43 +01:00
# else
jsonEditor - > showMaximized ( ) ;
# endif
2017-11-22 14:59:40 +01:00
jsonEditor - > exec ( ) ;
delete jsonEditor ;
}
2017-10-09 08:35:48 +02:00
void PictureDialog : : updated ( )
{
2017-11-22 14:59:40 +01:00
SnapmaticPicture * picture = smpic ; // used by macro
2017-12-12 04:45:46 +01:00
crewStr = crewDB - > getCrewName ( crewID ) ;
2021-01-27 14:35:42 +01:00
if ( globalMap . contains ( picArea ) ) {
2017-11-22 14:59:40 +01:00
picAreaStr = globalMap [ picArea ] ;
2017-10-09 08:35:48 +02:00
}
2021-01-27 14:35:42 +01:00
else {
2017-11-22 14:59:40 +01:00
picAreaStr = picArea ;
2017-10-09 08:35:48 +02:00
}
2018-02-04 02:34:16 +01:00
setWindowTitle ( windowTitleStr . arg ( picTitl ) ) ;
2017-10-09 08:35:48 +02:00
ui - > labJSON - > setText ( jsonDrawString . arg ( locX , locY , locZ , generatePlayersString ( ) , generateCrewString ( ) , picTitl , picAreaStr , created ) ) ;
2021-01-30 12:02:55 +01:00
QTimer : : singleShot ( 0 , this , SLOT ( adaptDialogSize ( ) ) ) ;
2017-10-09 08:35:48 +02:00
}
2017-12-17 13:03:43 +01:00
void PictureDialog : : customSignal ( QString signal )
{
SnapmaticPicture * picture = smpic ; // used by macro
2021-01-27 14:35:42 +01:00
if ( signal = = " PictureUpdated " ) {
2017-12-17 13:03:43 +01:00
snapmaticPicture = picture - > getImage ( ) ;
renderPicture ( ) ;
}
}