Skip to content

Commit

Permalink
Add a button/context menu items to show QR codes for addresses (#2741)
Browse files Browse the repository at this point in the history
* Add a button/context menu item to show qr codes for addresses in address book

* Add a context menu item to show qr code for addresses in transaction list
  • Loading branch information
UdjinM6 committed Mar 6, 2019
1 parent b617774 commit e63cdad
Show file tree
Hide file tree
Showing 13 changed files with 168 additions and 1 deletion.
25 changes: 25 additions & 0 deletions src/qt/addressbookpage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
#include "csvmodelwriter.h"
#include "editaddressdialog.h"
#include "guiutil.h"
#include "optionsmodel.h"
#include "platformstyle.h"
#include "qrdialog.h"

#include <QIcon>
#include <QMenu>
Expand All @@ -42,6 +44,7 @@ AddressBookPage::AddressBookPage(const PlatformStyle *platformStyle, Mode _mode,
ui->deleteAddress->setIcon(QIcon(":/icons/" + theme + "/remove"));
ui->exportButton->setIcon(QIcon(":/icons/" + theme + "/export"));
}
ui->showAddressQRCode->setIcon(QIcon());

switch(mode)
{
Expand Down Expand Up @@ -81,6 +84,7 @@ AddressBookPage::AddressBookPage(const PlatformStyle *platformStyle, Mode _mode,
QAction *copyAddressAction = new QAction(tr("&Copy Address"), this);
QAction *copyLabelAction = new QAction(tr("Copy &Label"), this);
QAction *editAction = new QAction(tr("&Edit"), this);
QAction *showAddressQRCodeAction = new QAction(tr("&Show address QR code"), this);
deleteAction = new QAction(ui->deleteAddress->text(), this);

// Build context menu
Expand All @@ -91,12 +95,14 @@ AddressBookPage::AddressBookPage(const PlatformStyle *platformStyle, Mode _mode,
if(tab == SendingTab)
contextMenu->addAction(deleteAction);
contextMenu->addSeparator();
contextMenu->addAction(showAddressQRCodeAction);

// Connect signals for context menu actions
connect(copyAddressAction, SIGNAL(triggered()), this, SLOT(on_copyAddress_clicked()));
connect(copyLabelAction, SIGNAL(triggered()), this, SLOT(onCopyLabelAction()));
connect(editAction, SIGNAL(triggered()), this, SLOT(onEditAction()));
connect(deleteAction, SIGNAL(triggered()), this, SLOT(on_deleteAddress_clicked()));
connect(showAddressQRCodeAction, SIGNAL(triggered()), this, SLOT(on_showAddressQRCode_clicked()));

connect(ui->tableView, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(contextualMenu(QPoint)));

Expand Down Expand Up @@ -213,6 +219,23 @@ void AddressBookPage::on_deleteAddress_clicked()
}
}

void AddressBookPage::on_showAddressQRCode_clicked()
{
QList<QModelIndex> entries = GUIUtil::getEntryData(ui->tableView, AddressTableModel::Address);
if (entries.empty()) {
return;
}

QString strAddress = entries.at(0).data(Qt::EditRole).toString();
QRDialog* dialog = new QRDialog(this);
OptionsModel *model = new OptionsModel(NULL, false);

dialog->setModel(model);
dialog->setAttribute(Qt::WA_DeleteOnClose);
dialog->setInfo(tr("QR code"), "dash:"+strAddress, "", strAddress);
dialog->show();
}

void AddressBookPage::selectionChanged()
{
// Set button states based on selected tab and selection
Expand All @@ -238,11 +261,13 @@ void AddressBookPage::selectionChanged()
break;
}
ui->copyAddress->setEnabled(true);
ui->showAddressQRCode->setEnabled(true);
}
else
{
ui->deleteAddress->setEnabled(false);
ui->copyAddress->setEnabled(false);
ui->showAddressQRCode->setEnabled(false);
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/qt/addressbookpage.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ private Q_SLOTS:
void onCopyLabelAction();
/** Edit currently selected address entry (no button) */
void onEditAction();
/** Show QR code for the currently selected address */
void on_showAddressQRCode_clicked();
/** Export button clicked */
void on_exportButton_clicked();

Expand Down
13 changes: 13 additions & 0 deletions src/qt/forms/addressbookpage.ui
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,19 @@
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="showAddressQRCode">
<property name="toolTip">
<string>Show QR code for the currently selected address</string>
</property>
<property name="text">
<string>&amp;Show QR code</string>
</property>
<property name="autoDefault">
<bool>false</bool>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="deleteAddress">
<property name="toolTip">
Expand Down
1 change: 0 additions & 1 deletion src/qt/masternodelist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#include "init.h"
#include "masternode-sync.h"
#include "netbase.h"
#include "qrdialog.h"
#include "sync.h"
#include "wallet/wallet.h"
#include "walletmodel.h"
Expand Down
4 changes: 4 additions & 0 deletions src/qt/qrdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,10 @@ void QRDialog::update()

setWindowTitle(strWindowtitle);
ui->button_saveImage->setEnabled(false);
if (strTextInfo.isEmpty()) {
ui->outUri->setVisible(false);
adjustSize();
}
ui->outUri->setText(strTextInfo);

#ifdef USE_QRCODE
Expand Down
17 changes: 17 additions & 0 deletions src/qt/res/css/crownium.css
Original file line number Diff line number Diff line change
Expand Up @@ -606,6 +606,23 @@ QWidget#AddressBookPage QPushButton#copyAddress:pressed {
border:1px solid #9e9e9e;
}

QWidget#AddressBookPage QPushButton#showAddressQRCode { /* Show Address QR code Button */
background-color:qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: .01 #f6f6f6, stop: .1 rgba(250, 250, 250, 128), stop: .95 rgba(250, 250, 250, 255), stop: 1 #ebebeb);
border:1px solid #d2d2d2;
color:#616161;
padding-left:10px;
padding-right:10px;
}

