From 255325e219f7d1922ac7740649fdbc89228a36c1 Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Thu, 17 Sep 2015 15:58:26 -0300 Subject: [PATCH] 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 Signed-off-by: Dirk Hohndel --- desktop-widgets/preferences/CMakeLists.txt | 16 +++- .../preferences/preferences_language.cpp | 47 ++++++++++++ .../preferences/preferences_language.h | 21 +++++ desktop-widgets/preferences/prefs_language.ui | 76 +++++++++++++++++++ 4 files changed, 158 insertions(+), 2 deletions(-) create mode 100644 desktop-widgets/preferences/preferences_language.cpp create mode 100644 desktop-widgets/preferences/preferences_language.h create mode 100644 desktop-widgets/preferences/prefs_language.ui diff --git a/desktop-widgets/preferences/CMakeLists.txt b/desktop-widgets/preferences/CMakeLists.txt index 953c587b1..6af8b4a73 100644 --- a/desktop-widgets/preferences/CMakeLists.txt +++ b/desktop-widgets/preferences/CMakeLists.txt @@ -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}) \ No newline at end of file +add_library(subsurface_desktop_preferences STATIC ${SUBSURFACE_PREFERENCES_LIB_SRCS} ${SUBSURFACE_PREFERENCES_UI_HDRS}) +target_link_libraries(subsurface_desktop_preferences ${QT_LIBRARIES}) + diff --git a/desktop-widgets/preferences/preferences_language.cpp b/desktop-widgets/preferences/preferences_language.cpp new file mode 100644 index 000000000..7254482e2 --- /dev/null +++ b/desktop-widgets/preferences/preferences_language.cpp @@ -0,0 +1,47 @@ +#include "preferences_language.h" +#include "ui_prefs_language.h" + +#include +#include +#include + + +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(); +} \ No newline at end of file diff --git a/desktop-widgets/preferences/preferences_language.h b/desktop-widgets/preferences/preferences_language.h new file mode 100644 index 000000000..43014c0fd --- /dev/null +++ b/desktop-widgets/preferences/preferences_language.h @@ -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 \ No newline at end of file diff --git a/desktop-widgets/preferences/prefs_language.ui b/desktop-widgets/preferences/prefs_language.ui new file mode 100644 index 000000000..80671fca8 --- /dev/null +++ b/desktop-widgets/preferences/prefs_language.ui @@ -0,0 +1,76 @@ + + + PreferencesLanguage + + + + 0 + 0 + 576 + 523 + + + + Form + + + + + + + 0 + 0 + + + + UI language + + + + + + System default + + + + + + + Qt::Horizontal + + + + 203 + 20 + + + + + + + + Filter + + + + + + + + + + + + + + 0 + 0 + + + + + + + + +