Browse Source

Merge pull request #1220 from laanwj/2012_05_organize_optionsdialog

Organize optionsdialog (split off Window and Network page) and add option to change language
miguelfreitas
Wladimir J. van der Laan 13 years ago
parent
commit
0981b80c29
  1. 289
      src/qt/optionsdialog.cpp
  2. 10
      src/qt/optionsdialog.h
  3. 9
      src/qt/optionsmodel.cpp
  4. 3
      src/qt/optionsmodel.h
  5. 6
      src/qt/qvaluecombobox.cpp
  6. 9
      src/qt/qvaluecombobox.h

289
src/qt/optionsdialog.cpp

@ -19,73 +19,103 @@
#include <QDoubleValidator> #include <QDoubleValidator>
#include <QRegExpValidator> #include <QRegExpValidator>
#include <QDialogButtonBox> #include <QDialogButtonBox>
#include <QDir>
#include <QMessageBox>
/* First page of options */ class OptionsPage: public QWidget
class MainOptionsPage : public QWidget {
Q_OBJECT
public:
explicit OptionsPage(QWidget *parent=0): QWidget(parent) {}
virtual void setMapper(MonitoredDataMapper *mapper) = 0;
};
class MainOptionsPage: public OptionsPage
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit MainOptionsPage(QWidget *parent=0); explicit MainOptionsPage(QWidget *parent=0);
void setMapper(MonitoredDataMapper *mapper); virtual void setMapper(MonitoredDataMapper *mapper);
private:
QCheckBox *detach_database;
BitcoinAmountField *fee_edit;
};
class WindowOptionsPage: public OptionsPage
{
Q_OBJECT
public:
explicit WindowOptionsPage(QWidget *parent=0);
virtual void setMapper(MonitoredDataMapper *mapper);
private: private:
QCheckBox *bitcoin_at_startup; QCheckBox *bitcoin_at_startup;
#ifndef Q_WS_MAC #ifndef Q_WS_MAC
QCheckBox *minimize_to_tray; QCheckBox *minimize_to_tray;
#endif #endif
QCheckBox *map_port_upnp;
#ifndef Q_WS_MAC #ifndef Q_WS_MAC
QCheckBox *minimize_on_close; QCheckBox *minimize_on_close;
#endif #endif
QCheckBox *connect_socks4;
QCheckBox *detach_database;
QLineEdit *proxy_ip;
QLineEdit *proxy_port;
BitcoinAmountField *fee_edit;
signals:
public slots:
}; };
class DisplayOptionsPage : public QWidget class DisplayOptionsPage: public OptionsPage
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit DisplayOptionsPage(QWidget *parent=0); explicit DisplayOptionsPage(QWidget *parent=0);
void setMapper(MonitoredDataMapper *mapper); virtual void setMapper(MonitoredDataMapper *mapper);
private: private:
QValueComboBox *lang;
QValueComboBox *unit; QValueComboBox *unit;
QCheckBox *display_addresses; QCheckBox *display_addresses;
signals: bool restart_warning_displayed;
private slots:
void showRestartWarning();
};
public slots: class NetworkOptionsPage: public OptionsPage
{
Q_OBJECT
public:
explicit NetworkOptionsPage(QWidget *parent=0);
virtual void setMapper(MonitoredDataMapper *mapper);
private:
QCheckBox *map_port_upnp;
QCheckBox *connect_socks4;
QLineEdit *proxy_ip;
QLineEdit *proxy_port;
BitcoinAmountField *fee_edit;
}; };
#include "optionsdialog.moc" #include "optionsdialog.moc"
OptionsDialog::OptionsDialog(QWidget *parent): OptionsDialog::OptionsDialog(QWidget *parent):
QDialog(parent), contents_widget(0), pages_widget(0), QDialog(parent), contents_widget(0), pages_widget(0),
model(0), main_page(0), display_page(0) model(0)
{ {
contents_widget = new QListWidget(); contents_widget = new QListWidget();
contents_widget->setMaximumWidth(128); contents_widget->setMaximumWidth(128);
pages_widget = new QStackedWidget(); pages_widget = new QStackedWidget();
pages_widget->setMinimumWidth(300); pages_widget->setMinimumWidth(500);
pages_widget->setMinimumHeight(300);
QListWidgetItem *item_main = new QListWidgetItem(tr("Main")); pages.append(new MainOptionsPage(this));
contents_widget->addItem(item_main); pages.append(new NetworkOptionsPage(this));
main_page = new MainOptionsPage(this); pages.append(new WindowOptionsPage(this));
pages_widget->addWidget(main_page); pages.append(new DisplayOptionsPage(this));
QListWidgetItem *item_display = new QListWidgetItem(tr("Display")); foreach(OptionsPage *page, pages)
contents_widget->addItem(item_display); {
display_page = new DisplayOptionsPage(this); QListWidgetItem *item = new QListWidgetItem(page->windowTitle());
pages_widget->addWidget(display_page); contents_widget->addItem(item);
pages_widget->addWidget(page);
}
contents_widget->setCurrentRow(0); contents_widget->setCurrentRow(0);
@ -125,8 +155,11 @@ void OptionsDialog::setModel(OptionsModel *model)
this->model = model; this->model = model;
mapper->setModel(model); mapper->setModel(model);
main_page->setMapper(mapper);
display_page->setMapper(mapper); foreach(OptionsPage *page, pages)
{
page->setMapper(mapper);
}
mapper->toFirst(); mapper->toFirst();
} }
@ -163,10 +196,116 @@ void OptionsDialog::disableApply()
apply_button->setEnabled(false); apply_button->setEnabled(false);
} }
/* Main options */
MainOptionsPage::MainOptionsPage(QWidget *parent): MainOptionsPage::MainOptionsPage(QWidget *parent):
QWidget(parent) OptionsPage(parent)
{
QVBoxLayout *layout = new QVBoxLayout();
setWindowTitle(tr("Main"));
QLabel *fee_help = new QLabel(tr("Optional transaction fee per kB that helps make sure your transactions are processed quickly. Most transactions are 1 kB. Fee 0.01 recommended."));
fee_help->setWordWrap(true);
layout->addWidget(fee_help);
QHBoxLayout *fee_hbox = new QHBoxLayout();
fee_hbox->addSpacing(18);
QLabel *fee_label = new QLabel(tr("Pay transaction &fee"));
fee_hbox->addWidget(fee_label);
fee_edit = new BitcoinAmountField();
fee_label->setBuddy(fee_edit);
fee_hbox->addWidget(fee_edit);
fee_hbox->addStretch(1);
layout->addLayout(fee_hbox);
detach_database = new QCheckBox(tr("Detach databases at shutdown"));
detach_database->setToolTip(tr("Detach block and address databases at shutdown. This means they can be moved to another data directory, but it slows down shutdown. The wallet is always detached."));
layout->addWidget(detach_database);
layout->addStretch(1); // Extra space at bottom
setLayout(layout);
}
void MainOptionsPage::setMapper(MonitoredDataMapper *mapper)
{
// Map model to widgets
mapper->addMapping(fee_edit, OptionsModel::Fee);
mapper->addMapping(detach_database, OptionsModel::DetachDatabases);
}
/* Display options */
DisplayOptionsPage::DisplayOptionsPage(QWidget *parent):
OptionsPage(parent), restart_warning_displayed(false)
{
setWindowTitle(tr("Display"));
QVBoxLayout *layout = new QVBoxLayout();
QHBoxLayout *lang_hbox = new QHBoxLayout();
lang_hbox->addSpacing(18);
QLabel *lang_label = new QLabel(tr("User Interface &Language: "));
lang_hbox->addWidget(lang_label);
lang = new QValueComboBox(this);
// Make list of languages
QDir translations(":translations");
lang->addItem("(default)", QVariant(""));
foreach(const QString &langStr, translations.entryList())
{
lang->addItem(langStr, QVariant(langStr));
}
lang->setToolTip(tr("The user interface language can be set here. This setting will only take effect after restarting Bitcoin."));
connect(lang, SIGNAL(activated(int)), this, SLOT(showRestartWarning()));
lang_label->setBuddy(lang);
lang_hbox->addWidget(lang);
layout->addLayout(lang_hbox);
QHBoxLayout *unit_hbox = new QHBoxLayout();
unit_hbox->addSpacing(18);
QLabel *unit_label = new QLabel(tr("&Unit to show amounts in: "));
unit_hbox->addWidget(unit_label);
unit = new QValueComboBox(this);
unit->setModel(new BitcoinUnits(this));
unit->setToolTip(tr("Choose the default subdivision unit to show in the interface, and when sending coins"));
unit_label->setBuddy(unit);
unit_hbox->addWidget(unit);
layout->addLayout(unit_hbox);
display_addresses = new QCheckBox(tr("&Display addresses in transaction list"), this);
display_addresses->setToolTip(tr("Whether to show Bitcoin addresses in the transaction list"));
layout->addWidget(display_addresses);
layout->addStretch();
setLayout(layout);
}
void DisplayOptionsPage::setMapper(MonitoredDataMapper *mapper)
{
mapper->addMapping(lang, OptionsModel::Language);
mapper->addMapping(unit, OptionsModel::DisplayUnit);
mapper->addMapping(display_addresses, OptionsModel::DisplayAddresses);
}
void DisplayOptionsPage::showRestartWarning()
{
if(!restart_warning_displayed)
{
QMessageBox::warning(this, tr("Warning"), tr("This setting will take effect after restarting Bitcoin."), QMessageBox::Ok);
restart_warning_displayed = true;
}
}
/* Window options */
WindowOptionsPage::WindowOptionsPage(QWidget *parent):
OptionsPage(parent)
{ {
QVBoxLayout *layout = new QVBoxLayout(); QVBoxLayout *layout = new QVBoxLayout();
setWindowTitle(tr("Window"));
bitcoin_at_startup = new QCheckBox(tr("&Start Bitcoin on window system startup")); bitcoin_at_startup = new QCheckBox(tr("&Start Bitcoin on window system startup"));
bitcoin_at_startup->setToolTip(tr("Automatically start Bitcoin after the computer is turned on")); bitcoin_at_startup->setToolTip(tr("Automatically start Bitcoin after the computer is turned on"));
@ -182,6 +321,29 @@ MainOptionsPage::MainOptionsPage(QWidget *parent):
layout->addWidget(minimize_on_close); layout->addWidget(minimize_on_close);
#endif #endif
layout->addStretch(1); // Extra space at bottom
setLayout(layout);
}
void WindowOptionsPage::setMapper(MonitoredDataMapper *mapper)
{
// Map model to widgets
mapper->addMapping(bitcoin_at_startup, OptionsModel::StartAtStartup);
#ifndef Q_WS_MAC
mapper->addMapping(minimize_to_tray, OptionsModel::MinimizeToTray);
#endif
#ifndef Q_WS_MAC
mapper->addMapping(minimize_on_close, OptionsModel::MinimizeOnClose);
#endif
}
/* Network options */
NetworkOptionsPage::NetworkOptionsPage(QWidget *parent):
OptionsPage(parent)
{
QVBoxLayout *layout = new QVBoxLayout();
setWindowTitle(tr("Network"));
map_port_upnp = new QCheckBox(tr("Map port using &UPnP")); map_port_upnp = new QCheckBox(tr("Map port using &UPnP"));
map_port_upnp->setToolTip(tr("Automatically open the Bitcoin client port on the router. This only works when your router supports UPnP and it is enabled.")); map_port_upnp->setToolTip(tr("Automatically open the Bitcoin client port on the router. This only works when your router supports UPnP and it is enabled."));
layout->addWidget(map_port_upnp); layout->addWidget(map_port_upnp);
@ -211,30 +373,9 @@ MainOptionsPage::MainOptionsPage(QWidget *parent):
proxy_port_label->setBuddy(proxy_port); proxy_port_label->setBuddy(proxy_port);
proxy_hbox->addWidget(proxy_port); proxy_hbox->addWidget(proxy_port);
proxy_hbox->addStretch(1); proxy_hbox->addStretch(1);
layout->addLayout(proxy_hbox); layout->addLayout(proxy_hbox);
QLabel *fee_help = new QLabel(tr("Optional transaction fee per kB that helps make sure your transactions are processed quickly. Most transactions are 1 kB. Fee 0.01 recommended."));
fee_help->setWordWrap(true);
layout->addWidget(fee_help);
QHBoxLayout *fee_hbox = new QHBoxLayout();
fee_hbox->addSpacing(18);
QLabel *fee_label = new QLabel(tr("Pay transaction &fee"));
fee_hbox->addWidget(fee_label);
fee_edit = new BitcoinAmountField();
fee_label->setBuddy(fee_edit);
fee_hbox->addWidget(fee_edit);
fee_hbox->addStretch(1);
layout->addLayout(fee_hbox);
detach_database = new QCheckBox(tr("Detach databases at shutdown"));
detach_database->setToolTip(tr("Detach block and address databases at shutdown. This means they can be moved to another data directory, but it slows down shutdown. The wallet is always detached."));
layout->addWidget(detach_database);
layout->addStretch(1); // Extra space at bottom layout->addStretch(1); // Extra space at bottom
setLayout(layout); setLayout(layout);
connect(connect_socks4, SIGNAL(toggled(bool)), proxy_ip, SLOT(setEnabled(bool))); connect(connect_socks4, SIGNAL(toggled(bool)), proxy_ip, SLOT(setEnabled(bool)));
@ -245,53 +386,11 @@ MainOptionsPage::MainOptionsPage(QWidget *parent):
#endif #endif
} }
void MainOptionsPage::setMapper(MonitoredDataMapper *mapper) void NetworkOptionsPage::setMapper(MonitoredDataMapper *mapper)
{ {
// Map model to widgets // Map model to widgets
mapper->addMapping(bitcoin_at_startup, OptionsModel::StartAtStartup);
#ifndef Q_WS_MAC
mapper->addMapping(minimize_to_tray, OptionsModel::MinimizeToTray);
#endif
mapper->addMapping(map_port_upnp, OptionsModel::MapPortUPnP); mapper->addMapping(map_port_upnp, OptionsModel::MapPortUPnP);
#ifndef Q_WS_MAC
mapper->addMapping(minimize_on_close, OptionsModel::MinimizeOnClose);
#endif
mapper->addMapping(connect_socks4, OptionsModel::ConnectSOCKS4); mapper->addMapping(connect_socks4, OptionsModel::ConnectSOCKS4);
mapper->addMapping(proxy_ip, OptionsModel::ProxyIP); mapper->addMapping(proxy_ip, OptionsModel::ProxyIP);
mapper->addMapping(proxy_port, OptionsModel::ProxyPort); mapper->addMapping(proxy_port, OptionsModel::ProxyPort);
mapper->addMapping(fee_edit, OptionsModel::Fee);
mapper->addMapping(detach_database, OptionsModel::DetachDatabases);
}
DisplayOptionsPage::DisplayOptionsPage(QWidget *parent):
QWidget(parent)
{
QVBoxLayout *layout = new QVBoxLayout();
QHBoxLayout *unit_hbox = new QHBoxLayout();
unit_hbox->addSpacing(18);
QLabel *unit_label = new QLabel(tr("&Unit to show amounts in: "));
unit_hbox->addWidget(unit_label);
unit = new QValueComboBox(this);
unit->setModel(new BitcoinUnits(this));
unit->setToolTip(tr("Choose the default subdivision unit to show in the interface, and when sending coins"));
unit_label->setBuddy(unit);
unit_hbox->addWidget(unit);
layout->addLayout(unit_hbox);
display_addresses = new QCheckBox(tr("&Display addresses in transaction list"), this);
display_addresses->setToolTip(tr("Whether to show Bitcoin addresses in the transaction list"));
layout->addWidget(display_addresses);
layout->addStretch();
setLayout(layout);
}
void DisplayOptionsPage::setMapper(MonitoredDataMapper *mapper)
{
mapper->addMapping(unit, OptionsModel::DisplayUnit);
mapper->addMapping(display_addresses, OptionsModel::DisplayAddresses);
} }

