From fd374fa7c4f5ed768c8f9af287e66e42594b37b7 Mon Sep 17 00:00:00 2001 From: agilob Date: Sun, 8 Mar 2015 14:20:15 +0000 Subject: [PATCH] allow saving qrcode as file (src only, no UI) --- src/misc/qrwidget.cpp | 18 ++++++++++++++++-- src/misc/qrwidget.h | 2 ++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/misc/qrwidget.cpp b/src/misc/qrwidget.cpp index cffb14804..10e971af0 100644 --- a/src/misc/qrwidget.cpp +++ b/src/misc/qrwidget.cpp @@ -19,7 +19,22 @@ QRWidget::QRWidget(QWidget *parent) : QWidget(parent), data("0") void QRWidget::setQRData(QString data) { this->data = "tox:" + data; - paintImage(); + paintImage(); +} + +QImage* QRWidget::getImage() +{ + return image; +} + +/** + * @brief QRWidget::saveImage + * @param path Full path to the file with extension. + * @return indicate if saving was successful. + */ +bool QRWidget::saveImage(QString path) +{ + return image->save(path, 0, 75); //0 - image format same as file extension, 75-quality, png file is ~6.3kb } QString QRWidget::getImageAsText() @@ -32,7 +47,6 @@ QString QRWidget::getImageAsText() QString iconBase64 = QString::fromLatin1(ba.toBase64().data()); QString base64Image = ""; - qDebug() << base64Image; return QString(base64Image); } diff --git a/src/misc/qrwidget.h b/src/misc/qrwidget.h index 10454a65c..75674da6c 100644 --- a/src/misc/qrwidget.h +++ b/src/misc/qrwidget.h @@ -13,6 +13,8 @@ public: explicit QRWidget(QWidget *parent = 0); void setQRData(QString data); QString getImageAsText(); + QImage* getImage(); + bool saveImage(QString path); private: QString data;