Skip to content

Commit

Permalink
Port to Qt 6
Browse files Browse the repository at this point in the history
Closes: #61
  • Loading branch information
plfiorini committed Apr 6, 2024
1 parent 3722698 commit 32d0348
Show file tree
Hide file tree
Showing 21 changed files with 245 additions and 285 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ on:
- develop

jobs:
linux-qt5:
uses: lirios/.github/.github/workflows/build-linux-qt5.yml@master
linux-qt6:
uses: lirios/.github/.github/workflows/build-linux-qt6.yml@master
with:
build_dependencies: "cmake-shared fluid"
windows:
uses: lirios/.github/.github/workflows/build-windows.yml@master
with:
output_name: LiriText
# windows-qt6:
# uses: lirios/.github/.github/workflows/build-windows-qt6.yml@master
# with:
# output_name: LiriText
39 changes: 9 additions & 30 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,39 +1,20 @@
cmake_minimum_required(VERSION 3.10.0)
cmake_minimum_required(VERSION 3.19)

project("Text"
VERSION "0.5.0"
DESCRIPTION "Text editor"
LANGUAGES CXX C
)

## Shared macros and functions:
if(TEXT_WITH_FLUID AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/fluid/CMakeLists.txt")
set(LIRI_LOCAL_ECM TRUE)
set(FLUID_WITH_DOCUMENTATION FALSE)
set(FLUID_WITH_DEMO FALSE)
endif()
if(LIRI_LOCAL_ECM)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/fluid/cmake/shared/modules")
else()
find_package(LiriCMakeShared "2.0.0" REQUIRED NO_MODULE)
list(APPEND CMAKE_MODULE_PATH "${LCS_MODULE_PATH}")
endif()
## Enable C++17:
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

## Set minimum versions required.
set(QT_MIN_VERSION "5.10.0")

## Liri specific setup common for all modules:
include(LiriSetup)

## Features:
option(TEXT_WITH_FLUID "Build together with Fluid" OFF)
add_feature_info("Text::WithFluid" TEXT_WITH_FLUID "Build together with Fluid")

## Find Qt 5.
find_package(Qt5 "${QT_MIN_VERSION}"
CONFIG REQUIRED
COMPONENTS
## Find Qt:
find_package(Qt6
REQUIRED COMPONENTS
Core
Core5Compat
Gui
Widgets
Svg
Expand All @@ -43,10 +24,8 @@ find_package(Qt5 "${QT_MIN_VERSION}"
Sql
LinguistTools
)
qt_standard_project_setup(REQUIRES 6.6)

## Add subdirectories:
if(TEXT_WITH_FLUID)
add_subdirectory(fluid)
endif()
add_subdirectory(data)
add_subdirectory(src)
12 changes: 3 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,15 @@ Liri Text is a cross-platform text editor made in accordance with Material Desig

## Dependencies

Qt >= 5.10.0 with at least the following modules is required:
Qt >= 6.6 with at least the following modules is required:

* [qtbase](http://code.qt.io/cgit/qt/qtbase.git)
* [qtdeclarative](http://code.qt.io/cgit/qt/qtdeclarative.git)
* [qtquickcontrols2](http://code.qt.io/cgit/qt/qtquickcontrols2.git)

The following modules and their dependencies are required:

* [cmake](https://gitlab.kitware.com/cmake/cmake) >= 3.10.0
* [cmake-shared](https://github.com/lirios/cmake-shared.git) >= 1.0.0
* [fluid](https://github.com/lirios/fluid.git) >= 1.0.0
* [cmake](https://gitlab.kitware.com/cmake/cmake) >= 3.19
* [fluid](https://github.com/lirios/fluid.git) >= 2.0.0
* [SQLite](https://www.sqlite.org/) >= 3.7.15

## Installation
Expand All @@ -39,10 +37,6 @@ make install # use sudo if necessary
Replace `/path/to/prefix` to your installation prefix.
Default is `/usr/local`.

You can also append the following options to the `cmake` command:

* `-DTEXT_WITH_FLUID:BOOL=ON`: Build with a local copy of the Fluid sources.

## Credits

Many thanks to ...
Expand Down
7 changes: 5 additions & 2 deletions data/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ if(UNIX AND NOT APPLE AND NOT ANDROID)
get_filename_component(icon_directory "${icon_basename}" DIRECTORY)
string(REPLACE "${icon_directory}/" "" icon_filename "${icon_basename}")
string(REGEX REPLACE "\.(png|svg)" "" icon_filename "${icon_filename}")
set(dest_path "${INSTALL_DATADIR}/icons/hicolor/${icon_directory}/")
set(dest_path "${CMAKE_INSTALL_DATADIR}/icons/hicolor/${icon_directory}/")
install(FILES "${source_path}" DESTINATION "${dest_path}")
endforeach()
endif()
Expand All @@ -17,5 +17,8 @@ if(WIN32)
elseif(APPLE)
install(FILES ${language_specs} DESTINATION "Contents/Resources/data/language-specs")
else()
install(FILES ${language_specs} DESTINATION "${INSTALL_DATADIR}/liri-text/language-specs")
install(FILES ${language_specs} DESTINATION "${CMAKE_INSTALL_DATADIR}/liri-text/language-specs")
endif()

install(FILES io.liri.Text.appdata.xml DESTINATION "${CMAKE_INSTALL_DATADIR}/appdata")
install(FILES io.liri.Text.desktop DESTINATION "${CMAKE_INSTALL_DATADIR}/applications")
164 changes: 77 additions & 87 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,104 +1,94 @@
# Translations
file(GLOB LiriText_TRANSLATIONS "${CMAKE_SOURCE_DIR}/translations/app/*_*.ts")
qt5_add_translation(LiriText_QM_FILES ${LiriText_TRANSLATIONS})
if(WIN32)
set(_translations_destdir "${CMAKE_CURRENT_BINARY_DIR}/translations")
elseif(APPLE)
set(_translations_destdir "${CMAKE_CURRENT_BINARY_DIR}/Contents/Resources/data/translations")
elseif(LINUX OR BSD)
set(_translations_destdir "${INSTALL_DATADIR}/liri-text/translations")
endif()
if(DEFINED _translations_destdir)
install(FILES ${LiriText_QM_FILES} DESTINATION "${_translations_destdir}")
endif()

set(LiriText_ICON "${CMAKE_CURRENT_SOURCE_DIR}/../data/icons/io.liri.Text.icns")
set_source_files_properties("${LiriText_ICON}" PROPERTIES
MACOSX_PACKAGE_LOCATION "Resources"
)

set(LiriText_RC "${CMAKE_CURRENT_SOURCE_DIR}/../data/io.liri.Text.rc")

qt_add_executable(LiriText
WIN32 MACOSX_BUNDLE
documenthandler.cpp documenthandler.h
highlightdata.cpp highlightdata.h
historymanager.cpp historymanager.h
languagecontextbase.cpp languagecontextbase.h
languagecontextcontainer.cpp languagecontextcontainer.h
languagecontext.cpp languagecontext.h
languagecontextkeyword.cpp languagecontextkeyword.h
languagecontextreference.cpp languagecontextreference.h
languagecontextsimple.cpp languagecontextsimple.h
languagecontextsubpattern.cpp languagecontextsubpattern.h
languagedatabasemaintainer.cpp languagedatabasemaintainer.h
languagedefaultstyles.cpp languagedefaultstyles.h
languageloader.cpp languageloader.h
languagemanager.cpp languagemanager.h
languagemetadata.h
lirisyntaxhighlighter.cpp lirisyntaxhighlighter.h
main.cpp
${LiriText_ICON}
${LiriText_RC}
)

qt_add_qml_module(LiriText
URI LiriText
VERSION 2.0
QML_FILES
qml/EditPage.qml
qml/FileGridView.qml
qml/Main.qml
qml/RecentFilesPage.qml
qml/SearchOverlay.qml
RESOURCES
resources/icon.png
)

file(GLOB ts_files "../translations/app/*.ts")
qt_add_translations(LiriText
TS_FILES ${ts_files}
RESOURCE_PREFIX /qt/qml/LiriText/i18n
)

target_compile_definitions(LiriText PRIVATE
#QT_NO_CAST_FROM_ASCII
#QT_NO_FOREACH
-DTEXT_VERSION="${PROJECT_VERSION}"
-DUSER_LANGUAGE_PATH="/language-specs/"
-DLANGUAGE_DB_VERSION=1
)

if(WIN32)
set(LiriText_DEFINES -DRELATIVE_LANGUAGE_PATH="/language-specs/")
target_compile_definitions(LiriText PRIVATE -DRELATIVE_LANGUAGE_PATH="/language-specs/")
elseif(APPLE)
set(LiriText_DEFINES -DRELATIVE_LANGUAGE_PATH="../Resources/data/language-specs/")
target_compile_definitions(LiriText PRIVATE -DRELATIVE_LANGUAGE_PATH="../Resources/data/language-specs/")
else()
set(LiriText_DEFINES -DABSOLUTE_LANGUAGE_PATH="${CMAKE_INSTALL_PREFIX}/${INSTALL_DATADIR}/liri-text/language-specs/")
target_compile_definitions(LiriText PRIVATE -DABSOLUTE_LANGUAGE_PATH="${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_DATADIR}/liri-text/language-specs/")
endif()

target_link_libraries(LiriText
PRIVATE
Qt6::Core
Qt6::Core5Compat
Qt6::Gui
Qt6::Widgets
Qt6::Qml
Qt6::Quick
Qt6::QuickControls2
Qt6::Sql
)

if(APPLE OR WIN32)
set(LiriText_OUTPUT_NAME "LiriText")
set_target_properties(LiriText PROPERTIES OUTPUT_NAME "LiriText")
else()
set(LiriText_OUTPUT_NAME "liri-text")
set_target_properties(LiriText PROPERTIES OUTPUT_NAME "liri-text")
endif()
if(APPLE)
set_target_properties(LiriText PROPERTIES
MACOSX_BUNDLE_GUI_IDENTIFIER "io.liri.Text"
MACOSX_BUNDLE_ICON_FILE "io.liri.Text"
MACOSX_BUNDLE_SHORT_VERSION_STRING "${PROJECT_VERSION}"
)
endif()

liri_add_executable(LiriText
OUTPUT_NAME
"${LiriText_OUTPUT_NAME}"
SOURCES
documenthandler.cpp
documenthandler.h
highlightdata.cpp
highlightdata.h
historymanager.cpp
historymanager.h
languagecontextbase.cpp
languagecontextbase.h
languagecontextcontainer.cpp
languagecontextcontainer.h
languagecontext.cpp
languagecontext.h
languagecontextkeyword.cpp
languagecontextkeyword.h
languagecontextreference.cpp
languagecontextreference.h
languagecontextsimple.cpp
languagecontextsimple.h
languagecontextsubpattern.cpp
languagecontextsubpattern.h
languagedatabasemaintainer.cpp
languagedatabasemaintainer.h
languagedefaultstyles.cpp
languagedefaultstyles.h
languageloader.cpp
languageloader.h
languagemanager.cpp
languagemanager.h
languagemetadata.h
lirisyntaxhighlighter.cpp
lirisyntaxhighlighter.h
main.cpp
${LiriText_ICON}
${LiriText_RC}
${LiriText_QM_FILES}
RESOURCES
text.qrc
DEFINES
#QT_NO_CAST_FROM_ASCII
#QT_NO_FOREACH
-DTEXT_VERSION="${PROJECT_VERSION}"
-DUSER_LANGUAGE_PATH="/language-specs/"
-DLANGUAGE_DB_VERSION=1
${LiriText_DEFINES}
APPDATA
"${CMAKE_CURRENT_SOURCE_DIR}/../data/io.liri.Text.appdata.xml"
DESKTOP
"${CMAKE_CURRENT_SOURCE_DIR}/../data/io.liri.Text.desktop"
LIBRARIES
Qt5::Core
Qt5::Gui
Qt5::Widgets
Qt5::Qml
Qt5::Quick
Qt5::QuickControls2
Qt5::Sql
GUI
install(TARGETS LiriText
BUNDLE DESTINATION .
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)
set_target_properties(LiriText PROPERTIES
MACOSX_BUNDLE_GUI_IDENTIFIER "io.liri.Text"
MACOSX_BUNDLE_ICON_FILE "io.liri.Text"
MACOSX_BUNDLE_SHORT_VERSION_STRING "${PROJECT_VERSION}"
)

liri_finalize_executable(LiriText)
2 changes: 2 additions & 0 deletions src/documenthandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,14 @@
#ifndef QT_NO_FILESYSTEMWATCHER
#include <QFileSystemWatcher>
#endif
#include <QQmlEngine>

#include "lirisyntaxhighlighter.h"

class DocumentHandler : public QObject
{
Q_OBJECT
QML_ELEMENT
Q_PROPERTY(QQuickItem *target READ target WRITE setTarget NOTIFY targetChanged)
Q_PROPERTY(QUrl fileUrl READ fileUrl WRITE setFileUrl NOTIFY fileUrlChanged)
Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged)
Expand Down
8 changes: 8 additions & 0 deletions src/historymanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,13 @@
#include <QHash>
#include <QUrl>
#include <QDateTime>
#include <QQmlEngine>

class HistoryManager : public QAbstractListModel
{
Q_OBJECT
QML_SINGLETON
QML_NAMED_ELEMENT(History)
public:
enum HistoryRoles {
NameRole = Qt::UserRole + 1,
Expand All @@ -54,6 +57,11 @@ class HistoryManager : public QAbstractListModel
Qt::ItemFlags flags(const QModelIndex &index) const;
Q_INVOKABLE QVariantMap getFileEditingInfo(const QUrl &fileUrl) const;

static HistoryManager *create(QQmlEngine *qmlEngine, QJSEngine *jsEngine)
{
return getInstance();
}

signals:
void countChanged();

Expand Down
Loading

0 comments on commit 32d0348

Please sign in to comment.