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 // Fill in label from address book, if address has an associated label
63 QString associatedLabel = model->getAddressTableModel()->labelForAddress(address);
64 if(!associatedLabel.isEmpty())
65 ui->addAsLabel->setText(associatedLabel);
68 void SendCoinsEntry::setModel(WalletModel *model)
74 void SendCoinsEntry::setRemoveEnabled(bool enabled)
76 ui->deleteButton->setEnabled(enabled);
79 void SendCoinsEntry::clear()
82 ui->addAsLabel->clear();
83 ui->payAmount->clear();
84 ui->payTo->setFocus();
85 if(model && model->getOptionsModel())
87 ui->payAmount->setDisplayUnit(model->getOptionsModel()->getDisplayUnit());
91 void SendCoinsEntry::on_deleteButton_clicked()
93 emit removeEntry(this);
96 bool SendCoinsEntry::validate()
98 // Check input validity
101 if(!ui->payAmount->validate())
107 if(ui->payAmount->value() <= 0)
109 // Cannot send 0 coins or less
110 ui->payAmount->setValid(false);
115 if(!ui->payTo->hasAcceptableInput() ||
116 (model && !model->validateAddress(ui->payTo->text())))
118 ui->payTo->setValid(false);
125 SendCoinsRecipient SendCoinsEntry::getValue()
127 SendCoinsRecipient rv;
129 rv.address = ui->payTo->text();
130 rv.label = ui->addAsLabel->text();
131 rv.amount = ui->payAmount->value();
136 QWidget *SendCoinsEntry::setupTabChain(QWidget *prev)
138 QWidget::setTabOrder(prev, ui->payTo);
139 QWidget::setTabOrder(ui->payTo, ui->addressBookButton);
140 QWidget::setTabOrder(ui->addressBookButton, ui->pasteButton);
141 QWidget::setTabOrder(ui->pasteButton, ui->deleteButton);
142 QWidget::setTabOrder(ui->deleteButton, ui->addAsLabel);
143 return ui->payAmount->setupTabChain(ui->addAsLabel);
146 void SendCoinsEntry::setValue(const SendCoinsRecipient &value)
148 ui->payTo->setText(value.address);
149 ui->addAsLabel->setText(value.label);
150 ui->payAmount->setValue(value.amount);
153 bool SendCoinsEntry::isClear()
155 return ui->payTo->text().isEmpty();
158 void SendCoinsEntry::setFocus()
160 ui->payTo->setFocus();