1 #include "sendcoinsentry.h"
2 #include "ui_sendcoinsentry.h"
4 #include "bitcoinunits.h"
5 #include "addressbookpage.h"
6 #include "walletmodel.h"
7 #include "optionsmodel.h"
8 #include "addresstablemodel.h"
10 #include "qapplication.h"
11 #include "qclipboard.h"
15 SendCoinsEntry::SendCoinsEntry(QWidget *parent) :
17 ui(new Ui::SendCoinsEntry),
22 #if QT_VERSION >= 0x040700
23 ui->payTo->setPlaceholderText(tr("Enter a Bitcoin address (e.g. 1NS17iag9jJgTHD1VXjvLCEnZuQ3rJDE9L)"));
24 ui->addAsLabel->setPlaceholderText(tr("Enter a label for this address to add it to your address book"));
26 setFocusPolicy(Qt::TabFocus);
27 setFocusProxy(ui->payTo);
29 GUIUtil::setupAddressWidget(ui->payTo, this);
32 SendCoinsEntry::~SendCoinsEntry()
37 void SendCoinsEntry::on_pasteButton_clicked()
39 // Paste text from clipboard into recipient field
40 ui->payTo->setText(QApplication::clipboard()->text());
43 void SendCoinsEntry::on_addressBookButton_clicked()
45 AddressBookPage dlg(AddressBookPage::ForSending, AddressBookPage::SendingTab, this);
46 dlg.setModel(model->getAddressTableModel());
49 ui->payTo->setText(dlg.getReturnValue());
50 ui->payAmount->setFocus();
54 void SendCoinsEntry::on_payTo_textChanged(const QString &address)
56 ui->addAsLabel->setText(model->getAddressTableModel()->labelForAddress(address));
59 void SendCoinsEntry::setModel(WalletModel *model)
64 void SendCoinsEntry::setRemoveEnabled(bool enabled)
66 ui->deleteButton->setEnabled(enabled);
69 void SendCoinsEntry::clear()
72 ui->addAsLabel->clear();
73 ui->payAmount->clear();
74 ui->payTo->setFocus();
77 ui->payAmount->setDisplayUnit(model->getOptionsModel()->getDisplayUnit());
81 void SendCoinsEntry::on_deleteButton_clicked()
83 emit removeEntry(this);
86 bool SendCoinsEntry::validate()
88 // Check input validity
91 if(!ui->payAmount->validate())
97 if(ui->payAmount->value() <= 0)
99 // Cannot send 0 coins or less
100 ui->payAmount->setValid(false);
106 if(!ui->payTo->hasAcceptableInput() ||
107 (model && !model->validateAddress(ui->payTo->text())))
109 ui->payTo->setValid(false);
116 SendCoinsRecipient SendCoinsEntry::getValue()
118 SendCoinsRecipient rv;
120 rv.address = ui->payTo->text();
121 rv.label = ui->addAsLabel->text();
122 rv.amount = ui->payAmount->value();
127 QWidget *SendCoinsEntry::setupTabChain(QWidget *prev)
129 QWidget::setTabOrder(prev, ui->payTo);
130 QWidget::setTabOrder(ui->payTo, ui->addressBookButton);
131 QWidget::setTabOrder(ui->addressBookButton, ui->pasteButton);
132 QWidget::setTabOrder(ui->pasteButton, ui->deleteButton);
133 QWidget::setTabOrder(ui->deleteButton, ui->addAsLabel);
134 return ui->payAmount->setupTabChain(ui->addAsLabel);