Fabcoin Core  0.16.2
P2P Digital Currency
sendcoinsentry.cpp
Go to the documentation of this file.
1 // Copyright (c) 2011-2017 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 <sendcoinsentry.h>
6 #include <ui_sendcoinsentry.h>
7 
8 #include <addressbookpage.h>
9 #include <addresstablemodel.h>
10 #include <guiutil.h>
11 #include <optionsmodel.h>
12 #include <platformstyle.h>
13 #include <walletmodel.h>
14 
15 #include <QApplication>
16 #include <QClipboard>
17 
18 SendCoinsEntry::SendCoinsEntry(const PlatformStyle *_platformStyle, QWidget *parent) :
19  QStackedWidget(parent),
20  ui(new Ui::SendCoinsEntry),
21  model(0),
22  platformStyle(_platformStyle)
23 {
24  ui->setupUi(this);
25 
26  ui->addressBookButton->setIcon(platformStyle->MultiStatesIcon(":/icons/address-book", PlatformStyle::PushButton));
27  ui->pasteButton->setIcon(platformStyle->MultiStatesIcon(":/icons/editpaste", PlatformStyle::PushButton));
28  ui->deleteButton->setIcon(platformStyle->MultiStatesIcon(":/icons/remove_entry", PlatformStyle::PushButton));
31 
32  setCurrentWidget(ui->SendCoins);
33 
35  ui->payToLayout->setSpacing(4);
36 #if QT_VERSION >= 0x040700
37  ui->addAsLabel->setPlaceholderText(tr("Enter a label for this address to add it to your address book"));
38 #endif
39 
40  // normal fabcoin address field
42  // just a label for displaying fabcoin address(es)
43  ui->payTo_is->setFont(GUIUtil::fixedPitchFont());
44  // format tool buttons
46 
47  // Connect signals
48  connect(ui->payAmount, SIGNAL(valueChanged()), this, SIGNAL(payAmountChanged()));
49  connect(ui->checkboxSubtractFeeFromAmount, SIGNAL(toggled(bool)), this, SIGNAL(subtractFeeFromAmountChanged()));
50  connect(ui->deleteButton, SIGNAL(clicked()), this, SLOT(deleteClicked()));
51  connect(ui->deleteButton_is, SIGNAL(clicked()), this, SLOT(deleteClicked()));
52  connect(ui->deleteButton_s, SIGNAL(clicked()), this, SLOT(deleteClicked()));
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 
80 {
81  updateLabel(address);
82 }
83 
85 {
86  this->model = _model;
87 
88  if (_model && _model->getOptionsModel())
89  connect(_model->getOptionsModel(), SIGNAL(displayUnitChanged(int)), this, SLOT(updateDisplayUnit()));
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  ui->checkboxSubtractFeeFromAmount->setCheckState(Qt::Unchecked);
101  ui->messageTextLabel->clear();
102  ui->messageTextLabel->hide();
103  ui->messageLabel->hide();
104  // clear UI elements for unauthenticated payment request
105  ui->payTo_is->clear();
106  ui->memoTextLabel_is->clear();
107  ui->payAmount_is->clear();
108  // clear UI elements for authenticated payment request
109  ui->payTo_s->clear();
110  ui->memoTextLabel_s->clear();
111  ui->payAmount_s->clear();
112 
113  // update the display unit, to not use the default ("FAB")
115 }
116 
118 {
119  Q_EMIT removeEntry(this);
120 }
121 
123 {
124  if (!model)
125  return false;
126 
127  // Check input validity
128  bool retval = true;
129 
130  // Skip checks for payment request
132  return retval;
133 
134  if (!model->validateAddress(ui->payTo->text()))
135  {
136  ui->payTo->setValid(false);
137  retval = false;
138  }
139 
140  if (!ui->payAmount->validate())
141  {
142  retval = false;
143  }
144 
145  // Sending a zero amount is invalid
146  if (ui->payAmount->value(0) <= 0)
147  {
148  ui->payAmount->setValid(false);
149  retval = false;
150  }
151 
152  // Reject dust outputs:
153  if (retval && GUIUtil::isDust(ui->payTo->text(), ui->payAmount->value())) {
154  ui->payAmount->setValid(false);
155  retval = false;
156  }
157 
158  return retval;
159 }
160 
162 {
163  // Payment request
165  return recipient;
166 
167  // Normal payment
168  recipient.address = ui->payTo->text();
169  recipient.label = ui->addAsLabel->text();
172  recipient.fSubtractFeeFromAmount = (ui->checkboxSubtractFeeFromAmount->checkState() == Qt::Checked);
173 
174  return recipient;
175 }
176 
177 QWidget *SendCoinsEntry::setupTabChain(QWidget *prev)
178 {
179  QWidget::setTabOrder(prev, ui->payTo);
180  QWidget::setTabOrder(ui->payTo, ui->addAsLabel);
181  QWidget *w = ui->payAmount->setupTabChain(ui->addAsLabel);
182  QWidget::setTabOrder(w, ui->checkboxSubtractFeeFromAmount);
183  QWidget::setTabOrder(ui->checkboxSubtractFeeFromAmount, ui->addressBookButton);
184  QWidget::setTabOrder(ui->addressBookButton, ui->pasteButton);
185  QWidget::setTabOrder(ui->pasteButton, ui->deleteButton);
186  return ui->deleteButton;
187 }
188 
190 {
191  recipient = value;
192 
193  if (recipient.paymentRequest.IsInitialized()) // payment request
194  {
195  if (recipient.authenticatedMerchant.isEmpty()) // unauthenticated
196  {
197  ui->payTo_is->setText(recipient.address);
200  ui->payAmount_is->setReadOnly(true);
201  setCurrentWidget(ui->SendCoins_UnauthenticatedPaymentRequest);
202  }
203  else // authenticated
204  {
206  ui->memoTextLabel_s->setText(recipient.message);
208  ui->payAmount_s->setReadOnly(true);
209  setCurrentWidget(ui->SendCoins_AuthenticatedPaymentRequest);
210  }
211  }
212  else // normal payment
213  {
214  // message
216  ui->messageTextLabel->setVisible(!recipient.message.isEmpty());
217  ui->messageLabel->setVisible(!recipient.message.isEmpty());
218 
219  ui->addAsLabel->clear();
220  ui->payTo->setText(recipient.address); // this may set a label from addressbook
221  if (!recipient.label.isEmpty()) // if a label had been set from the addressbook, don't overwrite with an empty label
222  ui->addAsLabel->setText(recipient.label);
224  }
225 }
226 
228 {
229  ui->payTo->setText(address);
230  ui->payAmount->setFocus();
231 }
232 
234 {
235  return ui->payTo->text().isEmpty() && ui->payTo_is->text().isEmpty() && ui->payTo_s->text().isEmpty();
236 }
237 
239 {
240  ui->payTo->setFocus();
241 }
242 
244 {
245  if(model && model->getOptionsModel())
246  {
247  // Update payAmount with the current unit
251  }
252 }
253 
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 }
FabcoinAmountField * payAmount_s
bool isDust(const QString &address, const CAmount &amount)
Definition: guiutil.cpp:250
QHBoxLayout * payToLayout
QLineEdit * addAsLabel
Ui::SendCoinsEntry * ui
void setValue(const SendCoinsRecipient &value)
void payAmountChanged()
QFont fixedPitchFont()
Definition: guiutil.cpp:90
PaymentRequestPlus paymentRequest
Definition: walletmodel.h:61
bool IsInitialized() const
QLabel * messageLabel
QToolButton * deleteButton
QLabel * memoTextLabel_is
QLabel * payTo_is
QLabel * messageTextLabel
void setFocus()
SendCoinsRecipient getValue()
QValidatedLineEdit * payTo
void setModel(AddressTableModel *model)
bool validate()
Perform input validation, mark field as invalid if entered value is not valid.
const QString & getReturnValue() const
void setAddress(const QString &address)
~SendCoinsEntry()
bool updateLabel(const QString &address)
void deleteClicked()
void on_payTo_textChanged(const QString &address)
QToolButton * deleteButton_s
void setReadOnly(bool fReadOnly)
Make read-only.
Open address book to pick address.
AddressTableModel * getAddressTableModel()
void updateDisplayUnit()
bool validate()
A single entry in the dialog for sending fabcoins.
QFrame * SendCoins_UnauthenticatedPaymentRequest
QLabel * memoTextLabel_s
QWidget * setupTabChain(QWidget *prev)
Set up the tab chain manually, as Qt messes up the tab chain by default in some cases (issue https://...
void clear()
void setupAddressWidget(QValidatedLineEdit *widget, QWidget *parent)
Definition: guiutil.cpp:122
QToolButton * deleteButton_is
void setupUi(QStackedWidget *SendCoinsEntry)
void setValid(bool valid)
Mark current value as invalid in UI.
FabcoinAmountField * payAmount_is
int getDisplayUnit()
Definition: optionsmodel.h:70
Widget that shows a list of sending or receiving addresses.
void removeEntry(SendCoinsEntry *entry)
bool isClear()
Return whether the entry is still empty and unedited.
bool validateAddress(const QString &address)
QLabel * payTo_s
QToolButton * pasteButton
void subtractFeeFromAmountChanged()
void setValue(const CAmount &value)
void on_pasteButton_clicked()
QFrame * SendCoins_AuthenticatedPaymentRequest
QString labelForAddress(const QString &address) const
WalletModel * model
QIcon MultiStatesIcon(const QString &resourcename, StateType type=NavBar, QColor color=Qt::white, QColor colorAlt=0x2d2d2d) const
Get multi-states icon.
QFrame * SendCoins
Interface to Fabcoin wallet from Qt view code.
Definition: walletmodel.h:103
SendCoinsRecipient recipient
void on_addressBookButton_clicked()
void setModel(WalletModel *model)
FabcoinAmountField * payAmount
QCheckBox * checkboxSubtractFeeFromAmount
QWidget * setupTabChain(QWidget *prev)
Qt messes up the tab chain by default in some cases (issue https://bugreports.qt-project.org/browse/QTBUG-10907), in these cases we have to set it up manually.
SendCoinsEntry(const PlatformStyle *platformStyle, QWidget *parent=0)
QToolButton * addressBookButton
bool fSubtractFeeFromAmount
Definition: walletmodel.h:65
struct evm_uint160be address(struct evm_env *env)
Definition: capi.c:13
void formatToolButtons(QToolButton *btn1, QToolButton *btn2, QToolButton *btn3)
Definition: guiutil.cpp:989
bool getUseExtraSpacing() const
Definition: platformstyle.h:22
const PlatformStyle * platformStyle
void setDisplayUnit(int unit)
Change unit used to display amount.
QString authenticatedMerchant
Definition: walletmodel.h:63
void clear()
Make field empty and ready for new input.
void setValid(bool valid)
OptionsModel * getOptionsModel()