Commit b5a860a7 authored by Martin Höher's avatar Martin Höher

Merge branch '228-syntax-highlighting-in-mark-down-editor' into 'master'

Resolve "Syntax highlighting in mark down editor"

Closes #228

See merge request !117
parents b2d4d778 6f0103ad
Pipeline #53374386 passed with stages
in 14 minutes and 46 seconds
......@@ -4,3 +4,9 @@
[submodule "3rdparty/SingleApplication"]
path = 3rdparty/SingleApplication
url = https://github.com/itay-grudev/SingleApplication.git
[submodule "3rdparty/KDE/syntax-highlighting"]
path = 3rdparty/KDE/syntax-highlighting
url = https://github.com/KDE/syntax-highlighting.git
[submodule "3rdparty/KDE/extra-cmake-modules"]
path = 3rdparty/KDE/extra-cmake-modules
url = https://github.com/KDE/extra-cmake-modules.git
Subproject commit 3f0b87c4750a5fbc1cb21ad6ed2c2e5f2ddc269e
Subproject commit 0d75f65bb73bc6574a7792490f4d3c09e282e416
{
"name": "KDE Syntax Highlighting",
"author": "KDE",
"website": "https://github.com/KDE/syntax-highlighting",
"licenseUrl": "https://raw.githubusercontent.com/KDE/syntax-highlighting/master/COPYING",
"licenseType": "MIT",
"downloadUrl": "https://github.com/KDE/syntax-highlighting"
}
......@@ -73,6 +73,10 @@ Page {
Keys.onEscapePressed: focus = false
Keys.onBackPressed: focus = false
}
OTL.SyntaxHighlighter {
document: textArea.textDocument
}
}
}
}
......@@ -108,5 +108,6 @@
<file>Components/MarkdownLabel.qml</file>
<file>Widgets/ItemProgressEditor.qml</file>
<file>Components/Slider.qml</file>
<file>3rdpartyinfo/syntax-highlighting/3rdpartyinfo.json</file>
</qresource>
</RCC>
......@@ -4,13 +4,54 @@ set -e
ninja-build --version || dnf install -y --nogpgcheck ninja-build
export PATH=$QT_ARM_ROOT/bin:$PATH
ANDROID_CMAKE_FLAGS="\
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_CXX_COMPILER:STRING=$ANDROID_NDK_ROOT/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/arm-linux-androideabi-g++ \
-DCMAKE_C_COMPILER:STRING=$ANDROID_NDK_ROOT/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/arm-linux-androideabi-gcc \
-DCMAKE_PREFIX_PATH:STRING=$QT_ARM_ROOT \
-DQT_QMAKE_EXECUTABLE:STRING=$QT_ARM_ROOT/bin/qmake \
-DCMAKE_SYSTEM_NAME=Android \
-DCMAKE_SYSTEM_VERSION=16 \
-DCMAKE_ANDROID_ARCH_ABI=armeabi-v7a \
-DCMAKE_ANDROID_STL_TYPE=gnustl_shared \
-DANDROID_SDK_ROOT=$ANDROID_SDK_ROOT \
"
if [ -n "$CI" ]; then
# Install ECM:
pushd 3rdparty/KDE/extra-cmake-modules
mkdir -p build-android-armv7
cd build-android-armv7
cmake -DCMAKE_PREFIX_PATH=$QT_ARM_ROOT -GNinja \
$ANDROID_CMAKE_FLAGS \
-DKF5_HOST_TOOLING=/usr \
-DCMAKE_INSTALL_PREFIX=$QT_ARM_ROOT \
..
cmake --build .
cmake --build . --target install
popd
# Install KDE syntax highlighting
pushd 3rdparty/KDE/syntax-highlighting/
mkdir -p build-android-armv7
cd build-android-armv7
cmake -DCMAKE_PREFIX_PATH=$QT_ARM_ROOT -GNinja \
$ANDROID_CMAKE_FLAGS \
-DKF5_HOST_TOOLING=/usr \
-DCMAKE_INSTALL_PREFIX=$QT_ARM_ROOT \
..
cmake --build .
cmake --build . --target install
popd
fi
# Build prerequisites:
./ci/android/build-openssl \
Setenv-android-armv7.sh \
$PWD/pre-build/android/openssl/arm-linux-androideabi-4.9-api-18/
export PATH=$QT_ARM_ROOT/bin:$PATH
# Gather extra libraries to include in APK:
for lib in $(find $PWD/pre-build/android/ -name \*.so); do
if [ -z "$EXTRA_LIBS" ]; then
......@@ -24,16 +65,7 @@ mkdir -p build-android-armv7
cd build-android-armv7
cmake \
-GNinja \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_CXX_COMPILER:STRING=$ANDROID_NDK_ROOT/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/arm-linux-androideabi-g++ \
-DCMAKE_C_COMPILER:STRING=$ANDROID_NDK_ROOT/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/arm-linux-androideabi-gcc \
-DCMAKE_PREFIX_PATH:STRING=$QT_ARM_ROOT \
-DQT_QMAKE_EXECUTABLE:STRING=$QT_ARM_ROOT/bin/qmake \
-DCMAKE_SYSTEM_NAME=Android \
-DCMAKE_SYSTEM_VERSION=16 \
-DCMAKE_ANDROID_ARCH_ABI=armeabi-v7a \
-DCMAKE_ANDROID_STL_TYPE=gnustl_shared \
-DANDROID_SDK_ROOT=$ANDROID_SDK_ROOT \
$ANDROID_CMAKE_FLAGS \
-DOPENTODOLIST_ANDROID_EXTRA_LIBS="$EXTRA_LIBS" \
..
cmake --build . -- opentodolist-translations
......
......@@ -4,12 +4,54 @@ set -e
ninja-build --version || dnf install -y --nogpgcheck ninja-build
export PATH=$QT_X86_ROOT/bin:$PATH
ANDROID_CMAKE_FLAGS="\
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_CXX_COMPILER:STRING=$ANDROID_NDK_ROOT/toolchains/x86-4.9/prebuilt/linux-x86_64/bin/i686-linux-android-g++ \
-DCMAKE_C_COMPILER:STRING=$ANDROID_NDK_ROOT/toolchains/x86-4.9/prebuilt/linux-x86_64/bin/i686-linux-android-gcc \
-DCMAKE_PREFIX_PATH:STRING=$QT_X86_ROOT \
-DQT_QMAKE_EXECUTABLE:STRING=$QT_X86_ROOT/bin/qmake \
-DCMAKE_SYSTEM_NAME=Android \
-DCMAKE_SYSTEM_VERSION=16 \
-DCMAKE_ANDROID_ARCH_ABI=x86 \
-DCMAKE_ANDROID_STL_TYPE=gnustl_shared \
-DANDROID_SDK_ROOT=$ANDROID_SDK_ROOT \
"
if [ -n "$CI" ]; then
# Install ECM:
pushd 3rdparty/KDE/extra-cmake-modules
mkdir -p build-android-x86
cd build-android-x86
cmake -DCMAKE_PREFIX_PATH=$QT_X86_ROOT -GNinja \
$ANDROID_CMAKE_FLAGS \
-DKF5_HOST_TOOLING=/usr \
-DCMAKE_INSTALL_PREFIX=$QT_X86_ROOT \
..
cmake --build .
cmake --build . --target install
popd
# Install KDE syntax highlighting
pushd 3rdparty/KDE/syntax-highlighting/
mkdir -p build-android-x86
cd build-android-x86
cmake -DCMAKE_PREFIX_PATH=$QT_X86_ROOT -GNinja \
$ANDROID_CMAKE_FLAGS \
-DKF5_HOST_TOOLING=/usr \
-DCMAKE_INSTALL_PREFIX=$QT_X86_ROOT \
..
cmake --build .
cmake --build . --target install
popd
fi
# Build prerequisites:
./ci/android/build-openssl \
Setenv-android-x86.sh \
$PWD/pre-build/android/openssl/x86-4.9-api-18/
export PATH=$QT_X86_ROOT/bin:$PATH
# Gather extra libraries to include in APK:
for lib in $(find $PWD/pre-build/android/ -name \*.so); do
......@@ -24,16 +66,7 @@ mkdir -p build-android-x86
cd build-android-x86
cmake \
-GNinja \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_CXX_COMPILER:STRING=$ANDROID_NDK_ROOT/toolchains/x86-4.9/prebuilt/linux-x86_64/bin/i686-linux-android-g++ \
-DCMAKE_C_COMPILER:STRING=$ANDROID_NDK_ROOT/toolchains/x86-4.9/prebuilt/linux-x86_64/bin/i686-linux-android-gcc \
-DCMAKE_PREFIX_PATH:STRING=$QT_X86_ROOT \
-DQT_QMAKE_EXECUTABLE:STRING=$QT_X86_ROOT/bin/qmake \
-DCMAKE_SYSTEM_NAME=Android \
-DCMAKE_SYSTEM_VERSION=16 \
-DCMAKE_ANDROID_ARCH_ABI=x86 \
-DCMAKE_ANDROID_STL_TYPE=gnustl_shared \
-DANDROID_SDK_ROOT=$ANDROID_SDK_ROOT \
$ANDROID_CMAKE_FLAGS \
-DOPENTODOLIST_ANDROID_EXTRA_LIBS="$EXTRA_LIBS" \
..
cmake --build . -- opentodolist-translations
......
......@@ -5,6 +5,7 @@ RUN \
wget make cmake git java-1.8.0-openjdk java-1.8.0-openjdk-devel \
libX11-xcb unzip extra-cmake-modules.noarch \
ncurses-compat-libs gradle ninja-build \
qt5-qtxmlpatterns-devel qt5-linguist appstream \
&& \
wget http://download.qt.io/official_releases/online_installers/qt-unified-linux-x64-online.run && \
chmod +x qt-unified-linux-x64-online.run && \
......
......@@ -4,11 +4,17 @@ RUN \
\
dnf install -y --nogpgcheck \
cmake \
make \
ninja-build \
python3 \
python \
git \
wget \
\
qt5-qtxmlpatterns-devel \
qt5-linguist \
appstream \
\
mingw32-qt5-qmake \
mingw32-qt5-qmldevtools \
mingw32-qt5-qmldevtools-devel \
......
......@@ -4,11 +4,17 @@ RUN \
\
dnf install -y --nogpgcheck \
cmake \
make \
ninja-build \
python3 \
python \
git \
wget \
\
qt5-qtxmlpatterns-devel \
qt5-linguist \
appstream \
\
mingw64-qt5-qmake \
mingw64-qt5-qmldevtools \
mingw64-qt5-qmldevtools-devel \
......
......@@ -2,9 +2,10 @@
set -e
rm -rf build-macos
mkdir build-macos
cd build-macos
BUILD_DIR=$PWD/build-macos
PACKAGES_DIR=$BUILD_DIR/__packages
rm -rf $BUILD_DIR
if [ ! -d "$QT_DIR" ]; then
echo "The variable QT_DIR is not set"
......@@ -13,16 +14,49 @@ fi
QTSDK=$QT_DIR
/Applications/CMake.app/Contents/bin/cmake \
-DCMAKE_PREFIX_PATH=$QTSDK \
if [ -n "$CI" ]; then
# Install ECM:
pushd 3rdparty/KDE/extra-cmake-modules
mkdir -p build-macos
cd build-macos
cmake \
-GNinja \
-DCMAKE_PREFIX_PATH=$QTSDK \
-DCMAKE_INSTALL_PREFIX=$PACKAGES_DIR \
..
cmake --build .
cmake --build . --target install
popd
# Install KDE syntax highlighting
pushd 3rdparty/KDE/syntax-highlighting/
mkdir -p build-macos
cd build-macos
cmake \
-GNinja \
-DCMAKE_PREFIX_PATH=$QTSDK \
-DCMAKE_INSTALL_PREFIX=$PACKAGES_DIR \
-Dt5_DIR=$QTSDK/lib/cmake \
..
cmake --build .
cmake --build . --target install
popd
fi
mkdir -p $BUILD_DIR
cd $BUILD_DIR
cmake \
-GNinja \
-DCMAKE_PREFIX_PATH=$QTSDK\;$PACKAGES_DIR \
-DCMAKE_BUILD_TYPE=Release \
-DOPENTODOLIST_WITH_UPDATE_SERVICE=ON \
-DQTKEYCHAIN_STATIC=ON \
-DCMAKE_OSX_DEPLOYMENT_TARGET=10.10 \
..
make opentodolist-translations
make -j2
make test
cmake --build . --target opentodolist-translations
cmake --build . -- -j2
cmake --build . -- test
$QTSDK/bin/macdeployqt app/OpenTodoList.app/ -qmldir=../app
# Prepare a "beautified" folder:
......
......@@ -2,6 +2,10 @@
set -e
PREFIX_PATH=/opt/qt511
which ninja-build || (apt-get update && apt-get install -y ninja-build)
if [ -n "$CI" ]; then
curl -d install="true" -d adminlogin=admin -d adminpass=admin \
http://nextcloud/index.php
......@@ -11,6 +15,24 @@ if [ -n "$CI" ]; then
-DOPENTODOLIST_NEXTCLOUD_TEST_URL=http://admin:admin@nextcloud/
-DOPENTODOLIST_OWNCLOUD_TEST_URL=http://admin:admin@owncloud/
"
# Install ECM:
pushd 3rdparty/KDE/extra-cmake-modules
mkdir -p build-ubuntu
cd build-ubuntu
cmake -DCMAKE_PREFIX_PATH=$PREFIX_PATH -GNinja ..
cmake --build .
cmake --build . --target install
popd
# Install KDE syntax highlighting
pushd 3rdparty/KDE/syntax-highlighting/
mkdir -p build-ubuntu
cd build-ubuntu
cmake -DCMAKE_PREFIX_PATH=$PREFIX_PATH -GNinja ..
cmake --build .
cmake --build . --target install
popd
fi
which cmake || (apt-get update && apt-get install -y cmake)
......@@ -19,14 +41,15 @@ which cmake || (apt-get update && apt-get install -y cmake)
desktop-file-validate templates/appimage/default.desktop
source /opt/qt511/bin/qt511-env.sh || true
source $PREFIX_PATH/bin/qt511-env.sh || true
export QT_QPA_PLATFORM=minimal
mkdir -p build-ubuntu
cd build-ubuntu
cmake \
-DCMAKE_PREFIX_PATH=/opt/qt510 \
-DCMAKE_PREFIX_PATH=$PREFIX_PATH \
-GNinja \
$CMAKE_EXTRA_FLAGS \
-DCMAKE_BUILD_TYPE=Release \
-DOPENTODOLIST_WITH_UPDATE_SERVICE=ON \
......
#!/bin/bash
set -e
if [ "$TARGET" == win64 ]; then
BUILD_DIR=build-win64
DEPLOY_DIR=deploy-win64
MXE_DIR=x86_64-w64-mingw32
CMAKE=mingw64-cmake
INSTALLER_FILE=win64-installer.nsis
EXTRA_LIBS="\
/usr/$MXE_DIR/sys-root/mingw/bin/libcrypto-1_1-x64.dll \
/usr/$MXE_DIR/sys-root/mingw/bin/libssl-1_1-x64.dll"
else
BUILD_DIR=build-win32
DEPLOY_DIR=deploy-win32
MXE_DIR=i686-w64-mingw32
CMAKE=mingw32-cmake
INSTALLER_FILE=win32-installer.nsis
EXTRA_LIBS="\
/usr/$MXE_DIR/sys-root/mingw/bin/libcrypto-1_1.dll \
/usr/$MXE_DIR/sys-root/mingw/bin/libssl-1_1.dll"
fi
if [ -n "$CI" ]; then
# Install ECM
pushd 3rdparty/KDE/extra-cmake-modules
mkdir -p $BUILD_DIR
cd $BUILD_DIR
$CMAKE -GNinja ..
cmake --build .
cmake --build . --target install
popd
# Install KDE syntax highlighting
pushd 3rdparty/KDE/syntax-highlighting
mkdir -p $BUILD_DIR
cd $BUILD_DIR
$CMAKE -GNinja -DKF5_HOST_TOOLING=/usr ..
cmake --build .
cmake --build . --target install
sed -i \
-e 's#INTERFACE_INCLUDE_DIRECTORIES "/usr/i686-w64-mingw32/sys-root/mingw/include/KF5/KSyntaxHighlighting;/usr/i686-w64-mingw32/sys-root/mingw/include/KF5;/usr/i686-w64-mingw32/sys-root/mingw/include"#INTERFACE_INCLUDE_DIRECTORIES "/usr/i686-w64-mingw32/sys-root/mingw/include/KF5/KSyntaxHighlighting;/usr/i686-w64-mingw32/sys-root/mingw/include/KF5"#g' \
-e 's#INTERFACE_INCLUDE_DIRECTORIES "/usr/x86_64-w64-mingw32/sys-root/mingw/include/KF5/KSyntaxHighlighting;/usr/x86_64-w64-mingw32/sys-root/mingw/include/KF5;/usr/x86_64-w64-mingw32/sys-root/mingw/include"#INTERFACE_INCLUDE_DIRECTORIES "/usr/x86_64-w64-mingw32/sys-root/mingw/include/KF5/KSyntaxHighlighting;/usr/x86_64-w64-mingw32/sys-root/mingw/include/KF5"#g' \
/usr/$MXE_DIR/sys-root/mingw/lib/cmake/KF5SyntaxHighlighting/KF5SyntaxHighlightingTargets.cmake
popd
fi
mkdir -p $BUILD_DIR
cd $BUILD_DIR
$CMAKE \
-GNinja \
-DCMAKE_BUILD_TYPE=Release \
-DOPENTODOLIST_WITH_UPDATE_SERVICE=ON \
-DUSE_CREDENTIAL_STORE=ON \
-DQTKEYCHAIN_STATIC=ON \
..
cmake --build . -- opentodolist-translations -j1
cmake --build . --target all
cd ..
mkdir -p $DEPLOY_DIR/bin
cp \
$BUILD_DIR/app/OpenTodoList.exe \
$BUILD_DIR/3rdparty/qlmdb/qlmdb/libqlmdb.dll \
$EXTRA_LIBS \
/usr/$MXE_DIR/sys-root/mingw/bin/libEGL.dll \
/usr/$MXE_DIR/sys-root/mingw/bin/libGLESv2.dll \
\
$DEPLOY_DIR/bin/
wget https://gitlab.com/rpdev/xwindeployqt/raw/master/xwindeployqt
chmod +x xwindeployqt
./xwindeployqt \
--driver fedora-mingw \
--qml-dir app \
--plugins platforms \
--plugins imageformats \
--plugins sqldrivers \
--plugins bearer \
--mingw-arch $MXE_DIR \
$DEPLOY_DIR/bin/
cp templates/nsis/$INSTALLER_FILE $DEPLOY_DIR/
cd $DEPLOY_DIR
makensis $INSTALLER_FILE
......@@ -2,45 +2,4 @@
set -e
mkdir -p build-win32
cd build-win32
mingw32-cmake \
-GNinja \
-DCMAKE_BUILD_TYPE=Release \
-DOPENTODOLIST_WITH_UPDATE_SERVICE=ON \
-DUSE_CREDENTIAL_STORE=ON \
-DQTKEYCHAIN_STATIC=ON \
..
cmake --build . -- opentodolist-translations
cmake --build . --target all
cd ..
mkdir -p deploy-win32/bin
cp \
build-win32/app/OpenTodoList.exe \
build-win32/3rdparty/qlmdb/qlmdb/libqlmdb.dll \
/usr/i686-w64-mingw32/sys-root/mingw/bin/libcrypto-1_1.dll \
/usr/i686-w64-mingw32/sys-root/mingw/bin/libssl-1_1.dll \
/usr/i686-w64-mingw32/sys-root/mingw/bin/libEGL.dll \
/usr/i686-w64-mingw32/sys-root/mingw/bin/libGLESv2.dll \
\
deploy-win32/bin/
wget https://gitlab.com/rpdev/xwindeployqt/raw/master/xwindeployqt
chmod +x xwindeployqt
./xwindeployqt \
--driver fedora-mingw \
--qml-dir app \
--plugins platforms \
--plugins imageformats \
--plugins sqldrivers \
--plugins bearer \
--mingw-arch i686-w64-mingw32 \
deploy-win32/bin/
cp templates/nsis/win32-installer.nsis deploy-win32/
cd deploy-win32
makensis win32-installer.nsis
TARGET=win32 ./ci/win-build.sh
......@@ -2,45 +2,4 @@
set -e
mkdir -p build-win64
cd build-win64
mingw64-cmake \
-GNinja \
-DCMAKE_BUILD_TYPE=Release \
-DOPENTODOLIST_WITH_UPDATE_SERVICE=ON \
-DUSE_CREDENTIAL_STORE=ON \
-DQTKEYCHAIN_STATIC=ON \
..
cmake --build . -- opentodolist-translations
cmake --build . --target all
cd ..
mkdir -p deploy-win64/bin
cp \
build-win64/app/OpenTodoList.exe \
build-win64/3rdparty/qlmdb/qlmdb/libqlmdb.dll \
/usr/x86_64-w64-mingw32/sys-root/mingw/bin/libcrypto-1_1-x64.dll \
/usr/x86_64-w64-mingw32/sys-root/mingw/bin/libssl-1_1-x64.dll \
/usr/x86_64-w64-mingw32/sys-root/mingw/bin/libEGL.dll \
/usr/x86_64-w64-mingw32/sys-root/mingw/bin/libGLESv2.dll \
\
deploy-win64/bin/
wget https://gitlab.com/rpdev/xwindeployqt/raw/master/xwindeployqt
chmod +x xwindeployqt
./xwindeployqt \
--driver fedora-mingw \
--qml-dir app \
--plugins platforms \
--plugins imageformats \
--plugins sqldrivers \
--plugins bearer \
--mingw-arch x86_64-w64-mingw32 \
deploy-win64/bin/
cp templates/nsis/win64-installer.nsis deploy-win64/
cd deploy-win64
makensis win64-installer.nsis
TARGET=win64 ./ci/win-build.sh
......@@ -46,6 +46,7 @@ set(LIB_HEADERS
utils/jsonutils.h
utils/keystore.h
utils/updateservice.h
utils/syntaxhighlighter.h
${LIB_HEADERS_ANDROID}
)
......@@ -85,6 +86,7 @@ set(LIB_SOURCES
utils/jsonutils.cpp
utils/keystore.cpp
utils/updateservice.cpp
utils/syntaxhighlighter.cpp
${LIB_SOURCES_ANDROID}
......@@ -100,6 +102,14 @@ find_package(Qt5Xml REQUIRED)
find_package(Qt5Concurrent REQUIRED)
find_package(Qt5Sql REQUIRED)
# Find KDE Syntax Highlighting engine
find_package(KF5SyntaxHighlighting)
if(KF5SyntaxHighlighting_FOUND)
set(LIB_LIBRARIES ${LIB_LIBRARIES} KF5::SyntaxHighlighting)
set(LIB_DEFINES ${LIB_DEFINES} HAVE_KF5_SYNTAX_HIGHLIGHTING)
endif()
if(ANDROID OR WIN32)
set(libtype STATIC)
else()
......@@ -121,6 +131,9 @@ target_include_directories(
${CMAKE_CURRENT_BINARY_DIR}/../3rdparty/qtkeychain
)
# Add compile definitions
target_compile_definitions(opentodolist-common PRIVATE ${LIB_DEFINES})
# Link against Qt libraries
target_link_libraries(opentodolist-common
......@@ -136,6 +149,9 @@ target_link_libraries(opentodolist-common
# Third party libraries:
qt5keychain
qlmdb
# Optional libraries
${LIB_LIBRARIES}
)
......
......@@ -19,6 +19,7 @@
#include "sync/webdavsynchronizer.h"
#include "utils/updateservice.h"
#include "utils/syntaxhighlighter.h"
#ifdef Q_OS_ANDROID
#include "utils/android/androidfiledialog.h"
......@@ -64,6 +65,7 @@ void OpenTodoListQmlExtensionsPlugin::registerTypes(const char *uri)
"Use sub-classes of abstract item model instead");
qmlRegisterType<UpdateService>(uri, 1, 0, "UpdateService");
qmlRegisterType<SyntaxHighlighter>(uri, 1, 0, "SyntaxHighlighter");
#ifdef Q_OS_ANDROID
qmlRegisterType<AndroidFileDialog>(uri, 1, 0, "AndroidFileDialog");
......
#include "syntaxhighlighter.h"
#ifdef HAVE_KF5_SYNTAX_HIGHLIGHTING
#include <KF5/KSyntaxHighlighting/Definition>
#include <KF5/KSyntaxHighlighting/Theme>
#endif
/**
* @brief Constructor.
*/
SyntaxHighlighter::SyntaxHighlighter(QObject *parent) : QObject(parent),
m_highlighter(nullptr),
m_repository(nullptr),
m_document(nullptr)
{
#ifdef HAVE_KF5_SYNTAX_HIGHLIGHTING
m_highlighter = new KSyntaxHighlighting::SyntaxHighlighter(this);
m_repository = new KSyntaxHighlighting::Repository();
m_highlighter->setDefinition(m_repository->definitionForFileName("test.md"));
m_highlighter->setTheme(m_repository->defaultTheme());
#endif
}
SyntaxHighlighter::~SyntaxHighlighter()
{
#ifdef HAVE_KF5_SYNTAX_HIGHLIGHTING
delete m_repository;
#endif
}
/**
* @brief The text document the highlighter works on.
*/
QQuickTextDocument *SyntaxHighlighter::document() const
{
return m_document;
}
/**
* @brief Set the document to highlight.
*/
void SyntaxHighlighter::setDocument(QQuickTextDocument *document)
{
if (m_document != document) {
m_document = document;
emit documentChanged();
#ifdef HAVE_KF5_SYNTAX_HIGHLIGHTING
if (m_document != nullptr) {
m_highlighter->setDocument(m_document->textDocument());
} else {
m_highlighter->setDocument(nullptr);
}
#endif
}
}
#ifndef SYNTAXHIGHLIGHTER_H
#define SYNTAXHIGHLIGHTER_H
#include <QObject>
#include <QQuickTextDocument>
#ifdef HAVE_KF5_SYNTAX_HIGHLIGHTING
#include <KF5/KSyntaxHighlighting/SyntaxHighlighter>
#include <KF5/KSyntaxHighlighting/Repository>
#else
namespace KSyntaxHighlighting {
class SyntaxHighlighter;
class Repository;
}
#endif
/**
* @brief Syntax highligher for QML.
*/
class SyntaxHighlighter : public QObject
{
Q_OBJECT
Q_PROPERTY(QQuickTextDocument* document READ document WRITE setDocument
NOTIFY documentChanged)
public:
explicit SyntaxHighlighter(QObject *parent = nullptr);
virtual ~SyntaxHighlighter();
QQuickTextDocument *document() const;
void setDocument(QQuickTextDocument *document);
signals:
void documentChanged();
public slots:
private:
KSyntaxHighlighting::SyntaxHighlighter *m_highlighter;
KSyntaxHighlighting::Repository *m_repository;
QQuickTextDocument *m_document;
};
#endif // SYNTAXHIGHLIGHTER_H
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment