PRCYCoin  2.0.0.7rc1
P2P Digital Currency
sendcoinsentry.cpp
Go to the documentation of this file.
1 // Copyright (c) 2011-2014 The Bitcoin developers
2 // Copyright (c) 2014-2015 The Dash developers
3 // Copyright (c) 2015-2018 The PIVX developers
4 // Copyright (c) 2018-2020 The DAPS Project developers
5 // Distributed under the MIT/X11 software license, see the accompanying
6 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
7 
8 #include "sendcoinsentry.h"
9 #include "ui_sendcoinsentry.h"
10 
11 #include "addressbookpage.h"
12 #include "addresstablemodel.h"
13 #include "bitcoinunits.h"
14 #include "guiutil.h"
15 #include "optionsmodel.h"
16 #include "walletmodel.h"
17 
18 #include <QApplication>
19 #include <QClipboard>
20 #include <QDoubleValidator>
21 
22 SendCoinsEntry::SendCoinsEntry(QWidget* parent) : QStackedWidget(parent),
23  ui(new Ui::SendCoinsEntry),
24  model(0)
25 {
26  ui->setupUi(this);
27 
28  setCurrentWidget(ui->SendCoins);
29 
30 
31 #ifdef Q_OS_MAC
32  ui->payToLayout_s->setSpacing(4);
33 #endif
34 
35  // normal prcycoin address field
36  GUIUtil::setupAddressWidget(ui->payTo, this);
37 
38  // Connect signals
39  connect(ui->deleteButton, SIGNAL(clicked()), this, SLOT(deleteClicked()));
40  connect(ui->deleteButton_is, SIGNAL(clicked()), this, SLOT(deleteClicked()));
41  connect(ui->deleteButton_s, SIGNAL(clicked()), this, SLOT(deleteClicked()));
42  // #HIDE multisend
43  ui->deleteButton->setVisible(false);
44 
45  //TODO-NOTE: Hide address book button
46  ui->addressBookButton->setVisible(false);
47 
48  QLocale lo(QLocale::C);
49  lo.setNumberOptions(QLocale::RejectGroupSeparator);
50  QDoubleValidator *dblVal = new QDoubleValidator(0, MAX_MONEY_OUT, 8, ui->payAmount);
51  dblVal->setNotation(QDoubleValidator::StandardNotation);
52  dblVal->setLocale(lo);
53  ui->payAmount->setValidator(dblVal);
54 }
55 
57 {
58  delete ui;
59 }
60 
61 /*void SendCoinsEntry::on_pasteButton_clicked()
62 {
63  // Paste text from clipboard into recipient field
64  ui->payTo->setText(QApplication::clipboard()->text());
65 }*/
66 
68 {
69  if (!model)
70  return;
73  if (dlg.exec()) {
74  ui->payTo->setText(dlg.getReturnValue());
75  ui->payAmount->setFocus();
76  }
77 }
78 
80 {
81  ui->payTo->clear();
82  ui->addAsLabel->clear();
83  ui->payAmount->clear();
84  ui->payTo->setStyleSheet(GUIUtil::loadStyleSheet());
85  ui->payAmount->setStyleSheet(GUIUtil::loadStyleSheet());
86 }
87 
88 void SendCoinsEntry::on_payTo_textChanged(const QString& address)
89 {
90  updateLabel(address);
91 }
92 
94 {
95  this->model = model;
96 
97  if (model && model->getOptionsModel())
98  connect(model->getOptionsModel(), SIGNAL(displayUnitChanged(int)), this, SLOT(updateDisplayUnit()));
99 
100  clear();
101 }
102 
104 {
105  // clear UI elements for normal payment
106  ui->payTo->clear();
107  ui->addAsLabel->clear();
108  ui->payAmount->clear();
109  // clear UI elements for insecure payment request
110  ui->payTo_is->clear();
111  ui->memoTextLabel_is->clear();
112  ui->payAmount_is->clear();
113  // clear UI elements for secure 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  Q_EMIT removeEntry(this);
125 }
126 
127 static inline int64_t roundint64(double d)
128 {
129  return (int64_t)(d > 0 ? d + 0.5 : d - 0.5);
130 }
131 
133  double dAmount = ui->payAmount->text().toDouble();
134  if (dAmount < 0.0 || dAmount > MAX_MONEY_OUT) {
135  QMessageBox msgBox;
136  msgBox.setWindowTitle("Invalid Amount");
137  msgBox.setText("Invalid amount entered. Please enter an amount less than 2.1B PRCY.");
138  msgBox.setStyleSheet(GUIUtil::loadStyleSheet());
139  msgBox.setIcon(QMessageBox::Warning);
140  msgBox.exec();
141  }
142  CAmount nAmount = roundint64(dAmount * COIN);
143  return nAmount;
144 }
145 
147 {
148  recipient.address = ui->payTo->text();
149  recipient.label = ui->addAsLabel->text();
151 
152  return recipient;
153 }
154 
155 QWidget* SendCoinsEntry::setupTabChain(QWidget* prev)
156 {
157  QWidget::setTabOrder(prev, ui->payTo);
158  QWidget::setTabOrder(ui->payTo, ui->addAsLabel);
159 
160  return ui->deleteButton;
161 }
162 
164 {
165  recipient = value;
166 
167  {
168  ui->addAsLabel->clear();
169  ui->payTo->setText(recipient.address); // this may set a label from addressbook
170  if (!recipient.label.isEmpty()) // if a label had been set from the addressbook, dont overwrite with an empty label
171  ui->addAsLabel->setText(recipient.label);
172  ui->payAmount->setText(QString::number((double)(recipient.amount) / (double)COIN, 'f', 3));
173  }
174 }
175 
176 void SendCoinsEntry::setAddress(const QString& address)
177 {
178  ui->payTo->setText(address);
179  ui->payAmount->setFocus();
180 }
181 
183 {
184  return ui->payTo->text().isEmpty() && ui->payTo_is->text().isEmpty() && ui->payTo_s->text().isEmpty();
185 }
186 
188 {
189  ui->payTo->setFocus();
190 }
191 
193 {
194  if (model && model->getOptionsModel()) {
195  // Update payAmount with the current unit
196  ui->payAmount_is->setDisplayUnit(model->getOptionsModel()->getDisplayUnit());
197  ui->payAmount_s->setDisplayUnit(model->getOptionsModel()->getDisplayUnit());
198  }
199 }
200 
201 bool SendCoinsEntry::updateLabel(const QString& address)
202 {
203  if (!model)
204  return false;
205 
206  // Fill in label from address book, if address has an associated label
207  QString associatedLabel = model->getAddressTableModel()->labelForAddress(address);
208  if (!associatedLabel.isEmpty()) {
209  ui->addAsLabel->setText(associatedLabel);
210  return true;
211  }
212 
213  return false;
214 }
215 
217  if (valid)
218  ui->payTo->setStyleSheet(GUIUtil::loadStyleSheet());
219  else ui->payTo->setStyleSheet("border-color: red;");
220 }
221 
223  if (valid)
224  ui->payAmount->setStyleSheet(GUIUtil::loadStyleSheet());
225  else ui->payAmount->setStyleSheet("border-color: red;");
226 }
227 
229 {
231 }
SendCoinsRecipient::amount
CAmount amount
Definition: walletmodel.h:61
WalletModel::getOptionsModel
OptionsModel * getOptionsModel()
Definition: walletmodel.cpp:358
SendCoinsEntry::setAddress
void setAddress(const QString &address)
Definition: sendcoinsentry.cpp:176
SendCoinsEntry::errorAddress
void errorAddress(bool valid)
Definition: sendcoinsentry.cpp:216
AddressBookPage::setModel
void setModel(AddressTableModel *model)
Definition: addressbookpage.cpp:110
AddressBookPage::SendingTab
@ SendingTab
Definition: addressbookpage.h:34
SendCoinsEntry::~SendCoinsEntry
~SendCoinsEntry()
Definition: sendcoinsentry.cpp:56
WalletModel
Interface to Bitcoin wallet from Qt view code.
Definition: walletmodel.h:102
SendCoinsEntry::setValue
void setValue(const SendCoinsRecipient &value)
Definition: sendcoinsentry.cpp:163
SendCoinsEntry::on_useAllSpendableButton_clicked
void on_useAllSpendableButton_clicked()
Definition: sendcoinsentry.cpp:228
addressbookpage.h
walletmodel.h
SendCoinsEntry::updateLabel
bool updateLabel(const QString &address)
Definition: sendcoinsentry.cpp:201
SendCoinsEntry::deleteClicked
void deleteClicked()
Definition: sendcoinsentry.cpp:122
WalletModel::getAddressTableModel
AddressTableModel * getAddressTableModel()
Definition: walletmodel.cpp:363
SendCoinsEntry::setFocus
void setFocus()
Definition: sendcoinsentry.cpp:187
AddressTableModel::labelForAddress
QString labelForAddress(const QString &address) const
Definition: addresstablemodel.cpp:400
SendCoinsRecipient::label
QString label
Definition: walletmodel.h:58
CWallet::GetSpendableBalance
CAmount GetSpendableBalance()
Definition: wallet.cpp:2260
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:155
SendCoinsEntry::ui
Ui::SendCoinsEntry * ui
Definition: sendcoinsentry.h:70
SendCoinsEntry::on_payTo_textChanged
void on_payTo_textChanged(const QString &address)
Definition: sendcoinsentry.cpp:88
SendCoinsEntry::getValidatedAmount
CAmount getValidatedAmount()
Definition: sendcoinsentry.cpp:132
OptionsModel::getDisplayUnit
int getDisplayUnit()
Definition: optionsmodel.h:60
SendCoinsEntry::clear
void clear()
Definition: sendcoinsentry.cpp:103
SendCoinsEntry::updateDisplayUnit
void updateDisplayUnit()
Definition: sendcoinsentry.cpp:192
SendCoinsRecipient
Definition: walletmodel.h:46
sendcoinsentry.h
BitcoinUnits::PRCY
@ PRCY
Definition: bitcoinunits.h:61
SendCoinsEntry::isClear
bool isClear()
Return whether the entry is still empty and unedited.
Definition: sendcoinsentry.cpp:182
CAmount
int64_t CAmount
Amount in PRCY (Can be negative)
Definition: amount.h:17
AddressBookPage
Widget that shows a list of sending or receiving addresses.
Definition: addressbookpage.h:28
SendCoinsEntry::on_clearAllButton_clicked
void on_clearAllButton_clicked()
Definition: sendcoinsentry.cpp:79
guiutil.h
SendCoinsEntry::model
WalletModel * model
Definition: sendcoinsentry.h:71
SendCoinsEntry::setModel
void setModel(WalletModel *model)
Definition: sendcoinsentry.cpp:93
BitcoinUnits::format
static QString format(int unit, const CAmount &amount, bool plussign=false, SeparatorStyle separators=separatorStandard)
Format as string.
Definition: bitcoinunits.cpp:140
Ui
Definition: 2faconfirmdialog.h:7
SendCoinsEntry::recipient
SendCoinsRecipient recipient
Definition: sendcoinsentry.h:69
SendCoinsRecipient::address
QString address
Definition: walletmodel.h:57
SendCoinsEntry::removeEntry
void removeEntry(SendCoinsEntry *entry)
bitcoinunits.h
SendCoinsEntry
A single entry in the dialog for sending bitcoins.
Definition: sendcoinsentry.h:25
SendCoinsEntry::on_addressBookButton_clicked
void on_addressBookButton_clicked()
Definition: sendcoinsentry.cpp:67
AddressBookPage::getReturnValue
const QString & getReturnValue() const
Definition: addressbookpage.h:47
optionsmodel.h
SendCoinsEntry::SendCoinsEntry
SendCoinsEntry(QWidget *parent=0)
Definition: sendcoinsentry.cpp:22
GUIUtil::loadStyleSheet
QString loadStyleSheet()
Load global CSS theme.
Definition: guiutil.cpp:721
GUIUtil::setupAddressWidget
void setupAddressWidget(QValidatedLineEdit *widget, QWidget *parent)
Definition: guiutil.cpp:86
pwalletMain
CWallet * pwalletMain
Definition: wallet.cpp:49
addresstablemodel.h
SendCoinsEntry::errorAmount
void errorAmount(bool valid)
Definition: sendcoinsentry.cpp:222
AddressBookPage::ForSelection
@ ForSelection
Open address book to pick address.
Definition: addressbookpage.h:39
SendCoinsEntry::getValue
SendCoinsRecipient getValue()
Definition: sendcoinsentry.cpp:146
BitcoinUnits::separatorNever
@ separatorNever
Definition: bitcoinunits.h:67