Skip to content

Commit

Permalink
Merge pull request #141 from saeugetier/feature/140-get-rid-of-hard-c…
Browse files Browse the repository at this point in the history
…oded-print-size

Feature/140 get rid of hard coded print size
  • Loading branch information
saeugetier authored May 31, 2024
2 parents 9d229e0 + 485a4eb commit 757ce4c
Show file tree
Hide file tree
Showing 14 changed files with 74 additions and 37 deletions.
6 changes: 6 additions & 0 deletions XmlData.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<icon>SingleNoPrint.svg</icon>
<background>WhiteBackground.png</background>
<foreground>ExampleForeground.png</foreground>
<size width="3570" height="2380"/>
<images>
<image><position x="0.0" y="0.0"/><size width="1.0" height="1.0"/></image>
</images>
Expand All @@ -14,6 +15,7 @@
<name>Single Image</name>
<icon>Single.svg</icon>
<background>WhiteBackground.png</background>
<size width="3570" height="2380"/>
<images>
<image><position x="0.0" y="0.0"/><size width="1.0" height="1.0"/></image>
</images>
Expand All @@ -22,6 +24,7 @@
<name>Two Images</name>
<icon>Double.svg</icon>
<background>WhiteBackground.png</background>
<size width="3570" height="2380"/>
<images>
<image>
<position x="0.0" y="0.0"/><size width="0.5" height="1.0"/>
Expand All @@ -38,6 +41,7 @@
<name>Four Images</name>
<icon>Four.svg</icon>
<background>WhiteBackground.png</background>
<size width="3570" height="2380"/>
<images>
<image><position x="0.0" y="0.0"/><size width="0.5" height="0.5"/></image>
<image><position x="0.5" y="0.0"/><size width="0.5" height="0.5"/></image>
Expand All @@ -49,6 +53,7 @@
<name>Four Images with Background</name>
<icon>FourStars.svg</icon>
<background>StarsBackground.jpg</background>
<size width="3570" height="2380"/>
<images>
<image><position x="0.05" y="0.05"/><size width="0.4" height="0.4"/></image>
<image><position x="0.55" y="0.05"/><size width="0.4" height="0.4"/></image>
Expand All @@ -60,6 +65,7 @@
<name>Four Images Border</name>
<icon>FourBorder.svg</icon>
<background>WhiteBackground.png</background>
<size width="3570" height="2380"/>
<images>
<image>
<position x="0.0" y="0.0"/><size width="0.5" height="0.5"/>
Expand Down
9 changes: 5 additions & 4 deletions qml/CollageMenu.qml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ CollageMenuForm {
signal exit

printButton.enabled: !printer.busy
property real printerHeight : printer.getPrintSize().height
property real printerWidth : printer.getPrintSize().width
property real printerHeight : form.collageImage.imageModel.collagePixelSize.height
property real printerWidth : form.collageImage.imageModel.collagePixelSize.width
printerRatio: printerHeight / printerWidth

nextButton.onClicked:
Expand All @@ -33,8 +33,9 @@ CollageMenuForm {
var cleanPath = decodeURIComponent(path);
console.log(cleanPath)
var filename = cleanPath + "/collage/Coll_"+ new Date().toLocaleString(locale, "dd_MM_yyyy_hh_mm_ss") + ".png"
collageRenderer.saveImage(filename, printer.getPrintSize())
console.log("Collage rendered")
collageRenderer.saveImage(filename, form.collageImage.imageModel.collagePixelSize)
console.log("Collage rendered width: " + Number(form.collageImage.imageModel.collagePixelSize.width).toString()
+ " height: " + form.collageImage.imageModel.collagePixelSize.height)
}

collageRenderer.onSavingChanged:
Expand Down
1 change: 0 additions & 1 deletion src/abstractprinter.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ class AbstractPrinter : public QObject
Q_PROPERTY(bool busy READ busy NOTIFY busyChanged)
public:
explicit AbstractPrinter(QObject *parent = nullptr) : QObject(parent) {};
Q_INVOKABLE virtual QSize getPrintSize() = 0;
Q_INVOKABLE virtual bool printerOnline() = 0;
virtual bool busy() = 0;
signals:
Expand Down
49 changes: 49 additions & 0 deletions src/collageimagemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ bool CollageImageModel::parseXml(const QDomNode& node)
mLine = element.lineNumber();
return false;
}
else
{
mErrorMsg = "at least one background nodes required";
mLine = element.lineNumber();
return false;
}

