SettingsGeneralPage.cpp 10.4 KB
Newer Older
1
/***************************************************************************
2
    File                 : SettingsGeneralPage.cpp
3 4
    Project              : LabPlot
    Description          : general settings page
5
    --------------------------------------------------------------------
6
    Copyright            : (C) 2008-2020 Alexander Semke (alexander.semke@web.de)
7
    Copyright            : (C) 2020 Stefan Gerlach (stefan.gerlach@uni.kn)
8

9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *  This program is free software; you can redistribute it and/or modify   *
 *  it under the terms of the GNU General Public License as published by   *
 *  the Free Software Foundation; either version 2 of the License, or      *
 *  (at your option) any later version.                                    *
 *                                                                         *
 *  This program is distributed in the hope that it will be useful,        *
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of         *
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          *
 *  GNU General Public License for more details.                           *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the Free Software           *
 *   Foundation, Inc., 51 Franklin Street, Fifth Floor,                    *
 *   Boston, MA  02110-1301  USA                                           *
 *                                                                         *
 ***************************************************************************/
29

Alexander Semke's avatar
Alexander Semke committed
30
#include "SettingsGeneralPage.h"
31
#include "backend/lib/macros.h"
Alexander Semke's avatar
Alexander Semke committed
32

33
#include <KI18n/KLocalizedString>
34 35
#include <KConfigGroup>
#include <KSharedConfig>
Alexander Semke's avatar
Alexander Semke committed
36

37 38 39
/**
 * \brief Page for the 'General' settings of the Labplot settings dialog.
 */
Stefan Gerlach's avatar
Stefan Gerlach committed
40
SettingsGeneralPage::SettingsGeneralPage(QWidget* parent) : SettingsPage(parent) {
Alexander Semke's avatar
Alexander Semke committed
41
	ui.setupUi(this);
42
	ui.sbAutoSaveInterval->setSuffix(i18n("min."));
43 44
	retranslateUi();

45 46 47 48 49 50
	connect(ui.cbLoadOnStart, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &SettingsGeneralPage::changed);
	connect(ui.cbTitleBar, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &SettingsGeneralPage::changed);
	connect(ui.cbInterface, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &SettingsGeneralPage::interfaceChanged);
	connect(ui.cbMdiVisibility, 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);
51
	connect(ui.cbDecimalSeparator, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &SettingsGeneralPage::changed);
52 53
	connect(ui.chkAutoSave, &QCheckBox::stateChanged, this, &SettingsGeneralPage::autoSaveChanged);
	connect(ui.chkMemoryInfo, &QCheckBox::stateChanged, this, &SettingsGeneralPage::changed);
Alexander Semke's avatar
Alexander Semke committed
54

55 56
	loadSettings();
	interfaceChanged(ui.cbInterface->currentIndex());
57
	autoSaveChanged(ui.chkAutoSave->checkState());
58
}
Alexander Semke's avatar
Alexander Semke committed
59

60
SettingsGeneralPage::DecimalSeparator SettingsGeneralPage::decimalSeparator(QLocale locale) {
61 62 63
	DEBUG("SettingsGeneralPage::decimalSeparator()")
	DEBUG("	LOCALE: " << STDSTRING(locale.name()))
	DEBUG("	LOCALE LANG: " << locale.language())
64
	QChar decimalPoint{locale.decimalPoint()};
65
	DEBUG("	SEPARATING CHAR: " << STDSTRING(QString(decimalPoint)) )
66 67 68 69 70 71 72 73 74 75
	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();
76 77 78 79
	DEBUG("	SYSTEM LOCALE: " << STDSTRING(QLocale().name()))
	DEBUG("	SYSTEM LOCALE LANG: " << QLocale().language())
	DEBUG("	CURRENT SEPARATING CHAR: " << STDSTRING(QString(QLocale().decimalPoint())) )
	DEBUG("	GERMAN SEPARATING CHAR: " << STDSTRING(QString(QLocale(QLocale::Language::German).decimalPoint())) )
80
	if (currentIndex == static_cast<int>(decimalSeparator())) 	// system decimal separator selected
81 82 83
		return QLocale().language();

	QChar groupSeparator{QLocale().groupSeparator()};
84 85
	switch (currentIndex) {
	case static_cast<int>(DecimalSeparator::Dot):
86 87 88 89 90 91
		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;	 	// . ,
92
	case static_cast<int>(DecimalSeparator::Comma):
93 94 95 96 97 98
		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;       // , .
99
	case static_cast<int>(DecimalSeparator::Arabic):
100
		return QLocale::Language::Arabic;		// \u066b \u066c
101 102
	default:	// automatic
		return QLocale().language();
103 104 105
	}
}

