selection mode added

This commit is contained in:
Rafael 2016-04-03 01:18:48 +02:00
parent d2baaa961e
commit 58b3843e94
11 changed files with 259 additions and 19 deletions

View file

@ -44,6 +44,7 @@ ProfileInterface::ProfileInterface(ProfileDatabase *profileDB, CrewDatabase *cre
ui->cmdImport->setEnabled(false); ui->cmdImport->setEnabled(false);
ui->cmdCloseProfile->setEnabled(false); ui->cmdCloseProfile->setEnabled(false);
loadingStr = ui->labProfileLoading->text(); loadingStr = ui->labProfileLoading->text();
selectedWidgts = 0;
profileFolder = ""; profileFolder = "";
profileLoader = 0; profileLoader = 0;
saSpacerItem = 0; saSpacerItem = 0;
@ -66,7 +67,7 @@ ProfileInterface::~ProfileInterface()
picture->deleteLater(); picture->deleteLater();
delete picture; delete picture;
} }
foreach(QWidget *widget, widgets.keys()) foreach(ProfileWidget *widget, widgets.keys())
{ {
widgets.remove(widget); widgets.remove(widget);
widget->deleteLater(); widget->deleteLater();
@ -102,6 +103,8 @@ void ProfileInterface::on_savegameLoaded(SavegameData *savegame, QString savegam
widgets[sgdWidget] = "SavegameWidget"; widgets[sgdWidget] = "SavegameWidget";
savegames.append(savegame); savegames.append(savegame);
QObject::connect(sgdWidget, SIGNAL(savegameDeleted()), this, SLOT(on_savegameDeleted())); 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) void ProfileInterface::on_pictureLoaded(SnapmaticPicture *picture, QString picturePath)
@ -112,6 +115,8 @@ void ProfileInterface::on_pictureLoaded(SnapmaticPicture *picture, QString pictu
widgets[picWidget] = "SnapmaticWidget"; widgets[picWidget] = "SnapmaticWidget";
pictures.append(picture); pictures.append(picture);
QObject::connect(picWidget, SIGNAL(pictureDeleted()), this, SLOT(on_pictureDeleted())); 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) void ProfileInterface::on_loadingProgress(int value, int maximum)
@ -323,3 +328,27 @@ bool ProfileInterface::importSavegameData(SavegameData *savegame, QString sgdPat
return false; 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--;
}

View file

@ -24,6 +24,7 @@
#include "ProfileDatabase.h" #include "ProfileDatabase.h"
#include "DatabaseThread.h" #include "DatabaseThread.h"
#include "ProfileLoader.h" #include "ProfileLoader.h"
#include "ProfileWidget.h"
#include "SavegameData.h" #include "SavegameData.h"
#include "CrewDatabase.h" #include "CrewDatabase.h"
#include <QSpacerItem> #include <QSpacerItem>
@ -53,6 +54,8 @@ private slots:
void on_pictureDeleted(); void on_pictureDeleted();
void on_profileLoaded(); void on_profileLoaded();
void on_cmdImport_clicked(); void on_cmdImport_clicked();
void on_profileWidgetSelected();
void on_profileWidgetDeselected();
private: private:
ProfileDatabase *profileDB; ProfileDatabase *profileDB;
@ -63,11 +66,12 @@ private:
ProfileLoader *profileLoader; ProfileLoader *profileLoader;
QList<SavegameData*> savegames; QList<SavegameData*> savegames;
QList<SnapmaticPicture*> pictures; QList<SnapmaticPicture*> pictures;
QMap<QWidget*,QString> widgets; QMap<ProfileWidget*,QString> widgets;
QSpacerItem *saSpacerItem; QSpacerItem *saSpacerItem;
QString profileFolder; QString profileFolder;
QString profileName; QString profileName;
QString loadingStr; QString loadingStr;
int selectedWidgts;
bool importSnapmaticPicture(SnapmaticPicture *picture, QString picPath); bool importSnapmaticPicture(SnapmaticPicture *picture, QString picPath);
bool importSavegameData(SavegameData *savegame, QString sgdPath); bool importSavegameData(SavegameData *savegame, QString sgdPath);

30
ProfileWidget.cpp Executable file
View file

@ -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 <http://www.gnu.org/licenses/>.
*****************************************************************************/
#include "ProfileWidget.h"
#include <QDebug>
ProfileWidget::ProfileWidget(QWidget *parent) : QWidget(parent)
{
}
void ProfileWidget::setSelectionMode(bool selectionMode)
{
qDebug() << "ProfileWidget got used without overwrite, result:" << selectionMode;
}

36
ProfileWidget.h Executable file
View file

@ -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 <http://www.gnu.org/licenses/>.
*****************************************************************************/
#ifndef PROFILEWIDGET_H
#define PROFILEWIDGET_H
#include <QWidget>
class ProfileWidget : public QWidget
{
Q_OBJECT
public:
explicit ProfileWidget(QWidget *parent = 0);
virtual void setSelectionMode(bool selectionMode);
signals:
public slots:
};
#endif // PROFILEWIDGET_H

View file

@ -28,13 +28,18 @@
#include <QSettings> #include <QSettings>
#include <QFileInfo> #include <QFileInfo>
#include <QFile> #include <QFile>
#include <QMenu>
#include <QUrl> #include <QUrl>
SavegameWidget::SavegameWidget(QWidget *parent) : SavegameWidget::SavegameWidget(QWidget *parent) :
QWidget(parent), ProfileWidget(parent),
ui(new Ui::SavegameWidget) ui(new Ui::SavegameWidget)
{ {
ui->setupUi(this); ui->setupUi(this);
ui->cmdCopy->setVisible(false);
ui->cmdView->setVisible(false);
ui->cmdDelete->setVisible(false);
ui->cbSelected->setVisible(false);
sgdPath = ""; sgdPath = "";
sgdStr = ""; sgdStr = "";
sgdata = 0; sgdata = 0;
@ -78,12 +83,8 @@ void SavegameWidget::on_cmdDelete_clicked()
} }
} }
void SavegameWidget::mouseDoubleClickEvent(QMouseEvent *ev) void SavegameWidget::on_cmdView_clicked()
{ {
QWidget::mouseDoubleClickEvent(ev);
if (ev->button() == Qt::LeftButton)
{
SavegameDialog *savegameDialog = new SavegameDialog(this); SavegameDialog *savegameDialog = new SavegameDialog(this);
savegameDialog->setWindowFlags(savegameDialog->windowFlags()^Qt::WindowContextHelpButtonHint); savegameDialog->setWindowFlags(savegameDialog->windowFlags()^Qt::WindowContextHelpButtonHint);
savegameDialog->setSavegameData(sgdata, sgdPath, true); savegameDialog->setSavegameData(sgdata, sgdPath, true);
@ -92,5 +93,50 @@ void SavegameWidget::mouseDoubleClickEvent(QMouseEvent *ev)
savegameDialog->exec(); savegameDialog->exec();
savegameDialog->deleteLater(); savegameDialog->deleteLater();
delete savegameDialog; delete savegameDialog;
}
void SavegameWidget::mouseDoubleClickEvent(QMouseEvent *ev)
{
QWidget::mouseDoubleClickEvent(ev);
if (ev->button() == Qt::LeftButton)
{
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);
}

View file

@ -19,29 +19,36 @@
#ifndef SAVEGAMEWIDGET_H #ifndef SAVEGAMEWIDGET_H
#define SAVEGAMEWIDGET_H #define SAVEGAMEWIDGET_H
#include "ProfileWidget.h"
#include "SavegameData.h"
#include <QContextMenuEvent>
#include <QMouseEvent> #include <QMouseEvent>
#include <QWidget> #include <QWidget>
#include "SavegameData.h"
namespace Ui { namespace Ui {
class SavegameWidget; class SavegameWidget;
} }
class SavegameWidget : public QWidget class SavegameWidget : public ProfileWidget
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit SavegameWidget(QWidget *parent = 0); SavegameWidget(QWidget *parent = 0);
void setSavegameData(SavegameData *savegame, QString savegamePath); void setSavegameData(SavegameData *savegame, QString savegamePath);
void setSelectionMode(bool selectionMode);
~SavegameWidget(); ~SavegameWidget();
private slots: private slots:
void on_cmdDelete_clicked(); void on_cmdView_clicked();
void on_cmdCopy_clicked(); void on_cmdCopy_clicked();
void on_cmdDelete_clicked();
void on_savegameSelected();
void on_cbSelected_stateChanged(int arg1);
protected: protected:
void mouseDoubleClickEvent(QMouseEvent *ev); void mouseDoubleClickEvent(QMouseEvent *ev);
void contextMenuEvent(QContextMenuEvent *ev);
private: private:
Ui::SavegameWidget *ui; Ui::SavegameWidget *ui;
@ -51,6 +58,8 @@ private:
signals: signals:
void savegameDeleted(); void savegameDeleted();
void widgetSelected();
void widgetDeselected();
}; };
#endif // SAVEGAMEWIDGET_H #endif // SAVEGAMEWIDGET_H

