diff --git a/src/gui/preferences/settingsgeneralwidget.cpp b/src/gui/preferences/settingsgeneralwidget.cpp index 89ddbb76..c6003018 100644 --- a/src/gui/preferences/settingsgeneralwidget.cpp +++ b/src/gui/preferences/settingsgeneralwidget.cpp @@ -1,117 +1,132 @@ /*************************************************************************** * Copyright (C) 2004-2018 by Thomas Fischer * * * * 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, see . * ***************************************************************************/ #include "settingsgeneralwidget.h" #include #include #include #include #include #include "guihelper.h" #include "value.h" #include "preferences.h" class SettingsGeneralWidget::SettingsGeneralWidgetPrivate { private: SettingsGeneralWidget *p; + KComboBox *comboBoxBibliographySystem; KComboBox *comboBoxPersonNameFormatting; const Person dummyPerson; QString restartRequiredMsg; KSharedConfigPtr config; const QString configGroupName; public: SettingsGeneralWidgetPrivate(SettingsGeneralWidget *parent) : p(parent), dummyPerson(Person(i18n("John"), i18n("Doe"), i18n("Jr."))), restartRequiredMsg(i18n("Changing this option requires a restart to take effect.")), config(KSharedConfig::openConfig(QStringLiteral("kbibtexrc"))), configGroupName(QStringLiteral("General")) { setupGUI(); } void loadState() { + comboBoxBibliographySystem->setCurrentIndex(comboBoxBibliographySystem->findData(QVariant::fromValue(static_cast(Preferences::bibliographySystem())))); + KConfigGroup configGroup(config, configGroupName); QString personNameFormatting = configGroup.readEntry(Preferences::keyPersonNameFormatting, Preferences::defaultPersonNameFormatting); int row = GUIHelper::selectValue(comboBoxPersonNameFormatting->model(), Person::transcribePersonName(&dummyPerson, personNameFormatting)); comboBoxPersonNameFormatting->setCurrentIndex(row); } void saveState() { + Preferences::setBibliographySystem(static_cast(comboBoxBibliographySystem->currentData().toInt())); + KConfigGroup configGroup(config, configGroupName); configGroup.writeEntry(Preferences::keyPersonNameFormatting, comboBoxPersonNameFormatting->itemData(comboBoxPersonNameFormatting->currentIndex())); config->sync(); } void resetToDefaults() { + comboBoxBibliographySystem->setCurrentIndex(static_cast(Preferences::defaultBibliographySystem)); + int row = GUIHelper::selectValue(comboBoxPersonNameFormatting->model(), Person::transcribePersonName(&dummyPerson, Preferences::defaultPersonNameFormatting)); comboBoxPersonNameFormatting->setCurrentIndex(row); } void setupGUI() { QFormLayout *layout = new QFormLayout(p); + comboBoxBibliographySystem = new KComboBox(false, p); + comboBoxBibliographySystem->setObjectName(QStringLiteral("comboBoxBibliographySystem")); + const QMap &availableBibliographySystems = Preferences::availableBibliographySystems(); + for (QMap::ConstIterator it = availableBibliographySystems.constBegin(), itEnd = availableBibliographySystems.constEnd(); it != itEnd; ++it) + comboBoxBibliographySystem->addItem(it.value(), QVariant::fromValue(static_cast(it.key()))); + layout->addRow(i18n("Bibliography System:"), comboBoxBibliographySystem); + connect(comboBoxBibliographySystem, static_cast(&QComboBox::currentIndexChanged), p, &SettingsGeneralWidget::changed); + comboBoxPersonNameFormatting = new KComboBox(false, p); layout->addRow(i18n("Person Names Formatting:"), comboBoxPersonNameFormatting); const QStringList formattingOptions {Preferences::personNameFormatFirstLast, Preferences::personNameFormatLastFirst}; for (const QString &formattingOption : formattingOptions) { comboBoxPersonNameFormatting->addItem(Person::transcribePersonName(&dummyPerson, formattingOption), formattingOption); } comboBoxPersonNameFormatting->setToolTip(restartRequiredMsg); connect(comboBoxPersonNameFormatting, static_cast(&QComboBox::currentIndexChanged), p, &SettingsGeneralWidget::changed); } }; SettingsGeneralWidget::SettingsGeneralWidget(QWidget *parent) : SettingsAbstractWidget(parent), d(new SettingsGeneralWidgetPrivate(this)) { d->loadState(); } SettingsGeneralWidget::~SettingsGeneralWidget() { delete d; } QString SettingsGeneralWidget::label() const { return i18n("General"); } QIcon SettingsGeneralWidget::icon() const { return QIcon::fromTheme(QStringLiteral("kbibtex")); } void SettingsGeneralWidget::loadState() { d->loadState(); } void SettingsGeneralWidget::saveState() { d->saveState(); } void SettingsGeneralWidget::resetToDefaults() { d->resetToDefaults(); } diff --git a/src/gui/preferences/settingsuserinterfacewidget.cpp b/src/gui/preferences/settingsuserinterfacewidget.cpp index d87b44c2..3c1ca093 100644 --- a/src/gui/preferences/settingsuserinterfacewidget.cpp +++ b/src/gui/preferences/settingsuserinterfacewidget.cpp @@ -1,144 +1,130 @@ /*************************************************************************** * Copyright (C) 2004-2018 by Thomas Fischer * * * * 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, see . * ***************************************************************************/ #include "settingsuserinterfacewidget.h" #include #include #include #include #include #include #include #include "preferences.h" #include "elementwidgets.h" #include "models/filemodel.h" class SettingsUserInterfaceWidget::SettingsUserInterfaceWidgetPrivate { private: SettingsUserInterfaceWidget *p; QCheckBox *checkBoxShowComments; QCheckBox *checkBoxShowMacros; - KComboBox *comboBoxBibliographySystem; KComboBox *comboBoxElementDoubleClickAction; KSharedConfigPtr config; static const QString configGroupName; public: SettingsUserInterfaceWidgetPrivate(SettingsUserInterfaceWidget *parent) : p(parent), config(KSharedConfig::openConfig(QStringLiteral("kbibtexrc"))) { setupGUI(); } void loadState() { KConfigGroup configGroup(config, configGroupName); checkBoxShowComments->setChecked(configGroup.readEntry(FileModel::keyShowComments, FileModel::defaultShowComments)); checkBoxShowMacros->setChecked(configGroup.readEntry(FileModel::keyShowMacros, FileModel::defaultShowMacros)); - int styleIndex = comboBoxBibliographySystem->findData(configGroup.readEntry("CurrentStyle", QString(QStringLiteral("bibtex")))); - if (styleIndex < 0) styleIndex = 0; - if (styleIndex < comboBoxBibliographySystem->count()) comboBoxBibliographySystem->setCurrentIndex(styleIndex); - comboBoxElementDoubleClickAction->setCurrentIndex(configGroup.readEntry(Preferences::keyElementDoubleClickAction, static_cast(Preferences::defaultElementDoubleClickAction))); } void saveState() { KConfigGroup configGroup(config, configGroupName); configGroup.writeEntry(FileModel::keyShowComments, checkBoxShowComments->isChecked()); configGroup.writeEntry(FileModel::keyShowMacros, checkBoxShowMacros->isChecked()); - configGroup.writeEntry("CurrentStyle", comboBoxBibliographySystem->itemData(comboBoxBibliographySystem->currentIndex()).toString()); configGroup.writeEntry(Preferences::keyElementDoubleClickAction, comboBoxElementDoubleClickAction->currentIndex()); config->sync(); } void resetToDefaults() { checkBoxShowComments->setChecked(FileModel::defaultShowComments); checkBoxShowMacros->setChecked(FileModel::defaultShowMacros); - comboBoxBibliographySystem->setCurrentIndex(0); comboBoxElementDoubleClickAction->setCurrentIndex(Preferences::defaultElementDoubleClickAction); } void setupGUI() { QFormLayout *layout = new QFormLayout(p); checkBoxShowComments = new QCheckBox(p); layout->addRow(i18n("Show Comments:"), checkBoxShowComments); connect(checkBoxShowComments, &QCheckBox::toggled, p, &SettingsUserInterfaceWidget::changed); checkBoxShowMacros = new QCheckBox(p); layout->addRow(i18n("Show Macros:"), checkBoxShowMacros); connect(checkBoxShowMacros, &QCheckBox::toggled, p, &SettingsUserInterfaceWidget::changed); - comboBoxBibliographySystem = new KComboBox(p); - comboBoxBibliographySystem->setObjectName(QStringLiteral("comboBoxBibtexStyle")); - comboBoxBibliographySystem->addItem(i18n("BibTeX"), QStringLiteral("bibtex")); - comboBoxBibliographySystem->addItem(i18n("BibLaTeX"), QStringLiteral("biblatex")); - layout->addRow(i18n("Bibliography System:"), comboBoxBibliographySystem); - connect(comboBoxBibliographySystem, static_cast(&QComboBox::currentIndexChanged), p, &SettingsUserInterfaceWidget::changed); - comboBoxElementDoubleClickAction = new KComboBox(p); comboBoxElementDoubleClickAction->setObjectName(QStringLiteral("comboBoxElementDoubleClickAction")); comboBoxElementDoubleClickAction->addItem(i18n("Open Editor")); ///< ActionOpenEditor = 0 comboBoxElementDoubleClickAction->addItem(i18n("View Document")); ///< ActionViewDocument = 1 layout->addRow(i18n("When double-clicking an element:"), comboBoxElementDoubleClickAction); connect(comboBoxElementDoubleClickAction, static_cast(&QComboBox::currentIndexChanged), p, &SettingsUserInterfaceWidget::changed); } }; const QString SettingsUserInterfaceWidget::SettingsUserInterfaceWidgetPrivate::configGroupName = QStringLiteral("User Interface"); SettingsUserInterfaceWidget::SettingsUserInterfaceWidget(QWidget *parent) : SettingsAbstractWidget(parent), d(new SettingsUserInterfaceWidgetPrivate(this)) { d->loadState(); } QString SettingsUserInterfaceWidget::label() const { return i18n("User Interface"); } QIcon SettingsUserInterfaceWidget::icon() const { return QIcon::fromTheme(QStringLiteral("user-identity")); } SettingsUserInterfaceWidget::~SettingsUserInterfaceWidget() { delete d; } void SettingsUserInterfaceWidget::loadState() { d->loadState(); } void SettingsUserInterfaceWidget::saveState() { d->saveState(); } void SettingsUserInterfaceWidget::resetToDefaults() { d->resetToDefaults(); }