diff options
author | Wladimir J. van der Laan <laanwj@gmail.com> | 2011-05-31 22:24:53 +0200 |
---|---|---|
committer | Wladimir J. van der Laan <laanwj@gmail.com> | 2011-05-31 22:24:53 +0200 |
commit | 92f20d53fb946a6d87e0b3aff3fd258ea31338db (patch) | |
tree | 9d2daffbf99d595476ef411cab2346887248168c /gui | |
parent | 6630c1cbf5cb1f2672776ada14315dcdf058b567 (diff) |
implement options model, show current options in options dialog
Diffstat (limited to 'gui')
-rw-r--r-- | gui/include/clientmodel.h | 5 | ||||
-rw-r--r-- | gui/include/mainoptionspage.h | 21 | ||||
-rw-r--r-- | gui/include/optionsdialog.h | 10 | ||||
-rw-r--r-- | gui/include/optionsmodel.h | 34 | ||||
-rw-r--r-- | gui/src/bitcoingui.cpp | 1 | ||||
-rw-r--r-- | gui/src/clientmodel.cpp | 9 | ||||
-rw-r--r-- | gui/src/mainoptionspage.cpp | 33 | ||||
-rw-r--r-- | gui/src/optionsdialog.cpp | 23 | ||||
-rw-r--r-- | gui/src/optionsmodel.cpp | 52 | ||||
-rw-r--r-- | gui/src/sendcoinsdialog.cpp | 5 |
10 files changed, 175 insertions, 18 deletions
diff --git a/gui/include/clientmodel.h b/gui/include/clientmodel.h index 828c80f8db..44f1c0ab64 100644 --- a/gui/include/clientmodel.h +++ b/gui/include/clientmodel.h @@ -2,6 +2,7 @@ #define CLIENTMODEL_H #include <QObject> +class OptionsModel; class ClientModel : public QObject { @@ -20,6 +21,8 @@ public: MiscError }; + OptionsModel *getOptionsModel(); + qint64 getBalance(); QString getAddress(); int getNumConnections(); @@ -29,6 +32,8 @@ public: qint64 getTransactionFee(); StatusCode sendCoins(const QString &payTo, qint64 payAmount); +private: + OptionsModel *options_model; signals: void balanceChanged(qint64 balance); diff --git a/gui/include/mainoptionspage.h b/gui/include/mainoptionspage.h index de2ef9fcd0..4ef5e60a25 100644 --- a/gui/include/mainoptionspage.h +++ b/gui/include/mainoptionspage.h @@ -3,11 +3,30 @@ #include <QWidget> +QT_BEGIN_NAMESPACE +class QDataWidgetMapper; +class QCheckBox; +class QLineEdit; +QT_END_NAMESPACE + +class OptionsModel; + class MainOptionsPage : public QWidget { Q_OBJECT public: - explicit MainOptionsPage(QWidget *parent = 0); + explicit MainOptionsPage(QWidget *parent=0); + + void setMapper(QDataWidgetMapper *mapper); +private: + QCheckBox *bitcoin_at_startup; + QCheckBox *minimize_to_tray; + QCheckBox *map_port_upnp; + QCheckBox *minimize_on_close; + QCheckBox *connect_socks4; + QLineEdit *proxy_ip; + QLineEdit *proxy_port; + QLineEdit *fee_edit; signals: diff --git a/gui/include/optionsdialog.h b/gui/include/optionsdialog.h index 501c82e9f3..c064b0a93c 100644 --- a/gui/include/optionsdialog.h +++ b/gui/include/optionsdialog.h @@ -7,13 +7,18 @@ QT_BEGIN_NAMESPACE class QStackedWidget; class QListWidget; class QListWidgetItem; +class QDataWidgetMapper; QT_END_NAMESPACE +class OptionsModel; +class MainOptionsPage; class OptionsDialog : public QDialog { Q_OBJECT public: - explicit OptionsDialog(QWidget *parent = 0); + explicit OptionsDialog(QWidget *parent=0); + + void setModel(OptionsModel *model); signals: @@ -22,6 +27,9 @@ public slots: private: QListWidget *contents_widget; QStackedWidget *pages_widget; + MainOptionsPage *main_options_page; + OptionsModel *model; + QDataWidgetMapper *mapper; void setupMainPage(); }; diff --git a/gui/include/optionsmodel.h b/gui/include/optionsmodel.h new file mode 100644 index 0000000000..4dd21c7f07 --- /dev/null +++ b/gui/include/optionsmodel.h @@ -0,0 +1,34 @@ +#ifndef OPTIONSMODEL_H +#define OPTIONSMODEL_H + +#include <QAbstractListModel> + +class OptionsModel : public QAbstractListModel +{ + Q_OBJECT +public: + explicit OptionsModel(QObject *parent = 0); + + enum OptionID { + StartAtStartup, + MinimizeToTray, + MapPortUPnP, + MinimizeOnClose, + ConnectSOCKS4, + ProxyIP, + ProxyPort, + Fee, + OptionIDRowCount + }; + + int rowCount(const QModelIndex & parent = QModelIndex()) const; + QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const; + bool setData(const QModelIndex & index, const QVariant & value, int role = Qt::EditRole); + +signals: + +public slots: + +}; + +#endif // OPTIONSMODEL_H diff --git a/gui/src/bitcoingui.cpp b/gui/src/bitcoingui.cpp index 66a3edd3ad..66891222a8 100644 --- a/gui/src/bitcoingui.cpp +++ b/gui/src/bitcoingui.cpp @@ -256,6 +256,7 @@ void BitcoinGUI::receivingAddressesClicked() void BitcoinGUI::optionsClicked() { OptionsDialog dlg; + dlg.setModel(model->getOptionsModel()); dlg.exec(); } diff --git a/gui/src/clientmodel.cpp b/gui/src/clientmodel.cpp index be8b0b4183..35824720df 100644 --- a/gui/src/clientmodel.cpp +++ b/gui/src/clientmodel.cpp @@ -1,11 +1,12 @@ #include "clientmodel.h" #include "main.h" #include "guiconstants.h" +#include "optionsmodel.h" #include <QTimer> ClientModel::ClientModel(QObject *parent) : - QObject(parent) + QObject(parent), options_model(0) { /* Until we build signal notifications into the bitcoin core, simply update everything using a timer. @@ -13,6 +14,8 @@ ClientModel::ClientModel(QObject *parent) : QTimer *timer = new QTimer(this); connect(timer, SIGNAL(timeout()), this, SLOT(update())); timer->start(MODEL_UPDATE_DELAY); + + options_model = new OptionsModel(this); } qint64 ClientModel::getBalance() @@ -112,3 +115,7 @@ ClientModel::StatusCode ClientModel::sendCoins(const QString &payTo, qint64 payA return OK; } +OptionsModel *ClientModel::getOptionsModel() +{ + return options_model; +} diff --git a/gui/src/mainoptionspage.cpp b/gui/src/mainoptionspage.cpp index 021e1e470f..3d69baeda7 100644 --- a/gui/src/mainoptionspage.cpp +++ b/gui/src/mainoptionspage.cpp @@ -1,42 +1,45 @@ #include "mainoptionspage.h" +#include "optionsmodel.h" #include <QHBoxLayout> #include <QVBoxLayout> #include <QCheckBox> #include <QLabel> #include <QLineEdit> +#include <QDataWidgetMapper> +#include <QDebug> MainOptionsPage::MainOptionsPage(QWidget *parent): QWidget(parent) { QVBoxLayout *layout = new QVBoxLayout(); - QCheckBox *bitcoin_at_startup = new QCheckBox(tr("&Start Bitcoin on window system startup")); + bitcoin_at_startup = new QCheckBox(tr("&Start Bitcoin on window system startup")); layout->addWidget(bitcoin_at_startup); - QCheckBox *minimize_to_tray = new QCheckBox(tr("&Minimize to the tray instead of the taskbar")); + minimize_to_tray = new QCheckBox(tr("&Minimize to the tray instead of the taskbar")); layout->addWidget(minimize_to_tray); - QCheckBox *map_port_upnp = new QCheckBox(tr("Map port using &UPnP")); + map_port_upnp = new QCheckBox(tr("Map port using &UPnP")); layout->addWidget(map_port_upnp); - QCheckBox *minimize_on_close = new QCheckBox(tr("M&inimize on close")); + minimize_on_close = new QCheckBox(tr("M&inimize on close")); layout->addWidget(minimize_on_close); - QCheckBox *connect_socks4 = new QCheckBox(tr("&Connect through socks4 proxy:")); + connect_socks4 = new QCheckBox(tr("&Connect through socks4 proxy:")); layout->addWidget(connect_socks4); QHBoxLayout *proxy_hbox = new QHBoxLayout(); proxy_hbox->addSpacing(18); QLabel *proxy_ip_label = new QLabel(tr("Proxy &IP: ")); proxy_hbox->addWidget(proxy_ip_label); - QLineEdit *proxy_ip = new QLineEdit(); + proxy_ip = new QLineEdit(); proxy_ip->setMaximumWidth(140); proxy_ip_label->setBuddy(proxy_ip); proxy_hbox->addWidget(proxy_ip); QLabel *proxy_port_label = new QLabel(tr("&Port: ")); proxy_hbox->addWidget(proxy_port_label); - QLineEdit *proxy_port = new QLineEdit(); + proxy_port = new QLineEdit(); proxy_port->setMaximumWidth(55); proxy_port_label->setBuddy(proxy_port); proxy_hbox->addWidget(proxy_port); @@ -51,7 +54,7 @@ MainOptionsPage::MainOptionsPage(QWidget *parent): fee_hbox->addSpacing(18); QLabel *fee_label = new QLabel(tr("Pay transaction &fee")); fee_hbox->addWidget(fee_label); - QLineEdit *fee_edit = new QLineEdit(); + fee_edit = new QLineEdit(); fee_edit->setMaximumWidth(70); fee_label->setBuddy(fee_edit); fee_hbox->addWidget(fee_edit); @@ -59,9 +62,21 @@ MainOptionsPage::MainOptionsPage(QWidget *parent): layout->addLayout(fee_hbox); - layout->addStretch(1); /* Extra space at bottom */ setLayout(layout); } +void MainOptionsPage::setMapper(QDataWidgetMapper *mapper) +{ + /* Map model to widgets */ + mapper->addMapping(bitcoin_at_startup, OptionsModel::StartAtStartup); + mapper->addMapping(minimize_to_tray, OptionsModel::MinimizeToTray); + mapper->addMapping(map_port_upnp, OptionsModel::MapPortUPnP); + mapper->addMapping(minimize_on_close, OptionsModel::MinimizeOnClose); + mapper->addMapping(connect_socks4, OptionsModel::ConnectSOCKS4); + mapper->addMapping(proxy_ip, OptionsModel::ProxyIP); + mapper->addMapping(proxy_port, OptionsModel::ProxyPort); + mapper->addMapping(fee_edit, OptionsModel::Fee); +} + diff --git a/gui/src/optionsdialog.cpp b/gui/src/optionsdialog.cpp index 70dd86323e..e1f3d67dd7 100644 --- a/gui/src/optionsdialog.cpp +++ b/gui/src/optionsdialog.cpp @@ -1,4 +1,5 @@ #include "optionsdialog.h" +#include "optionsmodel.h" #include "mainoptionspage.h" #include <QHBoxLayout> @@ -6,9 +7,11 @@ #include <QPushButton> #include <QListWidget> #include <QStackedWidget> +#include <QDataWidgetMapper> -OptionsDialog::OptionsDialog(QWidget *parent) : - QDialog(parent), contents_widget(0), pages_widget(0) +OptionsDialog::OptionsDialog(QWidget *parent): + QDialog(parent), contents_widget(0), pages_widget(0), + main_options_page(0), model(0) { contents_widget = new QListWidget(); contents_widget->setMaximumWidth(128); @@ -18,7 +21,8 @@ OptionsDialog::OptionsDialog(QWidget *parent) : QListWidgetItem *item_main = new QListWidgetItem(tr("Main")); contents_widget->addItem(item_main); - pages_widget->addWidget(new MainOptionsPage(this)); + main_options_page = new MainOptionsPage(this); + pages_widget->addWidget(main_options_page); contents_widget->setCurrentRow(0); @@ -40,11 +44,22 @@ OptionsDialog::OptionsDialog(QWidget *parent) : layout->addLayout(buttons); - setLayout(layout); setWindowTitle(tr("Options")); + mapper = new QDataWidgetMapper(); + mapper->setSubmitPolicy(QDataWidgetMapper::ManualSubmit); + mapper->setOrientation(Qt::Vertical); +} + +void OptionsDialog::setModel(OptionsModel *model) +{ + this->model = model; + + mapper->setModel(model); + main_options_page->setMapper(mapper); + mapper->toFirst(); } void OptionsDialog::changePage(QListWidgetItem *current, QListWidgetItem *previous) diff --git a/gui/src/optionsmodel.cpp b/gui/src/optionsmodel.cpp new file mode 100644 index 0000000000..25c7366c13 --- /dev/null +++ b/gui/src/optionsmodel.cpp @@ -0,0 +1,52 @@ +#include "optionsmodel.h" +#include "main.h" + +#include <QDebug> + +OptionsModel::OptionsModel(QObject *parent) : + QAbstractListModel(parent) +{ +} + +int OptionsModel::rowCount(const QModelIndex & parent) const +{ + return OptionIDRowCount; +} + +QVariant OptionsModel::data(const QModelIndex & index, int role) const +{ + qDebug() << "OptionsModel::data" << " " << index.row() << " " << role; + if(role == Qt::EditRole) + { + /* Delegate to specific column handlers */ + switch(index.row()) + { + case StartAtStartup: + return QVariant(); + case MinimizeToTray: + return QVariant(fMinimizeToTray); + case MapPortUPnP: + return QVariant(fUseUPnP); + case MinimizeOnClose: + return QVariant(fMinimizeOnClose); + case ConnectSOCKS4: + return QVariant(fUseProxy); + case ProxyIP: + return QVariant(QString::fromStdString(addrProxy.ToStringIP())); + case ProxyPort: + return QVariant(QString::fromStdString(addrProxy.ToStringPort())); + case Fee: + return QVariant(QString::fromStdString(FormatMoney(nTransactionFee))); + default: + return QVariant(); + } + } + return QVariant(); +} + +bool OptionsModel::setData(const QModelIndex & index, const QVariant & value, int role) +{ + qDebug() << "OptionsModel::setData" << " " << index.row() << "=" << value; + emit dataChanged(index, index); + return true; +} diff --git a/gui/src/sendcoinsdialog.cpp b/gui/src/sendcoinsdialog.cpp index 398e236ee5..9040d21fb3 100644 --- a/gui/src/sendcoinsdialog.cpp +++ b/gui/src/sendcoinsdialog.cpp @@ -90,9 +90,10 @@ void SendCoinsDialog::on_sendButton_clicked() QMessageBox::Ok, QMessageBox::Ok); ui->payAmount->setFocus(); break; + case ClientModel::OK: + accept(); + break; } - /* TODO: send command to core, once this succeeds do accept() */ - //accept(); } void SendCoinsDialog::on_pasteButton_clicked() |