Stefan Gerlach's avatar
Stefan Gerlach committed
106
void SettingsGeneralPage::applySettings() {
107 108
	KConfigGroup group = KSharedConfig::openConfig()->group(QLatin1String("Settings_General"));
	group.writeEntry(QLatin1String("LoadOnStart"), ui.cbLoadOnStart->currentIndex());
109
	group.writeEntry(QLatin1String("TitleBar"), ui.cbTitleBar->currentIndex());
110 111 112
	group.writeEntry(QLatin1String("ViewMode"), ui.cbInterface->currentIndex());
	group.writeEntry(QLatin1String("TabPosition"), ui.cbTabPosition->currentIndex());
	group.writeEntry(QLatin1String("MdiWindowVisibility"), ui.cbMdiVisibility->currentIndex());
113
	group.writeEntry(QLatin1String("Units"), ui.cbUnits->currentIndex());
114 115 116 117
	if (ui.cbDecimalSeparator->currentIndex() == static_cast<int>(DecimalSeparator::Automatic))
		group.writeEntry(QLatin1String("DecimalSeparatorLocale"), static_cast<int>(QLocale::Language::AnyLanguage));
	else
		group.writeEntry(QLatin1String("DecimalSeparatorLocale"), static_cast<int>(decimalSeparatorLocale()));
118 119
	group.writeEntry(QLatin1String("AutoSave"), ui.chkAutoSave->isChecked());
	group.writeEntry(QLatin1String("AutoSaveInterval"), ui.sbAutoSaveInterval->value());
120
	group.writeEntry(QLatin1String("ShowMemoryInfo"), ui.chkMemoryInfo->isChecked());
Alexander Semke's avatar
Alexander Semke committed
121 122
}

Stefan Gerlach's avatar
Stefan Gerlach committed
123
void SettingsGeneralPage::restoreDefaults() {
124
	DEBUG("SettingsGeneralPage::restoreDefaults()")
125
	ui.cbLoadOnStart->setCurrentIndex(0);
126
	ui.cbTitleBar->setCurrentIndex(0);
127 128 129 130
	ui.cbInterface->setCurrentIndex(0);
	ui.cbTabPosition->setCurrentIndex(0);
	ui.cbMdiVisibility->setCurrentIndex(0);
	ui.cbUnits->setCurrentIndex(0);
131
	ui.cbDecimalSeparator->setCurrentIndex(static_cast<int>(DecimalSeparator::Automatic));
132 133 134 135
	ui.chkAutoSave->setChecked(false);
	ui.sbAutoSaveInterval->setValue(0);
	ui.sbAutoSaveInterval->setValue(5);
	ui.chkMemoryInfo->setChecked(true);
Alexander Semke's avatar
Alexander Semke committed
136 137
}

