Fabcoin Core  0.16.2
P2P Digital Currency
receivecoinsdialog.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 <receivecoinsdialog.h>
7 
8 #include <addressbookpage.h>
9 #include <addresstablemodel.h>
10 #include <fabcoinunits.h>
11 #include <guiutil.h>
12 #include <optionsmodel.h>
13 #include <platformstyle.h>
14 #include <receiverequestdialog.h>
16 #include <walletmodel.h>
17 #include <styleSheet.h>
18 
19 #include <QAction>
20 #include <QCursor>
21 #include <QItemSelection>
22 #include <QMessageBox>
23 #include <QScrollBar>
24 #include <QTextDocument>
25 
26 ReceiveCoinsDialog::ReceiveCoinsDialog(const PlatformStyle *_platformStyle, QWidget *parent) :
27  QDialog(parent),
28  ui(new Ui::ReceiveCoinsDialog),
29  columnResizingFixer(0),
30  model(0),
31  platformStyle(_platformStyle)
32 {
33  ui->setupUi(this);
34 
35  // Set stylesheet
36  SetObjectStyleSheet(ui->clearButton, StyleSheetNames::ButtonBlack);
37  SetObjectStyleSheet(ui->showRequestButton, StyleSheetNames::ButtonTransparentBordered);
38  SetObjectStyleSheet(ui->removeRequestButton, StyleSheetNames::ButtonTransparentBordered);
39 
40  if (!_platformStyle->getImagesOnButtons()) {
41  ui->clearButton->setIcon(QIcon());
42  ui->receiveButton->setIcon(QIcon());
43  ui->showRequestButton->setIcon(QIcon());
44  ui->removeRequestButton->setIcon(QIcon());
45  } else {
46  ui->clearButton->setIcon(_platformStyle->MultiStatesIcon(":/icons/remove", PlatformStyle::PushButton));
47  ui->receiveButton->setIcon(_platformStyle->MultiStatesIcon(":/icons/request_payment", PlatformStyle::PushButton));
48  ui->showRequestButton->setIcon(_platformStyle->MultiStatesIcon(":/icons/show", PlatformStyle::PushButton));
49  ui->removeRequestButton->setIcon(_platformStyle->MultiStatesIcon(":/icons/remove", PlatformStyle::PushButton));
50  }
51 
53  ui->copyAddressButton->setEnabled(false);
54  ui->refreshButton->setIcon(platformStyle->MultiStatesIcon(":/movies/spinner-010", PlatformStyle::PushButton));
55  ui->refreshButton->setVisible(false);
56  ui->leAddress->setReadOnly(true);
57 
59 
60  // context menu actions
61  QAction *copyURIAction = new QAction(tr("Copy URI"), this);
62  QAction *copyLabelAction = new QAction(tr("Copy label"), this);
63  QAction *copyMessageAction = new QAction(tr("Copy message"), this);
64  QAction *copyAmountAction = new QAction(tr("Copy amount"), this);
65 
66  // context menu
67  contextMenu = new QMenu(this);
68  contextMenu->addAction(copyURIAction);
69  contextMenu->addAction(copyLabelAction);
70  contextMenu->addAction(copyMessageAction);
71  contextMenu->addAction(copyAmountAction);
72 
73  // context menu signals
74  connect(ui->recentRequestsView, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(showMenu(QPoint)));
75  connect(copyURIAction, SIGNAL(triggered()), this, SLOT(copyURI()));
76  connect(copyLabelAction, SIGNAL(triggered()), this, SLOT(copyLabel()));
77  connect(copyMessageAction, SIGNAL(triggered()), this, SLOT(copyMessage()));
78  connect(copyAmountAction, SIGNAL(triggered()), this, SLOT(copyAmount()));
79 
80  connect(ui->clearButton, SIGNAL(clicked()), this, SLOT(clear()));
81 }
82 
84 {
85  this->model = _model;
86 
87  if(_model && _model->getOptionsModel())
88  {
89  _model->getRecentRequestsTableModel()->sort(RecentRequestsTableModel::Date, Qt::DescendingOrder);
90  connect(_model->getOptionsModel(), SIGNAL(displayUnitChanged(int)), this, SLOT(updateDisplayUnit()));
92 
93  QTableView* tableView = ui->recentRequestsView;
94 
95  tableView->verticalHeader()->hide();
96  tableView->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
97  tableView->setModel(_model->getRecentRequestsTableModel());
98  tableView->setAlternatingRowColors(true);
99  tableView->setSelectionBehavior(QAbstractItemView::SelectRows);
100  tableView->setSelectionMode(QAbstractItemView::ContiguousSelection);
101  tableView->setColumnWidth(RecentRequestsTableModel::Date, DATE_COLUMN_WIDTH);
102  tableView->setColumnWidth(RecentRequestsTableModel::Label, LABEL_COLUMN_WIDTH);
104 
105  connect(tableView->selectionModel(),
106  SIGNAL(selectionChanged(QItemSelection, QItemSelection)), this,
107  SLOT(recentRequestsView_selectionChanged(QItemSelection, QItemSelection)));
108  // Last 2 columns are set by the columnResizingFixer, when the table geometry is ready.
110  }
111 }
112 
114 {
115  delete ui;
116 }
117 
119 {
120  ui->reqAmount->clear();
121  ui->reqLabel->setText("");
122  ui->reqMessage->setText("");
123  ui->reuseAddress->setChecked(false);
124  ui->leAddress->setText("");
125  ui->copyAddressButton->setEnabled(false);
126  QPixmap emptyPixmap;
127  ui->lblQRCode->setPixmap(emptyPixmap);
128  ui->lblQRCode->setText("");
130 }
131 
133 {
134  clear();
135 }
136 
138 {
139  clear();
140 }
141 
143 {
144  if(model && model->getOptionsModel())
145  {
147  }
148 }
149 
151 {
153  return;
154 
155  QString address;
156  QString label = ui->reqLabel->text();
157  if(ui->reuseAddress->isChecked())
158  {
159  /* Use selected address*/
160  if(ui->leAddress->text() != "")
161  {
162  address = ui->leAddress->text();
163  } else {
164  /* Choose existing receiving address */
167  if(dlg.exec())
168  {
169  address = dlg.getReturnValue();
170  if(label.isEmpty()) /* If no label provided, use the previously used label */
171  {
172  label = model->getAddressTableModel()->labelForAddress(address);
173  }
174  } else {
175  return;
176  }
177  }
178  } else {
179  /* Generate new receiving address */
181  }
182  SendCoinsRecipient info(address, label,
183  ui->reqAmount->value(), ui->reqMessage->text());
184  ReceiveRequestDialog *dialog = new ReceiveRequestDialog(this);
185  dialog->setAttribute(Qt::WA_DeleteOnClose);
186  dialog->setModel(model->getOptionsModel());
187  dialog->setInfo(info);
188  dialog->show();
189  clear();
190 
191  /* Store request for later reference */
193 }
194 
196 {
198  ReceiveRequestDialog *dialog = new ReceiveRequestDialog(this);
199  dialog->setModel(model->getOptionsModel());
200  dialog->setInfo(submodel->entry(index.row()).recipient);
201  dialog->setAttribute(Qt::WA_DeleteOnClose);
202  dialog->show();
203 }
204 
206 {
208  SendCoinsRecipient info = submodel->entry(index.row()).recipient;
209 
210  ui->leAddress->setText(info.address);
211  ui->reqLabel->setText(info.label);
212  ui->reqMessage->setText(info.message);
213  ui->reqAmount->setValue(info.amount);
214 
216  {
217  ui->lblQRCode->setScaledContents(true);
218  }
219 
220  ui->copyAddressButton->setEnabled(true);
221 }
222 
223 void ReceiveCoinsDialog::recentRequestsView_selectionChanged(const QItemSelection &selected, const QItemSelection &deselected)
224 {
225  // Enable Show/Remove buttons only if anything is selected.
226  bool enable = !ui->recentRequestsView->selectionModel()->selectedRows().isEmpty();
227  ui->showRequestButton->setEnabled(enable);
228  ui->removeRequestButton->setEnabled(enable);
229 }
230 
232 {
233  if(!model || !model->getRecentRequestsTableModel() || !ui->recentRequestsView->selectionModel())
234  return;
235  QModelIndexList selection = ui->recentRequestsView->selectionModel()->selectedRows();
236 
237  for (const QModelIndex& index : selection) {
239  }
240 }
241 
243 {
244  if(!model || !model->getRecentRequestsTableModel() || !ui->recentRequestsView->selectionModel())
245  return;
246  QModelIndexList selection = ui->recentRequestsView->selectionModel()->selectedRows();
247  if(selection.empty())
248  return;
249  // correct for selection mode ContiguousSelection
250  QModelIndex firstIndex = selection.at(0);
251  model->getRecentRequestsTableModel()->removeRows(firstIndex.row(), selection.length(), firstIndex.parent());
252 }
253 
255 {
257 }
258 
259 // We override the virtual resizeEvent of the QWidget to adjust tables column
260 // sizes as the tables width is proportional to the dialogs width.
261 void ReceiveCoinsDialog::resizeEvent(QResizeEvent *event)
262 {
263  QWidget::resizeEvent(event);
265 }
266 
267 void ReceiveCoinsDialog::keyPressEvent(QKeyEvent *event)
268 {
269  if (event->key() == Qt::Key_Return)
270  {
271  // press return -> submit form
272  if (ui->reqLabel->hasFocus() || ui->reqAmount->hasFocus() || ui->reqMessage->hasFocus())
273  {
274  event->ignore();
276  return;
277  }
278  }
279 
280  this->QDialog::keyPressEvent(event);
281 }
282 
284 {
285  if(!model || !model->getRecentRequestsTableModel() || !ui->recentRequestsView->selectionModel())
286  return QModelIndex();
287  QModelIndexList selection = ui->recentRequestsView->selectionModel()->selectedRows();
288  if(selection.empty())
289  return QModelIndex();
290  // correct for selection mode ContiguousSelection
291  QModelIndex firstIndex = selection.at(0);
292  return firstIndex;
293 }
294 
295 // copy column of selected row to clipboard
297 {
298  QModelIndex firstIndex = selectedRow();
299  if (!firstIndex.isValid()) {
300  return;
301  }
302  GUIUtil::setClipboard(model->getRecentRequestsTableModel()->data(firstIndex.child(firstIndex.row(), column), Qt::EditRole).toString());
303 }
304 
305 // context menu
306 void ReceiveCoinsDialog::showMenu(const QPoint &point)
307 {
308  if (!selectedRow().isValid()) {
309  return;
310  }
311  contextMenu->exec(QCursor::pos());
312 }
313 
314 // context menu action: copy URI
316 {
317  QModelIndex sel = selectedRow();
318  if (!sel.isValid()) {
319  return;
320  }
321 
322  const RecentRequestsTableModel * const submodel = model->getRecentRequestsTableModel();
323  const QString uri = GUIUtil::formatFabcoinURI(submodel->entry(sel.row()).recipient);
325 }
326 
327 // context menu action: copy label
329 {
331 }
332 
333 // context menu action: copy message
335 {
337 }
338 
339 // context menu action: copy amount
341 {
343 }
Model for list of recently generated payment requests / fabcoin: URIs.
void addNewRequest(const SendCoinsRecipient &recipient)
void sort(int column, Qt::SortOrder order=Qt::AscendingOrder)
Dialog for requesting payment of fabcoins.
#define SetObjectStyleSheet(object, name)
Definition: styleSheet.h:10
bool removeRows(int row, int count, const QModelIndex &parent=QModelIndex())
void recentRequestsView_selectionChanged(const QItemSelection &selected, const QItemSelection &deselected)
void setModel(AddressTableModel *model)
const QString & getReturnValue() const
GUIUtil::TableViewLastColumnResizingFixer * columnResizingFixer
ReceiveCoinsDialog(const PlatformStyle *platformStyle, QWidget *parent=0)
FabcoinAmountField * reqAmount
Open address book to pick address.
AddressTableModel * getAddressTableModel()
Ui::ReceiveCoinsDialog * ui
const RecentRequestEntry & entry(int row) const
void setModel(WalletModel *model)
void copyColumnToClipboard(int column)
QVariant data(const QModelIndex &index, int role) const
void setClipboard(const QString &str)
Definition: guiutil.cpp:858
void on_recentRequestsView_doubleClicked(const QModelIndex &index)
void setInfo(const SendCoinsRecipient &info)
Makes a QTableView last column feel as if it was being resized from its left border.
Definition: guiutil.h:158
virtual void keyPressEvent(QKeyEvent *event)
int getDisplayUnit()
Definition: optionsmodel.h:70
Widget that shows a list of sending or receiving addresses.
static bool createQRCode(QLabel *label, SendCoinsRecipient info, bool showAddress=false)
void on_recentRequestsView_clicked(const QModelIndex &index)
virtual void resizeEvent(QResizeEvent *event)
QString addRow(const QString &type, const QString &label, const QString &address)
void setValue(const CAmount &value)
RecentRequestsTableModel * getRecentRequestsTableModel()
QString formatFabcoinURI(const SendCoinsRecipient &info)
Definition: guiutil.cpp:222
QString labelForAddress(const QString &address) const
QIcon MultiStatesIcon(const QString &resourcename, StateType type=NavBar, QColor color=Qt::white, QColor colorAlt=0x2d2d2d) const
Get multi-states icon.
Interface to Fabcoin wallet from Qt view code.
Definition: walletmodel.h:103
void setupUi(QWidget *ReceiveCoinsDialog)
static const QString Receive
Specifies receive address.
const PlatformStyle * platformStyle
void showMenu(const QPoint &point)
bool getImagesOnButtons() const
Definition: platformstyle.h:21
struct evm_uint160be address(struct evm_env *env)
Definition: capi.c:13
void setModel(OptionsModel *model)
void formatToolButtons(QToolButton *btn1, QToolButton *btn2, QToolButton *btn3)
Definition: guiutil.cpp:989
void setDisplayUnit(int unit)
Change unit used to display amount.
void clear()
Make field empty and ready for new input.
OptionsModel * getOptionsModel()