From b53c27db9d3dc9fba76d853583fddd244c869eda Mon Sep 17 00:00:00 2001 From: Rafael Date: Sun, 3 Apr 2016 08:39:31 +0200 Subject: [PATCH] in selection mode view only with right click, menuBar Edit menu added --- ProfileInterface.cpp | 25 ++++++++++++++++--- ProfileInterface.h | 9 +++++-- ProfileWidget.cpp | 9 +++++-- ProfileWidget.h | 1 + SavegameWidget.cpp | 36 +++++++++++++-------------- SavegameWidget.h | 2 +- SnapmaticWidget.cpp | 21 ++++++++-------- SnapmaticWidget.h | 2 +- UserInterface.cpp | 47 +++++++++++++++++++++++++++++++++-- UserInterface.h | 4 +++ UserInterface.ui | 59 ++++++++++++++++++++++++++++++++++++++++++++ 11 files changed, 175 insertions(+), 40 deletions(-) diff --git a/ProfileInterface.cpp b/ProfileInterface.cpp index c51142e..3d4a117 100755 --- a/ProfileInterface.cpp +++ b/ProfileInterface.cpp @@ -94,7 +94,7 @@ void ProfileInterface::setupProfileInterface() QObject::connect(profileLoader, SIGNAL(savegameLoaded(SavegameData*, QString)), this, SLOT(savegameLoaded(SavegameData*, QString))); QObject::connect(profileLoader, SIGNAL(pictureLoaded(SnapmaticPicture*, QString)), this, SLOT(pictureLoaded(SnapmaticPicture*, QString))); QObject::connect(profileLoader, SIGNAL(loadingProgress(int,int)), this, SLOT(loadingProgress(int,int))); - QObject::connect(profileLoader, SIGNAL(finished()), this, SLOT(profileLoaded())); + QObject::connect(profileLoader, SIGNAL(finished()), this, SLOT(profileLoaded_p())); profileLoader->start(); } @@ -131,20 +131,21 @@ void ProfileInterface::loadingProgress(int value, int maximum) ui->labProfileLoading->setText(loadingStr.arg(QString::number(value), QString::number(maximum))); } -void ProfileInterface::profileLoaded() +void ProfileInterface::profileLoaded_p() { saSpacerItem = new QSpacerItem(0, 0, QSizePolicy::Minimum, QSizePolicy::Expanding); ui->saProfileContent->layout()->addItem(saSpacerItem); ui->swProfile->setCurrentWidget(ui->pageProfile); ui->cmdCloseProfile->setEnabled(true); ui->cmdImport->setEnabled(true); + emit profileLoaded(); } void ProfileInterface::savegameDeleted() { SavegameWidget *sgdWidget = (SavegameWidget*)sender(); SavegameData *savegame = sgdWidget->getSavegame(); - if (sgdWidget->isSelected()) { sgdWidget->setChecked(false); } + if (sgdWidget->isSelected()) { sgdWidget->setSelected(false); } sgdWidget->close(); savegames.removeAll(savegame); delete savegame; @@ -154,7 +155,7 @@ void ProfileInterface::pictureDeleted() { SnapmaticWidget *picWidget = (SnapmaticWidget*)sender(); SnapmaticPicture *picture = picWidget->getPicture(); - if (picWidget->isSelected()) { picWidget->setChecked(false); } + if (picWidget->isSelected()) { picWidget->setSelected(false); } picWidget->close(); pictures.removeAll(picture); delete picture; @@ -363,3 +364,19 @@ void ProfileInterface::profileWidgetDeselected() } selectedWidgts--; } + +void ProfileInterface::selectAllWidgets() +{ + foreach(ProfileWidget *widget, widgets.keys()) + { + widget->setSelected(true); + } +} + +void ProfileInterface::deselectAllWidgets() +{ + foreach(ProfileWidget *widget, widgets.keys()) + { + widget->setSelected(false); + } +} diff --git a/ProfileInterface.h b/ProfileInterface.h index df17935..8bf428f 100755 --- a/ProfileInterface.h +++ b/ProfileInterface.h @@ -45,15 +45,19 @@ public: void setupProfileInterface(); ~ProfileInterface(); +public slots: + void selectAllWidgets(); + void deselectAllWidgets(); + private slots: void on_cmdCloseProfile_clicked(); void on_cmdImport_clicked(); void pictureLoaded(SnapmaticPicture *picture, QString picturePath); void savegameLoaded(SavegameData *savegame, QString savegamePath); void loadingProgress(int value, int maximum); - void savegameDeleted(); void pictureDeleted(); - void profileLoaded(); + void savegameDeleted(); + void profileLoaded_p(); void profileWidgetSelected(); void profileWidgetDeselected(); @@ -77,6 +81,7 @@ private: bool importSavegameData(SavegameData *savegame, QString sgdPath); signals: + void profileLoaded(); void profileClosed(); }; diff --git a/ProfileWidget.cpp b/ProfileWidget.cpp index 98f42ac..e0190de 100755 --- a/ProfileWidget.cpp +++ b/ProfileWidget.cpp @@ -30,11 +30,16 @@ ProfileWidget::~ProfileWidget() bool ProfileWidget::isSelected() { - qDebug() << "ProfileWidget got used without overwrite"; + qDebug() << "ProfileWidget::isSelected got used without overwrite"; return false; } +void ProfileWidget::setSelected(bool isSelected) +{ + qDebug() << "ProfileWidget::setSelected got used without overwrite, result" << isSelected; +} + void ProfileWidget::setSelectionMode(bool selectionMode) { - qDebug() << "ProfileWidget got used without overwrite, result:" << selectionMode; + qDebug() << "ProfileWidget::setSelectionMode got used without overwrite, result:" << selectionMode; } diff --git a/ProfileWidget.h b/ProfileWidget.h index c8c6cd6..3fc46fb 100755 --- a/ProfileWidget.h +++ b/ProfileWidget.h @@ -27,6 +27,7 @@ class ProfileWidget : public QWidget public: explicit ProfileWidget(QWidget *parent = 0); virtual void setSelectionMode(bool selectionMode); + virtual void setSelected(bool isSelected); virtual bool isSelected(); ~ProfileWidget(); diff --git a/SavegameWidget.cpp b/SavegameWidget.cpp index 6a65258..9d89052 100755 --- a/SavegameWidget.cpp +++ b/SavegameWidget.cpp @@ -106,17 +106,6 @@ void SavegameWidget::on_cmdView_clicked() delete savegameDialog; } - -void SavegameWidget::setChecked(bool isChecked) -{ - ui->cbSelected->setChecked(isChecked); -} - -void SavegameWidget::savegameSelected() -{ - setChecked(true); -} - void SavegameWidget::mousePressEvent(QMouseEvent *ev) { ProfileWidget::mouseReleaseEvent(ev); @@ -131,7 +120,8 @@ void SavegameWidget::mouseReleaseEvent(QMouseEvent *ev) if (rect().contains(ev->pos()) && ev->button() == Qt::LeftButton) { clkIssued = false; - QTimer::singleShot(QApplication::doubleClickInterval(), this, SLOT(changeCheckedState())); + //QTimer::singleShot(QApplication::doubleClickInterval(), this, SLOT(changeCheckedState())); + ui->cbSelected->setChecked(!ui->cbSelected->isChecked()); } } else @@ -147,11 +137,11 @@ void SavegameWidget::mouseDoubleClickEvent(QMouseEvent *ev) { QWidget::mouseDoubleClickEvent(ev); - if (ev->button() == Qt::LeftButton) - { - clkIssued = true; - on_cmdView_clicked(); - } +// if (ev->button() == Qt::LeftButton) +// { +// clkIssued = true; +// on_cmdView_clicked(); +// } } void SavegameWidget::changeCheckedState() @@ -162,10 +152,20 @@ void SavegameWidget::changeCheckedState() } } +void SavegameWidget::setSelected(bool isSelected) +{ + ui->cbSelected->setChecked(isSelected); +} + +void SavegameWidget::savegameSelected() +{ + setSelected(true); +} + void SavegameWidget::contextMenuEvent(QContextMenuEvent *ev) { QMenu contextMenu(this); - if (!ui->cbSelected->isChecked()) + if (!ui->cbSelected->isVisible()) { contextMenu.addAction(tr("Select"), this, SLOT(savegameSelected())); contextMenu.addSeparator(); diff --git a/SavegameWidget.h b/SavegameWidget.h index c2a88d2..01c8b69 100755 --- a/SavegameWidget.h +++ b/SavegameWidget.h @@ -37,7 +37,7 @@ public: SavegameWidget(QWidget *parent = 0); void setSavegameData(SavegameData *savegame, QString savegamePath); void setSelectionMode(bool selectionMode); - void setChecked(bool isChecked); + void setSelected(bool isSelected); SavegameData* getSavegame(); bool isSelected(); ~SavegameWidget(); diff --git a/SnapmaticWidget.cpp b/SnapmaticWidget.cpp index c9922d5..4e29abe 100755 --- a/SnapmaticWidget.cpp +++ b/SnapmaticWidget.cpp @@ -129,7 +129,8 @@ void SnapmaticWidget::mouseReleaseEvent(QMouseEvent *ev) if (rect().contains(ev->pos()) && ev->button() == Qt::LeftButton) { clkIssued = false; - QTimer::singleShot(QApplication::doubleClickInterval(), this, SLOT(changeCheckedState())); + //QTimer::singleShot(QApplication::doubleClickInterval(), this, SLOT(changeCheckedState())); + ui->cbSelected->setChecked(!ui->cbSelected->isChecked()); } } else @@ -145,11 +146,11 @@ void SnapmaticWidget::mouseDoubleClickEvent(QMouseEvent *ev) { QWidget::mouseDoubleClickEvent(ev); - if (ev->button() == Qt::LeftButton) - { - clkIssued = true; - on_cmdView_clicked(); - } +// if (ev->button() == Qt::LeftButton) +// { +// clkIssued = true; +// on_cmdView_clicked(); +// } } void SnapmaticWidget::changeCheckedState() @@ -160,20 +161,20 @@ void SnapmaticWidget::changeCheckedState() } } -void SnapmaticWidget::setChecked(bool isChecked) +void SnapmaticWidget::setSelected(bool isSelected) { - ui->cbSelected->setChecked(isChecked); + ui->cbSelected->setChecked(isSelected); } void SnapmaticWidget::pictureSelected() { - setChecked(true); + setSelected(true); } void SnapmaticWidget::contextMenuEvent(QContextMenuEvent *ev) { QMenu contextMenu(this); - if (!ui->cbSelected->isChecked()) + if (!ui->cbSelected->isVisible()) { contextMenu.addAction(tr("Select"), this, SLOT(pictureSelected())); contextMenu.addSeparator(); diff --git a/SnapmaticWidget.h b/SnapmaticWidget.h index e007fc5..504e4df 100755 --- a/SnapmaticWidget.h +++ b/SnapmaticWidget.h @@ -39,7 +39,7 @@ public: SnapmaticWidget(ProfileDatabase *profileDB, DatabaseThread *threadDB, QWidget *parent = 0); void setSnapmaticPicture(SnapmaticPicture *picture, QString picturePath); void setSelectionMode(bool selectionMode); - void setChecked(bool isChecked); + void setSelected(bool isSelected); bool isSelected(); SnapmaticPicture *getPicture(); ~SnapmaticWidget(); diff --git a/UserInterface.cpp b/UserInterface.cpp index aea07e1..8bbb611 100755 --- a/UserInterface.cpp +++ b/UserInterface.cpp @@ -27,6 +27,7 @@ #include #include #include +#include #include #include #include @@ -39,6 +40,7 @@ UserInterface::UserInterface(ProfileDatabase *profileDB, CrewDatabase *crewDB, D ui->setupUi(this); profileOpen = 0; profileUI = 0; + ui->menuProfile->setEnabled(false); defaultWindowTitle = this->windowTitle(); this->setWindowIcon(QIcon(":/img/5sync.png")); @@ -67,7 +69,7 @@ UserInterface::UserInterface(ProfileDatabase *profileDB, CrewDatabase *crewDB, D } else { - QMessageBox::warning(this, tr("gta5sync"), tr("GTA V Folder not found!")); + QMessageBox::warning(this, tr("gta5sync"), tr("Grand Theft Auto V Folder not found!")); } SyncSettings.endGroup(); @@ -94,7 +96,16 @@ UserInterface::UserInterface(ProfileDatabase *profileDB, CrewDatabase *crewDB, D void UserInterface::setupProfileUi(QStringList GTAV_Profiles) { - foreach(const QString >AV_Profile, GTAV_Profiles) + if (GTAV_Profiles.length() == 0) + { + QPushButton *reloadBtn = new QPushButton(tr("Reload"), ui->swSelection); + reloadBtn->setObjectName("Reload"); + reloadBtn->setAutoDefault(true); + ui->swSelection->layout()->addWidget(reloadBtn); + + QObject::connect(reloadBtn, SIGNAL(clicked(bool)), this, SLOT(reloadProfiles_clicked())); + } + else foreach(const QString >AV_Profile, GTAV_Profiles) { QPushButton *profileBtn = new QPushButton(GTAV_Profile, ui->swSelection); profileBtn->setObjectName(GTAV_Profile); @@ -122,6 +133,22 @@ void UserInterface::setupProfileUi(QStringList GTAV_Profiles) QObject::connect(cmdClose, SIGNAL(clicked(bool)), this, SLOT(close())); } +void UserInterface::reloadProfiles_clicked() +{ + QStringList gta5sync_a = qApp->arguments(); + if (gta5sync_a.length() >= 1) + { + QProcess gta5sync_p; + QString gta5sync_exe = gta5sync_a.at(0); + gta5sync_a.removeAt(0); + gta5sync_p.startDetached(gta5sync_exe, gta5sync_a); + } + else + { + QMessageBox::warning(this, tr("Reload profiles"), tr("Not able to reload profiles")); + } +} + void UserInterface::profileButton_clicked() { QPushButton *profileBtn = (QPushButton*)sender(); @@ -137,6 +164,7 @@ void UserInterface::openProfile(QString profileName) profileUI->setProfileFolder(GTAV_ProfilesFolder + "/" + profileName, profileName); profileUI->setupProfileInterface(); QObject::connect(profileUI, SIGNAL(profileClosed()), this, SLOT(closeProfile())); + QObject::connect(profileUI, SIGNAL(profileLoaded()), this, SLOT(profileLoaded())); this->setWindowTitle(defaultWindowTitle.arg(profileName)); } @@ -183,3 +211,18 @@ void UserInterface::on_actionAbout_gta5sync_triggered() aboutDialog->deleteLater(); delete aboutDialog; } + +void UserInterface::profileLoaded() +{ + ui->menuProfile->setEnabled(true); +} + +void UserInterface::on_actionSelect_all_triggered() +{ + profileUI->selectAllWidgets(); +} + +void UserInterface::on_actionDeselect_all_triggered() +{ + profileUI->deselectAllWidgets(); +} diff --git a/UserInterface.h b/UserInterface.h index 913c901..7ffbc61 100755 --- a/UserInterface.h +++ b/UserInterface.h @@ -40,10 +40,14 @@ public: private slots: void closeProfile(); + void profileLoaded(); void profileButton_clicked(); + void reloadProfiles_clicked(); void on_actionExit_triggered(); void on_actionSelect_profile_triggered(); void on_actionAbout_gta5sync_triggered(); + void on_actionSelect_all_triggered(); + void on_actionDeselect_all_triggered(); private: ProfileDatabase *profileDB; diff --git a/UserInterface.ui b/UserInterface.ui index 1679842..7b3e933 100755 --- a/UserInterface.ui +++ b/UserInterface.ui @@ -94,7 +94,26 @@ + + + Edit + + + + Profile + + + + + + + + + + + + @@ -121,6 +140,46 @@ Ctrl+P + + + Options + + + Ctrl+O + + + + + Select all + + + Ctrl+S + + + + + Deselect all + + + Shift+S + + + + + Export selected + + + Ctrl+E + + + + + Delete selected + + + Ctrl+D + +