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 no label is filled in yet
63 if(ui->addAsLabel->text().isEmpty())
64 ui->addAsLabel->setText(model->getAddressTableModel()->labelForAddress(address));}
66 void SendCoinsEntry::setModel(WalletModel *model)
72 void SendCoinsEntry::setRemoveEnabled(bool enabled)
74 ui->deleteButton->setEnabled(enabled);
77 void SendCoinsEntry::clear()
80 ui->addAsLabel->clear();
81 ui->payAmount->clear();
82 ui->payTo->setFocus();
83 if(model && model->getOptionsModel())
85 ui->payAmount->setDisplayUnit(model->getOptionsModel()->getDisplayUnit());
89 void SendCoinsEntry::on_deleteButton_clicked()
91 emit removeEntry(this);
94 bool SendCoinsEntry::validate()
96 // Check input validity
99 if(!ui->payAmount->validate())
105 if(ui->payAmount->value() <= 0)
107 // Cannot send 0 coins or less
108 ui->payAmount->setValid(false);
113 if(!ui->payTo->hasAcceptableInput() ||
114 (model && !model->validateAddress(ui->payTo->text())))
116 ui->payTo->setValid(false);
123 SendCoinsRecipient SendCoinsEntry::getValue()
125 SendCoinsRecipient rv;
127 rv.address = ui->payTo->text();
128 rv.label = ui->addAsLabel->text();
129 rv.amount = ui->payAmount->value();
134 QWidget *SendCoinsEntry::setupTabChain(QWidget *prev)
136 QWidget::setTabOrder(prev, ui->payTo);
137 QWidget::setTabOrder(ui->payTo, ui->addressBookButton);
138 QWidget::setTabOrder(ui->addressBookButton, ui->pasteButton);
139 QWidget::setTabOrder(ui->pasteButton, ui->deleteButton);
140 QWidget::setTabOrder(ui->deleteButton, ui->addAsLabel);
141 return ui->payAmount->setupTabChain(ui->addAsLabel);
144 void SendCoinsEntry::setValue(const SendCoinsRecipient &value)
146 ui->payTo->setText(value.address);
147 ui->addAsLabel->setText(value.label);
148 ui->payAmount->setValue(value.amount);
151 bool SendCoinsEntry::isClear()
153 return ui->payTo->text().isEmpty();
156 void SendCoinsEntry::setFocus()
158 ui->payTo->setFocus();