pictures are openable with -showpic= argument
This commit is contained in:
parent
527a85ac23
commit
32004fe054
6 changed files with 177 additions and 8 deletions
|
@ -12,3 +12,8 @@ PictureDialog::~PictureDialog()
|
||||||
{
|
{
|
||||||
delete ui;
|
delete ui;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PictureDialog::setSnapmaticPicture(QPixmap pixmap)
|
||||||
|
{
|
||||||
|
ui->labPicture->setPixmap(pixmap);
|
||||||
|
}
|
||||||
|
|
|
@ -13,6 +13,7 @@ class PictureDialog : public QDialog
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit PictureDialog(QWidget *parent = 0);
|
explicit PictureDialog(QWidget *parent = 0);
|
||||||
|
void setSnapmaticPicture(QPixmap pixmap);
|
||||||
~PictureDialog();
|
~PictureDialog();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<ui version="4.0">
|
<ui version="4.0">
|
||||||
<class>PictureDialog</class>
|
<class>PictureDialog</class>
|
||||||
<widget class="QDialog" name="PictureDialog">
|
<widget class="QDialog" name="PictureDialog">
|
||||||
|
@ -12,6 +13,15 @@
|
||||||
<property name="windowTitle">
|
<property name="windowTitle">
|
||||||
<string>Dialog</string>
|
<string>Dialog</string>
|
||||||
</property>
|
</property>
|
||||||
|
<layout class="QVBoxLayout" name="vlPictureLayout">
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="labPicture">
|
||||||
|
<property name="text">
|
||||||
|
<string/>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
<resources/>
|
<resources/>
|
||||||
<connections/>
|
<connections/>
|
||||||
|
|
|
@ -16,8 +16,120 @@
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
|
|
||||||
#include "SnapmaticPicture.h"
|
#include "SnapmaticPicture.h"
|
||||||
|
#include <QPixmap>
|
||||||
|
#include <QString>
|
||||||
|
#include <QDebug>
|
||||||
|
#include <QFile>
|
||||||
|
int snapmaticHeaderLength = 278;
|
||||||
|
int snapmaticUsefulLength = 256;
|
||||||
|
int jpegPreHeaderLength = 14;
|
||||||
|
int jpegPicStreamLength = 524288;
|
||||||
|
|
||||||
SnapmaticPicture::SnapmaticPicture(QObject *parent) : QObject(parent)
|
SnapmaticPicture::SnapmaticPicture(QObject *parent, QString fileName) : QObject(parent)
|
||||||
{
|
{
|
||||||
|
// Init
|
||||||
|
cachePicture = QPixmap(0,0);
|
||||||
|
picFileName = "";
|
||||||
|
pictureStr = "";
|
||||||
|
lastStep = "";
|
||||||
|
jsonStr = "";
|
||||||
|
|
||||||
|
// Set pic fileName
|
||||||
|
if (fileName != "")
|
||||||
|
{
|
||||||
|
picFileName = fileName;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool SnapmaticPicture::readingPicture()
|
||||||
|
{
|
||||||
|
// Start opening file
|
||||||
|
// lastStep is like currentStep
|
||||||
|
|
||||||
|
QFile *picFile = new QFile(picFileName);
|
||||||
|
if (!picFile->open(QFile::ReadOnly))
|
||||||
|
{
|
||||||
|
lastStep = "1;/1,OpenFile," + convertDrawStringForLog(picFileName);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Reading Snapmatic Header
|
||||||
|
if (!picFile->isReadable())
|
||||||
|
{
|
||||||
|
lastStep = "2;/3,ReadingFile," + convertDrawStringForLog(picFileName) + ",1,NOHEADER";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
QByteArray snapmaticHeaderLine = picFile->read(snapmaticHeaderLength);
|
||||||
|
pictureStr = getSnapmaticPictureString(snapmaticHeaderLine);
|
||||||
|
|
||||||
|
// Reading JPEG Header Line
|
||||||
|
if (!picFile->isReadable())
|
||||||
|
{
|
||||||
|
lastStep = "2;/3,ReadingFile," + convertDrawStringForLog(picFileName) + ",2,NOHEADER";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
QByteArray jpegHeaderLine = picFile->read(jpegPreHeaderLength);
|
||||||
|
|
||||||
|
// Checking for JPEG
|
||||||
|
jpegHeaderLine.remove(0,2);
|
||||||
|
if (jpegHeaderLine.left(4) != "JPEG")
|
||||||
|
{
|
||||||
|
lastStep = "2;/3,ReadingFile," + convertDrawStringForLog(picFileName) + ",2,NOJPEG";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
lastStep = "3;/1,ReadedFile," + convertDrawStringForLog(picFileName);
|
||||||
|
QByteArray jpegRawContent = picFile->read(jpegPicStreamLength);
|
||||||
|
return cachePicture.loadFromData(jpegRawContent);
|
||||||
|
}
|
||||||
|
|
||||||
|
QString SnapmaticPicture::getSnapmaticPictureString(QByteArray snapmaticHeader)
|
||||||
|
{
|
||||||
|
QByteArray snapmaticUsefulBytes = snapmaticHeader.left(snapmaticUsefulLength);
|
||||||
|
snapmaticUsefulBytes.replace(QByteArray::fromHex("00"),"");
|
||||||
|
snapmaticUsefulBytes.replace(QByteArray::fromHex("01"),"");
|
||||||
|
return QString::fromAscii(snapmaticUsefulBytes);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool SnapmaticPicture::readingPictureFromFile(QString fileName)
|
||||||
|
{
|
||||||
|
if (fileName != "")
|
||||||
|
{
|
||||||
|
picFileName = fileName;
|
||||||
|
return readingPicture();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void SnapmaticPicture::setPixmap(QPixmap pixmap)
|
||||||
|
{
|
||||||
|
cachePicture = pixmap;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString SnapmaticPicture::getPictureStr()
|
||||||
|
{
|
||||||
|
return pictureStr;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString SnapmaticPicture::getLastStep()
|
||||||
|
{
|
||||||
|
return lastStep;
|
||||||
|
}
|
||||||
|
|
||||||
|
QPixmap SnapmaticPicture::getPixmap()
|
||||||
|
{
|
||||||
|
return cachePicture;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString SnapmaticPicture::convertDrawStringForLog(QString inputStr)
|
||||||
|
{
|
||||||
|
return inputStr.replace("&","&u;").replace(",","&c;");
|
||||||
|
}
|
||||||
|
|
||||||
|
QString SnapmaticPicture::convertLogStringForDraw(QString inputStr)
|
||||||
|
{
|
||||||
|
return inputStr.replace("&c;",",").replace("&u;","&");
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,20 +20,30 @@
|
||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QPixmap>
|
#include <QPixmap>
|
||||||
|
#include <QString>
|
||||||
|
#include <QFile>
|
||||||
|
|
||||||
class SnapmaticPicture : public QObject
|
class SnapmaticPicture : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit SnapmaticPicture(QObject *parent = 0);
|
explicit SnapmaticPicture(QObject *parent = 0, QString fileName = "");
|
||||||
bool readingPictureFromFile(QString fileName);
|
bool readingPictureFromFile(QString fileName);
|
||||||
bool setPicture(QPixmap pixmap);
|
bool readingPicture();
|
||||||
|
void setPixmap(QPixmap pixmap);
|
||||||
|
void resetValues();
|
||||||
QPixmap getPixmap();
|
QPixmap getPixmap();
|
||||||
|
QString getLastStep();
|
||||||
|
QString getPictureStr();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
QString getSnapmaticPictureString(QByteArray snapmaticHeader);
|
||||||
|
QString convertDrawStringForLog(QString inputStr);
|
||||||
|
QString convertLogStringForDraw(QString inputStr);
|
||||||
QPixmap cachePicture;
|
QPixmap cachePicture;
|
||||||
QString picDate;
|
QString picFileName;
|
||||||
QString picTime;
|
QString pictureStr;
|
||||||
|
QString lastStep;
|
||||||
QString jsonStr;
|
QString jsonStr;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
|
37
main.cpp
37
main.cpp
|
@ -15,15 +15,46 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
|
|
||||||
#include "frmGTA5Sync.h"
|
#include "SnapmaticPicture.h"
|
||||||
|
#include "PictureDialog.h"
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
|
#include <QStringList>
|
||||||
|
#include <QString>
|
||||||
|
#include <QDebug>
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
QApplication a(argc, argv);
|
QApplication a(argc, argv);
|
||||||
|
|
||||||
frmGTA5Sync w;
|
QStringList applicationArgs = a.arguments();
|
||||||
w.show();
|
QString selectedAction;
|
||||||
|
QString arg1;
|
||||||
|
|
||||||
|
foreach(QString currentArg, applicationArgs)
|
||||||
|
{
|
||||||
|
QString reworkedArg;
|
||||||
|
if (currentArg.left(9) == "-showpic=" && selectedAction == "")
|
||||||
|
{
|
||||||
|
reworkedArg = currentArg.remove(0,9);
|
||||||
|
arg1 = reworkedArg;
|
||||||
|
selectedAction = "showpic";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (selectedAction == "showpic")
|
||||||
|
{
|
||||||
|
SnapmaticPicture picture;
|
||||||
|
qDebug() << picture.readingPictureFromFile(arg1);
|
||||||
|
qDebug() << picture.getLastStep();
|
||||||
|
PictureDialog picDialog;
|
||||||
|
picDialog.setWindowTitle(picture.getPictureStr());
|
||||||
|
picDialog.setSnapmaticPicture(picture.getPixmap());
|
||||||
|
picDialog.show();
|
||||||
|
|
||||||
|
return a.exec();
|
||||||
|
|
||||||
|
qDebug() << "showpic runned";
|
||||||
|
}
|
||||||
|
|
||||||
return a.exec();
|
return a.exec();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue