PictureDialog navigating with arrow keys

This commit is contained in:
Rafael 2016-04-12 20:56:58 +02:00
parent 19ff5b4d7b
commit e27fb34908
7 changed files with 179 additions and 2 deletions

View file

@ -32,6 +32,7 @@
#include <QJsonObject> #include <QJsonObject>
#include <QVariantMap> #include <QVariantMap>
#include <QJsonArray> #include <QJsonArray>
#include <QKeyEvent>
#include <QDebug> #include <QDebug>
#include <QList> #include <QList>
#include <QUrl> #include <QUrl>
@ -46,6 +47,7 @@ PictureDialog::PictureDialog(ProfileDatabase *profileDB, QWidget *parent) :
jsonDrawString = ui->labJSON->text(); jsonDrawString = ui->labJSON->text();
ui->cmdExport->setEnabled(0); ui->cmdExport->setEnabled(0);
plyrsList = QStringList(); plyrsList = QStringList();
indexed = 0;
picTitl = ""; picTitl = "";
picPath = ""; picPath = "";
crewID = ""; crewID = "";
@ -59,6 +61,8 @@ PictureDialog::PictureDialog(ProfileDatabase *profileDB, QWidget *parent) :
exportMenu->addAction(tr("Export as &JPG picture..."), this, SLOT(exportSnapmaticPicture())); exportMenu->addAction(tr("Export as &JPG picture..."), this, SLOT(exportSnapmaticPicture()));
exportMenu->addAction(tr("Export as &GTA Snapmatic..."), this, SLOT(copySnapmaticPicture())); exportMenu->addAction(tr("Export as &GTA Snapmatic..."), this, SLOT(copySnapmaticPicture()));
ui->cmdExport->setMenu(exportMenu); ui->cmdExport->setMenu(exportMenu);
installEventFilter(this);
} }
PictureDialog::~PictureDialog() PictureDialog::~PictureDialog()
@ -67,8 +71,31 @@ PictureDialog::~PictureDialog()
delete ui; delete ui;
} }
void PictureDialog::setSnapmaticPicture(SnapmaticPicture *picture, QString picturePath, bool readOk) bool PictureDialog::eventFilter(QObject *obj, QEvent *ev)
{ {
if (obj == this)
{
if (ev->type() == QEvent::KeyPress)
{
QKeyEvent *keyEvent = (QKeyEvent*)ev;
switch (keyEvent->key()){
case Qt::Key_Left:
emit previousPictureRequested();
break;
case Qt::Key_Right:
emit nextPictureRequested();
break;
}
}
}
return false;
}
void PictureDialog::setSnapmaticPicture(SnapmaticPicture *picture, QString picturePath, bool readOk, bool _indexed, int _index)
{
indexed = _indexed;
index = _index;
// Showing error if reading error // Showing error if reading error
QImage snapmaticPicture; QImage snapmaticPicture;
picPath = picturePath; picPath = picturePath;
@ -127,6 +154,36 @@ void PictureDialog::setSnapmaticPicture(SnapmaticPicture *picture, QString pictu
} }
} }
void PictureDialog::setSnapmaticPicture(SnapmaticPicture *picture, QString picPath, bool readOk)
{
setSnapmaticPicture(picture, picPath, readOk, false, 0);
}
void PictureDialog::setSnapmaticPicture(SnapmaticPicture *picture, QString picPath)
{
setSnapmaticPicture(picture, picPath, true);
}
void PictureDialog::setSnapmaticPicture(SnapmaticPicture *picture, bool readOk, int index)
{
setSnapmaticPicture(picture, picture->getPictureFileName(), readOk, true, index);
}
void PictureDialog::setSnapmaticPicture(SnapmaticPicture *picture, bool readOk)
{
setSnapmaticPicture(picture, picture->getPictureFileName(), readOk);
}
void PictureDialog::setSnapmaticPicture(SnapmaticPicture *picture, int index)
{
setSnapmaticPicture(picture, true, index);
}
void PictureDialog::setSnapmaticPicture(SnapmaticPicture *picture)
{
setSnapmaticPicture(picture, true);
}
void PictureDialog::playerNameUpdated() void PictureDialog::playerNameUpdated()
{ {
if (plyrsList.count() >= 1) if (plyrsList.count() >= 1)
@ -196,3 +253,13 @@ void PictureDialog::on_labPicture_mouseDoubleClicked()
pictureWidget->deleteLater(); pictureWidget->deleteLater();
delete pictureWidget; delete pictureWidget;
} }
bool PictureDialog::isIndexed()
{
return indexed;
}
int PictureDialog::getIndex()
{
return index;
}

