Browse Source

Make it possible to set user interface language from options dialog

0.8
Wladimir J. van der Laan 13 years ago
parent
commit
5ac114c756
  1. 39
      src/qt/optionsdialog.cpp
  2. 9
      src/qt/optionsmodel.cpp
  3. 3
      src/qt/optionsmodel.h
  4. 6
      src/qt/qvaluecombobox.cpp
  5. 9
      src/qt/qvaluecombobox.h

39
src/qt/optionsdialog.cpp

@ -19,6 +19,8 @@ @@ -19,6 +19,8 @@
#include <QDoubleValidator>
#include <QRegExpValidator>
#include <QDialogButtonBox>
#include <QDir>
#include <QMessageBox>
class OptionsPage: public QWidget
{
@ -66,8 +68,12 @@ public: @@ -66,8 +68,12 @@ public:
virtual void setMapper(MonitoredDataMapper *mapper);
private:
QValueComboBox *lang;
QValueComboBox *unit;
QCheckBox *display_addresses;
bool restart_warning_displayed;
private slots:
void showRestartWarning();
};
class NetworkOptionsPage: public OptionsPage
@ -230,12 +236,33 @@ void MainOptionsPage::setMapper(MonitoredDataMapper *mapper) @@ -230,12 +236,33 @@ void MainOptionsPage::setMapper(MonitoredDataMapper *mapper)
/* Display options */
DisplayOptionsPage::DisplayOptionsPage(QWidget *parent):
OptionsPage(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: "));
@ -259,10 +286,20 @@ DisplayOptionsPage::DisplayOptionsPage(QWidget *parent): @@ -259,10 +286,20 @@ DisplayOptionsPage::DisplayOptionsPage(QWidget *parent):
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)

9
src/qt/optionsmodel.cpp

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

3
src/qt/optionsmodel.h

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

6
src/qt/qvaluecombobox.cpp

@ -6,12 +6,12 @@ QValueComboBox::QValueComboBox(QWidget *parent) : @@ -6,12 +6,12 @@ QValueComboBox::QValueComboBox(QWidget *parent) :
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));
}

9
src/qt/qvaluecombobox.h

@ -2,19 +2,20 @@ @@ -2,19 +2,20 @@
#define QVALUECOMBOBOX_H
#include <QComboBox>
#include <QVariant>
/* QComboBox that can be used with QDataWidgetMapper to select ordinal values from a model. */
class QValueComboBox : public QComboBox
{
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:
explicit QValueComboBox(QWidget *parent = 0);
int value() const;
void setValue(int value);
QVariant value() const;
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);
signals:

Loading…
Cancel
Save