File indexing completed on 2025-01-05 04:49:27

0001 /*
0002    SPDX-FileCopyrightText: 2016-2024 Laurent Montel <montel@kde.org>
0003 
0004    SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #include "autocorrectionplugineditorinterface.h"
0008 #include <KActionCollection>
0009 #include <KActionMenu>
0010 #include <KLocalizedString>
0011 #include <QAction>
0012 #include <TextCustomEditor/RichTextEditor>
0013 
0014 AutoCorrectionPluginEditorInterface::AutoCorrectionPluginEditorInterface(QObject *parent)
0015     : MessageComposer::PluginEditorInterface(parent)
0016 {
0017 }
0018 
0019 AutoCorrectionPluginEditorInterface::~AutoCorrectionPluginEditorInterface() = default;
0020 
0021 void AutoCorrectionPluginEditorInterface::createAction(KActionCollection *ac)
0022 {
0023     auto menu = new KActionMenu(i18n("Autocorrect Text"), this);
0024     ac->addAction(QStringLiteral("autocorrect_tool"), menu);
0025     MessageComposer::PluginActionType type(menu, MessageComposer::PluginActionType::Tools);
0026     setActionType(type);
0027 
0028     auto action = new QAction(i18n("Autocorrect Full Text"), this);
0029     menu->addAction(action);
0030     connect(action, &QAction::triggered, this, &AutoCorrectionPluginEditorInterface::slotAutoCorrectAllText);
0031 
0032     action = new QAction(i18n("Autocorrect Selected Text"), this);
0033     menu->addAction(action);
0034     connect(action, &QAction::triggered, this, &AutoCorrectionPluginEditorInterface::slotAutoCorrectSelectedText);
0035 }
0036 
0037 void AutoCorrectionPluginEditorInterface::slotAutoCorrectSelectedText()
0038 {
0039     mSelectedText = true;
0040     Q_EMIT emitPluginActivated(this);
0041 }
0042 
0043 void AutoCorrectionPluginEditorInterface::slotAutoCorrectAllText()
0044 {
0045     mSelectedText = false;
0046     Q_EMIT emitPluginActivated(this);
0047 }
0048 
0049 void AutoCorrectionPluginEditorInterface::exec()
0050 {
0051     richTextEditor()->forceAutoCorrection(mSelectedText);
0052 }
0053 
0054 #include "moc_autocorrectionplugineditorinterface.cpp"