diff options
-rw-r--r-- | framework/CMakeLists.txt | 1 | ||||
-rw-r--r-- | framework/qml/TextEditor.qml | 14 | ||||
-rw-r--r-- | framework/qml/tests/CMakeLists.txt | 11 | ||||
-rw-r--r-- | framework/qml/tests/testrunner.cpp | 6 | ||||
-rw-r--r-- | framework/qml/tests/tst_texteditor.qml | 46 |
5 files changed, 77 insertions, 1 deletions
diff --git a/framework/CMakeLists.txt b/framework/CMakeLists.txt index 431c1ac4..af456384 100644 --- a/framework/CMakeLists.txt +++ b/framework/CMakeLists.txt | |||
@@ -8,5 +8,6 @@ install(DIRECTORY qml/ DESTINATION ${FRAMEWORK_INSTALL_DIR}) | |||
8 | install(FILES qmldir DESTINATION ${FRAMEWORK_INSTALL_DIR}) | 8 | install(FILES qmldir DESTINATION ${FRAMEWORK_INSTALL_DIR}) |
9 | 9 | ||
10 | add_subdirectory(src) | 10 | add_subdirectory(src) |
11 | add_subdirectory(qml/tests) | ||
11 | 12 | ||
12 | feature_summary(WHAT ALL FATAL_ON_MISSING_REQUIRED_PACKAGES) | 13 | feature_summary(WHAT ALL FATAL_ON_MISSING_REQUIRED_PACKAGES) |
diff --git a/framework/qml/TextEditor.qml b/framework/qml/TextEditor.qml index 570bc322..609b85db 100644 --- a/framework/qml/TextEditor.qml +++ b/framework/qml/TextEditor.qml | |||
@@ -39,6 +39,19 @@ FocusScope { | |||
39 | } | 39 | } |
40 | } | 40 | } |
41 | 41 | ||
42 | onHtmlEnabledChanged: { | ||
43 | if (htmlEnabled) { | ||
44 | var t = document.htmlText | ||
45 | edit.textFormat = Qt.RichText | ||
46 | edit.text = t | ||
47 | } else { | ||
48 | var t = document.plainText | ||
49 | edit.textFormat = Qt.PlainText | ||
50 | edit.font.bold = false | ||
51 | edit.text = t | ||
52 | } | ||
53 | } | ||
54 | |||
42 | Kube.DocumentHandler { | 55 | Kube.DocumentHandler { |
43 | id: document | 56 | id: document |
44 | document: edit.textDocument | 57 | document: edit.textDocument |
@@ -92,7 +105,6 @@ FocusScope { | |||
92 | focus: true | 105 | focus: true |
93 | selectByMouse: true | 106 | selectByMouse: true |
94 | wrapMode: TextEdit.WordWrap | 107 | wrapMode: TextEdit.WordWrap |
95 | textFormat: root.htmlEnabled ? Qt.RichText : Qt.PlainText | ||
96 | onCursorRectangleChanged: flickableItem.ensureVisible(cursorRectangle) | 108 | onCursorRectangleChanged: flickableItem.ensureVisible(cursorRectangle) |
97 | 109 | ||
98 | color: Kube.Colors.textColor | 110 | color: Kube.Colors.textColor |
diff --git a/framework/qml/tests/CMakeLists.txt b/framework/qml/tests/CMakeLists.txt new file mode 100644 index 00000000..bc34855c --- /dev/null +++ b/framework/qml/tests/CMakeLists.txt | |||
@@ -0,0 +1,11 @@ | |||
1 | |||
2 | find_package(Qt5 REQUIRED NO_MODULE COMPONENTS Quick QuickTest) | ||
3 | |||
4 | add_executable(testrunner testrunner.cpp) | ||
5 | target_link_libraries(testrunner | ||
6 | Qt5::Quick | ||
7 | Qt5::QuickTest | ||
8 | ) | ||
9 | |||
10 | add_test(NAME frameworkqmltests COMMAND testrunner WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) | ||
11 | |||
diff --git a/framework/qml/tests/testrunner.cpp b/framework/qml/tests/testrunner.cpp new file mode 100644 index 00000000..c0bee01a --- /dev/null +++ b/framework/qml/tests/testrunner.cpp | |||
@@ -0,0 +1,6 @@ | |||
1 | #include <QtQuickTest/quicktest.h> | ||
2 | |||
3 | int main(int argc, char **argv) | ||
4 | { | ||
5 | return quick_test_main(argc, argv, "example", 0); | ||
6 | } | ||
diff --git a/framework/qml/tests/tst_texteditor.qml b/framework/qml/tests/tst_texteditor.qml new file mode 100644 index 00000000..21ebe642 --- /dev/null +++ b/framework/qml/tests/tst_texteditor.qml | |||
@@ -0,0 +1,46 @@ | |||
1 | /* | ||
2 | * Copyright 2017 Christian Mollekopf <mollekopf@kolabsystems.com> | ||
3 | * | ||
4 | * This program is free software; you can redistribute it and/or modify | ||
5 | * it under the terms of the GNU Library General Public License as | ||
6 | * published by the Free Software Foundation; either version 2, or | ||
7 | * (at your option) any later version. | ||
8 | * | ||
9 | * This program is distributed in the hope that it will be useful, | ||
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | * GNU Library General Public License for more details | ||
13 | * | ||
14 | * You should have received a copy of the GNU Library General Public | ||
15 | * License along with this program; if not, write to the | ||
16 | * Free Software Foundation, Inc., | ||
17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
18 | */ | ||
19 | |||
20 | import QtQuick 2.7 | ||
21 | import QtTest 1.0 | ||
22 | import org.kube.framework 1.0 as Kube | ||
23 | |||
24 | |||
25 | TestCase { | ||
26 | id: testCase | ||
27 | width: 400 | ||
28 | height: 400 | ||
29 | name: "TextEditor" | ||
30 | |||
31 | Kube.TextEditor { | ||
32 | id: editor | ||
33 | initialText: "Foobar" | ||
34 | htmlEnabled: false | ||
35 | } | ||
36 | |||
37 | function test_1initialText() { | ||
38 | compare(editor.text, editor.initialText) | ||
39 | } | ||
40 | |||
41 | function test_2htmlConversion() { | ||
42 | editor.htmlEnabled = true | ||
43 | editor.htmlEnabled = false | ||
44 | compare(editor.text, editor.initialText) | ||
45 | } | ||
46 | } | ||