File indexing completed on 2024-12-22 05:01:03
0001 /* 0002 SPDX-FileCopyrightText: 2019-2024 Laurent Montel <montel@kde.org> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #include "spellcheckerconfigdialog.h" 0008 #include "kmail_debug.h" 0009 #include "kmkernel.h" 0010 #include <QCheckBox> 0011 #include <QLabel> 0012 0013 #include <Sonnet/DictionaryComboBox> 0014 0015 #include <KConfigGroup> 0016 #include <KSharedConfig> 0017 #include <KWindowConfig> 0018 #include <QWindow> 0019 0020 SpellCheckerConfigDialog::SpellCheckerConfigDialog(QWidget *parent) 0021 : Sonnet::ConfigDialog(parent) 0022 { 0023 // Hackish way to hide the "Enable spell check by default" checkbox 0024 // Our highlighter ignores this setting, so we should not expose its UI 0025 auto enabledByDefaultCB = findChild<QCheckBox *>(QStringLiteral("kcfg_autodetectLanguage")); 0026 if (enabledByDefaultCB) { 0027 enabledByDefaultCB->hide(); 0028 } else { 0029 qCWarning(KMAIL_LOG) << "Could not find any checkbox named 'm_checkerEnabledByDefaultCB'. Sonnet::ConfigDialog must have changed!"; 0030 } 0031 auto textLabel = findChild<QLabel *>(QStringLiteral("textLabel1")); 0032 if (textLabel) { 0033 textLabel->hide(); 0034 } else { 0035 qCWarning(KMAIL_LOG) << "Could not find any label named 'textLabel'. Sonnet::ConfigDialog must have changed!"; 0036 } 0037 auto dictionaryComboBox = findChild<Sonnet::DictionaryComboBox *>(QStringLiteral("m_langCombo")); 0038 if (dictionaryComboBox) { 0039 dictionaryComboBox->hide(); 0040 } else { 0041 qCWarning(KMAIL_LOG) << "Could not find any Sonnet::DictionaryComboBox named 'dictionaryComboBox'. Sonnet::ConfigDialog must have changed!"; 0042 } 0043 readConfig(); 0044 } 0045 0046 SpellCheckerConfigDialog::~SpellCheckerConfigDialog() 0047 { 0048 writeConfig(); 0049 } 0050 0051 void SpellCheckerConfigDialog::readConfig() 0052 { 0053 create(); // ensure a window is created 0054 windowHandle()->resize(QSize(600, 400)); 0055 KConfigGroup group(KSharedConfig::openStateConfig(), QStringLiteral("SpellCheckerConfigDialog")); 0056 KWindowConfig::restoreWindowSize(windowHandle(), group); 0057 resize(windowHandle()->size()); // workaround for QTBUG-40584 0058 } 0059 0060 void SpellCheckerConfigDialog::writeConfig() 0061 { 0062 KConfigGroup notifyDialog(KSharedConfig::openStateConfig(), QStringLiteral("SpellCheckerConfigDialog")); 0063 KWindowConfig::saveWindowSize(windowHandle(), notifyDialog); 0064 notifyDialog.sync(); 0065 } 0066 0067 #include "moc_spellcheckerconfigdialog.cpp"