10
src/qt/optionsdialog.h

@ -2,6 +2,7 @@
#define OPTIONSDIALOG_H #define OPTIONSDIALOG_H
#include <QDialog> #include <QDialog>
#include <QList>
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
class QStackedWidget; class QStackedWidget;
@ -10,8 +11,7 @@ class QListWidgetItem;
class QPushButton; class QPushButton;
QT_END_NAMESPACE QT_END_NAMESPACE
class OptionsModel; class OptionsModel;
class MainOptionsPage; class OptionsPage;
class DisplayOptionsPage;
class MonitoredDataMapper; class MonitoredDataMapper;
/** Preferences dialog. */ /** Preferences dialog. */
@ -43,11 +43,7 @@ private:
MonitoredDataMapper *mapper; MonitoredDataMapper *mapper;
QPushButton *apply_button; QPushButton *apply_button;
// Pages QList<OptionsPage*> pages;
MainOptionsPage *main_page;
DisplayOptionsPage *display_page;
void setupMainPage();
}; };
#endif // OPTIONSDIALOG_H #endif // OPTIONSDIALOG_H

9
src/qt/optionsmodel.cpp

@ -21,6 +21,7 @@ void OptionsModel::Init()
fMinimizeToTray = settings.value("fMinimizeToTray", false).toBool(); fMinimizeToTray = settings.value("fMinimizeToTray", false).toBool();
fMinimizeOnClose = settings.value("fMinimizeOnClose", false).toBool(); fMinimizeOnClose = settings.value("fMinimizeOnClose", false).toBool();
nTransactionFee = settings.value("nTransactionFee").toLongLong(); nTransactionFee = settings.value("nTransactionFee").toLongLong();
language = settings.value("language", "").toString();
// These are shared with core bitcoin; we want // These are shared with core bitcoin; we want
// command-line options to override the GUI settings: // command-line options to override the GUI settings:
@ -30,6 +31,8 @@ void OptionsModel::Init()
SoftSetArg("-proxy", settings.value("addrProxy").toString().toStdString()); SoftSetArg("-proxy", settings.value("addrProxy").toString().toStdString());
if (settings.contains("detachDB")) if (settings.contains("detachDB"))
SoftSetBoolArg("-detachdb", settings.value("detachDB").toBool()); SoftSetBoolArg("-detachdb", settings.value("detachDB").toBool());
if (!language.isEmpty())
SoftSetArg("-lang", language.toStdString());
} }
bool OptionsModel::Upgrade() bool OptionsModel::Upgrade()
@ -125,6 +128,8 @@ QVariant OptionsModel::data(const QModelIndex & index, int role) const
return QVariant(bDisplayAddresses); return QVariant(bDisplayAddresses);
case DetachDatabases: case DetachDatabases:
return QVariant(fDetachDB); return QVariant(fDetachDB);
case Language:
return settings.value("language", "");
default: default:
return QVariant(); return QVariant();
} }
@ -213,6 +218,10 @@ bool OptionsModel::setData(const QModelIndex & index, const QVariant & value, in
settings.setValue("detachDB", fDetachDB); settings.setValue("detachDB", fDetachDB);
} }
break; break;
case Language: {
settings.setValue("language", value);
}
break;
default: default:
break; break;
} }

