From 4d1bb15e31d850776d13266262c37aedc8a68d72 Mon Sep 17 00:00:00 2001 From: "Wladimir J. van der Laan" Date: Fri, 13 May 2011 22:00:27 +0200 Subject: [PATCH] more improvements --- addressbookdialog.cpp | 52 ++++++++++++++++++++++++++++++++++--- addressbookdialog.h | 12 ++++++++- addressbookdialog.ui | 33 ++++++++++++++++++----- addresstablemodel.cpp | 2 +- bitcoin.pro | 6 +++-- bitcoinaddressvalidator.cpp | 8 ++++++ bitcoinaddressvalidator.h | 19 ++++++++++++++ bitcoingui.h | 3 +++ optionsdialog.cpp | 2 ++ optionsdialog.h | 8 ++++-- sendcoinsdialog.cpp | 14 ++++++---- sendcoinsdialog.h | 2 +- sendcoinsdialog.ui | 45 +++++++++++++++++++++++++++----- 13 files changed, 178 insertions(+), 28 deletions(-) create mode 100644 bitcoinaddressvalidator.cpp create mode 100644 bitcoinaddressvalidator.h diff --git a/addressbookdialog.cpp b/addressbookdialog.cpp index 72b0da35f..71543f11a 100644 --- a/addressbookdialog.cpp +++ b/addressbookdialog.cpp @@ -5,6 +5,7 @@ #include "editaddressdialog.h" #include +#include AddressBookDialog::AddressBookDialog(QWidget *parent) : QDialog(parent), @@ -62,14 +63,23 @@ void AddressBookDialog::setTab(int tab) ui->tabWidget->setCurrentIndex(tab); } -void AddressBookDialog::on_OKButton_clicked() +QTableView *AddressBookDialog::getCurrentTable() { - accept(); + switch(ui->tabWidget->currentIndex()) + { + case SendingTab: + return ui->sendTableView; + case ReceivingTab: + return ui->receiveTableView; + default: + return 0; + } } void AddressBookDialog::on_copyToClipboard_clicked() { - /* Copy currently selected address to clipboard */ + /* Copy currently selected address to clipboard */ + } void AddressBookDialog::on_editButton_clicked() @@ -84,3 +94,39 @@ void AddressBookDialog::on_newAddressButton_clicked() EditAddressDialog dlg; dlg.exec(); } + +void AddressBookDialog::on_tabWidget_currentChanged(int index) +{ + switch(index) + { + case SendingTab: + ui->deleteButton->show(); + break; + case ReceivingTab: + ui->deleteButton->hide(); + break; + } +} + +void AddressBookDialog::on_deleteButton_clicked() +{ + QTableView *table = getCurrentTable(); + QModelIndexList indexes = table->selectionModel()->selectedRows(); + + foreach (QModelIndex index, indexes) { + table->model()->removeRow(index.row()); + } +} + +void AddressBookDialog::on_buttonBox_accepted() +{ + QTableView *table = getCurrentTable(); + QModelIndexList indexes = table->selectionModel()->selectedRows(AddressTableModel::Address); + + foreach (QModelIndex index, indexes) { + QVariant address = table->model()->data(index); + returnValue = address.toString(); + } + + accept(); +} diff --git a/addressbookdialog.h b/addressbookdialog.h index d075c9ba0..bf7c2a65a 100644 --- a/addressbookdialog.h +++ b/addressbookdialog.h @@ -8,6 +8,10 @@ namespace Ui { } class AddressTableModel; +QT_BEGIN_NAMESPACE +class QTableView; +QT_END_NAMESPACE + class AddressBookDialog : public QDialog { Q_OBJECT @@ -23,15 +27,21 @@ public: void setModel(AddressTableModel *model); void setTab(int tab); + const QString &getReturnValue() const { return returnValue; } private: Ui::AddressBookDialog *ui; AddressTableModel *model; + QString returnValue; + + QTableView *getCurrentTable(); private slots: + void on_buttonBox_accepted(); + void on_deleteButton_clicked(); + void on_tabWidget_currentChanged(int index); void on_newAddressButton_clicked(); void on_editButton_clicked(); void on_copyToClipboard_clicked(); - void on_OKButton_clicked(); }; #endif // ADDRESSBOOKDIALOG_H diff --git a/addressbookdialog.ui b/addressbookdialog.ui index 0aa093e05..d66962a2b 100644 --- a/addressbookdialog.ui +++ b/addressbookdialog.ui @@ -26,6 +26,9 @@ + + QAbstractItemView::SingleSelection + QAbstractItemView::SelectRows @@ -56,6 +59,9 @@ + + QAbstractItemView::SingleSelection + QAbstractItemView::SelectRows @@ -83,31 +89,44 @@ + + + + &New Address... + + + - Copy to Clipboard + &Copy to Clipboard - Edit... + &Edit... - + - New Address... + &Delete - - - OK + + + + 0 + 0 + + + + QDialogButtonBox::Ok diff --git a/addresstablemodel.cpp b/addresstablemodel.cpp index e8746c2b8..d985bcee3 100644 --- a/addresstablemodel.cpp +++ b/addresstablemodel.cpp @@ -29,7 +29,7 @@ QVariant AddressTableModel::data(const QModelIndex &index, int role) const /* index.row(), index.column() */ /* Return QString */ if(index.column() == Address) - return "1PC9aZC4hNX2rmmrt7uHTfYAS3hRbph4UN"; + return "1PC9aZC4hNX2rmmrt7uHTfYAS3hRbph4UN" + QString::number(index.row()); else return "Description"; } else if (role == Qt::UserRole) diff --git a/bitcoin.pro b/bitcoin.pro index d0b9512b9..b34f562fd 100644 --- a/bitcoin.pro +++ b/bitcoin.pro @@ -16,7 +16,8 @@ HEADERS += bitcoingui.h \ sendcoinsdialog.h \ addressbookdialog.h \ aboutdialog.h \ - editaddressdialog.h + editaddressdialog.h \ + bitcoinaddressvalidator.h SOURCES += bitcoin.cpp bitcoingui.cpp \ transactiontablemodel.cpp \ addresstablemodel.cpp \ @@ -25,7 +26,8 @@ SOURCES += bitcoin.cpp bitcoingui.cpp \ sendcoinsdialog.cpp \ addressbookdialog.cpp \ aboutdialog.cpp \ - editaddressdialog.cpp + editaddressdialog.cpp \ + bitcoinaddressvalidator.cpp RESOURCES += \ bitcoin.qrc diff --git a/bitcoinaddressvalidator.cpp b/bitcoinaddressvalidator.cpp new file mode 100644 index 000000000..408027b4d --- /dev/null +++ b/bitcoinaddressvalidator.cpp @@ -0,0 +1,8 @@ +#include "bitcoinaddressvalidator.h" + +const QString BitcoinAddressValidator::valid_chars = "123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"; + +BitcoinAddressValidator::BitcoinAddressValidator(QObject *parent) : + QRegExpValidator(QRegExp("^["+valid_chars+"]+"), parent) +{ +} diff --git a/bitcoinaddressvalidator.h b/bitcoinaddressvalidator.h new file mode 100644 index 000000000..f6a2ac02b --- /dev/null +++ b/bitcoinaddressvalidator.h @@ -0,0 +1,19 @@ +#ifndef BITCOINADDRESSVALIDATOR_H +#define BITCOINADDRESSVALIDATOR_H + +#include + +class BitcoinAddressValidator : public QRegExpValidator +{ + Q_OBJECT +public: + explicit BitcoinAddressValidator(QObject *parent = 0); + + static const QString valid_chars; +signals: + +public slots: + +}; + +#endif // BITCOINADDRESSVALIDATOR_H diff --git a/bitcoingui.h b/bitcoingui.h index 12bbf58ba..9142b6b84 100644 --- a/bitcoingui.h +++ b/bitcoingui.h @@ -6,8 +6,11 @@ /* Forward declarations */ class TransactionTableModel; + +QT_BEGIN_NAMESPACE class QLabel; class QLineEdit; +QT_END_NAMESPACE class BitcoinGUI : public QMainWindow { diff --git a/optionsdialog.cpp b/optionsdialog.cpp index e609e5442..70dd86323 100644 --- a/optionsdialog.cpp +++ b/optionsdialog.cpp @@ -4,6 +4,8 @@ #include #include #include +#include +#include OptionsDialog::OptionsDialog(QWidget *parent) : QDialog(parent), contents_widget(0), pages_widget(0) diff --git a/optionsdialog.h b/optionsdialog.h index 2a4beacce..501c82e9f 100644 --- a/optionsdialog.h +++ b/optionsdialog.h @@ -2,8 +2,12 @@ #define OPTIONSDIALOG_H #include -#include -#include + +QT_BEGIN_NAMESPACE +class QStackedWidget; +class QListWidget; +class QListWidgetItem; +QT_END_NAMESPACE class OptionsDialog : public QDialog { diff --git a/sendcoinsdialog.cpp b/sendcoinsdialog.cpp index d8ef78129..6f459fb66 100644 --- a/sendcoinsdialog.cpp +++ b/sendcoinsdialog.cpp @@ -2,6 +2,7 @@ #include "ui_sendcoinsdialog.h" #include "addressbookdialog.h" +#include "bitcoinaddressvalidator.h" #include #include @@ -11,6 +12,8 @@ SendCoinsDialog::SendCoinsDialog(QWidget *parent) : ui(new Ui::SendCoinsDialog) { ui->setupUi(this); + ui->payTo->setValidator(new BitcoinAddressValidator(this)); + ui->payAmount->setValidator(new QDoubleValidator(this)); } SendCoinsDialog::~SendCoinsDialog() @@ -23,11 +26,6 @@ void SendCoinsDialog::on_sendButton_clicked() accept(); } -void SendCoinsDialog::on_cancelButton_clicked() -{ - reject(); -} - void SendCoinsDialog::on_pasteButton_clicked() { /* Paste text from clipboard into recipient field */ @@ -38,4 +36,10 @@ void SendCoinsDialog::on_addressBookButton_clicked() { AddressBookDialog dlg; dlg.exec(); + ui->payTo->setText(dlg.getReturnValue()); +} + +void SendCoinsDialog::on_buttonBox_rejected() +{ + reject(); } diff --git a/sendcoinsdialog.h b/sendcoinsdialog.h index e3ffd1d33..a2fcdd076 100644 --- a/sendcoinsdialog.h +++ b/sendcoinsdialog.h @@ -19,9 +19,9 @@ private: Ui::SendCoinsDialog *ui; private slots: + void on_buttonBox_rejected(); void on_addressBookButton_clicked(); void on_pasteButton_clicked(); - void on_cancelButton_clicked(); void on_sendButton_clicked(); }; diff --git a/sendcoinsdialog.ui b/sendcoinsdialog.ui index ef7eaf37c..f14ec2af1 100644 --- a/sendcoinsdialog.ui +++ b/sendcoinsdialog.ui @@ -43,7 +43,11 @@ - + + + 34 + + @@ -116,12 +120,22 @@ &Send + + + :/icons/send:/icons/send + - - - Cancel + + + + 0 + 0 + + + + QDialogButtonBox::Cancel @@ -129,6 +143,25 @@ - - + + + + + + payAmount + returnPressed() + sendButton + click() + + + 191 + 65 + + + 570 + 121 + + + +