Bitcoin Core 22.99.0
P2P Digital Currency
sendcoinsentry.cpp
Go to the documentation of this file.
1// Copyright (c) 2011-2019 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#if defined(HAVE_CONFIG_H)
7#endif
8
9#include <qt/sendcoinsentry.h>
11
12#include <qt/addressbookpage.h>
14#include <qt/guiutil.h>
15#include <qt/optionsmodel.h>
16#include <qt/platformstyle.h>
17#include <qt/walletmodel.h>
18
19#include <QApplication>
20#include <QClipboard>
21
22SendCoinsEntry::SendCoinsEntry(const PlatformStyle *_platformStyle, QWidget *parent) :
23 QStackedWidget(parent),
24 ui(new Ui::SendCoinsEntry),
25 model(nullptr),
26 platformStyle(_platformStyle)
27{
28 ui->setupUi(this);
29
30 ui->addressBookButton->setIcon(platformStyle->SingleColorIcon(":/icons/address-book"));
31 ui->pasteButton->setIcon(platformStyle->SingleColorIcon(":/icons/editpaste"));
32 ui->deleteButton->setIcon(platformStyle->SingleColorIcon(":/icons/remove"));
33 ui->deleteButton_is->setIcon(platformStyle->SingleColorIcon(":/icons/remove"));
34 ui->deleteButton_s->setIcon(platformStyle->SingleColorIcon(":/icons/remove"));
35
36 setCurrentWidget(ui->SendCoins);
37
39 ui->payToLayout->setSpacing(4);
40
41 // normal bitcoin address field
43 // just a label for displaying bitcoin address(es)
45
46 // Connect signals
49 connect(ui->deleteButton, &QPushButton::clicked, this, &SendCoinsEntry::deleteClicked);
50 connect(ui->deleteButton_is, &QPushButton::clicked, this, &SendCoinsEntry::deleteClicked);
51 connect(ui->deleteButton_s, &QPushButton::clicked, this, &SendCoinsEntry::deleteClicked);
52 connect(ui->useAvailableBalanceButton, &QPushButton::clicked, this, &SendCoinsEntry::useAvailableBalanceClicked);
53}
54
56{
57 delete ui;
58}
59
61{
62 // Paste text from clipboard into recipient field
63 ui->payTo->setText(QApplication::clipboard()->text());
64}
65
67{
68 if(!model)
69 return;
72 if(dlg.exec())
73 {
74 ui->payTo->setText(dlg.getReturnValue());
75 ui->payAmount->setFocus();
76 }
77}
78
79void SendCoinsEntry::on_payTo_textChanged(const QString &address)
80{
81 updateLabel(address);
82}
83
85{
86 this->model = _model;
87
88 if (_model && _model->getOptionsModel())
90
91 clear();
92}
93
95{
96 // clear UI elements for normal payment
97 ui->payTo->clear();
98 ui->addAsLabel->clear();
99 ui->payAmount->clear();
100 if (model && model->getOptionsModel()) {
102 }
103 ui->messageTextLabel->clear();
104 ui->messageTextLabel->hide();
105 ui->messageLabel->hide();
106 // clear UI elements for unauthenticated payment request
107 ui->payTo_is->clear();
108 ui->memoTextLabel_is->clear();
110 // clear UI elements for authenticated payment request
111 ui->payTo_s->clear();
112 ui->memoTextLabel_s->clear();
113 ui->payAmount_s->clear();
114
115 // update the display unit, to not use the default ("BTC")
117}
118
120{
121 ui->checkboxSubtractFeeFromAmount->setChecked(true);
122}
123
125{
126 Q_EMIT removeEntry(this);
127}
128
130{
131 Q_EMIT useAvailableBalance(this);
132}
133
135{
136 if (!model)
137 return false;
138
139 // Check input validity
140 bool retval = true;
141
142 if (!model->validateAddress(ui->payTo->text()))
143 {
144 ui->payTo->setValid(false);
145 retval = false;
146 }
147
148 if (!ui->payAmount->validate())
149 {
150 retval = false;
151 }
152
153 // Sending a zero amount is invalid
154 if (ui->payAmount->value(nullptr) <= 0)
155 {
156 ui->payAmount->setValid(false);
157 retval = false;
158 }
159
160 // Reject dust outputs:
161 if (retval && GUIUtil::isDust(node, ui->payTo->text(), ui->payAmount->value())) {
162 ui->payAmount->setValid(false);
163 retval = false;
164 }
165
166 return retval;
167}
168
170{
171 recipient.address = ui->payTo->text();
172 recipient.label = ui->addAsLabel->text();
175 recipient.fSubtractFeeFromAmount = (ui->checkboxSubtractFeeFromAmount->checkState() == Qt::Checked);
176
177 return recipient;
178}
179
180QWidget *SendCoinsEntry::setupTabChain(QWidget *prev)
181{
182 QWidget::setTabOrder(prev, ui->payTo);
183 QWidget::setTabOrder(ui->payTo, ui->addAsLabel);
184 QWidget *w = ui->payAmount->setupTabChain(ui->addAsLabel);
185 QWidget::setTabOrder(w, ui->checkboxSubtractFeeFromAmount);
186 QWidget::setTabOrder(ui->checkboxSubtractFeeFromAmount, ui->addressBookButton);
187 QWidget::setTabOrder(ui->addressBookButton, ui->pasteButton);
188 QWidget::setTabOrder(ui->pasteButton, ui->deleteButton);
189 return ui->deleteButton;
190}
191
193{
194 recipient = value;
195 {
196 // message
198 ui->messageTextLabel->setVisible(!recipient.message.isEmpty());
199 ui->messageLabel->setVisible(!recipient.message.isEmpty());
200
201 ui->addAsLabel->clear();
202 ui->payTo->setText(recipient.address); // this may set a label from addressbook
203 if (!recipient.label.isEmpty()) // if a label had been set from the addressbook, don't overwrite with an empty label
204 ui->addAsLabel->setText(recipient.label);
206 }
207}
208
209void SendCoinsEntry::setAddress(const QString &address)
210{
211 ui->payTo->setText(address);
212 ui->payAmount->setFocus();
213}
214
216{
217 ui->payAmount->setValue(amount);
218}
219
221{
222 return ui->payTo->text().isEmpty() && ui->payTo_is->text().isEmpty() && ui->payTo_s->text().isEmpty();
223}
224
226{
227 ui->payTo->setFocus();
228}
229
231{
232 if(model && model->getOptionsModel())
233 {
234 // Update payAmount with the current unit
238 }
239}
240
242{
243 if (e->type() == QEvent::PaletteChange) {
244 ui->addressBookButton->setIcon(platformStyle->SingleColorIcon(QStringLiteral(":/icons/address-book")));
245 ui->pasteButton->setIcon(platformStyle->SingleColorIcon(QStringLiteral(":/icons/editpaste")));
246 ui->deleteButton->setIcon(platformStyle->SingleColorIcon(QStringLiteral(":/icons/remove")));
247 ui->deleteButton_is->setIcon(platformStyle->SingleColorIcon(QStringLiteral(":/icons/remove")));
248 ui->deleteButton_s->setIcon(platformStyle->SingleColorIcon(QStringLiteral(":/icons/remove")));
249 }
250
251 QStackedWidget::changeEvent(e);
252}
253
254bool SendCoinsEntry::updateLabel(const QString &address)
255{
256 if(!model)
257 return false;
258
259 // Fill in label from address book, if address has an associated label
260 QString associatedLabel = model->getAddressTableModel()->labelForAddress(address);
261 if(!associatedLabel.isEmpty())
262 {
263 ui->addAsLabel->setText(associatedLabel);
264 return true;
265 }
266
267 return false;
268}
int64_t CAmount
Amount in satoshis (Can be negative)
Definition: amount.h:12
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(int 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)
int getDisplayUnit() const
Definition: optionsmodel.h:88
bool getSubFeeFromAmount() const
Definition: optionsmodel.h:92
void displayUnitChanged(int unit)
QIcon SingleColorIcon(const QString &filename) const
Colorize an icon (given filename) with the icon color.
bool getUseExtraSpacing() const
Definition: platformstyle.h:22
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()
QToolButton * deleteButton_is
QValidatedLineEdit * payTo
QLineEdit * addAsLabel
QLabel * memoTextLabel_s
BitcoinAmountField * payAmount_is
QPushButton * useAvailableBalanceButton
QLabel * memoTextLabel_is
QToolButton * pasteButton
BitcoinAmountField * payAmount_s
QLabel * messageTextLabel
QLabel * payTo_s
QFrame * SendCoins
QCheckBox * checkboxSubtractFeeFromAmount
QLabel * payTo_is
void setupUi(QStackedWidget *SendCoinsEntry)
QHBoxLayout * payToLayout
QToolButton * deleteButton
QToolButton * addressBookButton
QToolButton * deleteButton_s
BitcoinAmountField * payAmount
QLabel * messageLabel
Interface to Bitcoin wallet from Qt view code.
Definition: walletmodel.h:52
bool validateAddress(const QString &address)
AddressTableModel * getAddressTableModel()
OptionsModel * getOptionsModel()
Top-level interface for a bitcoin node (bitcoind process).
Definition: node.h:55
QFont fixedPitchFont(bool use_embedded_font)
Definition: guiutil.cpp:88
bool isDust(interfaces::Node &node, const QString &address, const CAmount &amount)
Definition: guiutil.cpp:225
void setupAddressWidget(QValidatedLineEdit *widget, QWidget *parent)
Definition: guiutil.cpp:114