Preferences: add a new page for language

This is not hooked into anything - It's the bare minimum that I
need to continue creating the new preferences dialog. But take a
look at it... very simple. :)

Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Tomaz Canabrava 2015-09-17 15:58:26 -03:00 committed by Dirk Hohndel
parent b35ccc3a35
commit 255325e219
4 changed files with 158 additions and 2 deletions

View file

@ -1,9 +1,21 @@
# the profile widget
include_directories(.
${CMAKE_CURRENT_BINARY_DIR}
${CMAKE_BINARY_DIR}
)
file(GLOB SUBSURFACE_PREFERENCES_UI *.ui)
qt5_wrap_ui(SUBSURFACE_PREFERENCES_UI_HDRS ${SUBSURFACE_PREFERENCES_UI})
source_group("Subsurface Interface Files" FILES ${SUBSURFACE_PREFERENCES_UI})
set(SUBSURFACE_PREFERENCES_LIB_SRCS
abstractpreferenceswidget.cpp
preferences_language.cpp
)
source_group("Subsurface Preferences" FILES ${SUBSURFACE_PREFERENCES_LIB_SRCS})
add_library(subsurface_desktop_preferences STATIC ${SUBSURFACE_PREFERENCES_LIB_SRCS})
target_link_libraries(subsurface_desktop_preferences ${QT_LIBRARIES})
add_library(subsurface_desktop_preferences STATIC ${SUBSURFACE_PREFERENCES_LIB_SRCS} ${SUBSURFACE_PREFERENCES_UI_HDRS})
target_link_libraries(subsurface_desktop_preferences ${QT_LIBRARIES})

View file

@ -0,0 +1,47 @@
#include "preferences_language.h"
#include "ui_prefs_language.h"
#include <QApplication>
#include <QSettings>
#include <QMessageBox>
PreferencesLanguage::PreferencesLanguage() : AbstractPreferencesWidget(tr("Language"), QIcon(":/language"), 4)
{
ui = new Ui::PreferencesLanguage();
ui->setupUi(this);
}
PreferencesLanguage::~PreferencesLanguage()
{
delete ui;
}
void PreferencesLanguage::refreshSettings()
{
QSettings s;
s.beginGroup("Language");
ui->languageSystemDefault->setChecked(s.value("UseSystemLanguage", true).toBool());
QAbstractItemModel *m = ui->languageView->model();
QModelIndexList languages = m->match(m->index(0, 0), Qt::UserRole, s.value("UiLanguage").toString());
if (languages.count())
ui->languageView->setCurrentIndex(languages.first());
s.endGroup();
}
void PreferencesLanguage::syncSettings()
{
// Locale
QLocale loc;
QSettings s;
s.beginGroup("Language");
bool useSystemLang = s.value("UseSystemLanguage", true).toBool();
if (useSystemLang != ui->languageSystemDefault->isChecked() ||
(!useSystemLang && s.value("UiLanguage").toString() != ui->languageView->currentIndex().data(Qt::UserRole))) {
QMessageBox::warning(this, tr("Restart required"),
tr("To correctly load a new language you must restart Subsurface."));
}
s.setValue("UseSystemLanguage", ui->languageSystemDefault->isChecked());
s.setValue("UiLanguage", ui->languageView->currentIndex().data(Qt::UserRole));
s.endGroup();
}

View file

@ -0,0 +1,21 @@
#ifndef PREFERENCES_LANGUAGE_H
#define PREFERENCES_LANGUAGE_H
#include "abstractpreferenceswidget.h"
namespace Ui {
class PreferencesLanguage;
}
class PreferencesLanguage : public AbstractPreferencesWidget {
Q_OBJECT
public:
PreferencesLanguage();
virtual ~PreferencesLanguage();
virtual void refreshSettings();
virtual void syncSettings();
private:
Ui::PreferencesLanguage *ui;
};
#endif

View file

@ -0,0 +1,76 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>PreferencesLanguage</class>
<widget class="QWidget" name="PreferencesLanguage">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>576</width>
<height>523</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QGroupBox" name="language_group">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="title">
<string>UI language</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QCheckBox" name="languageSystemDefault">
<property name="text">
<string>System default</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>203</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="label_14">
<property name="text">
<string>Filter</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="languageFilter"/>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QListView" name="languageView">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>