QWidget#AddressBookPage QPushButton#showAddressQRCode:hover {
background-color:qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: .01 #f6f6f6, stop: .1 rgba(240, 240, 240, 255), stop: .95 rgba(240, 240, 240, 255), stop: 1 #ebebeb);
color:#333;
}

QWidget#AddressBookPage QPushButton#showAddressQRCode:pressed {
border:1px solid #9e9e9e;
}

QWidget#AddressBookPage QPushButton#deleteAddress { /* Delete Address Button */
background-color:qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: .01 #f6f6f6, stop: .1 rgba(250, 250, 250, 128), stop: .95 rgba(250, 250, 250, 255), stop: 1 #ebebeb);
border:1px solid #d2d2d2;
Expand Down
17 changes: 17 additions & 0 deletions src/qt/res/css/drkblue.css
Original file line number Diff line number Diff line change
Expand Up @@ -601,6 +601,23 @@ QWidget#AddressBookPage QPushButton#copyAddress:pressed {
border:1px solid #9e9e9e;
}

QWidget#AddressBookPage QPushButton#showAddressQRCode { /* Show Address QR code Button */
background-color:qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: .01 #f6f6f6, stop: .1 rgba(250, 250, 250, 128), stop: .95 rgba(250, 250, 250, 255), stop: 1 #ebebeb);
border:1px solid #d2d2d2;
color:#616161;
padding-left:10px;
padding-right:10px;
}

QWidget#AddressBookPage QPushButton#showAddressQRCode:hover {
background-color:qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: .01 #f6f6f6, stop: .1 rgba(240, 240, 240, 255), stop: .95 rgba(240, 240, 240, 255), stop: 1 #ebebeb);
color:#333;
}

QWidget#AddressBookPage QPushButton#showAddressQRCode:pressed {
border:1px solid #9e9e9e;
}

QWidget#AddressBookPage QPushButton#deleteAddress { /* Delete Address Button */
background-color:qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: .01 #f6f6f6, stop: .1 rgba(250, 250, 250, 128), stop: .95 rgba(250, 250, 250, 255), stop: 1 #ebebeb);
border:1px solid #d2d2d2;
Expand Down
17 changes: 17 additions & 0 deletions src/qt/res/css/light-hires-retro.css
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,23 @@ QWidget#AddressBookPage QPushButton#copyAddress:pressed {
border:1px solid #9e9e9e;
}

