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/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 +-- 18 files changed, 342 insertions(+), 318 deletions(-) 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/source') 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