Dash Core  0.12.2.1
P2P Digital Currency
receivecoinsdialog.cpp
Go to the documentation of this file.
1 // Copyright (c) 2011-2015 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 "bitcoinunits.h"
11 #include "guiutil.h"
12 #include "optionsmodel.h"
13 #include "platformstyle.h"
14 #include "receiverequestdialog.h"
16 #include "walletmodel.h"
17 
18 #include <QAction>
19 #include <QCursor>
20 #include <QItemSelection>
21 #include <QMessageBox>
22 #include <QScrollBar>
23 #include <QTextDocument>
24 
25 ReceiveCoinsDialog::ReceiveCoinsDialog(const PlatformStyle *platformStyle, QWidget *parent) :
26  QDialog(parent),
27  ui(new Ui::ReceiveCoinsDialog),
28  columnResizingFixer(0),
29  model(0),
30  platformStyle(platformStyle)
31 {
32  ui->setupUi(this);
33  QString theme = GUIUtil::getThemeName();
34 
36  ui->clearButton->setIcon(QIcon());
37  ui->receiveButton->setIcon(QIcon());
38  ui->showRequestButton->setIcon(QIcon());
39  ui->removeRequestButton->setIcon(QIcon());
40  } else {
41  ui->clearButton->setIcon(QIcon(":/icons/" + theme + "/remove"));
42  ui->receiveButton->setIcon(QIcon(":/icons/" + theme + "/receiving_addresses"));
43  ui->showRequestButton->setIcon(QIcon(":/icons/" + theme + "/edit"));
44  ui->removeRequestButton->setIcon(QIcon(":/icons/" + theme + "/remove"));
45  }
46 
47  // context menu actions
48  QAction *copyURIAction = new QAction(tr("Copy URI"), this);
49  QAction *copyLabelAction = new QAction(tr("Copy label"), this);
50  QAction *copyMessageAction = new QAction(tr("Copy message"), this);
51  QAction *copyAmountAction = new QAction(tr("Copy amount"), this);
52 
53  // context menu
54  contextMenu = new QMenu(this);
55  contextMenu->addAction(copyURIAction);
56  contextMenu->addAction(copyLabelAction);
57  contextMenu->addAction(copyMessageAction);
58  contextMenu->addAction(copyAmountAction);
59 
60  // context menu signals
61  connect(ui->recentRequestsView, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(showMenu(QPoint)));
62  connect(copyURIAction, SIGNAL(triggered()), this, SLOT(copyURI()));
63  connect(copyLabelAction, SIGNAL(triggered()), this, SLOT(copyLabel()));
64  connect(copyMessageAction, SIGNAL(triggered()), this, SLOT(copyMessage()));
65  connect(copyAmountAction, SIGNAL(triggered()), this, SLOT(copyAmount()));
66 
67  connect(ui->clearButton, SIGNAL(clicked()), this, SLOT(clear()));
68 }
69 
71 {
72  this->model = model;
73 
74  if(model && model->getOptionsModel())
75  {
77  connect(model->getOptionsModel(), SIGNAL(displayUnitChanged(int)), this, SLOT(updateDisplayUnit()));
79 
80  QTableView* tableView = ui->recentRequestsView;
81 
82  tableView->verticalHeader()->hide();
83  tableView->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
84  tableView->setModel(model->getRecentRequestsTableModel());
85  tableView->setAlternatingRowColors(true);
86  tableView->setSelectionBehavior(QAbstractItemView::SelectRows);
87  tableView->setSelectionMode(QAbstractItemView::ContiguousSelection);
88  tableView->setColumnWidth(RecentRequestsTableModel::Date, DATE_COLUMN_WIDTH);
89  tableView->setColumnWidth(RecentRequestsTableModel::Label, LABEL_COLUMN_WIDTH);
90 
91  connect(tableView->selectionModel(),
92  SIGNAL(selectionChanged(QItemSelection, QItemSelection)), this,
93  SLOT(recentRequestsView_selectionChanged(QItemSelection, QItemSelection)));
94  // Last 2 columns are set by the columnResizingFixer, when the table geometry is ready.
96  }
97 }
98 
100 {
101  delete ui;
102 }
103 
105 {
106  ui->reqAmount->clear();
107  ui->reqLabel->setText("");
108  ui->reqMessage->setText("");
109  ui->reuseAddress->setChecked(false);
111 }
112 
114 {
115  clear();
116 }
117 
119 {
120  clear();
121 }
122 
124 {
125  if(model && model->getOptionsModel())
126  {
128  }
129 }
130 
132 {
134  return;
135 
136  QString address;
137  QString label = ui->reqLabel->text();
138  if(ui->reuseAddress->isChecked())
139  {
140  /* Choose existing receiving address */
143  if(dlg.exec())
144  {
145  address = dlg.getReturnValue();
146  if(label.isEmpty()) /* If no label provided, use the previously used label */
147  {
148  label = model->getAddressTableModel()->labelForAddress(address);
149  }
150  } else {
151  return;
152  }
153  } else {
154  /* Generate new receiving address */
156  }
157  SendCoinsRecipient info(address, label,
158  ui->reqAmount->value(), ui->reqMessage->text());
159  info.fUseInstantSend = ui->checkUseInstantSend->isChecked();
160  ReceiveRequestDialog *dialog = new ReceiveRequestDialog(this);
161  dialog->setAttribute(Qt::WA_DeleteOnClose);
162  dialog->setModel(model->getOptionsModel());
163  dialog->setInfo(info);
164  dialog->show();
165  clear();
166 
167  /* Store request for later reference */
169 }
170 
172 {
174  ReceiveRequestDialog *dialog = new ReceiveRequestDialog(this);
175  dialog->setModel(model->getOptionsModel());
176  dialog->setInfo(submodel->entry(index.row()).recipient);
177  dialog->setAttribute(Qt::WA_DeleteOnClose);
178  dialog->show();
179 }
180 
181 void ReceiveCoinsDialog::recentRequestsView_selectionChanged(const QItemSelection &selected, const QItemSelection &deselected)
182 {
183  // Enable Show/Remove buttons only if anything is selected.
184  bool enable = !ui->recentRequestsView->selectionModel()->selectedRows().isEmpty();
185  ui->showRequestButton->setEnabled(enable);
186  ui->removeRequestButton->setEnabled(enable);
187 }
188 
190 {
191  if(!model || !model->getRecentRequestsTableModel() || !ui->recentRequestsView->selectionModel())
192  return;
193  QModelIndexList selection = ui->recentRequestsView->selectionModel()->selectedRows();
194 
195  Q_FOREACH (const QModelIndex& index, selection) {
197  }
198 }
199 
201 {
202  if(!model || !model->getRecentRequestsTableModel() || !ui->recentRequestsView->selectionModel())
203  return;
204  QModelIndexList selection = ui->recentRequestsView->selectionModel()->selectedRows();
205  if(selection.empty())
206  return;
207  // correct for selection mode ContiguousSelection
208  QModelIndex firstIndex = selection.at(0);
209  model->getRecentRequestsTableModel()->removeRows(firstIndex.row(), selection.length(), firstIndex.parent());
210 }
211 
212 // We override the virtual resizeEvent of the QWidget to adjust tables column
213 // sizes as the tables width is proportional to the dialogs width.
214 void ReceiveCoinsDialog::resizeEvent(QResizeEvent *event)
215 {
216  QWidget::resizeEvent(event);
218 }
219 
220 void ReceiveCoinsDialog::keyPressEvent(QKeyEvent *event)
221 {
222  if (event->key() == Qt::Key_Return)
223  {
224  // press return -> submit form
225  if (ui->reqLabel->hasFocus() || ui->reqAmount->hasFocus() || ui->reqMessage->hasFocus())
226  {
227  event->ignore();
229  return;
230  }
231  }
232 
233  this->QDialog::keyPressEvent(event);
234 }
235 
237 {
238  if(!model || !model->getRecentRequestsTableModel() || !ui->recentRequestsView->selectionModel())
239  return QModelIndex();
240  QModelIndexList selection = ui->recentRequestsView->selectionModel()->selectedRows();
241  if(selection.empty())
242  return QModelIndex();
243  // correct for selection mode ContiguousSelection
244  QModelIndex firstIndex = selection.at(0);
245  return firstIndex;
246 }
247 
248 // copy column of selected row to clipboard
250 {
251  QModelIndex firstIndex = selectedRow();
252  if (!firstIndex.isValid()) {
253  return;
254  }
255  GUIUtil::setClipboard(model->getRecentRequestsTableModel()->data(firstIndex.child(firstIndex.row(), column), Qt::EditRole).toString());
256 }
257 
258 // context menu
259 void ReceiveCoinsDialog::showMenu(const QPoint &point)
260 {
261  if (!selectedRow().isValid()) {
262  return;
263  }
264  contextMenu->exec(QCursor::pos());
265 }
266 
267 // context menu action: copy URI
269 {
270  QModelIndex sel = selectedRow();
271  if (!sel.isValid()) {
272  return;
273  }
274 
275  const RecentRequestsTableModel * const submodel = model->getRecentRequestsTableModel();
276  const QString uri = GUIUtil::formatBitcoinURI(submodel->entry(sel.row()).recipient);
278 }
279 
280 // context menu action: copy label
282 {
284 }
285 
286 // context menu action: copy message
288 {
290 }
291 
292 // context menu action: copy amount
294 {
296 }
Ui::ReceiveCoinsDialog * ui
QString addRow(const QString &type, const QString &label, const QString &address)
static const QString Receive
ReceiveCoinsDialog(const PlatformStyle *platformStyle, QWidget *parent=0)
void setModel(WalletModel *model)
void setInfo(const SendCoinsRecipient &info)
void setModel(OptionsModel *model)
virtual void resizeEvent(QResizeEvent *event)
const PlatformStyle * platformStyle
void addNewRequest(const SendCoinsRecipient &recipient)
void recentRequestsView_selectionChanged(const QItemSelection &selected, const QItemSelection &deselected)
QVariant data(const QModelIndex &index, int role) const
const RecentRequestEntry & entry(int row) const
void showMenu(const QPoint &point)
void setDisplayUnit(int unit)
RecentRequestsTableModel * getRecentRequestsTableModel()
void setClipboard(const QString &str)
Definition: guiutil.cpp:937
void copyColumnToClipboard(int column)
QString labelForAddress(const QString &address) const
void setupUi(QWidget *ReceiveCoinsDialog)
GUIUtil::TableViewLastColumnResizingFixer * columnResizingFixer
OptionsModel * getOptionsModel()
QString formatBitcoinURI(const SendCoinsRecipient &info)
Definition: guiutil.cpp:219
const QString & getReturnValue() const
bool getImagesOnButtons() const
Definition: platformstyle.h:21
BitcoinAmountField * reqAmount
QString getThemeName()
Definition: guiutil.cpp:902
bool removeRows(int row, int count, const QModelIndex &parent=QModelIndex())
void on_recentRequestsView_doubleClicked(const QModelIndex &index)
virtual void keyPressEvent(QKeyEvent *event)
int getDisplayUnit()
Definition: optionsmodel.h:73
void sort(int column, Qt::SortOrder order=Qt::AscendingOrder)
AddressTableModel * getAddressTableModel()
void setModel(AddressTableModel *model)