From 58b3843e945c23a8e9ee39e05c98356eca637c6b Mon Sep 17 00:00:00 2001 From: Rafael Date: Sun, 3 Apr 2016 01:18:48 +0200 Subject: [PATCH] selection mode added --- ProfileInterface.cpp | 31 ++++++++++++++++++++- ProfileInterface.h | 6 ++++- ProfileWidget.cpp | 30 +++++++++++++++++++++ ProfileWidget.h | 36 +++++++++++++++++++++++++ SavegameWidget.cpp | 64 +++++++++++++++++++++++++++++++++++++------- SavegameWidget.h | 17 +++++++++--- SavegameWidget.ui | 14 ++++++++++ SnapmaticWidget.cpp | 48 ++++++++++++++++++++++++++++++++- SnapmaticWidget.h | 14 ++++++++-- SnapmaticWidget.ui | 16 ++++++++++- gta5sync.pro | 2 ++ 11 files changed, 259 insertions(+), 19 deletions(-) create mode 100755 ProfileWidget.cpp create mode 100755 ProfileWidget.h diff --git a/ProfileInterface.cpp b/ProfileInterface.cpp index c5fbae0..940bda3 100755 --- a/ProfileInterface.cpp +++ b/ProfileInterface.cpp @@ -44,6 +44,7 @@ ProfileInterface::ProfileInterface(ProfileDatabase *profileDB, CrewDatabase *cre ui->cmdImport->setEnabled(false); ui->cmdCloseProfile->setEnabled(false); loadingStr = ui->labProfileLoading->text(); + selectedWidgts = 0; profileFolder = ""; profileLoader = 0; saSpacerItem = 0; @@ -66,7 +67,7 @@ ProfileInterface::~ProfileInterface() picture->deleteLater(); delete picture; } - foreach(QWidget *widget, widgets.keys()) + foreach(ProfileWidget *widget, widgets.keys()) { widgets.remove(widget); widget->deleteLater(); @@ -102,6 +103,8 @@ void ProfileInterface::on_savegameLoaded(SavegameData *savegame, QString savegam widgets[sgdWidget] = "SavegameWidget"; savegames.append(savegame); QObject::connect(sgdWidget, SIGNAL(savegameDeleted()), this, SLOT(on_savegameDeleted())); + QObject::connect(sgdWidget, SIGNAL(widgetSelected()), this, SLOT(on_profileWidgetSelected())); + QObject::connect(sgdWidget, SIGNAL(widgetDeselected()), this, SLOT(on_profileWidgetDeselected())); } void ProfileInterface::on_pictureLoaded(SnapmaticPicture *picture, QString picturePath) @@ -112,6 +115,8 @@ void ProfileInterface::on_pictureLoaded(SnapmaticPicture *picture, QString pictu widgets[picWidget] = "SnapmaticWidget"; pictures.append(picture); QObject::connect(picWidget, SIGNAL(pictureDeleted()), this, SLOT(on_pictureDeleted())); + QObject::connect(picWidget, SIGNAL(widgetSelected()), this, SLOT(on_profileWidgetSelected())); + QObject::connect(picWidget, SIGNAL(widgetDeselected()), this, SLOT(on_profileWidgetDeselected())); } void ProfileInterface::on_loadingProgress(int value, int maximum) @@ -323,3 +328,27 @@ bool ProfileInterface::importSavegameData(SavegameData *savegame, QString sgdPat return false; } } + +void ProfileInterface::on_profileWidgetSelected() +{ + if (selectedWidgts == 0) + { + foreach(ProfileWidget *widget, widgets.keys()) + { + widget->setSelectionMode(true); + } + } + selectedWidgts++; +} + +void ProfileInterface::on_profileWidgetDeselected() +{ + if (selectedWidgts == 1) + { + foreach(ProfileWidget *widget, widgets.keys()) + { + widget->setSelectionMode(false); + } + } + selectedWidgts--; +} diff --git a/ProfileInterface.h b/ProfileInterface.h index 8083f82..675d547 100755 --- a/ProfileInterface.h +++ b/ProfileInterface.h @@ -24,6 +24,7 @@ #include "ProfileDatabase.h" #include "DatabaseThread.h" #include "ProfileLoader.h" +#include "ProfileWidget.h" #include "SavegameData.h" #include "CrewDatabase.h" #include @@ -53,6 +54,8 @@ private slots: void on_pictureDeleted(); void on_profileLoaded(); void on_cmdImport_clicked(); + void on_profileWidgetSelected(); + void on_profileWidgetDeselected(); private: ProfileDatabase *profileDB; @@ -63,11 +66,12 @@ private: ProfileLoader *profileLoader; QList savegames; QList pictures; - QMap widgets; + QMap widgets; QSpacerItem *saSpacerItem; QString profileFolder; QString profileName; QString loadingStr; + int selectedWidgts; bool importSnapmaticPicture(SnapmaticPicture *picture, QString picPath); bool importSavegameData(SavegameData *savegame, QString sgdPath); diff --git a/ProfileWidget.cpp b/ProfileWidget.cpp new file mode 100755 index 0000000..6046640 --- /dev/null +++ b/ProfileWidget.cpp @@ -0,0 +1,30 @@ +/***************************************************************************** +* gta5sync GRAND THEFT AUTO V SYNC +* Copyright (C) 2016 Syping +* +* 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 . +*****************************************************************************/ + +#include "ProfileWidget.h" +#include + +ProfileWidget::ProfileWidget(QWidget *parent) : QWidget(parent) +{ + +} + +void ProfileWidget::setSelectionMode(bool selectionMode) +{ + qDebug() << "ProfileWidget got used without overwrite, result:" << selectionMode; +} diff --git a/ProfileWidget.h b/ProfileWidget.h new file mode 100755 index 0000000..ebdbd0d --- /dev/null +++ b/ProfileWidget.h @@ -0,0 +1,36 @@ +/***************************************************************************** +* gta5sync GRAND THEFT AUTO V SYNC +* Copyright (C) 2016 Syping +* +* 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 . +*****************************************************************************/ + +#ifndef PROFILEWIDGET_H +#define PROFILEWIDGET_H + +#include + +class ProfileWidget : public QWidget +{ + Q_OBJECT +public: + explicit ProfileWidget(QWidget *parent = 0); + virtual void setSelectionMode(bool selectionMode); + +signals: + +public slots: +}; + +#endif // PROFILEWIDGET_H diff --git a/SavegameWidget.cpp b/SavegameWidget.cpp index 02addfe..4720e39 100755 --- a/SavegameWidget.cpp +++ b/SavegameWidget.cpp @@ -28,13 +28,18 @@ #include #include #include +#include #include SavegameWidget::SavegameWidget(QWidget *parent) : - QWidget(parent), + ProfileWidget(parent), ui(new Ui::SavegameWidget) { ui->setupUi(this); + ui->cmdCopy->setVisible(false); + ui->cmdView->setVisible(false); + ui->cmdDelete->setVisible(false); + ui->cbSelected->setVisible(false); sgdPath = ""; sgdStr = ""; sgdata = 0; @@ -78,19 +83,60 @@ void SavegameWidget::on_cmdDelete_clicked() } } +void SavegameWidget::on_cmdView_clicked() +{ + SavegameDialog *savegameDialog = new SavegameDialog(this); + savegameDialog->setWindowFlags(savegameDialog->windowFlags()^Qt::WindowContextHelpButtonHint); + savegameDialog->setSavegameData(sgdata, sgdPath, true); + savegameDialog->setModal(true); + savegameDialog->show(); + savegameDialog->exec(); + savegameDialog->deleteLater(); + delete savegameDialog; +} + void SavegameWidget::mouseDoubleClickEvent(QMouseEvent *ev) { QWidget::mouseDoubleClickEvent(ev); if (ev->button() == Qt::LeftButton) { - SavegameDialog *savegameDialog = new SavegameDialog(this); - savegameDialog->setWindowFlags(savegameDialog->windowFlags()^Qt::WindowContextHelpButtonHint); - savegameDialog->setSavegameData(sgdata, sgdPath, true); - savegameDialog->setModal(true); - savegameDialog->show(); - savegameDialog->exec(); - savegameDialog->deleteLater(); - delete savegameDialog; + on_cmdView_clicked(); } } + +void SavegameWidget::on_savegameSelected() +{ + ui->cbSelected->setChecked(true); +} + +void SavegameWidget::contextMenuEvent(QContextMenuEvent *ev) +{ + QMenu contextMenu(this); + if (!ui->cbSelected->isChecked()) + { + contextMenu.addAction(tr("Select"), this, SLOT(on_savegameSelected())); + contextMenu.addSeparator(); + } + contextMenu.addAction(tr("View savegame"), this, SLOT(on_cmdView_clicked())); + contextMenu.addAction(tr("Copy savegame"), this, SLOT(on_cmdCopy_clicked())); + contextMenu.addAction(tr("Delete savegame"), this, SLOT(on_cmdDelete_clicked())); + contextMenu.exec(ev->globalPos()); +} + +void SavegameWidget::on_cbSelected_stateChanged(int arg1) +{ + if (arg1 == Qt::Checked) + { + emit widgetSelected(); + } + else if (arg1 == Qt::Unchecked) + { + emit widgetDeselected(); + } +} + +void SavegameWidget::setSelectionMode(bool selectionMode) +{ + ui->cbSelected->setVisible(selectionMode); +} diff --git a/SavegameWidget.h b/SavegameWidget.h index 503c665..492850f 100755 --- a/SavegameWidget.h +++ b/SavegameWidget.h @@ -19,29 +19,36 @@ #ifndef SAVEGAMEWIDGET_H #define SAVEGAMEWIDGET_H +#include "ProfileWidget.h" +#include "SavegameData.h" +#include #include #include -#include "SavegameData.h" namespace Ui { class SavegameWidget; } -class SavegameWidget : public QWidget +class SavegameWidget : public ProfileWidget { Q_OBJECT public: - explicit SavegameWidget(QWidget *parent = 0); + SavegameWidget(QWidget *parent = 0); void setSavegameData(SavegameData *savegame, QString savegamePath); + void setSelectionMode(bool selectionMode); ~SavegameWidget(); private slots: - void on_cmdDelete_clicked(); + void on_cmdView_clicked(); void on_cmdCopy_clicked(); + void on_cmdDelete_clicked(); + void on_savegameSelected(); + void on_cbSelected_stateChanged(int arg1); protected: void mouseDoubleClickEvent(QMouseEvent *ev); + void contextMenuEvent(QContextMenuEvent *ev); private: Ui::SavegameWidget *ui; @@ -51,6 +58,8 @@ private: signals: void savegameDeleted(); + void widgetSelected(); + void widgetDeselected(); }; #endif // SAVEGAMEWIDGET_H diff --git a/SavegameWidget.ui b/SavegameWidget.ui index 0cbbd6c..f8ea666 100755 --- a/SavegameWidget.ui +++ b/SavegameWidget.ui @@ -14,6 +14,13 @@ Savegame Widget + + + + + + + @@ -40,6 +47,13 @@ + + + + View + + + diff --git a/SnapmaticWidget.cpp b/SnapmaticWidget.cpp index 06ec401..ffe9aee 100755 --- a/SnapmaticWidget.cpp +++ b/SnapmaticWidget.cpp @@ -24,13 +24,18 @@ #include #include #include +#include #include SnapmaticWidget::SnapmaticWidget(ProfileDatabase *profileDB, DatabaseThread *threadDB, QWidget *parent) : - QWidget(parent), profileDB(profileDB), threadDB(threadDB), + ProfileWidget(parent), profileDB(profileDB), threadDB(threadDB), ui(new Ui::SnapmaticWidget) { ui->setupUi(this); + ui->cmdView->setVisible(false); + ui->cmdCopy->setVisible(false); + ui->cmdDelete->setVisible(false); + ui->cbSelected->setVisible(false); picPath = ""; picStr = ""; smpic = 0; @@ -70,6 +75,11 @@ void SnapmaticWidget::on_cmdView_clicked() delete picDialog; } +void SnapmaticWidget::on_cmdCopy_clicked() +{ + +} + void SnapmaticWidget::on_cmdDelete_clicked() { int uchoice = QMessageBox::question(this, tr("Delete picture"), tr("Are you sure to delete %1 from your Snapmatic pictures?").arg("\""+picStr+"\""), QMessageBox::Yes | QMessageBox::No, QMessageBox::No); @@ -99,3 +109,39 @@ void SnapmaticWidget::mouseDoubleClickEvent(QMouseEvent *ev) on_cmdView_clicked(); } } + +void SnapmaticWidget::on_pictureSelected() +{ + ui->cbSelected->setChecked(true); +} + +void SnapmaticWidget::contextMenuEvent(QContextMenuEvent *ev) +{ + QMenu contextMenu(this); + if (!ui->cbSelected->isChecked()) + { + contextMenu.addAction(tr("Select"), this, SLOT(on_pictureSelected())); + contextMenu.addSeparator(); + } + contextMenu.addAction(tr("View picture"), this, SLOT(on_cmdView_clicked())); + contextMenu.addAction(tr("Copy picture"), this, SLOT(on_cmdView_clicked())); + contextMenu.addAction(tr("Delete picture"), this, SLOT(on_cmdDelete_clicked())); + contextMenu.exec(ev->globalPos()); +} + +void SnapmaticWidget::on_cbSelected_stateChanged(int arg1) +{ + if (arg1 == Qt::Checked) + { + emit widgetSelected(); + } + else if (arg1 == Qt::Unchecked) + { + emit widgetDeselected(); + } +} + +void SnapmaticWidget::setSelectionMode(bool selectionMode) +{ + ui->cbSelected->setVisible(selectionMode); +} diff --git a/SnapmaticWidget.h b/SnapmaticWidget.h index 9437afe..8dd5232 100755 --- a/SnapmaticWidget.h +++ b/SnapmaticWidget.h @@ -22,6 +22,8 @@ #include "SnapmaticPicture.h" #include "ProfileDatabase.h" #include "DatabaseThread.h" +#include "ProfileWidget.h" +#include #include #include @@ -29,32 +31,40 @@ namespace Ui { class SnapmaticWidget; } -class SnapmaticWidget : public QWidget +class SnapmaticWidget : public ProfileWidget { Q_OBJECT public: - explicit SnapmaticWidget(ProfileDatabase *profileDB, DatabaseThread *threadDB, QWidget *parent = 0); + SnapmaticWidget(ProfileDatabase *profileDB, DatabaseThread *threadDB, QWidget *parent = 0); void setSnapmaticPicture(SnapmaticPicture *picture, QString picturePath); + void setSelectionMode(bool selectionMode); ~SnapmaticWidget(); private slots: void on_cmdView_clicked(); + void on_cmdCopy_clicked(); void on_cmdDelete_clicked(); + void on_pictureSelected(); + void on_cbSelected_stateChanged(int arg1); protected: void mouseDoubleClickEvent(QMouseEvent *ev); + void contextMenuEvent(QContextMenuEvent *ev); private: ProfileDatabase *profileDB; DatabaseThread *threadDB; Ui::SnapmaticWidget *ui; SnapmaticPicture *smpic; + QAction *actSelectPic; QString picPath; QString picStr; signals: void pictureDeleted(); + void widgetSelected(); + void widgetDeselected(); }; #endif // SNAPMATICWIDGET_H diff --git a/SnapmaticWidget.ui b/SnapmaticWidget.ui index 572bc36..b389de7 100755 --- a/SnapmaticWidget.ui +++ b/SnapmaticWidget.ui @@ -13,7 +13,14 @@ Snapmatic Widget - + + + + + + + + @@ -65,6 +72,13 @@ + + + + Copy + + + diff --git a/gta5sync.pro b/gta5sync.pro index 1f8c675..cc6adcd 100755 --- a/gta5sync.pro +++ b/gta5sync.pro @@ -32,6 +32,7 @@ SOURCES += main.cpp \ ProfileDatabase.cpp \ ProfileInterface.cpp \ ProfileLoader.cpp \ + ProfileWidget.cpp \ SavegameCopy.cpp \ SavegameData.cpp \ SavegameDialog.cpp \ @@ -53,6 +54,7 @@ HEADERS += \ ProfileDatabase.h \ ProfileInterface.h \ ProfileLoader.h \ + ProfileWidget.h \ SavegameCopy.h \ SavegameData.h \ SavegameDialog.h \