diff --git a/CMakeLists.txt b/CMakeLists.txt --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -65,6 +65,7 @@ find_package(KF5AkonadiNotes ${AKONADINOTES_LIB_VERSION} CONFIG REQUIRED) find_package(KF5XmlGui ${KF5_VERSION} CONFIG REQUIRED) find_package(KF5Declarative ${KF5_VERSION} CONFIG REQUIRED) +find_package(KF5SyntaxHighlighting ${KF5_VERSION} CONFIG REQUIRED) set(MAILCOMMON_LIB_VERSION "5.6.43") set(GRAVATAR_LIB_VERSION "5.6.41") diff --git a/plugins/webengineurlinterceptor/adblock/lib/CMakeLists.txt b/plugins/webengineurlinterceptor/adblock/lib/CMakeLists.txt --- a/plugins/webengineurlinterceptor/adblock/lib/CMakeLists.txt +++ b/plugins/webengineurlinterceptor/adblock/lib/CMakeLists.txt @@ -12,7 +12,6 @@ widgets/adblocklistwidget.cpp widgets/adblocksettingwidget.cpp widgets/adblockshowlistdialog.cpp - widgets/adblocksyntaxhighlighter.cpp widgets/adblockutil.cpp ) @@ -57,6 +56,7 @@ KF5::TextWidgets KF5::PimTextEdit KF5::Libkdepim + KF5::SyntaxHighlighting ) set_target_properties(adblocklibprivate diff --git a/plugins/webengineurlinterceptor/adblock/lib/widgets/adblockshowlistdialog.h b/plugins/webengineurlinterceptor/adblock/lib/widgets/adblockshowlistdialog.h --- a/plugins/webengineurlinterceptor/adblock/lib/widgets/adblockshowlistdialog.h +++ b/plugins/webengineurlinterceptor/adblock/lib/widgets/adblockshowlistdialog.h @@ -21,6 +21,7 @@ #define ADBLOCKSHOWLISTDIALOG_H #include +#include class KJob; class QTemporaryFile; @@ -59,6 +60,7 @@ QTemporaryFile *mTemporaryFile; KPIM::ProgressIndicatorLabel *mProgress; QPushButton *mUser1Button; + KSyntaxHighlighting::Repository mSyntaxRepo; }; } diff --git a/plugins/webengineurlinterceptor/adblock/lib/widgets/adblockshowlistdialog.cpp b/plugins/webengineurlinterceptor/adblock/lib/widgets/adblockshowlistdialog.cpp --- a/plugins/webengineurlinterceptor/adblock/lib/widgets/adblockshowlistdialog.cpp +++ b/plugins/webengineurlinterceptor/adblock/lib/widgets/adblockshowlistdialog.cpp @@ -19,19 +19,21 @@ #include "adblockshowlistdialog.h" #include "adblockinterceptor_debug.h" -#include "adblocksyntaxhighlighter.h" #include "kpimtextedit/plaintexteditorwidget.h" #include "kpimtextedit/plaintexteditor.h" #include "Libkdepim/ProgressIndicatorLabel" #include #include -#include #include -#include +#include +#include +#include +#include +#include +#include #include -#include #include #include @@ -57,7 +59,12 @@ mainLayout->addLayout(lay); mTextEdit = new KPIMTextEdit::PlainTextEditorWidget; - (void)new AdBlock::AdBlockSyntaxHighlighter(mTextEdit->editor()->document()); + + auto highlighter = new KSyntaxHighlighting::SyntaxHighlighter(mTextEdit->editor()->document()); + highlighter->setDefinition(mSyntaxRepo.definitionForName(QStringLiteral("Adblock Plus"))); + highlighter->setTheme((palette().color(QPalette::Base).lightness() < 128) + ? mSyntaxRepo.defaultTheme(KSyntaxHighlighting::Repository::DarkTheme) + : mSyntaxRepo.defaultTheme(KSyntaxHighlighting::Repository::LightTheme)); mTextEdit->setReadOnly(true); lay->addWidget(mTextEdit); diff --git a/plugins/webengineurlinterceptor/adblock/lib/widgets/adblocksyntaxhighlighter.h b/plugins/webengineurlinterceptor/adblock/lib/widgets/adblocksyntaxhighlighter.h deleted file mode 100644 --- a/plugins/webengineurlinterceptor/adblock/lib/widgets/adblocksyntaxhighlighter.h +++ /dev/null @@ -1,38 +0,0 @@ -/* - Copyright (C) 2013-2016 Montel Laurent - - This program is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - 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; see the file COPYING. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#ifndef ADBLOCKSYNTAXHIGHLIGHTER_H -#define ADBLOCKSYNTAXHIGHLIGHTER_H - -#include - -namespace AdBlock { -class AdBlockSyntaxHighlighter : public KPIMTextEdit::SyntaxHighlighterBase -{ - Q_OBJECT -public: - explicit AdBlockSyntaxHighlighter(QTextDocument *doc); - ~AdBlockSyntaxHighlighter(); - -private: - void init() override; -}; -} - -#endif // ADBLOCKSYNTAXHIGHLIGHTER_H diff --git a/plugins/webengineurlinterceptor/adblock/lib/widgets/adblocksyntaxhighlighter.cpp b/plugins/webengineurlinterceptor/adblock/lib/widgets/adblocksyntaxhighlighter.cpp deleted file mode 100644 --- a/plugins/webengineurlinterceptor/adblock/lib/widgets/adblocksyntaxhighlighter.cpp +++ /dev/null @@ -1,56 +0,0 @@ -/* - Copyright (C) 2013-2017 Montel Laurent - - This program is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - 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; see the file COPYING. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#include "adblocksyntaxhighlighter.h" - -using namespace AdBlock; - -AdBlockSyntaxHighlighter::AdBlockSyntaxHighlighter(QTextDocument *doc) - : KPIMTextEdit::SyntaxHighlighterBase(doc) -{ - init(); -} - -AdBlockSyntaxHighlighter::~AdBlockSyntaxHighlighter() -{ -} - -void AdBlockSyntaxHighlighter::init() -{ - QTextCharFormat commentFormat; - commentFormat.setForeground(Qt::darkYellow); - m_rules.reserve(4); - QRegularExpression commentRegex(QStringLiteral("^!.*")); - m_rules.append(KPIMTextEdit::Rule(commentRegex, commentFormat)); - - QTextCharFormat exceptionFormat; - exceptionFormat.setForeground(Qt::magenta); - QRegularExpression exceptionRegex(QStringLiteral("^@@.*")); - m_rules.append(KPIMTextEdit::Rule(exceptionRegex, exceptionFormat)); - - QTextCharFormat headerFormat; - headerFormat.setForeground(Qt::red); - QRegularExpression headerRegex(QStringLiteral("^\\[.*")); - m_rules.append(KPIMTextEdit::Rule(headerRegex, headerFormat)); - - QTextCharFormat elementFormat; - elementFormat.setForeground(Qt::blue); - QRegularExpression elementRegex(QStringLiteral(".*##.*")); - m_rules.append(KPIMTextEdit::Rule(elementRegex, elementFormat)); -}