diff --git a/CMakeLists.txt b/CMakeLists.txt index db356ee..b3f80c5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,10 +1,16 @@ cmake_minimum_required(VERSION 3.6) project(QCodeEditor) +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) @@ -82,14 +88,34 @@ 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} ) +if (TYPEOFLIBRARY STREQUAL "SHARED") + # 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() + target_include_directories(QCodeEditor PUBLIC - include + PUBLIC $/include + PUBLIC $ +) + +install(TARGETS QCodeEditor EXPORT QCodeEditorTarget + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/QCodeEditor +) + +install(DIRECTORY "${CMAKE_SOURCE_DIR}/include/" + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/QCodeEditor ) if(CMAKE_COMPILER_IS_GNUCXX) @@ -105,7 +131,38 @@ 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 ) + +# 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) 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. 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") 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);