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())
92 if(ui->payAmount->value() <= 0)
94 // Cannot send 0 coins or less
95 ui->payAmount->setValid(false);
101 if(!ui->payTo->hasAcceptableInput() ||
102 (model && !model->validateAddress(ui->payTo->text())))
104 ui->payTo->setValid(false);
111 SendCoinsRecipient SendCoinsEntry::getValue()
113 SendCoinsRecipient rv;
115 rv.address = ui->payTo->text();
116 rv.label = ui->addAsLabel->text();
117 rv.amount = ui->payAmount->value();
122 QWidget *SendCoinsEntry::setupTabChain(QWidget *prev)
124 QWidget::setTabOrder(prev, ui->payTo);
125 QWidget::setTabOrder(ui->payTo, ui->addressBookButton);
126 QWidget::setTabOrder(ui->addressBookButton, ui->pasteButton);
127 QWidget::setTabOrder(ui->pasteButton, ui->deleteButton);
128 QWidget::setTabOrder(ui->deleteButton, ui->addAsLabel);
129 return ui->payAmount->setupTabChain(ui->addAsLabel);