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()
{
SettingsDialog dialog(mSettings, mApplications, this);
SettingsDialog dialog(mSettings, mApplications, mTranslation, this);
if (dialog.exec() == QDialog::Accepted)
{
dialog.SaveSettingValues();
@ -444,6 +444,10 @@ void MainWindow::ProgramSettings()
dialog.SaveFullPath(),
dialog.SaveAllErrors(),
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>
</layout>
</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>
</item>
<item>

View File

@ -30,14 +30,17 @@
#include "settingsdialog.h"
#include "applicationdialog.h"
#include "applicationlist.h"
#include "translationhandler.h"
#include "common.h"
SettingsDialog::SettingsDialog(QSettings *programSettings,
ApplicationList *list,
TranslationHandler *translator,
QWidget *parent) :
QDialog(parent),
mSettings(programSettings),
mApplications(list),
mTranslator(translator),
mTempApplications(new ApplicationList(this))
{
mUI.setupUi(this);
@ -78,6 +81,7 @@ SettingsDialog::SettingsDialog(QSettings *programSettings,
mUI.mLblIdealThreads->setText(tr("N/A"));
LoadSettings();
InitTranslationsList();
}
SettingsDialog::~SettingsDialog()
@ -85,6 +89,17 @@ SettingsDialog::~SettingsDialog()
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
{
if (yes)
@ -133,6 +148,7 @@ void SettingsDialog::SaveSettingValues()
SaveCheckboxValue(mUI.mShowDebugWarnings, SETTINGS_SHOW_DEBUG_WARNINGS);
SaveCheckboxValue(mUI.mInlineSuppressions, SETTINGS_INLINE_SUPPRESSIONS);
mSettings->setValue(SETTINGS_GLOBAL_INCLUDE_PATHS, mUI.mEditIncludePaths->text());
mSettings->setValue(SETTINGS_LANGUAGE, mUI.mListLanguages->currentRow());
}
void SettingsDialog::SaveCheckboxValue(QCheckBox *box, const QString &name)

View File

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

View File

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