QWidget#AddressBookPage QPushButton#showAddressQRCode { /* Show Address QR code Button */
background-color:qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: .01 #f6f6f6, stop: .1 rgba(250, 250, 250, 128), stop: .95 rgba(250, 250, 250, 255), stop: 1 #ebebeb);
border:1px solid #d2d2d2;
color:#616161;
padding-left:10px;
padding-right:10px;
}

QWidget#AddressBookPage QPushButton#showAddressQRCode:hover {
background-color:qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: .01 #f6f6f6, stop: .1 rgba(240, 240, 240, 255), stop: .95 rgba(240, 240, 240, 255), stop: 1 #ebebeb);
color:#333;
}

QWidget#AddressBookPage QPushButton#showAddressQRCode:pressed {
border:1px solid #9e9e9e;
}

QWidget#AddressBookPage QPushButton#deleteAddress { /* Delete Address Button */
background-color:qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: .01 #f6f6f6, stop: .1 rgba(250, 250, 250, 128), stop: .95 rgba(250, 250, 250, 255), stop: 1 #ebebeb);
border:1px solid #d2d2d2;
Expand Down
17 changes: 17 additions & 0 deletions src/qt/res/css/light-hires.css
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,23 @@ QWidget#AddressBookPage QPushButton#copyAddress:pressed {
border:1px solid #9e9e9e;
}

QWidget#AddressBookPage QPushButton#showAddressQRCode { /* Show Address QR code Button */
background-color:qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: .01 #f6f6f6, stop: .1 rgba(250, 250, 250, 128), stop: .95 rgba(250, 250, 250, 255), stop: 1 #ebebeb);
border:1px solid #d2d2d2;
color:#616161;
padding-left:10px;
padding-right:10px;
}

QWidget#AddressBookPage QPushButton#showAddressQRCode:hover {
background-color:qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: .01 #f6f6f6, stop: .1 rgba(240, 240, 240, 255), stop: .95 rgba(240, 240, 240, 255), stop: 1 #ebebeb);
color:#333;
}

QWidget#AddressBookPage QPushButton#showAddressQRCode:pressed {
border:1px solid #9e9e9e;
}

QWidget#AddressBookPage QPushButton#deleteAddress { /* Delete Address Button */
background-color:qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: .01 #f6f6f6, stop: .1 rgba(250, 250, 250, 128), stop: .95 rgba(250, 250, 250, 255), stop: 1 #ebebeb);
border:1px solid #d2d2d2;
Expand Down
17 changes: 17 additions & 0 deletions src/qt/res/css/light-retro.css
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,23 @@ QWidget#AddressBookPage QPushButton#copyAddress:pressed {
border:1px solid #9e9e9e;
}

QWidget#AddressBookPage QPushButton#showAddressQRCode { /* Show Address QR code Button */
background-color:qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: .01 #f6f6f6, stop: .1 rgba(250, 250, 250, 128), stop: .95 rgba(250, 250, 250, 255), stop: 1 #ebebeb);
border:1px solid #d2d2d2;
color:#616161;
padding-left:10px;
padding-right:10px;
}

QWidget#AddressBookPage QPushButton#showAddressQRCode:hover {
background-color:qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: .01 #f6f6f6, stop: .1 rgba(240, 240, 240, 255), stop: .95 rgba(240, 240, 240, 255), stop: 1 #ebebeb);
color:#333;
}

QWidget#AddressBookPage QPushButton#showAddressQRCode:pressed {
border:1px solid #9e9e9e;
}

QWidget#AddressBookPage QPushButton#deleteAddress { /* Delete Address Button */
background-color:qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: .01 #f6f6f6, stop: .1 rgba(250, 250, 250, 128), stop: .95 rgba(250, 250, 250, 255), stop: 1 #ebebeb);
border:1px solid #d2d2d2;
Expand Down
17 changes: 17 additions & 0 deletions src/qt/res/css/light.css
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,23 @@ QWidget#AddressBookPage QPushButton#copyAddress:pressed {
border:1px solid #9e9e9e;
}