3
src/qt/optionsmodel.h

@ -27,6 +27,7 @@ public:
DisplayUnit, // BitcoinUnits::Unit DisplayUnit, // BitcoinUnits::Unit
DisplayAddresses, // bool DisplayAddresses, // bool
DetachDatabases, // bool DetachDatabases, // bool
Language, // QString
OptionIDRowCount, OptionIDRowCount,
}; };
@ -45,11 +46,13 @@ public:
bool getMinimizeOnClose(); bool getMinimizeOnClose();
int getDisplayUnit(); int getDisplayUnit();
bool getDisplayAddresses(); bool getDisplayAddresses();
QString getLanguage() { return language; }
private: private:
int nDisplayUnit; int nDisplayUnit;
bool bDisplayAddresses; bool bDisplayAddresses;
bool fMinimizeToTray; bool fMinimizeToTray;
bool fMinimizeOnClose; bool fMinimizeOnClose;
QString language;
signals: signals:
void displayUnitChanged(int unit); void displayUnitChanged(int unit);

6
src/qt/qvaluecombobox.cpp

@ -6,12 +6,12 @@ QValueComboBox::QValueComboBox(QWidget *parent) :
connect(this, SIGNAL(currentIndexChanged(int)), this, SLOT(handleSelectionChanged(int))); connect(this, SIGNAL(currentIndexChanged(int)), this, SLOT(handleSelectionChanged(int)));
} }
int QValueComboBox::value() const QVariant QValueComboBox::value() const
{ {
return itemData(currentIndex(), role).toInt(); return itemData(currentIndex(), role);
} }
void QValueComboBox::setValue(int value) void QValueComboBox::setValue(const QVariant &value)
{ {
setCurrentIndex(findData(value, role)); setCurrentIndex(findData(value, role));
} }

9
src/qt/qvaluecombobox.h

@ -2,19 +2,20 @@
#define QVALUECOMBOBOX_H #define QVALUECOMBOBOX_H
#include <QComboBox> #include <QComboBox>
#include <QVariant>
/* QComboBox that can be used with QDataWidgetMapper to select ordinal values from a model. */ /* QComboBox that can be used with QDataWidgetMapper to select ordinal values from a model. */
class QValueComboBox : public QComboBox class QValueComboBox : public QComboBox
{ {
Q_OBJECT Q_OBJECT
Q_PROPERTY(int value READ value WRITE setValue NOTIFY valueChanged USER true) Q_PROPERTY(QVariant value READ value WRITE setValue NOTIFY valueChanged USER true)
public: public:
explicit QValueComboBox(QWidget *parent = 0); explicit QValueComboBox(QWidget *parent = 0);
int value() const; QVariant value() const;
void setValue(int value); void setValue(const QVariant &value);
/** Specify model role to use as ordinal value */ /** Specify model role to use as ordinal value (defaults to Qt::UserRole) */
void setRole(int role); void setRole(int role);
signals: signals:

Loading…
Cancel
Save