summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMontel Laurent <montel@kde.org>2016-09-20 19:15:45 (GMT)
committerMontel Laurent <montel@kde.org>2016-09-20 19:15:45 (GMT)
commit082e3b59261a442c3971040deea9b25a577ac873 (patch)
tree54c5b49d67ef52a78571104c57468af15173078a
parent1cc31f5e7bc4d6cdab3cf66d011ca886a0cf0978 (diff)
Use syntaxhighlighting
-rw-r--r--CMakeLists.txt9
-rw-r--r--src/CMakeLists.txt5
-rw-r--r--src/config-kpimtextedit.h.cmake1
-rw-r--r--src/inserthtmldialog.cpp45
-rw-r--r--src/inserthtmldialog.h22
-rw-r--r--src/inserthtmleditor.cpp87
-rw-r--r--src/inserthtmleditor.h51
-rw-r--r--tests/CMakeLists.txt6
8 files changed, 164 insertions, 62 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index d9f4791..99772e7 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -76,6 +76,15 @@ else()
endif()
endif()
+option(KDEPIM_KF5SYNTAXHIGHLIGHTING_SUPPORT "Enable this feature if you want to use new kf5 syntax highlighting module. No stable yet" FALSE)
+
+if (KDEPIM_KF5SYNTAXHIGHLIGHTING_SUPPORT)
+ find_package(KF5SyntaxHighlighting ${KF5_VERSION})
+ if (KF5SyntaxHighlighting_FOUND)
+ MESSAGE(STATUS "found KF5SyntaxHighlighting")
+ set(KDEPIM_KF5SYNTAXHIGHLIGHTING_SUPPORT true)
+ endif()
+endif()
########### Targets ###########
add_subdirectory(src)
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 620a73a..42923d2 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -59,6 +59,7 @@ set(kpimtextedit_SRCS
inserttablewidget.cpp
syntaxhighlighterbase.cpp
texteditorcompleter.cpp
+ inserthtmleditor.cpp
slidecontainer.cpp
editorutil.cpp
)
@@ -93,6 +94,10 @@ if(KPIMTEXTEDIT_HAVE_TEXTTOSPEECH)
target_link_libraries(KF5PimTextEdit PRIVATE Qt5::TextToSpeech)
endif()
+if (KDEPIM_KF5SYNTAXHIGHLIGHTING_SUPPORT)
+ target_link_libraries(KF5PimTextEdit PRIVATE KF5::SyntaxHighlighting)
+endif()
+
set_target_properties(KF5PimTextEdit PROPERTIES
VERSION ${KPIMTEXTEDIT_VERSION_STRING}
SOVERSION ${KPIMTEXTEDIT_SOVERSION}
diff --git a/src/config-kpimtextedit.h.cmake b/src/config-kpimtextedit.h.cmake
index fadbc68..fd8a0be 100644
--- a/src/config-kpimtextedit.h.cmake
+++ b/src/config-kpimtextedit.h.cmake
@@ -1,3 +1,4 @@
/* config-kpimtextedit.h. Generated by cmake from config-kpimtextedit.h.cmake */
#cmakedefine01 KPIMTEXTEDIT_HAVE_TEXTTOSPEECH
+#cmakedefine KDEPIM_KF5SYNTAXHIGHLIGHTING_SUPPORT 1
diff --git a/src/inserthtmldialog.cpp b/src/inserthtmldialog.cpp
index 033c8c9..8020c54 100644
--- a/src/inserthtmldialog.cpp
+++ b/src/inserthtmldialog.cpp
@@ -19,15 +19,11 @@
*/
#include "inserthtmldialog.h"
-
+#include "inserthtmleditor.h"
#include <KLocalizedString>
-#include "texteditorcompleter.h"
-#include "htmlhighlighter.h"
#include "texteditor/plaintexteditor/plaintexteditorwidget.h"
-#include <QCompleter>
-#include <QAbstractItemView>
#include <QDialogButtonBox>
#include <QPushButton>
#include <QVBoxLayout>
@@ -97,45 +93,6 @@ QString InsertHtmlDialog::html() const
return d->editor->toPlainText();
}
-InsertHtmlEditor::InsertHtmlEditor(QWidget *parent)
- : KPIMTextEdit::PlainTextEditor(parent)
-{
- new KPIMTextEdit::HtmlHighlighter(document());
- setFocus();
- mTextEditorCompleter = new KPIMTextEdit::TextEditorCompleter(this, this);
- QStringList completerList;
- completerList << QStringLiteral("<b></b>")
- << QStringLiteral("<i></i>")
- << QStringLiteral("<u></u>");
- //Add more
- mTextEditorCompleter->setCompleterStringList(completerList);
- mTextEditorCompleter->setExcludeOfCharacters(QStringLiteral("~!@#$%^&*()+{}|,./;'[]\\-= "));
-}
-
-InsertHtmlEditor::~InsertHtmlEditor()
-{
-
-}
-
-void InsertHtmlEditor::keyPressEvent(QKeyEvent *e)
-{
- if (mTextEditorCompleter->completer()->popup()->isVisible()) {
- switch (e->key()) {
- case Qt::Key_Enter:
- case Qt::Key_Return:
- case Qt::Key_Escape:
- case Qt::Key_Tab:
- case Qt::Key_Backtab:
- e->ignore();
- return; // let the completer do default behavior
- default:
- break;
- }
- }
- KPIMTextEdit::PlainTextEditor::keyPressEvent(e);
- mTextEditorCompleter->completeText();
-}
-
}
#include "moc_inserthtmldialog.cpp"
diff --git a/src/inserthtmldialog.h b/src/inserthtmldialog.h
index 7a81868..a68874e 100644
--- a/src/inserthtmldialog.h
+++ b/src/inserthtmldialog.h
@@ -22,29 +22,17 @@
#define RICHTEXTCOMPOSER_INSERTHTMLDIALOG_H
#include <QDialog>
+#include "config-kpimtextedit.h"
+
#include "kpimtextedit_export.h"
#include "kpimtextedit/plaintexteditor.h"
+#ifdef KDEPIM_KF5SYNTAXHIGHLIGHTING_SUPPORT
+#include <SyntaxHighlighting/Repository>
+#endif
namespace KPIMTextEdit
{
-class TextEditorCompleter;
-}
-namespace KPIMTextEdit
-{
-class TextEditorCompleter;
class InsertHtmlDialogPrivate;
-class InsertHtmlEditor : public KPIMTextEdit::PlainTextEditor
-{
- Q_OBJECT
-public:
- explicit InsertHtmlEditor(QWidget *parent = Q_NULLPTR);
- ~InsertHtmlEditor();
-protected:
- void keyPressEvent(QKeyEvent *e) Q_DECL_OVERRIDE;
-private:
- KPIMTextEdit::TextEditorCompleter *mTextEditorCompleter;
-};
-
class KPIMTEXTEDIT_EXPORT InsertHtmlDialog : public QDialog
{
Q_OBJECT
diff --git a/src/inserthtmleditor.cpp b/src/inserthtmleditor.cpp
new file mode 100644
index 0000000..04fc65e
--- /dev/null
+++ b/src/inserthtmleditor.cpp
@@ -0,0 +1,87 @@
+/*
+ Copyright (c) 2016 Montel Laurent <montel@kde.org>
+
+ 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 "inserthtmleditor.h"
+#include "texteditorcompleter.h"
+
+#ifdef KDEPIM_KF5SYNTAXHIGHLIGHTING_SUPPORT
+#include <SyntaxHighlighting/SyntaxHighlighter>
+#include <SyntaxHighlighting/Definition>
+#include <SyntaxHighlighting/Theme>
+#else
+#include "htmlhighlighter.h"
+#endif
+
+#include <QStringList>
+#include <QCompleter>
+#include <QAbstractItemView>
+
+using namespace KPIMTextEdit;
+
+InsertHtmlEditor::InsertHtmlEditor(QWidget *parent)
+ : KPIMTextEdit::PlainTextEditor(parent)
+{
+#ifdef KDEPIM_KF5SYNTAXHIGHLIGHTING_SUPPORT
+ SyntaxHighlighting::Definition def;
+ def = mRepo.definitionForName(QStringLiteral("HTML"));
+
+ SyntaxHighlighting::SyntaxHighlighter *hl = new SyntaxHighlighting::SyntaxHighlighter(document());
+ hl->setTheme((palette().color(QPalette::Base).lightness() < 128)
+ ? mRepo.theme(QStringLiteral("Breeze Dark"))
+ : mRepo.theme(QStringLiteral("Default")));
+
+ hl->setDefinition(def);
+#else
+ new KPIMTextEdit::HtmlHighlighter(document());
+#endif
+ setFocus();
+ mTextEditorCompleter = new KPIMTextEdit::TextEditorCompleter(this, this);
+ QStringList completerList;
+ completerList << QStringLiteral("<b></b>")
+ << QStringLiteral("<i></i>")
+ << QStringLiteral("<u></u>");
+ //Add more
+ mTextEditorCompleter->setCompleterStringList(completerList);
+ mTextEditorCompleter->setExcludeOfCharacters(QStringLiteral("~!@#$%^&*()+{}|,./;'[]\\-= "));
+}
+
+InsertHtmlEditor::~InsertHtmlEditor()
+{
+
+}
+
+void InsertHtmlEditor::keyPressEvent(QKeyEvent *e)
+{
+ if (mTextEditorCompleter->completer()->popup()->isVisible()) {
+ switch (e->key()) {
+ case Qt::Key_Enter:
+ case Qt::Key_Return:
+ case Qt::Key_Escape:
+ case Qt::Key_Tab:
+ case Qt::Key_Backtab:
+ e->ignore();
+ return; // let the completer do default behavior
+ default:
+ break;
+ }
+ }
+ KPIMTextEdit::PlainTextEditor::keyPressEvent(e);
+ mTextEditorCompleter->completeText();
+}
diff --git a/src/inserthtmleditor.h b/src/inserthtmleditor.h
new file mode 100644
index 0000000..8c119b8
--- /dev/null
+++ b/src/inserthtmleditor.h
@@ -0,0 +1,51 @@
+/*
+ Copyright (c) 2016 Montel Laurent <montel@kde.org>
+
+ 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 RICHTEXTCOMPOSER_INSERTHTMLEDITOR_H
+#define RICHTEXTCOMPOSER_INSERTHTMLEDITOR_H
+
+#include "config-kpimtextedit.h"
+#include <QWidget>
+
+#include "kpimtextedit/plaintexteditor.h"
+#ifdef KDEPIM_KF5SYNTAXHIGHLIGHTING_SUPPORT
+#include <SyntaxHighlighting/Repository>
+#endif
+
+namespace KPIMTextEdit
+{
+class TextEditorCompleter;
+class InsertHtmlEditor : public KPIMTextEdit::PlainTextEditor
+{
+ Q_OBJECT
+public:
+ explicit InsertHtmlEditor(QWidget *parent = Q_NULLPTR);
+ ~InsertHtmlEditor();
+protected:
+ void keyPressEvent(QKeyEvent *e) Q_DECL_OVERRIDE;
+private:
+ KPIMTextEdit::TextEditorCompleter *mTextEditorCompleter;
+#ifdef KDEPIM_KF5SYNTAXHIGHLIGHTING_SUPPORT
+ SyntaxHighlighting::Repository mRepo;
+#endif
+};
+}
+
+#endif // INSERTHTMLEDITOR_H
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 9f61b8a..3767b78 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -1,7 +1,11 @@
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../src ${CMAKE_CURRENT_BINARY_DIR}/../src)
add_executable(inserthtmldialog_demo inserthtmldialog_demo.cpp)
-target_link_libraries(inserthtmldialog_demo KF5PimTextEdit Qt5::Widgets)
+set(inserthtmldialog_demo_LIBS KF5PimTextEdit Qt5::Widgets)
+if (KDEPIM_KF5SYNTAXHIGHLIGHTING_SUPPORT)
+ set(inserthtmldialog_demo_LIBS ${inserthtmldialog_demo_LIBS} KF5::SyntaxHighlighting)
+endif()
+target_link_libraries(inserthtmldialog_demo ${inserthtmldialog_demo_LIBS})
set(slidecontainer_gui_SRCS slidecontainer_gui.cpp)
add_executable(slidecontainer_gui ${slidecontainer_gui_SRCS})