View file

@ -14,6 +14,13 @@
<string>Savegame Widget</string> <string>Savegame Widget</string>
</property> </property>
<layout class="QHBoxLayout" name="hlSavegameContent"> <layout class="QHBoxLayout" name="hlSavegameContent">
<item>
<widget class="QCheckBox" name="cbSelected">
<property name="text">
<string/>
</property>
</widget>
</item>
<item> <item>
<widget class="QLabel" name="labSavegamePic"> <widget class="QLabel" name="labSavegamePic">
<property name="text"> <property name="text">
@ -40,6 +47,13 @@
</property> </property>
</widget> </widget>
</item> </item>
<item>
<widget class="QPushButton" name="cmdView">
<property name="text">
<string>View</string>
</property>
</widget>
</item>
<item> <item>
<widget class="QPushButton" name="cmdCopy"> <widget class="QPushButton" name="cmdCopy">
<property name="text"> <property name="text">

View file

@ -24,13 +24,18 @@
#include <QMessageBox> #include <QMessageBox>
#include <QPixmap> #include <QPixmap>
#include <QDebug> #include <QDebug>
#include <QMenu>
#include <QFile> #include <QFile>
SnapmaticWidget::SnapmaticWidget(ProfileDatabase *profileDB, DatabaseThread *threadDB, QWidget *parent) : 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(new Ui::SnapmaticWidget)
{ {
ui->setupUi(this); ui->setupUi(this);
ui->cmdView->setVisible(false);
ui->cmdCopy->setVisible(false);
ui->cmdDelete->setVisible(false);
ui->cbSelected->setVisible(false);
picPath = ""; picPath = "";
picStr = ""; picStr = "";
smpic = 0; smpic = 0;
@ -70,6 +75,11 @@ void SnapmaticWidget::on_cmdView_clicked()
delete picDialog; delete picDialog;
} }
void SnapmaticWidget::on_cmdCopy_clicked()
{
}
void SnapmaticWidget::on_cmdDelete_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); 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(); 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);
}

