summaryrefslogtreecommitdiff
path: root/examples/quickcontrols/controls/texteditor
diff options
context:
space:
mode:
Diffstat (limited to 'examples/quickcontrols/controls/texteditor')
-rw-r--r--examples/quickcontrols/controls/texteditor/example.html79
-rw-r--r--examples/quickcontrols/controls/texteditor/qml/ToolBarSeparator.qml61
-rw-r--r--examples/quickcontrols/controls/texteditor/qml/images/editcopy.pngbin0 -> 1468 bytes
-rw-r--r--examples/quickcontrols/controls/texteditor/qml/images/editcut.pngbin0 -> 1512 bytes
-rw-r--r--examples/quickcontrols/controls/texteditor/qml/images/editpaste.pngbin0 -> 1906 bytes
-rw-r--r--examples/quickcontrols/controls/texteditor/qml/images/editredo.pngbin0 -> 1752 bytes
-rw-r--r--examples/quickcontrols/controls/texteditor/qml/images/editundo.pngbin0 -> 1746 bytes
-rw-r--r--examples/quickcontrols/controls/texteditor/qml/images/exportpdf.pngbin0 -> 1215 bytes
-rw-r--r--examples/quickcontrols/controls/texteditor/qml/images/filenew.pngbin0 -> 1172 bytes
-rw-r--r--examples/quickcontrols/controls/texteditor/qml/images/fileopen.pngbin0 -> 2168 bytes
-rw-r--r--examples/quickcontrols/controls/texteditor/qml/images/fileprint.pngbin0 -> 2087 bytes
-rw-r--r--examples/quickcontrols/controls/texteditor/qml/images/filesave.pngbin0 -> 1206 bytes
-rw-r--r--examples/quickcontrols/controls/texteditor/qml/images/qt-logo.pngbin0 -> 3531 bytes
-rw-r--r--examples/quickcontrols/controls/texteditor/qml/images/textbold.pngbin0 -> 1611 bytes
-rw-r--r--examples/quickcontrols/controls/texteditor/qml/images/textcenter.pngbin0 -> 1404 bytes
-rw-r--r--examples/quickcontrols/controls/texteditor/qml/images/textitalic.pngbin0 -> 1164 bytes
-rw-r--r--examples/quickcontrols/controls/texteditor/qml/images/textjustify.pngbin0 -> 1257 bytes
-rw-r--r--examples/quickcontrols/controls/texteditor/qml/images/textleft.pngbin0 -> 1235 bytes
-rw-r--r--examples/quickcontrols/controls/texteditor/qml/images/textright.pngbin0 -> 1406 bytes
-rw-r--r--examples/quickcontrols/controls/texteditor/qml/images/textunder.pngbin0 -> 1183 bytes
-rw-r--r--examples/quickcontrols/controls/texteditor/qml/images/zoomin.pngbin0 -> 1696 bytes
-rw-r--r--examples/quickcontrols/controls/texteditor/qml/images/zoomout.pngbin0 -> 1662 bytes
-rw-r--r--examples/quickcontrols/controls/texteditor/qml/main.qml357
-rw-r--r--examples/quickcontrols/controls/texteditor/resources.qrc27
-rw-r--r--examples/quickcontrols/controls/texteditor/src/documenthandler.cpp335
-rw-r--r--examples/quickcontrols/controls/texteditor/src/documenthandler.h171
-rw-r--r--examples/quickcontrols/controls/texteditor/src/main.cpp53
-rw-r--r--examples/quickcontrols/controls/texteditor/src/src.pri9
-rw-r--r--examples/quickcontrols/controls/texteditor/texteditor.pro16
29 files changed, 1108 insertions, 0 deletions
diff --git a/examples/quickcontrols/controls/texteditor/example.html b/examples/quickcontrols/controls/texteditor/example.html
new file mode 100644
index 00000000..52bb507a
--- /dev/null
+++ b/examples/quickcontrols/controls/texteditor/example.html
@@ -0,0 +1,79 @@
+<html><head><meta name="qrichtext" content="1" /><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>TextArea Example</title><style type="text/css">
+p, li { white-space: pre-wrap; }
+</style></head><body style=" font-size:9pt; font-weight:400; font-style:normal; text-decoration:none;">
+<p align="center" style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:20pt; font-weight:600;">TextArea</span></p>
+<p align="justify" style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:11pt;">The TextArea control is an advanced editor that supports formatted rich text. It can be used to display HTML and other rich document formats. Internally, TextArea uses the QQuickTextDocument class to describe both the high-level structure of each document and the low-level formatting of paragraphs.</span></p>
+<p align="justify" style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:11pt;">If you are viewing this document in the <span style=" font-style:italic;">Text Editor</span> example, you can edit this document to explore Qt's rich text editing features. We have included some comments in each of the following sections to encourage you to experiment. </p>
+<p style=" margin-top:16px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:18pt; font-weight:600;"><span style=" font-size:16pt;">Font and Paragraph Styles</span></p>
+<p align="justify" style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:11pt;">TextArea supports </span><span style=" font-size:11pt; font-weight:600;">bold</span><span style=" font-size:11pt;">, </span><span style=" font-size:11pt; font-style:italic;">italic</span><span style=" font-size:11pt;">, and </span><span style=" font-size:11pt; text-decoration: underline;">underlined</span><span style=" font-size:11pt;"> font styles, and can display </span><span style=" font-size:11pt; font-weight:600; color:#00007f;">multicolored</span>
+<span style=" font-size:11pt;"> </span><span style=" font-size:11pt; font-weight:600; color:#aa0000;">text</span><span style=" font-size:11pt;">. Font families such as</span><span style=" font-family:'Helvetica'; font-size:11pt; font-weight:600;"> Helvetica</span><span style=" font-size:11pt;"> and
+</span><span style=" font-family:'Courier'; font-size:11pt; font-weight:600;"> Courier</span><span style=" font-size:11pt;"> can also be used directly.<span style=" font-size:11pt; font-style:italic;"> If you place the cursor in a region of styled text, the corresponding controls in the tool bar will change to reflect the current style, font size and color.</span></p>
+<p align="justify" style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:11pt;">Paragraphs can be formatted so that the text is left-aligned, right-aligned, centered, or fully justified.</p>
+<p align="center" style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:11pt;"><span style=" font-style:italic;">Try changing the alignment of some text and resize the editor to see how the text layout changes.</span> </p>
+<p align="justify" style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:16pt; font-weight:600;">Lists</span></p>
+<p align="justify" style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:16pt; font-weight:600;"><span style=" font-size:11pt; font-weight:400;">Different kinds of lists can be included in rich text documents. Standard bullet lists can be nested, using different symbols for each level of the list: </span></p>
+<ul style="-qt-list-indent: 1;"><li style=" font-size:11pt;" style=" margin-top:0px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Disc symbols are typically used for top-level list items. </li></ul>
+<ul type=circle style="-qt-list-indent: 2;"><li style=" font-size:11pt;" style=" margin-top:0px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Circle symbols can be used to distinguish between items in lower-level lists.</li></ul>
+<ul type=square style="-qt-list-indent: 3;"><li style=" font-size:11pt;" style=" margin-top:0px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Square symbols provide a reasonable alternative to discs and circles. </li></ul>
+<p style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:11pt;">Ordered lists can be used for tables of contents. Different characters can be used to enumerate items, and one can use both Roman and Arabic numerals in the same list structure: </p>
+<ol style="-qt-list-indent: 1;"><li style=" font-size:11pt;" style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Introduction</li>
+<li style=" font-size:11pt;" style=" margin-top:0px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Qt Tools </li></ol>
+<ol type=a style="-qt-list-indent: 2;"><li style=" font-size:11pt;" style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Qt Assistant</li>
+<li style=" font-size:11pt;" style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Qt Designer</li>
+<ol type=A style="-qt-list-indent: 3;"><li style=" font-size:11pt;" style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Form Editor</li>
+<li style=" font-size:11pt;" style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Component Architecture</li></ol>
+<li style=" font-size:11pt;" style=" margin-top:0px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Qt Linguist</li></ol>
+<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:11pt;"></p>
+<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:11pt;">The list will automatically be renumbered if you add or remove items. <span style=" font-style:italic;">Try adding new sections to the above list or removing existing item to see the numbers change.</span> </p>
+<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:11pt;"></p>
+<p style=" margin-top:0px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:11pt;"><span style=" font-size:16pt; font-weight:600;">Images</span></p>
+<p style=" margin-top:0px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:16pt; font-weight:600;"><span style=" font-size:11pt; font-weight:400;">Inline images are treated like ordinary ranges of characters in the text editor, so they flow with the surrounding text. Images can also be selected in the same way as text, making it easy to cut, copy, and paste them. </span></p>
+<p align="justify" style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:11pt;"><img src="qrc:qml/images/qt-logo.png" /><span style=" font-style:italic;"> Try to select this image by clicking and dragging over it with the mouse, or use the text cursor to select it by holding down Shift and using the arrow keys. You can then cut or copy it, and paste it into different parts of this document.</span></p>
+<p align="justify" style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:11pt;"><span style=" font-size:16pt; font-weight:600;">Tables</span></p>
+<p align="justify" style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:16pt; font-weight:600;"><span style=" font-size:11pt; font-weight:400;">TextArea can arrange and format tables, supporting features such as row and column spans, text formatting within cells, and size constraints for columns. </span></p>
+<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:11pt;"></p>
+<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:11pt;"></p>
+<table border="1" align="center" width="90%" cellspacing="0" cellpadding="4">
+<tr>
+<td>
+<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"> </p></td>
+<td>
+<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-weight:600;">Development Tools </span></p></td>
+<td>
+<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-weight:600;">Programming Techniques </span></p></td>
+<td>
+<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-weight:600;">Graphical User Interfaces </span></p></td></tr>
+<tr>
+<td>
+<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-weight:600;">9:00 - 11:00 </span></p></td>
+<td colspan="3">
+<p align="center" style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Introduction to <span style=" font-style:italic;">Qt </span></p></td></tr>
+<tr>
+<td>
+<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-weight:600;">11:00 - 13:00 </span></p></td>
+<td>
+<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Using <span style=" font-style:italic;">qmake</span> </p></td>
+<td>
+<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Object-oriented Programming </p></td>
+<td>
+<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Layouts in <span style=" font-style:italic;">Qt</span> </p></td></tr>
+<tr>
+<td>
+<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-weight:600;">13:00 - 15:00 </span></p></td>
+<td>
+<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-style:italic;">Qt Designer</span> Tutorial </p></td>
+<td rowspan="2">
+<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Extreme Programming </p></td>
+<td>
+<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Writing Custom Styles </p></td></tr>
+<tr>
+<td>
+<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-weight:600;">15:00 - 17:00 </span></p></td>
+<td>
+<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-style:italic;">Qt Linguist</span> and Internationalization </p></td>
+<td></td></tr></table>
+<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:11pt;"></p>
+<p style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:11pt; font-style:italic;">Try adding text to the cells in the table and experiment with the alignment of the paragraphs.</p>
+<p style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:11pt;"><span style=" font-size:16pt; font-weight:600;">Undo and Redo</span></p>
+<p style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:11pt;">Full support for undo and redo operations is built into TextArea and the underlying rich text framework. Operations on a document can be packaged together to make editing easier for the user.</p>
+<p style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:11pt;"><span style=" font-style:italic;">Try making changes to this document and press Ctrl+Z to undo them. You can always recover the original contents of the document.</span> </p></body></html>
diff --git a/examples/quickcontrols/controls/texteditor/qml/ToolBarSeparator.qml b/examples/quickcontrols/controls/texteditor/qml/ToolBarSeparator.qml
new file mode 100644
index 00000000..a225e2ea
--- /dev/null
+++ b/examples/quickcontrols/controls/texteditor/qml/ToolBarSeparator.qml
@@ -0,0 +1,61 @@
+/****************************************************************************
+**
+** Copyright (C) 2015 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of The Qt Company Ltd nor the names of its
+** contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+import QtQuick 2.2
+
+Item {
+ width: 8
+ anchors.top: parent.top
+ anchors.bottom: parent.bottom
+ anchors.margins: 6
+ Rectangle {
+ width: 1
+ height: parent.height
+ anchors.horizontalCenter: parent.horizontalCenter
+ color: "#22000000"
+ }
+ Rectangle {
+ width: 1
+ height: parent.height
+ anchors.horizontalCenterOffset: 1
+ anchors.horizontalCenter: parent.horizontalCenter
+ color: "#33ffffff"
+ }
+}
diff --git a/examples/quickcontrols/controls/texteditor/qml/images/editcopy.png b/examples/quickcontrols/controls/texteditor/qml/images/editcopy.png
new file mode 100644
index 00000000..f5513644
--- /dev/null
+++ b/examples/quickcontrols/controls/texteditor/qml/images/editcopy.png
Binary files differ
diff --git a/examples/quickcontrols/controls/texteditor/qml/images/editcut.png b/examples/quickcontrols/controls/texteditor/qml/images/editcut.png
new file mode 100644
index 00000000..a784fd57
--- /dev/null
+++ b/examples/quickcontrols/controls/texteditor/qml/images/editcut.png
Binary files differ
diff --git a/examples/quickcontrols/controls/texteditor/qml/images/editpaste.png b/examples/quickcontrols/controls/texteditor/qml/images/editpaste.png
new file mode 100644
index 00000000..64c0b2d6
--- /dev/null
+++ b/examples/quickcontrols/controls/texteditor/qml/images/editpaste.png
Binary files differ
diff --git a/examples/quickcontrols/controls/texteditor/qml/images/editredo.png b/examples/quickcontrols/controls/texteditor/qml/images/editredo.png
new file mode 100644
index 00000000..8875bf24
--- /dev/null
+++ b/examples/quickcontrols/controls/texteditor/qml/images/editredo.png
Binary files differ
diff --git a/examples/quickcontrols/controls/texteditor/qml/images/editundo.png b/examples/quickcontrols/controls/texteditor/qml/images/editundo.png
new file mode 100644
index 00000000..a3bd5e0b
--- /dev/null
+++ b/examples/quickcontrols/controls/texteditor/qml/images/editundo.png
Binary files differ
diff --git a/examples/quickcontrols/controls/texteditor/qml/images/exportpdf.png b/examples/quickcontrols/controls/texteditor/qml/images/exportpdf.png
new file mode 100644
index 00000000..ebb44e6b
--- /dev/null
+++ b/examples/quickcontrols/controls/texteditor/qml/images/exportpdf.png
Binary files differ
diff --git a/examples/quickcontrols/controls/texteditor/qml/images/filenew.png b/examples/quickcontrols/controls/texteditor/qml/images/filenew.png
new file mode 100644
index 00000000..d3882c7b
--- /dev/null
+++ b/examples/quickcontrols/controls/texteditor/qml/images/filenew.png
Binary files differ
diff --git a/examples/quickcontrols/controls/texteditor/qml/images/fileopen.png b/examples/quickcontrols/controls/texteditor/qml/images/fileopen.png
new file mode 100644
index 00000000..fc06c5ec
--- /dev/null
+++ b/examples/quickcontrols/controls/texteditor/qml/images/fileopen.png
Binary files differ
diff --git a/examples/quickcontrols/controls/texteditor/qml/images/fileprint.png b/examples/quickcontrols/controls/texteditor/qml/images/fileprint.png
new file mode 100644
index 00000000..10ca56c8
--- /dev/null
+++ b/examples/quickcontrols/controls/texteditor/qml/images/fileprint.png
Binary files differ
diff --git a/examples/quickcontrols/controls/texteditor/qml/images/filesave.png b/examples/quickcontrols/controls/texteditor/qml/images/filesave.png
new file mode 100644
index 00000000..b41ecf53
--- /dev/null
+++ b/examples/quickcontrols/controls/texteditor/qml/images/filesave.png
Binary files differ
diff --git a/examples/quickcontrols/controls/texteditor/qml/images/qt-logo.png b/examples/quickcontrols/controls/texteditor/qml/images/qt-logo.png
new file mode 100644
index 00000000..be1bb106
--- /dev/null
+++ b/examples/quickcontrols/controls/texteditor/qml/images/qt-logo.png
Binary files differ
diff --git a/examples/quickcontrols/controls/texteditor/qml/images/textbold.png b/examples/quickcontrols/controls/texteditor/qml/images/textbold.png
new file mode 100644
index 00000000..38400bd1
--- /dev/null
+++ b/examples/quickcontrols/controls/texteditor/qml/images/textbold.png
Binary files differ
diff --git a/examples/quickcontrols/controls/texteditor/qml/images/textcenter.png b/examples/quickcontrols/controls/texteditor/qml/images/textcenter.png
new file mode 100644
index 00000000..2ef5b2ee
--- /dev/null
+++ b/examples/quickcontrols/controls/texteditor/qml/images/textcenter.png
Binary files differ
diff --git a/examples/quickcontrols/controls/texteditor/qml/images/textitalic.png b/examples/quickcontrols/controls/texteditor/qml/images/textitalic.png
new file mode 100644
index 00000000..0170ee26
--- /dev/null
+++ b/examples/quickcontrols/controls/texteditor/qml/images/textitalic.png
Binary files differ
diff --git a/examples/quickcontrols/controls/texteditor/qml/images/textjustify.png b/examples/quickcontrols/controls/texteditor/qml/images/textjustify.png
new file mode 100644
index 00000000..39cd6c1a
--- /dev/null
+++ b/examples/quickcontrols/controls/texteditor/qml/images/textjustify.png
Binary files differ
diff --git a/examples/quickcontrols/controls/texteditor/qml/images/textleft.png b/examples/quickcontrols/controls/texteditor/qml/images/textleft.png
new file mode 100644
index 00000000..83a66d55
--- /dev/null
+++ b/examples/quickcontrols/controls/texteditor/qml/images/textleft.png
Binary files differ
diff --git a/examples/quickcontrols/controls/texteditor/qml/images/textright.png b/examples/quickcontrols/controls/texteditor/qml/images/textright.png
new file mode 100644
index 00000000..e7c04645
--- /dev/null
+++ b/examples/quickcontrols/controls/texteditor/qml/images/textright.png
Binary files differ
diff --git a/examples/quickcontrols/controls/texteditor/qml/images/textunder.png b/examples/quickcontrols/controls/texteditor/qml/images/textunder.png
new file mode 100644
index 00000000..968bac5e
--- /dev/null
+++ b/examples/quickcontrols/controls/texteditor/qml/images/textunder.png
Binary files differ
diff --git a/examples/quickcontrols/controls/texteditor/qml/images/zoomin.png b/examples/quickcontrols/controls/texteditor/qml/images/zoomin.png
new file mode 100644
index 00000000..d46f5aff
--- /dev/null
+++ b/examples/quickcontrols/controls/texteditor/qml/images/zoomin.png
Binary files differ
diff --git a/examples/quickcontrols/controls/texteditor/qml/images/zoomout.png b/examples/quickcontrols/controls/texteditor/qml/images/zoomout.png
new file mode 100644
index 00000000..46326566
--- /dev/null
+++ b/examples/quickcontrols/controls/texteditor/qml/images/zoomout.png
Binary files differ
diff --git a/examples/quickcontrols/controls/texteditor/qml/main.qml b/examples/quickcontrols/controls/texteditor/qml/main.qml
new file mode 100644
index 00000000..42f5e7f9
--- /dev/null
+++ b/examples/quickcontrols/controls/texteditor/qml/main.qml
@@ -0,0 +1,357 @@
+/****************************************************************************
+**
+** Copyright (C) 2015 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of The Qt Company Ltd nor the names of its
+** contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+import QtQuick 2.2
+import QtQuick.Controls 1.2
+import QtQuick.Layouts 1.0
+import QtQuick.Dialogs 1.1
+import QtQuick.Window 2.1
+import org.qtproject.example 1.0
+
+ApplicationWindow {
+ visible: true
+ width: 640
+ height: 480
+ minimumWidth: 400
+ minimumHeight: 300
+
+ title: document.documentTitle + " - Text Editor Example"
+
+ MessageDialog {
+ id: aboutBox
+ title: "About Text"
+ text: "This is a basic text editor \nwritten with Qt Quick Controls"
+ icon: StandardIcon.Information
+ }
+
+ Action {
+ id: cutAction
+ text: "Cut"
+ shortcut: "ctrl+x"
+ iconSource: "images/editcut.png"
+ iconName: "edit-cut"
+ onTriggered: textArea.cut()
+ }
+
+ Action {
+ id: copyAction
+ text: "Copy"
+ shortcut: "Ctrl+C"
+ iconSource: "images/editcopy.png"
+ iconName: "edit-copy"
+ onTriggered: textArea.copy()
+ }
+
+ Action {
+ id: pasteAction
+ text: "Paste"
+ shortcut: "ctrl+v"
+ iconSource: "qrc:images/editpaste.png"
+ iconName: "edit-paste"
+ onTriggered: textArea.paste()
+ }
+
+ Action {
+ id: alignLeftAction
+ text: "&Left"
+ iconSource: "images/textleft.png"
+ iconName: "format-justify-left"
+ shortcut: "ctrl+l"
+ onTriggered: document.alignment = Qt.AlignLeft
+ checkable: true
+ checked: document.alignment == Qt.AlignLeft
+ }
+ Action {
+ id: alignCenterAction
+ text: "C&enter"
+ iconSource: "images/textcenter.png"
+ iconName: "format-justify-center"
+ onTriggered: document.alignment = Qt.AlignHCenter
+ checkable: true
+ checked: document.alignment == Qt.AlignHCenter
+ }
+ Action {
+ id: alignRightAction
+ text: "&Right"
+ iconSource: "images/textright.png"
+ iconName: "format-justify-right"
+ onTriggered: document.alignment = Qt.AlignRight
+ checkable: true
+ checked: document.alignment == Qt.AlignRight
+ }
+ Action {
+ id: alignJustifyAction
+ text: "&Justify"
+ iconSource: "images/textjustify.png"
+ iconName: "format-justify-fill"
+ onTriggered: document.alignment = Qt.AlignJustify
+ checkable: true
+ checked: document.alignment == Qt.AlignJustify
+ }
+
+ Action {
+ id: boldAction
+ text: "&Bold"
+ iconSource: "images/textbold.png"
+ iconName: "format-text-bold"
+ onTriggered: document.bold = !document.bold
+ checkable: true
+ checked: document.bold
+ }
+
+ Action {
+ id: italicAction
+ text: "&Italic"
+ iconSource: "images/textitalic.png"
+ iconName: "format-text-italic"
+ onTriggered: document.italic = !document.italic
+ checkable: true
+ checked: document.italic
+ }
+ Action {
+ id: underlineAction
+ text: "&Underline"
+ iconSource: "images/textunder.png"
+ iconName: "format-text-underline"
+ onTriggered: document.underline = !document.underline
+ checkable: true
+ checked: document.underline
+ }
+
+ FileDialog {
+ id: fileDialog
+ nameFilters: ["Text files (*.txt)", "HTML files (*.html, *.htm)"]
+ onAccepted: {
+ if (fileDialog.selectExisting)
+ document.fileUrl = fileUrl
+ else
+ document.saveAs(fileUrl, selectedNameFilter)
+ }
+ }
+
+ ColorDialog {
+ id: colorDialog
+ color: "black"
+ }
+
+ Action {
+ id: fileOpenAction
+ iconSource: "images/fileopen.png"
+ iconName: "document-open"
+ text: "Open"
+ onTriggered: {
+ fileDialog.selectExisting = true
+ fileDialog.open()
+ }
+ }
+
+ Action {
+ id: fileSaveAsAction
+ iconSource: "images/filesave.png"
+ iconName: "document-save"
+ text: "Save As…"
+ onTriggered: {
+ fileDialog.selectExisting = false
+ fileDialog.open()
+ }
+ }
+
+ menuBar: MenuBar {
+ Menu {
+ title: "&File"
+ MenuItem { action: fileOpenAction }
+ MenuItem { action: fileSaveAsAction }
+ MenuItem { text: "Quit"; onTriggered: Qt.quit() }
+ }
+ Menu {
+ title: "&Edit"
+ MenuItem { action: copyAction }
+ MenuItem { action: cutAction }
+ MenuItem { action: pasteAction }
+ }
+ Menu {
+ title: "F&ormat"
+ MenuItem { action: boldAction }
+ MenuItem { action: italicAction }
+ MenuItem { action: underlineAction }
+ MenuSeparator {}
+ MenuItem { action: alignLeftAction }
+ MenuItem { action: alignCenterAction }
+ MenuItem { action: alignRightAction }
+ MenuItem { action: alignJustifyAction }
+ MenuSeparator {}
+ MenuItem {
+ text: "&Color ..."
+ onTriggered: {
+ colorDialog.color = document.textColor
+ colorDialog.open()
+ }
+ }
+ }
+ Menu {
+ title: "&Help"
+ MenuItem { text: "About..." ; onTriggered: aboutBox.open() }
+ }
+ }
+
+ toolBar: ToolBar {
+ id: mainToolBar
+ width: parent.width
+ RowLayout {
+ anchors.fill: parent
+ spacing: 0
+ ToolButton { action: fileOpenAction }
+
+ ToolBarSeparator {}
+
+ ToolButton { action: copyAction }
+ ToolButton { action: cutAction }
+ ToolButton { action: pasteAction }
+
+ ToolBarSeparator {}
+
+ ToolButton { action: boldAction }
+ ToolButton { action: italicAction }
+ ToolButton { action: underlineAction }
+
+ ToolBarSeparator {}
+
+ ToolButton { action: alignLeftAction }
+ ToolButton { action: alignCenterAction }
+ ToolButton { action: alignRightAction }
+ ToolButton { action: alignJustifyAction }
+
+ ToolBarSeparator {}
+
+ ToolButton {
+ id: colorButton
+ property var color : document.textColor
+ Rectangle {
+ id: colorRect
+ anchors.fill: parent
+ anchors.margins: 8
+ color: Qt.darker(document.textColor, colorButton.pressed ? 1.4 : 1)
+ border.width: 1
+ border.color: Qt.darker(colorRect.color, 2)
+ }
+ onClicked: {
+ colorDialog.color = document.textColor
+ colorDialog.open()
+ }
+ }
+ Item { Layout.fillWidth: true }
+ }
+ }
+
+ ToolBar {
+ id: secondaryToolBar
+ width: parent.width
+
+ RowLayout {
+ anchors.fill: parent
+ ComboBox {
+ id: fontFamilyComboBox
+ implicitWidth: 150
+ model: Qt.fontFamilies()
+ property bool special : false
+ onActivated: {
+ if (special == false || index != 0) {
+ document.fontFamily = textAt(index)
+ }
+ }
+ }
+ SpinBox {
+ id: fontSizeSpinBox
+ activeFocusOnPress: false
+ implicitWidth: 50
+ value: 0
+ property bool valueGuard: true
+ onValueChanged: if (valueGuard) document.fontSize = value
+ }
+ Item { Layout.fillWidth: true }
+ }
+ }
+
+ TextArea {
+ Accessible.name: "document"
+ id: textArea
+ frameVisible: false
+ width: parent.width
+ anchors.top: secondaryToolBar.bottom
+ anchors.bottom: parent.bottom
+ baseUrl: "qrc:/"
+ text: document.text
+ textFormat: Qt.RichText
+ Component.onCompleted: forceActiveFocus()
+ }
+
+ MessageDialog {
+ id: errorDialog
+ }
+
+ DocumentHandler {
+ id: document
+ target: textArea
+ cursorPosition: textArea.cursorPosition
+ selectionStart: textArea.selectionStart
+ selectionEnd: textArea.selectionEnd
+ textColor: colorDialog.color
+ Component.onCompleted: document.fileUrl = "qrc:/example.html"
+ onFontSizeChanged: {
+ fontSizeSpinBox.valueGuard = false
+ fontSizeSpinBox.value = document.fontSize
+ fontSizeSpinBox.valueGuard = true
+ }
+ onFontFamilyChanged: {
+ var index = Qt.fontFamilies().indexOf(document.fontFamily)
+ if (index == -1) {
+ fontFamilyComboBox.currentIndex = 0
+ fontFamilyComboBox.special = true
+ } else {
+ fontFamilyComboBox.currentIndex = index
+ fontFamilyComboBox.special = false
+ }
+ }
+ onError: {
+ errorDialog.text = message
+ errorDialog.visible = true
+ }
+ }
+}
diff --git a/examples/quickcontrols/controls/texteditor/resources.qrc b/examples/quickcontrols/controls/texteditor/resources.qrc
new file mode 100644
index 00000000..27c7b921
--- /dev/null
+++ b/examples/quickcontrols/controls/texteditor/resources.qrc
@@ -0,0 +1,27 @@
+<RCC>
+ <qresource prefix="/">
+ <file>qml/main.qml</file>
+ <file>qml/ToolBarSeparator.qml</file>
+ <file>qml/images/editcopy.png</file>
+ <file>qml/images/editcut.png</file>
+ <file>qml/images/editpaste.png</file>
+ <file>qml/images/editredo.png</file>
+ <file>qml/images/editundo.png</file>
+ <file>qml/images/exportpdf.png</file>
+ <file>qml/images/filenew.png</file>
+ <file>qml/images/fileopen.png</file>
+ <file>qml/images/fileprint.png</file>
+ <file>qml/images/filesave.png</file>
+ <file>qml/images/textbold.png</file>
+ <file>qml/images/textcenter.png</file>
+ <file>qml/images/textitalic.png</file>
+ <file>qml/images/textjustify.png</file>
+ <file>qml/images/textleft.png</file>
+ <file>qml/images/textright.png</file>
+ <file>qml/images/textunder.png</file>
+ <file>qml/images/zoomin.png</file>
+ <file>qml/images/zoomout.png</file>
+ <file>example.html</file>
+ <file>qml/images/qt-logo.png</file>
+ </qresource>
+</RCC>
diff --git a/examples/quickcontrols/controls/texteditor/src/documenthandler.cpp b/examples/quickcontrols/controls/texteditor/src/documenthandler.cpp
new file mode 100644
index 00000000..2e03f747
--- /dev/null
+++ b/examples/quickcontrols/controls/texteditor/src/documenthandler.cpp
@@ -0,0 +1,335 @@
+/****************************************************************************
+**
+** Copyright (C) 2015 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of The Qt Company Ltd nor the names of its
+** contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "documenthandler.h"
+
+#include <QtGui/QTextDocument>
+#include <QtGui/QTextCursor>
+#include <QtGui/QFontDatabase>
+#include <QtCore/QFileInfo>
+
+DocumentHandler::DocumentHandler()
+ : m_target(0)
+ , m_doc(0)
+ , m_cursorPosition(-1)
+ , m_selectionStart(0)
+ , m_selectionEnd(0)
+{
+}
+
+void DocumentHandler::setTarget(QQuickItem *target)
+{
+ m_doc = 0;
+ m_target = target;
+ if (!m_target)
+ return;
+
+ QVariant doc = m_target->property("textDocument");
+ if (doc.canConvert<QQuickTextDocument*>()) {
+ QQuickTextDocument *qqdoc = doc.value<QQuickTextDocument*>();
+ if (qqdoc)
+ m_doc = qqdoc->textDocument();
+ }
+ emit targetChanged();
+}
+
+void DocumentHandler::setFileUrl(const QUrl &arg)
+{
+ if (m_fileUrl != arg) {
+ m_fileUrl = arg;
+ QString fileName = QQmlFile::urlToLocalFileOrQrc(arg);
+ if (QFile::exists(fileName)) {
+ QFile file(fileName);
+ if (file.open(QFile::ReadOnly)) {
+ QByteArray data = file.readAll();
+ QTextCodec *codec = QTextCodec::codecForHtml(data);
+ setText(codec->toUnicode(data));
+ if (m_doc)
+ m_doc->setModified(false);
+ if (fileName.isEmpty())
+ m_documentTitle = QStringLiteral("untitled.txt");
+ else
+ m_documentTitle = QFileInfo(fileName).fileName();
+
+ emit textChanged();
+ emit documentTitleChanged();
+
+ reset();
+ }
+ }
+ emit fileUrlChanged();
+ }
+}
+
+QString DocumentHandler::documentTitle() const
+{
+ return m_documentTitle;
+}
+
+void DocumentHandler::setDocumentTitle(QString arg)
+{
+ if (m_documentTitle != arg) {
+ m_documentTitle = arg;
+ emit documentTitleChanged();
+ }
+}
+
+void DocumentHandler::setText(const QString &arg)
+{
+ if (m_text != arg) {
+ m_text = arg;
+ emit textChanged();
+ }
+}
+
+void DocumentHandler::saveAs(const QUrl &arg, const QString &fileType)
+{
+ bool isHtml = fileType.contains(QLatin1String("htm"));
+ QLatin1String ext(isHtml ? ".html" : ".txt");
+ QString localPath = arg.toLocalFile();
+ if (!localPath.endsWith(ext))
+ localPath += ext;
+ QFile f(localPath);
+ if (!f.open(QFile::WriteOnly | QFile::Truncate | (isHtml ? QFile::NotOpen : QFile::Text))) {
+ emit error(tr("Cannot save: ") + f.errorString());
+ return;
+ }
+ f.write((isHtml ? m_doc->toHtml() : m_doc->toPlainText()).toLocal8Bit());
+ f.close();
+ setFileUrl(QUrl::fromLocalFile(localPath));
+}
+
+QUrl DocumentHandler::fileUrl() const
+{
+ return m_fileUrl;
+}
+
+QString DocumentHandler::text() const
+{
+ return m_text;
+}
+
+void DocumentHandler::setCursorPosition(int position)
+{
+ if (position == m_cursorPosition)
+ return;
+
+ m_cursorPosition = position;
+
+ reset();
+}
+
+void DocumentHandler::reset()
+{
+ emit fontFamilyChanged();
+ emit alignmentChanged();
+ emit boldChanged();
+ emit italicChanged();
+ emit underlineChanged();
+ emit fontSizeChanged();
+ emit textColorChanged();
+}
+
+QTextCursor DocumentHandler::textCursor() const
+{
+ QTextCursor cursor = QTextCursor(m_doc);
+ if (m_selectionStart != m_selectionEnd) {
+ cursor.setPosition(m_selectionStart);
+ cursor.setPosition(m_selectionEnd, QTextCursor::KeepAnchor);
+ } else {
+ cursor.setPosition(m_cursorPosition);
+ }
+ return cursor;
+}
+
+void DocumentHandler::mergeFormatOnWordOrSelection(const QTextCharFormat &format)
+{
+ QTextCursor cursor = textCursor();
+ if (!cursor.hasSelection())
+ cursor.select(QTextCursor::WordUnderCursor);
+ cursor.mergeCharFormat(format);
+}
+
+void DocumentHandler::setSelectionStart(int position)
+{
+ m_selectionStart = position;
+}
+
+void DocumentHandler::setSelectionEnd(int position)
+{
+ m_selectionEnd = position;
+}
+
+void DocumentHandler::setAlignment(Qt::Alignment a)
+{
+ QTextBlockFormat fmt;
+ fmt.setAlignment((Qt::Alignment) a);
+ QTextCursor cursor = QTextCursor(m_doc);
+ cursor.setPosition(m_selectionStart, QTextCursor::MoveAnchor);
+ cursor.setPosition(m_selectionEnd, QTextCursor::KeepAnchor);
+ cursor.mergeBlockFormat(fmt);
+ emit alignmentChanged();
+}
+
+Qt::Alignment DocumentHandler::alignment() const
+{
+ QTextCursor cursor = textCursor();
+ if (cursor.isNull())
+ return Qt::AlignLeft;
+ return textCursor().blockFormat().alignment();
+}
+
+bool DocumentHandler::bold() const
+{
+ QTextCursor cursor = textCursor();
+ if (cursor.isNull())
+ return false;
+ return textCursor().charFormat().fontWeight() == QFont::Bold;
+}
+
+bool DocumentHandler::italic() const
+{
+ QTextCursor cursor = textCursor();
+ if (cursor.isNull())
+ return false;
+ return textCursor().charFormat().fontItalic();
+}
+
+bool DocumentHandler::underline() const
+{
+ QTextCursor cursor = textCursor();
+ if (cursor.isNull())
+ return false;
+ return textCursor().charFormat().fontUnderline();
+}
+
+void DocumentHandler::setBold(bool arg)
+{
+ QTextCharFormat fmt;
+ fmt.setFontWeight(arg ? QFont::Bold : QFont::Normal);
+ mergeFormatOnWordOrSelection(fmt);
+ emit boldChanged();
+}
+
+void DocumentHandler::setItalic(bool arg)
+{
+ QTextCharFormat fmt;
+ fmt.setFontItalic(arg);
+ mergeFormatOnWordOrSelection(fmt);
+ emit italicChanged();
+}
+
+void DocumentHandler::setUnderline(bool arg)
+{
+ QTextCharFormat fmt;
+ fmt.setFontUnderline(arg);
+ mergeFormatOnWordOrSelection(fmt);
+ emit underlineChanged();
+}
+
+int DocumentHandler::fontSize() const
+{
+ QTextCursor cursor = textCursor();
+ if (cursor.isNull())
+ return 0;
+ QTextCharFormat format = cursor.charFormat();
+ return format.font().pointSize();
+}
+
+void DocumentHandler::setFontSize(int arg)
+{
+ QTextCursor cursor = textCursor();
+ if (cursor.isNull())
+ return;
+ QTextCharFormat format;
+ format.setFontPointSize(arg);
+ mergeFormatOnWordOrSelection(format);
+ emit fontSizeChanged();
+}
+
+QColor DocumentHandler::textColor() const
+{
+ QTextCursor cursor = textCursor();
+ if (cursor.isNull())
+ return QColor(Qt::black);
+ QTextCharFormat format = cursor.charFormat();
+ return format.foreground().color();
+}
+
+void DocumentHandler::setTextColor(const QColor &c)
+{
+ QTextCursor cursor = textCursor();
+ if (cursor.isNull())
+ return;
+ QTextCharFormat format;
+ format.setForeground(QBrush(c));
+ mergeFormatOnWordOrSelection(format);
+ emit textColorChanged();
+}
+
+QString DocumentHandler::fontFamily() const
+{
+ QTextCursor cursor = textCursor();
+ if (cursor.isNull())
+ return QString();
+ QTextCharFormat format = cursor.charFormat();
+ return format.font().family();
+}
+
+void DocumentHandler::setFontFamily(const QString &arg)
+{
+ QTextCursor cursor = textCursor();
+ if (cursor.isNull())
+ return;
+ QTextCharFormat format;
+ format.setFontFamily(arg);
+ mergeFormatOnWordOrSelection(format);
+ emit fontFamilyChanged();
+}
+
+QStringList DocumentHandler::defaultFontSizes() const
+{
+ // uhm... this is quite ugly
+ QStringList sizes;
+ QFontDatabase db;
+ foreach (int size, db.standardSizes())
+ sizes.append(QString::number(size));
+ return sizes;
+}
diff --git a/examples/quickcontrols/controls/texteditor/src/documenthandler.h b/examples/quickcontrols/controls/texteditor/src/documenthandler.h
new file mode 100644
index 00000000..f2bd4eea
--- /dev/null
+++ b/examples/quickcontrols/controls/texteditor/src/documenthandler.h
@@ -0,0 +1,171 @@
+/****************************************************************************
+**
+** Copyright (C) 2015 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of The Qt Company Ltd nor the names of its
+** contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef DOCUMENTHANDLER_H
+#define DOCUMENTHANDLER_H
+
+#include <QQuickTextDocument>
+
+#include <QtGui/QTextCharFormat>
+#include <QtCore/QTextCodec>
+
+#include <qqmlfile.h>
+
+QT_BEGIN_NAMESPACE
+class QTextDocument;
+QT_END_NAMESPACE
+
+class DocumentHandler : public QObject
+{
+ Q_OBJECT
+
+ Q_ENUMS(HAlignment)
+
+ Q_PROPERTY(QQuickItem *target READ target WRITE setTarget NOTIFY targetChanged)
+ Q_PROPERTY(int cursorPosition READ cursorPosition WRITE setCursorPosition NOTIFY cursorPositionChanged)
+ Q_PROPERTY(int selectionStart READ selectionStart WRITE setSelectionStart NOTIFY selectionStartChanged)
+ Q_PROPERTY(int selectionEnd READ selectionEnd WRITE setSelectionEnd NOTIFY selectionEndChanged)
+
+ Q_PROPERTY(QColor textColor READ textColor WRITE setTextColor NOTIFY textColorChanged)
+ Q_PROPERTY(QString fontFamily READ fontFamily WRITE setFontFamily NOTIFY fontFamilyChanged)
+ Q_PROPERTY(Qt::Alignment alignment READ alignment WRITE setAlignment NOTIFY alignmentChanged)
+
+ Q_PROPERTY(bool bold READ bold WRITE setBold NOTIFY boldChanged)
+ Q_PROPERTY(bool italic READ italic WRITE setItalic NOTIFY italicChanged)
+ Q_PROPERTY(bool underline READ underline WRITE setUnderline NOTIFY underlineChanged)
+
+ Q_PROPERTY(int fontSize READ fontSize WRITE setFontSize NOTIFY fontSizeChanged)
+
+ Q_PROPERTY(QStringList defaultFontSizes READ defaultFontSizes NOTIFY defaultFontSizesChanged)
+
+ Q_PROPERTY(QUrl fileUrl READ fileUrl WRITE setFileUrl NOTIFY fileUrlChanged)
+ Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged)
+ Q_PROPERTY(QString documentTitle READ documentTitle WRITE setDocumentTitle NOTIFY documentTitleChanged)
+
+public:
+ DocumentHandler();
+
+ QQuickItem *target() { return m_target; }
+
+ void setTarget(QQuickItem *target);
+
+ void setCursorPosition(int position);
+ void setSelectionStart(int position);
+ void setSelectionEnd(int position);
+
+ int cursorPosition() const { return m_cursorPosition; }
+ int selectionStart() const { return m_selectionStart; }
+ int selectionEnd() const { return m_selectionEnd; }
+
+ QString fontFamily() const;
+
+ QColor textColor() const;
+
+ Qt::Alignment alignment() const;
+ void setAlignment(Qt::Alignment a);
+
+ bool bold() const;
+ bool italic() const;
+ bool underline() const;
+ int fontSize() const;
+
+ QStringList defaultFontSizes() const;
+ QUrl fileUrl() const;
+ QString text() const;
+
+ QString documentTitle() const;
+
+public Q_SLOTS:
+ void setBold(bool arg);
+ void setItalic(bool arg);
+ void setUnderline(bool arg);
+ void setFontSize(int arg);
+ void setTextColor(const QColor &arg);
+ void setFontFamily(const QString &arg);
+
+ void setFileUrl(const QUrl &arg);
+ void setText(const QString &arg);
+ void saveAs(const QUrl &arg, const QString &fileType);
+
+ void setDocumentTitle(QString arg);
+
+Q_SIGNALS:
+ void targetChanged();
+ void cursorPositionChanged();
+ void selectionStartChanged();
+ void selectionEndChanged();
+
+ void fontFamilyChanged();
+ void textColorChanged();
+ void alignmentChanged();
+
+ void boldChanged();
+ void italicChanged();
+ void underlineChanged();
+
+ void fontSizeChanged();
+ void defaultFontSizesChanged();
+
+ void fileUrlChanged();
+
+ void textChanged();
+ void documentTitleChanged();
+ void error(QString message);
+
+private:
+ void reset();
+ QTextCursor textCursor() const;
+ void mergeFormatOnWordOrSelection(const QTextCharFormat &format);
+
+ QQuickItem *m_target;
+ QTextDocument *m_doc;
+
+ int m_cursorPosition;
+ int m_selectionStart;
+ int m_selectionEnd;
+
+ QFont m_font;
+ int m_fontSize;
+ QUrl m_fileUrl;
+ QString m_text;
+ QString m_documentTitle;
+};
+
+#endif
diff --git a/examples/quickcontrols/controls/texteditor/src/main.cpp b/examples/quickcontrols/controls/texteditor/src/main.cpp
new file mode 100644
index 00000000..1ef76e3a
--- /dev/null
+++ b/examples/quickcontrols/controls/texteditor/src/main.cpp
@@ -0,0 +1,53 @@
+/****************************************************************************
+**
+** Copyright (C) 2015 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of The Qt Company Ltd nor the names of its
+** contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qtquickcontrolsapplication.h"
+#include "documenthandler.h"
+#include <QtQml/QQmlApplicationEngine>
+
+int main(int argc, char *argv[])
+{
+ QtQuickControlsApplication app(argc, argv);
+ qmlRegisterType<DocumentHandler>("org.qtproject.example", 1, 0, "DocumentHandler");
+ QQmlApplicationEngine engine(QUrl("qrc:/qml/main.qml"));
+ if (engine.rootObjects().isEmpty())
+ return -1;
+ return app.exec();
+}
diff --git a/examples/quickcontrols/controls/texteditor/src/src.pri b/examples/quickcontrols/controls/texteditor/src/src.pri
new file mode 100644
index 00000000..2b89cd62
--- /dev/null
+++ b/examples/quickcontrols/controls/texteditor/src/src.pri
@@ -0,0 +1,9 @@
+SOURCES += \
+ $$PWD/documenthandler.cpp \
+ $$PWD/main.cpp
+
+
+HEADERS += \
+ $$PWD/documenthandler.h
+
+
diff --git a/examples/quickcontrols/controls/texteditor/texteditor.pro b/examples/quickcontrols/controls/texteditor/texteditor.pro
new file mode 100644
index 00000000..f5255255
--- /dev/null
+++ b/examples/quickcontrols/controls/texteditor/texteditor.pro
@@ -0,0 +1,16 @@
+QT += qml quick
+TARGET = texteditor
+!no_desktop: QT += widgets
+
+include(src/src.pri)
+include(../shared/shared.pri)
+
+OTHER_FILES += \
+ qml/main.qml \
+ qml/ToolBarSeparator.qml
+
+RESOURCES += \
+ resources.qrc
+
+target.path = $$[QT_INSTALL_EXAMPLES]/quickcontrols/controls/texteditor
+INSTALLS += target