Skip to content
Open
69 changes: 63 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
Expand Down Expand Up @@ -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 $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>/include
PUBLIC $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/QCodeEditor>
)

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)
Expand All @@ -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)
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
3 changes: 3 additions & 0 deletions cmake/QCodeEditorConfig.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@PACKAGE_INIT@

include("${CMAKE_CURRENT_LIST_DIR}/QCodeEditorTargets.cmake")
11 changes: 7 additions & 4 deletions example/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
)
3 changes: 2 additions & 1 deletion example/src/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include <QSpinBox>
#include <QStyle>
#include <QVBoxLayout>
#include <QFile>

MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent), m_setupLayout(nullptr), m_codeSampleCombobox(nullptr), m_highlighterCombobox(nullptr),
Expand Down Expand Up @@ -376,4 +377,4 @@ void MainWindow::updateDiagnostics()
auto item = dynamic_cast<const DiagnosticListItem *>(m_diagnostics->item(i));
m_codeEditor->addDiagnostic(item->m_severity, item->m_span, item->m_message, item->m_code);
}
}
}
3 changes: 3 additions & 0 deletions include/internal/QLineNumberArea.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
20 changes: 19 additions & 1 deletion src/internal/QLineNumberArea.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);

Expand Down