aboutsummaryrefslogtreecommitdiff
path: root/ui.qt/source/document.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'ui.qt/source/document.hpp')
-rw-r--r--ui.qt/source/document.hpp68
1 files changed, 39 insertions, 29 deletions
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 <QDateTime>
#include <QObject>
#include <QQuickTextDocument>
+#include <QTextCharFormat>
-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<DocumentBlock*> 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<int, QByteArray> roleNames() const override;
+private:
+ QTextCursor makeTextCursor() const;
+ void mergeFormatOnWordOrSelection(const QTextCharFormat& format);
};