QDomNodeList foregroundNode = element.elementsByTagName("foreground");
if(foregroundNode.count() == 1)
Expand All @@ -50,6 +56,44 @@ bool CollageImageModel::parseXml(const QDomNode& node)
return false;
}

QDomElement sizeElement = element.firstChildElement("size");
if(sizeElement.isElement())
{
if(sizeElement.hasAttributes() && sizeElement.toElement().hasAttribute("width") && sizeElement.toElement().hasAttribute("height"))
{
bool ok;
QString x = sizeElement.toElement().attribute("width");
mPixelSize.setWidth(x.toInt(&ok));
if(!ok)
{
mErrorMsg = "size 'width' must be defined as float";
mLine = sizeElement.lineNumber();
return false;
}

QString y = sizeElement.toElement().attribute("height");
mPixelSize.setHeight(y.toInt(&ok));
if(!ok)
{
mErrorMsg = "size 'height' must be defined as float";
mLine = sizeElement.lineNumber();
return false;
}
}
else
{
mErrorMsg = "size must be defined be 'width' and 'height' attributes";
mLine = sizeElement.lineNumber();
return false;
}
}
else
{
mErrorMsg = "at least one size nodes required";
mLine = element.lineNumber();
return false;
}

QDomNodeList imagesNode = element.elementsByTagName("images");
if(imagesNode.length() != 1)
{
Expand Down Expand Up @@ -231,6 +275,11 @@ bool CollageImageModel::collageFull()
return false;
}

QSize CollageImageModel::collagePixelSize() const
{
return mPixelSize;
}

