GUI: Add language selection panel to settings-dialog.

Settings-dialog is more natural place for language selection than
the main menu. We also have more space and freedom there to have
longer text etc to make the selection easier (menus are quite limited
controls).
This commit is contained in:
Kimmo Varis 2011-01-10 00:21:51 +02:00
parent 226b605774
commit 29d6b443fa
5 changed files with 48 additions and 3 deletions

View File

@ -436,7 +436,7 @@ void MainWindow::CheckDone()
void MainWindow::ProgramSettings() void MainWindow::ProgramSettings()
{ {
SettingsDialog dialog(mSettings, mApplications, this); SettingsDialog dialog(mSettings, mApplications, mTranslation, this);
if (dialog.exec() == QDialog::Accepted) if (dialog.exec() == QDialog::Accepted)
{ {
dialog.SaveSettingValues(); dialog.SaveSettingValues();
@ -444,6 +444,10 @@ void MainWindow::ProgramSettings()
dialog.SaveFullPath(), dialog.SaveFullPath(),
dialog.SaveAllErrors(), dialog.SaveAllErrors(),
dialog.ShowNoErrorsMessage()); dialog.ShowNoErrorsMessage());
const int currentLang = mTranslation->GetCurrentLanguage();
const int newLang = mSettings->value(SETTINGS_LANGUAGE, 0).toInt();
if (currentLang != newLang)
SetLanguage(newLang);
} }
} }

View File

@ -254,6 +254,20 @@
</item> </item>
</layout> </layout>
</widget> </widget>
<widget class="QWidget" name="tab_4">
<attribute name="title">
<string>Language</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_5">
<item>
<widget class="QListWidget" name="mListLanguages">
<property name="selectionBehavior">
<enum>QAbstractItemView::SelectRows</enum>
</property>
</widget>
</item>
</layout>
</widget>
</widget> </widget>
</item> </item>
<item> <item>

View File

@ -30,14 +30,17 @@
#include "settingsdialog.h" #include "settingsdialog.h"
#include "applicationdialog.h" #include "applicationdialog.h"
#include "applicationlist.h" #include "applicationlist.h"
#include "translationhandler.h"
#include "common.h" #include "common.h"
SettingsDialog::SettingsDialog(QSettings *programSettings, SettingsDialog::SettingsDialog(QSettings *programSettings,
ApplicationList *list, ApplicationList *list,
TranslationHandler *translator,
QWidget *parent) : QWidget *parent) :
QDialog(parent), QDialog(parent),
mSettings(programSettings), mSettings(programSettings),
mApplications(list), mApplications(list),
mTranslator(translator),
mTempApplications(new ApplicationList(this)) mTempApplications(new ApplicationList(this))
{ {
mUI.setupUi(this); mUI.setupUi(this);
@ -78,6 +81,7 @@ SettingsDialog::SettingsDialog(QSettings *programSettings,
mUI.mLblIdealThreads->setText(tr("N/A")); mUI.mLblIdealThreads->setText(tr("N/A"));
LoadSettings(); LoadSettings();
InitTranslationsList();
} }
SettingsDialog::~SettingsDialog() SettingsDialog::~SettingsDialog()
@ -85,6 +89,17 @@ SettingsDialog::~SettingsDialog()
SaveSettings(); SaveSettings();
} }
void SettingsDialog::InitTranslationsList()
{
QStringList languages = mTranslator->GetNames();
foreach(const QString lang, languages)
{
mUI.mListLanguages->addItem(lang);
}
const int current = mTranslator->GetCurrentLanguage();
mUI.mListLanguages->setCurrentRow(current);
}
Qt::CheckState SettingsDialog::BoolToCheckState(bool yes) const Qt::CheckState SettingsDialog::BoolToCheckState(bool yes) const
{ {
if (yes) if (yes)
@ -133,6 +148,7 @@ void SettingsDialog::SaveSettingValues()
SaveCheckboxValue(mUI.mShowDebugWarnings, SETTINGS_SHOW_DEBUG_WARNINGS); SaveCheckboxValue(mUI.mShowDebugWarnings, SETTINGS_SHOW_DEBUG_WARNINGS);
SaveCheckboxValue(mUI.mInlineSuppressions, SETTINGS_INLINE_SUPPRESSIONS); SaveCheckboxValue(mUI.mInlineSuppressions, SETTINGS_INLINE_SUPPRESSIONS);
mSettings->setValue(SETTINGS_GLOBAL_INCLUDE_PATHS, mUI.mEditIncludePaths->text()); mSettings->setValue(SETTINGS_GLOBAL_INCLUDE_PATHS, mUI.mEditIncludePaths->text());
mSettings->setValue(SETTINGS_LANGUAGE, mUI.mListLanguages->currentRow());
} }
void SettingsDialog::SaveCheckboxValue(QCheckBox *box, const QString &name) void SettingsDialog::SaveCheckboxValue(QCheckBox *box, const QString &name)

View File

@ -27,6 +27,7 @@
class QSettings; class QSettings;
class QWidget; class QWidget;
class ApplicationList; class ApplicationList;
class TranslationHandler;
/// @addtogroup GUI /// @addtogroup GUI
/// @{ /// @{
@ -41,6 +42,7 @@ class SettingsDialog : public QDialog
public: public:
SettingsDialog(QSettings *programSettings, SettingsDialog(QSettings *programSettings,
ApplicationList *list, ApplicationList *list,
TranslationHandler *translator,
QWidget *parent = 0); QWidget *parent = 0);
virtual ~SettingsDialog(); virtual ~SettingsDialog();
@ -163,6 +165,10 @@ protected:
*/ */
bool CheckStateToBool(Qt::CheckState state) const; bool CheckStateToBool(Qt::CheckState state) const;
/**
* @brief Populate the translations list.
*/
void InitTranslationsList();
/** /**
* @brief Settings * @brief Settings
@ -183,6 +189,12 @@ protected:
*/ */
ApplicationList *mTempApplications; ApplicationList *mTempApplications;
/**
* @brief List of translations.
*
*/
TranslationHandler *mTranslator;
/** /**
* @brief Dialog from UI designer * @brief Dialog from UI designer
* *

View File

@ -16,12 +16,11 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "translationhandler.h"
#include <QApplication> #include <QApplication>
#include <QFile> #include <QFile>
#include <QDebug> #include <QDebug>
#include <QLocale> #include <QLocale>
#include "translationhandler.h"
TranslationHandler::TranslationHandler(QObject *parent) : TranslationHandler::TranslationHandler(QObject *parent) :
QObject(parent), QObject(parent),