diff options
author | rtk0c <[email protected]> | 2022-06-27 00:14:58 +0000 |
---|---|---|
committer | rtk0c <[email protected]> | 2022-06-27 00:14:58 +0000 |
commit | 3250fc72f906797f113855cf9dde4e7803a66bd9 (patch) | |
tree | 2e270e38e6578738ffd9e91b7d5aaa9b4db545cb /ui.qt/source/Document.hpp | |
parent | 8a23aa89a58d3a90d5851b449b5552e1fcdcaded (diff) |
(From git) Reformat qt ui project
git-svn-id: file:///home/arch/svn/epistmool/trunk@5 71f44415-077c-4ad7-a976-72ddbf76608f
Diffstat (limited to 'ui.qt/source/Document.hpp')
-rw-r--r-- | ui.qt/source/Document.hpp | 72 |
1 files changed, 72 insertions, 0 deletions
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 <QAbstractItemModel> +#include <QDateTime> +#include <QObject> +#include <QQuickTextDocument> +#include <QTextCharFormat> + +// 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); +}; |