summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2017-09-13 11:12:30 +0200
committerChristian Mollekopf <chrigi_1@fastmail.fm>2017-09-13 11:12:30 +0200
commit5e9d12d1d9793afe0099fc8b68eeae1b8bbe8098 (patch)
treef6e8e526e82885ee7d50878d9b43c6907e73baa8
parent8edb362d96ed740cf5f387649d760c17c7c17d31 (diff)
downloadkube-5e9d12d1d9793afe0099fc8b68eeae1b8bbe8098.tar.gz
kube-5e9d12d1d9793afe0099fc8b68eeae1b8bbe8098.zip
Extract html or plaintext depending on setting
-rw-r--r--framework/qml/TextEditor.qml2
-rw-r--r--framework/src/domain/documenthandler.cpp26
-rw-r--r--framework/src/domain/documenthandler.h6
3 files changed, 33 insertions, 1 deletions
diff --git a/framework/qml/TextEditor.qml b/framework/qml/TextEditor.qml
index 047c9b77..8a298989 100644
--- a/framework/qml/TextEditor.qml
+++ b/framework/qml/TextEditor.qml
@@ -46,7 +46,7 @@ FocusScope {
46 selectionStart: edit.selectionStart 46 selectionStart: edit.selectionStart
47 selectionEnd: edit.selectionEnd 47 selectionEnd: edit.selectionEnd
48 //textColor: colorDialog.color 48 //textColor: colorDialog.color
49 onTextChanged: root.text = text 49 onTextChanged: root.htmlEnabled ? root.text = htmlText : root.text = plainText
50 } 50 }
51 51
52 Kube.ScrollHelper { 52 Kube.ScrollHelper {
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