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>
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 ui->payAmount->setDisplayUnit(model->getOptionsModel()->getDisplayUnit());
79 void SendCoinsEntry::on_deleteButton_clicked()
81 emit removeEntry(this);
84 bool SendCoinsEntry::validate()
86 // Check input validity
89 if(!ui->payAmount->validate())
95 if(ui->payAmount->value() <= 0)
97 // Cannot send 0 coins or less
98 ui->payAmount->setValid(false);
103 if(!ui->payTo->hasAcceptableInput() ||
104 (model && !model->validateAddress(ui->payTo->text())))
106 ui->payTo->setValid(false);
113 SendCoinsRecipient SendCoinsEntry::getValue()
115 SendCoinsRecipient rv;
117 rv.address = ui->payTo->text();
118 rv.label = ui->addAsLabel->text();
119 rv.amount = ui->payAmount->value();
124 QWidget *SendCoinsEntry::setupTabChain(QWidget *prev)
126 QWidget::setTabOrder(prev, ui->payTo);
127 QWidget::setTabOrder(ui->payTo, ui->addressBookButton);
128 QWidget::setTabOrder(ui->addressBookButton, ui->pasteButton);
129 QWidget::setTabOrder(ui->pasteButton, ui->deleteButton);
130 QWidget::setTabOrder(ui->deleteButton, ui->addAsLabel);
131 return ui->payAmount->setupTabChain(ui->addAsLabel);
134 void SendCoinsEntry::setValue(const SendCoinsRecipient &value)
136 ui->payTo->setText(value.address);
137 ui->addAsLabel->setText(value.label);
138 ui->payAmount->setValue(value.amount);
141 bool SendCoinsEntry::isClear()
143 return ui->payTo->text().isEmpty();