bool CollageImageModel::nextImageIsEffectSelectable()
{
if(!collageFull())
Expand Down
12 changes: 6 additions & 6 deletions src/collageimagemodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,11 @@ class CollageImage : public QObject, public ModelParser
class CollageImageModel : public QAbstractListModel, public ModelParser
{
Q_OBJECT
Q_PROPERTY(QUrl backgroundImage READ backgroundImage NOTIFY backgroundImageChanged)
Q_PROPERTY(QUrl foregroundImage READ foregroundImage NOTIFY foregroundImageChanged)
Q_PROPERTY(int countImagePathSet READ countImagePathSet NOTIFY countImagePatchSetChanged)
Q_PROPERTY(QUrl backgroundImage READ backgroundImage)
Q_PROPERTY(QUrl foregroundImage READ foregroundImage)
Q_PROPERTY(int countImagePathSet READ countImagePathSet)
Q_PROPERTY(bool collageFull READ collageFull NOTIFY collageFullChanged)
Q_PROPERTY(QSize collagePixelSize READ collagePixelSize)
public:
enum ImageRoles {
ImagePathRole = Qt::UserRole + 1,
Expand All @@ -81,16 +82,15 @@ class CollageImageModel : public QAbstractListModel, public ModelParser
Q_INVOKABLE bool collageFull();
Q_INVOKABLE bool nextImageIsEffectSelectable();
Q_INVOKABLE QString nextImageEffectPreset();
Q_INVOKABLE QSize collagePixelSize() const;
int countImagePathSet() const;
signals:
void backgroundImageChanged(const QUrl &image);
void foregroundImageChanged(const QUrl &image);
void countImagePatchSetChanged(const int &count);
void collageFullChanged(bool full);
protected:
QList<CollageImage*> mImages;
QUrl mBackgroundImage;
QUrl mForegroundImage;
QSize mPixelSize;
};

#endif // COLLAGEIMAGEMODEL_H
5 changes: 0 additions & 5 deletions src/fakeprinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,6 @@ FakePrinter::FakePrinter(QObject *parent) : AbstractPrinter(parent)
QObject::connect(&mBusyTimer, SIGNAL(timeout()), this, SLOT(busyTimeout()));
};

QSize FakePrinter::getPrintSize()
{
return QSize(3570,2380); //hard coded pixel size
}

bool FakePrinter::printerOnline()
{
return true;
Expand Down
1 change: 0 additions & 1 deletion src/fakeprinter.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ class FakePrinter : public AbstractPrinter, public PrinterList<FakePrinter>
Q_OBJECT
Q_INTERFACES(AbstractPrinter)
public:
QSize getPrintSize() override;
bool printerOnline() override;
bool busy() override;
int printImage(const QString &filename, int copyCount) override;
Expand Down
9 changes: 8 additions & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,14 @@ void redirectDebugMessages(QtMsgType type, const QMessageLogContext & context, c
QTextStream ts(&outFile);
ts << datetime << txt << context.file << str << endl;

std::cout << datetime.toStdString() << " - " << txt.toStdString() << " - " << context.file << "(" << context.line << ") - " << str.toStdString() << std::endl;
if(context.file != nullptr && context.line != 0)
{
std::cout << datetime.toStdString() << " - " << txt.toStdString() << " - " << context.file << "(" << context.line << ") - " << str.toStdString() << std::endl;
}
else
{
std::cout << datetime.toStdString() << " - " << txt.toStdString() << " - " << str.toStdString() << std::endl;
}

//close fd
outFile.close();
Expand Down
5 changes: 0 additions & 5 deletions src/noprinter.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
#include "noprinter.h"

QSize NoPrinter::getPrintSize()
{
return QSize(3570,2380); //hard coded pixel size
}

bool NoPrinter::printerOnline()
{
return false;
Expand Down
1 change: 0 additions & 1 deletion src/noprinter.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ class NoPrinter : public AbstractPrinter, public PrinterList<NoPrinter>
Q_OBJECT
Q_INTERFACES(AbstractPrinter)
public:
QSize getPrintSize() override;
bool printerOnline() override;
bool busy() override;
int printImage(const QString &filename, int copyCount) override;
Expand Down
6 changes: 0 additions & 6 deletions src/selphyprinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,6 @@ bool SelphyPrinter::printerOnline()
}
}


QSize SelphyPrinter::getPrintSize()
{
return QSize(3570,2380); //hard coded pixel size
}

int SelphyPrinter::printImage(const QString &filename, int copyCount)
{
if(mIp.length() > 0)
Expand Down
1 change: 0 additions & 1 deletion src/selphyprinter.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ class SelphyPrinter : public AbstractPrinter, public PrinterList<SelphyPrinter>
Q_OBJECT
Q_INTERFACES(AbstractPrinter)
public:
Q_INVOKABLE QSize getPrintSize();
Q_INVOKABLE bool printerOnline();
bool busy();
public slots:
Expand Down
5 changes: 0 additions & 5 deletions src/standardprinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,6 @@
#include <QDebug>
#include <QPainter>

QSize StandardPrinter::getPrintSize()
{
return QSize(3570,2380); //hard coded pixel size @TODO
}

bool StandardPrinter::printerOnline()
{
return true; //cannot determine online state @TODO
Expand Down
1 change: 0 additions & 1 deletion src/standardprinter.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ class StandardPrinter : public AbstractPrinter, public PrinterList<StandardPrint
Q_OBJECT
Q_INTERFACES(AbstractPrinter)
public:
QSize getPrintSize() override;
bool printerOnline() override;
bool busy() override;
int printImage(const QString &filename, int copyCount) override;
Expand Down

0 comments on commit 757ce4c

Please sign in to comment.