7#include "templatestexteditor.h"
8#include "templatesutil_p.h"
10#include <TextCustomEditor/PlainTextSyntaxSpellCheckingHighlighter>
11#include <TextCustomEditor/TextEditorCompleter>
13#include <KSyntaxHighlighting/Definition>
14#include <KSyntaxHighlighting/Theme>
16#include <QAbstractItemView>
18#include <QFontDatabase>
20using namespace TemplateParser;
22TemplatesTextEditor::TemplatesTextEditor(
QWidget *parent)
23 : TextCustomEditor::PlainTextEditor(parent)
29 const QStringList lst = TemplateParser::Util::keywords();
35 addIgnoreWords(excludeKeyWord);
41TemplatesTextEditor::~TemplatesTextEditor() =
default;
43void TemplatesTextEditor::updateHighLighter()
45 auto hlighter =
dynamic_cast<TextCustomEditor::PlainTextSyntaxSpellCheckingHighlighter *
>(highlighter());
47 hlighter->toggleSpellHighlighting(checkSpellingEnabled());
51void TemplatesTextEditor::clearDecorator()
56void TemplatesTextEditor::createHighlighter()
58 auto highlighter =
new TextCustomEditor::PlainTextSyntaxSpellCheckingHighlighter(
this);
59 highlighter->toggleSpellHighlighting(checkSpellingEnabled());
60 highlighter->setCurrentLanguage(spellCheckingLanguage());
61 highlighter->setDefinition(mSyntaxRepo.definitionForName(QStringLiteral(
"KMail Template")));
64 setHighlighter(highlighter);
67void TemplatesTextEditor::initCompleter()
70 QStringList excludeKeyWord;
71 const QStringList lst = TemplateParser::Util::keywords();
73 for (QString str : lst) {
74 excludeKeyWord << str.
replace(QLatin1StringView(
"\\("), QLatin1StringView(
"("));
76 listWord << excludeKeyWord;
77 listWord << Util::keywordsWithArgs();
79 mTextEditorCompleter =
new TextCustomEditor::TextEditorCompleter(
this,
this);
80 mTextEditorCompleter->setCompleterStringList(listWord);
81 mTextEditorCompleter->setExcludeOfCharacters(QStringLiteral(
"~!@#$^&*()+{}|\"<>,./;'[]\\-= "));
84void TemplatesTextEditor::keyPressEvent(QKeyEvent *e)
86 if (mTextEditorCompleter->completer()->popup()->isVisible()) {
100 mTextEditorCompleter->completeText();
103#include "moc_templatestexteditor.cpp"
QFont systemFont(SystemFont type)
qsizetype count() const const
void remove(qsizetype i, qsizetype n)
void replace(qsizetype i, parameter_type value)
void reserve(qsizetype size)