Commit 4c541beb authored by Stefan Gerlach's avatar Stefan Gerlach

[settings] Add decimal separator selection

parent 9da04c54
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
Description : general settings page Description : general settings page
-------------------------------------------------------------------- --------------------------------------------------------------------
Copyright : (C) 2008-2020 Alexander Semke (alexander.semke@web.de) Copyright : (C) 2008-2020 Alexander Semke (alexander.semke@web.de)
Copyright : (C) 2020 Stefan Gerlach (stefan.gerlach@uni.kn)
***************************************************************************/ ***************************************************************************/
...@@ -27,6 +28,7 @@ ...@@ -27,6 +28,7 @@
***************************************************************************/ ***************************************************************************/
#include "SettingsGeneralPage.h" #include "SettingsGeneralPage.h"
#include "backend/lib/macros.h"
#include <KI18n/KLocalizedString> #include <KI18n/KLocalizedString>
#include <KConfigGroup> #include <KConfigGroup>
...@@ -46,6 +48,7 @@ SettingsGeneralPage::SettingsGeneralPage(QWidget* parent) : SettingsPage(parent) ...@@ -46,6 +48,7 @@ SettingsGeneralPage::SettingsGeneralPage(QWidget* parent) : SettingsPage(parent)
connect(ui.cbMdiVisibility, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &SettingsGeneralPage::changed); connect(ui.cbMdiVisibility, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &SettingsGeneralPage::changed);
connect(ui.cbTabPosition, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &SettingsGeneralPage::changed); connect(ui.cbTabPosition, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &SettingsGeneralPage::changed);
connect(ui.cbUnits, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &SettingsGeneralPage::changed); connect(ui.cbUnits, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &SettingsGeneralPage::changed);
connect(ui.cbDecimalSeparator, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &SettingsGeneralPage::changed);
connect(ui.chkAutoSave, &QCheckBox::stateChanged, this, &SettingsGeneralPage::autoSaveChanged); connect(ui.chkAutoSave, &QCheckBox::stateChanged, this, &SettingsGeneralPage::autoSaveChanged);
connect(ui.chkMemoryInfo, &QCheckBox::stateChanged, this, &SettingsGeneralPage::changed); connect(ui.chkMemoryInfo, &QCheckBox::stateChanged, this, &SettingsGeneralPage::changed);
...@@ -54,6 +57,42 @@ SettingsGeneralPage::SettingsGeneralPage(QWidget* parent) : SettingsPage(parent) ...@@ -54,6 +57,42 @@ SettingsGeneralPage::SettingsGeneralPage(QWidget* parent) : SettingsPage(parent)
autoSaveChanged(ui.chkAutoSave->checkState()); autoSaveChanged(ui.chkAutoSave->checkState());
} }
SettingsGeneralPage::DecimalSeparator SettingsGeneralPage::decimalSeparator(QLocale locale) {
QChar decimalPoint{locale.decimalPoint()};
if (decimalPoint == QChar('.'))
return DecimalSeparator::Dot;
else if (decimalPoint == QChar(','))
return DecimalSeparator::Comma;
return DecimalSeparator::Arabic;
}
QLocale::Language SettingsGeneralPage::decimalSeparatorLocale() const {
int currentIndex = ui.cbDecimalSeparator->currentIndex();
if (currentIndex == static_cast<int>(decimalSeparator()))
return QLocale().language();
QChar groupSeparator{QLocale().groupSeparator()};
QChar decimalPoint{QLocale().decimalPoint()};
if (currentIndex == static_cast<int>(DecimalSeparator::Dot)) {
if (groupSeparator == QLocale(QLocale::Language::Zarma).groupSeparator()) // \u00a0
return QLocale::Language::Zarma; // . \u00a0
else if (groupSeparator == QLocale(QLocale::Language::SwissGerman).groupSeparator()) // \u2019
return QLocale::Language::SwissGerman; // . \u2019
else
return QLocale::Language::C; // . ,
} else if (currentIndex == static_cast<int>(DecimalSeparator::Comma)) {
if (groupSeparator == QLocale(QLocale::Language::French).groupSeparator()) // \u00a0
return QLocale::Language::French; // , \u00a0
else if (groupSeparator == QLocale(QLocale::Language::Walser).groupSeparator()) // \u2019
return QLocale::Language::Walser; // , \u2019
else
return QLocale::Language::German; // , .
} else {
return QLocale::Language::Arabic; // \u066b \u066c
}
}
void SettingsGeneralPage::applySettings() { void SettingsGeneralPage::applySettings() {
KConfigGroup group = KSharedConfig::openConfig()->group(QLatin1String("Settings_General")); KConfigGroup group = KSharedConfig::openConfig()->group(QLatin1String("Settings_General"));
group.writeEntry(QLatin1String("LoadOnStart"), ui.cbLoadOnStart->currentIndex()); group.writeEntry(QLatin1String("LoadOnStart"), ui.cbLoadOnStart->currentIndex());
...@@ -62,18 +101,21 @@ void SettingsGeneralPage::applySettings() { ...@@ -62,18 +101,21 @@ void SettingsGeneralPage::applySettings() {
group.writeEntry(QLatin1String("TabPosition"), ui.cbTabPosition->currentIndex()); group.writeEntry(QLatin1String("TabPosition"), ui.cbTabPosition->currentIndex());
group.writeEntry(QLatin1String("MdiWindowVisibility"), ui.cbMdiVisibility->currentIndex()); group.writeEntry(QLatin1String("MdiWindowVisibility"), ui.cbMdiVisibility->currentIndex());
group.writeEntry(QLatin1String("Units"), ui.cbUnits->currentIndex()); group.writeEntry(QLatin1String("Units"), ui.cbUnits->currentIndex());
group.writeEntry(QLatin1String("DecimalSeparatorLocale"), static_cast<int>(decimalSeparatorLocale()));
group.writeEntry(QLatin1String("AutoSave"), ui.chkAutoSave->isChecked()); group.writeEntry(QLatin1String("AutoSave"), ui.chkAutoSave->isChecked());
group.writeEntry(QLatin1String("AutoSaveInterval"), ui.sbAutoSaveInterval->value()); group.writeEntry(QLatin1String("AutoSaveInterval"), ui.sbAutoSaveInterval->value());
group.writeEntry(QLatin1String("ShowMemoryInfo"), ui.chkMemoryInfo->isChecked()); group.writeEntry(QLatin1String("ShowMemoryInfo"), ui.chkMemoryInfo->isChecked());
} }
void SettingsGeneralPage::restoreDefaults() { void SettingsGeneralPage::restoreDefaults() {
DEBUG("SettingsGeneralPage::restoreDefaults()")
ui.cbLoadOnStart->setCurrentIndex(0); ui.cbLoadOnStart->setCurrentIndex(0);
ui.cbTitleBar->setCurrentIndex(0); ui.cbTitleBar->setCurrentIndex(0);
ui.cbInterface->setCurrentIndex(0); ui.cbInterface->setCurrentIndex(0);
ui.cbTabPosition->setCurrentIndex(0); ui.cbTabPosition->setCurrentIndex(0);
ui.cbMdiVisibility->setCurrentIndex(0); ui.cbMdiVisibility->setCurrentIndex(0);
ui.cbUnits->setCurrentIndex(0); ui.cbUnits->setCurrentIndex(0);
ui.cbDecimalSeparator->setCurrentIndex(static_cast<int>(decimalSeparator()));
ui.chkAutoSave->setChecked(false); ui.chkAutoSave->setChecked(false);
ui.sbAutoSaveInterval->setValue(0); ui.sbAutoSaveInterval->setValue(0);
ui.sbAutoSaveInterval->setValue(5); ui.sbAutoSaveInterval->setValue(5);
...@@ -81,6 +123,7 @@ void SettingsGeneralPage::restoreDefaults() { ...@@ -81,6 +123,7 @@ void SettingsGeneralPage::restoreDefaults() {
} }
void SettingsGeneralPage::loadSettings() { void SettingsGeneralPage::loadSettings() {
DEBUG("SettingsGeneralPage::loadSettings()")
const KConfigGroup group = KSharedConfig::openConfig()->group(QLatin1String("Settings_General")); const KConfigGroup group = KSharedConfig::openConfig()->group(QLatin1String("Settings_General"));
ui.cbLoadOnStart->setCurrentIndex(group.readEntry(QLatin1String("LoadOnStart"), 0)); ui.cbLoadOnStart->setCurrentIndex(group.readEntry(QLatin1String("LoadOnStart"), 0));
ui.cbTitleBar->setCurrentIndex(group.readEntry(QLatin1String("TitleBar"), 0)); ui.cbTitleBar->setCurrentIndex(group.readEntry(QLatin1String("TitleBar"), 0));
...@@ -88,6 +131,8 @@ void SettingsGeneralPage::loadSettings() { ...@@ -88,6 +131,8 @@ void SettingsGeneralPage::loadSettings() {
ui.cbTabPosition->setCurrentIndex(group.readEntry(QLatin1String("TabPosition"), 0)); ui.cbTabPosition->setCurrentIndex(group.readEntry(QLatin1String("TabPosition"), 0));
ui.cbMdiVisibility->setCurrentIndex(group.readEntry(QLatin1String("MdiWindowVisibility"), 0)); ui.cbMdiVisibility->setCurrentIndex(group.readEntry(QLatin1String("MdiWindowVisibility"), 0));
ui.cbUnits->setCurrentIndex(group.readEntry(QLatin1String("Units"), 0)); ui.cbUnits->setCurrentIndex(group.readEntry(QLatin1String("Units"), 0));
QLocale::Language decimalSeparatorLocale{ static_cast<QLocale::Language>(group.readEntry( QLatin1String("DecimalSeparatorLocale"), static_cast<int>(QLocale().language()) )) };
ui.cbDecimalSeparator->setCurrentIndex( static_cast<int>(decimalSeparator(QLocale(decimalSeparatorLocale))) );
ui.chkAutoSave->setChecked(group.readEntry<bool>(QLatin1String("AutoSave"), false)); ui.chkAutoSave->setChecked(group.readEntry<bool>(QLatin1String("AutoSave"), false));
ui.sbAutoSaveInterval->setValue(group.readEntry(QLatin1String("AutoSaveInterval"), 0)); ui.sbAutoSaveInterval->setValue(group.readEntry(QLatin1String("AutoSaveInterval"), 0));
ui.chkMemoryInfo->setChecked(group.readEntry<bool>(QLatin1String("ShowMemoryInfo"), true)); ui.chkMemoryInfo->setChecked(group.readEntry<bool>(QLatin1String("ShowMemoryInfo"), true));
...@@ -123,6 +168,10 @@ void SettingsGeneralPage::retranslateUi() { ...@@ -123,6 +168,10 @@ void SettingsGeneralPage::retranslateUi() {
ui.cbUnits->addItem(i18n("Metric")); ui.cbUnits->addItem(i18n("Metric"));
ui.cbUnits->addItem(i18n("Imperial")); ui.cbUnits->addItem(i18n("Imperial"));
ui.cbDecimalSeparator->addItem(i18n("Dot (.)"));
ui.cbDecimalSeparator->addItem(i18n("Comma (,)"));
ui.cbDecimalSeparator->addItem(i18n("Arabic"));
} }
void SettingsGeneralPage::changed() { void SettingsGeneralPage::changed() {
......
...@@ -37,8 +37,13 @@ class SettingsGeneralPage : public SettingsPage { ...@@ -37,8 +37,13 @@ class SettingsGeneralPage : public SettingsPage {
Q_OBJECT Q_OBJECT
public: public:
enum class DecimalSeparator{Dot, Comma, Arabic};
explicit SettingsGeneralPage(QWidget*); explicit SettingsGeneralPage(QWidget*);
static DecimalSeparator decimalSeparator(QLocale locale = QLocale());
QLocale::Language decimalSeparatorLocale() const;
void applySettings() override; void applySettings() override;
void restoreDefaults() override; void restoreDefaults() override;
......
...@@ -80,14 +80,14 @@ ...@@ -80,14 +80,14 @@
<item row="5" column="0"> <item row="5" column="0">
<widget class="QLabel" name="lUnits"> <widget class="QLabel" name="lUnits">
<property name="text"> <property name="text">
<string>Units</string> <string>Units:</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="5" column="3"> <item row="5" column="3">
<widget class="QComboBox" name="cbUnits"/> <widget class="QComboBox" name="cbUnits"/>
</item> </item>
<item row="6" column="1"> <item row="7" column="1">
<spacer name="verticalSpacer_2"> <spacer name="verticalSpacer_2">
<property name="orientation"> <property name="orientation">
<enum>Qt::Vertical</enum> <enum>Qt::Vertical</enum>
...@@ -103,14 +103,14 @@ ...@@ -103,14 +103,14 @@
</property> </property>
</spacer> </spacer>
</item> </item>
<item row="7" column="0"> <item row="8" column="0">
<widget class="QLabel" name="lAutoSave"> <widget class="QLabel" name="lAutoSave">
<property name="text"> <property name="text">
<string>Auto-Save:</string> <string>Auto-Save:</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="7" column="3"> <item row="8" column="3">
<widget class="QFrame" name="frame"> <widget class="QFrame" name="frame">
<property name="frameShape"> <property name="frameShape">
<enum>QFrame::NoFrame</enum> <enum>QFrame::NoFrame</enum>
...@@ -119,16 +119,7 @@ ...@@ -119,16 +119,7 @@
<enum>QFrame::Raised</enum> <enum>QFrame::Raised</enum>
</property> </property>
<layout class="QHBoxLayout" name="horizontalLayout"> <layout class="QHBoxLayout" name="horizontalLayout">
<property name="leftMargin"> <property name="margin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number> <number>0</number>
</property> </property>
<item> <item>
...@@ -187,21 +178,21 @@ ...@@ -187,21 +178,21 @@
</layout> </layout>
</widget> </widget>
</item> </item>
<item row="8" column="0"> <item row="9" column="0">
<widget class="QLabel" name="lMemoryInfo"> <widget class="QLabel" name="lMemoryInfo">
<property name="text"> <property name="text">
<string>Show memory info:</string> <string>Show memory info:</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="8" column="3"> <item row="9" column="3">
<widget class="QCheckBox" name="chkMemoryInfo"> <widget class="QCheckBox" name="chkMemoryInfo">
<property name="text"> <property name="text">
<string>Enabled</string> <string>Enabled</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="9" column="1"> <item row="10" column="1">
<spacer name="verticalSpacer"> <spacer name="verticalSpacer">
<property name="orientation"> <property name="orientation">
<enum>Qt::Vertical</enum> <enum>Qt::Vertical</enum>
...@@ -214,6 +205,16 @@ ...@@ -214,6 +205,16 @@
</property> </property>
</spacer> </spacer>
</item> </item>
<item row="6" column="0">
<widget class="QLabel" name="lDecimalSeparator">
<property name="text">
<string>Decimal separator:</string>
</property>
</widget>
</item>
<item row="6" column="3">
<widget class="QComboBox" name="cbDecimalSeparator"/>
</item>
</layout> </layout>
</widget> </widget>
<customwidgets> <customwidgets>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment