X-Git-Url: https://git.novaco.in/?a=blobdiff_plain;f=src%2Fqt%2Fsendcoinsentry.cpp;h=7e960beba9ea5c6db8bc658bc6b20179d0fd7736;hb=f8ea0dd6459856f2df18ca2ad532d49432a087dd;hp=2d4fe9b12383d099cc44292f08e7483097fb5ebf;hpb=73cd5e5212be7ff05f7205c1e7519af1cf01e322;p=novacoin.git diff --git a/src/qt/sendcoinsentry.cpp b/src/qt/sendcoinsentry.cpp index 2d4fe9b..7e960be 100644 --- a/src/qt/sendcoinsentry.cpp +++ b/src/qt/sendcoinsentry.cpp @@ -1,14 +1,14 @@ #include "sendcoinsentry.h" #include "ui_sendcoinsentry.h" #include "guiutil.h" +#include "bitcoinunits.h" #include "addressbookpage.h" #include "walletmodel.h" +#include "optionsmodel.h" #include "addresstablemodel.h" -#include "qapplication.h" -#include "qclipboard.h" - -#include +#include +#include SendCoinsEntry::SendCoinsEntry(QWidget *parent) : QFrame(parent), @@ -17,9 +17,13 @@ SendCoinsEntry::SendCoinsEntry(QWidget *parent) : { ui->setupUi(this); +#ifdef Q_OS_MAC + ui->payToLayout->setSpacing(4); +#endif #if QT_VERSION >= 0x040700 - ui->payTo->setPlaceholderText(tr("Enter a Bitcoin address (e.g. 1NS17iag9jJgTHD1VXjvLCEnZuQ3rJDE9L)")); + /* Do not move this to the XML file, Qt before 4.7 will choke on it */ ui->addAsLabel->setPlaceholderText(tr("Enter a label for this address to add it to your address book")); + ui->payTo->setPlaceholderText(tr("Enter a NovaCoin address (e.g. 4Zo1ga6xuKuQ7JV7M9rGDoxdbYwV5zgQJ5)")); #endif setFocusPolicy(Qt::TabFocus); setFocusProxy(ui->payTo); @@ -40,6 +44,8 @@ void SendCoinsEntry::on_pasteButton_clicked() void SendCoinsEntry::on_addressBookButton_clicked() { + if(!model) + return; AddressBookPage dlg(AddressBookPage::ForSending, AddressBookPage::SendingTab, this); dlg.setModel(model->getAddressTableModel()); if(dlg.exec()) @@ -51,12 +57,22 @@ void SendCoinsEntry::on_addressBookButton_clicked() void SendCoinsEntry::on_payTo_textChanged(const QString &address) { + if(!model) + return; + // Fill in label from address book ui->addAsLabel->setText(model->getAddressTableModel()->labelForAddress(address)); } void SendCoinsEntry::setModel(WalletModel *model) { this->model = model; + + if(model && model->getOptionsModel()) + connect(model->getOptionsModel(), SIGNAL(displayUnitChanged(int)), this, SLOT(updateDisplayUnit())); + + connect(ui->payAmount, SIGNAL(textChanged()), this, SIGNAL(payAmountChanged())); + + clear(); } void SendCoinsEntry::setRemoveEnabled(bool enabled) @@ -70,6 +86,8 @@ void SendCoinsEntry::clear() ui->addAsLabel->clear(); ui->payAmount->clear(); ui->payTo->setFocus(); + // update the display unit, to not use the default ("BTC") + updateDisplayUnit(); } void SendCoinsEntry::on_deleteButton_clicked() @@ -86,6 +104,15 @@ bool SendCoinsEntry::validate() { retval = false; } + else + { + if(ui->payAmount->value() <= 0) + { + // Cannot send 0 coins or less + ui->payAmount->setValid(false); + retval = false; + } + } if(!ui->payTo->hasAcceptableInput() || (model && !model->validateAddress(ui->payTo->text()))) @@ -103,7 +130,7 @@ SendCoinsRecipient SendCoinsEntry::getValue() rv.address = ui->payTo->text(); rv.label = ui->addAsLabel->text(); - GUIUtil::parseMoney(ui->payAmount->text(), &rv.amount); + rv.amount = ui->payAmount->value(); return rv; } @@ -117,3 +144,29 @@ QWidget *SendCoinsEntry::setupTabChain(QWidget *prev) QWidget::setTabOrder(ui->deleteButton, ui->addAsLabel); return ui->payAmount->setupTabChain(ui->addAsLabel); } + +void SendCoinsEntry::setValue(const SendCoinsRecipient &value) +{ + ui->payTo->setText(value.address); + ui->addAsLabel->setText(value.label); + ui->payAmount->setValue(value.amount); +} + +bool SendCoinsEntry::isClear() +{ + return ui->payTo->text().isEmpty(); +} + +void SendCoinsEntry::setFocus() +{ + ui->payTo->setFocus(); +} + +void SendCoinsEntry::updateDisplayUnit() +{ + if(model && model->getOptionsModel()) + { + // Update payAmount with the current unit + ui->payAmount->setDisplayUnit(model->getOptionsModel()->getDisplayUnit()); + } +}