Dash Core Source Documentation (0.16.0.1)

Find detailed information regarding the Dash Core source code.

sendcoinsentry.cpp
Go to the documentation of this file.
1 // Copyright (c) 2011-2015 The Bitcoin Core developers
2 // Copyright (c) 2014-2019 The Dash Core developers
3 // Distributed under the MIT software license, see the accompanying
4 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
5 
6 #include <qt/sendcoinsentry.h>
7 #include <qt/forms/ui_sendcoinsentry.h>
8 
9 #include <qt/addressbookpage.h>
10 #include <qt/addresstablemodel.h>
11 #include <qt/guiutil.h>
12 #include <qt/optionsmodel.h>
13 
14 #include <QApplication>
15 #include <QClipboard>
16 
18  QStackedWidget(parent),
19  ui(new Ui::SendCoinsEntry),
20  model(0)
21 {
22  ui->setupUi(this);
23 
25 
26  setCurrentWidget(ui->SendCoins);
27 
28 #if QT_VERSION >= 0x040700
29  ui->addAsLabel->setPlaceholderText(tr("Enter a label for this address to add it to your address book"));
30 #endif
31 
33 
34  // normal dash address field
35  GUIUtil::setupAddressWidget(ui->payTo, this, true);
36 
37  GUIUtil::setFont({ui->payToLabel,
38  ui->labellLabel,
39  ui->amountLabel,
40  ui->messageLabel}, GUIUtil::FontWeight::Normal, 15);
41 
43 
44  // Connect signals
45  connect(ui->payAmount, SIGNAL(valueChanged()), this, SIGNAL(payAmountChanged()));
46  connect(ui->checkboxSubtractFeeFromAmount, SIGNAL(toggled(bool)), this, SIGNAL(subtractFeeFromAmountChanged()));
47  connect(ui->deleteButton, SIGNAL(clicked()), this, SLOT(deleteClicked()));
48  connect(ui->deleteButton_is, SIGNAL(clicked()), this, SLOT(deleteClicked()));
49  connect(ui->deleteButton_s, SIGNAL(clicked()), this, SLOT(deleteClicked()));
50  connect(ui->useAvailableBalanceButton, SIGNAL(clicked()), this, SLOT(useAvailableBalanceClicked()));
51 }
52 
54 {
55  delete ui;
56 }
57 
59 {
60  // Paste text from clipboard into recipient field
61  ui->payTo->setText(QApplication::clipboard()->text());
62 }
63 
65 {
66  if(!model)
67  return;
70  if(dlg.exec())
71  {
72  ui->payTo->setText(dlg.getReturnValue());
73  ui->payAmount->setFocus();
74  }
75 }
76 
77 void SendCoinsEntry::on_payTo_textChanged(const QString &address)
78 {
80  if (GUIUtil::parseBitcoinURI(address, &rcp)) {
81  ui->payTo->blockSignals(true);
82  setValue(rcp);
83  ui->payTo->blockSignals(false);
84  } else {
85  updateLabel(address);
86  }
87 }
88 
90 {
91  this->model = _model;
92 
93  if (_model && _model->getOptionsModel())
94  connect(_model->getOptionsModel(), SIGNAL(displayUnitChanged(int)), this, SLOT(updateDisplayUnit()));
95 
96  clear();
97 }
98 
100 {
101  // clear UI elements for normal payment
102  ui->payTo->clear();
103  ui->addAsLabel->clear();
104  ui->payAmount->clear();
105  ui->checkboxSubtractFeeFromAmount->setCheckState(Qt::Unchecked);
106  ui->messageTextLabel->clear();
107  ui->messageTextLabel->hide();
108  ui->messageLabel->hide();
109  // clear UI elements for unauthenticated payment request
110  ui->payTo_is->clear();
111  ui->memoTextLabel_is->clear();
112  ui->payAmount_is->clear();
113  // clear UI elements for authenticated payment request
114  ui->payTo_s->clear();
115  ui->memoTextLabel_s->clear();
116  ui->payAmount_s->clear();
117 
118  // update the display unit, to not use the default ("BTC")
120 }
121 
123 {
124  ui->checkboxSubtractFeeFromAmount->setChecked(true);
125 }
126 
128 {
129  Q_EMIT removeEntry(this);
130 }
131 
133 {
134  Q_EMIT useAvailableBalance(this);
135 }
136 
138 {
139  if (!model)
140  return false;
141 
142  // Check input validity
143  bool retval = true;
144 
145  // Skip checks for payment request
147  return retval;
148 
149  if (!model->validateAddress(ui->payTo->text()))
150  {
151  ui->payTo->setValid(false);
152  retval = false;
153  }
154 
155  if (!ui->payAmount->validate())
156  {
157  retval = false;
158  }
159 
160  // Sending a zero amount is invalid
161  if (ui->payAmount->value(0) <= 0)
162  {
163  ui->payAmount->setValid(false);
164  retval = false;
165  }
166 
167  // Reject dust outputs:
168  if (retval && GUIUtil::isDust(ui->payTo->text(), ui->payAmount->value())) {
169  ui->payAmount->setValid(false);
170  retval = false;
171  }
172 
173  return retval;
174 }
175 
177 {
178  // Payment request
180  return recipient;
181 
182  // Normal payment
183  recipient.address = ui->payTo->text();
184  recipient.label = ui->addAsLabel->text();
185  recipient.amount = ui->payAmount->value();
186  recipient.message = ui->messageTextLabel->text();
187  recipient.fSubtractFeeFromAmount = (ui->checkboxSubtractFeeFromAmount->checkState() == Qt::Checked);
188 
189  return recipient;
190 }
191 
192 QWidget *SendCoinsEntry::setupTabChain(QWidget *prev)
193 {
194  QWidget::setTabOrder(prev, ui->payTo);
195  QWidget::setTabOrder(ui->payTo, ui->addAsLabel);
196  QWidget *w = ui->payAmount->setupTabChain(ui->addAsLabel);
197  QWidget::setTabOrder(w, ui->checkboxSubtractFeeFromAmount);
198  QWidget::setTabOrder(ui->checkboxSubtractFeeFromAmount, ui->addressBookButton);
199  QWidget::setTabOrder(ui->addressBookButton, ui->pasteButton);
200  QWidget::setTabOrder(ui->pasteButton, ui->deleteButton);
201  return ui->deleteButton;
202 }
203 
205 {
206  recipient = value;
207 
208  if (recipient.paymentRequest.IsInitialized()) // payment request
209  {
210  if (recipient.authenticatedMerchant.isEmpty()) // unauthenticated
211  {
212  ui->payTo_is->setText(recipient.address);
213  ui->memoTextLabel_is->setText(recipient.message);
214  ui->payAmount_is->setValue(recipient.amount);
215  ui->payAmount_is->setReadOnly(true);
216  setCurrentWidget(ui->SendCoins_UnauthenticatedPaymentRequest);
217  }
218  else // authenticated
219  {
220  ui->payTo_s->setText(recipient.authenticatedMerchant);
221  ui->memoTextLabel_s->setText(recipient.message);
222  ui->payAmount_s->setValue(recipient.amount);
223  ui->payAmount_s->setReadOnly(true);
224  setCurrentWidget(ui->SendCoins_AuthenticatedPaymentRequest);
225  }
226  }
227  else // normal payment
228  {
229  // message
230  ui->messageTextLabel->setText(recipient.message);
231  ui->messageTextLabel->setVisible(!recipient.message.isEmpty());
232  ui->messageLabel->setVisible(!recipient.message.isEmpty());
233 
234  ui->payTo->setText(recipient.address);
235  ui->addAsLabel->setText(recipient.label);
236  ui->payAmount->setValue(recipient.amount);
237  }
238 
240 }
241 
242 void SendCoinsEntry::setAddress(const QString &address)
243 {
244  ui->payTo->setText(address);
245  ui->payAmount->setFocus();
246 }
247 
249 {
250  ui->payAmount->setValue(amount);
251 }
252 
254 {
255  return ui->payTo->text().isEmpty() && ui->payTo_is->text().isEmpty() && ui->payTo_s->text().isEmpty();
256 }
257 
259 {
260  ui->payTo->setFocus();
261 }
262 
264 {
265  if(model && model->getOptionsModel())
266  {
267  // Update payAmount with the current unit
268  ui->payAmount->setDisplayUnit(model->getOptionsModel()->getDisplayUnit());
269  ui->payAmount_is->setDisplayUnit(model->getOptionsModel()->getDisplayUnit());
270  ui->payAmount_s->setDisplayUnit(model->getOptionsModel()->getDisplayUnit());
271  }
272 }
273 
275 {
276  QStackedWidget::changeEvent(e);
277  if (e->type() == QEvent::StyleChange) {
278  // Adjust button icon colors on theme changes
279  setButtonIcons();
280  }
281 }
282 
284 {
285  GUIUtil::setIcon(ui->addressBookButton, "address-book");
286  GUIUtil::setIcon(ui->pasteButton, "editpaste");
287  GUIUtil::setIcon(ui->deleteButton, "remove", GUIUtil::ThemedColor::RED);
288  GUIUtil::setIcon(ui->deleteButton_is, "remove", GUIUtil::ThemedColor::RED);
289  GUIUtil::setIcon(ui->deleteButton_s, "remove", GUIUtil::ThemedColor::RED);
290 }
291 
292 bool SendCoinsEntry::updateLabel(const QString &address)
293 {
294  if(!model)
295  return false;
296 
297  // Fill in label from address book, if address has an associated label
298  QString associatedLabel = model->getAddressTableModel()->labelForAddress(address);
299  if(!associatedLabel.isEmpty())
300  {
301  ui->addAsLabel->setText(associatedLabel);
302  return true;
303  }
304 
305  return false;
306 }
bool isDust(const QString &address, const CAmount &amount)
Definition: guiutil.cpp:473
Ui::SendCoinsEntry * ui
void setValue(const SendCoinsRecipient &value)
void payAmountChanged()
PaymentRequestPlus paymentRequest
Definition: walletmodel.h:58
void setFont(const std::vector< QWidget *> &vecWidgets, FontWeight weight, int nPointSize, bool fItalic)
Workaround to set correct font styles in all themes since there is a bug in macOS which leads to issu...
Definition: guiutil.cpp:1552
void setFocus()
SendCoinsRecipient getValue()
void setModel(AddressTableModel *model)
void setAddress(const QString &address)
~SendCoinsEntry()
bool updateLabel(const QString &address)
void deleteClicked()
void on_payTo_textChanged(const QString &address)
void setupAddressWidget(QValidatedLineEdit *widget, QWidget *parent, bool fAllowURI)
Definition: guiutil.cpp:286
Open address book to pick address.
AddressTableModel * getAddressTableModel()
bool parseBitcoinURI(const QUrl &uri, SendCoinsRecipient *out)
Definition: guiutil.cpp:358
void updateDisplayUnit()
bool validate()
A single entry in the dialog for sending bitcoins.
int getDisplayUnit() const
Definition: optionsmodel.h:82
QWidget * setupTabChain(QWidget *prev)
Set up the tab chain manually, as Qt messes up the tab chain by default in some cases (issue https://...
int64_t CAmount
Amount in satoshis (Can be negative)
Definition: amount.h:12
void updateFonts()
Update the font of all widgets where a custom font has been set with GUIUtil::setFont.
Definition: guiutil.cpp:1563
void clear()
QString labelForAddress(const QString &address) const
Widget that shows a list of sending or receiving addresses.
void removeEntry(SendCoinsEntry *entry)
void disableMacFocusRect(const QWidget *w)
Disable the OS default focus rect for macOS because we have custom focus rects set in the css files...
Definition: guiutil.cpp:1789
void checkSubtractFeeFromAmount()
bool isClear()
Return whether the entry is still empty and unedited.
bool validateAddress(const QString &address)
void subtractFeeFromAmountChanged()
void on_pasteButton_clicked()
void changeEvent(QEvent *e)
WalletModel * model
Interface to Bitcoin wallet from Qt view code.
Definition: walletmodel.h:100
SendCoinsRecipient recipient
void setAmount(const CAmount &amount)
void on_addressBookButton_clicked()
void setModel(WalletModel *model)
void setIcon(QAbstractButton *button, const QString &strIcon, const ThemedColor color, const ThemedColor colorAlternative, const QSize &size)
Helper to set an icon for a button with the given color (replaces black) and colorAlternative (replac...
Definition: guiutil.cpp:247
void useAvailableBalance(SendCoinsEntry *entry)
SendCoinsEntry(QWidget *parent=0)
bool fSubtractFeeFromAmount
Definition: walletmodel.h:62
void useAvailableBalanceClicked()
QString authenticatedMerchant
Definition: walletmodel.h:60
void setButtonIcons()
Set required icons for buttons inside the dialog.
OptionsModel * getOptionsModel()
const QString & getReturnValue() const
Released under the MIT license