diff options
Diffstat (limited to 'framework/src')
-rw-r--r-- | framework/src/domain/textdocumenthandler.cpp | 19 | ||||
-rw-r--r-- | framework/src/domain/textdocumenthandler.h | 6 |
2 files changed, 19 insertions, 6 deletions
diff --git a/framework/src/domain/textdocumenthandler.cpp b/framework/src/domain/textdocumenthandler.cpp index f0cde10d..ba0aa98f 100644 --- a/framework/src/domain/textdocumenthandler.cpp +++ b/framework/src/domain/textdocumenthandler.cpp | |||
@@ -32,7 +32,7 @@ TextDocumentHandler::TextDocumentHandler(QObject *parent) | |||
32 | { | 32 | { |
33 | } | 33 | } |
34 | 34 | ||
35 | bool TextDocumentHandler::containsFormatting() | 35 | bool TextDocumentHandler::containsFormatting() const |
36 | { | 36 | { |
37 | if (mDocument) { | 37 | if (mDocument) { |
38 | for (const auto &format : mDocument->textDocument()->allFormats()) { | 38 | for (const auto &format : mDocument->textDocument()->allFormats()) { |
@@ -62,7 +62,9 @@ bool TextDocumentHandler::containsFormatting() | |||
62 | 62 | ||
63 | void TextDocumentHandler::resetFormat() | 63 | void TextDocumentHandler::resetFormat() |
64 | { | 64 | { |
65 | mDocument->textDocument()->setPlainText(mDocument->textDocument()->toPlainText()); | 65 | if (mDocument) { |
66 | mDocument->textDocument()->setPlainText(mDocument->textDocument()->toPlainText()); | ||
67 | } | ||
66 | mCachedTextFormat = {}; | 68 | mCachedTextFormat = {}; |
67 | reset(); | 69 | reset(); |
68 | } | 70 | } |
@@ -76,12 +78,18 @@ void TextDocumentHandler::setDocument(QQuickTextDocument *document) | |||
76 | { | 78 | { |
77 | if (document != mDocument) { | 79 | if (document != mDocument) { |
78 | mDocument = document; | 80 | mDocument = document; |
79 | connect(mDocument->textDocument(), &QTextDocument::contentsChanged, this, [this] () { | ||
80 | emit textChanged(); | ||
81 | }); | ||
82 | connect(mDocument->textDocument(), &QTextDocument::contentsChange, this, &TextDocumentHandler::contentsChange); | 81 | connect(mDocument->textDocument(), &QTextDocument::contentsChange, this, &TextDocumentHandler::contentsChange); |
83 | emit documentChanged(); | 82 | emit documentChanged(); |
83 | emit textChanged(); | ||
84 | } | ||
85 | } | ||
86 | |||
87 | QString TextDocumentHandler::text() const | ||
88 | { | ||
89 | if (containsFormatting()) { | ||
90 | return htmlText(); | ||
84 | } | 91 | } |
92 | return plainText(); | ||
85 | } | 93 | } |
86 | 94 | ||
87 | QString TextDocumentHandler::plainText() const | 95 | QString TextDocumentHandler::plainText() const |
@@ -296,6 +304,7 @@ void TextDocumentHandler::contentsChange(int position, int charsRemoved, int cha | |||
296 | } | 304 | } |
297 | mCachedTextFormat = {}; | 305 | mCachedTextFormat = {}; |
298 | } | 306 | } |
307 | emit textChanged(); | ||
299 | } | 308 | } |
300 | 309 | ||
301 | void TextDocumentHandler::mergeFormatOnWordOrSelection(const QTextCharFormat &format) | 310 | void TextDocumentHandler::mergeFormatOnWordOrSelection(const QTextCharFormat &format) |
diff --git a/framework/src/domain/textdocumenthandler.h b/framework/src/domain/textdocumenthandler.h index cb4d4e29..e5fe705b 100644 --- a/framework/src/domain/textdocumenthandler.h +++ b/framework/src/domain/textdocumenthandler.h | |||
@@ -41,9 +41,11 @@ class KUBE_EXPORT TextDocumentHandler : public QObject | |||
41 | Q_PROPERTY(bool bold READ bold WRITE setBold NOTIFY boldChanged) | 41 | Q_PROPERTY(bool bold READ bold WRITE setBold NOTIFY boldChanged) |
42 | Q_PROPERTY(bool italic READ italic WRITE setItalic NOTIFY italicChanged) | 42 | Q_PROPERTY(bool italic READ italic WRITE setItalic NOTIFY italicChanged) |
43 | Q_PROPERTY(bool underline READ underline WRITE setUnderline NOTIFY underlineChanged) | 43 | Q_PROPERTY(bool underline READ underline WRITE setUnderline NOTIFY underlineChanged) |
44 | Q_PROPERTY(bool containsFormatting READ containsFormatting NOTIFY textChanged) | ||
44 | 45 | ||
45 | Q_PROPERTY(int fontSize READ fontSize WRITE setFontSize NOTIFY fontSizeChanged) | 46 | Q_PROPERTY(int fontSize READ fontSize WRITE setFontSize NOTIFY fontSizeChanged) |
46 | 47 | ||
48 | Q_PROPERTY(QString text READ text NOTIFY textChanged) | ||
47 | Q_PROPERTY(QString plainText READ plainText NOTIFY textChanged) | 49 | Q_PROPERTY(QString plainText READ plainText NOTIFY textChanged) |
48 | Q_PROPERTY(QString htmlText READ htmlText NOTIFY textChanged) | 50 | Q_PROPERTY(QString htmlText READ htmlText NOTIFY textChanged) |
49 | 51 | ||
@@ -53,9 +55,12 @@ public: | |||
53 | QQuickTextDocument *document() const; | 55 | QQuickTextDocument *document() const; |
54 | void setDocument(QQuickTextDocument *document); | 56 | void setDocument(QQuickTextDocument *document); |
55 | 57 | ||
58 | QString text() const; | ||
56 | QString plainText() const; | 59 | QString plainText() const; |
57 | QString htmlText() const; | 60 | QString htmlText() const; |
58 | 61 | ||
62 | bool containsFormatting() const; | ||
63 | |||
59 | int cursorPosition() const; | 64 | int cursorPosition() const; |
60 | void setCursorPosition(int position); | 65 | void setCursorPosition(int position); |
61 | 66 | ||
@@ -87,7 +92,6 @@ public: | |||
87 | void setFontSize(int size); | 92 | void setFontSize(int size); |
88 | 93 | ||
89 | Q_INVOKABLE void resetFormat(); | 94 | Q_INVOKABLE void resetFormat(); |
90 | Q_INVOKABLE bool containsFormatting(); | ||
91 | 95 | ||
92 | Q_INVOKABLE static bool isHtml(const QString &); | 96 | Q_INVOKABLE static bool isHtml(const QString &); |
93 | 97 | ||