summaryrefslogtreecommitdiffstats
path: root/framework/src
diff options
context:
space:
mode:
Diffstat (limited to 'framework/src')
-rw-r--r--framework/src/domain/documenthandler.cpp26
-rw-r--r--framework/src/domain/documenthandler.h6
2 files changed, 32 insertions, 0 deletions
diff --git a/framework/src/domain/documenthandler.cpp b/framework/src/domain/documenthandler.cpp
index 0f949da8..3589fc9f 100644
--- a/framework/src/domain/documenthandler.cpp
+++ b/framework/src/domain/documenthandler.cpp
@@ -79,10 +79,36 @@ void DocumentHandler::setDocument(QQuickTextDocument *document)
79{ 79{
80 if (document != m_document) { 80 if (document != m_document) {
81 m_document = document; 81 m_document = document;
82 connect(m_document->textDocument(), &QTextDocument::contentsChanged, this, [this] () {
83 emit textChanged();
84 });
82 emit documentChanged(); 85 emit documentChanged();
83 } 86 }
84} 87}
85 88
89static QString stripInvisibleChars(const QString &s)
90{
91 auto text = s;
92 text.replace("\u2063", "");
93 return text;
94}
95
96QString DocumentHandler::plainText() const
97{
98 if (m_document) {
99 return stripInvisibleChars(m_document->textDocument()->toPlainText());
100 }
101 return {};
102}
103
104QString DocumentHandler::htmlText() const
105{
106 if (m_document) {
107 return stripInvisibleChars(m_document->textDocument()->toHtml());
108 }
109 return {};
110}
111
86int DocumentHandler::cursorPosition() const 112int DocumentHandler::cursorPosition() const
87{ 113{
88 return m_cursorPosition; 114 return m_cursorPosition;
diff --git a/framework/src/domain/documenthandler.h b/framework/src/domain/documenthandler.h
index 24b3b35f..0c1bf971 100644
--- a/framework/src/domain/documenthandler.h
+++ b/framework/src/domain/documenthandler.h
@@ -80,12 +80,18 @@ class DocumentHandler : public QObject
80 80
81 Q_PROPERTY(int fontSize READ fontSize WRITE setFontSize NOTIFY fontSizeChanged) 81 Q_PROPERTY(int fontSize READ fontSize WRITE setFontSize NOTIFY fontSizeChanged)
82 82
83 Q_PROPERTY(QString plainText READ plainText NOTIFY textChanged)
84 Q_PROPERTY(QString htmlText READ htmlText NOTIFY textChanged)
85
83public: 86public:
84 explicit DocumentHandler(QObject *parent = nullptr); 87 explicit DocumentHandler(QObject *parent = nullptr);
85 88
86 QQuickTextDocument *document() const; 89 QQuickTextDocument *document() const;
87 void setDocument(QQuickTextDocument *document); 90 void setDocument(QQuickTextDocument *document);
88 91
92 QString plainText() const;
93 QString htmlText() const;
94
89 int cursorPosition() const; 95 int cursorPosition() const;
90 void setCursorPosition(int position); 96 void setCursorPosition(int position);
91 97