Bitcoin Core 28.0.0
P2P Digital Currency
Loading...
Searching...
No Matches
sendcoinsentry.cpp
Go to the documentation of this file.
1// Copyright (c) 2011-2022 The Bitcoin Core developers
2// Distributed under the MIT software license, see the accompanying
3// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
5#include <qt/sendcoinsentry.h>
7
10#include <qt/guiutil.h>
11#include <qt/optionsmodel.h>
12#include <qt/platformstyle.h>
13#include <qt/walletmodel.h>
14
15#include <QApplication>
16#include <QClipboard>
17
18SendCoinsEntry::SendCoinsEntry(const PlatformStyle *_platformStyle, QWidget *parent) :
19 QWidget(parent),
20 ui(new Ui::SendCoinsEntry),
21 platformStyle(_platformStyle)
22{
23 ui->setupUi(this);
24
25 ui->addressBookButton->setIcon(platformStyle->SingleColorIcon(":/icons/address-book"));
26 ui->pasteButton->setIcon(platformStyle->SingleColorIcon(":/icons/editpaste"));
27 ui->deleteButton->setIcon(platformStyle->SingleColorIcon(":/icons/remove"));
28
30 ui->payToLayout->setSpacing(4);
31
33
34 // Connect signals
37 connect(ui->deleteButton, &QPushButton::clicked, this, &SendCoinsEntry::deleteClicked);
38 connect(ui->useAvailableBalanceButton, &QPushButton::clicked, this, &SendCoinsEntry::useAvailableBalanceClicked);
39}
40
45
47{
48 // Paste text from clipboard into recipient field
49 ui->payTo->setText(QApplication::clipboard()->text());
50}
51
64
65void SendCoinsEntry::on_payTo_textChanged(const QString &address)
66{
67 updateLabel(address);
68}
69
71{
72 this->model = _model;
73
74 if (_model && _model->getOptionsModel())
76
77 clear();
78}
79
81{
82 // clear UI elements for normal payment
83 ui->payTo->clear();
84 ui->addAsLabel->clear();
85 ui->payAmount->clear();
86 if (model && model->getOptionsModel()) {
88 }
89 ui->messageTextLabel->clear();
90 ui->messageTextLabel->hide();
91 ui->messageLabel->hide();
92
93 // update the display unit, to not use the default ("BTC")
95}
96
101
103{
104 Q_EMIT removeEntry(this);
105}
106
111
113{
114 if (!model)
115 return false;
116
117 // Check input validity
118 bool retval = true;
119
120 if (!model->validateAddress(ui->payTo->text()))
121 {
122 ui->payTo->setValid(false);
123 retval = false;
124 }
125
126 if (!ui->payAmount->validate())
127 {
128 retval = false;
129 }
130
131 // Sending a zero amount is invalid
132 if (ui->payAmount->value(nullptr) <= 0)
133 {
134 ui->payAmount->setValid(false);
135 retval = false;
136 }
137
138 // Reject dust outputs:
139 if (retval && GUIUtil::isDust(node, ui->payTo->text(), ui->payAmount->value())) {
140 ui->payAmount->setValid(false);
141 retval = false;
142 }
143
144 return retval;
145}
146
157
158QWidget *SendCoinsEntry::setupTabChain(QWidget *prev)
159{
160 QWidget::setTabOrder(prev, ui->payTo);
161 QWidget::setTabOrder(ui->payTo, ui->addAsLabel);
162 QWidget *w = ui->payAmount->setupTabChain(ui->addAsLabel);
163 QWidget::setTabOrder(w, ui->checkboxSubtractFeeFromAmount);
164 QWidget::setTabOrder(ui->checkboxSubtractFeeFromAmount, ui->addressBookButton);
165 QWidget::setTabOrder(ui->addressBookButton, ui->pasteButton);
166 QWidget::setTabOrder(ui->pasteButton, ui->deleteButton);
167 return ui->deleteButton;
168}
169
171{
172 recipient = value;
173 {
174 // message
176 ui->messageTextLabel->setVisible(!recipient.message.isEmpty());
177 ui->messageLabel->setVisible(!recipient.message.isEmpty());
178
179 ui->addAsLabel->clear();
180 ui->payTo->setText(recipient.address); // this may set a label from addressbook
181 if (!recipient.label.isEmpty()) // if a label had been set from the addressbook, don't overwrite with an empty label
182 ui->addAsLabel->setText(recipient.label);
184 }
185}
186
187void SendCoinsEntry::setAddress(const QString &address)
188{
189 ui->payTo->setText(address);
190 ui->payAmount->setFocus();
191}
192
194{
195 ui->payAmount->setValue(amount);
196}
197
199{
200 return ui->payTo->text().isEmpty();
201}
202
204{
205 ui->payTo->setFocus();
206}
207
214
216{
217 if (e->type() == QEvent::PaletteChange) {
218 ui->addressBookButton->setIcon(platformStyle->SingleColorIcon(QStringLiteral(":/icons/address-book")));
219 ui->pasteButton->setIcon(platformStyle->SingleColorIcon(QStringLiteral(":/icons/editpaste")));
220 ui->deleteButton->setIcon(platformStyle->SingleColorIcon(QStringLiteral(":/icons/remove")));
221 }
222
223 QWidget::changeEvent(e);
224}
225
226bool SendCoinsEntry::updateLabel(const QString &address)
227{
228 if(!model)
229 return false;
230
231 // Fill in label from address book, if address has an associated label
232 QString associatedLabel = model->getAddressTableModel()->labelForAddress(address);
233 if(!associatedLabel.isEmpty())
234 {
235 ui->addAsLabel->setText(associatedLabel);
236 return true;
237 }
238
239 return false;
240}
int64_t CAmount
Amount in satoshis (Can be negative)
Definition amount.h:12
if(!SetupNetworking())
Widget that shows a list of sending or receiving addresses.
@ ForSelection
Open address book to pick address.
void setModel(AddressTableModel *model)
const QString & getReturnValue() const
QString labelForAddress(const QString &address) const
Look up label for address in address book, if not found return empty string.
void setDisplayUnit(BitcoinUnit new_unit)
Change unit used to display amount.
void clear()
Make field empty and ready for new input.
bool validate()
Perform input validation, mark field as invalid if entered value is not valid.
QWidget * setupTabChain(QWidget *prev)
Qt messes up the tab chain by default in some cases (issue https://bugreports.qt-project....
void setValid(bool valid)
Mark current value as invalid in UI.
void setValue(const CAmount &value)
bool getSubFeeFromAmount() const
void displayUnitChanged(BitcoinUnit unit)
BitcoinUnit getDisplayUnit() const
QIcon SingleColorIcon(const QString &filename) const
Colorize an icon (given filename) with the icon color.
bool getUseExtraSpacing() const
void setText(const QString &)
void setValid(bool valid)
A single entry in the dialog for sending bitcoins.
WalletModel * model
void setFocus()
bool updateLabel(const QString &address)
void setAddress(const QString &address)
bool isClear()
Return whether the entry is still empty and unedited.
void subtractFeeFromAmountChanged()
void useAvailableBalance(SendCoinsEntry *entry)
~SendCoinsEntry()
SendCoinsRecipient recipient
void setValue(const SendCoinsRecipient &value)
void changeEvent(QEvent *e) override
void updateDisplayUnit()
void on_payTo_textChanged(const QString &address)
void on_pasteButton_clicked()
SendCoinsEntry(const PlatformStyle *platformStyle, QWidget *parent=nullptr)
void setModel(WalletModel *model)
void useAvailableBalanceClicked()
void removeEntry(SendCoinsEntry *entry)
void payAmountChanged()
void setAmount(const CAmount &amount)
QWidget * setupTabChain(QWidget *prev)
Set up the tab chain manually, as Qt messes up the tab chain by default in some cases (issue https://...
const PlatformStyle * platformStyle
void deleteClicked()
void clear()
void on_addressBookButton_clicked()
bool validate(interfaces::Node &node)
Ui::SendCoinsEntry * ui
void checkSubtractFeeFromAmount()
SendCoinsRecipient getValue()
QValidatedLineEdit * payTo
QLineEdit * addAsLabel
QPushButton * useAvailableBalanceButton
QToolButton * pasteButton
QLabel * messageTextLabel
QCheckBox * checkboxSubtractFeeFromAmount
void setupUi(QWidget *SendCoinsEntry)
QHBoxLayout * payToLayout
QToolButton * deleteButton
QToolButton * addressBookButton
BitcoinAmountField * payAmount
QLabel * messageLabel
Interface to Bitcoin wallet from Qt view code.
Definition walletmodel.h:48
AddressTableModel * getAddressTableModel() const
bool validateAddress(const QString &address) const
OptionsModel * getOptionsModel() const
Top-level interface for a bitcoin node (bitcoind process).
Definition node.h:70
bool isDust(interfaces::Node &node, const QString &address, const CAmount &amount)
Definition guiutil.cpp:241
void setupAddressWidget(QValidatedLineEdit *widget, QWidget *parent)
Definition guiutil.cpp:131