From a81e2e142e8363eccb8bcf18842e3431d1dcb9f6 Mon Sep 17 00:00:00 2001 From: Rafael Date: Thu, 14 Apr 2016 06:33:15 +0200 Subject: [PATCH] added default profile, added contentMode for selection/open --- OptionsDialog.cpp | 86 +++++++++++++++++++++++++++++++++++++++----- OptionsDialog.h | 10 ++++++ OptionsDialog.ui | 12 +++++++ ProfileInterface.cpp | 37 +++++++++++++++++-- ProfileInterface.h | 2 ++ ProfileWidget.cpp | 12 ++++++- ProfileWidget.h | 5 +++ SavegameWidget.cpp | 23 +++--------- SavegameWidget.h | 2 -- SnapmaticWidget.cpp | 22 +++--------- SnapmaticWidget.h | 2 -- UserInterface.cpp | 66 ++++++++++++++++++++++++++-------- UserInterface.h | 6 +++- 13 files changed, 218 insertions(+), 67 deletions(-) diff --git a/OptionsDialog.cpp b/OptionsDialog.cpp index c233953..3a59e94 100755 --- a/OptionsDialog.cpp +++ b/OptionsDialog.cpp @@ -34,12 +34,18 @@ OptionsDialog::OptionsDialog(ProfileDatabase *profileDB, QWidget *parent) : { ui->setupUi(this); ui->tabWidget->setCurrentIndex(0); + contentMode = 0; + settings = new QSettings(GTA5SYNC_APPVENDOR, GTA5SYNC_APPSTR); + setupTreeWidget(); setupLanguageBox(); + setupRadioButtons(); + setupDefaultProfile(); } OptionsDialog::~OptionsDialog() { + delete settings; foreach(QTreeWidgetItem *playerItem, playerItems) { delete playerItem; @@ -71,10 +77,9 @@ void OptionsDialog::setupTreeWidget() void OptionsDialog::setupLanguageBox() { - QSettings settings(GTA5SYNC_APPVENDOR, GTA5SYNC_APPSTR); - settings.beginGroup("Interface"); - currentLanguage = settings.value("Language","System").toString(); - settings.endGroup(); + settings->beginGroup("Interface"); + currentLanguage = settings->value("Language","System").toString(); + settings->endGroup(); QString cbSysStr = tr("%1 (%2 if available) [sys]", "System like PC System = %1, System Language like Deutsch = %2").arg(tr("System", "System like PC System"), QLocale::system().nativeLanguageName()); @@ -117,6 +122,30 @@ void OptionsDialog::setupLanguageBox() } } +void OptionsDialog::setupRadioButtons() +{ + bool contentModeOk; + settings->beginGroup("Profile"); + contentMode = settings->value("ContentMode", 0).toInt(&contentModeOk); + settings->endGroup(); + + if (contentModeOk) + { + if (contentMode == 0) + { + ui->rbOpenWithSC->setChecked(true); + } + else if (contentMode == 1) + { + ui->rbOpenWithDC->setChecked(true); + } + else if (contentMode == 2) + { + ui->rbSelectWithSC->setChecked(true); + } + } +} + void OptionsDialog::on_cmdOK_clicked() { applySettings(); @@ -125,13 +154,54 @@ void OptionsDialog::on_cmdOK_clicked() void OptionsDialog::applySettings() { - QSettings settings(GTA5SYNC_APPVENDOR, GTA5SYNC_APPSTR); - settings.beginGroup("Interface"); - settings.setValue("Language", ui->cbLanguage->currentData()); - settings.endGroup(); + settings->beginGroup("Interface"); + settings->setValue("Language", ui->cbLanguage->currentData()); + settings->endGroup(); + + settings->beginGroup("Profile"); + int newContentMode = 0; + if (ui->rbOpenWithSC->isChecked()) + { + newContentMode = 0; + } + else if (ui->rbOpenWithDC->isChecked()) + { + newContentMode = 1; + } + else if (ui->rbSelectWithSC->isChecked()) + { + newContentMode = 2; + } + settings->setValue("ContentMode", newContentMode); + settings->setValue("Default", ui->cbProfiles->currentData()); + settings->endGroup(); + + emit settingsApplied(newContentMode, ui->cbLanguage->currentData().toString()); if (ui->cbLanguage->currentData().toString() != currentLanguage) { QMessageBox::information(this, tr("%1", "%1").arg(GTA5SYNC_APPSTR), tr("The language change will take effect after you restart %1.").arg(GTA5SYNC_APPSTR)); } } + +void OptionsDialog::setupDefaultProfile() +{ + settings->beginGroup("Profile"); + defaultProfile = settings->value("Default", "").toString(); + settings->endGroup(); + + QString cbNoneStr = tr("No Profile", "No Profile, as default"); + ui->cbProfiles->addItem(cbNoneStr, ""); +} + +void OptionsDialog::commitProfiles(QStringList profiles) +{ + foreach(const QString &profile, profiles) + { + ui->cbProfiles->addItem(tr("Profile: %1").arg(profile), profile); + if (defaultProfile == profile) + { + ui->cbProfiles->setCurrentText(tr("Profile: %1").arg(profile)); + } + } +} diff --git a/OptionsDialog.h b/OptionsDialog.h index 5cebad3..ea9d101 100755 --- a/OptionsDialog.h +++ b/OptionsDialog.h @@ -21,6 +21,7 @@ #include #include +#include #include #include "ProfileDatabase.h" @@ -34,18 +35,27 @@ class OptionsDialog : public QDialog public: explicit OptionsDialog(ProfileDatabase *profileDB, QWidget *parent = 0); + void commitProfiles(QStringList profiles); ~OptionsDialog(); private slots: void on_cmdOK_clicked(); +signals: + void settingsApplied(int contentMode, QString language); + private: ProfileDatabase *profileDB; Ui::OptionsDialog *ui; QList playerItems; QString currentLanguage; + QString defaultProfile; + QSettings *settings; + int contentMode; void setupTreeWidget(); void setupLanguageBox(); + void setupRadioButtons(); + void setupDefaultProfile(); void applySettings(); }; diff --git a/OptionsDialog.ui b/OptionsDialog.ui index c552f87..9b7487d 100755 --- a/OptionsDialog.ui +++ b/OptionsDialog.ui @@ -60,6 +60,18 @@ + + + + Default Profile + + + + + + + + diff --git a/ProfileInterface.cpp b/ProfileInterface.cpp index 0bd0aef..7abf4ce 100755 --- a/ProfileInterface.cpp +++ b/ProfileInterface.cpp @@ -117,9 +117,10 @@ void ProfileInterface::savegameLoaded_f(SavegameData *savegame, QString savegame { SavegameWidget *sgdWidget = new SavegameWidget(); sgdWidget->setSavegameData(savegame, savegamePath); + sgdWidget->setContentMode(contentMode); widgets[sgdWidget] = "SGD" + QFileInfo(savegamePath).fileName(); savegames.append(savegame); - if (selectedWidgts != 0) { sgdWidget->setSelectionMode(true); } + if (selectedWidgts != 0 || contentMode == 2) { sgdWidget->setSelectionMode(true); } QObject::connect(sgdWidget, SIGNAL(savegameDeleted()), this, SLOT(savegameDeleted())); QObject::connect(sgdWidget, SIGNAL(widgetSelected()), this, SLOT(profileWidgetSelected())); QObject::connect(sgdWidget, SIGNAL(widgetDeselected()), this, SLOT(profileWidgetDeselected())); @@ -137,9 +138,10 @@ void ProfileInterface::pictureLoaded_f(SnapmaticPicture *picture, QString pictur { SnapmaticWidget *picWidget = new SnapmaticWidget(profileDB, threadDB); picWidget->setSnapmaticPicture(picture, picturePath); + picWidget->setContentMode(contentMode); widgets[picWidget] = "PIC" + picture->getPictureSortStr(); pictures.append(picture); - if (selectedWidgts != 0) { picWidget->setSelectionMode(true); } + if (selectedWidgts != 0 || contentMode == 2) { picWidget->setSelectionMode(true); } QObject::connect(picWidget, SIGNAL(pictureDeleted()), this, SLOT(pictureDeleted())); QObject::connect(picWidget, SIGNAL(widgetSelected()), this, SLOT(profileWidgetSelected())); QObject::connect(picWidget, SIGNAL(widgetDeselected()), this, SLOT(profileWidgetDeselected())); @@ -561,7 +563,10 @@ void ProfileInterface::profileWidgetDeselected() int scrollBarValue = ui->saProfile->verticalScrollBar()->value(); foreach(ProfileWidget *widget, widgets.keys()) { - widget->setSelectionMode(false); + if (contentMode != 2) + { + widget->setSelectionMode(false); + } } ui->saProfile->verticalScrollBar()->setValue(scrollBarValue); } @@ -780,3 +785,29 @@ void ProfileInterface::importFiles() { on_cmdImport_clicked(); } + +void ProfileInterface::settingsApplied(int _contentMode, QString language) +{ + Q_UNUSED(language) + contentMode = _contentMode; + + if (contentMode == 2) + { + foreach(ProfileWidget *widget, widgets.keys()) + { + widget->setSelectionMode(true); + widget->setContentMode(contentMode); + } + } + else + { + foreach(ProfileWidget *widget, widgets.keys()) + { + if (selectedWidgts == 0) + { + widget->setSelectionMode(false); + } + widget->setContentMode(contentMode); + } + } +} diff --git a/ProfileInterface.h b/ProfileInterface.h index 184d0c6..78d98f9 100755 --- a/ProfileInterface.h +++ b/ProfileInterface.h @@ -45,6 +45,7 @@ class ProfileInterface : public QWidget public: explicit ProfileInterface(ProfileDatabase *profileDB, CrewDatabase *crewDB, DatabaseThread *threadDB, QWidget *parent = 0); void setProfileFolder(QString folder, QString profile); + void settingsApplied(int contentMode, QString language); void setupProfileInterface(); ~ProfileInterface(); @@ -84,6 +85,7 @@ private: QString profileName; QString loadingStr; int selectedWidgts; + int contentMode; bool importFile(QString selectedFile, bool warn); bool importSnapmaticPicture(SnapmaticPicture *picture, QString picPath, bool warn = true); diff --git a/ProfileWidget.cpp b/ProfileWidget.cpp index ac76743..1b208e2 100755 --- a/ProfileWidget.cpp +++ b/ProfileWidget.cpp @@ -21,7 +21,7 @@ ProfileWidget::ProfileWidget(QWidget *parent) : QWidget(parent) { - + contentMode = 0; } ProfileWidget::~ProfileWidget() @@ -49,3 +49,13 @@ QString ProfileWidget::getWidgetType() qDebug() << "ProfileWidget::getWidgetType got used without overwrite"; return "ProfileWidget"; } + +int ProfileWidget::getContentMode() +{ + return contentMode; +} + +void ProfileWidget::setContentMode(int _contentMode) +{ + contentMode = _contentMode; +} diff --git a/ProfileWidget.h b/ProfileWidget.h index c6b8267..cde3218 100755 --- a/ProfileWidget.h +++ b/ProfileWidget.h @@ -27,11 +27,16 @@ class ProfileWidget : public QWidget public: explicit ProfileWidget(QWidget *parent = 0); virtual void setSelectionMode(bool selectionMode); + virtual void setContentMode(int contentMode); virtual void setSelected(bool isSelected); virtual bool isSelected(); virtual QString getWidgetType(); + virtual int getContentMode(); ~ProfileWidget(); +private: + int contentMode; + signals: public slots: diff --git a/SavegameWidget.cpp b/SavegameWidget.cpp index 54a1b2e..18c37b0 100755 --- a/SavegameWidget.cpp +++ b/SavegameWidget.cpp @@ -53,7 +53,6 @@ SavegameWidget::SavegameWidget(QWidget *parent) : highlightBackColor = palette.highlight().color(); highlightTextColor = palette.highlightedText().color(); - clkIssued = 0; sgdPath = ""; sgdStr = ""; sgdata = 0; @@ -131,8 +130,7 @@ void SavegameWidget::on_cmdView_clicked() void SavegameWidget::mousePressEvent(QMouseEvent *ev) { - ProfileWidget::mouseReleaseEvent(ev); - clkIssued = true; + ProfileWidget::mousePressEvent(ev); } void SavegameWidget::mouseReleaseEvent(QMouseEvent *ev) @@ -142,14 +140,12 @@ void SavegameWidget::mouseReleaseEvent(QMouseEvent *ev) { if (rect().contains(ev->pos()) && ev->button() == Qt::LeftButton) { - clkIssued = false; - //QTimer::singleShot(QApplication::doubleClickInterval(), this, SLOT(changeCheckedState())); ui->cbSelected->setChecked(!ui->cbSelected->isChecked()); } } else { - if (rect().contains(ev->pos()) && ev->button() == Qt::LeftButton) + if (getContentMode() == 0 && rect().contains(ev->pos()) && ev->button() == Qt::LeftButton) { on_cmdView_clicked(); } @@ -158,20 +154,11 @@ void SavegameWidget::mouseReleaseEvent(QMouseEvent *ev) void SavegameWidget::mouseDoubleClickEvent(QMouseEvent *ev) { - QWidget::mouseDoubleClickEvent(ev); + ProfileWidget::mouseDoubleClickEvent(ev); -// if (ev->button() == Qt::LeftButton) -// { -// clkIssued = true; -// on_cmdView_clicked(); -// } -} - -void SavegameWidget::changeCheckedState() -{ - if (!clkIssued) + if (!ui->cbSelected->isVisible() && getContentMode() == 1 && ev->button() == Qt::LeftButton) { - ui->cbSelected->setChecked(!ui->cbSelected->isChecked()); + on_cmdView_clicked(); } } diff --git a/SavegameWidget.h b/SavegameWidget.h index b3003fb..ca4571a 100755 --- a/SavegameWidget.h +++ b/SavegameWidget.h @@ -50,7 +50,6 @@ private slots: void on_cmdCopy_clicked(); void on_cmdDelete_clicked(); void on_cbSelected_stateChanged(int arg1); - void changeCheckedState(); void savegameSelected(); void selectAllWidgets(); void deselectAllWidgets(); @@ -69,7 +68,6 @@ private: QColor highlightTextColor; QString sgdPath; QString sgdStr; - bool clkIssued; signals: void savegameDeleted(); diff --git a/SnapmaticWidget.cpp b/SnapmaticWidget.cpp index b56fea7..582904c 100755 --- a/SnapmaticWidget.cpp +++ b/SnapmaticWidget.cpp @@ -45,7 +45,6 @@ SnapmaticWidget::SnapmaticWidget(ProfileDatabase *profileDB, DatabaseThread *thr highlightBackColor = palette.highlight().color(); highlightTextColor = palette.highlightedText().color(); - clkIssued = 0; picPath = ""; picStr = ""; smpic = 0; @@ -156,14 +155,12 @@ void SnapmaticWidget::mouseReleaseEvent(QMouseEvent *ev) { if (rect().contains(ev->pos()) && ev->button() == Qt::LeftButton) { - clkIssued = false; - //QTimer::singleShot(QApplication::doubleClickInterval(), this, SLOT(changeCheckedState())); ui->cbSelected->setChecked(!ui->cbSelected->isChecked()); } } else { - if (rect().contains(ev->pos()) && ev->button() == Qt::LeftButton) + if (getContentMode() == 0 && rect().contains(ev->pos()) && ev->button() == Qt::LeftButton) { on_cmdView_clicked(); } @@ -172,20 +169,11 @@ void SnapmaticWidget::mouseReleaseEvent(QMouseEvent *ev) void SnapmaticWidget::mouseDoubleClickEvent(QMouseEvent *ev) { - QWidget::mouseDoubleClickEvent(ev); + ProfileWidget::mouseDoubleClickEvent(ev); - // if (ev->button() == Qt::LeftButton) - // { - // clkIssued = true; - // on_cmdView_clicked(); - // } -} - -void SnapmaticWidget::changeCheckedState() -{ - if (!clkIssued) + if (!ui->cbSelected->isVisible() && getContentMode() == 1 && ev->button() == Qt::LeftButton) { - ui->cbSelected->setChecked(!ui->cbSelected->isChecked()); + on_cmdView_clicked(); } } @@ -223,9 +211,7 @@ void SnapmaticWidget::contextMenuEvent(QContextMenuEvent *ev) contextMenu.addAction(tr("&Select"), this, SLOT(pictureSelected())); contextMenu.addAction(QIcon::fromTheme("edit-select-all"), tr("Select &All"), this, SLOT(selectAllWidgets()), QKeySequence::fromString("Ctrl+A")); } - //ui->SnapmaticFrame->setStyleSheet(QString("QFrame#SnapmaticFrame{background-color: rgb(%1, %2, %3)}QLabel#labPicStr{color: rgb(%4, %5, %6)}").arg(QString::number(highlightBackColor.red()), QString::number(highlightBackColor.green()), QString::number(highlightBackColor.blue()), QString::number(highlightTextColor.red()), QString::number(highlightTextColor.green()), QString::number(highlightTextColor.blue()))); contextMenu.exec(ev->globalPos()); - //ui->SnapmaticFrame->setStyleSheet(""); } void SnapmaticWidget::dialogNextPictureRequested() diff --git a/SnapmaticWidget.h b/SnapmaticWidget.h index 76ed809..0ee9fc4 100755 --- a/SnapmaticWidget.h +++ b/SnapmaticWidget.h @@ -54,7 +54,6 @@ private slots: void on_cmdExport_clicked(); void on_cmdDelete_clicked(); void on_cbSelected_stateChanged(int arg1); - void changeCheckedState(); void pictureSelected(); void selectAllWidgets(); void deselectAllWidgets(); @@ -78,7 +77,6 @@ private: QString picPath; QString picTitl; QString picStr; - bool clkIssued; signals: void pictureDeleted(); diff --git a/UserInterface.cpp b/UserInterface.cpp index 073dd3f..f54b3c5 100755 --- a/UserInterface.cpp +++ b/UserInterface.cpp @@ -48,6 +48,7 @@ UserInterface::UserInterface(ProfileDatabase *profileDB, CrewDatabase *crewDB, D ui(new Ui::UserInterface) { ui->setupUi(this); + contentMode = 0; profileOpen = 0; profileUI = 0; ui->menuProfile->setEnabled(false); @@ -78,9 +79,16 @@ void UserInterface::setupDirEnv() } // profiles init - QSettings SyncSettings(GTA5SYNC_APPVENDOR, GTA5SYNC_APPSTR); - SyncSettings.beginGroup("Profile"); - QString defaultProfile = SyncSettings.value("Default", "").toString(); + QSettings settings(GTA5SYNC_APPVENDOR, GTA5SYNC_APPSTR); + settings.beginGroup("Profile"); + QString defaultProfile = settings.value("Default", "").toString(); + + bool contentModeOk; + contentMode = settings.value("ContentMode", 0).toInt(&contentModeOk); + if (contentMode != 0 || contentMode != 1 || contentMode != 2) + { + contentMode = 0; + } if (folderExists) { @@ -88,8 +96,8 @@ void UserInterface::setupDirEnv() GTAV_ProfilesFolder = GTAV_Folder + QDir::separator() + "Profiles"; GTAV_ProfilesDir.setPath(GTAV_ProfilesFolder); - QStringList GTAV_Profiles = GTAV_ProfilesDir.entryList(QDir::Dirs | QDir::NoDotAndDotDot, QDir::NoSort); - setupProfileUi(GTAV_Profiles); + GTAV_Profiles = GTAV_ProfilesDir.entryList(QDir::Dirs | QDir::NoDotAndDotDot, QDir::NoSort); + setupProfileUi(); if (GTAV_Profiles.length() == 1) { @@ -102,11 +110,13 @@ void UserInterface::setupDirEnv() } else { - setupProfileUi(QStringList()); + GTAV_Profiles = QStringList(); + setupProfileUi(); } + settings.endGroup(); } -void UserInterface::setupProfileUi(QStringList GTAV_Profiles) +void UserInterface::setupProfileUi() { if (GTAV_Profiles.length() == 0) { @@ -167,7 +177,8 @@ void UserInterface::openProfile(QString profileName) profileUI = new ProfileInterface(profileDB, crewDB, threadDB); ui->swProfile->addWidget(profileUI); ui->swProfile->setCurrentWidget(profileUI); - profileUI->setProfileFolder(GTAV_ProfilesFolder + "/" + profileName, profileName); + profileUI->setProfileFolder(GTAV_ProfilesFolder + QDir::separator() + profileName, profileName); + profileUI->settingsApplied(contentMode, language); profileUI->setupProfileInterface(); QObject::connect(profileUI, SIGNAL(profileClosed()), this, SLOT(closeProfile())); QObject::connect(profileUI, SIGNAL(profileLoaded()), this, SLOT(profileLoaded())); @@ -232,38 +243,55 @@ void UserInterface::profileLoaded() void UserInterface::on_actionSelect_all_triggered() { - profileUI->selectAllWidgets(); + if (profileOpen) + { + profileUI->selectAllWidgets(); + } } void UserInterface::on_actionDeselect_all_triggered() { - profileUI->deselectAllWidgets(); + if (profileOpen) + { + profileUI->deselectAllWidgets(); + } } void UserInterface::on_actionExport_selected_triggered() { - profileUI->exportSelected(); + if (profileOpen) + { + profileUI->exportSelected(); + } } void UserInterface::on_actionDelete_selected_triggered() { - profileUI->deleteSelected(); + if (profileOpen) + { + profileUI->deleteSelected(); + } } void UserInterface::on_actionOptions_triggered() { OptionsDialog *optionsDialog = new OptionsDialog(profileDB, this); optionsDialog->setWindowFlags(optionsDialog->windowFlags()^Qt::WindowContextHelpButtonHint); + optionsDialog->commitProfiles(GTAV_Profiles); + QObject::connect(optionsDialog, SIGNAL(settingsApplied(int,QString)), this, SLOT(settingsApplied(int,QString))); + optionsDialog->setModal(true); optionsDialog->show(); optionsDialog->exec(); - optionsDialog->deleteLater(); delete optionsDialog; } void UserInterface::on_action_Import_triggered() { - profileUI->importFiles(); + if (profileOpen) + { + profileUI->importFiles(); + } } void UserInterface::on_actionOpen_File_triggered() @@ -401,3 +429,13 @@ void UserInterface::openSavegameFile(SavegameData *savegame) sgdDialog->exec(); delete sgdDialog; } + +void UserInterface::settingsApplied(int _contentMode, QString _language) +{ + language = _language; + contentMode = _contentMode; + if (profileOpen) + { + profileUI->settingsApplied(contentMode, language); + } +} diff --git a/UserInterface.h b/UserInterface.h index b908bb0..a3dc952 100755 --- a/UserInterface.h +++ b/UserInterface.h @@ -57,6 +57,7 @@ private slots: void on_actionOptions_triggered(); void on_action_Import_triggered(); void on_actionOpen_File_triggered(); + void settingsApplied(int contentMode, QString language); private: ProfileDatabase *profileDB; @@ -66,10 +67,13 @@ private: ProfileInterface *profileUI; QList profileBtns; bool profileOpen; + int contentMode; + QString language; QString defaultWindowTitle; QString GTAV_Folder; QString GTAV_ProfilesFolder; - void setupProfileUi(QStringList GTAV_Profiles); + QStringList GTAV_Profiles; + void setupProfileUi(); void openProfile(QString profileName); void openSelectProfile();