123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175 |
- // ECOin - Copyright (c) - 2014/2021 - GPLv3 - epsylon@riseup.net (https://03c8.net)
- #include "sendcoinsentry.h"
- #include "ui_sendcoinsentry.h"
- #include "guiutil.h"
- #include "ecoinunits.h"
- #include "addressbookpage.h"
- #include "walletmodel.h"
- #include "optionsmodel.h"
- #include "addresstablemodel.h"
- #include <QApplication>
- #include <QClipboard>
- SendCoinsEntry::SendCoinsEntry(QWidget *parent) :
- QFrame(parent),
- ui(new Ui::SendCoinsEntry),
- model(0)
- {
- ui->setupUi(this);
- #ifdef Q_OS_MAC
- ui->payToLayout->setSpacing(4);
- #endif
- #if QT_VERSION >= 0x040700
- /* 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 Ecoin address (e.g. EJiA1K71didR1ovdVUtse1AJVWye2V1jeV)"));
- #endif
- setFocusPolicy(Qt::TabFocus);
- setFocusProxy(ui->payTo);
- GUIUtil::setupAddressWidget(ui->payTo, this);
- }
- SendCoinsEntry::~SendCoinsEntry()
- {
- delete ui;
- }
- void SendCoinsEntry::on_pasteButton_clicked()
- {
- // Paste text from clipboard into recipient field
- ui->payTo->setText(QApplication::clipboard()->text());
- }
- void SendCoinsEntry::on_addressBookButton_clicked()
- {
- if(!model)
- return;
- AddressBookPage dlg(AddressBookPage::ForSending, AddressBookPage::SendingTab, this);
- dlg.setModel(model->getAddressTableModel());
- if(dlg.exec())
- {
- ui->payTo->setText(dlg.getReturnValue());
- ui->payAmount->setFocus();
- }
- }
- void SendCoinsEntry::on_payTo_textChanged(const QString &address)
- {
- if(!model)
- return;
- // Fill in label from address book, if address has an associated label
- QString associatedLabel = model->getAddressTableModel()->labelForAddress(address);
- if(!associatedLabel.isEmpty())
- ui->addAsLabel->setText(associatedLabel);
- }
- 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)
- {
- ui->deleteButton->setEnabled(enabled);
- }
- void SendCoinsEntry::clear()
- {
- ui->payTo->clear();
- ui->addAsLabel->clear();
- ui->payAmount->clear();
- ui->payTo->setFocus();
- // update the display unit, to not use the default ("ECO")
- updateDisplayUnit();
- }
- void SendCoinsEntry::on_deleteButton_clicked()
- {
- emit removeEntry(this);
- }
- bool SendCoinsEntry::validate()
- {
- // Check input validity
- bool retval = true;
- if(!ui->payAmount->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())))
- {
- ui->payTo->setValid(false);
- retval = false;
- }
- return retval;
- }
- SendCoinsRecipient SendCoinsEntry::getValue()
- {
- SendCoinsRecipient rv;
- rv.address = ui->payTo->text();
- rv.label = ui->addAsLabel->text();
- rv.amount = ui->payAmount->value();
- return rv;
- }
- QWidget *SendCoinsEntry::setupTabChain(QWidget *prev)
- {
- QWidget::setTabOrder(prev, ui->payTo);
- QWidget::setTabOrder(ui->payTo, ui->addressBookButton);
- QWidget::setTabOrder(ui->addressBookButton, ui->pasteButton);
- QWidget::setTabOrder(ui->pasteButton, ui->deleteButton);
- 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());
- }
- }
|