From 3250fc72f906797f113855cf9dde4e7803a66bd9 Mon Sep 17 00:00:00 2001 From: rtk0c Date: Mon, 27 Jun 2022 00:14:58 +0000 Subject: (From git) Reformat qt ui project git-svn-id: file:///home/arch/svn/epistmool/trunk@5 71f44415-077c-4ad7-a976-72ddbf76608f --- ui.qt/CMakeLists.txt | 18 +- ui.qt/CMakeLists.txt.user | 332 ------------------------------------- ui.qt/source/DatabaseClient.cpp | 5 + ui.qt/source/DatabaseClient.hpp | 7 + ui.qt/source/DatabaseServer.cpp | 5 + ui.qt/source/DatabaseServer.hpp | 7 + ui.qt/source/Document.cpp | 152 +++++++++++++++++ ui.qt/source/Document.hpp | 72 ++++++++ ui.qt/source/Keyword.cpp | 10 ++ ui.qt/source/Keyword.hpp | 26 +++ ui.qt/source/KnowledgeFragment.cpp | 11 ++ ui.qt/source/KnowledgeFragment.hpp | 38 +++++ ui.qt/source/document.cpp | 152 ----------------- ui.qt/source/document.hpp | 72 -------- ui.qt/source/fwd.hpp | 6 +- ui.qt/source/keyword.cpp | 10 -- ui.qt/source/keyword.hpp | 26 --- ui.qt/source/knowledgefragment.cpp | 11 -- ui.qt/source/knowledgefragment.hpp | 38 ----- ui.qt/source/main.cpp | 12 +- 20 files changed, 352 insertions(+), 658 deletions(-) delete mode 100644 ui.qt/CMakeLists.txt.user create mode 100644 ui.qt/source/DatabaseClient.cpp create mode 100644 ui.qt/source/DatabaseClient.hpp create mode 100644 ui.qt/source/DatabaseServer.cpp create mode 100644 ui.qt/source/DatabaseServer.hpp create mode 100644 ui.qt/source/Document.cpp create mode 100644 ui.qt/source/Document.hpp create mode 100644 ui.qt/source/Keyword.cpp create mode 100644 ui.qt/source/Keyword.hpp create mode 100644 ui.qt/source/KnowledgeFragment.cpp create mode 100644 ui.qt/source/KnowledgeFragment.hpp delete mode 100644 ui.qt/source/document.cpp delete mode 100644 ui.qt/source/document.hpp delete mode 100644 ui.qt/source/keyword.cpp delete mode 100644 ui.qt/source/keyword.hpp delete mode 100644 ui.qt/source/knowledgefragment.cpp delete mode 100644 ui.qt/source/knowledgefragment.hpp (limited to 'ui.qt') diff --git a/ui.qt/CMakeLists.txt b/ui.qt/CMakeLists.txt index c16e915..c235133 100644 --- a/ui.qt/CMakeLists.txt +++ b/ui.qt/CMakeLists.txt @@ -2,22 +2,25 @@ cmake_minimum_required(VERSION 3.16) project(EpistmoolUI VERSION 0.1 LANGUAGES CXX) set(CMAKE_AUTOMOC ON) +set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED ON) -find_package(Qt6 6.2 COMPONENTS Widgets Quick REQUIRED) +find_package(Qt6 6.2 COMPONENTS Network Widgets Quick REQUIRED) qt_add_executable(appEpistmoolUI source/main.cpp source/fwd.hpp - source/knowledgefragment.hpp source/knowledgefragment.cpp - source/keyword.hpp source/keyword.cpp + source/DatabaseClient.hpp source/DatabaseClient.cpp + source/DatabaseServer.hpp source/DatabaseServer.cpp + source/KnowledgeFragment.hpp source/KnowledgeFragment.cpp + source/Keyword.hpp source/Keyword.cpp ) qt_add_qml_module(appEpistmoolUI URI EpistmoolUI VERSION 1.0 SOURCES - source/document.hpp source/document.cpp + source/Document.hpp source/Document.cpp QML_FILES source/qml/MainWindow.qml source/qml/Navigator.qml @@ -34,12 +37,11 @@ set_target_properties(appEpistmoolUI PROPERTIES ) target_include_directories(appEpistmoolUI PUBLIC source) -target_compile_definitions(appEpistmoolUI -PRIVATE +target_compile_definitions(appEpistmoolUI PRIVATE $<$,$>:QT_QML_DEBUG> ) -target_link_libraries(appEpistmoolUI -PRIVATE +target_link_libraries(appEpistmoolUI PRIVATE + Qt6::Network Qt6::Widgets Qt6::Quick ) diff --git a/ui.qt/CMakeLists.txt.user b/ui.qt/CMakeLists.txt.user deleted file mode 100644 index 8611bff..0000000 --- a/ui.qt/CMakeLists.txt.user +++ /dev/null @@ -1,332 +0,0 @@ - - - - - - EnvironmentId - {f75faabe-ab95-4cc2-874a-48bde0690e72} - - - ProjectExplorer.Project.ActiveTarget - 0 - - - ProjectExplorer.Project.EditorSettings - - true - false - true - - Cpp - - CppGlobal - - - - QmlJS - - QmlJSGlobal - - - 2 - UTF-8 - false - 4 - false - 80 - true - true - 1 - false - true - false - 0 - true - true - 0 - 8 - true - false - 1 - true - true - true - *.md, *.MD, Makefile - false - true - - - - ProjectExplorer.Project.PluginSettings - - - true - false - true - true - true - true - - - 0 - true - - true - Builtin.BuildSystem - - true - true - Builtin.DefaultTidyAndClazy - 6 - - - - true - - - true - - - - - ProjectExplorer.Project.Target.0 - - Desktop - Desktop (Qt 6) - Desktop (Qt 6) - {bb2c42c9-b15c-4e15-9289-35a041c6fb85} - 0 - 0 - 0 - - Debug - -GNinja --DCMAKE_BUILD_TYPE:STRING=Debug --DCMAKE_PROJECT_INCLUDE_BEFORE:PATH=%{IDE:ResourcePath}/package-manager/auto-setup.cmake --DQT_QMAKE_EXECUTABLE:STRING=%{Qt:qmakeExecutable} --DCMAKE_PREFIX_PATH:STRING=%{Qt:QT_INSTALL_PREFIX} --DCMAKE_C_COMPILER:STRING=%{Compiler:Executable:C} --DCMAKE_CXX_COMPILER:STRING=%{Compiler:Executable:Cxx} - 0 - /home/rtk0c/Development/epistmool/ui.qt/build/Debug - - - - all - - true - Build - CMakeProjectManager.MakeStep - - 1 - Build - Build - ProjectExplorer.BuildSteps.Build - - - - - clean - - true - Build - CMakeProjectManager.MakeStep - - 1 - Clean - Clean - ProjectExplorer.BuildSteps.Clean - - 2 - false - - false - - Debug - CMakeProjectManager.CMakeBuildConfiguration - - - Release - -GNinja --DCMAKE_BUILD_TYPE:STRING=Release --DCMAKE_PROJECT_INCLUDE_BEFORE:PATH=%{IDE:ResourcePath}/package-manager/auto-setup.cmake --DQT_QMAKE_EXECUTABLE:STRING=%{Qt:qmakeExecutable} --DCMAKE_PREFIX_PATH:STRING=%{Qt:QT_INSTALL_PREFIX} --DCMAKE_C_COMPILER:STRING=%{Compiler:Executable:C} --DCMAKE_CXX_COMPILER:STRING=%{Compiler:Executable:Cxx} - /home/rtk0c/Development/epistmool/ui.qt/build-EpistmoolUI-Desktop_Qt_6-Release - - - - all - - true - Build - CMakeProjectManager.MakeStep - - 1 - Build - Build - ProjectExplorer.BuildSteps.Build - - - - - clean - - true - Build - CMakeProjectManager.MakeStep - - 1 - Clean - Clean - ProjectExplorer.BuildSteps.Clean - - 2 - false - - false - - Release - CMakeProjectManager.CMakeBuildConfiguration - - - RelWithDebInfo - -GNinja --DCMAKE_BUILD_TYPE:STRING=RelWithDebInfo --DCMAKE_PROJECT_INCLUDE_BEFORE:PATH=%{IDE:ResourcePath}/package-manager/auto-setup.cmake --DQT_QMAKE_EXECUTABLE:STRING=%{Qt:qmakeExecutable} --DCMAKE_PREFIX_PATH:STRING=%{Qt:QT_INSTALL_PREFIX} --DCMAKE_C_COMPILER:STRING=%{Compiler:Executable:C} --DCMAKE_CXX_COMPILER:STRING=%{Compiler:Executable:Cxx} - /home/rtk0c/Development/epistmool/ui.qt/build-EpistmoolUI-Desktop_Qt_6-RelWithDebInfo - - - - all - - true - Build - CMakeProjectManager.MakeStep - - 1 - Build - Build - ProjectExplorer.BuildSteps.Build - - - - - clean - - true - Build - CMakeProjectManager.MakeStep - - 1 - Clean - Clean - ProjectExplorer.BuildSteps.Clean - - 2 - false - - false - - Release with Debug Information - CMakeProjectManager.CMakeBuildConfiguration - - - MinSizeRel - -GNinja --DCMAKE_BUILD_TYPE:STRING=MinSizeRel --DCMAKE_PROJECT_INCLUDE_BEFORE:PATH=%{IDE:ResourcePath}/package-manager/auto-setup.cmake --DQT_QMAKE_EXECUTABLE:STRING=%{Qt:qmakeExecutable} --DCMAKE_PREFIX_PATH:STRING=%{Qt:QT_INSTALL_PREFIX} --DCMAKE_C_COMPILER:STRING=%{Compiler:Executable:C} --DCMAKE_CXX_COMPILER:STRING=%{Compiler:Executable:Cxx} - /home/rtk0c/Development/epistmool/ui.qt/build-EpistmoolUI-Desktop_Qt_6-MinSizeRel - - - - all - - true - Build - CMakeProjectManager.MakeStep - - 1 - Build - Build - ProjectExplorer.BuildSteps.Build - - - - - clean - - true - Build - CMakeProjectManager.MakeStep - - 1 - Clean - Clean - ProjectExplorer.BuildSteps.Clean - - 2 - false - - false - - Minimum Size Release - CMakeProjectManager.CMakeBuildConfiguration - - 4 - - - 0 - Deploy - Deploy - ProjectExplorer.BuildSteps.Deploy - - 1 - - false - ProjectExplorer.DefaultDeployConfiguration - - 1 - - true - true - true - - 2 - - appEpistmoolUI - CMakeProjectManager.CMakeRunConfiguration.appEpistmoolUI - appEpistmoolUI - false - true - true - false - true - /home/rtk0c/Development/epistmool/ui.qt/build/Debug - - 1 - - - - ProjectExplorer.Project.TargetCount - 1 - - - ProjectExplorer.Project.Updater.FileVersion - 22 - - - Version - 22 - - diff --git a/ui.qt/source/DatabaseClient.cpp b/ui.qt/source/DatabaseClient.cpp new file mode 100644 index 0000000..430fe79 --- /dev/null +++ b/ui.qt/source/DatabaseClient.cpp @@ -0,0 +1,5 @@ +#include "DatabaseClient.hpp" + +DatabaseClient::DatabaseClient() +{ +} diff --git a/ui.qt/source/DatabaseClient.hpp b/ui.qt/source/DatabaseClient.hpp new file mode 100644 index 0000000..17c6ed7 --- /dev/null +++ b/ui.qt/source/DatabaseClient.hpp @@ -0,0 +1,7 @@ +#pragma once + +class DatabaseClient +{ +public: + DatabaseClient(); +}; diff --git a/ui.qt/source/DatabaseServer.cpp b/ui.qt/source/DatabaseServer.cpp new file mode 100644 index 0000000..a850e63 --- /dev/null +++ b/ui.qt/source/DatabaseServer.cpp @@ -0,0 +1,5 @@ +#include "DatabaseServer.hpp" + +DatabaseServer::DatabaseServer() +{ +} diff --git a/ui.qt/source/DatabaseServer.hpp b/ui.qt/source/DatabaseServer.hpp new file mode 100644 index 0000000..0cd5039 --- /dev/null +++ b/ui.qt/source/DatabaseServer.hpp @@ -0,0 +1,7 @@ +#pragma once + +class DatabaseServer +{ +public: + DatabaseServer(); +}; diff --git a/ui.qt/source/Document.cpp b/ui.qt/source/Document.cpp new file mode 100644 index 0000000..272ac4c --- /dev/null +++ b/ui.qt/source/Document.cpp @@ -0,0 +1,152 @@ +#include "Document.hpp" + +#include +#include +#include +#include + +DocumentHandler::DocumentHandler(QObject* parent) + : QObject{ parent } +{ +} + +QQuickTextDocument* DocumentHandler::getDoc() const +{ + return mDoc; +} + +void DocumentHandler::setDoc(QQuickTextDocument* newDoc) +{ + if (mDoc != newDoc) { + auto oldDoc = mDoc; + mDoc = newDoc; + + if (oldDoc) { + disconnect(oldDoc->textDocument(), nullptr, this, nullptr); + } + if (newDoc) { + connect(newDoc->textDocument(), &QTextDocument::modificationChanged, this, [&]() { + // TODO add a timer to wait for 1 second before updating? + mModifyTime = QDateTime::currentDateTime(); + emit modificationChanged(); + }); + } + + emit docChanged(oldDoc); + } +} + +const QDateTime& DocumentHandler::getModifyTime() const +{ + return mModifyTime; +} + +int DocumentHandler::getCursorPos() const +{ + return mCursorPos; +} + +void DocumentHandler::setCursorPos(int newCursorPos) +{ + if (mCursorPos == newCursorPos) { + return; + } + mCursorPos = newCursorPos; + emit cursorPosChanged(); +} + +int DocumentHandler::getSelectionBegin() const +{ + return mSelectionBegin; +} + +void DocumentHandler::setSelectionBegin(int newSelectionBegin) +{ + if (mSelectionBegin == newSelectionBegin) { + return; + } + mSelectionBegin = newSelectionBegin; + emit selectionBeginChanged(); +} + +int DocumentHandler::getSelectionEnd() const +{ + return mSelectionEnd; +} + +void DocumentHandler::setSelectionEnd(int newSelectionEnd) +{ + if (mSelectionEnd == newSelectionEnd) { + return; + } + mSelectionEnd = newSelectionEnd; + emit selectionEndChanged(); +} + +QFont DocumentHandler::getActiveFont() const +{ + auto cursor = makeTextCursor(); + if (cursor.isNull()) { + return mDoc->textDocument()->defaultFont(); + } + auto format = cursor.charFormat(); + return format.font(); +} + +void DocumentHandler::setActiveFont(const QFont& font) +{ + auto cursor = makeTextCursor(); + if (!cursor.isNull() && cursor.charFormat().font() == font) { + return; + } + + QTextCharFormat format; + format.setFont(font); + mergeFormatOnWordOrSelection(format); + + emit activeFontChanged(); +} + +QColor DocumentHandler::getActiveTextColor() const +{ + auto cursor = makeTextCursor(); + if (cursor.isNull()) { + return QColor(Qt::black); + } + QTextCharFormat format = cursor.charFormat(); + return format.foreground().color(); +} + +void DocumentHandler::setActiveTextColor(const QColor& color) +{ + QTextCharFormat format; + format.setForeground(QBrush(color)); + mergeFormatOnWordOrSelection(format); + emit activeTextColorChanged(); +} + +QTextCursor DocumentHandler::makeTextCursor() const +{ + auto doc = mDoc->textDocument(); + if (!doc) { + return QTextCursor(); + } + + QTextCursor cursor(doc); + if (mSelectionBegin != mSelectionEnd) { + cursor.setPosition(mSelectionBegin); + cursor.setPosition(mSelectionEnd, QTextCursor::KeepAnchor); + } else { + cursor.setPosition(mCursorPos); + } + return cursor; +} + +void DocumentHandler::mergeFormatOnWordOrSelection(const QTextCharFormat& format) +{ + auto cursor = makeTextCursor(); + if (!cursor.hasSelection()) { + cursor.select(QTextCursor::WordUnderCursor); + } + cursor.mergeCharFormat(format); +} diff --git a/ui.qt/source/Document.hpp b/ui.qt/source/Document.hpp new file mode 100644 index 0000000..5ef1bba --- /dev/null +++ b/ui.qt/source/Document.hpp @@ -0,0 +1,72 @@ +#pragma once + +#include "fwd.hpp" + +#include +#include +#include +#include +#include + +// To be instanciated in QML as the logic backend to some TextArea +class DocumentHandler : public QObject +{ + Q_OBJECT + QML_ELEMENT + + Q_PROPERTY(QQuickTextDocument* document READ getDoc WRITE setDoc NOTIFY docChanged) + Q_PROPERTY(QDateTime modifyTime READ getModifyTime NOTIFY modificationChanged) + + Q_PROPERTY(int cursorPos READ getCursorPos WRITE setCursorPos NOTIFY cursorPosChanged) + Q_PROPERTY(int selectionBegin READ getSelectionBegin WRITE setSelectionBegin NOTIFY selectionBeginChanged) + Q_PROPERTY(int selectionEnd READ getSelectionEnd WRITE setSelectionEnd NOTIFY selectionEndChanged) + + Q_PROPERTY(QFont activeFont READ getActiveFont WRITE setActiveFont NOTIFY activeFontChanged) + Q_PROPERTY(QColor activeTextColor READ getActiveTextColor WRITE setActiveTextColor NOTIFY activeTextColorChanged) + +private: + QQuickTextDocument* mDoc = nullptr; + QDateTime mModifyTime; + + int mCursorPos; + int mSelectionBegin; + int mSelectionEnd; + +public: + explicit DocumentHandler(QObject* parent = nullptr); + + QQuickTextDocument* getDoc() const; + void setDoc(QQuickTextDocument* newDoc); + + const QDateTime& getModifyTime() const; + + int getCursorPos() const; + void setCursorPos(int newCursorPos); + + int getSelectionBegin() const; + void setSelectionBegin(int newSelectionBegin); + + int getSelectionEnd() const; + void setSelectionEnd(int newSelectionEnd); + + QFont getActiveFont() const; + void setActiveFont(const QFont& font); + + QColor getActiveTextColor() const; + void setActiveTextColor(const QColor& color); + +signals: + void docChanged(QQuickTextDocument* oldDoc); + void modificationChanged(); // Redirected from the currently bound document + + void cursorPosChanged(); + void selectionBeginChanged(); + void selectionEndChanged(); + + void activeFontChanged(); + void activeTextColorChanged(); + +private: + QTextCursor makeTextCursor() const; + void mergeFormatOnWordOrSelection(const QTextCharFormat& format); +}; diff --git a/ui.qt/source/Keyword.cpp b/ui.qt/source/Keyword.cpp new file mode 100644 index 0000000..f6c18be --- /dev/null +++ b/ui.qt/source/Keyword.cpp @@ -0,0 +1,10 @@ +#include "Keyword.hpp" + +#include "KnowledgeFragment.hpp" + +Keyword::Keyword(const QString& name) + : mName(name) +{ +} + +Keyword::~Keyword() = default; diff --git a/ui.qt/source/Keyword.hpp b/ui.qt/source/Keyword.hpp new file mode 100644 index 0000000..481b5bb --- /dev/null +++ b/ui.qt/source/Keyword.hpp @@ -0,0 +1,26 @@ +#pragma once + +#include "fwd.hpp" + +#include +#include + +class Keyword +{ +private: + QString mName; + std::vector mAssociations; + +public: + Keyword(const QString& name); + ~Keyword(); + + Keyword(const Keyword&) = default; + Keyword& operator=(const Keyword&) = default; + Keyword(Keyword&&) = default; + Keyword& operator=(Keyword&&) = default; +}; + +class KeywordDatabase +{ +}; diff --git a/ui.qt/source/KnowledgeFragment.cpp b/ui.qt/source/KnowledgeFragment.cpp new file mode 100644 index 0000000..3d08f6e --- /dev/null +++ b/ui.qt/source/KnowledgeFragment.cpp @@ -0,0 +1,11 @@ +#include "KnowledgeFragment.hpp" + +KnowledgeFragment::KnowledgeFragment(KnowledgeId id) + : mId{ id } +{ +} + +KnowledgeId KnowledgeFragment::getId() const +{ + return mId; +} diff --git a/ui.qt/source/KnowledgeFragment.hpp b/ui.qt/source/KnowledgeFragment.hpp new file mode 100644 index 0000000..9f4912d --- /dev/null +++ b/ui.qt/source/KnowledgeFragment.hpp @@ -0,0 +1,38 @@ +#pragma once + +#include "fwd.hpp" + +#include +#include +#include + +struct KnowledgeId +{ + size_t id; +}; + +class KnowledgeFragment +{ +private: + QDateTime mCreateTime; + QDateTime mModifyTime; + KnowledgeId mId; + +public: + KnowledgeFragment(KnowledgeId id); + + KnowledgeId getId() const; +}; + +class KnowledgeDatabase +{ +private: + std::vector mStorage; + std::vector mIndex; // Mapping from KnowledgeId (index) to `storage` index + KnowledgeId mNextId; + +public: + KnowledgeId allocateFragment(); + bool deleteFragment(KnowledgeId id); + KnowledgeFragment* getFragment(KnowledgeId id); +}; diff --git a/ui.qt/source/document.cpp b/ui.qt/source/document.cpp deleted file mode 100644 index 377913b..0000000 --- a/ui.qt/source/document.cpp +++ /dev/null @@ -1,152 +0,0 @@ -#include "document.hpp" - -#include -#include -#include -#include - -DocumentHandler::DocumentHandler(QObject* parent) - : QObject{ parent } -{ -} - -QQuickTextDocument* DocumentHandler::getDoc() const -{ - return mDoc; -} - -void DocumentHandler::setDoc(QQuickTextDocument* newDoc) -{ - if (mDoc != newDoc) { - auto oldDoc = mDoc; - mDoc = newDoc; - - if (oldDoc) { - disconnect(oldDoc->textDocument(), nullptr, this, nullptr); - } - if (newDoc) { - connect(newDoc->textDocument(), &QTextDocument::modificationChanged, this, [&]() { - // TODO add a timer to wait for 1 second before updating? - mModifyTime = QDateTime::currentDateTime(); - emit modificationChanged(); - }); - } - - emit docChanged(oldDoc); - } -} - -const QDateTime& DocumentHandler::getModifyTime() const -{ - return mModifyTime; -} - -int DocumentHandler::getCursorPos() const -{ - return mCursorPos; -} - -void DocumentHandler::setCursorPos(int newCursorPos) -{ - if (mCursorPos == newCursorPos) { - return; - } - mCursorPos = newCursorPos; - emit cursorPosChanged(); -} - -int DocumentHandler::getSelectionBegin() const -{ - return mSelectionBegin; -} - -void DocumentHandler::setSelectionBegin(int newSelectionBegin) -{ - if (mSelectionBegin == newSelectionBegin) { - return; - } - mSelectionBegin = newSelectionBegin; - emit selectionBeginChanged(); -} - -int DocumentHandler::getSelectionEnd() const -{ - return mSelectionEnd; -} - -void DocumentHandler::setSelectionEnd(int newSelectionEnd) -{ - if (mSelectionEnd == newSelectionEnd) { - return; - } - mSelectionEnd = newSelectionEnd; - emit selectionEndChanged(); -} - -QFont DocumentHandler::getActiveFont() const -{ - auto cursor = makeTextCursor(); - if (cursor.isNull()) { - return mDoc->textDocument()->defaultFont(); - } - auto format = cursor.charFormat(); - return format.font(); -} - -void DocumentHandler::setActiveFont(const QFont& font) -{ - auto cursor = makeTextCursor(); - if (!cursor.isNull() && cursor.charFormat().font() == font) { - return; - } - - QTextCharFormat format; - format.setFont(font); - mergeFormatOnWordOrSelection(format); - - emit activeFontChanged(); -} - -QColor DocumentHandler::getActiveTextColor() const -{ - auto cursor = makeTextCursor(); - if (cursor.isNull()) { - return QColor(Qt::black); - } - QTextCharFormat format = cursor.charFormat(); - return format.foreground().color(); -} - -void DocumentHandler::setActiveTextColor(const QColor& color) -{ - QTextCharFormat format; - format.setForeground(QBrush(color)); - mergeFormatOnWordOrSelection(format); - emit activeTextColorChanged(); -} - -QTextCursor DocumentHandler::makeTextCursor() const -{ - auto doc = mDoc->textDocument(); - if (!doc) { - return QTextCursor(); - } - - QTextCursor cursor(doc); - if (mSelectionBegin != mSelectionEnd) { - cursor.setPosition(mSelectionBegin); - cursor.setPosition(mSelectionEnd, QTextCursor::KeepAnchor); - } else { - cursor.setPosition(mCursorPos); - } - return cursor; -} - -void DocumentHandler::mergeFormatOnWordOrSelection(const QTextCharFormat& format) -{ - auto cursor = makeTextCursor(); - if (!cursor.hasSelection()) { - cursor.select(QTextCursor::WordUnderCursor); - } - cursor.mergeCharFormat(format); -} diff --git a/ui.qt/source/document.hpp b/ui.qt/source/document.hpp deleted file mode 100644 index 5ef1bba..0000000 --- a/ui.qt/source/document.hpp +++ /dev/null @@ -1,72 +0,0 @@ -#pragma once - -#include "fwd.hpp" - -#include -#include -#include -#include -#include - -// To be instanciated in QML as the logic backend to some TextArea -class DocumentHandler : public QObject -{ - Q_OBJECT - QML_ELEMENT - - Q_PROPERTY(QQuickTextDocument* document READ getDoc WRITE setDoc NOTIFY docChanged) - Q_PROPERTY(QDateTime modifyTime READ getModifyTime NOTIFY modificationChanged) - - Q_PROPERTY(int cursorPos READ getCursorPos WRITE setCursorPos NOTIFY cursorPosChanged) - Q_PROPERTY(int selectionBegin READ getSelectionBegin WRITE setSelectionBegin NOTIFY selectionBeginChanged) - Q_PROPERTY(int selectionEnd READ getSelectionEnd WRITE setSelectionEnd NOTIFY selectionEndChanged) - - Q_PROPERTY(QFont activeFont READ getActiveFont WRITE setActiveFont NOTIFY activeFontChanged) - Q_PROPERTY(QColor activeTextColor READ getActiveTextColor WRITE setActiveTextColor NOTIFY activeTextColorChanged) - -private: - QQuickTextDocument* mDoc = nullptr; - QDateTime mModifyTime; - - int mCursorPos; - int mSelectionBegin; - int mSelectionEnd; - -public: - explicit DocumentHandler(QObject* parent = nullptr); - - QQuickTextDocument* getDoc() const; - void setDoc(QQuickTextDocument* newDoc); - - const QDateTime& getModifyTime() const; - - int getCursorPos() const; - void setCursorPos(int newCursorPos); - - int getSelectionBegin() const; - void setSelectionBegin(int newSelectionBegin); - - int getSelectionEnd() const; - void setSelectionEnd(int newSelectionEnd); - - QFont getActiveFont() const; - void setActiveFont(const QFont& font); - - QColor getActiveTextColor() const; - void setActiveTextColor(const QColor& color); - -signals: - void docChanged(QQuickTextDocument* oldDoc); - void modificationChanged(); // Redirected from the currently bound document - - void cursorPosChanged(); - void selectionBeginChanged(); - void selectionEndChanged(); - - void activeFontChanged(); - void activeTextColorChanged(); - -private: - QTextCursor makeTextCursor() const; - void mergeFormatOnWordOrSelection(const QTextCharFormat& format); -}; diff --git a/ui.qt/source/fwd.hpp b/ui.qt/source/fwd.hpp index 7a24ded..14e0033 100644 --- a/ui.qt/source/fwd.hpp +++ b/ui.qt/source/fwd.hpp @@ -1,13 +1,13 @@ #pragma once -// document.hpp +// Document.hpp class DocumentHandler; -// keyword.hpp +// Keyword.hpp class Keyword; class KeywordDatabase; -// knowledgefragment.cpp +// Knowledgefragment.cpp struct KnowledgeId; class KnowledgeFragment; class KnowledgeDatabase; diff --git a/ui.qt/source/keyword.cpp b/ui.qt/source/keyword.cpp deleted file mode 100644 index f782437..0000000 --- a/ui.qt/source/keyword.cpp +++ /dev/null @@ -1,10 +0,0 @@ -#include "keyword.hpp" - -#include "knowledgefragment.hpp" - -Keyword::Keyword(const QString& name) - : name(name) -{ -} - -Keyword::~Keyword() = default; diff --git a/ui.qt/source/keyword.hpp b/ui.qt/source/keyword.hpp deleted file mode 100644 index bc50473..0000000 --- a/ui.qt/source/keyword.hpp +++ /dev/null @@ -1,26 +0,0 @@ -#pragma once - -#include "fwd.hpp" - -#include -#include - -class Keyword -{ -private: - QString name; - std::vector associations; - -public: - Keyword(const QString& name); - ~Keyword(); - - Keyword(const Keyword&) = default; - Keyword& operator=(const Keyword&) = default; - Keyword(Keyword&&) = default; - Keyword& operator=(Keyword&&) = default; -}; - -class KeywordDatabase -{ -}; diff --git a/ui.qt/source/knowledgefragment.cpp b/ui.qt/source/knowledgefragment.cpp deleted file mode 100644 index 4db09e7..0000000 --- a/ui.qt/source/knowledgefragment.cpp +++ /dev/null @@ -1,11 +0,0 @@ -#include "knowledgefragment.hpp" - -KnowledgeFragment::KnowledgeFragment(KnowledgeId id) - : id{ id } -{ -} - -KnowledgeId KnowledgeFragment::getId() const -{ - return id; -} diff --git a/ui.qt/source/knowledgefragment.hpp b/ui.qt/source/knowledgefragment.hpp deleted file mode 100644 index 533d99f..0000000 --- a/ui.qt/source/knowledgefragment.hpp +++ /dev/null @@ -1,38 +0,0 @@ -#pragma once - -#include "fwd.hpp" - -#include -#include -#include - -struct KnowledgeId -{ - size_t id; -}; - -class KnowledgeFragment -{ -private: - QDateTime createTime; - QDateTime modifyTime; - KnowledgeId id; - -public: - KnowledgeFragment(KnowledgeId id); - - KnowledgeId getId() const; -}; - -class KnowledgeDatabase -{ -private: - std::vector storage; - std::vector index; // Mapping from KnowledgeId (index) to `storage` index - KnowledgeId nextId; - -public: - KnowledgeId allocateFragment(); - bool deleteFragment(KnowledgeId id); - KnowledgeFragment* getFragment(KnowledgeId id); -}; diff --git a/ui.qt/source/main.cpp b/ui.qt/source/main.cpp index fab148c..863ee20 100644 --- a/ui.qt/source/main.cpp +++ b/ui.qt/source/main.cpp @@ -8,14 +8,14 @@ int main(int argc, char *argv[]) QApplication app(argc, argv); QTranslator translator; - const QStringList uiLanguages = QLocale::system().uiLanguages(); - for (const QString& locale : uiLanguages) { - const QString baseName = "EpistmoolUI_" + QLocale(locale).name(); - if (translator.load(":/i18n/" + baseName)) { + const QStringList uiLanguages = QLocale::system().uiLanguages(); + for (const QString& locale : uiLanguages) { + const QString baseName = "EpistmoolUI_" + QLocale(locale).name(); + if (translator.load(":/i18n/" + baseName)) { app.installTranslator(&translator); break; - } - } + } + } QQmlApplicationEngine engine; const QUrl url(u"qrc:/EpistmoolUI/source/qml/MainWindow.qml"_qs); -- cgit v1.2.3-70-g09d2