Dash Core Source Documentation (0.16.0.1)

Find detailed information regarding the Dash Core source code.

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 
6 #include <qt/forms/ui_receivecoinsdialog.h>
7 
8 #include <qt/addressbookpage.h>
9 #include <qt/addresstablemodel.h>
10 #include <qt/bitcoinunits.h>
11 #include <qt/optionsmodel.h>
14 #include <qt/walletmodel.h>
15 
16 #include <QAction>
17 #include <QCursor>
18 #include <QMessageBox>
19 #include <QScrollBar>
20 #include <QTextDocument>
21 
23  QDialog(parent),
24  ui(new Ui::ReceiveCoinsDialog),
25  columnResizingFixer(0),
26  model(0)
27 {
28  ui->setupUi(this);
29 
31  GUIUtil::setFont({ui->label,
32  ui->label_2,
33  ui->label_3}, GUIUtil::FontWeight::Normal, 15);
35 
36 #if QT_VERSION >= 0x040700
37  ui->reqLabel->setPlaceholderText(tr("Enter a label to associate with the new receiving address"));
38  ui->reqMessage->setPlaceholderText(tr("Enter a message to attach to the payment request"));
39 #endif
40 
41  // context menu actions
42  QAction *copyURIAction = new QAction(tr("Copy URI"), this);
43  QAction *copyLabelAction = new QAction(tr("Copy label"), this);
44  QAction *copyMessageAction = new QAction(tr("Copy message"), this);
45  QAction *copyAmountAction = new QAction(tr("Copy amount"), this);
46 
47  // context menu
48  contextMenu = new QMenu(this);
49  contextMenu->addAction(copyURIAction);
50  contextMenu->addAction(copyLabelAction);
51  contextMenu->addAction(copyMessageAction);
52  contextMenu->addAction(copyAmountAction);
53 
54  // context menu signals
55  connect(ui->recentRequestsView, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(showMenu(QPoint)));
56  connect(copyURIAction, SIGNAL(triggered()), this, SLOT(copyURI()));
57  connect(copyLabelAction, SIGNAL(triggered()), this, SLOT(copyLabel()));
58  connect(copyMessageAction, SIGNAL(triggered()), this, SLOT(copyMessage()));
59  connect(copyAmountAction, SIGNAL(triggered()), this, SLOT(copyAmount()));
60 
61  connect(ui->clearButton, SIGNAL(clicked()), this, SLOT(clear()));
62 }
63 
65 {
66  this->model = _model;
67 
68  if(_model && _model->getOptionsModel())
69  {
70  _model->getRecentRequestsTableModel()->sort(RecentRequestsTableModel::Date, Qt::DescendingOrder);
71  connect(_model->getOptionsModel(), SIGNAL(displayUnitChanged(int)), this, SLOT(updateDisplayUnit()));
73 
74  QTableView* tableView = ui->recentRequestsView;
75 
76  tableView->verticalHeader()->hide();
77  tableView->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
78  tableView->setModel(_model->getRecentRequestsTableModel());
79  tableView->setAlternatingRowColors(true);
80  tableView->setSelectionBehavior(QAbstractItemView::SelectRows);
81  tableView->setSelectionMode(QAbstractItemView::ContiguousSelection);
82  tableView->setColumnWidth(RecentRequestsTableModel::Date, DATE_COLUMN_WIDTH);
83  tableView->setColumnWidth(RecentRequestsTableModel::Label, LABEL_COLUMN_WIDTH);
85 
86  connect(tableView->selectionModel(),
87  SIGNAL(selectionChanged(QItemSelection, QItemSelection)), this,
88  SLOT(recentRequestsView_selectionChanged(QItemSelection, QItemSelection)));
89  // Last 2 columns are set by the columnResizingFixer, when the table geometry is ready.
91  }
92 }
93 
95 {
96  delete ui;
97 }
98 
100 {
101  ui->reqAmount->clear();
102  ui->reqLabel->setText("");
103  ui->reqMessage->setText("");
105 }
106 
108 {
109  clear();
110 }
111 
113 {
114  clear();
115 }
116 
118 {
119  if(model && model->getOptionsModel())
120  {
121  ui->reqAmount->setDisplayUnit(model->getOptionsModel()->getDisplayUnit());
122  }
123 }
124 
126 {
128  return;
129 
130  QString address;
131  QString label = ui->reqLabel->text();
132  /* Generate new receiving address */
134  SendCoinsRecipient info(address, label,
135  ui->reqAmount->value(), ui->reqMessage->text());
136  ReceiveRequestDialog *dialog = new ReceiveRequestDialog(this);
137  dialog->setAttribute(Qt::WA_DeleteOnClose);
138  dialog->setModel(model->getOptionsModel());
139  dialog->setInfo(info);
140  dialog->show();
141  clear();
142 
143  /* Store request for later reference */
145 }
146 
148 {
150  ReceiveRequestDialog *dialog = new ReceiveRequestDialog(this);
151  dialog->setModel(model->getOptionsModel());
152  dialog->setInfo(submodel->entry(index.row()).recipient);
153  dialog->setAttribute(Qt::WA_DeleteOnClose);
154  dialog->show();
155 }
156 
157 void ReceiveCoinsDialog::recentRequestsView_selectionChanged(const QItemSelection &selected, const QItemSelection &deselected)
158 {
159  // Enable Show/Remove buttons only if anything is selected.
160  bool enable = !ui->recentRequestsView->selectionModel()->selectedRows().isEmpty();
161  ui->showRequestButton->setEnabled(enable);
162  ui->removeRequestButton->setEnabled(enable);
163 }
164 
166 {
167  if(!model || !model->getRecentRequestsTableModel() || !ui->recentRequestsView->selectionModel())
168  return;
169  QModelIndexList selection = ui->recentRequestsView->selectionModel()->selectedRows();
170 
171  for (const QModelIndex& index : selection) {
173  }
174 }
175 
177 {
178  if(!model || !model->getRecentRequestsTableModel() || !ui->recentRequestsView->selectionModel())
179  return;
180  QModelIndexList selection = ui->recentRequestsView->selectionModel()->selectedRows();
181  if(selection.empty())
182  return;
183  // correct for selection mode ContiguousSelection
184  QModelIndex firstIndex = selection.at(0);
185  model->getRecentRequestsTableModel()->removeRows(firstIndex.row(), selection.length(), firstIndex.parent());
186 }
187 
188 // We override the virtual resizeEvent of the QWidget to adjust tables column
189 // sizes as the tables width is proportional to the dialogs width.
190 void ReceiveCoinsDialog::resizeEvent(QResizeEvent *event)
191 {
192  QWidget::resizeEvent(event);
194 }
195 
196 void ReceiveCoinsDialog::keyPressEvent(QKeyEvent *event)
197 {
198  if (event->key() == Qt::Key_Return)
199  {
200  // press return -> submit form
201  if (ui->reqLabel->hasFocus() || ui->reqAmount->hasFocus() || ui->reqMessage->hasFocus())
202  {
203  event->ignore();
205  return;
206  }
207  }
208 
209  this->QDialog::keyPressEvent(event);
210 }
211 
213 {
214  if(!model || !model->getRecentRequestsTableModel() || !ui->recentRequestsView->selectionModel())
215  return QModelIndex();
216  QModelIndexList selection = ui->recentRequestsView->selectionModel()->selectedRows();
217  if(selection.empty())
218  return QModelIndex();
219  // correct for selection mode ContiguousSelection
220  QModelIndex firstIndex = selection.at(0);
221  return firstIndex;
222 }
223 
224 // copy column of selected row to clipboard
226 {
227  QModelIndex firstIndex = selectedRow();
228  if (!firstIndex.isValid()) {
229  return;
230  }
231  GUIUtil::setClipboard(model->getRecentRequestsTableModel()->data(firstIndex.child(firstIndex.row(), column), Qt::EditRole).toString());
232 }
233 
234 // context menu
235 void ReceiveCoinsDialog::showMenu(const QPoint &point)
236 {
237  if (!selectedRow().isValid()) {
238  return;
239  }
240  contextMenu->exec(QCursor::pos());
241 }
242 
243 // context menu action: copy URI
245 {
246  QModelIndex sel = selectedRow();
247  if (!sel.isValid()) {
248  return;
249  }
250 
251  const RecentRequestsTableModel * const submodel = model->getRecentRequestsTableModel();
252  const QString uri = GUIUtil::formatBitcoinURI(submodel->entry(sel.row()).recipient);
254 }
255 
256 // context menu action: copy label
258 {
260 }
261 
262 // context menu action: copy message
264 {
266 }
267 
268 // context menu action: copy amount
270 {
272 }
Model for list of recently generated payment requests / dash: URIs.
void addNewRequest(const SendCoinsRecipient &recipient)
void sort(int column, Qt::SortOrder order=Qt::AscendingOrder)
Dialog for requesting payment of bitcoins.
bool removeRows(int row, int count, const QModelIndex &parent=QModelIndex())
void setFont(const std::vector< QWidget *> &vecWidgets, FontWeight weight, int nPointSize, bool fItalic)
Workaround to set correct font styles in all themes since there is a bug in macOS which leads to issu...
Definition: guiutil.cpp:1552
void recentRequestsView_selectionChanged(const QItemSelection &selected, const QItemSelection &deselected)
GUIUtil::TableViewLastColumnResizingFixer * columnResizingFixer
AddressTableModel * getAddressTableModel()
Ui::ReceiveCoinsDialog * ui
QString formatBitcoinURI(const SendCoinsRecipient &info)
Definition: guiutil.cpp:445
int getDisplayUnit() const
Definition: optionsmodel.h:82
void setModel(WalletModel *model)
void updateFonts()
Update the font of all widgets where a custom font has been set with GUIUtil::setFont.
Definition: guiutil.cpp:1563
void copyColumnToClipboard(int column)
virtual void keyPressEvent(QKeyEvent *event) override
void setClipboard(const QString &str)
Definition: guiutil.cpp:1817
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:221
virtual void resizeEvent(QResizeEvent *event) override
const RecentRequestEntry & entry(int row) const
QVariant data(const QModelIndex &index, int role) const
QString addRow(const QString &type, const QString &label, const QString &address)
RecentRequestsTableModel * getRecentRequestsTableModel()
Interface to Bitcoin wallet from Qt view code.
Definition: walletmodel.h:100
static const QString Receive
Specifies receive address.
void showMenu(const QPoint &point)
void setModel(OptionsModel *model)
ReceiveCoinsDialog(QWidget *parent=0)
OptionsModel * getOptionsModel()
Released under the MIT license