[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: [kdepim] templateparser: Fix highlighter + spell checking. Use a PlainTextEditor directly
From: Montel Laurent <montel () kde ! org>
Date: 2015-06-30 20:52:47
Message-ID: E1ZA2WN-0005cx-Hb () scm ! kde ! org
[Download RAW message or body]
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 [License: GPL \
(v2)] C +15 -19 templateparser/templatessyntaxhighlighterrules.h [from: \
templateparser/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/customtemplates.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 <KIconLoader>
#include <KLocalizedString>
diff --git a/templateparser/templatesconfiguration.cpp \
b/templateparser/templatesconfiguration.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 <KMessageBox>
#include <KLocalizedString>
@@ -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) == page_new) {
@@ -349,7 +349,7 @@ QTextEdit *TemplatesConfiguration::currentTextEdit() const
void TemplatesConfiguration::slotInsertCommand(const QString &cmd, int adjustCursor)
{
- QTextEdit *edit = currentTextEdit();
+ QPlainTextEdit *edit = currentTextEdit();
if (!edit) {
return;
}
diff --git a/templateparser/templatesconfiguration.h \
b/templateparser/templatesconfiguration.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 <QPalette>
+#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 = 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 = QStringList() << \
Util::keywordsWithArgsForCompleter();
-
- Q_FOREACH (const QString &s, keywordsWithArgs) {
- const QRegExp regex(s, Qt::CaseInsensitive);
- m_rules.append(KPIMTextEdit::Rule(regex, keywordWithArgsFormat));
- }
+ m_rules = mRules.rules();
}
diff --git a/templateparser/templatessyntaxhighlighter.h \
b/templateparser/templatessyntaxhighlighter.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 <KPIMTextEdit/SyntaxHighlighterBase>
namespace TemplateParser
{
-
class TEMPLATEPARSER_EXPORT TemplatesSyntaxHighlighter : public \
KPIMTextEdit::SyntaxHighlighterBase {
Q_OBJECT
@@ -34,6 +34,7 @@ public:
private:
void init() Q_DECL_OVERRIDE;
+ TemplatesSyntaxHighlighterRules mRules;
};
}
diff --git a/templateparser/templatessyntaxhighlighterrules.cpp \
b/templateparser/templatessyntaxhighlighterrules.cpp new file mode 100644
index 0000000..83bae43
--- /dev/null
+++ b/templateparser/templatessyntaxhighlighterrules.cpp
@@ -0,0 +1,59 @@
+/*
+ Copyright (c) 2015 Montel Laurent <montel@kde.org>
+
+ 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 <QTextListFormat>
+#include "templatesutil.h"
+#include <QPalette>
+#include <KPIMTextEdit/SyntaxHighlighterBase>
+using namespace TemplateParser;
+
+TemplatesSyntaxHighlighterRules::TemplatesSyntaxHighlighterRules()
+{
+ init();
+}
+
+void TemplatesSyntaxHighlighterRules::init()
+{
+ QTextCharFormat keywordFormat;
+ QPalette palette;
+ keywordFormat.setForeground(palette.link());
+
+ const QStringList keywords = 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 = QStringList() << \
Util::keywordsWithArgsForCompleter(); +
+ Q_FOREACH (const QString &s, keywordsWithArgs) {
+ const QRegExp regex(s, Qt::CaseInsensitive);
+ mRules.append(KPIMTextEdit::Rule(regex, keywordWithArgsFormat));
+ }
+
+}
+
+QVector<KPIMTextEdit::Rule> TemplatesSyntaxHighlighterRules::rules() const
+{
+ return mRules;
+}
+
diff --git a/templateparser/templatestexteditor.h \
b/templateparser/templatessyntaxhighlighterrules.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 <montel@kde.org>
+ Copyright (c) 2015 Montel Laurent <montel@kde.org>
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 <QVector>
namespace KPIMTextEdit
{
-class TextEditorCompleter;
+class Rule;
}
-namespace TemplateParser
-{
-class TemplatesTextEditor : public PimCommon::RichTextEditor
+
+namespace TemplateParser {
+class TemplatesSyntaxHighlighterRules
{
- Q_OBJECT
public:
- explicit TemplatesTextEditor(QWidget *parent = Q_NULLPTR);
- ~TemplatesTextEditor();
-
-protected:
- void initCompleter();
- void keyPressEvent(QKeyEvent *e) Q_DECL_OVERRIDE;
+ TemplatesSyntaxHighlighterRules();
+ QVector<KPIMTextEdit::Rule> rules() const;
private:
- KPIMTextEdit::TextEditorCompleter *mTextEditorCompleter;
+ void init();
+ QVector<KPIMTextEdit::Rule> mRules;
};
}
-#endif // TEMPLATESTEXTEDITOR_H
+
+#endif // TEMPLATESSYNTAXHIGHLIGHTERRULES_H
diff --git a/templateparser/templatestextedit.cpp \
b/templateparser/templatestextedit.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/templatestextedit.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::RichTextEditorWidget +class TEMPLATEPARSER_EXPORT TemplatesTextEdit : \
public PimCommon::PlainTextEditorWidget {
Q_OBJECT
public:
diff --git a/templateparser/templatestexteditor.cpp \
b/templateparser/templatestexteditor.cpp index a6cc784..60c4624 100644
--- a/templateparser/templatestexteditor.cpp
+++ b/templateparser/templatestexteditor.cpp
@@ -27,10 +27,12 @@
#include <QAbstractItemView>
#include <QFontDatabase>
+#include <texteditor/plaintexteditor/plaintextsyntaxspellcheckinghighlighter.h>
+
using namespace TemplateParser;
TemplatesTextEditor::TemplatesTextEditor(QWidget *parent)
- : PimCommon::RichTextEditor(parent)
+ : PimCommon::PlainTextEditor(parent)
{
setFocus();
const QFont f = QFontDatabase::systemFont(QFontDatabase::FixedFont);
@@ -50,6 +52,30 @@ TemplatesTextEditor::~TemplatesTextEditor()
}
+void TemplatesTextEditor::updateHighLighter()
+{
+ PimCommon::PlainTextSyntaxSpellCheckingHighlighter *hlighter = \
dynamic_cast<PimCommon::PlainTextSyntaxSpellCheckingHighlighter *>(highlighter()); + \
if (hlighter) { + hlighter->toggleSpellHighlighting(checkSpellingEnabled());
+ }
+}
+
+void TemplatesTextEditor::clearDecorator()
+{
+ //Nothing
+}
+
+void TemplatesTextEditor::createHighlighter()
+{
+ PimCommon::PlainTextSyntaxSpellCheckingHighlighter *highlighter = new \
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/templatestexteditor.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 @@
<property name="whatsThis">
<string comment="@info:whatsthis">This area contains the associated custom \
template.</string> </property>
- <property name="acceptRichText">
- <bool>false</bool>
- </property>
</widget>
</item>
<item>
@@ -321,7 +318,7 @@
</customwidget>
<customwidget>
<class>TemplateParser::TemplatesTextEdit</class>
- <extends>QTextEdit</extends>
+ <extends>QPlainTextEdit</extends>
<header>templatestextedit.h</header>
</customwidget>
<customwidget>
diff --git a/templateparser/ui/templatesconfiguration_base.ui \
b/templateparser/ui/templatesconfiguration_base.ui index 75f5a4d..965b631 100644
--- a/templateparser/ui/templatesconfiguration_base.ui
+++ b/templateparser/ui/templatesconfiguration_base.ui
@@ -82,9 +82,6 @@
<property name="whatsThis">
<string comment="@info:whatsthis">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.</string> </property>
- <property name="acceptRichText">
- <bool>false</bool>
- </property>
</widget>
</item>
</layout>
@@ -133,9 +130,6 @@
<property name="whatsThis">
<string comment="@info:whatsthis">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.</string> </property>
- <property name="acceptRichText">
- <bool>false</bool>
- </property>
</widget>
</item>
</layout>
@@ -184,9 +178,6 @@
<property name="whatsThis">
<string comment="@info:whatsthis">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.</string> </property>
- <property name="acceptRichText">
- <bool>false</bool>
- </property>
</widget>
</item>
</layout>
@@ -235,9 +226,6 @@
<property name="whatsThis">
<string comment="@info:whatsthis">In this area you create the template for \
message forwards. For more information about how to create the template, press the \
"How does this work?" link on this dialog.</string> </property>
- <property name="acceptRichText">
- <bool>false</bool>
- </property>
</widget>
</item>
</layout>
@@ -301,7 +289,7 @@
<customwidgets>
<customwidget>
<class>TemplateParser::TemplatesTextEdit</class>
- <extends>QTextEdit</extends>
+ <extends>QPlainTextEdit</extends>
<header>templatestextedit.h</header>
</customwidget>
<customwidget>
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic