diff --git a/src/ksieveui/CMakeLists.txt b/src/ksieveui/CMakeLists.txt --- a/src/ksieveui/CMakeLists.txt +++ b/src/ksieveui/CMakeLists.txt @@ -164,7 +164,6 @@ set(ksieveui_scriptsparsing_LIB_SRCS scriptsparsing/xmlprintingscriptbuilder.cpp scriptsparsing/parsingresultdialog.cpp - scriptsparsing/xmlprintingsyntaxhighlighter.cpp scriptsparsing/parsingutil.cpp ) diff --git a/src/ksieveui/scriptsparsing/parsingresultdialog.h b/src/ksieveui/scriptsparsing/parsingresultdialog.h --- a/src/ksieveui/scriptsparsing/parsingresultdialog.h +++ b/src/ksieveui/scriptsparsing/parsingresultdialog.h @@ -20,6 +20,7 @@ #define PARSINGRESULTDIALOG_H #include "ksieveui_private_export.h" #include +#include namespace KPIMTextEdit { class PlainTextEditorWidget; @@ -41,6 +42,7 @@ void readConfig(); void writeConfig(); KPIMTextEdit::PlainTextEditorWidget *mTextEdit = nullptr; + KSyntaxHighlighting::Repository mSyntaxRepo; }; } diff --git a/src/ksieveui/scriptsparsing/parsingresultdialog.cpp b/src/ksieveui/scriptsparsing/parsingresultdialog.cpp --- a/src/ksieveui/scriptsparsing/parsingresultdialog.cpp +++ b/src/ksieveui/scriptsparsing/parsingresultdialog.cpp @@ -18,15 +18,18 @@ */ #include "parsingresultdialog.h" -#include "xmlprintingsyntaxhighlighter.h" #include #include "kpimtextedit/plaintexteditorwidget.h" #include "kpimtextedit/plaintexteditor.h" #include #include -#include #include +#include +#include +#include + +#include #include #include @@ -45,7 +48,11 @@ user1Button->setText(i18n("Save As...")); mTextEdit = new KPIMTextEdit::PlainTextEditorWidget(this); - new XMLPrintingSyntaxHighLighter(mTextEdit->editor()->document()); + auto highlighter = new KSyntaxHighlighting::SyntaxHighlighter(mTextEdit->editor()->document()); + highlighter->setDefinition(mSyntaxRepo.definitionForName(QStringLiteral("XML"))); + highlighter->setTheme((palette().color(QPalette::Base).lightness() < 128) + ? mSyntaxRepo.defaultTheme(KSyntaxHighlighting::Repository::DarkTheme) + : mSyntaxRepo.defaultTheme(KSyntaxHighlighting::Repository::LightTheme)); mTextEdit->setReadOnly(true); mainLayout->addWidget(mTextEdit); mainLayout->addWidget(buttonBox); diff --git a/src/ksieveui/scriptsparsing/xmlprintingsyntaxhighlighter.h b/src/ksieveui/scriptsparsing/xmlprintingsyntaxhighlighter.h deleted file mode 100644 --- a/src/ksieveui/scriptsparsing/xmlprintingsyntaxhighlighter.h +++ /dev/null @@ -1,39 +0,0 @@ -/* - Copyright (C) 2013-2017 Laurent Montel - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#ifndef XMLPRINTINGSYNTAXHIGHLIGHTER_H -#define XMLPRINTINGSYNTAXHIGHLIGHTER_H - -#include -#include - -class QTextDocument; -namespace KSieveUi { -class XMLPrintingSyntaxHighLighter : public KPIMTextEdit::SyntaxHighlighterBase -{ - Q_OBJECT -public: - explicit XMLPrintingSyntaxHighLighter(QTextDocument *doc); - ~XMLPrintingSyntaxHighLighter(); - -private: - void init() override; -}; -} -#endif // XMLPRINTINGSYNTAXHIGHLIGHTER_H diff --git a/src/ksieveui/scriptsparsing/xmlprintingsyntaxhighlighter.cpp b/src/ksieveui/scriptsparsing/xmlprintingsyntaxhighlighter.cpp deleted file mode 100644 --- a/src/ksieveui/scriptsparsing/xmlprintingsyntaxhighlighter.cpp +++ /dev/null @@ -1,70 +0,0 @@ -/* - Copyright (C) 2013-2017 Laurent Montel - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#include "xmlprintingsyntaxhighlighter.h" - -using namespace KSieveUi; - -XMLPrintingSyntaxHighLighter::XMLPrintingSyntaxHighLighter(QTextDocument *doc) - : KPIMTextEdit::SyntaxHighlighterBase(doc) -{ - init(); -} - -XMLPrintingSyntaxHighLighter::~XMLPrintingSyntaxHighLighter() -{ -} - -void XMLPrintingSyntaxHighLighter::init() -{ - QTextCharFormat testFormat; - testFormat.setForeground(Qt::gray); - testFormat.setFontWeight(QFont::Bold); - const QStringList testType = { QStringLiteral("require") }; - - for (const QString &s : testType) { - const QRegularExpression regex(s, QRegularExpression::CaseInsensitiveOption); - m_rules.append(KPIMTextEdit::Rule(regex, testFormat)); - } - - QTextCharFormat quoteFormat; - quoteFormat.setForeground(Qt::blue); - quoteFormat.setFontWeight(QFont::Bold); - const QStringList quoteType = { QStringLiteral("quoted"), QStringLiteral("hash"), QStringLiteral("bracket"), QStringLiteral("multiline")}; - for (const QString &s : quoteType) { - const QRegularExpression regex(s, QRegularExpression::CaseInsensitiveOption); - m_rules.append(KPIMTextEdit::Rule(regex, quoteFormat)); - } - - QTextCharFormat misc; - misc.setForeground(Qt::red); - misc.setFontWeight(QFont::Bold); - const QStringList miscType = QStringList() - << QStringLiteral("control") << QStringLiteral("block") << QStringLiteral("script") << QStringLiteral("action") << QStringLiteral("comment") - << QStringLiteral("num") << QStringLiteral("tag") << QStringLiteral("list") << QStringLiteral("str") << QStringLiteral("test") << QStringLiteral("crlf/"); - for (const QString &s : miscType) { - const QRegularExpression regex(s, QRegularExpression::CaseInsensitiveOption); - m_rules.append(KPIMTextEdit::Rule(regex, misc)); - } - - QTextCharFormat header; - header.setForeground(Qt::black); - header.setFontWeight(QFont::Bold); - m_rules.append(KPIMTextEdit::Rule(QRegularExpression(QStringLiteral("<\\?xml.*"), QRegularExpression::CaseInsensitiveOption), header)); -}