QWidget#AddressBookPage QPushButton#showAddressQRCode { /* Show Address QR code Button */
background-color:qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: .01 #f6f6f6, stop: .1 rgba(250, 250, 250, 128), stop: .95 rgba(250, 250, 250, 255), stop: 1 #ebebeb);
border:1px solid #d2d2d2;
color:#616161;
padding-left:10px;
padding-right:10px;
}

QWidget#AddressBookPage QPushButton#showAddressQRCode:hover {
background-color:qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: .01 #f6f6f6, stop: .1 rgba(240, 240, 240, 255), stop: .95 rgba(240, 240, 240, 255), stop: 1 #ebebeb);
color:#333;
}

QWidget#AddressBookPage QPushButton#showAddressQRCode:pressed {
border:1px solid #9e9e9e;
}

QWidget#AddressBookPage QPushButton#deleteAddress { /* Delete Address Button */
background-color:qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: .01 #f6f6f6, stop: .1 rgba(250, 250, 250, 128), stop: .95 rgba(250, 250, 250, 255), stop: 1 #ebebeb);
border:1px solid #d2d2d2;
Expand Down
21 changes: 21 additions & 0 deletions src/qt/transactionview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "guiutil.h"
#include "optionsmodel.h"
#include "platformstyle.h"
#include "qrdialog.h"
#include "transactiondescdialog.h"
#include "transactionfilterproxy.h"
#include "transactionrecord.h"
Expand Down Expand Up @@ -167,6 +168,7 @@ TransactionView::TransactionView(const PlatformStyle *platformStyle, QWidget *pa
QAction *copyTxPlainText = new QAction(tr("Copy full transaction details"), this);
QAction *editLabelAction = new QAction(tr("Edit label"), this);
QAction *showDetailsAction = new QAction(tr("Show transaction details"), this);
QAction *showAddressQRCodeAction = new QAction(tr("Show address QR code"), this);

contextMenu = new QMenu(this);
contextMenu->addAction(copyAddressAction);
Expand All @@ -176,6 +178,7 @@ TransactionView::TransactionView(const PlatformStyle *platformStyle, QWidget *pa
contextMenu->addAction(copyTxHexAction);
contextMenu->addAction(copyTxPlainText);
contextMenu->addAction(showDetailsAction);
contextMenu->addAction(showAddressQRCodeAction);
contextMenu->addSeparator();
contextMenu->addAction(abandonAction);
contextMenu->addAction(editLabelAction);
Expand Down Expand Up @@ -205,6 +208,7 @@ TransactionView::TransactionView(const PlatformStyle *platformStyle, QWidget *pa
connect(copyTxPlainText, SIGNAL(triggered()), this, SLOT(copyTxPlainText()));
connect(editLabelAction, SIGNAL(triggered()), this, SLOT(editLabel()));
connect(showDetailsAction, SIGNAL(triggered()), this, SLOT(showDetails()));
connect(showAddressQRCodeAction, SIGNAL(triggered()), this, SLOT(showAddressQRCode()));
}

void TransactionView::setModel(WalletModel *_model)
Expand Down Expand Up @@ -542,6 +546,23 @@ void TransactionView::showDetails()
}
}

void TransactionView::showAddressQRCode()
{
QList<QModelIndex> entries = GUIUtil::getEntryData(transactionView, 0);
if (entries.empty()) {
return;
}

QString strAddress = entries.at(0).data(TransactionTableModel::AddressRole).toString();
QRDialog* dialog = new QRDialog(this);
OptionsModel *model = new OptionsModel(NULL, false);

dialog->setModel(model);
dialog->setAttribute(Qt::WA_DeleteOnClose);
dialog->setInfo(tr("QR code"), "dash:"+strAddress, "", strAddress);
dialog->show();
}

/** Compute sum of all selected transactions */
void TransactionView::computeSum()
{
Expand Down
1 change: 1 addition & 0 deletions src/qt/transactionview.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ private Q_SLOTS:
void contextualMenu(const QPoint &);
void dateRangeChanged();
void showDetails();
void showAddressQRCode();
void copyAddress();
void editLabel();
void copyLabel();
Expand Down

0 comments on commit e63cdad

Please sign in to comment.