From e7721404b6e782fc6ebf62c2784889119890b957 Mon Sep 17 00:00:00 2001 From: Syping Date: Fri, 6 Oct 2023 00:20:48 +0200 Subject: [PATCH] more work towards supporting RDR 2, some export changes --- src/AppEnv.cpp | 67 +++++++++++- src/AppEnv.h | 2 +- src/ExportThread.cpp | 106 +++--------------- src/OptionsDialog.cpp | 244 +++++++++++++----------------------------- src/OptionsDialog.h | 26 ++--- src/OptionsDialog.ui | 205 ++++++----------------------------- src/PictureExport.cpp | 85 +++------------ src/UserInterface.cpp | 136 +++++++++++------------ src/UserInterface.h | 3 +- src/UserInterface.ui | 38 ++++--- 10 files changed, 302 insertions(+), 610 deletions(-) diff --git a/src/AppEnv.cpp b/src/AppEnv.cpp index 3783fb8..328ec1e 100644 --- a/src/AppEnv.cpp +++ b/src/AppEnv.cpp @@ -78,6 +78,13 @@ QString AppEnv::getGTAVFolder(bool *ok) GTAV_returnFolder = settings.value("dir", GTAV_defaultFolder).toString(); settings.endGroup(); + settings.beginGroup("GameDirectory"); + settings.beginGroup("GTA V"); + forceDir = settings.value("ForceCustom", forceDir).toBool(); + GTAV_returnFolder = settings.value("Directory", GTAV_returnFolder).toString(); + settings.endGroup(); + settings.endGroup(); + if (forceDir) { dir.setPath(GTAV_returnFolder); if (dir.exists()) { @@ -108,13 +115,63 @@ QString AppEnv::getGTAVFolder(bool *ok) return QString(); } -bool AppEnv::setGTAVFolder(QString gameFolder) +QString AppEnv::getRDR2Folder(bool *ok) { QDir dir; - dir.setPath(gameFolder); - if (dir.exists()) - return true; - return false; + QString RDR2_FOLDER = QString::fromUtf8(qgetenv("RDR2_FOLDER")); + if (!RDR2_FOLDER.isEmpty()) { + dir.setPath(RDR2_FOLDER); + if (dir.exists()) { + if (ok) + *ok = true; + return dir.absolutePath(); + } + } + +#ifdef Q_OS_UNIX + // TODO: Try to locate the Steam Proton RDR 2 folder + const QString RDR2_defaultFolder = StandardPaths::documentsLocation() % "/Rockstar Games/Red Dead Redemption 2"; +#else + const QString RDR2_defaultFolder = StandardPaths::documentsLocation() % "/Rockstar Games/Red Dead Redemption 2"; +#endif + QString RDR2_returnFolder = RDR2_defaultFolder; + + QSettings settings(GTA5SYNC_APPVENDOR, GTA5SYNC_APPSTR); + settings.beginGroup("GameDirectory"); + settings.beginGroup("RDR 2"); + bool forceDir = settings.value("ForceCustom", false).toBool(); + RDR2_returnFolder = settings.value("Directory", RDR2_defaultFolder).toString(); + settings.endGroup(); + settings.endGroup(); + + if (forceDir) { + dir.setPath(RDR2_returnFolder); + if (dir.exists()) { + if (ok) + *ok = true; + return dir.absolutePath(); + } + } + + dir.setPath(RDR2_defaultFolder); + if (dir.exists()) { + if (ok) + *ok = true; + return dir.absolutePath(); + } + + if (!forceDir) { + dir.setPath(RDR2_returnFolder); + if (dir.exists()) { + if (ok) + *ok = true; + return dir.absolutePath(); + } + } + + if (ok) + *ok = false; + return QString(); } QString AppEnv::getExLangFolder() diff --git a/src/AppEnv.h b/src/AppEnv.h index a584805..ffb72df 100644 --- a/src/AppEnv.h +++ b/src/AppEnv.h @@ -36,7 +36,7 @@ public: // Folder Stuff static QString getGTAVFolder(bool *ok = 0); - static bool setGTAVFolder(QString gameFolder); + static QString getRDR2Folder(bool *ok = 0); static QString getExLangFolder(); static QString getInLangFolder(); static QString getImagesFolder(); diff --git a/src/ExportThread.cpp b/src/ExportThread.cpp index cd99d44..4cb8a08 100644 --- a/src/ExportThread.cpp +++ b/src/ExportThread.cpp @@ -26,6 +26,7 @@ #include "config.h" #include #include +#include #include #include @@ -38,122 +39,50 @@ ExportThread::ExportThread(QMap profileMap, QString exportDirectory, bool pictureCopyEnabled, bool pictureExportEnabled, int exportCount, QObject *parent) : QThread(parent), profileMap(profileMap), exportDirectory(exportDirectory), pictureCopyEnabled(pictureCopyEnabled), pictureExportEnabled(pictureExportEnabled), exportCount(exportCount) { - } void ExportThread::run() { - QSettings settings(GTA5SYNC_APPVENDOR, GTA5SYNC_APPSTR); - - // Picture Settings - // Quality Settings - settings.beginGroup("Pictures"); - int defaultQuality = 100; - int customQuality = settings.value("CustomQuality", defaultQuality).toInt(); - if (customQuality < 1 || customQuality > 100) - customQuality = 100; - bool useCustomQuality = settings.value("CustomQualityEnabled", false).toBool(); - - // Size Settings - const QSize defExportSize = QSize(960, 536); - QSize cusExportSize = settings.value("CustomSize", defExportSize).toSize(); - if (cusExportSize.width() > 7680) { - cusExportSize.setWidth(7680); - } - else if (cusExportSize.height() > 4320) { - cusExportSize.setHeight(4320); - } - if (cusExportSize.width() < 1) { - cusExportSize.setWidth(1); - } - else if (cusExportSize.height() < 1) { - cusExportSize.setHeight(1); - } - QString sizeMode = settings.value("ExportSizeMode", "Default").toString(); - Qt::AspectRatioMode aspectRatio = (Qt::AspectRatioMode)settings.value("AspectRatio", Qt::KeepAspectRatio).toInt(); - settings.endGroup(); - // End Picture Settings - - int intExportProgress = 0; - for (ProfileWidget *widget : profileMap.keys()) - { - if (widget->isSelected()) - { - if (widget->getWidgetType() == "SnapmaticWidget") - { + size_t intExportProgress = 0; + for (ProfileWidget *widget : profileMap.keys()) { + if (widget->isSelected()) { + if (widget->getWidgetType() == "SnapmaticWidget") { SnapmaticWidget *picWidget = qobject_cast(widget); SnapmaticPicture *picture = picWidget->getPicture(); - if (pictureExportEnabled) - { + if (pictureExportEnabled) { QString exportFileName = PictureExport::getPictureFileName(picture); - if (exportFileName.right(4) != ".jpg" && exportFileName.right(4) != ".png") - { + if (!exportFileName.endsWith(".jpg")) exportFileName += ".jpg"; - } intExportProgress++; emit exportStringUpdate(ProfileInterface::tr("Export file %1 of %2 files").arg(QString::number(intExportProgress), QString::number(exportCount))); emit exportProgressUpdate(intExportProgress); - // Scale Picture - QImage exportPicture = picture->getImage(); - if (sizeMode == "Desktop") - { -#if QT_VERSION >= 0x050000 - qreal screenRatioPR = AppEnv::screenRatioPR(); - QRect desktopResolution = QApplication::primaryScreen()->geometry(); - int desktopSizeWidth = qRound((double)desktopResolution.width() * screenRatioPR); - int desktopSizeHeight = qRound((double)desktopResolution.height() * screenRatioPR); -#else - QRect desktopResolution = QApplication::desktop()->screenGeometry(); - int desktopSizeWidth = desktopResolution.width(); - int desktopSizeHeight = desktopResolution.height(); -#endif - exportPicture = exportPicture.scaled(desktopSizeWidth, desktopSizeHeight, aspectRatio, Qt::SmoothTransformation); - } - else if (sizeMode == "Custom") - { - exportPicture = exportPicture.scaled(cusExportSize, aspectRatio, Qt::SmoothTransformation); - } - - bool isSaved; - if (useCustomQuality) - { - isSaved = exportPicture.save(exportDirectory % "/" % exportFileName, "JPEG", customQuality); - } - else - { - isSaved = exportPicture.save(exportDirectory % "/" % exportFileName, "JPEG", 100); - } + QSaveFile exportFile(exportDirectory % "/" % exportFileName); + exportFile.write(picture->getPictureStream()); + bool isSaved = exportFile.commit(); if (!isSaved) - { failedExportPictures += exportFileName; - } } - if (pictureCopyEnabled) - { + if (pictureCopyEnabled) { QString exportFileName = PictureExport::getPictureFileName(picture); - if (exportFileName.right(4) != ".g5e") - { + if (!exportFileName.endsWith(".g5e")) exportFileName += ".g5e"; - } intExportProgress++; emit exportStringUpdate(ProfileInterface::tr("Export file %1 of %2 files").arg(QString::number(intExportProgress), QString::number(exportCount))); emit exportProgressUpdate(intExportProgress); QString exportFilePath = exportDirectory % "/" % exportFileName; - if (QFile::exists(exportFilePath)) {QFile::remove(exportFilePath);} + if (QFile::exists(exportFilePath)) + QFile::remove(exportFilePath); if (!picture->exportPicture(exportDirectory % "/" % exportFileName, SnapmaticFormat::G5E_Format)) - { failedCopyPictures += exportFileName; - } } } - else if (widget->getWidgetType() == "SavegameWidget") - { + else if (widget->getWidgetType() == "SavegameWidget") { SavegameWidget *sgdWidget = qobject_cast(widget); SavegameData *savegame = sgdWidget->getSavegame(); @@ -166,11 +95,10 @@ void ExportThread::run() emit exportProgressUpdate(intExportProgress); QString exportFilePath = exportDirectory % "/" % exportFileName; - if (QFile::exists(exportFilePath)) {QFile::remove(exportFilePath);} + if (QFile::exists(exportFilePath)) + QFile::remove(exportFilePath); if (!QFile::copy(originalFileName, exportFilePath)) - { failedSavegames += exportFileName; - } } } } diff --git a/src/OptionsDialog.cpp b/src/OptionsDialog.cpp index 04f9c1f..af47fed 100644 --- a/src/OptionsDialog.cpp +++ b/src/OptionsDialog.cpp @@ -60,26 +60,10 @@ OptionsDialog::OptionsDialog(ProfileDatabase *profileDB, QWidget *parent) : // Setup User Interface ui->setupUi(this); ui->tabWidget->setCurrentIndex(0); - ui->labPicCustomRes->setVisible(false); ui->cmdCancel->setDefault(true); ui->cmdCancel->setFocus(); qreal screenRatioPR = AppEnv::screenRatioPR(); - QRect desktopResolution = QApplication::primaryScreen()->geometry(); - int desktopSizeWidth = qRound((double)desktopResolution.width() * screenRatioPR); - int desktopSizeHeight = qRound((double)desktopResolution.height() * screenRatioPR); - aspectRatio = Qt::KeepAspectRatio; - defExportSize = QSize(960, 536); - cusExportSize = defExportSize; - defaultQuality = 100; - customQuality = 100; - contentMode = 0; - settings = new QSettings(GTA5SYNC_APPVENDOR, GTA5SYNC_APPSTR); - - percentString = ui->labPicQuality->text(); - ui->labPicQuality->setText(percentString.arg(QString::number(defaultQuality))); - ui->rbPicDesktopRes->setText(ui->rbPicDesktopRes->text().arg(QString::number(desktopSizeWidth), QString::number(desktopSizeHeight))); - ui->rbPicDefaultRes->setText(ui->rbPicDefaultRes->text().arg(QString::number(defExportSize.width()), QString::number(defExportSize.height()))); // Set Icon for OK Button if (QIcon::hasThemeIcon("dialog-ok")) { @@ -102,15 +86,15 @@ OptionsDialog::OptionsDialog(ProfileDatabase *profileDB, QWidget *parent) : ui->cmdCopyStatsID->setIcon(QIcon::fromTheme("edit-copy")); } + QSettings settings(GTA5SYNC_APPVENDOR, GTA5SYNC_APPSTR); setupTreeWidget(); - setupLanguageBox(); - setupRadioButtons(); - setupDefaultProfile(); - setupPictureSettings(); - setupCustomGTAFolder(); - setupInterfaceSettings(); - setupStatisticsSettings(); - setupSnapmaticPictureViewer(); + setupLanguageBox(&settings); + setupRadioButtons(&settings); + setupDefaultProfile(&settings); + setupCustomGameFolder(&settings); + setupInterfaceSettings(&settings); + setupStatisticsSettings(&settings); + setupSnapmaticPictureViewer(&settings); setupWindowsGameSettings(); #ifndef Q_QS_ANDROID @@ -126,7 +110,6 @@ OptionsDialog::OptionsDialog(ProfileDatabase *profileDB, QWidget *parent) : OptionsDialog::~OptionsDialog() { - delete settings; qDeleteAll(playerItems.begin(), playerItems.end()); playerItems.clear(); delete ui; @@ -158,7 +141,7 @@ void OptionsDialog::setupTreeWidget() } } -void OptionsDialog::setupLanguageBox() +void OptionsDialog::setupLanguageBox(QSettings *settings) { settings->beginGroup("Interface"); currentLanguage = settings->value("Language", "System").toString(); @@ -259,7 +242,7 @@ void OptionsDialog::setupLanguageBox() ui->labCurrentAreaLanguage->setText(tr("Current: %1").arg(currentLocale.nativeLanguageName() % " (" % currentLocale.nativeCountryName() % ") [" % aCurrentAreaLanguage % "]")); } -void OptionsDialog::setupRadioButtons() +void OptionsDialog::setupRadioButtons(QSettings *settings) { bool contentModeOk; settings->beginGroup("Profile"); @@ -291,7 +274,7 @@ void OptionsDialog::setupRadioButtons() } } -void OptionsDialog::setupInterfaceSettings() +void OptionsDialog::setupInterfaceSettings(QSettings *settings) { settings->beginGroup("Startup"); const QString currentStyle = QApplication::style()->objectName(); @@ -339,24 +322,25 @@ void OptionsDialog::on_cmdOK_clicked() void OptionsDialog::applySettings() { - settings->beginGroup("Interface"); + QSettings settings(GTA5SYNC_APPVENDOR, GTA5SYNC_APPSTR); + settings.beginGroup("Interface"); #if QT_VERSION >= 0x050000 - settings->setValue("Language", ui->cbLanguage->currentData()); - settings->setValue("AreaLanguage", ui->cbAreaLanguage->currentData()); + settings.setValue("Language", ui->cbLanguage->currentData()); + settings.setValue("AreaLanguage", ui->cbAreaLanguage->currentData()); #else settings->setValue("Language", ui->cbLanguage->itemData(ui->cbLanguage->currentIndex())); settings->setValue("AreaLanguage", ui->cbAreaLanguage->itemData(ui->cbAreaLanguage->currentIndex())); #endif #ifdef Q_OS_WIN #if QT_VERSION >= 0x050200 - settings->setValue("NavigationBar", ui->cbSnapmaticNavigationBar->isChecked()); + settings.setValue("NavigationBar", ui->cbSnapmaticNavigationBar->isChecked()); #endif #else - settings->setValue("NavigationBar", ui->cbSnapmaticNavigationBar->isChecked()); + settings.setValue("NavigationBar", ui->cbSnapmaticNavigationBar->isChecked()); #endif - settings->endGroup(); + settings.endGroup(); - settings->beginGroup("Profile"); + settings.beginGroup("Profile"); int newContentMode = 20; if (ui->rbModern->isChecked()) { newContentMode = 20; @@ -367,66 +351,56 @@ void OptionsDialog::applySettings() if (ui->cbDoubleclick->isChecked()) { newContentMode++; } - settings->setValue("ContentMode", newContentMode); + settings.setValue("ContentMode", newContentMode); #if QT_VERSION >= 0x050000 - settings->setValue("Default", ui->cbProfiles->currentData()); + settings.setValue("Default", ui->cbProfiles->currentData()); #else settings->setValue("Default", ui->cbProfiles->itemData(ui->cbProfiles->currentIndex())); #endif - settings->endGroup(); + settings.endGroup(); - settings->beginGroup("Pictures"); - if (ui->cbPicCustomQuality->isChecked()) { - settings->setValue("CustomQuality", ui->hsPicQuality->value()); - } - settings->setValue("CustomQualityEnabled", ui->cbPicCustomQuality->isChecked()); - QString sizeMode = "Default"; - if (ui->rbPicDesktopRes->isChecked()) { - sizeMode = "Desktop"; - } - else if (ui->rbPicCustomRes->isChecked()) { - sizeMode = "Custom"; - settings->setValue("CustomSize", QSize(ui->sbPicExportWidth->value(), ui->sbPicExportHeight->value())); - } - settings->setValue("ExportSizeMode", sizeMode); - settings->setValue("AspectRatio", aspectRatio); - settings->endGroup(); + const bool forceCustomFolder = ui->cbForceCustomFolder->isChecked(); + const bool forceCustomFolder_RDR2 = ui->cbForceCustomFolder_RDR2->isChecked(); + settings.beginGroup("GameDirectory"); + settings.beginGroup("GTA V"); + settings.setValue("Directory", ui->txtFolder->text()); + settings.setValue("ForceCustom", forceCustomFolder); + settings.endGroup(); + settings.beginGroup("RDR 2"); + settings.setValue("Directory", ui->txtFolder_RDR2->text()); + settings.setValue("ForceCustom", forceCustomFolder_RDR2); + settings.endGroup(); + settings.endGroup(); - bool forceCustomFolder = ui->cbForceCustomFolder->isChecked(); - settings->beginGroup("dir"); - settings->setValue("dir", ui->txtFolder->text()); - settings->setValue("force", forceCustomFolder); - settings->endGroup(); - - bool defaultStyle = ui->cbDefaultStyle->isChecked(); - settings->beginGroup("Startup"); + const bool defaultStyle = ui->cbDefaultStyle->isChecked(); + settings.beginGroup("Startup"); if (!defaultStyle) { QString newStyle = ui->cbStyleList->currentText(); - settings->setValue("CustomStyle", true); - settings->setValue("AppStyle", newStyle); + settings.setValue("CustomStyle", true); + settings.setValue("AppStyle", newStyle); QApplication::setStyle(QStyleFactory::create(newStyle)); } else { - settings->setValue("CustomStyle", false); + settings.setValue("CustomStyle", false); } - bool defaultFont = ui->cbDefaultFont->isChecked(); + const bool defaultFont = ui->cbDefaultFont->isChecked(); if (!defaultFont) { QFont newFont = ui->cbFont->currentFont(); - settings->setValue("CustomFont", true); - settings->setValue("AppFont", newFont); + settings.setValue("CustomFont", true); + settings.setValue("AppFont", newFont); QApplication::setFont(newFont); } else { - settings->setValue("CustomFont", false); + settings.setValue("CustomFont", false); } - settings->endGroup(); + settings.endGroup(); #ifdef GTA5SYNC_TELEMETRY - settings->beginGroup("Telemetry"); - settings->setValue("PushAppConf", ui->cbAppConfigStats->isChecked()); - settings->setValue("PushUsageData", ui->cbUsageData->isChecked()); - if (!Telemetry->isStateForced()) { settings->setValue("IsEnabled", ui->cbParticipateStats->isChecked()); } - settings->endGroup(); + settings.beginGroup("Telemetry"); + settings.setValue("PushAppConf", ui->cbAppConfigStats->isChecked()); + settings.setValue("PushUsageData", ui->cbUsageData->isChecked()); + if (!Telemetry->isStateForced()) { settings.setValue("IsEnabled", ui->cbParticipateStats->isChecked()); } + settings.endGroup(); Telemetry->refresh(); Telemetry->work(); if (ui->cbUsageData->isChecked() && Telemetry->canPush()) { @@ -459,7 +433,7 @@ void OptionsDialog::applySettings() Translator->initUserLanguage(); } - settings->sync(); + settings.sync(); emit settingsApplied(newContentMode, languageChanged); if ((forceCustomFolder && ui->txtFolder->text() != currentCFolder) || (forceCustomFolder != currentFFolder && forceCustomFolder)) { @@ -467,14 +441,14 @@ void OptionsDialog::applySettings() } } -void OptionsDialog::setupDefaultProfile() +void OptionsDialog::setupDefaultProfile(QSettings *settings) { settings->beginGroup("Profile"); - defaultProfile = settings->value("Default", "").toString(); + defaultProfile = settings->value("Default", QString()).toString(); settings->endGroup(); QString cbNoneStr = tr("No Profile", "No Profile, as default"); - ui->cbProfiles->addItem(cbNoneStr, ""); + ui->cbProfiles->addItem(cbNoneStr, QString()); } void OptionsDialog::commitProfiles(const QStringList &profiles) @@ -492,77 +466,7 @@ void OptionsDialog::commitProfiles(const QStringList &profiles) } } -void OptionsDialog::on_rbPicCustomRes_toggled(bool checked) -{ - ui->labPicCustomRes->setEnabled(checked); - ui->sbPicExportWidth->setEnabled(checked); - ui->sbPicExportHeight->setEnabled(checked); - ui->labPicXDescription->setEnabled(checked); -} - -void OptionsDialog::on_cbPicCustomQuality_toggled(bool checked) -{ - ui->hsPicQuality->setEnabled(checked); - ui->labPicQuality->setEnabled(checked); - ui->labPicQualityDescription->setEnabled(checked); -} - -void OptionsDialog::on_hsPicQuality_valueChanged(int value) -{ - customQuality = value; - ui->labPicQuality->setText(percentString.arg(QString::number(value))); -} - -void OptionsDialog::setupPictureSettings() -{ - settings->beginGroup("Pictures"); - - // Quality Settings - customQuality = settings->value("CustomQuality", defaultQuality).toInt(); - if (customQuality < 1 || customQuality > 100) - customQuality = 100; - ui->hsPicQuality->setValue(customQuality); - ui->cbPicCustomQuality->setChecked(settings->value("CustomQualityEnabled", false).toBool()); - - // Size Settings - cusExportSize = settings->value("CustomSize", defExportSize).toSize(); - if (cusExportSize.width() > 7680) { - cusExportSize.setWidth(7680); - } - else if (cusExportSize.height() > 4320) { - cusExportSize.setHeight(4320); - } - if (cusExportSize.width() < 1) { - cusExportSize.setWidth(1); - } - else if (cusExportSize.height() < 1) { - cusExportSize.setHeight(1); - } - ui->sbPicExportWidth->setMaximum(7680); - ui->sbPicExportWidth->setValue(cusExportSize.width()); - ui->sbPicExportHeight->setMaximum(4320); - ui->sbPicExportHeight->setValue(cusExportSize.height()); - - QString sizeMode = settings->value("ExportSizeMode", "Default").toString(); - if (sizeMode == "Desktop") { - ui->rbPicDesktopRes->setChecked(true); - } - else if (sizeMode == "Custom") { - ui->rbPicCustomRes->setChecked(true); - } - else { - ui->rbPicDefaultRes->setChecked(true); - } - - aspectRatio = static_cast(settings->value("AspectRatio", Qt::KeepAspectRatio).toInt()); - if (aspectRatio == Qt::IgnoreAspectRatio) { - ui->cbIgnoreAspectRatio->setChecked(true); - } - - settings->endGroup(); -} - -void OptionsDialog::setupStatisticsSettings() +void OptionsDialog::setupStatisticsSettings(QSettings *settings) { #ifdef GTA5SYNC_TELEMETRY ui->cbParticipateStats->setText(tr("Participate in %1 User Statistics").arg(GTA5SYNC_APPSTR)); @@ -648,32 +552,36 @@ void OptionsDialog::setupWindowsGameSettings() #endif } -void OptionsDialog::on_cbIgnoreAspectRatio_toggled(bool checked) +void OptionsDialog::setupCustomGameFolder(QSettings *settings) { - if (checked) { - aspectRatio = Qt::IgnoreAspectRatio; - } - else { - aspectRatio = Qt::KeepAspectRatio; - } -} - -void OptionsDialog::setupCustomGTAFolder() -{ - bool ok; - QString defaultGameFolder = AppEnv::getGTAVFolder(&ok); + bool ok_GTAV, ok_RDR2; + const QString defaultGameFolder = AppEnv::getGTAVFolder(&ok_GTAV); + const QString defaultGameFolderR = AppEnv::getRDR2Folder(&ok_RDR2); settings->beginGroup("dir"); - currentCFolder = settings->value("dir", "").toString(); + currentCFolder = settings->value("dir", QString()).toString(); currentFFolder = settings->value("force", false).toBool(); - if (currentCFolder == "" && ok) { + settings->endGroup(); + settings->beginGroup("GameDirectory"); + settings->beginGroup("GTA V"); + currentCFolder = settings->value("Directory", currentCFolder).toString(); + currentFFolder = settings->value("ForceCustom", currentFFolder).toBool(); + settings->endGroup(); + settings->beginGroup("RDR 2"); + currentCFolderR = settings->value("Directory", QString()).toString(); + currentFFolderR = settings->value("ForceCustom", false).toBool(); + settings->endGroup(); + settings->endGroup(); + if (currentCFolder.isEmpty() && ok_GTAV) currentCFolder = defaultGameFolder; - } + if (currentCFolderR.isEmpty() && ok_RDR2) + currentCFolderR = defaultGameFolderR; ui->txtFolder->setText(currentCFolder); ui->cbForceCustomFolder->setChecked(currentFFolder); - settings->endGroup(); + ui->txtFolder_RDR2->setText(currentCFolderR); + ui->cbForceCustomFolder_RDR2->setChecked(currentFFolderR); } -void OptionsDialog::setupSnapmaticPictureViewer() +void OptionsDialog::setupSnapmaticPictureViewer(QSettings *settings) { #ifdef Q_OS_WIN #if QT_VERSION >= 0x050200 diff --git a/src/OptionsDialog.h b/src/OptionsDialog.h index f53854e..cb2ba1a 100644 --- a/src/OptionsDialog.h +++ b/src/OptionsDialog.h @@ -41,10 +41,6 @@ public: private slots: void on_cmdOK_clicked(); - void on_rbPicCustomRes_toggled(bool checked); - void on_cbPicCustomQuality_toggled(bool checked); - void on_hsPicQuality_valueChanged(int value); - void on_cbIgnoreAspectRatio_toggled(bool checked); void on_cmdExploreFolder_clicked(); void on_cbDefaultStyle_toggled(bool checked); void on_cbDefaultFont_toggled(bool checked); @@ -63,25 +59,21 @@ private: QString currentAreaLanguage; QString currentLanguage; QString currentCFolder; + QString currentCFolderR; QString defaultProfile; QString percentString; - QSettings *settings; bool withoutPlayers; bool currentFFolder; + bool currentFFolderR; int contentMode; - int customQuality; - int defaultQuality; - QSize defExportSize; - QSize cusExportSize; void setupTreeWidget(); - void setupLanguageBox(); - void setupRadioButtons(); - void setupDefaultProfile(); - void setupPictureSettings(); - void setupCustomGTAFolder(); - void setupInterfaceSettings(); - void setupStatisticsSettings(); - void setupSnapmaticPictureViewer(); + void setupLanguageBox(QSettings *settings); + void setupRadioButtons(QSettings *settings); + void setupDefaultProfile(QSettings *settings); + void setupCustomGameFolder(QSettings *settings); + void setupInterfaceSettings(QSettings *settings); + void setupStatisticsSettings(QSettings *settings); + void setupSnapmaticPictureViewer(QSettings *settings); void setupWindowsGameSettings(); void applySettings(); }; diff --git a/src/OptionsDialog.ui b/src/OptionsDialog.ui index 6c5e80b..203f3d8 100644 --- a/src/OptionsDialog.ui +++ b/src/OptionsDialog.ui @@ -102,6 +102,36 @@ + + + + Custom RDR 2 Folder + + + + + + Force using Custom Folder + + + + + + + + + + + + ... + + + + + + + + @@ -122,181 +152,6 @@ Pictures - - - - Export Size - - - - - - Default: %1x%2 - - - true - - - - - - - Screen Resolution: %1x%2 - - - - - - - - - Custom Size: - - - - - - - false - - - Custom Size: - - - - - - - false - - - 1 - - - 3840 - - - 960 - - - - - - - false - - - x - - - - - - - false - - - 1 - - - 2160 - - - 536 - - - - - - - Qt::Horizontal - - - - 0 - 0 - - - - - - - - - - - - Ignore Aspect Ratio - - - - - - - - - - - - Export Quality - - - - - - Enable Custom Quality - - - - - - - - - false - - - Quality: - - - - - - - false - - - 1 - - - 100 - - - 100 - - - Qt::Horizontal - - - - - - - false - - - %1% - - - true - - - - - - - - diff --git a/src/PictureExport.cpp b/src/PictureExport.cpp index 3eb15c5..5af7bf3 100644 --- a/src/PictureExport.cpp +++ b/src/PictureExport.cpp @@ -26,16 +26,9 @@ #include #include #include -#include - -#if QT_VERSION < 0x050000 -#include -#endif - -#if QT_VERSION >= 0x050000 #include #include -#endif +#include PictureExport::PictureExport() { @@ -48,29 +41,6 @@ void PictureExport::exportAsPicture(QWidget *parent, SnapmaticPicture *picture) // Picture Settings // Quality Settings settings.beginGroup("Pictures"); - int defaultQuality = 100; - int customQuality = settings.value("CustomQuality", defaultQuality).toInt(); - if (customQuality < 1 || customQuality > 100) - customQuality = 100; - bool useCustomQuality = settings.value("CustomQualityEnabled", false).toBool(); - - // Size Settings - const QSize defExportSize = QSize(960, 536); - QSize cusExportSize = settings.value("CustomSize", defExportSize).toSize(); - if (cusExportSize.width() > 7680) { - cusExportSize.setWidth(7680); - } - else if (cusExportSize.height() > 4320) { - cusExportSize.setHeight(4320); - } - if (cusExportSize.width() < 1) { - cusExportSize.setWidth(1); - } - else if (cusExportSize.height() < 1) { - cusExportSize.setHeight(1); - } - QString sizeMode = settings.value("ExportSizeMode", "Default").toString(); - Qt::AspectRatioMode aspectRatio = (Qt::AspectRatioMode)settings.value("AspectRatio", Qt::KeepAspectRatio).toInt(); QString defaultExportFormat = settings.value("DefaultExportFormat", ".jpg").toString(); settings.endGroup(); // End Picture Settings @@ -87,7 +57,7 @@ fileDialogPreSave: //Work? fileDialog.setOption(QFileDialog::DontUseNativeDialog, dontUseNativeDialog); fileDialog.setOption(QFileDialog::DontConfirmOverwrite, true); fileDialog.setDefaultSuffix("suffix"); - fileDialog.setWindowFlags(fileDialog.windowFlags()^Qt::WindowContextHelpButtonHint); + fileDialog.setWindowFlag(Qt::WindowContextHelpButtonHint, false); fileDialog.setWindowTitle(PictureDialog::tr("Export as Picture...")); fileDialog.setLabelText(QFileDialog::Accept, PictureDialog::tr("Export")); @@ -107,16 +77,13 @@ fileDialogPreSave: //Work? QString saveFileFormat; QString selectedFile = selectedFiles.at(0); - if (selectedFile.right(4) == ".jpg") { + if (selectedFile.endsWith(".jpg") || selectedFile.endsWith(".jpeg")) { saveFileFormat = "JPEG"; } - else if (selectedFile.right(4) == ".jpeg") { - saveFileFormat = "JPEG"; - } - else if (selectedFile.right(4) == ".png") { + else if (selectedFile.endsWith(".png")) { saveFileFormat = "PNG"; } - else if (selectedFile.right(7) == ".suffix") { + else if (selectedFile.endsWith(".suffix")) { if (fileDialog.selectedNameFilter() == "JPEG picture (*.jpg)") { selectedFile.replace(".suffix", ".jpg"); } @@ -134,49 +101,23 @@ fileDialogPreSave: //Work? } } - // Scale Picture QImage exportPicture = picture->getImage(); - if (sizeMode == "Desktop") { -#if QT_VERSION >= 0x050000 - qreal screenRatioPR = AppEnv::screenRatioPR(); - QRect desktopResolution = QApplication::primaryScreen()->geometry(); - int desktopSizeWidth = qRound((double)desktopResolution.width() * screenRatioPR); - int desktopSizeHeight = qRound((double)desktopResolution.height() * screenRatioPR); -#else - QRect desktopResolution = QApplication::desktop()->screenGeometry(); - int desktopSizeWidth = desktopResolution.width(); - int desktopSizeHeight = desktopResolution.height(); -#endif - exportPicture = exportPicture.scaled(desktopSizeWidth, desktopSizeHeight, aspectRatio, Qt::SmoothTransformation); - } - else if (sizeMode == "Custom") { - exportPicture = exportPicture.scaled(cusExportSize, aspectRatio, Qt::SmoothTransformation); - } int errorId = 0; bool isSaved = false; -#if QT_VERSION >= 0x050000 - QSaveFile *picFile = new QSaveFile(selectedFile); -#else - QFile *picFile = new QFile(selectedFile); -#endif - if (picFile->open(QIODevice::WriteOnly)) { - isSaved = exportPicture.save(picFile, saveFileFormat.toStdString().c_str(), useCustomQuality ? customQuality : defaultQuality); -#if QT_VERSION >= 0x050000 + QSaveFile picFile(selectedFile); + if (picFile.open(QIODevice::WriteOnly)) { + isSaved = exportPicture.save(&picFile, saveFileFormat.toStdString().c_str(), 100); if (isSaved) { - isSaved = picFile->commit(); + isSaved = picFile.commit(); } else { errorId = 1; } -#else - picFile->close(); -#endif } else { errorId = 2; } - delete picFile; if (!isSaved) { switch (errorId) { @@ -225,7 +166,7 @@ fileDialogPreSave: //Work? fileDialog.setOption(QFileDialog::DontUseNativeDialog, dontUseNativeDialog); fileDialog.setOption(QFileDialog::DontConfirmOverwrite, true); fileDialog.setDefaultSuffix(".rem"); - fileDialog.setWindowFlags(fileDialog.windowFlags()^Qt::WindowContextHelpButtonHint); + fileDialog.setWindowFlag(Qt::WindowContextHelpButtonHint, false); fileDialog.setWindowTitle(PictureDialog::tr("Export as Snapmatic...")); fileDialog.setLabelText(QFileDialog::Accept, PictureDialog::tr("Export")); @@ -246,14 +187,14 @@ fileDialogPreSave: //Work? QString selectedFile = selectedFiles.at(0); bool isAutoExt = false; #ifndef GTA5SYNC_FLATPAK - if (selectedFile.right(5) == ".auto") { + if (selectedFile.endsWith(".auto")) { isAutoExt = true; QString dirPath = QFileInfo(selectedFile).dir().path(); QString stockFileName = sgdFileInfo.fileName(); selectedFile = dirPath % "/" % stockFileName; } #endif - if (selectedFile.right(4) == ".rem") { + if (selectedFile.endsWith(".rem")) { selectedFile.remove(selectedFile.length() - 4, 4); } @@ -263,7 +204,7 @@ fileDialogPreSave: //Work? } } - if (selectedFile.right(4) == ".g5e") { + if (selectedFile.endsWith(".g5e")) { bool isExported = picture->exportPicture(selectedFile, SnapmaticFormat::G5E_Format); if (!isExported) { QMessageBox::warning(parent, PictureDialog::tr("Export as Snapmatic"), PictureDialog::tr("Failed to export current Snapmatic picture")); diff --git a/src/UserInterface.cpp b/src/UserInterface.cpp index b6c0c91..c4c2915 100644 --- a/src/UserInterface.cpp +++ b/src/UserInterface.cpp @@ -309,32 +309,19 @@ UserInterface::UserInterface(ProfileDatabase *profileDB, CrewDatabase *crewDB, D ui->vlUserInterface->setContentsMargins(9 * screenRatio, 9 * screenRatio, 9 * screenRatio, 9 * screenRatio); } -void UserInterface::setupDirEnv(bool showFolderDialog) +void UserInterface::setupDirEnv(bool showFolderWindow) { // settings init QSettings settings(GTA5SYNC_APPVENDOR, GTA5SYNC_APPSTR); - bool folderExists; - GTAV_Folder = AppEnv::getGTAVFolder(&folderExists); - if (!folderExists && showFolderDialog) { - const QString GTAV_Folder_Temp = QFileDialog::getExistingDirectory(this, tr("Select GTA V Folder..."), StandardPaths::documentsLocation(), QFileDialog::ShowDirsOnly); - if (!GTAV_Folder_Temp.isEmpty() && QDir(GTAV_Folder_Temp).exists()) { - GTAV_Folder = GTAV_Folder_Temp; - folderExists = true; - AppEnv::setGTAVFolder(GTAV_Folder); - - // First time folder selection save - settings.beginGroup("dir"); - if (settings.value("dir", "").toString().isEmpty()) { - settings.setValue("dir", GTAV_Folder); - } - settings.endGroup(); - } - } + bool folderExists_GTAV, folderExists_RDR2; + GTAV_Folder = AppEnv::getGTAVFolder(&folderExists_GTAV); + RDR2_Folder = AppEnv::getRDR2Folder(&folderExists_RDR2); // profiles init settings.beginGroup("Profile"); - QString defaultProfile = settings.value("Default", "").toString(); + QString defaultProfile = settings.value("Default", QString()).toString(); + settings.endGroup(); contentMode = settings.value("ContentMode", 0).toInt(); if (contentMode == 1) { @@ -344,51 +331,78 @@ void UserInterface::setupDirEnv(bool showFolderDialog) contentMode = 20; } - if (folderExists) { + if (folderExists_GTAV) { QDir GTAV_ProfilesDir; GTAV_ProfilesDir.setPath(GTAV_Folder % "/Profiles"); - GTAV_Profiles = GTAV_ProfilesDir.entryList(QDir::Dirs | QDir::NoDotAndDotDot, QDir::NoSort); - setupProfileUi(); - - if (GTAV_Profiles.length() == 1) { - openProfile(GTAV_Profiles.at(0), RagePhoto::PhotoFormat::GTA5); - } - else if(GTAV_Profiles.contains(defaultProfile)) { - openProfile(defaultProfile, RagePhoto::PhotoFormat::GTA5); - } } else { GTAV_Profiles = QStringList(); - setupProfileUi(); } - settings.endGroup(); + + if (folderExists_RDR2) { + QDir RDR2_ProfilesDir; + RDR2_ProfilesDir.setPath(RDR2_Folder % "/Profiles"); + RDR2_Profiles = RDR2_ProfilesDir.entryList(QDir::Dirs | QDir::NoDotAndDotDot, QDir::NoSort); + } + else { + RDR2_Profiles = QStringList(); + } + + setupProfileUi(); + + if (GTAV_Profiles.contains(defaultProfile)) { + openProfile(defaultProfile, RagePhoto::PhotoFormat::GTA5); + } + else if (GTAV_Profiles.length() == 1 && RDR2_Profiles.length() == 0) { + openProfile(GTAV_Profiles.at(0), RagePhoto::PhotoFormat::GTA5); + } + else if (GTAV_Profiles.length() == 0 && RDR2_Profiles.length() == 1) { + openProfile(RDR2_Profiles.at(0), RagePhoto::PhotoFormat::RDR2); + } } void UserInterface::setupProfileUi() { qreal screenRatio = AppEnv::screenRatio(); - if (GTAV_Profiles.isEmpty()) { - QPushButton *changeDirBtn = new QPushButton(tr("Select >A V Folder..."), ui->swSelection); - changeDirBtn->setObjectName("cmdChangeDir"); - changeDirBtn->setMinimumSize(0, 40 * screenRatio); - changeDirBtn->setAutoDefault(true); - ui->vlButtons->addWidget(changeDirBtn); - profileBtns += changeDirBtn; + if (!GTAV_Profiles.isEmpty()) { + int row = 1; + for (const QString >AV_Profile : GTAV_Profiles) { + QPushButton *profileBtn = new QPushButton(tr("Profile: %1").arg(GTAV_Profile), ui->swSelection); + profileBtn->setObjectName(GTAV_Profile); + profileBtn->setMinimumSize(0, 40 * screenRatio); + profileBtn->setAutoDefault(true); + ui->glProfiles->addWidget(profileBtn, row++, 0); + profileBtns += profileBtn; - QObject::connect(changeDirBtn, SIGNAL(clicked(bool)), this, SLOT(changeFolder_clicked())); + QObject::connect(profileBtn, &QPushButton::clicked, this, [=](){ + openProfile(profileBtn->objectName(), RagePhoto::PhotoFormat::GTA5); + }); + } + ui->labGTAV->setVisible(true); } - else for (const QString >AV_Profile : GTAV_Profiles) { - QPushButton *profileBtn = new QPushButton(GTAV_Profile, ui->swSelection); - profileBtn->setObjectName(GTAV_Profile); - profileBtn->setMinimumSize(0, 40 * screenRatio); - profileBtn->setAutoDefault(true); - ui->vlButtons->addWidget(profileBtn); - profileBtns += profileBtn; + else { + ui->labGTAV->setVisible(false); + } + if (!RDR2_Profiles.isEmpty()) { + int row = 1; + for (const QString &RDR2_Profile : RDR2_Profiles) { + QPushButton *profileBtn = new QPushButton(tr("Profile: %1").arg(RDR2_Profile), ui->swSelection); + profileBtn->setObjectName(RDR2_Profile); + profileBtn->setMinimumSize(0, 40 * screenRatio); + profileBtn->setAutoDefault(true); + ui->glProfiles->addWidget(profileBtn, row++, 1); + profileBtns += profileBtn; - QObject::connect(profileBtn, SIGNAL(clicked(bool)), this, SLOT(profileButton_clicked())); + QObject::connect(profileBtn, &QPushButton::clicked, this, [=](){ + openProfile(profileBtn->objectName(), RagePhoto::PhotoFormat::RDR2); + }); + } + ui->labRDR2->setVisible(true); + } + else { + ui->labRDR2->setVisible(false); } - profileBtns.at(0)->setFocus(); } void UserInterface::changeFolder_clicked() @@ -399,19 +413,13 @@ void UserInterface::changeFolder_clicked() void UserInterface::on_cmdReload_clicked() { for (QPushButton *profileBtn : profileBtns) { - ui->vlButtons->removeWidget(profileBtn); + ui->glProfiles->removeWidget(profileBtn); delete profileBtn; } profileBtns.clear(); setupDirEnv(); } -void UserInterface::profileButton_clicked() -{ - QPushButton *profileBtn = (QPushButton*)sender(); - openProfile(profileBtn->objectName(), RagePhoto::PhotoFormat::GTA5); -} - void UserInterface::openProfile(const QString &profileName_, quint32 gameFormat) { profileOpen = true; @@ -529,16 +537,13 @@ void UserInterface::on_actionDelete_selected_triggered() void UserInterface::on_actionOptions_triggered() { - OptionsDialog *optionsDialog = new OptionsDialog(profileDB, this); - optionsDialog->setWindowIcon(windowIcon()); - optionsDialog->commitProfiles(GTAV_Profiles); - QObject::connect(optionsDialog, SIGNAL(settingsApplied(int, bool)), this, SLOT(settingsApplied(int, bool))); - - optionsDialog->setModal(true); - optionsDialog->show(); - optionsDialog->exec(); - - delete optionsDialog; + OptionsDialog optionsDialog(profileDB, this); + optionsDialog.setWindowIcon(windowIcon()); + optionsDialog.commitProfiles(GTAV_Profiles); // TODO: Diff. GTA V and RDR 2 profiles + QObject::connect(&optionsDialog, &OptionsDialog::settingsApplied, this, &UserInterface::settingsApplied); + optionsDialog.setModal(true); + optionsDialog.show(); + optionsDialog.exec(); } void UserInterface::on_action_Import_triggered() @@ -810,7 +815,6 @@ void UserInterface::on_actionSelect_GTA_Folder_triggered() closeProfile_p(); } GTAV_Folder = GTAV_Folder_Temp; - AppEnv::setGTAVFolder(GTAV_Folder); on_cmdReload_clicked(); } } diff --git a/src/UserInterface.h b/src/UserInterface.h index b02300e..6989c1d 100644 --- a/src/UserInterface.h +++ b/src/UserInterface.h @@ -48,14 +48,13 @@ public: #else explicit UserInterface(ProfileDatabase *profileDB, CrewDatabase *crewDB, DatabaseThread *threadDB, QWidget *parent = 0); #endif - void setupDirEnv(bool showFolderDialog = true); + void setupDirEnv(bool showFolderWindow = true); ~UserInterface(); private slots: void closeProfile(); void profileLoaded(); void changeFolder_clicked(); - void profileButton_clicked(); void on_cmdReload_clicked(); void on_actionExit_triggered(); void on_actionSelect_profile_triggered(); diff --git a/src/UserInterface.ui b/src/UserInterface.ui index 7927dcc..ee66d28 100644 --- a/src/UserInterface.ui +++ b/src/UserInterface.ui @@ -69,20 +69,28 @@ - - - Select profile - - - Qt::AlignCenter - - - true - - - - - + + + + + RDR 2 + + + Qt::AlignCenter + + + + + + + GTA V + + + Qt::AlignCenter + + + + @@ -171,7 +179,7 @@ 0 0 625 - 23 + 21