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),
21 ui->payToLayout->setSpacing(4);
24 #if QT_VERSION >= 0x040700
25 ui->payTo->setPlaceholderText(tr("Enter a Bitcoin address (e.g. 1NS17iag9jJgTHD1VXjvLCEnZuQ3rJDE9L)"));
26 ui->addAsLabel->setPlaceholderText(tr("Enter a label for this address to add it to your address book"));
28 setFocusPolicy(Qt::TabFocus);
29 setFocusProxy(ui->payTo);
31 GUIUtil::setupAddressWidget(ui->payTo, this);
34 SendCoinsEntry::~SendCoinsEntry()
39 void SendCoinsEntry::on_pasteButton_clicked()
41 // Paste text from clipboard into recipient field
42 ui->payTo->setText(QApplication::clipboard()->text());
45 void SendCoinsEntry::on_addressBookButton_clicked()
49 AddressBookPage dlg(AddressBookPage::ForSending, AddressBookPage::SendingTab, this);
50 dlg.setModel(model->getAddressTableModel());
53 ui->payTo->setText(dlg.getReturnValue());
54 ui->payAmount->setFocus();
58 void SendCoinsEntry::on_payTo_textChanged(const QString &address)
62 ui->addAsLabel->setText(model->getAddressTableModel()->labelForAddress(address));
65 void SendCoinsEntry::setModel(WalletModel *model)
70 void SendCoinsEntry::setRemoveEnabled(bool enabled)
72 ui->deleteButton->setEnabled(enabled);
75 void SendCoinsEntry::clear()
78 ui->addAsLabel->clear();
79 ui->payAmount->clear();
80 ui->payTo->setFocus();
81 if(model && model->getOptionsModel())
83 ui->payAmount->setDisplayUnit(model->getOptionsModel()->getDisplayUnit());
87 void SendCoinsEntry::on_deleteButton_clicked()
89 emit removeEntry(this);
92 bool SendCoinsEntry::validate()
94 // Check input validity
97 if(!ui->payAmount->validate())
103 if(ui->payAmount->value() <= 0)
105 // Cannot send 0 coins or less
106 ui->payAmount->setValid(false);
111 if(!ui->payTo->hasAcceptableInput() ||
112 (model && !model->validateAddress(ui->payTo->text())))
114 ui->payTo->setValid(false);
121 SendCoinsRecipient SendCoinsEntry::getValue()
123 SendCoinsRecipient rv;
125 rv.address = ui->payTo->text();
126 rv.label = ui->addAsLabel->text();
127 rv.amount = ui->payAmount->value();
132 QWidget *SendCoinsEntry::setupTabChain(QWidget *prev)
134 QWidget::setTabOrder(prev, ui->payTo);
135 QWidget::setTabOrder(ui->payTo, ui->addressBookButton);
136 QWidget::setTabOrder(ui->addressBookButton, ui->pasteButton);
137 QWidget::setTabOrder(ui->pasteButton, ui->deleteButton);
138 QWidget::setTabOrder(ui->deleteButton, ui->addAsLabel);
139 return ui->payAmount->setupTabChain(ui->addAsLabel);
142 void SendCoinsEntry::setValue(const SendCoinsRecipient &value)
144 ui->payTo->setText(value.address);
145 ui->addAsLabel->setText(value.label);
146 ui->payAmount->setValue(value.amount);
149 bool SendCoinsEntry::isClear()
151 return ui->payTo->text().isEmpty();
154 void SendCoinsEntry::setFocus()
156 ui->payTo->setFocus();