diff --git a/pages/Receive.qml b/pages/Receive.qml index 773d14ed..5ba14527 100644 --- a/pages/Receive.qml +++ b/pages/Receive.qml @@ -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() + } } } diff --git a/src/libwalletqt/QRCodeImageProvider.cpp b/src/libwalletqt/QRCodeImageProvider.cpp index ad07897f..6d99b35c 100644 --- a/src/libwalletqt/QRCodeImageProvider.cpp +++ b/src/libwalletqt/QRCodeImageProvider.cpp @@ -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); +} diff --git a/src/libwalletqt/QRCodeImageProvider.h b/src/libwalletqt/QRCodeImageProvider.h index 930b731a..b040bfe0 100644 --- a/src/libwalletqt/QRCodeImageProvider.h +++ b/src/libwalletqt/QRCodeImageProvider.h @@ -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); }; diff --git a/src/libwalletqt/WalletManager.cpp b/src/libwalletqt/WalletManager.cpp index fa06edd3..45aff22e 100644 --- a/src/libwalletqt/WalletManager.cpp +++ b/src/libwalletqt/WalletManager.cpp @@ -2,6 +2,7 @@ #include "Wallet.h" #include "wallet/wallet2_api.h" #include "zxcvbn-c/zxcvbn.h" +#include "QRCodeImageProvider.h" #include #include #include @@ -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(); diff --git a/src/libwalletqt/WalletManager.h b/src/libwalletqt/WalletManager.h index 5b8adf5a..20d2bec7 100644 --- a/src/libwalletqt/WalletManager.h +++ b/src/libwalletqt/WalletManager.h @@ -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 &unknown_parameters, QString &error); + Q_INVOKABLE bool saveQrCode(const QString &, const QString &) const; signals: