Skip to content

Commit

Permalink
Split source to core and shell parts
Browse files Browse the repository at this point in the history
Ahead of distinct macOS shell
  • Loading branch information
IgKh committed Oct 19, 2024
1 parent be16297 commit 0855af1
Show file tree
Hide file tree
Showing 59 changed files with 282 additions and 192 deletions.
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ find_package(Qt6 REQUIRED COMPONENTS Core)
qt_standard_project_setup(REQUIRES 6.5)

add_subdirectory(typstdriver)
add_subdirectory(src)
add_subdirectory(core)
add_subdirectory(shell)
add_subdirectory(tests)

if(APPLE)
Expand Down
64 changes: 64 additions & 0 deletions core/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
find_package(Qt6 REQUIRED COMPONENTS Widgets)

find_package(Git)
if(Git_FOUND)
execute_process(
COMMAND ${GIT_EXECUTABLE} log -1 --format=%h
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
OUTPUT_VARIABLE KATVAN_GIT_SHA
OUTPUT_STRIP_TRAILING_WHITESPACE
)
else()
set(KATVAN_GIT_SHA "unknown")
endif()
configure_file(katvan_version.h.in katvan_version.h @ONLY)

set(SOURCES
katvan_codemodel.cpp
katvan_diagnosticsmodel.cpp
katvan_editor.cpp
katvan_editorlayout.cpp
katvan_editorsettings.cpp
katvan_editortheme.cpp
katvan_highlighter.cpp
katvan_parsing.cpp
katvan_previewerview.cpp
katvan_spellchecker.cpp
katvan_typstdriverwrapper.cpp
katvan_text_utils.cpp
)

qt_add_resources(SOURCES themes/themes.qrc)

if(APPLE)
list(APPEND SOURCES
katvan_spellchecker_macos.mm
)
else()
list(APPEND SOURCES
katvan_spellchecker_hunspell.cpp
)
endif()

add_library(katvan_core STATIC ${SOURCES})

target_include_directories(katvan_core PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR})
target_compile_definitions(katvan_core PUBLIC QT_RESTRICTED_CAST_FROM_ASCII QT_NO_EMIT)

if(MSVC)
target_compile_options(katvan_core PUBLIC /W4)
else()
target_compile_options(katvan_core PUBLIC -Wall -Wextra -pedantic -Wno-switch)
endif()

target_link_libraries(katvan_core PUBLIC
typstdriver
Qt6::Widgets
)

if(NOT APPLE)
find_package(PkgConfig REQUIRED)
pkg_check_modules(hunspell REQUIRED IMPORTED_TARGET hunspell)

target_link_libraries(katvan_core PUBLIC PkgConfig::hunspell)
endif()
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion src/katvan_editor.cpp → core/katvan_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#include "katvan_editorlayout.h"
#include "katvan_highlighter.h"
#include "katvan_spellchecker.h"
#include "katvan_utils.h"
#include "katvan_text_utils.h"

#include <QMenu>
#include <QPainter>
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "katvan_editorlayout.h"
#include "katvan_utils.h"
#include "katvan_text_utils.h"

#include <QGuiApplication>
#include <QPainter>
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
6 changes: 6 additions & 0 deletions src/katvan_editortheme.cpp → core/katvan_editortheme.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@
#include <QStyle>
#include <QStyleHints>

QT_BEGIN_NAMESPACE
extern int qInitResources_themes();
QT_END_NAMESPACE

namespace katvan {

using HiglightingMarkerKind = parsing::HiglightingMarker::Kind;
Expand Down Expand Up @@ -132,6 +136,8 @@ static void readEditorColors(const QJsonObject& obj,

EditorTheme::EditorTheme(const QString& themeJsonFile)
{
qInitResources_themes();

QFile file(themeJsonFile);
if (!file.open(QIODevice::ReadOnly)) {
qWarning() << "Couldn't open theme file!" << file.errorString();
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion src/katvan_highlighter.cpp → core/katvan_highlighter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#include "katvan_editortheme.h"
#include "katvan_highlighter.h"
#include "katvan_spellchecker.h"
#include "katvan_utils.h"
#include "katvan_text_utils.h"

#include <QTextDocument>

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
64 changes: 64 additions & 0 deletions core/katvan_text_utils.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* This file is part of Katvan
* Copyright (c) 2024 Igor Khanin
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "katvan_text_utils.h"

namespace katvan::utils {

bool isBidiControlChar(QChar ch)
{
return ch == ALM_MARK
|| ch == LRM_MARK
|| ch == RLM_MARK
|| ch == LRI_MARK
|| ch == RLI_MARK
|| ch == PDI_MARK;
}

Qt::LayoutDirection naturalTextDirection(const QString& text)
{
int count = 0;
const QChar* ptr = text.constData();
const QChar* end = ptr + text.length();

while (ptr < end) {
if (count++ > 100) {
break;
}

uint codepoint = ptr->unicode();
if (QChar::isHighSurrogate(codepoint) && ptr + 1 < end) {
ushort low = ptr[1].unicode();
if (QChar::isLowSurrogate(low)) {
codepoint = QChar::surrogateToUcs4(codepoint, low);
ptr++;
}
}

QChar::Direction direction = QChar::direction(codepoint);
if (direction == QChar::DirR || direction == QChar::DirAL) {
return Qt::RightToLeft;
}
else if (direction == QChar::DirL) {
return Qt::LeftToRight;
}
ptr++;
}
return Qt::LayoutDirectionAuto;
}

}
14 changes: 0 additions & 14 deletions src/katvan_utils.h → core/katvan_text_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,8 @@
*/
#pragma once

#include <QIcon>
#include <QString>

QT_BEGIN_NAMESPACE
class QWidget;
QT_END_NAMESPACE

namespace katvan::utils {

static constexpr QChar ALM_MARK = (ushort)0x061c;
Expand All @@ -35,15 +30,6 @@ static constexpr QChar PDI_MARK = (ushort)0x2069;

bool isBidiControlChar(QChar ch);

QString getApplicationDir(bool& isInstalled);

QIcon themeIcon(const char* xdgIcon);
QIcon themeIcon(const char* xdgIcon, const char* macIcon);

QString formatFilePath(QString path);

Qt::LayoutDirection naturalTextDirection(const QString& text);

QString showPdfExportDialog(QWidget* parent, const QString& sourceFilePath);

}
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ private slots:
Status d_status;
std::optional<QString> d_pendingSource;
QList<PendingEdit> d_pendingEdits;

QSet<int> d_pendingPagesToRender;
};

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
55 changes: 55 additions & 0 deletions shell/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
find_package(Qt6 REQUIRED COMPONENTS LinguistTools)

set(SOURCES
katvan_backuphandler.cpp
katvan_compileroutput.cpp
katvan_mainwindow.cpp
katvan_previewer.cpp
katvan_recentfiles.cpp
katvan_searchbar.cpp
katvan_settingsdialog.cpp
katvan_utils.cpp
main.cpp
)

qt_add_resources(SOURCES ${PROJECT_SOURCE_DIR}/assets/assets.qrc)
if(WIN32)
file(COPY ${PROJECT_SOURCE_DIR}/assets/katvan.ico DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
configure_file(${PROJECT_SOURCE_DIR}/assets/katvan.rc.in katvan.rc @ONLY)
list(APPEND SOURCES ${CMAKE_CURRENT_BINARY_DIR}/katvan.rc)
elseif(APPLE)
list(APPEND SOURCES
katvan_utils_macos.mm
)

set(macos_icon "${PROJECT_SOURCE_DIR}/assets/katvan.icns")
set_source_files_properties(${macos_icon} PROPERTIES MACOSX_PACKAGE_LOCATION "Resources")
list(APPEND SOURCES ${macos_icon})
endif()

add_executable(katvan ${SOURCES})
target_link_libraries(katvan PRIVATE katvan_core)

if(KATVAN_DISABLE_PORTABLE)
target_compile_definitions(katvan PRIVATE KATVAN_DISABLE_PORTABLE)
elseif(KATVAN_PORTABLE_BUILD)
target_compile_definitions(katvan PRIVATE KATVAN_PORTABLE_BUILD)
endif()

set_target_properties(katvan PROPERTIES
OUTPUT_NAME $<IF:$<PLATFORM_ID:Darwin>,Katvan,katvan>
WIN32_EXECUTABLE ON
MACOSX_BUNDLE ON
MACOSX_BUNDLE_INFO_PLIST ${PROJECT_SOURCE_DIR}/assets/Info.plist.in
MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION}
XCODE_EMBED_FRAMEWORKS typstdriver
)

qt_create_translation(QM_FILES . ../core translations/katvan_en.ts OPTIONS -pluralonly -no-obsolete -locations none)
qt_create_translation(QM_FILES . ../core translations/katvan_he.ts OPTIONS -no-obsolete -locations none)

qt_add_resources(katvan "translations"
PREFIX "/i18n"
BASE "${CMAKE_CURRENT_BINARY_DIR}"
FILES "${QM_FILES}"
)
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "katvan_backuphandler.h"

#include "katvan_editor.h"

#include <QDateTime>
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "katvan_compileroutput.h"

#include "katvan_diagnosticsmodel.h"

#include <QHeaderView>
Expand Down
File renamed without changes.
9 changes: 5 additions & 4 deletions src/katvan_mainwindow.cpp → shell/katvan_mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,18 @@
*/
#include "katvan_backuphandler.h"
#include "katvan_compileroutput.h"
#include "katvan_diagnosticsmodel.h"
#include "katvan_editor.h"
#include "katvan_editorsettings.h"
#include "katvan_mainwindow.h"
#include "katvan_previewer.h"
#include "katvan_recentfiles.h"
#include "katvan_searchbar.h"
#include "katvan_settingsdialog.h"
#include "katvan_utils.h"

#include "katvan_diagnosticsmodel.h"
#include "katvan_editor.h"
#include "katvan_editorsettings.h"
#include "katvan_spellchecker.h"
#include "katvan_typstdriverwrapper.h"
#include "katvan_utils.h"

#include <QApplication>
#include <QClipboard>
Expand Down
5 changes: 3 additions & 2 deletions src/katvan_mainwindow.h → shell/katvan_mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,12 @@ namespace katvan

class BackupHandler;
class CompilerOutput;
class Editor;
class EditorSettingsDialog;
class Previewer;
class RecentFiles;
class SearchBar;

class Editor;
class EditorSettingsDialog;
class TypstDriverWrapper;

class MainWindow : public QMainWindow
Expand Down
3 changes: 2 additions & 1 deletion src/katvan_previewer.cpp → shell/katvan_previewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "katvan_previewer.h"
#include "katvan_utils.h"

#include "katvan_previewerview.h"
#include "katvan_typstdriverwrapper.h"
#include "katvan_utils.h"

#include <QComboBox>
#include <QHBoxLayout>
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 0855af1

Please sign in to comment.