Bitcoin Core
31.1.0
P2P Digital Currency
Toggle main menu visibility
Loading...
Searching...
No Matches
src
qt
sendcoinsentry.cpp
Go to the documentation of this file.
1
// Copyright (c) 2011-present 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
>
6
#include <qt/forms/ui_sendcoinsentry.h>
7
8
#include <
qt/addressbookpage.h
>
9
#include <
qt/addresstablemodel.h
>
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
18
SendCoinsEntry::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
29
if
(
platformStyle
->getUseExtraSpacing())
30
ui
->payToLayout->setSpacing(4);
31
32
GUIUtil::setupAddressWidget
(
ui
->payTo,
this
);
33
34
// Connect signals
35
connect(
ui
->payAmount, &
BitcoinAmountField::valueChanged
,
this
, &
SendCoinsEntry::payAmountChanged
);
36
connect(
ui
->checkboxSubtractFeeFromAmount, &QCheckBox::toggled,
this
, &
SendCoinsEntry::subtractFeeFromAmountChanged
);
37
connect(
ui
->deleteButton, &QPushButton::clicked,
this
, &
SendCoinsEntry::deleteClicked
);
38
connect(
ui
->useAvailableBalanceButton, &QPushButton::clicked,
this
, &
SendCoinsEntry::useAvailableBalanceClicked
);
39
}
40
41
SendCoinsEntry::~SendCoinsEntry
()
42
{
43
delete
ui
;
44
}
45
46
void
SendCoinsEntry::on_pasteButton_clicked
()
47
{
48
// Paste text from clipboard into recipient field
49
ui
->payTo->setText(QApplication::clipboard()->text());
50
}
51
52
void
SendCoinsEntry::on_addressBookButton_clicked
()
53
{
54
if
(!
model
)
55
return
;
56
AddressBookPage
dlg(
platformStyle
,
AddressBookPage::ForSelection
,
AddressBookPage::SendingTab
,
this
);
57
dlg.
setModel
(
model
->getAddressTableModel());
58
if
(dlg.exec())
59
{
60
ui
->payTo->setText(dlg.
getReturnValue
());
61
ui
->payAmount->setFocus();
62
}
63
}
64
65
void
SendCoinsEntry::on_payTo_textChanged
(
const
QString &address)
66
{
67
updateLabel
(address);
68
}
69
70
void
SendCoinsEntry::setModel
(
WalletModel
*_model)
71
{
72
this->
model
= _model;
73
74
if
(_model && _model->
getOptionsModel
())
75
connect(_model->
getOptionsModel
(), &
OptionsModel::displayUnitChanged
,
this
, &
SendCoinsEntry::updateDisplayUnit
);
76
77
clear
();
78
}
79
80
void
SendCoinsEntry::clear
()
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()) {
87
ui
->checkboxSubtractFeeFromAmount->setChecked(
model
->getOptionsModel()->getSubFeeFromAmount());
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")
94
updateDisplayUnit
();
95
}
96
97
void
SendCoinsEntry::checkSubtractFeeFromAmount
()
98
{
99
ui
->checkboxSubtractFeeFromAmount->setChecked(
true
);
100
}
101
102
void
SendCoinsEntry::deleteClicked
()
103
{
104
Q_EMIT
removeEntry
(
this
);
105
}
106
107
void
SendCoinsEntry::useAvailableBalanceClicked
()
108
{
109
Q_EMIT
useAvailableBalance
(
this
);
110
}
111
112
bool
SendCoinsEntry::validate
(
interfaces::Node
&
node
)
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
147
SendCoinsRecipient
SendCoinsEntry::getValue
()
148
{
149
recipient
.address =
ui
->payTo->text();
150
recipient
.label =
ui
->addAsLabel->text();
151
recipient
.amount =
ui
->payAmount->value();
152
recipient
.message =
ui
->messageTextLabel->text();
153
recipient
.fSubtractFeeFromAmount = (
ui
->checkboxSubtractFeeFromAmount->checkState() == Qt::Checked);
154
155
return
recipient
;
156
}
157
158
QWidget *
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
170
void
SendCoinsEntry::setValue
(
const
SendCoinsRecipient
&value)
171
{
172
recipient
= value;
173
{
174
// message
175
ui
->messageTextLabel->setText(
recipient
.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);
183
ui
->payAmount->setValue(
recipient
.amount);
184
}
185
}
186
187
void
SendCoinsEntry::setAddress
(
const
QString &address)
188
{
189
ui
->payTo->setText(address);
190
ui
->payAmount->setFocus();
191
}
192
193
void
SendCoinsEntry::setAmount
(
const
CAmount
&amount)
194
{
195
ui
->payAmount->setValue(amount);
196
}
197
198
bool
SendCoinsEntry::isClear
()
199
{
200
return
ui
->payTo->text().isEmpty();
201
}
202
203
void
SendCoinsEntry::setFocus
()
204
{
205
ui
->payTo->setFocus();
206
}
207
208
void
SendCoinsEntry::updateDisplayUnit
()
209
{
210
if
(
model
&&
model
->getOptionsModel()) {
211
ui
->payAmount->setDisplayUnit(
model
->getOptionsModel()->getDisplayUnit());
212
}
213
}
214
215
void
SendCoinsEntry::changeEvent
(QEvent* e)
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
226
bool
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
}
addressbookpage.h
addresstablemodel.h
CAmount
int64_t CAmount
Amount in satoshis (Can be negative).
Definition
amount.h:12
if
if(!SetupNetworking())
Definition
bitcoin-cli.cpp:1331
AddressBookPage
Widget that shows a list of sending or receiving addresses.
Definition
addressbookpage.h:27
AddressBookPage::ForSelection
@ ForSelection
Open address book to pick address.
Definition
addressbookpage.h:37
AddressBookPage::setModel
void setModel(AddressTableModel *model)
Definition
addressbookpage.cpp:119
AddressBookPage::SendingTab
@ SendingTab
Definition
addressbookpage.h:32
AddressBookPage::getReturnValue
const QString & getReturnValue() const
Definition
addressbookpage.h:45
BitcoinAmountField::valueChanged
void valueChanged()
OptionsModel::displayUnitChanged
void displayUnitChanged(BitcoinUnit unit)
PlatformStyle
Definition
platformstyle.h:14
SendCoinsEntry::model
WalletModel * model
Definition
sendcoinsentry.h:76
SendCoinsEntry::setFocus
void setFocus()
Definition
sendcoinsentry.cpp:203
SendCoinsEntry::updateLabel
bool updateLabel(const QString &address)
Definition
sendcoinsentry.cpp:226
SendCoinsEntry::setAddress
void setAddress(const QString &address)
Definition
sendcoinsentry.cpp:187
SendCoinsEntry::isClear
bool isClear()
Return whether the entry is still empty and unedited.
Definition
sendcoinsentry.cpp:198
SendCoinsEntry::subtractFeeFromAmountChanged
void subtractFeeFromAmountChanged()
SendCoinsEntry::useAvailableBalance
void useAvailableBalance(SendCoinsEntry *entry)
SendCoinsEntry::~SendCoinsEntry
~SendCoinsEntry()
Definition
sendcoinsentry.cpp:41
SendCoinsEntry::recipient
SendCoinsRecipient recipient
Definition
sendcoinsentry.h:74
SendCoinsEntry::setValue
void setValue(const SendCoinsRecipient &value)
Definition
sendcoinsentry.cpp:170
SendCoinsEntry::changeEvent
void changeEvent(QEvent *e) override
Definition
sendcoinsentry.cpp:215
SendCoinsEntry::updateDisplayUnit
void updateDisplayUnit()
Definition
sendcoinsentry.cpp:208
SendCoinsEntry::on_payTo_textChanged
void on_payTo_textChanged(const QString &address)
Definition
sendcoinsentry.cpp:65
SendCoinsEntry::on_pasteButton_clicked
void on_pasteButton_clicked()
Definition
sendcoinsentry.cpp:46
SendCoinsEntry::SendCoinsEntry
SendCoinsEntry(const PlatformStyle *platformStyle, QWidget *parent=nullptr)
Definition
sendcoinsentry.cpp:18
SendCoinsEntry::setModel
void setModel(WalletModel *model)
Definition
sendcoinsentry.cpp:70
SendCoinsEntry::useAvailableBalanceClicked
void useAvailableBalanceClicked()
Definition
sendcoinsentry.cpp:107
SendCoinsEntry::removeEntry
void removeEntry(SendCoinsEntry *entry)
SendCoinsEntry::payAmountChanged
void payAmountChanged()
SendCoinsEntry::setAmount
void setAmount(const CAmount &amount)
Definition
sendcoinsentry.cpp:193
SendCoinsEntry::setupTabChain
QWidget * setupTabChain(QWidget *prev)
Set up the tab chain manually, as Qt messes up the tab chain by default in some cases (issue https://...
Definition
sendcoinsentry.cpp:158
SendCoinsEntry::platformStyle
const PlatformStyle * platformStyle
Definition
sendcoinsentry.h:77
SendCoinsEntry::deleteClicked
void deleteClicked()
Definition
sendcoinsentry.cpp:102
SendCoinsEntry::clear
void clear()
Definition
sendcoinsentry.cpp:80
SendCoinsEntry::on_addressBookButton_clicked
void on_addressBookButton_clicked()
Definition
sendcoinsentry.cpp:52
SendCoinsEntry::validate
bool validate(interfaces::Node &node)
Definition
sendcoinsentry.cpp:112
SendCoinsEntry::ui
Ui::SendCoinsEntry * ui
Definition
sendcoinsentry.h:75
SendCoinsEntry::checkSubtractFeeFromAmount
void checkSubtractFeeFromAmount()
Definition
sendcoinsentry.cpp:97
SendCoinsEntry::getValue
SendCoinsRecipient getValue()
Definition
sendcoinsentry.cpp:147
SendCoinsRecipient
Definition
sendcoinsrecipient.h:16
WalletModel
Interface to Bitcoin wallet from Qt view code.
Definition
walletmodel.h:49
WalletModel::getOptionsModel
OptionsModel * getOptionsModel() const
Definition
walletmodel.cpp:284
interfaces::Node
Top-level interface for a bitcoin node (bitcoind process).
Definition
node.h:70
guiutil.h
GUIUtil::isDust
bool isDust(interfaces::Node &node, const QString &address, const CAmount &amount)
Definition
guiutil.cpp:241
GUIUtil::setupAddressWidget
void setupAddressWidget(QValidatedLineEdit *widget, QWidget *parent)
Definition
guiutil.cpp:131
Ui
Definition
addressbookpage.h:14
node
Definition
messages.h:21
optionsmodel.h
platformstyle.h
sendcoinsentry.h
walletmodel.h
Generated on
for Bitcoin Core by
1.17.0