Raven Core  3.0.0
P2P Digital Currency
receivecoinsdialog.cpp
Go to the documentation of this file.
1 // Copyright (c) 2011-2016 The Bitcoin Core developers
2 // Copyright (c) 2017-2019 The Raven 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 "receivecoinsdialog.h"
7 #include "ui_receivecoinsdialog.h"
8 
9 #include "addressbookpage.h"
10 #include "addresstablemodel.h"
11 #include "ravenunits.h"
12 #include "guiutil.h"
13 #include "optionsmodel.h"
14 #include "platformstyle.h"
15 #include "receiverequestdialog.h"
17 #include "walletmodel.h"
18 #include "guiconstants.h"
19 
20 #include <QAction>
21 #include <QCursor>
22 #include <QItemSelection>
23 #include <QMessageBox>
24 #include <QScrollBar>
25 #include <QTextDocument>
26 #include <QGraphicsDropShadowEffect>
27 
28 ReceiveCoinsDialog::ReceiveCoinsDialog(const PlatformStyle *_platformStyle, QWidget *parent) :
29  QDialog(parent),
30  ui(new Ui::ReceiveCoinsDialog),
31  columnResizingFixer(0),
32  model(0),
33  platformStyle(_platformStyle)
34 {
35  ui->setupUi(this);
36 
37  if (!_platformStyle->getImagesOnButtons()) {
38  ui->clearButton->setIcon(QIcon());
39  ui->receiveButton->setIcon(QIcon());
40  ui->showRequestButton->setIcon(QIcon());
41  ui->removeRequestButton->setIcon(QIcon());
42  } else {
43  ui->clearButton->setIcon(_platformStyle->SingleColorIcon(":/icons/remove"));
44  ui->receiveButton->setIcon(_platformStyle->SingleColorIcon(":/icons/receiving_addresses"));
45  ui->showRequestButton->setIcon(_platformStyle->SingleColorIcon(":/icons/edit"));
46  ui->removeRequestButton->setIcon(_platformStyle->SingleColorIcon(":/icons/remove"));
47  }
48 
49  // context menu actions
50  QAction *copyURIAction = new QAction(tr("Copy URI"), this);
51  QAction *copyLabelAction = new QAction(tr("Copy label"), this);
52  QAction *copyMessageAction = new QAction(tr("Copy message"), this);
53  QAction *copyAmountAction = new QAction(tr("Copy amount"), this);
54 
55  // context menu
56  contextMenu = new QMenu(this);
57  contextMenu->addAction(copyURIAction);
58  contextMenu->addAction(copyLabelAction);
59  contextMenu->addAction(copyMessageAction);
60  contextMenu->addAction(copyAmountAction);
61 
62  // context menu signals
63  connect(ui->recentRequestsView, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(showMenu(QPoint)));
64  connect(copyURIAction, SIGNAL(triggered()), this, SLOT(copyURI()));
65  connect(copyLabelAction, SIGNAL(triggered()), this, SLOT(copyLabel()));
66  connect(copyMessageAction, SIGNAL(triggered()), this, SLOT(copyMessage()));
67  connect(copyAmountAction, SIGNAL(triggered()), this, SLOT(copyAmount()));
68 
69  connect(ui->clearButton, SIGNAL(clicked()), this, SLOT(clear()));
70 
73 }
74 
76 {
77  this->model = _model;
78 
79  if(_model && _model->getOptionsModel())
80  {
81  _model->getRecentRequestsTableModel()->sort(RecentRequestsTableModel::Date, Qt::DescendingOrder);
82  connect(_model->getOptionsModel(), SIGNAL(displayUnitChanged(int)), this, SLOT(updateDisplayUnit()));
84 
85  QTableView* tableView = ui->recentRequestsView;
86 
87  tableView->verticalHeader()->hide();
88  tableView->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
89  tableView->setModel(_model->getRecentRequestsTableModel());
90  tableView->setAlternatingRowColors(true);
91  tableView->setSelectionBehavior(QAbstractItemView::SelectRows);
92  tableView->setSelectionMode(QAbstractItemView::ContiguousSelection);
93  tableView->setColumnWidth(RecentRequestsTableModel::Date, DATE_COLUMN_WIDTH);
94  tableView->setColumnWidth(RecentRequestsTableModel::Label, LABEL_COLUMN_WIDTH);
96 
97  connect(tableView->selectionModel(),
98  SIGNAL(selectionChanged(QItemSelection, QItemSelection)), this,
99  SLOT(recentRequestsView_selectionChanged(QItemSelection, QItemSelection)));
100  // Last 2 columns are set by the columnResizingFixer, when the table geometry is ready.
102 
103  tableView->show();
104  }
105 }
106 
108 {
109  delete ui;
110 }
111 
113 {
114  ui->reqAmount->clear();
115  ui->reqLabel->setText("");
116  ui->reqMessage->setText("");
117  ui->reuseAddress->setChecked(false);
119 }
120 
122 {
123  clear();
124 }
125 
127 {
128  clear();
129 }
130 
132 {
134  ui->frame2->setStyleSheet(QString(".QFrame {background-color: %1; border: none;}").arg(platformStyle->WidgetBackGroundColor().name()));
137  ui->frame2->setGraphicsEffect(GUIUtil::getShadowEffect());
138 
139  ui->label_5->setStyleSheet(STRING_LABEL_COLOR);
140 
141  ui->label_2->setStyleSheet(STRING_LABEL_COLOR);
142  ui->label_2->setFont(GUIUtil::getSubLabelFont());
143 
144  ui->label->setStyleSheet(STRING_LABEL_COLOR);
145  ui->label->setFont(GUIUtil::getSubLabelFont());
146 
147  ui->label_3->setStyleSheet(STRING_LABEL_COLOR);
148  ui->label_3->setFont(GUIUtil::getSubLabelFont());
149 
150  ui->label_4->setStyleSheet(STRING_LABEL_COLOR);
151  ui->label_4->setFont(GUIUtil::getSubLabelFont());
152 
153  ui->label_7->setStyleSheet(STRING_LABEL_COLOR);
154  ui->label_7->setFont(GUIUtil::getSubLabelFont());
155 
156  ui->reuseAddress->setStyleSheet(QString(".QCheckBox{ %1; }").arg(STRING_LABEL_COLOR));
157  ui->reqLabel->setFont(GUIUtil::getSubLabelFont());
158  ui->reqAmount->setFont(GUIUtil::getSubLabelFont());
159  ui->reqMessage->setFont(GUIUtil::getSubLabelFont());
160  ui->receiveButton->setFont(GUIUtil::getSubLabelFont());
161  ui->clearButton->setFont(GUIUtil::getSubLabelFont());
162  ui->recentRequestsView->setFont(GUIUtil::getSubLabelFont());
163  ui->showRequestButton->setFont(GUIUtil::getSubLabelFont());
164  ui->removeRequestButton->setFont(GUIUtil::getSubLabelFont());
165  ui->label_5->setFont(GUIUtil::getSubLabelFont());
166 
167  ui->label_6->setFont(GUIUtil::getSubLabelFontBolded());
168 }
169 
171 {
173  ui->frame->setStyleSheet(QString(".QFrame {background-color: %1; border: none;}").arg(platformStyle->WidgetBackGroundColor().name()));
176  ui->frame->setGraphicsEffect(GUIUtil::getShadowEffect());
177 
178  ui->label_6->setStyleSheet(STRING_LABEL_COLOR);
179 
181 
182 }
183 
185 {
186  if(model && model->getOptionsModel())
187  {
188  ui->reqAmount->setDisplayUnit(model->getOptionsModel()->getDisplayUnit());
189  }
190 }
191 
193 {
195  return;
196 
197  QString address;
198  QString label = ui->reqLabel->text();
199  if(ui->reuseAddress->isChecked())
200  {
201  /* Choose existing receiving address */
204  if(dlg.exec())
205  {
206  address = dlg.getReturnValue();
207  if(label.isEmpty()) /* If no label provided, use the previously used label */
208  {
209  label = model->getAddressTableModel()->labelForAddress(address);
210  }
211  } else {
212  return;
213  }
214  } else {
215  /* Generate new receiving address */
217  }
218  SendCoinsRecipient info(address, label,
219  ui->reqAmount->value(), ui->reqMessage->text());
220  ReceiveRequestDialog *dialog = new ReceiveRequestDialog(this);
221  dialog->setAttribute(Qt::WA_DeleteOnClose);
222  dialog->setModel(model->getOptionsModel());
223  dialog->setInfo(info);
224  dialog->show();
225  clear();
226 
227  /* Store request for later reference */
229 }
230 
232 {
234  ReceiveRequestDialog *dialog = new ReceiveRequestDialog(this);
235  dialog->setModel(model->getOptionsModel());
236  dialog->setInfo(submodel->entry(index.row()).recipient);
237  dialog->setAttribute(Qt::WA_DeleteOnClose);
238  dialog->show();
239 }
240 
241 void ReceiveCoinsDialog::recentRequestsView_selectionChanged(const QItemSelection &selected, const QItemSelection &deselected)
242 {
243  // Enable Show/Remove buttons only if anything is selected.
244  bool enable = !ui->recentRequestsView->selectionModel()->selectedRows().isEmpty();
245  ui->showRequestButton->setEnabled(enable);
246  ui->removeRequestButton->setEnabled(enable);
247 }
248 
250 {
251  if(!model || !model->getRecentRequestsTableModel() || !ui->recentRequestsView->selectionModel())
252  return;
253  QModelIndexList selection = ui->recentRequestsView->selectionModel()->selectedRows();
254 
255  for (const QModelIndex& index : selection) {
257  }
258 }
259 
261 {
262  if(!model || !model->getRecentRequestsTableModel() || !ui->recentRequestsView->selectionModel())
263  return;
264  QModelIndexList selection = ui->recentRequestsView->selectionModel()->selectedRows();
265  if(selection.empty())
266  return;
267  // correct for selection mode ContiguousSelection
268  QModelIndex firstIndex = selection.at(0);
269  model->getRecentRequestsTableModel()->removeRows(firstIndex.row(), selection.length(), firstIndex.parent());
270 }
271 
272 // We override the virtual resizeEvent of the QWidget to adjust tables column
273 // sizes as the tables width is proportional to the dialogs width.
274 void ReceiveCoinsDialog::resizeEvent(QResizeEvent *event)
275 {
276  QWidget::resizeEvent(event);
278 }
279 
280 void ReceiveCoinsDialog::keyPressEvent(QKeyEvent *event)
281 {
282  if (event->key() == Qt::Key_Return)
283  {
284  // press return -> submit form
285  if (ui->reqLabel->hasFocus() || ui->reqAmount->hasFocus() || ui->reqMessage->hasFocus())
286  {
287  event->ignore();
289  return;
290  }
291  }
292 
293  this->QDialog::keyPressEvent(event);
294 }
295 
297 {
298  if(!model || !model->getRecentRequestsTableModel() || !ui->recentRequestsView->selectionModel())
299  return QModelIndex();
300  QModelIndexList selection = ui->recentRequestsView->selectionModel()->selectedRows();
301  if(selection.empty())
302  return QModelIndex();
303  // correct for selection mode ContiguousSelection
304  QModelIndex firstIndex = selection.at(0);
305  return firstIndex;
306 }
307 
308 // copy column of selected row to clipboard
310 {
311  QModelIndex firstIndex = selectedRow();
312  if (!firstIndex.isValid()) {
313  return;
314  }
315  GUIUtil::setClipboard(model->getRecentRequestsTableModel()->data(firstIndex.child(firstIndex.row(), column), Qt::EditRole).toString());
316 }
317 
318 // context menu
319 void ReceiveCoinsDialog::showMenu(const QPoint &point)
320 {
321  if (!selectedRow().isValid()) {
322  return;
323  }
324  contextMenu->exec(QCursor::pos());
325 }
326 
327 // context menu action: copy URI
329 {
330  QModelIndex sel = selectedRow();
331  if (!sel.isValid()) {
332  return;
333  }
334 
335  const RecentRequestsTableModel * const submodel = model->getRecentRequestsTableModel();
336  const QString uri = GUIUtil::formatRavenURI(submodel->entry(sel.row()).recipient);
338 }
339 
340 // context menu action: copy label
342 {
344 }
345 
346 // context menu action: copy message
348 {
350 }
351 
352 // context menu action: copy amount
354 {
356 }
Model for list of recently generated payment requests / raven: URIs.
void addNewRequest(const SendCoinsRecipient &recipient)
void sort(int column, Qt::SortOrder order=Qt::AscendingOrder)
Dialog for requesting payment of ravens.
bool removeRows(int row, int count, const QModelIndex &parent=QModelIndex())
QGraphicsDropShadowEffect * getShadowEffect()
Definition: guiutil.cpp:146
void recentRequestsView_selectionChanged(const QItemSelection &selected, const QItemSelection &deselected)
void setModel(AddressTableModel *model)
GUIUtil::TableViewLastColumnResizingFixer * columnResizingFixer
ReceiveCoinsDialog(const PlatformStyle *platformStyle, QWidget *parent=0)
QIcon SingleColorIcon(const QString &filename) const
Colorize an icon (given filename) with the icon color.
Open address book to pick address.
AddressTableModel * getAddressTableModel()
Ui::ReceiveCoinsDialog * ui
int getDisplayUnit() const
Definition: optionsmodel.h:68
void setModel(WalletModel *model)
QFont getSubLabelFont()
Definition: guiutil.cpp:86
void copyColumnToClipboard(int column)
void setupHistoryFrame(const PlatformStyle *platformStyle)
void setClipboard(const QString &str)
Definition: guiutil.cpp:945
#define STRING_LABEL_COLOR
Definition: guiconstants.h:90
void on_recentRequestsView_doubleClicked(const QModelIndex &index)
void setInfo(const SendCoinsRecipient &info)
QString labelForAddress(const QString &address) const
Makes a QTableView last column feel as if it was being resized from its left border.
Definition: guiutil.h:167
virtual void keyPressEvent(QKeyEvent *event)
const RecentRequestEntry & entry(int row) const
Widget that shows a list of sending or receiving addresses.
QVariant data(const QModelIndex &index, int role) const
virtual void resizeEvent(QResizeEvent *event)
QString addRow(const QString &type, const QString &label, const QString &address)
QColor WidgetBackGroundColor() const
RecentRequestsTableModel * getRecentRequestsTableModel()
QString formatRavenURI(const SendCoinsRecipient &info)
Definition: guiutil.cpp:300
Interface to Raven wallet from Qt view code.
Definition: walletmodel.h:165
static const QString Receive
Specifies receive address.
const PlatformStyle * platformStyle
void showMenu(const QPoint &point)
void setModel(OptionsModel *model)
void setupRequestFrame(const PlatformStyle *platformStyle)
QFont getSubLabelFontBolded()
Definition: guiutil.cpp:98
bool getImagesOnButtons() const
Definition: platformstyle.h:24
OptionsModel * getOptionsModel()
const QString & getReturnValue() const