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);
23 #if QT_VERSION >= 0x040700
24 /* Do not move this to the XML file, Qt before 4.7 will choke on it */
25 ui->addAsLabel->setPlaceholderText(tr("Enter a label for this address to add it to your address book"));
26 ui->payTo->setPlaceholderText(tr("Enter a NovaCoin address (e.g. 4Zo1ga6xuKuQ7JV7M9rGDoxdbYwV5zgQJ5)"));
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
63 ui->addAsLabel->setText(model->getAddressTableModel()->labelForAddress(address));
66 void SendCoinsEntry::setModel(WalletModel *model)
70 if(model && model->getOptionsModel())
71 connect(model->getOptionsModel(), SIGNAL(displayUnitChanged(int)), this, SLOT(updateDisplayUnit()));
73 connect(ui->payAmount, SIGNAL(textChanged()), this, SIGNAL(payAmountChanged()));
78 void SendCoinsEntry::setRemoveEnabled(bool enabled)
80 ui->deleteButton->setEnabled(enabled);
83 void SendCoinsEntry::clear()
86 ui->addAsLabel->clear();
87 ui->payAmount->clear();
88 ui->payTo->setFocus();
89 // update the display unit, to not use the default ("BTC")
93 void SendCoinsEntry::on_deleteButton_clicked()
95 emit removeEntry(this);
98 bool SendCoinsEntry::validate()
100 // Check input validity
103 if(!ui->payAmount->validate())
109 if(ui->payAmount->value() <= 0)
111 // Cannot send 0 coins or less
112 ui->payAmount->setValid(false);
117 if(!ui->payTo->hasAcceptableInput() ||
118 (model && !model->validateAddress(ui->payTo->text())))
120 ui->payTo->setValid(false);
127 SendCoinsRecipient SendCoinsEntry::getValue()
129 SendCoinsRecipient rv;
131 rv.address = ui->payTo->text();
132 rv.label = ui->addAsLabel->text();
133 rv.amount = ui->payAmount->value();
138 QWidget *SendCoinsEntry::setupTabChain(QWidget *prev)
140 QWidget::setTabOrder(prev, ui->payTo);
141 QWidget::setTabOrder(ui->payTo, ui->addressBookButton);
142 QWidget::setTabOrder(ui->addressBookButton, ui->pasteButton);
143 QWidget::setTabOrder(ui->pasteButton, ui->deleteButton);
144 QWidget::setTabOrder(ui->deleteButton, ui->addAsLabel);
145 return ui->payAmount->setupTabChain(ui->addAsLabel);
148 void SendCoinsEntry::setValue(const SendCoinsRecipient &value)
150 ui->payTo->setText(value.address);
151 ui->addAsLabel->setText(value.label);
152 ui->payAmount->setValue(value.amount);
155 bool SendCoinsEntry::isClear()
157 return ui->payTo->text().isEmpty();
160 void SendCoinsEntry::setFocus()
162 ui->payTo->setFocus();
165 void SendCoinsEntry::updateDisplayUnit()
167 if(model && model->getOptionsModel())
169 // Update payAmount with the current unit
170 ui->payAmount->setDisplayUnit(model->getOptionsModel()->getDisplayUnit());