File indexing completed on 2025-01-19 04:46:39

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 "changecaseplugineditorinterface.h"
0008 #include "changecaseeditorplugin_debug.h"
0009 #include <KActionCollection>
0010 #include <PimCommon/KActionMenuChangeCase>
0011 #include <QAction>
0012 #include <TextCustomEditor/RichTextEditor>
0013 #include <TextUtils/ConvertText>
0014 
0015 ChangeCasePluginEditorInterface::ChangeCasePluginEditorInterface(QObject *parent)
0016     : MessageComposer::PluginEditorInterface(parent)
0017 {
0018     setNeedSelectedText(true);
0019 }
0020 
0021 ChangeCasePluginEditorInterface::~ChangeCasePluginEditorInterface() = default;
0022 
0023 void ChangeCasePluginEditorInterface::createAction(KActionCollection *ac)
0024 {
0025     auto ChangeCaseMenu = new PimCommon::KActionMenuChangeCase(this);
0026     ChangeCaseMenu->appendInActionCollection(ac);
0027     ac->addAction(QStringLiteral("change_case_menu"), ChangeCaseMenu);
0028     connect(ChangeCaseMenu, &PimCommon::KActionMenuChangeCase::upperCase, this, &ChangeCasePluginEditorInterface::slotUpperCase);
0029     connect(ChangeCaseMenu, &PimCommon::KActionMenuChangeCase::lowerCase, this, &ChangeCasePluginEditorInterface::slotLowerCase);
0030     connect(ChangeCaseMenu, &PimCommon::KActionMenuChangeCase::sentenceCase, this, &ChangeCasePluginEditorInterface::slotSentenceCase);
0031     connect(ChangeCaseMenu, &PimCommon::KActionMenuChangeCase::reverseCase, this, &ChangeCasePluginEditorInterface::slotReverseCase);
0032     MessageComposer::PluginActionType type(ChangeCaseMenu, MessageComposer::PluginActionType::Edit);
0033     setActionType(type);
0034 }
0035 
0036 void ChangeCasePluginEditorInterface::exec()
0037 {
0038     switch (mType) {
0039     case Unknown:
0040         qCWarning(KMAIL_EDITOR_CHANGECASE_PLUGIN_LOG) << " There is an error here. We can't call this plugin with unknown type";
0041         break;
0042     case UpperCase:
0043         upperCase();
0044         break;
0045     case LowerCase:
0046         lowerCase();
0047         break;
0048     case SentenseCase:
0049         sentenceCase();
0050         break;
0051     case ReverseCase:
0052         reverseCase();
0053         break;
0054     }
0055     mType = Unknown;
0056 }
0057 
0058 void ChangeCasePluginEditorInterface::sentenceCase()
0059 {
0060     QTextCursor textCursor = richTextEditor()->textCursor();
0061     TextUtils::ConvertText::sentenceCase(textCursor);
0062 }
0063 
0064 void ChangeCasePluginEditorInterface::upperCase()
0065 {
0066     QTextCursor textCursor = richTextEditor()->textCursor();
0067     TextUtils::ConvertText::upperCase(textCursor);
0068 }
0069 
0070 void ChangeCasePluginEditorInterface::lowerCase()
0071 {
0072     QTextCursor textCursor = richTextEditor()->textCursor();
0073     TextUtils::ConvertText::lowerCase(textCursor);
0074 }
0075 
0076 void ChangeCasePluginEditorInterface::reverseCase()
0077 {
0078     QTextCursor textCursor = richTextEditor()->textCursor();
0079     TextUtils::ConvertText::reverseCase(textCursor);
0080 }
0081 
0082 void ChangeCasePluginEditorInterface::slotUpperCase()
0083 {
0084     mType = UpperCase;
0085     Q_EMIT emitPluginActivated(this);
0086 }
0087 
0088 void ChangeCasePluginEditorInterface::slotLowerCase()
0089 {
0090     mType = LowerCase;
0091     Q_EMIT emitPluginActivated(this);
0092 }
0093 
0094 void ChangeCasePluginEditorInterface::slotSentenceCase()
0095 {
0096     mType = SentenseCase;
0097     Q_EMIT emitPluginActivated(this);
0098 }
0099 
0100 void ChangeCasePluginEditorInterface::slotReverseCase()
0101 {
0102     mType = ReverseCase;
0103     Q_EMIT emitPluginActivated(this);
0104 }
0105 
0106 #include "moc_changecaseplugineditorinterface.cpp"