View file

@ -33,7 +33,15 @@ class PictureDialog : public QDialog
Q_OBJECT Q_OBJECT
public: public:
explicit PictureDialog(ProfileDatabase *profileDB, QWidget *parent = 0); explicit PictureDialog(ProfileDatabase *profileDB, QWidget *parent = 0);
void setSnapmaticPicture(SnapmaticPicture *picture, QString picPath, bool readOk, bool indexed, int index);
void setSnapmaticPicture(SnapmaticPicture *picture, QString picPath, bool readOk); void setSnapmaticPicture(SnapmaticPicture *picture, QString picPath, bool readOk);
void setSnapmaticPicture(SnapmaticPicture *picture, QString picPath);
void setSnapmaticPicture(SnapmaticPicture *picture, bool readOk, int index);
void setSnapmaticPicture(SnapmaticPicture *picture, bool readOk);
void setSnapmaticPicture(SnapmaticPicture *picture, int index);
void setSnapmaticPicture(SnapmaticPicture *picture);
bool isIndexed();
int getIndex();
~PictureDialog(); ~PictureDialog();
public slots: public slots:
@ -44,6 +52,13 @@ private slots:
void exportSnapmaticPicture(); void exportSnapmaticPicture();
void on_labPicture_mouseDoubleClicked(); void on_labPicture_mouseDoubleClicked();
signals:
void nextPictureRequested();
void previousPictureRequested();
protected:
bool eventFilter(QObject *obj, QEvent *ev);
private: private:
ProfileDatabase *profileDB; ProfileDatabase *profileDB;
Ui::PictureDialog *ui; Ui::PictureDialog *ui;
@ -57,6 +72,8 @@ private:
QString locX; QString locX;
QString locY; QString locY;
QString locZ; QString locZ;
bool indexed;
int index;
QMenu *exportMenu; QMenu *exportMenu;
}; };

View file

