diff options
-rw-r--r-- | components/kube/contents/ui/ComposerView.qml | 41 | ||||
-rw-r--r-- | framework/qml/TextEditor.qml | 30 | ||||
-rw-r--r-- | framework/src/domain/documenthandler.cpp | 16 | ||||
-rw-r--r-- | framework/src/domain/documenthandler.h | 3 |
4 files changed, 56 insertions, 34 deletions
diff --git a/components/kube/contents/ui/ComposerView.qml b/components/kube/contents/ui/ComposerView.qml index 1571a746..29858767 100644 --- a/components/kube/contents/ui/ComposerView.qml +++ b/components/kube/contents/ui/ComposerView.qml | |||
@@ -287,24 +287,24 @@ Kube.View { | |||
287 | Kube.IconButton { | 287 | Kube.IconButton { |
288 | iconName: Kube.Icons.bold | 288 | iconName: Kube.Icons.bold |
289 | checkable: true | 289 | checkable: true |
290 | checked: document.bold | 290 | checked: textEditor.bold |
291 | onClicked: document.bold = !document.bold | 291 | onClicked: textEditor.bold = !textEditor.bold |
292 | focusPolicy: Qt.TabFocus | 292 | focusPolicy: Qt.TabFocus |
293 | focus: false | 293 | focus: false |
294 | } | 294 | } |
295 | Kube.IconButton { | 295 | Kube.IconButton { |
296 | iconName: Kube.Icons.italic | 296 | iconName: Kube.Icons.italic |
297 | checkable: true | 297 | checkable: true |
298 | checked: document.italic | 298 | checked: textEditor.italic |
299 | onClicked: document.italic = !document.italic | 299 | onClicked: textEditor.italic = !textEditor.italic |
300 | focusPolicy: Qt.TabFocus | 300 | focusPolicy: Qt.TabFocus |
301 | focus: false | 301 | focus: false |
302 | } | 302 | } |
303 | Kube.IconButton { | 303 | Kube.IconButton { |
304 | iconName: Kube.Icons.underline | 304 | iconName: Kube.Icons.underline |
305 | checkable: true | 305 | checkable: true |
306 | checked: document.underline | 306 | checked: textEditor.underline |
307 | onClicked: document.underline = !document.underline | 307 | onClicked: textEditor.underline = !textEditor.underline |
308 | focusPolicy: Qt.TabFocus | 308 | focusPolicy: Qt.TabFocus |
309 | focus: false | 309 | focus: false |
310 | } | 310 | } |
@@ -337,31 +337,24 @@ Kube.View { | |||
337 | } | 337 | } |
338 | } | 338 | } |
339 | 339 | ||
340 | Kube.DocumentHandler { | 340 | Kube.TextEditor { |
341 | id: document | ||
342 | document: textEditor.textDocument | ||
343 | cursorPosition: textEditor.cursorPosition | ||
344 | selectionStart: textEditor.selectionStart | ||
345 | selectionEnd: textEditor.selectionEnd | ||
346 | //textColor: colorDialog.color | ||
347 | } | ||
348 | |||
349 | Kube.TextArea { | ||
350 | id: textEditor | 341 | id: textEditor |
351 | 342 | ||
352 | Layout.fillWidth: true | 343 | Layout.fillWidth: true |
353 | Layout.fillHeight: true | 344 | Layout.fillHeight: true |
354 | 345 | htmlEnabled: html.checked | |
355 | textFormat: Qt.RichText | ||
356 | wrapMode: TextArea.Wrap | ||
357 | focus: true | ||
358 | selectByMouse: true | ||
359 | persistentSelection: true | ||
360 | 346 | ||
361 | onActiveFocusChanged: closeFirstSplitIfNecessary() | 347 | onActiveFocusChanged: closeFirstSplitIfNecessary() |
362 | Keys.onEscapePressed: recipients.forceActiveFocus() | 348 | Keys.onEscapePressed: recipients.forceActiveFocus() |
363 | cursorPosition: document.cursorPosition | 349 | initialText: composerController.body |
364 | text: composerController.body | 350 | /** |
351 | * We need to: | ||
352 | * * initially load the text from the controller (for replies and whatnot) | ||
353 | * * Then only read from documenthandler in either html or plain (depending on the format). | ||
354 | * * Convert between html and plain when switching the format. | ||
355 | * * Skip invisible chars | ||
356 | * * Remove invisible chars from copied text somehow | ||
357 | */ | ||
365 | onTextChanged: composerController.body = text; | 358 | onTextChanged: composerController.body = text; |
366 | } | 359 | } |
367 | } | 360 | } |
diff --git a/framework/qml/TextEditor.qml b/framework/qml/TextEditor.qml index 5f29cef3..047c9b77 100644 --- a/framework/qml/TextEditor.qml +++ b/framework/qml/TextEditor.qml | |||
@@ -23,7 +23,32 @@ import QtQuick.Controls 2.2 | |||
23 | import org.kube.framework 1.0 as Kube | 23 | import org.kube.framework 1.0 as Kube |
24 | 24 | ||
25 | FocusScope { | 25 | FocusScope { |
26 | property alias text: edit.text | 26 | id: root |
27 | property string text: "" | ||
28 | |||
29 | property bool htmlEnabled: false | ||
30 | |||
31 | property alias bold: document.bold | ||
32 | property alias italic: document.italic | ||
33 | property alias underline: document.underline | ||
34 | |||
35 | property string initialText | ||
36 | onInitialTextChanged: { | ||
37 | if (text == "") { | ||
38 | edit.text = initialText | ||
39 | } | ||
40 | } | ||
41 | |||
42 | Kube.DocumentHandler { | ||
43 | id: document | ||
44 | document: edit.textDocument | ||
45 | cursorPosition: edit.cursorPosition | ||
46 | selectionStart: edit.selectionStart | ||
47 | selectionEnd: edit.selectionEnd | ||
48 | //textColor: colorDialog.color | ||
49 | onTextChanged: root.text = text | ||
50 | } | ||
51 | |||
27 | Kube.ScrollHelper { | 52 | Kube.ScrollHelper { |
28 | anchors.fill: parent | 53 | anchors.fill: parent |
29 | flickable: flickableItem | 54 | flickable: flickableItem |
@@ -37,7 +62,10 @@ FocusScope { | |||
37 | focus: true | 62 | focus: true |
38 | anchors.fill: parent | 63 | anchors.fill: parent |
39 | selectByMouse: true | 64 | selectByMouse: true |
65 | persistentSelection: true | ||
40 | wrapMode: TextEdit.Wrap | 66 | wrapMode: TextEdit.Wrap |
67 | textFormat: Qt.RichText | ||
68 | cursorPosition: document.cursorPosition | ||
41 | } | 69 | } |
42 | TextArea.flickable: edit | 70 | TextArea.flickable: edit |
43 | } | 71 | } |
diff --git a/framework/src/domain/documenthandler.cpp b/framework/src/domain/documenthandler.cpp index 266f4a27..0f949da8 100644 --- a/framework/src/domain/documenthandler.cpp +++ b/framework/src/domain/documenthandler.cpp | |||
@@ -94,16 +94,20 @@ void DocumentHandler::setCursorPosition(int position) | |||
94 | //Skip over invisible char | 94 | //Skip over invisible char |
95 | if (m_cursorPosition < position) { | 95 | if (m_cursorPosition < position) { |
96 | auto cursor = textCursor(); | 96 | auto cursor = textCursor(); |
97 | cursor.movePosition(QTextCursor::NextCharacter, QTextCursor::KeepAnchor); | 97 | if (!cursor.atEnd()) { |
98 | if (cursor.selectedText() == "\u2063") { | 98 | cursor.movePosition(QTextCursor::NextCharacter, QTextCursor::KeepAnchor); |
99 | position++; | 99 | if (cursor.selectedText() == "\u2063") { |
100 | position++; | ||
101 | } | ||
100 | } | 102 | } |
101 | } | 103 | } |
102 | if (m_cursorPosition > position) { | 104 | if (m_cursorPosition > position) { |
103 | auto cursor = textCursor(); | 105 | auto cursor = textCursor(); |
104 | cursor.movePosition(QTextCursor::PreviousCharacter, QTextCursor::KeepAnchor); | 106 | if (!cursor.atStart()) { |
105 | if (cursor.selectedText() == "\u2063") { | 107 | cursor.movePosition(QTextCursor::PreviousCharacter, QTextCursor::KeepAnchor); |
106 | position--; | 108 | if (cursor.selectedText() == "\u2063") { |
109 | position--; | ||
110 | } | ||
107 | } | 111 | } |
108 | } | 112 | } |
109 | m_cursorPosition = position; | 113 | m_cursorPosition = position; |
diff --git a/framework/src/domain/documenthandler.h b/framework/src/domain/documenthandler.h index 74b7c4f9..24b3b35f 100644 --- a/framework/src/domain/documenthandler.h +++ b/framework/src/domain/documenthandler.h | |||
@@ -145,9 +145,6 @@ private: | |||
145 | int m_cursorPosition; | 145 | int m_cursorPosition; |
146 | int m_selectionStart; | 146 | int m_selectionStart; |
147 | int m_selectionEnd; | 147 | int m_selectionEnd; |
148 | |||
149 | QFont m_font; | ||
150 | int m_fontSize; | ||
151 | }; | 148 | }; |
152 | 149 | ||
153 | #endif // DOCUMENTHANDLER_H | 150 | #endif // DOCUMENTHANDLER_H |