Change language selection combo to a more practical list

This commit is contained in:
Mark Watkins 2014-05-14 20:36:04 +10:00
parent eaba138287
commit 84d56d99ee

View File

@ -21,6 +21,7 @@
#include <QDir> #include <QDir>
#include <QSettings> #include <QSettings>
#include <QTranslator> #include <QTranslator>
#include <QListWidget>
#ifndef nullptr #ifndef nullptr
#define nullptr NULL #define nullptr NULL
@ -92,7 +93,6 @@ void initTranslations(QSettings & settings) {
langFiles[code]=fi.fileName(); langFiles[code]=fi.fileName();
} }
if (language.isEmpty() || !langNames.contains(language)) { if (language.isEmpty() || !langNames.contains(language)) {
QDialog langsel(nullptr, Qt::CustomizeWindowHint | Qt::WindowTitleHint); QDialog langsel(nullptr, Qt::CustomizeWindowHint | Qt::WindowTitleHint);
QFont font; QFont font;
@ -106,39 +106,43 @@ void initTranslations(QSettings & settings) {
// hard coded non translatable // hard coded non translatable
QComboBox lang_combo(&langsel);
QPushButton lang_okbtn("->", &langsel); QPushButton lang_okbtn("->", &langsel);
QVBoxLayout layout1; QVBoxLayout layout1;
QVBoxLayout layout2; QVBoxLayout layout2;
QListWidget langlist;
lang_layout.addLayout(&layout1); lang_layout.addLayout(&layout1);
lang_layout.addLayout(&layout2); lang_layout.addLayout(&layout2);
layout1.addWidget(&img); layout1.addWidget(&img);
layout2.addWidget(&langlist, 1);
for (int i=0;i<welcome.size(); i++) { langlist.setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
QLabel *welcomeLabel = new QLabel(welcome[i]); int row = 0;
layout2.addWidget(welcomeLabel);
}
QWidget spacer;
layout2.addWidget(&spacer,1);
layout2.addWidget(&lang_combo, 1);
layout2.addWidget(&lang_okbtn);
for (QHash<QString, QString>::iterator it = langNames.begin(); it != langNames.end(); ++it) { for (QHash<QString, QString>::iterator it = langNames.begin(); it != langNames.end(); ++it) {
const QString & code = it.key(); const QString & code = it.key();
const QString & name = it.value(); const QString & name = it.value();
lang_combo.addItem(name, code); QListWidgetItem *item = new QListWidgetItem(name);
item->setData(Qt::UserRole, code);
langlist.insertItem(row++, item);
// Todo: Use base system language code
if (code.compare("en")==0) {
langlist.setCurrentItem(item);
} }
}
langlist.sortItems();
layout2.addWidget(&lang_okbtn);
langsel.connect(&langlist, SIGNAL(itemDoubleClicked(QListWidgetItem*)), &langsel, SLOT(close()));
langsel.connect(&lang_okbtn, SIGNAL(clicked()), &langsel, SLOT(close())); langsel.connect(&lang_okbtn, SIGNAL(clicked()), &langsel, SLOT(close()));
langsel.exec(); langsel.exec();
langsel.disconnect(&lang_okbtn, SIGNAL(clicked()), &langsel, SLOT(close())); langsel.disconnect(&lang_okbtn, SIGNAL(clicked()), &langsel, SLOT(close()));
langname = lang_combo.currentText(); langsel.disconnect(&langlist, SIGNAL(itemDoubleClicked(QListWidgetItem*)), &langsel, SLOT(close()));
language = lang_combo.itemData(lang_combo.currentIndex()).toString(); langname = langlist.currentItem()->text();
language = langlist.currentItem()->data(Qt::UserRole).toString();
settings.setValue("Settings/Language", language); settings.setValue("Settings/Language", language);
} }