Merge pull request #427

1d7a1f6 save qrcode to file (MoroccanMalinois)
This commit is contained in:
Riccardo Spagni 2017-01-23 08:05:22 -05:00
commit d4a40499ac
No known key found for this signature in database
GPG Key ID: 55432DF31CCD4FCD
5 changed files with 51 additions and 1 deletions

View File

@ -358,6 +358,32 @@ Rectangle {
standardButtons: StandardButton.Ok 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 { Image {
id: qrCode id: qrCode
anchors.margins: 50 anchors.margins: 50
@ -367,6 +393,15 @@ Rectangle {
smooth: false smooth: false
fillMode: Image.PreserveAspectFit fillMode: Image.PreserveAspectFit
source: "image://qrcode/" + makeQRCodeString() 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" #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; using namespace qrcodegen;
@ -15,3 +15,8 @@ QImage QRCodeImageProvider::requestImage(const QString &id, QSize *size, const Q
*size = QSize(qrcode.size, qrcode.size); *size = QSize(qrcode.size, qrcode.size);
return img; 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) {} QRCodeImageProvider(): QQuickImageProvider(QQuickImageProvider::Image) {}
QImage requestImage(const QString &id, QSize *size, const QSize &requestedSize); 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.h"
#include "wallet/wallet2_api.h" #include "wallet/wallet2_api.h"
#include "zxcvbn-c/zxcvbn.h" #include "zxcvbn-c/zxcvbn.h"
#include "QRCodeImageProvider.h"
#include <QFile> #include <QFile>
#include <QFileInfo> #include <QFileInfo>
#include <QDir> #include <QDir>
@ -291,6 +292,13 @@ double WalletManager::getPasswordStrength(const QString &password) const
return e; 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) WalletManager::WalletManager(QObject *parent) : QObject(parent)
{ {
m_pimpl = Monero::WalletManagerFactory::getWalletManager(); m_pimpl = Monero::WalletManagerFactory::getWalletManager();

View File

@ -123,6 +123,7 @@ public:
Q_INVOKABLE QString resolveOpenAlias(const QString &address) const; 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 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: signals: