aboutsummaryrefslogtreecommitdiffstats
path: root/desktop-widgets
diff options
context:
space:
mode:
Diffstat (limited to 'desktop-widgets')
-rw-r--r--desktop-widgets/preferences/CMakeLists.txt16
-rw-r--r--desktop-widgets/preferences/preferences_language.cpp47
-rw-r--r--desktop-widgets/preferences/preferences_language.h21
-rw-r--r--desktop-widgets/preferences/prefs_language.ui76
4 files changed, 158 insertions, 2 deletions
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 <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();
+} \ 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 @@
+<?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>