File indexing completed on 2024-12-22 05:01:05
0001 /* 0002 SPDX-FileCopyrightText: 2015-2024 Laurent Montel <montel@kde.org> 0003 0004 SPDX-License-Identifier: GPL-2.0-only 0005 */ 0006 0007 #include "kmcomposereditorng.h" 0008 #include "dialog/spellcheckerconfigdialog.h" 0009 #include "job/dndfromarkjob.h" 0010 #include "kmcomposerwin.h" 0011 #include "kmkernel.h" 0012 0013 #include <KPIMTextEdit/RichTextComposerEmailQuoteHighlighter> 0014 #include <KToggleAction> 0015 #include <MessageCore/ColorUtil> 0016 #include <MessageCore/MessageCoreSettings> 0017 #include <QCheckBox> 0018 #include <QMenu> 0019 #include <QMimeData> 0020 #include <Sonnet/ConfigDialog> 0021 #include <sonnet/dictionarycombobox.h> 0022 0023 namespace 0024 { 0025 inline QString textSnippetMimeType() 0026 { 0027 return QStringLiteral("text/x-kmail-textsnippet"); 0028 } 0029 } 0030 0031 KMComposerEditorNg::KMComposerEditorNg(KMComposerWin *win, QWidget *parent) 0032 : MessageComposer::RichTextComposerNg(parent) 0033 , mComposerWin(win) 0034 { 0035 setSpellCheckingConfigFileName(QStringLiteral("kmail2rc")); 0036 setAutocorrection(KMKernel::self()->composerAutoCorrection()); 0037 createHighlighter(); 0038 } 0039 0040 KMComposerEditorNg::~KMComposerEditorNg() = default; 0041 0042 void KMComposerEditorNg::addExtraMenuEntry(QMenu *menu, QPoint pos) 0043 { 0044 Q_UNUSED(pos) 0045 const QList<QAction *> lstAct = mComposerWin->pluginToolsActionListForPopupMenu(); 0046 for (QAction *a : lstAct) { 0047 menu->addSeparator(); 0048 menu->addAction(a); 0049 } 0050 0051 menu->addSeparator(); 0052 const QList<KToggleAction *> lstTa = mComposerWin->customToolsList(); 0053 for (KToggleAction *ta : lstTa) { 0054 menu->addAction(ta); 0055 } 0056 } 0057 0058 bool KMComposerEditorNg::canInsertFromMimeData(const QMimeData *source) const 0059 { 0060 if (source->hasImage() && source->hasFormat(QStringLiteral("image/png"))) { 0061 return true; 0062 } 0063 if (source->hasFormat(textSnippetMimeType())) { 0064 return true; 0065 } 0066 if (source->hasUrls()) { 0067 return true; 0068 } 0069 0070 if (DndFromArkJob::dndFromArk(source)) { 0071 return true; 0072 } 0073 0074 return MessageComposer::RichTextComposerNg::canInsertFromMimeData(source); 0075 } 0076 0077 void KMComposerEditorNg::insertFromMimeData(const QMimeData *source) 0078 { 0079 if (source->hasFormat(textSnippetMimeType())) { 0080 Q_EMIT insertSnippet(); 0081 return; 0082 } 0083 0084 if (!mComposerWin->insertFromMimeData(source, false)) { 0085 MessageComposer::RichTextComposerNg::insertFromMimeData(source); 0086 } 0087 } 0088 0089 void KMComposerEditorNg::setHighlighterColors(KPIMTextEdit::RichTextComposerEmailQuoteHighlighter *highlighter) 0090 { 0091 QColor color1 = MessageCore::ColorUtil::self()->quoteLevel1DefaultTextColor(); 0092 QColor color2 = MessageCore::ColorUtil::self()->quoteLevel2DefaultTextColor(); 0093 QColor color3 = MessageCore::ColorUtil::self()->quoteLevel3DefaultTextColor(); 0094 const QColor misspelled = MessageCore::ColorUtil::self()->misspelledDefaultTextColor(); 0095 0096 if (!MessageCore::MessageCoreSettings::self()->useDefaultColors()) { 0097 color1 = MessageCore::MessageCoreSettings::self()->quotedText1(); 0098 color2 = MessageCore::MessageCoreSettings::self()->quotedText2(); 0099 color3 = MessageCore::MessageCoreSettings::self()->quotedText3(); 0100 } 0101 0102 highlighter->setQuoteColor(Qt::black /* ignored anyway */, color1, color2, color3, misspelled); 0103 } 0104 0105 QString KMComposerEditorNg::smartQuote(const QString &msg) 0106 { 0107 return mComposerWin->smartQuote(msg); 0108 } 0109 0110 void KMComposerEditorNg::showSpellConfigDialog(const QString &configFileName) 0111 { 0112 Q_UNUSED(configFileName) 0113 QPointer<SpellCheckerConfigDialog> dialog = new SpellCheckerConfigDialog(this); 0114 if (!spellCheckingLanguage().isEmpty()) { 0115 dialog->setLanguage(spellCheckingLanguage()); 0116 } 0117 0118 if (dialog->exec()) { 0119 setSpellCheckingLanguage(dialog->language()); 0120 } 0121 delete dialog; 0122 } 0123 0124 MessageComposer::PluginEditorConvertTextInterface::ConvertTextStatus KMComposerEditorNg::convertPlainText(MessageComposer::TextPart *textPart) 0125 { 0126 if (mComposerWin->convertPlainText(textPart) == MessageComposer::PluginEditorConvertTextInterface::ConvertTextStatus::Converted) { 0127 return MessageComposer::PluginEditorConvertTextInterface::ConvertTextStatus::Converted; 0128 } 0129 return MessageComposer::PluginEditorConvertTextInterface::ConvertTextStatus::NotConverted; 0130 } 0131 0132 bool KMComposerEditorNg::processModifyText(QKeyEvent *event) 0133 { 0134 if (!mComposerWin->processModifyText(event)) { 0135 return MessageComposer::RichTextComposerNg::processModifyText(event); 0136 } 0137 return true; 0138 } 0139 0140 #include "moc_kmcomposereditorng.cpp"