Stefan Gerlach's avatar
Stefan Gerlach committed
138
void SettingsGeneralPage::loadSettings() {
139
	DEBUG("SettingsGeneralPage::loadSettings()")
140 141
	const KConfigGroup group = KSharedConfig::openConfig()->group(QLatin1String("Settings_General"));
	ui.cbLoadOnStart->setCurrentIndex(group.readEntry(QLatin1String("LoadOnStart"), 0));
142
	ui.cbTitleBar->setCurrentIndex(group.readEntry(QLatin1String("TitleBar"), 0));
143 144 145
	ui.cbInterface->setCurrentIndex(group.readEntry(QLatin1String("ViewMode"), 0));
	ui.cbTabPosition->setCurrentIndex(group.readEntry(QLatin1String("TabPosition"), 0));
	ui.cbMdiVisibility->setCurrentIndex(group.readEntry(QLatin1String("MdiWindowVisibility"), 0));
146
	ui.cbUnits->setCurrentIndex(group.readEntry(QLatin1String("Units"), 0));
147
	QLocale locale(static_cast<QLocale::Language>(group.readEntry( QLatin1String("DecimalSeparatorLocale"), static_cast<int>(QLocale().language()) )) );
148 149 150 151
	if (locale.language() == QLocale().language()) 	// no or default setting
		ui.cbDecimalSeparator->setCurrentIndex( static_cast<int>(DecimalSeparator::Automatic) );
	else
		ui.cbDecimalSeparator->setCurrentIndex( static_cast<int>(decimalSeparator(locale)) );
Stefan Gerlach's avatar
Stefan Gerlach committed
152
	ui.chkAutoSave->setChecked(group.readEntry<bool>(QLatin1String("AutoSave"), false));
153
	ui.sbAutoSaveInterval->setValue(group.readEntry(QLatin1String("AutoSaveInterval"), 0));
154
	ui.chkMemoryInfo->setChecked(group.readEntry<bool>(QLatin1String("ShowMemoryInfo"), true));
Alexander Semke's avatar
Alexander Semke committed
155
}
156 157 158 159 160 161 162

void SettingsGeneralPage::retranslateUi() {
	ui.cbLoadOnStart->clear();
	ui.cbLoadOnStart->addItem(i18n("Do nothing"));
	ui.cbLoadOnStart->addItem(i18n("Create new empty project"));
	ui.cbLoadOnStart->addItem(i18n("Create new project with worksheet"));
	ui.cbLoadOnStart->addItem(i18n("Load last used project"));
163
// 	ui.cbLoadOnStart->addItem(i18n("Show Welcome Screen"));
164

165 166 167 168 169
	ui.cbTitleBar->clear();
	ui.cbTitleBar->addItem(i18n("Show File Path"));
	ui.cbTitleBar->addItem(i18n("Show File Name"));
	ui.cbTitleBar->addItem(i18n("Show Project Name"));

170 171 172
	ui.cbInterface->clear();
	ui.cbInterface->addItem(i18n("Sub-window view"));
	ui.cbInterface->addItem(i18n("Tabbed view"));
173

174 175 176 177 178 179 180 181 182 183
	ui.cbMdiVisibility->clear();
	ui.cbMdiVisibility->addItem(i18n("Show windows of the current folder only"));
	ui.cbMdiVisibility->addItem(i18n("Show windows of the current folder and its subfolders only"));
	ui.cbMdiVisibility->addItem(i18n("Show all windows"));

	ui.cbTabPosition->clear();
	ui.cbTabPosition->addItem(i18n("Top"));
	ui.cbTabPosition->addItem(i18n("Bottom"));
	ui.cbTabPosition->addItem(i18n("Left"));
	ui.cbTabPosition->addItem(i18n("Right"));
184 185 186

	ui.cbUnits->addItem(i18n("Metric"));
	ui.cbUnits->addItem(i18n("Imperial"));
187 188 189 190

	ui.cbDecimalSeparator->addItem(i18n("Dot (.)"));
	ui.cbDecimalSeparator->addItem(i18n("Comma (,)"));
	ui.cbDecimalSeparator->addItem(i18n("Arabic"));
191
	ui.cbDecimalSeparator->addItem(i18n("Automatic"));
192 193 194 195
}

void SettingsGeneralPage::changed() {
	m_changed = true;
196
	emit settingsChanged();
197 198 199
}

void SettingsGeneralPage::interfaceChanged(int index) {
Stefan Gerlach's avatar
Stefan Gerlach committed
200
	bool tabbedView = (index == 1);
201 202 203 204 205 206
	ui.lTabPosition->setVisible(tabbedView);
	ui.cbTabPosition->setVisible(tabbedView);
	ui.lMdiVisibility->setVisible(!tabbedView);
	ui.cbMdiVisibility->setVisible(!tabbedView);
	changed();
}
207 208 209 210 211 212 213

void SettingsGeneralPage::autoSaveChanged(int state) {
	const bool visible = (state == Qt::Checked);
	ui.lAutoSaveInterval->setVisible(visible);
	ui.sbAutoSaveInterval->setVisible(visible);
	changed();
}