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 <QVariantMap>
#include <QJsonArray>
#include <QKeyEvent>
#include <QDebug>
#include <QList>
#include <QUrl>
@ -46,6 +47,7 @@ PictureDialog::PictureDialog(ProfileDatabase *profileDB, QWidget *parent) :
jsonDrawString = ui->labJSON->text();
ui->cmdExport->setEnabled(0);
plyrsList = QStringList();
indexed = 0;
picTitl = "";
picPath = "";
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 &GTA Snapmatic..."), this, SLOT(copySnapmaticPicture()));
ui->cmdExport->setMenu(exportMenu);
installEventFilter(this);
}
PictureDialog::~PictureDialog()
@ -67,8 +71,31 @@ PictureDialog::~PictureDialog()
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
QImage snapmaticPicture;
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()
{
if (plyrsList.count() >= 1)
@ -196,3 +253,13 @@ void PictureDialog::on_labPicture_mouseDoubleClicked()
pictureWidget->deleteLater();
delete pictureWidget;
}
bool PictureDialog::isIndexed()
{
return indexed;
}
int PictureDialog::getIndex()
{
return index;
}

View file

@ -33,7 +33,15 @@ class PictureDialog : public QDialog
Q_OBJECT
public:
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);
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();
public slots:
@ -44,6 +52,13 @@ private slots:
void exportSnapmaticPicture();
void on_labPicture_mouseDoubleClicked();
signals:
void nextPictureRequested();
void previousPictureRequested();
protected:
bool eventFilter(QObject *obj, QEvent *ev);
private:
ProfileDatabase *profileDB;
Ui::PictureDialog *ui;
@ -57,6 +72,8 @@ private:
QString locX;
QString locY;
QString locZ;
bool indexed;
int index;
QMenu *exportMenu;
};

View file

@ -22,6 +22,7 @@
#include "SnapmaticWidget.h"
#include "DatabaseThread.h"
#include "SavegameWidget.h"
#include "PictureDialog.h"
#include "PictureExport.h"
#include "StandardPaths.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(allWidgetsSelected()), this, SLOT(selectAllWidgets()));
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); }
}
@ -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()
{
ui->vlSavegame->setEnabled(false);

View file

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

View file

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

View file

@ -40,6 +40,7 @@ class SnapmaticWidget : public ProfileWidget
public:
SnapmaticWidget(ProfileDatabase *profileDB, DatabaseThread *threadDB, QWidget *parent = 0);
void setSnapmaticPicture(SnapmaticPicture *picture, QString picturePath);
void setSnapmaticPicture(SnapmaticPicture *picture);
void setSelectionMode(bool selectionMode);
void setSelected(bool isSelected);
SnapmaticPicture *getPicture();
@ -57,6 +58,8 @@ private slots:
void pictureSelected();
void selectAllWidgets();
void deselectAllWidgets();
void dialogNextPictureRequested();
void dialogPreviousPictureRequested();
protected:
bool eventFilter(QObject *obj, QEvent *ev);
@ -83,6 +86,8 @@ signals:
void widgetDeselected();
void allWidgetsSelected();
void allWidgetsDeselected();
void nextPictureRequested(QWidget *dialog);
void previousPictureRequested(QWidget *dialog);
};
#endif // SNAPMATICWIDGET_H

View file

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