@ -22,6 +22,7 @@
#include "SnapmaticWidget.h" #include "SnapmaticWidget.h"
#include "DatabaseThread.h" #include "DatabaseThread.h"
#include "SavegameWidget.h" #include "SavegameWidget.h"
#include "PictureDialog.h"
#include "PictureExport.h" #include "PictureExport.h"
#include "StandardPaths.h" #include "StandardPaths.h"
#include "ProfileLoader.h" #include "ProfileLoader.h"
@ -143,6 +144,8 @@ void ProfileInterface::pictureLoaded_f(SnapmaticPicture *picture, QString pictur
QObject::connect(picWidget, SIGNAL(widgetDeselected()), this, SLOT(profileWidgetDeselected())); QObject::connect(picWidget, SIGNAL(widgetDeselected()), this, SLOT(profileWidgetDeselected()));
QObject::connect(picWidget, SIGNAL(allWidgetsSelected()), this, SLOT(selectAllWidgets())); QObject::connect(picWidget, SIGNAL(allWidgetsSelected()), this, SLOT(selectAllWidgets()));
QObject::connect(picWidget, SIGNAL(allWidgetsDeselected()), this, SLOT(deselectAllWidgets())); QObject::connect(picWidget, SIGNAL(allWidgetsDeselected()), this, SLOT(deselectAllWidgets()));
QObject::connect(picWidget, SIGNAL(nextPictureRequested(QWidget*)), this, SLOT(dialogNextPictureRequested(QWidget*)));
QObject::connect(picWidget, SIGNAL(previousPictureRequested(QWidget*)), this, SLOT(dialogPreviousPictureRequested(QWidget*)));
if (inserted) { insertSnapmaticIPI(picWidget); } if (inserted) { insertSnapmaticIPI(picWidget); }
} }
@ -191,6 +194,72 @@ void ProfileInterface::insertSavegameIPI(QWidget *widget)
} }
} }
void ProfileInterface::dialogNextPictureRequested(QWidget *dialog)
{
PictureDialog *picDialog = (PictureDialog*)dialog;
ProfileWidget *proWidget = (ProfileWidget*)sender();
if (widgets.contains(proWidget))
{
QString widgetKey = widgets[proWidget];
QStringList widgetsKeyList = widgets.values();
QStringList pictureKeyList = widgetsKeyList.filter("PIC", Qt::CaseSensitive);
#if QT_VERSION >= 0x050600
qSort(pictureKeyList.rbegin(), pictureKeyList.rend());
#else
qSort(pictureKeyList.begin(), pictureKeyList.end(), qGreater<QString>());
#endif
int picIndex;
if (picDialog->isIndexed())
{
picIndex = picDialog->getIndex();
}
else
{
picIndex = pictureKeyList.indexOf(QRegExp(widgetKey));
}
picIndex++;
if (pictureKeyList.length() > picIndex)
{
QString newWidgetKey = pictureKeyList.at(picIndex);
SnapmaticWidget *picWidget = (SnapmaticWidget*)widgets.key(newWidgetKey);
picDialog->setSnapmaticPicture(picWidget->getPicture(), picIndex);
}
}
}
void ProfileInterface::dialogPreviousPictureRequested(QWidget *dialog)
{
PictureDialog *picDialog = (PictureDialog*)dialog;
ProfileWidget *proWidget = (ProfileWidget*)sender();
if (widgets.contains(proWidget))
{
QString widgetKey = widgets[proWidget];
QStringList widgetsKeyList = widgets.values();
QStringList pictureKeyList = widgetsKeyList.filter("PIC", Qt::CaseSensitive);
#if QT_VERSION >= 0x050600
qSort(pictureKeyList.rbegin(), pictureKeyList.rend());
#else
qSort(pictureKeyList.begin(), pictureKeyList.end(), qGreater<QString>());
#endif
int picIndex;
if (picDialog->isIndexed())
{
picIndex = picDialog->getIndex();
}
else
{
picIndex = pictureKeyList.indexOf(QRegExp(widgetKey));
}
if (picIndex > 0)
{
picIndex--;
QString newWidgetKey = pictureKeyList.at(picIndex );
SnapmaticWidget *picWidget = (SnapmaticWidget*)widgets.key(newWidgetKey);
picDialog->setSnapmaticPicture(picWidget->getPicture(), picIndex);
}
}
}
void ProfileInterface::sortingProfileInterface() void ProfileInterface::sortingProfileInterface()
{ {
ui->vlSavegame->setEnabled(false); ui->vlSavegame->setEnabled(false);

View file

@ -65,6 +65,8 @@ private slots:
void profileLoaded_p(); void profileLoaded_p();
void profileWidgetSelected(); void profileWidgetSelected();
void profileWidgetDeselected(); void profileWidgetDeselected();
void dialogNextPictureRequested(QWidget *dialog);
void dialogPreviousPictureRequested(QWidget *dialog);
private: private:
ProfileDatabase *profileDB; ProfileDatabase *profileDB;

View file

@ -89,6 +89,11 @@ void SnapmaticWidget::setSnapmaticPicture(SnapmaticPicture *picture, QString pic
ui->labPicture->setPixmap(SnapmaticPixmap); ui->labPicture->setPixmap(SnapmaticPixmap);
} }
void SnapmaticWidget::setSnapmaticPicture(SnapmaticPicture *picture)
{
setSnapmaticPicture(picture, picture->getPictureFileName());
}
void SnapmaticWidget::on_cmdView_clicked() void SnapmaticWidget::on_cmdView_clicked()
{ {
PictureDialog *picDialog = new PictureDialog(profileDB, this); PictureDialog *picDialog = new PictureDialog(profileDB, this);
@ -98,6 +103,8 @@ void SnapmaticWidget::on_cmdView_clicked()
// be ready for playerName updated // be ready for playerName updated
QObject::connect(threadDB, SIGNAL(playerNameUpdated()), picDialog, SLOT(playerNameUpdated())); QObject::connect(threadDB, SIGNAL(playerNameUpdated()), picDialog, SLOT(playerNameUpdated()));
QObject::connect(picDialog, SIGNAL(nextPictureRequested()), this, SLOT(dialogNextPictureRequested()));
QObject::connect(picDialog, SIGNAL(previousPictureRequested()), this, SLOT(dialogPreviousPictureRequested()));
// show picture dialog // show picture dialog
picDialog->showNormal(); picDialog->showNormal();
@ -220,6 +227,16 @@ void SnapmaticWidget::contextMenuEvent(QContextMenuEvent *ev)
//ui->SnapmaticFrame->setStyleSheet(""); //ui->SnapmaticFrame->setStyleSheet("");
} }
void SnapmaticWidget::dialogNextPictureRequested()
{
emit nextPictureRequested((QWidget*)sender());
}
void SnapmaticWidget::dialogPreviousPictureRequested()
{
emit previousPictureRequested((QWidget*)sender());
}
void SnapmaticWidget::on_cbSelected_stateChanged(int arg1) void SnapmaticWidget::on_cbSelected_stateChanged(int arg1)
{ {
if (arg1 == Qt::Checked) if (arg1 == Qt::Checked)

View file

@ -40,6 +40,7 @@ class SnapmaticWidget : public ProfileWidget
public: public:
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 setSnapmaticPicture(SnapmaticPicture *picture);
void setSelectionMode(bool selectionMode); void setSelectionMode(bool selectionMode);
void setSelected(bool isSelected); void setSelected(bool isSelected);
SnapmaticPicture *getPicture(); SnapmaticPicture *getPicture();
@ -57,6 +58,8 @@ private slots:
void pictureSelected(); void pictureSelected();
void selectAllWidgets(); void selectAllWidgets();
void deselectAllWidgets(); void deselectAllWidgets();
void dialogNextPictureRequested();
void dialogPreviousPictureRequested();
protected: protected:
bool eventFilter(QObject *obj, QEvent *ev); bool eventFilter(QObject *obj, QEvent *ev);
@ -83,6 +86,8 @@ signals:
void widgetDeselected(); void widgetDeselected();
void allWidgetsSelected(); void allWidgetsSelected();
void allWidgetsDeselected(); void allWidgetsDeselected();
void nextPictureRequested(QWidget *dialog);
void previousPictureRequested(QWidget *dialog);
}; };
#endif // SNAPMATICWIDGET_H #endif // SNAPMATICWIDGET_H

View file

@ -412,7 +412,7 @@ int main(int argc, char *argv[])
bool readOk = picture.readingPictureFromFile(arg1); bool readOk = picture.readingPictureFromFile(arg1);
picDialog->setWindowFlags(picDialog->windowFlags()^Qt::WindowContextHelpButtonHint); picDialog->setWindowFlags(picDialog->windowFlags()^Qt::WindowContextHelpButtonHint);
picDialog->setWindowIcon(IconLoader::loadingAppIcon()); picDialog->setWindowIcon(IconLoader::loadingAppIcon());
picDialog->setSnapmaticPicture(&picture, arg1, readOk); picDialog->setSnapmaticPicture(&picture, readOk);
int crewID = picture.getCrewNumber(); int crewID = picture.getCrewNumber();
if (crewID != 0) { crewDB->addCrew(crewID); } if (crewID != 0) { crewDB->addCrew(crewID); }