mirror of
https://github.com/twisterarmy/twister-core.git
synced 2025-01-14 16:57:57 +00:00
implement options model, show current options in options dialog
This commit is contained in:
parent
6630c1cbf5
commit
92f20d53fb
@ -60,7 +60,8 @@ HEADERS += gui/include/bitcoingui.h \
|
|||||||
gui/include/clientmodel.h \
|
gui/include/clientmodel.h \
|
||||||
gui/include/guiutil.h \
|
gui/include/guiutil.h \
|
||||||
gui/include/transactionrecord.h \
|
gui/include/transactionrecord.h \
|
||||||
gui/include/guiconstants.h
|
gui/include/guiconstants.h \
|
||||||
|
gui/include/optionsmodel.h
|
||||||
SOURCES += gui/src/bitcoin.cpp gui/src/bitcoingui.cpp \
|
SOURCES += gui/src/bitcoin.cpp gui/src/bitcoingui.cpp \
|
||||||
gui/src/transactiontablemodel.cpp \
|
gui/src/transactiontablemodel.cpp \
|
||||||
gui/src/addresstablemodel.cpp \
|
gui/src/addresstablemodel.cpp \
|
||||||
@ -86,7 +87,8 @@ SOURCES += gui/src/bitcoin.cpp gui/src/bitcoingui.cpp \
|
|||||||
json/src/json_spirit_reader.cpp \
|
json/src/json_spirit_reader.cpp \
|
||||||
gui/src/clientmodel.cpp \
|
gui/src/clientmodel.cpp \
|
||||||
gui/src/guiutil.cpp \
|
gui/src/guiutil.cpp \
|
||||||
gui/src/transactionrecord.cpp
|
gui/src/transactionrecord.cpp \
|
||||||
|
gui/src/optionsmodel.cpp
|
||||||
|
|
||||||
RESOURCES += \
|
RESOURCES += \
|
||||||
gui/bitcoin.qrc
|
gui/bitcoin.qrc
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
#define CLIENTMODEL_H
|
#define CLIENTMODEL_H
|
||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
|
class OptionsModel;
|
||||||
|
|
||||||
class ClientModel : public QObject
|
class ClientModel : public QObject
|
||||||
{
|
{
|
||||||
@ -20,6 +21,8 @@ public:
|
|||||||
MiscError
|
MiscError
|
||||||
};
|
};
|
||||||
|
|
||||||
|
OptionsModel *getOptionsModel();
|
||||||
|
|
||||||
qint64 getBalance();
|
qint64 getBalance();
|
||||||
QString getAddress();
|
QString getAddress();
|
||||||
int getNumConnections();
|
int getNumConnections();
|
||||||
@ -29,6 +32,8 @@ public:
|
|||||||
qint64 getTransactionFee();
|
qint64 getTransactionFee();
|
||||||
|
|
||||||
StatusCode sendCoins(const QString &payTo, qint64 payAmount);
|
StatusCode sendCoins(const QString &payTo, qint64 payAmount);
|
||||||
|
private:
|
||||||
|
OptionsModel *options_model;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void balanceChanged(qint64 balance);
|
void balanceChanged(qint64 balance);
|
||||||
|
@ -3,11 +3,30 @@
|
|||||||
|
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
|
|
||||||
|
QT_BEGIN_NAMESPACE
|
||||||
|
class QDataWidgetMapper;
|
||||||
|
class QCheckBox;
|
||||||
|
class QLineEdit;
|
||||||
|
QT_END_NAMESPACE
|
||||||
|
|
||||||
|
class OptionsModel;
|
||||||
|
|
||||||
class MainOptionsPage : public QWidget
|
class MainOptionsPage : public QWidget
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
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:
|
signals:
|
||||||
|
|
||||||
|
@ -7,13 +7,18 @@ QT_BEGIN_NAMESPACE
|
|||||||
class QStackedWidget;
|
class QStackedWidget;
|
||||||
class QListWidget;
|
class QListWidget;
|
||||||
class QListWidgetItem;
|
class QListWidgetItem;
|
||||||
|
class QDataWidgetMapper;
|
||||||
QT_END_NAMESPACE
|
QT_END_NAMESPACE
|
||||||
|
class OptionsModel;
|
||||||
|
class MainOptionsPage;
|
||||||
|
|
||||||
class OptionsDialog : public QDialog
|
class OptionsDialog : public QDialog
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit OptionsDialog(QWidget *parent = 0);
|
explicit OptionsDialog(QWidget *parent=0);
|
||||||
|
|
||||||
|
void setModel(OptionsModel *model);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
|
||||||
@ -22,6 +27,9 @@ public slots:
|
|||||||
private:
|
private:
|
||||||
QListWidget *contents_widget;
|
QListWidget *contents_widget;
|
||||||
QStackedWidget *pages_widget;
|
QStackedWidget *pages_widget;
|
||||||
|
MainOptionsPage *main_options_page;
|
||||||
|
OptionsModel *model;
|
||||||
|
QDataWidgetMapper *mapper;
|
||||||
|
|
||||||
void setupMainPage();
|
void setupMainPage();
|
||||||
};
|
};
|
||||||
|
34
gui/include/optionsmodel.h
Normal file
34
gui/include/optionsmodel.h
Normal file
@ -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
|
@ -256,6 +256,7 @@ void BitcoinGUI::receivingAddressesClicked()
|
|||||||
void BitcoinGUI::optionsClicked()
|
void BitcoinGUI::optionsClicked()
|
||||||
{
|
{
|
||||||
OptionsDialog dlg;
|
OptionsDialog dlg;
|
||||||
|
dlg.setModel(model->getOptionsModel());
|
||||||
dlg.exec();
|
dlg.exec();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,11 +1,12 @@
|
|||||||
#include "clientmodel.h"
|
#include "clientmodel.h"
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
#include "guiconstants.h"
|
#include "guiconstants.h"
|
||||||
|
#include "optionsmodel.h"
|
||||||
|
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
|
|
||||||
ClientModel::ClientModel(QObject *parent) :
|
ClientModel::ClientModel(QObject *parent) :
|
||||||
QObject(parent)
|
QObject(parent), options_model(0)
|
||||||
{
|
{
|
||||||
/* Until we build signal notifications into the bitcoin core,
|
/* Until we build signal notifications into the bitcoin core,
|
||||||
simply update everything using a timer.
|
simply update everything using a timer.
|
||||||
@ -13,6 +14,8 @@ ClientModel::ClientModel(QObject *parent) :
|
|||||||
QTimer *timer = new QTimer(this);
|
QTimer *timer = new QTimer(this);
|
||||||
connect(timer, SIGNAL(timeout()), this, SLOT(update()));
|
connect(timer, SIGNAL(timeout()), this, SLOT(update()));
|
||||||
timer->start(MODEL_UPDATE_DELAY);
|
timer->start(MODEL_UPDATE_DELAY);
|
||||||
|
|
||||||
|
options_model = new OptionsModel(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
qint64 ClientModel::getBalance()
|
qint64 ClientModel::getBalance()
|
||||||
@ -112,3 +115,7 @@ ClientModel::StatusCode ClientModel::sendCoins(const QString &payTo, qint64 payA
|
|||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
OptionsModel *ClientModel::getOptionsModel()
|
||||||
|
{
|
||||||
|
return options_model;
|
||||||
|
}
|
||||||
|
@ -1,42 +1,45 @@
|
|||||||
#include "mainoptionspage.h"
|
#include "mainoptionspage.h"
|
||||||
|
#include "optionsmodel.h"
|
||||||
|
|
||||||
#include <QHBoxLayout>
|
#include <QHBoxLayout>
|
||||||
#include <QVBoxLayout>
|
#include <QVBoxLayout>
|
||||||
#include <QCheckBox>
|
#include <QCheckBox>
|
||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
#include <QLineEdit>
|
#include <QLineEdit>
|
||||||
|
#include <QDataWidgetMapper>
|
||||||
|
#include <QDebug>
|
||||||
|
|
||||||
MainOptionsPage::MainOptionsPage(QWidget *parent):
|
MainOptionsPage::MainOptionsPage(QWidget *parent):
|
||||||
QWidget(parent)
|
QWidget(parent)
|
||||||
{
|
{
|
||||||
QVBoxLayout *layout = new QVBoxLayout();
|
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);
|
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);
|
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);
|
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);
|
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);
|
layout->addWidget(connect_socks4);
|
||||||
|
|
||||||
QHBoxLayout *proxy_hbox = new QHBoxLayout();
|
QHBoxLayout *proxy_hbox = new QHBoxLayout();
|
||||||
proxy_hbox->addSpacing(18);
|
proxy_hbox->addSpacing(18);
|
||||||
QLabel *proxy_ip_label = new QLabel(tr("Proxy &IP: "));
|
QLabel *proxy_ip_label = new QLabel(tr("Proxy &IP: "));
|
||||||
proxy_hbox->addWidget(proxy_ip_label);
|
proxy_hbox->addWidget(proxy_ip_label);
|
||||||
QLineEdit *proxy_ip = new QLineEdit();
|
proxy_ip = new QLineEdit();
|
||||||
proxy_ip->setMaximumWidth(140);
|
proxy_ip->setMaximumWidth(140);
|
||||||
proxy_ip_label->setBuddy(proxy_ip);
|
proxy_ip_label->setBuddy(proxy_ip);
|
||||||
proxy_hbox->addWidget(proxy_ip);
|
proxy_hbox->addWidget(proxy_ip);
|
||||||
QLabel *proxy_port_label = new QLabel(tr("&Port: "));
|
QLabel *proxy_port_label = new QLabel(tr("&Port: "));
|
||||||
proxy_hbox->addWidget(proxy_port_label);
|
proxy_hbox->addWidget(proxy_port_label);
|
||||||
QLineEdit *proxy_port = new QLineEdit();
|
proxy_port = new QLineEdit();
|
||||||
proxy_port->setMaximumWidth(55);
|
proxy_port->setMaximumWidth(55);
|
||||||
proxy_port_label->setBuddy(proxy_port);
|
proxy_port_label->setBuddy(proxy_port);
|
||||||
proxy_hbox->addWidget(proxy_port);
|
proxy_hbox->addWidget(proxy_port);
|
||||||
@ -51,7 +54,7 @@ MainOptionsPage::MainOptionsPage(QWidget *parent):
|
|||||||
fee_hbox->addSpacing(18);
|
fee_hbox->addSpacing(18);
|
||||||
QLabel *fee_label = new QLabel(tr("Pay transaction &fee"));
|
QLabel *fee_label = new QLabel(tr("Pay transaction &fee"));
|
||||||
fee_hbox->addWidget(fee_label);
|
fee_hbox->addWidget(fee_label);
|
||||||
QLineEdit *fee_edit = new QLineEdit();
|
fee_edit = new QLineEdit();
|
||||||
fee_edit->setMaximumWidth(70);
|
fee_edit->setMaximumWidth(70);
|
||||||
fee_label->setBuddy(fee_edit);
|
fee_label->setBuddy(fee_edit);
|
||||||
fee_hbox->addWidget(fee_edit);
|
fee_hbox->addWidget(fee_edit);
|
||||||
@ -59,9 +62,21 @@ MainOptionsPage::MainOptionsPage(QWidget *parent):
|
|||||||
|
|
||||||
layout->addLayout(fee_hbox);
|
layout->addLayout(fee_hbox);
|
||||||
|
|
||||||
|
|
||||||
layout->addStretch(1); /* Extra space at bottom */
|
layout->addStretch(1); /* Extra space at bottom */
|
||||||
|
|
||||||
setLayout(layout);
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
#include "optionsdialog.h"
|
#include "optionsdialog.h"
|
||||||
|
#include "optionsmodel.h"
|
||||||
#include "mainoptionspage.h"
|
#include "mainoptionspage.h"
|
||||||
|
|
||||||
#include <QHBoxLayout>
|
#include <QHBoxLayout>
|
||||||
@ -6,9 +7,11 @@
|
|||||||
#include <QPushButton>
|
#include <QPushButton>
|
||||||
#include <QListWidget>
|
#include <QListWidget>
|
||||||
#include <QStackedWidget>
|
#include <QStackedWidget>
|
||||||
|
#include <QDataWidgetMapper>
|
||||||
|
|
||||||
OptionsDialog::OptionsDialog(QWidget *parent) :
|
OptionsDialog::OptionsDialog(QWidget *parent):
|
||||||
QDialog(parent), contents_widget(0), pages_widget(0)
|
QDialog(parent), contents_widget(0), pages_widget(0),
|
||||||
|
main_options_page(0), model(0)
|
||||||
{
|
{
|
||||||
contents_widget = new QListWidget();
|
contents_widget = new QListWidget();
|
||||||
contents_widget->setMaximumWidth(128);
|
contents_widget->setMaximumWidth(128);
|
||||||
@ -18,7 +21,8 @@ OptionsDialog::OptionsDialog(QWidget *parent) :
|
|||||||
|
|
||||||
QListWidgetItem *item_main = new QListWidgetItem(tr("Main"));
|
QListWidgetItem *item_main = new QListWidgetItem(tr("Main"));
|
||||||
contents_widget->addItem(item_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);
|
contents_widget->setCurrentRow(0);
|
||||||
|
|
||||||
@ -40,11 +44,22 @@ OptionsDialog::OptionsDialog(QWidget *parent) :
|
|||||||
|
|
||||||
layout->addLayout(buttons);
|
layout->addLayout(buttons);
|
||||||
|
|
||||||
|
|
||||||
setLayout(layout);
|
setLayout(layout);
|
||||||
setWindowTitle(tr("Options"));
|
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)
|
void OptionsDialog::changePage(QListWidgetItem *current, QListWidgetItem *previous)
|
||||||
|
52
gui/src/optionsmodel.cpp
Normal file
52
gui/src/optionsmodel.cpp
Normal file
@ -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;
|
||||||
|
}
|
@ -90,9 +90,10 @@ void SendCoinsDialog::on_sendButton_clicked()
|
|||||||
QMessageBox::Ok, QMessageBox::Ok);
|
QMessageBox::Ok, QMessageBox::Ok);
|
||||||
ui->payAmount->setFocus();
|
ui->payAmount->setFocus();
|
||||||
break;
|
break;
|
||||||
|
case ClientModel::OK:
|
||||||
|
accept();
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
/* TODO: send command to core, once this succeeds do accept() */
|
|
||||||
//accept();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SendCoinsDialog::on_pasteButton_clicked()
|
void SendCoinsDialog::on_pasteButton_clicked()
|
||||||
|
Loading…
Reference in New Issue
Block a user