1 #include "sendcoinsentry.h"
2 #include "ui_sendcoinsentry.h"
4 #include "addressbookpage.h"
5 #include "walletmodel.h"
6 #include "addresstablemodel.h"
8 #include "qapplication.h"
9 #include "qclipboard.h"
13 SendCoinsEntry::SendCoinsEntry(QWidget *parent) :
15 ui(new Ui::SendCoinsEntry),
20 #if QT_VERSION >= 0x040700
21 ui->payTo->setPlaceholderText(tr("Enter a Bitcoin address (e.g. 1NS17iag9jJgTHD1VXjvLCEnZuQ3rJDE9L)"));
22 ui->addAsLabel->setPlaceholderText(tr("Enter a label for this address to add it to your address book"));
24 setFocusPolicy(Qt::TabFocus);
25 setFocusProxy(ui->payTo);
27 GUIUtil::setupAddressWidget(ui->payTo, this);
30 SendCoinsEntry::~SendCoinsEntry()
35 void SendCoinsEntry::on_pasteButton_clicked()
37 // Paste text from clipboard into recipient field
38 ui->payTo->setText(QApplication::clipboard()->text());
41 void SendCoinsEntry::on_addressBookButton_clicked()
43 AddressBookPage dlg(AddressBookPage::ForSending, AddressBookPage::SendingTab, this);
44 dlg.setModel(model->getAddressTableModel());
47 ui->payTo->setText(dlg.getReturnValue());
48 ui->payAmount->setFocus();
52 void SendCoinsEntry::on_payTo_textChanged(const QString &address)
54 ui->addAsLabel->setText(model->getAddressTableModel()->labelForAddress(address));
57 void SendCoinsEntry::setModel(WalletModel *model)
62 void SendCoinsEntry::setRemoveEnabled(bool enabled)
64 ui->deleteButton->setEnabled(enabled);
67 void SendCoinsEntry::clear()
70 ui->addAsLabel->clear();
71 ui->payAmount->clear();
72 ui->payTo->setFocus();
75 void SendCoinsEntry::on_deleteButton_clicked()
77 emit removeEntry(this);
80 bool SendCoinsEntry::validate()
82 // Check input validity
85 if(!ui->payAmount->validate())
90 if(!ui->payTo->hasAcceptableInput() ||
91 (model && !model->validateAddress(ui->payTo->text())))
93 ui->payTo->setValid(false);
100 SendCoinsRecipient SendCoinsEntry::getValue()
102 SendCoinsRecipient rv;
104 rv.address = ui->payTo->text();
105 rv.label = ui->addAsLabel->text();
106 GUIUtil::parseMoney(ui->payAmount->text(), &rv.amount);
111 QWidget *SendCoinsEntry::setupTabChain(QWidget *prev)
113 QWidget::setTabOrder(prev, ui->payTo);
114 QWidget::setTabOrder(ui->payTo, ui->addressBookButton);
115 QWidget::setTabOrder(ui->addressBookButton, ui->pasteButton);
116 QWidget::setTabOrder(ui->pasteButton, ui->deleteButton);
117 QWidget::setTabOrder(ui->deleteButton, ui->addAsLabel);
118 return ui->payAmount->setupTabChain(ui->addAsLabel);