From 9ad9af9f2596b91e1dd65e71543f75b0644e8283 Mon Sep 17 00:00:00 2001 From: rtk0c Date: Mon, 27 Jun 2022 00:10:58 +0000 Subject: (From git) Initial GUI setup for text document git-svn-id: file:///home/arch/svn/epistmool/trunk@3 71f44415-077c-4ad7-a976-72ddbf76608f --- ui.qt/source/document.hpp | 68 +++++++++++++++++++++++++++-------------------- 1 file changed, 39 insertions(+), 29 deletions(-) (limited to 'ui.qt/source/document.hpp') diff --git a/ui.qt/source/document.hpp b/ui.qt/source/document.hpp index ba11e26..5ef1bba 100644 --- a/ui.qt/source/document.hpp +++ b/ui.qt/source/document.hpp @@ -6,57 +6,67 @@ #include #include #include +#include -class DocumentBlock : public QObject +// To be instanciated in QML as the logic backend to some TextArea +class DocumentHandler : public QObject { Q_OBJECT QML_ELEMENT - Q_PROPERTY(QQuickTextDocument* textDocument READ getDoc WRITE setDoc NOTIFY docChanged) + 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: - DocumentModel* mModel; QQuickTextDocument* mDoc = nullptr; QDateTime mModifyTime; -public: - explicit DocumentBlock(QObject* parent = nullptr); + int mCursorPos; + int mSelectionBegin; + int mSelectionEnd; - DocumentModel* getModel() const; - void setModel(DocumentModel* newModel); +public: + explicit DocumentHandler(QObject* parent = nullptr); QQuickTextDocument* getDoc() const; void setDoc(QQuickTextDocument* newDoc); const QDateTime& getModifyTime() const; -signals: - void docChanged(); - void modificationChanged(); -}; + int getCursorPos() const; + void setCursorPos(int newCursorPos); -class DocumentModel : public QAbstractItemModel -{ - Q_OBJECT - QML_ELEMENT + int getSelectionBegin() const; + void setSelectionBegin(int newSelectionBegin); -private: - std::vector mBlocks; + int getSelectionEnd() const; + void setSelectionEnd(int newSelectionEnd); -public: - enum DocumentRoles { - ModifyTimeRole = Qt::UserRole + 1, - }; + QFont getActiveFont() const; + void setActiveFont(const QFont& font); - DocumentModel(QObject* parent = nullptr); + QColor getActiveTextColor() const; + void setActiveTextColor(const QColor& color); - void appendBlock(DocumentBlock* block); - // TODO - // void moveBlock() +signals: + void docChanged(QQuickTextDocument* oldDoc); + void modificationChanged(); // Redirected from the currently bound document + + void cursorPosChanged(); + void selectionBeginChanged(); + void selectionEndChanged(); - int rowCount(const QModelIndex& parent = QModelIndex()) const override; - QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override; + void activeFontChanged(); + void activeTextColorChanged(); -protected: - QHash roleNames() const override; +private: + QTextCursor makeTextCursor() const; + void mergeFormatOnWordOrSelection(const QTextCharFormat& format); }; -- cgit v1.2.3-70-g09d2