File indexing completed on 2024-05-12 16:27:07

0001 /*
0002    SPDX-FileCopyrightText: 2020-2024 Laurent Montel <montel@kde.org>
0003 
0004    SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #include "configurefontwidget.h"
0008 #include "ruqolaglobalconfig.h"
0009 #include <KFontChooser>
0010 #include <KLocalizedString>
0011 
0012 #include <QCheckBox>
0013 #include <QVBoxLayout>
0014 
0015 ConfigureFontWidget::ConfigureFontWidget(QWidget *parent)
0016     : QWidget(parent)
0017     , mCustomFontCheck(new QCheckBox(i18n("&Use custom fonts"), this))
0018     , mFontChooser(new KFontChooser(KFontChooser::DisplayFrame, this))
0019 {
0020     mFontChooser->setMinVisibleItems(4);
0021     auto mainLayout = new QVBoxLayout(this);
0022     mainLayout->setObjectName(QStringLiteral("mainLayout"));
0023 
0024     mCustomFontCheck->setObjectName(QStringLiteral("mCustomFontCheck"));
0025     mainLayout->addWidget(mCustomFontCheck);
0026 
0027     mFontChooser->setObjectName(QStringLiteral("mFontChooser"));
0028     mFontChooser->setEnabled(false); // since !mCustomFontCheck->isChecked()
0029     mainLayout->addWidget(mFontChooser);
0030     connect(mCustomFontCheck, &QCheckBox::toggled, mFontChooser, &KFontChooser::setEnabled);
0031 }
0032 
0033 ConfigureFontWidget::~ConfigureFontWidget() = default;
0034 
0035 void ConfigureFontWidget::save()
0036 {
0037     RuqolaGlobalConfig::self()->setUseCustomFont(mCustomFontCheck->isChecked());
0038     RuqolaGlobalConfig::self()->setGeneralFont(mFontChooser->font());
0039     RuqolaGlobalConfig::self()->save();
0040 }
0041 
0042 void ConfigureFontWidget::load()
0043 {
0044     mCustomFontCheck->setChecked(RuqolaGlobalConfig::self()->useCustomFont());
0045     mFontChooser->setFont(RuqolaGlobalConfig::self()->generalFont());
0046 }
0047 
0048 #include "moc_configurefontwidget.cpp"