Git commit 602f72f54164870f057c6d00a6cd6e0d11360268 by Montel Laurent. Committed on 30/06/2015 at 20:50. Pushed by mlaurent into branch 'master'. Fix highlighter + spell checking. Use a PlainTextEditor directly M +1 -0 templateparser/CMakeLists.txt M +1 -1 templateparser/customtemplates.cpp M +4 -4 templateparser/templatesconfiguration.cpp M +2 -2 templateparser/templatesconfiguration.h M +2 -21 templateparser/templatessyntaxhighlighter.cpp M +2 -1 templateparser/templatessyntaxhighlighter.h A +59 -0 templateparser/templatessyntaxhighlighterrules.cpp [Lice= nse: GPL (v2)] C +15 -19 templateparser/templatessyntaxhighlighterrules.h [from: temp= lateparser/templatestexteditor.h - 053% similarity] M +1 -1 templateparser/templatestextedit.cpp M +2 -2 templateparser/templatestextedit.h M +28 -2 templateparser/templatestexteditor.cpp M +6 -2 templateparser/templatestexteditor.h M +1 -4 templateparser/ui/customtemplates_base.ui M +1 -13 templateparser/ui/templatesconfiguration_base.ui http://commits.kde.org/kdepim/602f72f54164870f057c6d00a6cd6e0d11360268 diff --git a/templateparser/CMakeLists.txt b/templateparser/CMakeLists.txt index f5e3956..e4a094a 100644 --- a/templateparser/CMakeLists.txt +++ b/templateparser/CMakeLists.txt @@ -19,6 +19,7 @@ set(templateparser_LIB_SRCS templatestextedit.cpp templatestexteditor.cpp templateparser_debug.cpp + templatessyntaxhighlighterrules.cpp ) = include_directories( diff --git a/templateparser/customtemplates.cpp b/templateparser/customtemp= lates.cpp index 1ab442e..318eb5a 100644 --- a/templateparser/customtemplates.cpp +++ b/templateparser/customtemplates.cpp @@ -21,7 +21,7 @@ #include "customtemplates_kfg.h" #include "globalsettings_base.h" #include "ui_customtemplates_base.h" -#include "pimcommon/texteditor/richtexteditor/richtexteditor.h" +#include "pimcommon/texteditor/plaintexteditor/plaintexteditor.h" = #include #include diff --git a/templateparser/templatesconfiguration.cpp b/templateparser/tem= platesconfiguration.cpp index 3e62f9c..92706db7b 100644 --- a/templateparser/templatesconfiguration.cpp +++ b/templateparser/templatesconfiguration.cpp @@ -20,7 +20,7 @@ #include "templatesconfiguration.h" #include "globalsettings_base.h" #include "templatesconfiguration_kfg.h" -#include "pimcommon/texteditor/richtexteditor/richtexteditor.h" +#include "pimcommon/texteditor/plaintexteditor/plaintexteditor.h" = #include #include @@ -327,9 +327,9 @@ void TemplatesConfiguration::saveToFolder(const QString= &id) t.save(); } = -QTextEdit *TemplatesConfiguration::currentTextEdit() const +QPlainTextEdit *TemplatesConfiguration::currentTextEdit() const { - QTextEdit *edit; + QPlainTextEdit *edit; = const int toolboxCurrentIndex(toolBox1->currentIndex()); if (toolBox1->widget(toolboxCurrentIndex) =3D=3D page_new) { @@ -349,7 +349,7 @@ QTextEdit *TemplatesConfiguration::currentTextEdit() co= nst = void TemplatesConfiguration::slotInsertCommand(const QString &cmd, int adj= ustCursor) { - QTextEdit *edit =3D currentTextEdit(); + QPlainTextEdit *edit =3D currentTextEdit(); if (!edit) { return; } diff --git a/templateparser/templatesconfiguration.h b/templateparser/templ= atesconfiguration.h index 96b17bf..c48a220 100644 --- a/templateparser/templatesconfiguration.h +++ b/templateparser/templatesconfiguration.h @@ -21,7 +21,7 @@ = #include "templateparser_export.h" #include "ui_templatesconfiguration_base.h" -class QTextEdit; +class QPlainTextEdit; namespace TemplateParser { = @@ -56,7 +56,7 @@ Q_SIGNALS: void changed(); = private: - QTextEdit *currentTextEdit() const; + QPlainTextEdit *currentTextEdit() const; QString strOrBlank(const QString &str); QString mHelpString; = diff --git a/templateparser/templatessyntaxhighlighter.cpp b/templateparser= /templatessyntaxhighlighter.cpp index 5aa6df7..cda3e7f 100644 --- a/templateparser/templatessyntaxhighlighter.cpp +++ b/templateparser/templatessyntaxhighlighter.cpp @@ -17,8 +17,7 @@ */ = #include "templatessyntaxhighlighter.h" -#include "templatesutil.h" -#include +#include "templatessyntaxhighlighterrules.h" = using namespace TemplateParser; = @@ -34,24 +33,6 @@ TemplatesSyntaxHighlighter::~TemplatesSyntaxHighlighter() = void TemplatesSyntaxHighlighter::init() { - QTextCharFormat keywordFormat; - QPalette palette; - keywordFormat.setForeground(palette.link()); - - const QStringList keywords =3D QStringList() << Util::keywords(); - - Q_FOREACH (const QString &s, keywords) { - const QRegExp regex(s, Qt::CaseInsensitive); - m_rules.append(KPIMTextEdit::Rule(regex, keywordFormat)); - } - - QTextCharFormat keywordWithArgsFormat; - keywordWithArgsFormat.setForeground(palette.link()); - const QStringList keywordsWithArgs =3D QStringList() << Util::keywords= WithArgsForCompleter(); - - Q_FOREACH (const QString &s, keywordsWithArgs) { - const QRegExp regex(s, Qt::CaseInsensitive); - m_rules.append(KPIMTextEdit::Rule(regex, keywordWithArgsFormat)); - } + m_rules =3D mRules.rules(); } = diff --git a/templateparser/templatessyntaxhighlighter.h b/templateparser/t= emplatessyntaxhighlighter.h index 6e89753..8a4be00 100644 --- a/templateparser/templatessyntaxhighlighter.h +++ b/templateparser/templatessyntaxhighlighter.h @@ -20,11 +20,11 @@ #define TEMPLATEPARSER_TEMPLATESSYNTAXHIGHLIGHTER_H = #include "templateparser_export.h" +#include "templatessyntaxhighlighterrules.h" #include = namespace TemplateParser { - class TEMPLATEPARSER_EXPORT TemplatesSyntaxHighlighter : public KPIMTextEd= it::SyntaxHighlighterBase { Q_OBJECT @@ -34,6 +34,7 @@ public: = private: void init() Q_DECL_OVERRIDE; + TemplatesSyntaxHighlighterRules mRules; }; = } diff --git a/templateparser/templatessyntaxhighlighterrules.cpp b/templatep= arser/templatessyntaxhighlighterrules.cpp new file mode 100644 index 0000000..83bae43 --- /dev/null +++ b/templateparser/templatessyntaxhighlighterrules.cpp @@ -0,0 +1,59 @@ +/* + Copyright (c) 2015 Montel Laurent + + This program is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License, version 2, as + published by the Free Software Foundation. + + This program is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#include "templatessyntaxhighlighterrules.h" + +#include +#include "templatesutil.h" +#include +#include +using namespace TemplateParser; + +TemplatesSyntaxHighlighterRules::TemplatesSyntaxHighlighterRules() +{ + init(); +} + +void TemplatesSyntaxHighlighterRules::init() +{ + QTextCharFormat keywordFormat; + QPalette palette; + keywordFormat.setForeground(palette.link()); + + const QStringList keywords =3D QStringList() << Util::keywords(); + + Q_FOREACH (const QString &s, keywords) { + const QRegExp regex(s, Qt::CaseInsensitive); + mRules.append(KPIMTextEdit::Rule(regex, keywordFormat)); + } + + QTextCharFormat keywordWithArgsFormat; + keywordWithArgsFormat.setForeground(palette.link()); + const QStringList keywordsWithArgs =3D QStringList() << Util::keywords= WithArgsForCompleter(); + + Q_FOREACH (const QString &s, keywordsWithArgs) { + const QRegExp regex(s, Qt::CaseInsensitive); + mRules.append(KPIMTextEdit::Rule(regex, keywordWithArgsFormat)); + } + +} + +QVector TemplatesSyntaxHighlighterRules::rules() const +{ + return mRules; +} + diff --git a/templateparser/templatestexteditor.h b/templateparser/template= ssyntaxhighlighterrules.h similarity index 53% copy from templateparser/templatestexteditor.h copy to templateparser/templatessyntaxhighlighterrules.h index 0eff200..77e084a 100644 --- a/templateparser/templatestexteditor.h +++ b/templateparser/templatessyntaxhighlighterrules.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2013-2015 Montel Laurent + Copyright (c) 2015 Montel Laurent = This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2, as @@ -15,30 +15,26 @@ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ = -#ifndef TEMPLATESTEXTEDITOR_H -#define TEMPLATESTEXTEDITOR_H -#include "pimcommon/texteditor/richtexteditor/richtexteditor.h" -class QCompleter; -class QKeyEvent; +#ifndef TEMPLATESSYNTAXHIGHLIGHTERRULES_H +#define TEMPLATESSYNTAXHIGHLIGHTERRULES_H + +#include namespace KPIMTextEdit { -class TextEditorCompleter; +class Rule; } -namespace TemplateParser -{ -class TemplatesTextEditor : public PimCommon::RichTextEditor + +namespace TemplateParser { +class TemplatesSyntaxHighlighterRules { - Q_OBJECT public: - explicit TemplatesTextEditor(QWidget *parent =3D Q_NULLPTR); - ~TemplatesTextEditor(); - -protected: - void initCompleter(); - void keyPressEvent(QKeyEvent *e) Q_DECL_OVERRIDE; + TemplatesSyntaxHighlighterRules(); + QVector rules() const; = private: - KPIMTextEdit::TextEditorCompleter *mTextEditorCompleter; + void init(); + QVector mRules; }; } -#endif // TEMPLATESTEXTEDITOR_H + +#endif // TEMPLATESSYNTAXHIGHLIGHTERRULES_H diff --git a/templateparser/templatestextedit.cpp b/templateparser/template= stextedit.cpp index 30972fb..9bbbce6 100644 --- a/templateparser/templatestextedit.cpp +++ b/templateparser/templatestextedit.cpp @@ -22,7 +22,7 @@ using namespace TemplateParser; = TemplatesTextEdit::TemplatesTextEdit(QWidget *parent) - : PimCommon::RichTextEditorWidget(new TemplatesTextEditor, parent) + : PimCommon::PlainTextEditorWidget(new TemplatesTextEditor, parent) { } = diff --git a/templateparser/templatestextedit.h b/templateparser/templatest= extedit.h index d62f6ff..94ce82f 100644 --- a/templateparser/templatestextedit.h +++ b/templateparser/templatestextedit.h @@ -21,11 +21,11 @@ = #include "templateparser_export.h" = -#include "pimcommon/texteditor/richtexteditor/richtexteditorwidget.h" +#include "pimcommon/texteditor/plaintexteditor/plaintexteditorwidget.h" = namespace TemplateParser { -class TEMPLATEPARSER_EXPORT TemplatesTextEdit : public PimCommon::RichText= EditorWidget +class TEMPLATEPARSER_EXPORT TemplatesTextEdit : public PimCommon::PlainTex= tEditorWidget { Q_OBJECT public: diff --git a/templateparser/templatestexteditor.cpp b/templateparser/templa= testexteditor.cpp index a6cc784..60c4624 100644 --- a/templateparser/templatestexteditor.cpp +++ b/templateparser/templatestexteditor.cpp @@ -27,10 +27,12 @@ #include #include = +#include + using namespace TemplateParser; = TemplatesTextEditor::TemplatesTextEditor(QWidget *parent) - : PimCommon::RichTextEditor(parent) + : PimCommon::PlainTextEditor(parent) { setFocus(); const QFont f =3D QFontDatabase::systemFont(QFontDatabase::FixedFont); @@ -50,6 +52,30 @@ TemplatesTextEditor::~TemplatesTextEditor() = } = +void TemplatesTextEditor::updateHighLighter() +{ + PimCommon::PlainTextSyntaxSpellCheckingHighlighter *hlighter =3D dynam= ic_cast(highlighter()= ); + if (hlighter) { + hlighter->toggleSpellHighlighting(checkSpellingEnabled()); + } +} + +void TemplatesTextEditor::clearDecorator() +{ + //Nothing +} + +void TemplatesTextEditor::createHighlighter() +{ + PimCommon::PlainTextSyntaxSpellCheckingHighlighter *highlighter =3D ne= w PimCommon::PlainTextSyntaxSpellCheckingHighlighter(this); + highlighter->toggleSpellHighlighting(checkSpellingEnabled()); + highlighter->setCurrentLanguage(spellCheckingLanguage()); + TemplatesSyntaxHighlighterRules rules; + highlighter->setSyntaxHighlighterRules(rules.rules()); + setHighlighter(highlighter); +} + + void TemplatesTextEditor::initCompleter() { QStringList listWord; @@ -76,6 +102,6 @@ void TemplatesTextEditor::keyPressEvent(QKeyEvent *e) break; } } - PimCommon::RichTextEditor::keyPressEvent(e); + PimCommon::PlainTextEditor::keyPressEvent(e); mTextEditorCompleter->completeText(); } diff --git a/templateparser/templatestexteditor.h b/templateparser/template= stexteditor.h index 0eff200..99b94b3 100644 --- a/templateparser/templatestexteditor.h +++ b/templateparser/templatestexteditor.h @@ -17,7 +17,7 @@ = #ifndef TEMPLATESTEXTEDITOR_H #define TEMPLATESTEXTEDITOR_H -#include "pimcommon/texteditor/richtexteditor/richtexteditor.h" +#include "pimcommon/texteditor/plaintexteditor/plaintexteditor.h" class QCompleter; class QKeyEvent; namespace KPIMTextEdit @@ -26,7 +26,7 @@ class TextEditorCompleter; } namespace TemplateParser { -class TemplatesTextEditor : public PimCommon::RichTextEditor +class TemplatesTextEditor : public PimCommon::PlainTextEditor { Q_OBJECT public: @@ -37,6 +37,10 @@ protected: void initCompleter(); void keyPressEvent(QKeyEvent *e) Q_DECL_OVERRIDE; = + void updateHighLighter() Q_DECL_OVERRIDE; + + void clearDecorator() Q_DECL_OVERRIDE; + void createHighlighter() Q_DECL_OVERRIDE; private: KPIMTextEdit::TextEditorCompleter *mTextEditorCompleter; }; diff --git a/templateparser/ui/customtemplates_base.ui b/templateparser/ui/= customtemplates_base.ui index afc5d94..2425ebc 100644 --- a/templateparser/ui/customtemplates_base.ui +++ b/templateparser/ui/customtemplates_base.ui @@ -218,9 +218,6 @@ This area contains the assoc= iated custom template. - - false - @@ -321,7 +318,7 @@ TemplateParser::TemplatesTextEdit - QTextEdit + QPlainTextEdit
templatestextedit.h
diff --git a/templateparser/ui/templatesconfiguration_base.ui b/templatepar= ser/ui/templatesconfiguration_base.ui index 75f5a4d..965b631 100644 --- a/templateparser/ui/templatesconfiguration_base.ui +++ b/templateparser/ui/templatesconfiguration_base.ui @@ -82,9 +82,6 @@ In this area you create the = template for new email messages. For more information about how to create = the template, press the "How does this work?" link on this dialog= . - - false -
@@ -133,9 +130,6 @@ In this area you create the = template for messages replies. For more information about how to create the= template, press the "How does this work?" link on this dialog. - - false - @@ -184,9 +178,6 @@ In this area you create the = template for reply-to-all messages or replies to a mailing list. For more = information about how to create the template, press the "How does this= work?" link on this dialog. - - false - @@ -235,9 +226,6 @@ In this area you create the = template for message forwards. For more information about how to create th= e template, press the "How does this work?" link on this dialog.<= /string> - - false - @@ -301,7 +289,7 @@ TemplateParser::TemplatesTextEdit - QTextEdit + QPlainTextEdit
templatestextedit.h