File indexing completed on 2024-02-18 05:27:42

0001 /*
0002  *   SPDX-FileCopyrightText: 2008 Laurent Montel <montel@kde.org>
0003  *
0004  *   SPDX-License-Identifier: GPL-2.0-or-later
0005  *
0006  */
0007 
0008 #include "preferencesdlg.h"
0009 
0010 #include <QCheckBox>
0011 #include <QGroupBox>
0012 #include <QHBoxLayout>
0013 #include <QPushButton>
0014 
0015 #include "configurationmanager.h"
0016 #include <KLocalizedString>
0017 #include <sonnet/configwidget.h>
0018 
0019 PreferencesDialog::PreferencesDialog(QWidget *parent)
0020     : KPageDialog(parent)
0021 {
0022     setFaceType(List);
0023     setStandardButtons(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
0024 
0025     m_pageMisc = new MiscPage(this);
0026     KPageWidgetItem *page = new KPageWidgetItem(m_pageMisc, i18n("General options"));
0027     page->setIcon(QIcon::fromTheme(QStringLiteral("kmenuedit")));
0028     addPage(page);
0029 
0030     m_pageSpellChecking = new SpellCheckingPage(this);
0031     page = new KPageWidgetItem(m_pageSpellChecking, i18n("Spell Checking"));
0032     page->setHeader(i18n("Spell checking Options"));
0033     page->setIcon(QIcon::fromTheme(QStringLiteral("tools-check-spelling")));
0034     addPage(page);
0035 
0036     connect(button(QDialogButtonBox::Ok), &QPushButton::clicked, this, &PreferencesDialog::slotSave);
0037 }
0038 
0039 void PreferencesDialog::slotSave()
0040 {
0041     m_pageSpellChecking->saveOptions();
0042     m_pageMisc->saveOptions();
0043 }
0044 
0045 SpellCheckingPage::SpellCheckingPage(QWidget *parent)
0046     : QWidget(parent)
0047 {
0048     QHBoxLayout *lay = new QHBoxLayout(this);
0049     m_confPage = new Sonnet::ConfigWidget(this);
0050     lay->addWidget(m_confPage);
0051     setLayout(lay);
0052 }
0053 
0054 void SpellCheckingPage::saveOptions()
0055 {
0056     m_confPage->save();
0057 }
0058 
0059 MiscPage::MiscPage(QWidget *parent)
0060     : QWidget(parent)
0061 {
0062     // general group
0063     QGroupBox *generalGroup = new QGroupBox(i18n("General"));
0064     QVBoxLayout *generalGroupLayout = new QVBoxLayout(generalGroup);
0065     m_showHiddenEntries = new QCheckBox(i18n("Show hidden entries"));
0066     generalGroupLayout->addWidget(m_showHiddenEntries);
0067 
0068     // add groups
0069     QVBoxLayout *pageLayout = new QVBoxLayout(this);
0070     pageLayout->addWidget(generalGroup);
0071     pageLayout->addStretch();
0072 
0073     // update displayed config
0074     m_showHiddenEntries->setChecked(ConfigurationManager::getInstance()->hiddenEntriesVisible());
0075 }
0076 
0077 void MiscPage::saveOptions()
0078 {
0079     ConfigurationManager::getInstance()->setHiddenEntriesVisible(m_showHiddenEntries->isChecked());
0080 }