1 #include "sendcoinsentry.h"
2 #include "ui_sendcoinsentry.h"
4 #include "bitcoinunits.h"
5 #include "addressbookpage.h"
6 #include "walletmodel.h"
7 #include "addresstablemodel.h"
9 #include "qapplication.h"
10 #include "qclipboard.h"
14 SendCoinsEntry::SendCoinsEntry(QWidget *parent) :
16 ui(new Ui::SendCoinsEntry),
21 #if QT_VERSION >= 0x040700
22 ui->payTo->setPlaceholderText(tr("Enter a Bitcoin address (e.g. 1NS17iag9jJgTHD1VXjvLCEnZuQ3rJDE9L)"));
23 ui->addAsLabel->setPlaceholderText(tr("Enter a label for this address to add it to your address book"));
25 setFocusPolicy(Qt::TabFocus);
26 setFocusProxy(ui->payTo);
28 GUIUtil::setupAddressWidget(ui->payTo, this);
31 SendCoinsEntry::~SendCoinsEntry()
36 void SendCoinsEntry::on_pasteButton_clicked()
38 // Paste text from clipboard into recipient field
39 ui->payTo->setText(QApplication::clipboard()->text());
42 void SendCoinsEntry::on_addressBookButton_clicked()
44 AddressBookPage dlg(AddressBookPage::ForSending, AddressBookPage::SendingTab, this);
45 dlg.setModel(model->getAddressTableModel());
48 ui->payTo->setText(dlg.getReturnValue());
49 ui->payAmount->setFocus();
53 void SendCoinsEntry::on_payTo_textChanged(const QString &address)
55 ui->addAsLabel->setText(model->getAddressTableModel()->labelForAddress(address));
58 void SendCoinsEntry::setModel(WalletModel *model)
63 void SendCoinsEntry::setRemoveEnabled(bool enabled)
65 ui->deleteButton->setEnabled(enabled);
68 void SendCoinsEntry::clear()
71 ui->addAsLabel->clear();
72 ui->payAmount->clear();
73 ui->payTo->setFocus();
76 void SendCoinsEntry::on_deleteButton_clicked()
78 emit removeEntry(this);
81 bool SendCoinsEntry::validate()
83 // Check input validity
86 if(!ui->payAmount->validate())
91 if(!ui->payTo->hasAcceptableInput() ||
92 (model && !model->validateAddress(ui->payTo->text())))
94 ui->payTo->setValid(false);
101 SendCoinsRecipient SendCoinsEntry::getValue()
103 SendCoinsRecipient rv;
105 rv.address = ui->payTo->text();
106 rv.label = ui->addAsLabel->text();
107 BitcoinUnits::parse(BitcoinUnits::BTC, ui->payAmount->text(), &rv.amount);
112 QWidget *SendCoinsEntry::setupTabChain(QWidget *prev)
114 QWidget::setTabOrder(prev, ui->payTo);
115 QWidget::setTabOrder(ui->payTo, ui->addressBookButton);
116 QWidget::setTabOrder(ui->addressBookButton, ui->pasteButton);
117 QWidget::setTabOrder(ui->pasteButton, ui->deleteButton);
118 QWidget::setTabOrder(ui->deleteButton, ui->addAsLabel);
119 return ui->payAmount->setupTabChain(ui->addAsLabel);