save qrcode to file

This commit is contained in:
MoroccanMalinois 2017-01-23 04:15:49 +00:00
parent 6d73fba14c
commit 1d7a1f6d53
5 changed files with 51 additions and 1 deletions

View file

@ -358,6 +358,32 @@ Rectangle {
standardButtons: StandardButton.Ok
}
FileDialog {
id: qrFileDialog
title: "Please choose a name"
folder: shortcuts.pictures
selectExisting: false
nameFilters: [ "Image (*.png)"]
onAccepted: {
if( ! walletManager.saveQrCode(makeQRCodeString(), walletManager.urlToLocalPath(fileUrl))) {
console.log("Failed to save QrCode to file " + walletManager.urlToLocalPath(fileUrl) )
trackingHowToUseDialog.title = qsTr("Save QrCode") + translationManager.emptyString;
trackingHowToUseDialog.text = qsTr("Failed to save QrCode to ") + walletManager.urlToLocalPath(fileUrl) + translationManager.emptyString;
trackingHowToUseDialog.icon = StandardIcon.Error
trackingHowToUseDialog.open()
}
}
}
Menu {
id: qrMenu
title: "QrCode"
MenuItem {
text: qsTr("Save As")
onTriggered: qrFileDialog.open()
}
}
Image {
id: qrCode
anchors.margins: 50
@ -367,6 +393,15 @@ Rectangle {
smooth: false
fillMode: Image.PreserveAspectFit
source: "image://qrcode/" + makeQRCodeString()
MouseArea {
anchors.fill: parent
acceptedButtons: Qt.RightButton
onClicked: {
if (mouse.button == Qt.RightButton)
qrMenu.popup()
}
onPressAndHold: qrFileDialog.open()
}
}
}

View file

@ -2,7 +2,7 @@
#include "QRCodeImageProvider.h"
QImage QRCodeImageProvider::requestImage(const QString &id, QSize *size, const QSize &requestedSize)
QImage QRCodeImageProvider::genQrImage(const QString &id, QSize *size)
{
using namespace qrcodegen;
@ -15,3 +15,8 @@ QImage QRCodeImageProvider::requestImage(const QString &id, QSize *size, const Q
*size = QSize(qrcode.size, qrcode.size);
return img;
}
QImage QRCodeImageProvider::requestImage(const QString &id, QSize *size, const QSize &/* requestedSize */)
{
return genQrImage(id, size);
}

View file

@ -7,5 +7,6 @@ public:
QRCodeImageProvider(): QQuickImageProvider(QQuickImageProvider::Image) {}
QImage requestImage(const QString &id, QSize *size, const QSize &requestedSize);
static QImage genQrImage(const QString &id, QSize *size);
};

View file

@ -2,6 +2,7 @@
#include "Wallet.h"
#include "wallet/wallet2_api.h"
#include "zxcvbn-c/zxcvbn.h"
#include "QRCodeImageProvider.h"
#include <QFile>
#include <QFileInfo>
#include <QDir>
@ -291,6 +292,13 @@ double WalletManager::getPasswordStrength(const QString &password) const
return e;
}
bool WalletManager::saveQrCode(const QString &code, const QString &path) const
{
QSize size;
// 240 <=> mainLayout.qrCodeSize (Receive.qml)
return QRCodeImageProvider::genQrImage(code, &size).scaled(size.expandedTo(QSize(240, 240)), Qt::KeepAspectRatio).save(path, "PNG", 100);
}
WalletManager::WalletManager(QObject *parent) : QObject(parent)
{
m_pimpl = Monero::WalletManagerFactory::getWalletManager();

View file

@ -123,6 +123,7 @@ public:
Q_INVOKABLE QString resolveOpenAlias(const QString &address) const;
Q_INVOKABLE bool parse_uri(const QString &uri, QString &address, QString &payment_id, uint64_t &amount, QString &tx_description, QString &recipient_name, QVector<QString> &unknown_parameters, QString &error);
Q_INVOKABLE bool saveQrCode(const QString &, const QString &) const;
signals: