File indexing completed on 2024-05-12 07:41:28

0001 /*
0002     File                 : SettingsNotebookPage.cpp
0003     Project              : LabPlot
0004     Description          : Settings page for Notebook
0005     --------------------------------------------------------------------
0006     SPDX-FileCopyrightText: 2021 Alexander Semke <alexander.semke@web.de>
0007     SPDX-License-Identifier: GPL-2.0-or-later
0008 */
0009 
0010 #include "SettingsNotebookPage.h"
0011 #include "backend/core/Settings.h"
0012 
0013 #include <KConfigGroup>
0014 #include <KLocalizedString>
0015 
0016 /**
0017  * \brief Page for Notebook settings of the Labplot settings dialog.
0018  */
0019 SettingsNotebookPage::SettingsNotebookPage(QWidget* parent)
0020     : SettingsPage(parent) {
0021     ui.setupUi(this);
0022 
0023     ui.chkSyntaxHighlighting->setToolTip(i18n("Enable syntax highlighting"));
0024     ui.chkSyntaxCompletion->setToolTip(i18n("Enable syntax completion"));
0025     ui.chkLineNumbers->setToolTip(i18n("Show line numbers"));
0026     ui.chkLatexTypesetting->setToolTip(i18n("Use LaTeX typesetting for the results of calculations, if supported by the backend system."));
0027     ui.chkAnimations->setToolTip(i18n("Animate transitions"));
0028 
0029     ui.chkReevaluateEntries->setToolTip(i18n("Automatically re-evaluate all entries below the current one."));
0030     ui.chkAskConfirmation->setToolTip(i18n("Ask for confirmation when restarting the backend system."));
0031 
0032     connect(ui.chkSyntaxHighlighting, &QCheckBox::toggled, this, &SettingsNotebookPage::changed);
0033     connect(ui.chkSyntaxCompletion, &QCheckBox::toggled, this, &SettingsNotebookPage::changed);
0034     connect(ui.chkLineNumbers, &QCheckBox::toggled, this, &SettingsNotebookPage::changed);
0035     connect(ui.chkLatexTypesetting, &QCheckBox::toggled, this, &SettingsNotebookPage::changed);
0036     connect(ui.chkAnimations, &QCheckBox::toggled, this, &SettingsNotebookPage::changed);
0037     connect(ui.chkReevaluateEntries, &QCheckBox::toggled, this, &SettingsNotebookPage::changed);
0038     connect(ui.chkAskConfirmation, &QCheckBox::toggled, this, &SettingsNotebookPage::changed);
0039 
0040     loadSettings();
0041 }
0042 
0043 void SettingsNotebookPage::applySettings() {
0044     if (!m_changed)
0045         return;
0046 
0047     KConfigGroup group = Settings::group(QStringLiteral("Settings_Notebook"));
0048 
0049     // Appearance
0050     group.writeEntry(QLatin1String("SyntaxHighlighting"), ui.chkSyntaxHighlighting->isChecked());
0051     group.writeEntry(QLatin1String("SyntaxCompletion"), ui.chkSyntaxCompletion->isChecked());
0052     group.writeEntry(QLatin1String("LineNumbers"), ui.chkLineNumbers->isChecked());
0053     group.writeEntry(QLatin1String("LatexTypesetting"), ui.chkLatexTypesetting->isChecked());
0054     group.writeEntry(QLatin1String("Animations"), ui.chkAnimations->isChecked());
0055 
0056     // Evaluation
0057     group.writeEntry(QLatin1String("ReevaluateEntries"), ui.chkReevaluateEntries->isChecked());
0058     group.writeEntry(QLatin1String("AskConfirmation"), ui.chkAskConfirmation->isChecked());
0059 }
0060 
0061 void SettingsNotebookPage::restoreDefaults() {
0062     // Appearance
0063     ui.chkSyntaxHighlighting->setChecked(true);
0064     ui.chkSyntaxCompletion->setChecked(true);
0065     ui.chkLineNumbers->setChecked(false);
0066     ui.chkLatexTypesetting->setChecked(true);
0067     ui.chkAnimations->setChecked(true);
0068 
0069     // Evaluation
0070     ui.chkReevaluateEntries->setChecked(false);
0071     ui.chkAskConfirmation->setChecked(true);
0072 }
0073 
0074 void SettingsNotebookPage::loadSettings() {
0075     const KConfigGroup group = Settings::group(QStringLiteral("Settings_Notebook"));
0076 
0077     // Appearance
0078     ui.chkSyntaxHighlighting->setChecked(group.readEntry(QLatin1String("SyntaxHighlighting"), true));
0079     ui.chkSyntaxCompletion->setChecked(group.readEntry(QLatin1String("SyntaxCompletion"), true));
0080     ui.chkLineNumbers->setChecked(group.readEntry(QLatin1String("LineNumbers"), false));
0081     ui.chkLatexTypesetting->setChecked(group.readEntry(QLatin1String("LatexTypesetting"), true));
0082     ui.chkAnimations->setChecked(group.readEntry(QLatin1String("Animations"), true));
0083 
0084     // Evaluation
0085     ui.chkReevaluateEntries->setChecked(group.readEntry(QLatin1String("ReevaluateEntries"), false));
0086     ui.chkAskConfirmation->setChecked(group.readEntry(QLatin1String("AskConfirmation"), true));
0087 }
0088 
0089 void SettingsNotebookPage::changed() {
0090     m_changed = true;
0091     Q_EMIT settingsChanged();
0092 }