Master Core  v0.0.9 - 49a5c0d97abf09ef2911ddfe8d9551df59f9efd3-dirty
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
receivecoinsdialog.cpp
Go to the documentation of this file.
1 // Copyright (c) 2011-2014 The Bitcoin developers
2 // Distributed under the MIT/X11 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 "receiverequestdialog.h"
15 #include "walletmodel.h"
16 
17 #include <QAction>
18 #include <QCursor>
19 #include <QItemSelection>
20 #include <QMessageBox>
21 #include <QScrollBar>
22 #include <QTextDocument>
23 
25  QDialog(parent),
26  ui(new Ui::ReceiveCoinsDialog),
27  model(0)
28 {
29  ui->setupUi(this);
30 
31 #ifdef Q_OS_MAC // Icons on push buttons are very uncommon on Mac
32  ui->clearButton->setIcon(QIcon());
33  ui->receiveButton->setIcon(QIcon());
34  ui->showRequestButton->setIcon(QIcon());
35  ui->removeRequestButton->setIcon(QIcon());
36 #endif
37 
38  // context menu actions
39  QAction *copyLabelAction = new QAction(tr("Copy label"), this);
40  QAction *copyMessageAction = new QAction(tr("Copy message"), this);
41  QAction *copyAmountAction = new QAction(tr("Copy amount"), this);
42 
43  // context menu
44  contextMenu = new QMenu();
45  contextMenu->addAction(copyLabelAction);
46  contextMenu->addAction(copyMessageAction);
47  contextMenu->addAction(copyAmountAction);
48 
49  // context menu signals
50  connect(ui->recentRequestsView, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(showMenu(QPoint)));
51  connect(copyLabelAction, SIGNAL(triggered()), this, SLOT(copyLabel()));
52  connect(copyMessageAction, SIGNAL(triggered()), this, SLOT(copyMessage()));
53  connect(copyAmountAction, SIGNAL(triggered()), this, SLOT(copyAmount()));
54 
55  connect(ui->clearButton, SIGNAL(clicked()), this, SLOT(clear()));
56 }
57 
59 {
60  this->model = model;
61 
62  if(model && model->getOptionsModel())
63  {
64  model->getRecentRequestsTableModel()->sort(RecentRequestsTableModel::Date, Qt::DescendingOrder);
65  connect(model->getOptionsModel(), SIGNAL(displayUnitChanged(int)), this, SLOT(updateDisplayUnit()));
67 
68  QTableView* tableView = ui->recentRequestsView;
69 
70  tableView->verticalHeader()->hide();
71  tableView->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
72  tableView->setModel(model->getRecentRequestsTableModel());
73  tableView->setAlternatingRowColors(true);
74  tableView->setSelectionBehavior(QAbstractItemView::SelectRows);
75  tableView->setSelectionMode(QAbstractItemView::ContiguousSelection);
76  tableView->setColumnWidth(RecentRequestsTableModel::Date, DATE_COLUMN_WIDTH);
77  tableView->setColumnWidth(RecentRequestsTableModel::Label, LABEL_COLUMN_WIDTH);
78 
79  connect(tableView->selectionModel(),
80  SIGNAL(selectionChanged(QItemSelection, QItemSelection)), this,
81  SLOT(recentRequestsView_selectionChanged(QItemSelection, QItemSelection)));
82  // Last 2 columns are set by the columnResizingFixer, when the table geometry is ready.
84  }
85 }
86 
88 {
89  delete ui;
90 }
91 
93 {
94  ui->reqAmount->clear();
95  ui->reqLabel->setText("");
96  ui->reqMessage->setText("");
97  ui->reuseAddress->setChecked(false);
99 }
100 
102 {
103  clear();
104 }
105 
107 {
108  clear();
109 }
110 
112 {
113  if(model && model->getOptionsModel())
114  {
116  }
117 }
118 
120 {
122  return;
123 
124  QString address;
125  QString label = ui->reqLabel->text();
126  if(ui->reuseAddress->isChecked())
127  {
128  /* Choose existing receiving address */
131  if(dlg.exec())
132  {
133  address = dlg.getReturnValue();
134  if(label.isEmpty()) /* If no label provided, use the previously used label */
135  {
136  label = model->getAddressTableModel()->labelForAddress(address);
137  }
138  } else {
139  return;
140  }
141  } else {
142  /* Generate new receiving address */
144  }
145  SendCoinsRecipient info(address, label,
146  ui->reqAmount->value(), ui->reqMessage->text());
147  ReceiveRequestDialog *dialog = new ReceiveRequestDialog(this);
148  dialog->setAttribute(Qt::WA_DeleteOnClose);
149  dialog->setModel(model->getOptionsModel());
150  dialog->setInfo(info);
151  dialog->show();
152  clear();
153 
154  /* Store request for later reference */
156 }
157 
159 {
161  ReceiveRequestDialog *dialog = new ReceiveRequestDialog(this);
162  dialog->setModel(model->getOptionsModel());
163  dialog->setInfo(submodel->entry(index.row()).recipient);
164  dialog->setAttribute(Qt::WA_DeleteOnClose);
165  dialog->show();
166 }
167 
168 void ReceiveCoinsDialog::recentRequestsView_selectionChanged(const QItemSelection &selected, const QItemSelection &deselected)
169 {
170  // Enable Show/Remove buttons only if anything is selected.
171  bool enable = !ui->recentRequestsView->selectionModel()->selectedRows().isEmpty();
172  ui->showRequestButton->setEnabled(enable);
173  ui->removeRequestButton->setEnabled(enable);
174 }
175 
177 {
178  if(!model || !model->getRecentRequestsTableModel() || !ui->recentRequestsView->selectionModel())
179  return;
180  QModelIndexList selection = ui->recentRequestsView->selectionModel()->selectedRows();
181 
182  foreach (QModelIndex index, selection)
183  {
185  }
186 }
187 
189 {
190  if(!model || !model->getRecentRequestsTableModel() || !ui->recentRequestsView->selectionModel())
191  return;
192  QModelIndexList selection = ui->recentRequestsView->selectionModel()->selectedRows();
193  if(selection.empty())
194  return;
195  // correct for selection mode ContiguousSelection
196  QModelIndex firstIndex = selection.at(0);
197  model->getRecentRequestsTableModel()->removeRows(firstIndex.row(), selection.length(), firstIndex.parent());
198 }
199 
200 // We override the virtual resizeEvent of the QWidget to adjust tables column
201 // sizes as the tables width is proportional to the dialogs width.
202 void ReceiveCoinsDialog::resizeEvent(QResizeEvent *event)
203 {
204  QWidget::resizeEvent(event);
206 }
207 
208 void ReceiveCoinsDialog::keyPressEvent(QKeyEvent *event)
209 {
210  if (event->key() == Qt::Key_Return)
211  {
212  // press return -> submit form
213  if (ui->reqLabel->hasFocus() || ui->reqAmount->hasFocus() || ui->reqMessage->hasFocus())
214  {
215  event->ignore();
217  return;
218  }
219  }
220 
221  this->QDialog::keyPressEvent(event);
222 }
223 
224 // copy column of selected row to clipboard
226 {
227  if(!model || !model->getRecentRequestsTableModel() || !ui->recentRequestsView->selectionModel())
228  return;
229  QModelIndexList selection = ui->recentRequestsView->selectionModel()->selectedRows();
230  if(selection.empty())
231  return;
232  // correct for selection mode ContiguousSelection
233  QModelIndex firstIndex = selection.at(0);
234  GUIUtil::setClipboard(model->getRecentRequestsTableModel()->data(firstIndex.child(firstIndex.row(), column), Qt::EditRole).toString());
235 }
236 
237 // context menu
238 void ReceiveCoinsDialog::showMenu(const QPoint &point)
239 {
240  if(!model || !model->getRecentRequestsTableModel() || !ui->recentRequestsView->selectionModel())
241  return;
242  QModelIndexList selection = ui->recentRequestsView->selectionModel()->selectedRows();
243  if(selection.empty())
244  return;
245  contextMenu->exec(QCursor::pos());
246 }
247 
248 // context menu action: copy label
250 {
252 }
253 
254 // context menu action: copy message
256 {
258 }
259 
260 // context menu action: copy amount
262 {
264 }
Model for list of recently generated payment requests / bitcoin: 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 recentRequestsView_selectionChanged(const QItemSelection &selected, const QItemSelection &deselected)
BitcoinAmountField * reqAmount
void setModel(AddressTableModel *model)
const QString & getReturnValue() const
GUIUtil::TableViewLastColumnResizingFixer * columnResizingFixer
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:755
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:137
virtual void keyPressEvent(QKeyEvent *event)
int getDisplayUnit()
Definition: optionsmodel.h:58
Widget that shows a list of sending or receiving addresses.
virtual void resizeEvent(QResizeEvent *event)
QString addRow(const QString &type, const QString &label, const QString &address)
RecentRequestsTableModel * getRecentRequestsTableModel()
QString labelForAddress(const QString &address) const
Interface to Bitcoin wallet from Qt view code.
Definition: walletmodel.h:96
void clear()
Make field empty and ready for new input.
void setupUi(QWidget *ReceiveCoinsDialog)
static const QString Receive
Specifies receive address.
void showMenu(const QPoint &point)
void setModel(OptionsModel *model)
void setDisplayUnit(int unit)
Change unit used to display amount.
ReceiveCoinsDialog(QWidget *parent=0)
OptionsModel * getOptionsModel()