File indexing completed on 2025-02-16 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 "insertspecialcharacterplugineditorinterface.h"
0008 #include <KActionCollection>
0009 #include <KLocalizedString>
0010 #include <QAction>
0011 
0012 InsertSpecialCharacterPluginEditorInterface::InsertSpecialCharacterPluginEditorInterface(QObject *parent)
0013     : MessageComposer::PluginEditorInterface(parent)
0014 {
0015 }
0016 
0017 InsertSpecialCharacterPluginEditorInterface::~InsertSpecialCharacterPluginEditorInterface() = default;
0018 
0019 void InsertSpecialCharacterPluginEditorInterface::createAction(KActionCollection *ac)
0020 {
0021     auto action = new QAction(i18n("Insert Special Character..."), this);
0022     ac->addAction(QStringLiteral("insert_special_character"), action);
0023     connect(action, &QAction::triggered, this, &InsertSpecialCharacterPluginEditorInterface::slotActivated);
0024     MessageComposer::PluginActionType type(action, MessageComposer::PluginActionType::Insert);
0025     setActionType(type);
0026 }
0027 
0028 void InsertSpecialCharacterPluginEditorInterface::slotActivated()
0029 {
0030     Q_EMIT emitPluginActivated(this);
0031 }
0032 
0033 void InsertSpecialCharacterPluginEditorInterface::exec()
0034 {
0035     if (!mSelectSpecialChar) {
0036         mSelectSpecialChar = new TextAddonsWidgets::SelectSpecialCharDialog(parentWidget());
0037         mSelectSpecialChar->setWindowTitle(i18nc("@title:window", "Insert Special Character"));
0038         mSelectSpecialChar->setOkButtonText(i18n("Insert"));
0039         connect(mSelectSpecialChar.data(),
0040                 &TextAddonsWidgets::SelectSpecialCharDialog::charSelected,
0041                 this,
0042                 &InsertSpecialCharacterPluginEditorInterface::charSelected);
0043     }
0044     mSelectSpecialChar->show();
0045 }
0046 
0047 void InsertSpecialCharacterPluginEditorInterface::charSelected(QChar c)
0048 {
0049     Q_EMIT insertText(c);
0050 }
0051 
0052 #include "moc_insertspecialcharacterplugineditorinterface.cpp"