View file

@ -22,6 +22,8 @@
#include "SnapmaticPicture.h" #include "SnapmaticPicture.h"
#include "ProfileDatabase.h" #include "ProfileDatabase.h"
#include "DatabaseThread.h" #include "DatabaseThread.h"
#include "ProfileWidget.h"
#include <QContextMenuEvent>
#include <QMouseEvent> #include <QMouseEvent>
#include <QWidget> #include <QWidget>
@ -29,32 +31,40 @@ namespace Ui {
class SnapmaticWidget; class SnapmaticWidget;
} }
class SnapmaticWidget : public QWidget class SnapmaticWidget : public ProfileWidget
{ {
Q_OBJECT Q_OBJECT
public: 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 setSnapmaticPicture(SnapmaticPicture *picture, QString picturePath);
void setSelectionMode(bool selectionMode);
~SnapmaticWidget(); ~SnapmaticWidget();
private slots: private slots:
void on_cmdView_clicked(); void on_cmdView_clicked();
void on_cmdCopy_clicked();
void on_cmdDelete_clicked(); void on_cmdDelete_clicked();
void on_pictureSelected();
void on_cbSelected_stateChanged(int arg1);
protected: protected:
void mouseDoubleClickEvent(QMouseEvent *ev); void mouseDoubleClickEvent(QMouseEvent *ev);
void contextMenuEvent(QContextMenuEvent *ev);
private: private:
ProfileDatabase *profileDB; ProfileDatabase *profileDB;
DatabaseThread *threadDB; DatabaseThread *threadDB;
Ui::SnapmaticWidget *ui; Ui::SnapmaticWidget *ui;
SnapmaticPicture *smpic; SnapmaticPicture *smpic;
QAction *actSelectPic;
QString picPath; QString picPath;
QString picStr; QString picStr;
signals: signals:
void pictureDeleted(); void pictureDeleted();
void widgetSelected();
void widgetDeselected();
}; };
#endif // SNAPMATICWIDGET_H #endif // SNAPMATICWIDGET_H

View file

@ -13,7 +13,14 @@
<property name="windowTitle"> <property name="windowTitle">
<string>Snapmatic Widget</string> <string>Snapmatic Widget</string>
</property> </property>
<layout class="QHBoxLayout" name="horizontalLayout"> <layout class="QHBoxLayout" name="hlSnapmaticWidget">
<item>
<widget class="QCheckBox" name="cbSelected">
<property name="text">
<string/>
</property>
</widget>
</item>
<item> <item>
<widget class="QLabel" name="labPicture"> <widget class="QLabel" name="labPicture">
<property name="minimumSize"> <property name="minimumSize">
@ -65,6 +72,13 @@
</property> </property>
</widget> </widget>
</item> </item>
<item>
<widget class="QPushButton" name="cmdCopy">
<property name="text">
<string>Copy</string>
</property>
</widget>
</item>
<item> <item>
<widget class="QPushButton" name="cmdDelete"> <widget class="QPushButton" name="cmdDelete">
<property name="text"> <property name="text">

View file

@ -32,6 +32,7 @@ SOURCES += main.cpp \
ProfileDatabase.cpp \ ProfileDatabase.cpp \
ProfileInterface.cpp \ ProfileInterface.cpp \
ProfileLoader.cpp \ ProfileLoader.cpp \
ProfileWidget.cpp \
SavegameCopy.cpp \ SavegameCopy.cpp \
SavegameData.cpp \ SavegameData.cpp \
SavegameDialog.cpp \ SavegameDialog.cpp \
@ -53,6 +54,7 @@ HEADERS += \
ProfileDatabase.h \ ProfileDatabase.h \
ProfileInterface.h \ ProfileInterface.h \
ProfileLoader.h \ ProfileLoader.h \
ProfileWidget.h \
SavegameCopy.h \ SavegameCopy.h \
SavegameData.h \ SavegameData.h \
SavegameDialog.h \ SavegameDialog.h \