diff options
author | Wladimir J. van der Laan <laanwj@gmail.com> | 2011-06-02 15:57:23 +0200 |
---|---|---|
committer | Wladimir J. van der Laan <laanwj@gmail.com> | 2011-06-02 15:57:23 +0200 |
commit | e457b021421c9065c8677e7fb7d7cae0391bf1f8 (patch) | |
tree | a656f00574cd40683656b976cc67607e5318bbb2 | |
parent | ef1b844e7b444b07e708dcd9a1e0dc93510dade5 (diff) |
namespacing, user friendly base58 entry, addressbook work
-rw-r--r-- | gui/forms/editaddressdialog.ui | 46 | ||||
-rw-r--r-- | gui/include/bitcoinaddressvalidator.h | 2 | ||||
-rw-r--r-- | gui/include/editaddressdialog.h | 11 | ||||
-rw-r--r-- | gui/include/guiutil.h | 22 | ||||
-rw-r--r-- | gui/src/addressbookdialog.cpp | 16 | ||||
-rw-r--r-- | gui/src/addresstablemodel.cpp | 4 | ||||
-rw-r--r-- | gui/src/bitcoinaddressvalidator.cpp | 37 | ||||
-rw-r--r-- | gui/src/bitcoingui.cpp | 2 | ||||
-rw-r--r-- | gui/src/editaddressdialog.cpp | 5 | ||||
-rw-r--r-- | gui/src/guiutil.cpp | 25 | ||||
-rw-r--r-- | gui/src/sendcoinsdialog.cpp | 11 | ||||
-rw-r--r-- | gui/src/transactiontablemodel.cpp | 4 |
12 files changed, 147 insertions, 38 deletions
diff --git a/gui/forms/editaddressdialog.ui b/gui/forms/editaddressdialog.ui index 2d8aa880f6..763a0bb8e4 100644 --- a/gui/forms/editaddressdialog.ui +++ b/gui/forms/editaddressdialog.ui @@ -6,26 +6,46 @@ <rect> <x>0</x> <y>0</y> - <width>400</width> - <height>300</height> + <width>458</width> + <height>113</height> </rect> </property> <property name="windowTitle"> - <string>Dialog</string> + <string>Edit Address</string> </property> <layout class="QVBoxLayout" name="verticalLayout"> <item> - <spacer name="verticalSpacer"> - <property name="orientation"> - <enum>Qt::Vertical</enum> - </property> - <property name="sizeHint" stdset="0"> - <size> - <width>20</width> - <height>40</height> - </size> + <layout class="QFormLayout" name="formLayout"> + <property name="fieldGrowthPolicy"> + <enum>QFormLayout::AllNonFixedFieldsGrow</enum> </property> - </spacer> + <item row="0" column="0"> + <widget class="QLabel" name="label"> + <property name="text"> + <string>&Label</string> + </property> + <property name="buddy"> + <cstring>labelEdit</cstring> + </property> + </widget> + </item> + <item row="1" column="0"> + <widget class="QLabel" name="label_2"> + <property name="text"> + <string>&Address</string> + </property> + <property name="buddy"> + <cstring>addressEdit</cstring> + </property> + </widget> + </item> + <item row="0" column="1"> + <widget class="QLineEdit" name="labelEdit"/> + </item> + <item row="1" column="1"> + <widget class="QLineEdit" name="addressEdit"/> + </item> + </layout> </item> <item> <widget class="QDialogButtonBox" name="buttonBox"> diff --git a/gui/include/bitcoinaddressvalidator.h b/gui/include/bitcoinaddressvalidator.h index 8322eef739..c7b2eefc69 100644 --- a/gui/include/bitcoinaddressvalidator.h +++ b/gui/include/bitcoinaddressvalidator.h @@ -9,6 +9,8 @@ class BitcoinAddressValidator : public QRegExpValidator public: explicit BitcoinAddressValidator(QObject *parent = 0); + State validate(QString &input, int &pos) const; + static const int MaxAddressLength = 34; signals: diff --git a/gui/include/editaddressdialog.h b/gui/include/editaddressdialog.h index 650ed534a0..8e4a0388c2 100644 --- a/gui/include/editaddressdialog.h +++ b/gui/include/editaddressdialog.h @@ -12,8 +12,15 @@ class EditAddressDialog : public QDialog Q_OBJECT public: - explicit EditAddressDialog(QWidget *parent = 0); - ~EditAddressDialog(); + enum Mode { + NewReceivingAddress, + NewSendingAddress, + EditReceivingAddress, + EditSendingAddress + }; + + explicit EditAddressDialog(Mode mode, QWidget *parent = 0); + ~EditAddressDialog(); private: Ui::EditAddressDialog *ui; diff --git a/gui/include/guiutil.h b/gui/include/guiutil.h index eaa8199900..748e29bf37 100644 --- a/gui/include/guiutil.h +++ b/gui/include/guiutil.h @@ -2,10 +2,24 @@ #define GUIUTIL_H #include <QString> -#include <QFont> -QString DateTimeStr(qint64 nTime); -/* Render bitcoin addresses in monospace font */ -QFont bitcoinAddressFont(); +QT_BEGIN_NAMESPACE +class QFont; +class QLineEdit; +class QWidget; +QT_END_NAMESPACE + +class GUIUtil +{ +public: + static QString DateTimeStr(qint64 nTime); + + /* Render bitcoin addresses in monospace font */ + static QFont bitcoinAddressFont(); + + static void setupAddressWidget(QLineEdit *widget, QWidget *parent); + + static void setupAmountWidget(QLineEdit *widget, QWidget *parent); +}; #endif // GUIUTIL_H diff --git a/gui/src/addressbookdialog.cpp b/gui/src/addressbookdialog.cpp index ba6fdb51a0..853da5852e 100644 --- a/gui/src/addressbookdialog.cpp +++ b/gui/src/addressbookdialog.cpp @@ -87,14 +87,20 @@ void AddressBookDialog::on_copyToClipboard_clicked() void AddressBookDialog::on_editButton_clicked() { - /* Double click triggers edit button */ - EditAddressDialog dlg; + /* Double click also triggers edit button */ + EditAddressDialog dlg( + ui->tabWidget->currentIndex() == SendingTab ? + EditAddressDialog::EditSendingAddress : + EditAddressDialog::EditReceivingAddress); dlg.exec(); } void AddressBookDialog::on_newAddressButton_clicked() { - EditAddressDialog dlg; + EditAddressDialog dlg( + ui->tabWidget->currentIndex() == SendingTab ? + EditAddressDialog::NewSendingAddress : + EditAddressDialog::NewReceivingAddress); dlg.exec(); } @@ -103,10 +109,10 @@ void AddressBookDialog::on_tabWidget_currentChanged(int index) switch(index) { case SendingTab: - ui->deleteButton->show(); + ui->deleteButton->setEnabled(true); break; case ReceivingTab: - ui->deleteButton->hide(); + ui->deleteButton->setEnabled(false); break; } } diff --git a/gui/src/addresstablemodel.cpp b/gui/src/addresstablemodel.cpp index 21a9044271..c375ca7555 100644 --- a/gui/src/addresstablemodel.cpp +++ b/gui/src/addresstablemodel.cpp @@ -2,6 +2,8 @@ #include "guiutil.h" #include "main.h" +#include <QFont> + const QString AddressTableModel::Send = "S"; const QString AddressTableModel::Receive = "R"; @@ -108,7 +110,7 @@ QVariant AddressTableModel::data(const QModelIndex &index, int role) const { if(index.column() == Address) { - return bitcoinAddressFont(); + return GUIUtil::bitcoinAddressFont(); } } else if (role == TypeRole) { diff --git a/gui/src/bitcoinaddressvalidator.cpp b/gui/src/bitcoinaddressvalidator.cpp index 8e71916391..bccf445757 100644 --- a/gui/src/bitcoinaddressvalidator.cpp +++ b/gui/src/bitcoinaddressvalidator.cpp @@ -2,7 +2,44 @@ #include "base58.h" +#include <QDebug> + +/* Base58 characters are: + "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz" + + This is: + - All numbers except for '0' + - All uppercase letters except for 'I' and 'O' + - All lowercase letters except for 'l' + + User friendly Base58 input can map + - 'l' and 'I' to '1' + - '0' and 'O' to 'o' +*/ + BitcoinAddressValidator::BitcoinAddressValidator(QObject *parent) : QRegExpValidator(QRegExp(QString("^[")+QString(pszBase58)+QString("]+")), parent) { } + +QValidator::State BitcoinAddressValidator::validate(QString &input, int &pos) const +{ + for(int idx=0; idx<input.size(); ++idx) + { + switch(input.at(idx).unicode()) + { + case 'l': + case 'I': + input[idx] = QChar('1'); + break; + case '0': + case 'O': + input[idx] = QChar('o'); + break; + default: + break; + } + + } + return QRegExpValidator::validate(input, pos); +} diff --git a/gui/src/bitcoingui.cpp b/gui/src/bitcoingui.cpp index 0dc895dcc9..a7f2368034 100644 --- a/gui/src/bitcoingui.cpp +++ b/gui/src/bitcoingui.cpp @@ -10,6 +10,7 @@ #include "optionsdialog.h" #include "aboutdialog.h" #include "clientmodel.h" +#include "guiutil.h" #include "main.h" @@ -70,6 +71,7 @@ BitcoinGUI::BitcoinGUI(QWidget *parent): hbox_address->addWidget(new QLabel(tr("Your Bitcoin Address:"))); address = new QLineEdit(); address->setReadOnly(true); + address->setFont(GUIUtil::bitcoinAddressFont()); hbox_address->addWidget(address); QPushButton *button_new = new QPushButton(tr("&New...")); diff --git a/gui/src/editaddressdialog.cpp b/gui/src/editaddressdialog.cpp index bd5559792a..0699b56321 100644 --- a/gui/src/editaddressdialog.cpp +++ b/gui/src/editaddressdialog.cpp @@ -1,11 +1,14 @@ #include "editaddressdialog.h" #include "ui_editaddressdialog.h" +#include "guiutil.h" -EditAddressDialog::EditAddressDialog(QWidget *parent) : +EditAddressDialog::EditAddressDialog(Mode mode, QWidget *parent) : QDialog(parent), ui(new Ui::EditAddressDialog) { ui->setupUi(this); + + GUIUtil::setupAddressWidget(ui->addressEdit, this); } EditAddressDialog::~EditAddressDialog() diff --git a/gui/src/guiutil.cpp b/gui/src/guiutil.cpp index 59b4de305d..d01f23d851 100644 --- a/gui/src/guiutil.cpp +++ b/gui/src/guiutil.cpp @@ -1,16 +1,37 @@ #include "guiutil.h" +#include "bitcoinaddressvalidator.h" +#include <QString> #include <QDateTime> +#include <QDoubleValidator> +#include <QFont> +#include <QLineEdit> -QString DateTimeStr(qint64 nTime) +QString GUIUtil::DateTimeStr(qint64 nTime) { QDateTime date = QDateTime::fromMSecsSinceEpoch(nTime*1000); return date.date().toString(Qt::SystemLocaleShortDate) + QString(" ") + date.toString("hh:mm"); } -QFont bitcoinAddressFont() +QFont GUIUtil::bitcoinAddressFont() { QFont font("Monospace"); font.setStyleHint(QFont::TypeWriter); return font; } + +void GUIUtil::setupAddressWidget(QLineEdit *widget, QWidget *parent) +{ + widget->setMaxLength(BitcoinAddressValidator::MaxAddressLength); + widget->setValidator(new BitcoinAddressValidator(parent)); + widget->setFont(bitcoinAddressFont()); +} + +void GUIUtil::setupAmountWidget(QLineEdit *widget, QWidget *parent) +{ + QDoubleValidator *amountValidator = new QDoubleValidator(parent); + amountValidator->setDecimals(8); + amountValidator->setBottom(0.0); + widget->setValidator(amountValidator); +} + diff --git a/gui/src/sendcoinsdialog.cpp b/gui/src/sendcoinsdialog.cpp index a6ab601592..b50ed99099 100644 --- a/gui/src/sendcoinsdialog.cpp +++ b/gui/src/sendcoinsdialog.cpp @@ -1,9 +1,9 @@ #include "sendcoinsdialog.h" #include "ui_sendcoinsdialog.h" #include "clientmodel.h" +#include "guiutil.h" #include "addressbookdialog.h" -#include "bitcoinaddressvalidator.h" #include "optionsmodel.h" #include <QApplication> @@ -22,13 +22,8 @@ SendCoinsDialog::SendCoinsDialog(QWidget *parent, const QString &address) : { ui->setupUi(this); - /* Set up validators */ - ui->payTo->setMaxLength(BitcoinAddressValidator::MaxAddressLength); - ui->payTo->setValidator(new BitcoinAddressValidator(this)); - QDoubleValidator *amountValidator = new QDoubleValidator(this); - amountValidator->setDecimals(8); - amountValidator->setBottom(0.0); - ui->payAmount->setValidator(amountValidator); + GUIUtil::setupAddressWidget(ui->payTo, this); + GUIUtil::setupAmountWidget(ui->payAmount, this); /* Set initial address if provided */ if(!address.isEmpty()) diff --git a/gui/src/transactiontablemodel.cpp b/gui/src/transactiontablemodel.cpp index c7fb43edbe..e23f45dd0e 100644 --- a/gui/src/transactiontablemodel.cpp +++ b/gui/src/transactiontablemodel.cpp @@ -159,7 +159,7 @@ QVariant TransactionTableModel::formatTxStatus(const TransactionRecord *wtx) con status = tr("Open for %n block(s)","",wtx->status.open_for); break; case TransactionStatus::OpenUntilDate: - status = tr("Open until ") + DateTimeStr(wtx->status.open_for); + status = tr("Open until ") + GUIUtil::DateTimeStr(wtx->status.open_for); break; case TransactionStatus::Offline: status = tr("%1/offline").arg(wtx->status.depth); @@ -179,7 +179,7 @@ QVariant TransactionTableModel::formatTxDate(const TransactionRecord *wtx) const { if(wtx->time) { - return QVariant(DateTimeStr(wtx->time)); + return QVariant(GUIUtil::DateTimeStr(wtx->time)); } else { return QVariant(); } |