From 9249f8a18cad0a829f6a6d80a9758a01616c97fd Mon Sep 17 00:00:00 2001 From: Wilfried Holzke Date: Fri, 14 Jan 2022 22:38:25 +0100 Subject: [PATCH 01/12] Changed a few things to build QCodeEditor against Qt5 and Qt6 --- CMakeLists.txt | 6 +++--- example/CMakeLists.txt | 11 +++++++---- example/src/MainWindow.cpp | 3 ++- include/internal/QLineNumberArea.hpp | 3 +++ src/internal/QLineNumberArea.cpp | 20 +++++++++++++++++++- 5 files changed, 34 insertions(+), 9 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index db356ee..f5fade7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -105,7 +105,7 @@ if(CMAKE_COMPILER_IS_GNUCXX) endif(CMAKE_COMPILER_IS_GNUCXX) target_link_libraries(QCodeEditor - Qt5::Core - Qt5::Widgets - Qt5::Gui + ${QT_VERSION}::Core + ${QT_VERSION}::Widgets + ${QT_VERSION}::Gui ) diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt index 712d761..162c3e0 100644 --- a/example/CMakeLists.txt +++ b/example/CMakeLists.txt @@ -6,7 +6,10 @@ set(CMAKE_CXX_STANDARD 17) set(CMAKE_AUTOMOC On) set(CMAKE_AUTORCC ON) -find_package(Qt5 COMPONENTS Widgets Gui REQUIRED) +if(NOT QT_VERSION) + set(QT_VERSION Qt5) +endif() +find_package(${QT_VERSION} COMPONENTS Widgets Gui REQUIRED) add_executable(QCodeEditorExample resources/demo_resources.qrc @@ -22,8 +25,8 @@ target_include_directories(QCodeEditorExample PUBLIC ) target_link_libraries(QCodeEditorExample - Qt5::Core - Qt5::Widgets - Qt5::Gui + ${QT_VERSION}::Core + ${QT_VERSION}::Widgets + ${QT_VERSION}::Gui QCodeEditor ) diff --git a/example/src/MainWindow.cpp b/example/src/MainWindow.cpp index 18925fc..a84c0db 100644 --- a/example/src/MainWindow.cpp +++ b/example/src/MainWindow.cpp @@ -33,6 +33,7 @@ #include #include #include +#include MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), m_setupLayout(nullptr), m_codeSampleCombobox(nullptr), m_highlighterCombobox(nullptr), @@ -376,4 +377,4 @@ void MainWindow::updateDiagnostics() auto item = dynamic_cast(m_diagnostics->item(i)); m_codeEditor->addDiagnostic(item->m_severity, item->m_span, item->m_message, item->m_code); } -} \ No newline at end of file +} diff --git a/include/internal/QLineNumberArea.hpp b/include/internal/QLineNumberArea.hpp index 1425a94..6673027 100644 --- a/include/internal/QLineNumberArea.hpp +++ b/include/internal/QLineNumberArea.hpp @@ -59,6 +59,9 @@ class QLineNumberArea : public QWidget void paintEvent(QPaintEvent *event) override; private: + QFont::Weight intToFontWeight(int v); + + QSyntaxStyle *m_syntaxStyle; QCodeEditor *m_codeEditParent; diff --git a/src/internal/QLineNumberArea.cpp b/src/internal/QLineNumberArea.cpp index 548b975..c6912de 100644 --- a/src/internal/QLineNumberArea.cpp +++ b/src/internal/QLineNumberArea.cpp @@ -68,6 +68,24 @@ void QLineNumberArea::clearDiagnosticMarkers() update(); } +QFont::Weight QLineNumberArea::intToFontWeight(int v) { + + QFont::Weight w; + + if (v <= 100) w = QFont::Thin; + else if (v <= 200) w = QFont::ExtraLight; + else if (v <= 300) w = QFont::Light; + else if (v <= 400) w = QFont::Normal; + else if (v <= 500) w = QFont::Medium; + else if (v <= 600) w = QFont::DemiBold; + else if (v <= 700) w = QFont::Bold; + else if (v <= 800) w = QFont::Bold; + else if (v <= 900) w = QFont::ExtraBold; + else w = QFont::Black; + + return w; +} + void QLineNumberArea::paintEvent(QPaintEvent *event) { QPainter painter(this); @@ -99,7 +117,7 @@ void QLineNumberArea::paintEvent(QPaintEvent *event) auto font = m_codeEditParent->font(); QFont currentLineFont(font); - currentLineFont.setWeight(currentLineFormat.fontWeight()); + currentLineFont.setWeight(intToFontWeight(currentLineFormat.fontWeight())); currentLineFont.setItalic(currentLineFormat.fontItalic()); painter.setFont(font); From 2b176435b70f7a0eb3ebc0918b12fe797b76e50c Mon Sep 17 00:00:00 2001 From: Wilfried Holzke Date: Fri, 14 Jan 2022 22:43:48 +0100 Subject: [PATCH 02/12] Updated README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index a03e1f5..bc6e4ba 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ must not use a resource file with the same name. ## Requirements 0. C++17 featured compiler. -0. Qt 5. +0. Qt 5 / Qt 6. ## Abilities 1. Highlight matched parentheses. From 9333ad617ca27363b9971d066aaed25ffd9cb22a Mon Sep 17 00:00:00 2001 From: Wilfried Holzke Date: Fri, 14 Jan 2022 23:36:19 +0100 Subject: [PATCH 03/12] Added an option to change the type of the library to shared --- CMakeLists.txt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f5fade7..285bb16 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -82,7 +82,10 @@ if(NOT QT_VERSION) endif() find_package(${QT_VERSION} REQUIRED COMPONENTS Core Gui Widgets) -add_library(QCodeEditor STATIC +if(NOT TYPEOFLIBRARY) + set(TYPEOFLIBRARY STATIC) +endif() +add_library(QCodeEditor ${TYPEOFLIBRARY} ${RESOURCES_FILE} ${SOURCE_FILES} ${INCLUDE_FILES} From 2acac9b970516f8d3eb2e649bb9f348095c91425 Mon Sep 17 00:00:00 2001 From: Wilfried Holzke Date: Sat, 15 Jan 2022 20:38:25 +0100 Subject: [PATCH 04/12] Added an install target --- CMakeLists.txt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 285bb16..1c35125 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -95,6 +95,11 @@ target_include_directories(QCodeEditor PUBLIC include ) +install(TARGETS QCodeEditor + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/QCodeEditor +) + if(CMAKE_COMPILER_IS_GNUCXX) target_compile_options(QCodeEditor PRIVATE From a27877477b95624a39e00ae154278ed2ee9547f6 Mon Sep 17 00:00:00 2001 From: Wilfried Holzke Date: Sat, 15 Jan 2022 20:44:46 +0100 Subject: [PATCH 05/12] Work on installing of header files --- CMakeLists.txt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1c35125..fbc7d10 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,8 @@ cmake_minimum_required(VERSION 3.6) project(QCodeEditor) +include(GNUInstallDirs) + set(CMAKE_CXX_STANDARD 17) option(BUILD_EXAMPLE "Example building required" Off) @@ -92,7 +94,8 @@ add_library(QCodeEditor ${TYPEOFLIBRARY} ) target_include_directories(QCodeEditor PUBLIC - include + PUBLIC $/include + PUBLIC $ ) install(TARGETS QCodeEditor From 8629f3ccd40079e1073bf7d57d2310aab5700c0e Mon Sep 17 00:00:00 2001 From: Wilfried Holzke Date: Sat, 15 Jan 2022 20:55:20 +0100 Subject: [PATCH 06/12] Work on installing of header files --- CMakeLists.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index fbc7d10..ffffa3e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -93,6 +93,8 @@ add_library(QCodeEditor ${TYPEOFLIBRARY} ${INCLUDE_FILES} ) +set_target_properties(QCodeEditor PROPERTIES PUBLIC_HEADER ${INCLUDE_FILES}) + target_include_directories(QCodeEditor PUBLIC PUBLIC $/include PUBLIC $ From db1a2ee009af892b588f3f53f108c4dd67ef79a2 Mon Sep 17 00:00:00 2001 From: Wilfried Holzke Date: Sat, 15 Jan 2022 21:01:54 +0100 Subject: [PATCH 07/12] Work on installing of header files --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ffffa3e..7c9957a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -93,7 +93,7 @@ add_library(QCodeEditor ${TYPEOFLIBRARY} ${INCLUDE_FILES} ) -set_target_properties(QCodeEditor PROPERTIES PUBLIC_HEADER ${INCLUDE_FILES}) +set_target_properties(QCodeEditor PROPERTIES PUBLIC_HEADER "${INCLUDE_FILES}") target_include_directories(QCodeEditor PUBLIC PUBLIC $/include From 23572ce21e7415fb62394a4b093e29f967d50cd4 Mon Sep 17 00:00:00 2001 From: Wilfried Holzke Date: Sat, 15 Jan 2022 21:09:00 +0100 Subject: [PATCH 08/12] Work on installing of header files --- CMakeLists.txt | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7c9957a..6fdf8e1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -93,8 +93,6 @@ add_library(QCodeEditor ${TYPEOFLIBRARY} ${INCLUDE_FILES} ) -set_target_properties(QCodeEditor PROPERTIES PUBLIC_HEADER "${INCLUDE_FILES}") - target_include_directories(QCodeEditor PUBLIC PUBLIC $/include PUBLIC $ @@ -105,6 +103,10 @@ install(TARGETS QCodeEditor PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/QCodeEditor ) +install(DIRECTORY "${CMAKE_SOURCE_DIR}/include" + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/QCodeEditor +) + if(CMAKE_COMPILER_IS_GNUCXX) target_compile_options(QCodeEditor PRIVATE From 7e6a47b61c4f8a6c32291e979fc1eedbf3366ebc Mon Sep 17 00:00:00 2001 From: Wilfried Holzke Date: Sat, 15 Jan 2022 21:13:12 +0100 Subject: [PATCH 09/12] Work on installing of header files --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6fdf8e1..01e4ed1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -103,7 +103,7 @@ install(TARGETS QCodeEditor PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/QCodeEditor ) -install(DIRECTORY "${CMAKE_SOURCE_DIR}/include" +install(DIRECTORY "${CMAKE_SOURCE_DIR}/include/" DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/QCodeEditor ) From 414990bab3d99dbc1640f531f333723c2dbd8d69 Mon Sep 17 00:00:00 2001 From: Wilfried Holzke Date: Sat, 15 Jan 2022 21:35:53 +0100 Subject: [PATCH 10/12] Added a version to the library target --- CMakeLists.txt | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 01e4ed1..7d14946 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,12 +1,16 @@ cmake_minimum_required(VERSION 3.6) project(QCodeEditor) -include(GNUInstallDirs) +set(LIB_VERSION_MAJOR 0) +set(LIB_VERSION_MINOR 1) +set(LIB_VERSION_TWEAK 0) +set(LIB_VERSION ${LIB_VERSION_MAJOR}.${LIB_VERSION_MINOR}.${LIB_VERSION_TWEAK}) set(CMAKE_CXX_STANDARD 17) -option(BUILD_EXAMPLE "Example building required" Off) +include(GNUInstallDirs) +option(BUILD_EXAMPLE "Example building required" Off) if (${BUILD_EXAMPLE}) message(STATUS "QCodeEditor example will be built.") add_subdirectory(example) @@ -93,6 +97,14 @@ add_library(QCodeEditor ${TYPEOFLIBRARY} ${INCLUDE_FILES} ) +# Set version of the library +set_target_properties(QCodeEditor PROPERTIES VERSION ${LIB_VERSION_MAJOR}.${LIB_VERSION_MINOR}.${LIB_VERSION_TWEAK}) + +if (TYPEOFLIBRARY STREQUAL "SHARED") + # Create symlink "libtestlib.${LIB_VERSION_MAJOR} ->" + set_target_properties(QCodeEditor PROPERTIES SOVERSION ${LIB_VERSION_MAJOR}) +endif() + target_include_directories(QCodeEditor PUBLIC PUBLIC $/include PUBLIC $ From 7069dbe379d97cb8f5f7df94c2425d13e95ea236 Mon Sep 17 00:00:00 2001 From: Wilfried Holzke Date: Sat, 15 Jan 2022 21:46:42 +0100 Subject: [PATCH 11/12] Added configuration to use find_package() --- CMakeLists.txt | 40 +++++++++++++++++++++++++++++++++++----- 1 file changed, 35 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7d14946..b3f80c5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -97,11 +97,10 @@ add_library(QCodeEditor ${TYPEOFLIBRARY} ${INCLUDE_FILES} ) -# Set version of the library -set_target_properties(QCodeEditor PROPERTIES VERSION ${LIB_VERSION_MAJOR}.${LIB_VERSION_MINOR}.${LIB_VERSION_TWEAK}) - if (TYPEOFLIBRARY STREQUAL "SHARED") - # Create symlink "libtestlib.${LIB_VERSION_MAJOR} ->" + # Set version of the library + set_target_properties(QCodeEditor PROPERTIES VERSION ${LIB_VERSION_MAJOR}.${LIB_VERSION_MINOR}.${LIB_VERSION_TWEAK}) + # Create symlink "libQCodeEditor.${LIB_VERSION_MAJOR} ->" set_target_properties(QCodeEditor PROPERTIES SOVERSION ${LIB_VERSION_MAJOR}) endif() @@ -110,7 +109,7 @@ target_include_directories(QCodeEditor PUBLIC PUBLIC $ ) -install(TARGETS QCodeEditor +install(TARGETS QCodeEditor EXPORT QCodeEditorTarget LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/QCodeEditor ) @@ -136,3 +135,34 @@ target_link_libraries(QCodeEditor ${QT_VERSION}::Widgets ${QT_VERSION}::Gui ) + +# Install files to use "find_package(QCodeEditor )" +set(INSTALL_CONFIGDIR ${CMAKE_INSTALL_LIBDIR}/cmake/QCodeEditor) + +include(CMakePackageConfigHelpers) +write_basic_package_version_file( + ${CMAKE_CURRENT_BINARY_DIR}/QCodeEditorConfigVersion.cmake + VERSION ${LIB_VERSION} + COMPATIBILITY AnyNewerVersion +) + +configure_package_config_file( + ${CMAKE_CURRENT_LIST_DIR}/cmake/QCodeEditorConfig.cmake.in + ${CMAKE_CURRENT_BINARY_DIR}/QCodeEditorConfig.cmake + INSTALL_DESTINATION ${INSTALL_CONFIGDIR} +) + +install( + FILES + ${CMAKE_CURRENT_BINARY_DIR}/QCodeEditorConfig.cmake + ${CMAKE_CURRENT_BINARY_DIR}/QCodeEditorConfigVersion.cmake + DESTINATION ${INSTALL_CONFIGDIR} +) + +install(EXPORT QCodeEditorTarget + FILE QCodeEditorTargets.cmake + NAMESPACE QCodeEditor:: + DESTINATION ${INSTALL_CONFIGDIR} +) + +add_library(QCodeEditor::QCodeEditor ALIAS QCodeEditor) From 4c29f7f453e2355f6abac0d953feb4f3739583b1 Mon Sep 17 00:00:00 2001 From: Wilfried Holzke Date: Sat, 15 Jan 2022 21:50:12 +0100 Subject: [PATCH 12/12] Added missing config file --- cmake/QCodeEditorConfig.cmake.in | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 cmake/QCodeEditorConfig.cmake.in diff --git a/cmake/QCodeEditorConfig.cmake.in b/cmake/QCodeEditorConfig.cmake.in new file mode 100644 index 0000000..fc5041d --- /dev/null +++ b/cmake/QCodeEditorConfig.cmake.in @@ -0,0 +1,3 @@ +@PACKAGE_INIT@ + +include("${CMAKE_CURRENT_LIST_DIR}/QCodeEditorTargets.cmake")