summaryrefslogtreecommitdiff
path: root/examples/quick/controls/text
diff options
context:
space:
mode:
Diffstat (limited to 'examples/quick/controls/text')
-rw-r--r--examples/quick/controls/text/example.html22
-rw-r--r--examples/quick/controls/text/qml/ToolBarSeparator.qml61
-rw-r--r--examples/quick/controls/text/qml/images/logo32.pngbin1410 -> 0 bytes
-rw-r--r--examples/quick/controls/text/qml/images/qt-logo.pngbin0 -> 3960 bytes
-rw-r--r--examples/quick/controls/text/qml/main.qml199
-rw-r--r--examples/quick/controls/text/resources.qrc51
-rw-r--r--examples/quick/controls/text/src/documenthandler.cpp60
-rw-r--r--examples/quick/controls/text/src/documenthandler.h16
-rw-r--r--examples/quick/controls/text/src/main.cpp14
-rw-r--r--examples/quick/controls/text/text.pro3
10 files changed, 300 insertions, 126 deletions
diff --git a/examples/quick/controls/text/example.html b/examples/quick/controls/text/example.html
index 0560897b..52bb507a 100644
--- a/examples/quick/controls/text/example.html
+++ b/examples/quick/controls/text/example.html
@@ -1,11 +1,13 @@
-<html><head><meta name="qrichtext" content="1" /><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>QTextEdit Example</title><style type="text/css">
+<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;">QTextEdit</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 QTextEdit widget is an advanced editor that supports formatted rich text. It can be used to display HTML and other rich document formats. Internally, QTextEdit uses the QTextDocument 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;">textedit</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 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;">QTextEdit 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:'Times'; font-size:11pt; font-weight:600;">Times New Roman</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><span style=" font-size:11pt; font-style:italic;">If you place the cursor in a region of styled text, the controls in the tool bars will change to reflect the current style.</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>
@@ -13,7 +15,7 @@ p, li { white-space: pre-wrap; }
<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 created that can be used for tables of contents. Different characters can be used to enumerate items, and we can use both Roman and Arabic numerals in the same list structure: </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;">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>
@@ -26,9 +28,9 @@ p, li { white-space: pre-wrap; }
<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/logo32.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;"><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;">QTextEdit 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 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">
@@ -72,8 +74,6 @@ p, li { white-space: pre-wrap; }
<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;">Hyperlinks</span></p>
-<p 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;">QTextEdit is designed to support hyperlinks between documents, and this feature is used extensively in </span><span style=" font-size:11pt; font-style:italic;">Qt Assistant</span><span style=" font-size:11pt;">. Hyperlinks are automatically created when an HTML file is imported into an editor. Since the rich text framework supports hyperlinks natively, they can also be created programatically.</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;"><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 QTextEdit and the underlying rich text framework. Operations on a document can be packaged together to make editing a more comfortable experience 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;">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/quick/controls/text/qml/ToolBarSeparator.qml b/examples/quick/controls/text/qml/ToolBarSeparator.qml
new file mode 100644
index 00000000..40a2bc58
--- /dev/null
+++ b/examples/quick/controls/text/qml/ToolBarSeparator.qml
@@ -0,0 +1,61 @@
+/****************************************************************************
+**
+** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the Qt Quick Controls module 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 Digia Plc and its Subsidiary(-ies) 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.1
+
+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/quick/controls/text/qml/images/logo32.png b/examples/quick/controls/text/qml/images/logo32.png
deleted file mode 100644
index 5f91e987..00000000
--- a/examples/quick/controls/text/qml/images/logo32.png
+++ /dev/null
Binary files differ
diff --git a/examples/quick/controls/text/qml/images/qt-logo.png b/examples/quick/controls/text/qml/images/qt-logo.png
new file mode 100644
index 00000000..6dedc8bf
--- /dev/null
+++ b/examples/quick/controls/text/qml/images/qt-logo.png
Binary files differ
diff --git a/examples/quick/controls/text/qml/main.qml b/examples/quick/controls/text/qml/main.qml
index dd8b1848..d8f175ed 100644
--- a/examples/quick/controls/text/qml/main.qml
+++ b/examples/quick/controls/text/qml/main.qml
@@ -42,6 +42,7 @@ import QtQuick 2.1
import QtQuick.Controls 1.0
import QtQuick.Layouts 1.0
import QtQuick.Dialogs 1.0
+import QtQuick.Window 2.1
import org.qtproject.example 1.0
ApplicationWindow {
@@ -52,33 +53,66 @@ ApplicationWindow {
title: document.documentTitle + " - Text Editor Example"
+ ApplicationWindow {
+ id: aboutBox
+
+ width: 280
+ height: 120
+ title: "About Text"
+
+ ColumnLayout {
+ anchors.fill: parent
+ anchors.margins: 8
+ Item {
+ Layout.fillWidth: true
+ Layout.fillHeight: true
+ Label {
+ anchors.centerIn: parent
+ horizontalAlignment: Text.AlignHCenter
+ text: "This is a basic text editor \nwritten with Qt Quick Controls"
+ }
+ }
+ Button {
+ text: "Ok"
+ isDefault: true
+ anchors.horizontalCenter: parent.horizontalCenter
+ anchors.bottom: parent.bottom
+ onClicked: aboutBox.close()
+ }
+ Keys.onReturnPressed: aboutBox.close()
+ focus: true
+ }
+ }
+
Action {
- id: cut
+ id: cutAction
text: "Cut"
shortcut: "ctrl+x"
iconSource: "images/editcut.png"
iconName: "edit-cut"
+ onTriggered: textArea.cut()
}
Action {
- id: copy
+ id: copyAction
text: "Copy"
shortcut: "Ctrl+C"
iconSource: "images/editcopy.png"
iconName: "edit-copy"
- onTriggered: console.log("Ctrl C pressed - in action...")
+ onTriggered: textArea.copy()
}
Action {
- id: paste
+ id: pasteAction
text: "Paste"
shortcut: "ctrl+v"
iconSource: "qrc:images/editpaste.png"
iconName: "edit-paste"
+ onTriggered: textArea.paste()
}
Action {
- id: alignLeft
+ id: alignLeftAction
text: "&Left"
iconSource: "images/textleft.png"
iconName: "format-justify-left"
@@ -88,16 +122,16 @@ ApplicationWindow {
checked: document.alignment == Qt.AlignLeft
}
Action {
- id: alignCenter
+ id: alignCenterAction
text: "C&enter"
iconSource: "images/textcenter.png"
iconName: "format-justify-center"
- onTriggered: document.alignment = Qt.AlignCenter
+ onTriggered: document.alignment = Qt.AlignHCenter
checkable: true
- checked: document.alignment == Qt.AlignCenter
+ checked: document.alignment == Qt.AlignHCenter
}
Action {
- id: alignRight
+ id: alignRightAction
text: "&Right"
iconSource: "images/textright.png"
iconName: "format-justify-right"
@@ -106,7 +140,7 @@ ApplicationWindow {
checked: document.alignment == Qt.AlignRight
}
Action {
- id: alignJustify
+ id: alignJustifyAction
text: "&Justify"
iconSource: "images/textjustify.png"
iconName: "format-justify-fill"
@@ -116,7 +150,7 @@ ApplicationWindow {
}
Action {
- id: bold
+ id: boldAction
text: "&Bold"
iconSource: "images/textbold.png"
iconName: "format-text-bold"
@@ -124,8 +158,9 @@ ApplicationWindow {
checkable: true
checked: document.bold
}
+
Action {
- id: italic
+ id: italicAction
text: "&Italic"
iconSource: "images/textitalic.png"
iconName: "format-text-italic"
@@ -134,7 +169,7 @@ ApplicationWindow {
checked: document.italic
}
Action {
- id: underline
+ id: underlineAction
text: "&Underline"
iconSource: "images/textunder.png"
iconName: "format-text-underline"
@@ -142,56 +177,61 @@ ApplicationWindow {
checkable: true
checked: document.underline
}
- Action {
- id: color
- text: "&Color ..."
- iconSource: "images/textcolor.png"
- iconName: "format-text-color"
- }
FileDialog {
- id: file
+ id: fileDialog
nameFilters: ["Text files (*.txt)", "HTML files (*.html)"]
onAccepted: document.fileUrl = fileUrl
}
+ ColorDialog {
+ id: colorDialog
+ color: "black"
+ onAccepted: document.textColor = color
+ }
+
Action {
- id: fileOpen
+ id: fileOpenAction
iconSource: "images/fileopen.png"
iconName: "document-open"
text: "Open"
- onTriggered: file.open()
+ onTriggered: fileDialog.open()
}
menuBar: MenuBar {
Menu {
title: "&File"
- MenuItem { action: fileOpen }
+ MenuItem { action: fileOpenAction }
MenuItem { text: "Quit"; onTriggered: Qt.quit() }
}
Menu {
title: "&Edit"
- MenuItem { action: copy }
- MenuItem { action: cut }
- MenuItem { action: paste }
+ MenuItem { action: copyAction }
+ MenuItem { action: cutAction }
+ MenuItem { action: pasteAction }
}
Menu {
title: "F&ormat"
- MenuItem { action: bold }
- MenuItem { action: italic }
- MenuItem { action: underline }
+ MenuItem { action: boldAction }
+ MenuItem { action: italicAction }
+ MenuItem { action: underlineAction }
MenuSeparator {}
- MenuItem { action: alignLeft }
- MenuItem { action: alignCenter }
- MenuItem { action: alignRight }
- MenuItem { action: alignJustify }
+ MenuItem { action: alignLeftAction }
+ MenuItem { action: alignCenterAction }
+ MenuItem { action: alignRightAction }
+ MenuItem { action: alignJustifyAction }
MenuSeparator {}
- MenuItem { action: color }
+ MenuItem {
+ text: "&Color ..."
+ onTriggered: {
+ colorDialog.color = document.textColor
+ colorDialog.open()
+ }
+ }
}
Menu {
title: "&Help"
- MenuItem { text: "About..." }
- MenuItem { text: "About Qt" }
+ MenuItem { text: "About..." ; onTriggered: aboutBox.show() }
}
}
@@ -200,39 +240,72 @@ ApplicationWindow {
width: parent.width
RowLayout {
anchors.fill: parent
- spacing: 1
- ToolButton { action: fileOpen }
+ 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 }
- Item { width: 4 }
- ToolButton { action: copy }
- ToolButton { action: cut }
- ToolButton { action: paste }
- Item { width: 4 }
- ToolButton { action: bold }
- ToolButton { action: italic }
- ToolButton { action: underline }
+ ToolBarSeparator {}
- Item { width: 4 }
- ToolButton { action: alignLeft }
- ToolButton { action: alignCenter }
- ToolButton { action: alignRight }
- ToolButton { action: alignJustify }
+ 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
- anchors.margins: 4
ComboBox {
- model: document.defaultFontSizes
- onCurrentTextChanged: document.fontSize = currentText
- currentIndex: document.defaultFontSizes.indexOf(document.fontSize + "")
+ id: fontFamilyComboBox
+ implicitWidth: 150
+ model: Qt.fontFamilies()
+ property bool special : false
+ onCurrentTextChanged: {
+ if (special == false || currentIndex != 0)
+ document.fontFamily = currentText
+ }
+ }
+ SpinBox {
+ id: fontSizeSpinBox
+ implicitWidth: 50
+ value: 0
+ onValueChanged: document.fontSize = value
}
- TextField { id: fontEdit; enabled: false }
Item { Layout.fillWidth: true }
}
}
@@ -240,6 +313,7 @@ ApplicationWindow {
TextArea {
Accessible.name: "document"
id: textArea
+ frameVisible: false
width: parent.width
anchors.top: secondaryToolBar.bottom
anchors.bottom: parent.bottom
@@ -254,8 +328,17 @@ ApplicationWindow {
cursorPosition: textArea.cursorPosition
selectionStart: textArea.selectionStart
selectionEnd: textArea.selectionEnd
- onCurrentFontChanged: {
- fontEdit.text = currentFont.family
+ Component.onCompleted: document.fileUrl = "qrc:/example.html"
+ onFontSizeChanged: fontSizeSpinBox.value = document.fontSize
+ onFontFamilyChanged: {
+ var index = Qt.fontFamilies().indexOf(document.fontFamily)
+ if (index == -1) {
+ fontFamilyComboBox.currentIndex = 0
+ fontFamilyComboBox.special = true
+ } else {
+ fontFamilyComboBox.currentIndex = index
+ fontFamilyComboBox.special = false
+ }
}
}
}
diff --git a/examples/quick/controls/text/resources.qrc b/examples/quick/controls/text/resources.qrc
index e67fac6a..27c7b921 100644
--- a/examples/quick/controls/text/resources.qrc
+++ b/examples/quick/controls/text/resources.qrc
@@ -1,26 +1,27 @@
-<!DOCTYPE RCC><RCC version="1.0">
-<qresource prefix="/">
- <file>qml/main.qml</file>
- <file>qml/images/logo32.png</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>
-</qresource>
+<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/quick/controls/text/src/documenthandler.cpp b/examples/quick/controls/text/src/documenthandler.cpp
index 48b6d033..e0c9610d 100644
--- a/examples/quick/controls/text/src/documenthandler.cpp
+++ b/examples/quick/controls/text/src/documenthandler.cpp
@@ -52,7 +52,6 @@ DocumentHandler::DocumentHandler()
, m_selectionStart(0)
, m_selectionEnd(0)
{
- setFileUrl(QUrl("qrc:/example.html"));
}
void DocumentHandler::setTarget(QQuickItem *target)
@@ -91,6 +90,8 @@ void DocumentHandler::setFileUrl(const QUrl &arg)
emit textChanged();
emit documentTitleChanged();
+
+ reset();
}
}
emit fileUrlChanged();
@@ -135,12 +136,18 @@ void DocumentHandler::setCursorPosition(int position)
m_cursorPosition = position;
- emit currentFontChanged();
+ reset();
+}
+
+void DocumentHandler::reset()
+{
+ emit fontFamilyChanged();
emit alignmentChanged();
emit boldChanged();
emit italicChanged();
emit underlineChanged();
emit fontSizeChanged();
+ emit textColorChanged();
}
QTextCursor DocumentHandler::textCursor() const
@@ -166,13 +173,11 @@ void DocumentHandler::mergeFormatOnWordOrSelection(const QTextCharFormat &format
void DocumentHandler::setSelectionStart(int position)
{
m_selectionStart = position;
-// emit selectionStartChanged();
}
void DocumentHandler::setSelectionEnd(int position)
{
m_selectionEnd = position;
-// emit selectionEndChanged();
}
void DocumentHandler::setAlignment(Qt::Alignment a)
@@ -188,10 +193,8 @@ void DocumentHandler::setAlignment(Qt::Alignment a)
Qt::Alignment DocumentHandler::alignment() const
{
-// if (!m_doc || m_doc->isEmpty() || m_cursorPosition < 0)
-// return Qt::AlignLeft;
QTextCursor cursor = textCursor();
- if (cursor.isNull() || cursor.blockNumber() == 0)
+ if (cursor.isNull())
return Qt::AlignLeft;
return textCursor().blockFormat().alignment();
}
@@ -199,7 +202,7 @@ Qt::Alignment DocumentHandler::alignment() const
bool DocumentHandler::bold() const
{
QTextCursor cursor = textCursor();
- if (cursor.isNull() || cursor.blockNumber() == 0)
+ if (cursor.isNull())
return false;
return textCursor().charFormat().fontWeight() == QFont::Bold;
}
@@ -207,7 +210,7 @@ bool DocumentHandler::bold() const
bool DocumentHandler::italic() const
{
QTextCursor cursor = textCursor();
- if (cursor.isNull() || cursor.blockNumber() == 0)
+ if (cursor.isNull())
return false;
return textCursor().charFormat().fontItalic();
}
@@ -215,7 +218,7 @@ bool DocumentHandler::italic() const
bool DocumentHandler::underline() const
{
QTextCursor cursor = textCursor();
- if (cursor.isNull() || cursor.blockNumber() == 0)
+ if (cursor.isNull())
return false;
return textCursor().charFormat().fontUnderline();
}
@@ -264,13 +267,44 @@ void DocumentHandler::setFontSize(int arg)
emit fontSizeChanged();
}
-QFont DocumentHandler::currentFont() const
+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 QFont();
+ return QString();
QTextCharFormat format = cursor.charFormat();
- return format.font();
+ 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
diff --git a/examples/quick/controls/text/src/documenthandler.h b/examples/quick/controls/text/src/documenthandler.h
index c60bc1d5..a759c403 100644
--- a/examples/quick/controls/text/src/documenthandler.h
+++ b/examples/quick/controls/text/src/documenthandler.h
@@ -63,7 +63,8 @@ class DocumentHandler : public QObject
Q_PROPERTY(int selectionStart READ selectionStart WRITE setSelectionStart NOTIFY selectionStartChanged)
Q_PROPERTY(int selectionEnd READ selectionEnd WRITE setSelectionEnd NOTIFY selectionEndChanged)
- Q_PROPERTY(QFont currentFont READ currentFont NOTIFY currentFontChanged)
+ 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)
@@ -93,7 +94,9 @@ public:
int selectionStart() const { return m_selectionStart; }
int selectionEnd() const { return m_selectionEnd; }
- QFont currentFont() const;
+ QString fontFamily() const;
+
+ QColor textColor() const;
Qt::Alignment alignment() const;
void setAlignment(Qt::Alignment a);
@@ -114,6 +117,8 @@ public Q_SLOTS:
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);
@@ -126,7 +131,8 @@ Q_SIGNALS:
void selectionStartChanged();
void selectionEndChanged();
- void currentFontChanged();
+ void fontFamilyChanged();
+ void textColorChanged();
void alignmentChanged();
void boldChanged();
@@ -142,6 +148,7 @@ Q_SIGNALS:
void documentTitleChanged();
private:
+ void reset();
QTextCursor textCursor() const;
void mergeFormatOnWordOrSelection(const QTextCharFormat &format);
@@ -153,9 +160,6 @@ private:
int m_selectionEnd;
QFont m_font;
- bool m_bold;
- bool m_italic;
- bool m_underline;
int m_fontSize;
QUrl m_fileUrl;
QString m_text;
diff --git a/examples/quick/controls/text/src/main.cpp b/examples/quick/controls/text/src/main.cpp
index 0fc064dc..8d2b8dd0 100644
--- a/examples/quick/controls/text/src/main.cpp
+++ b/examples/quick/controls/text/src/main.cpp
@@ -49,24 +49,14 @@
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
- QQmlEngine engine;
-
qmlRegisterType<DocumentHandler>("org.qtproject.example", 1, 0, "DocumentHandler");
-
- QQmlComponent component(&engine);
- component.loadUrl(QUrl("qrc:/qml/main.qml"));
- if ( !component.isReady() ) {
- qWarning("%s", qPrintable(component.errorString()));
- return -1;
- }
- QObject *topLevel = component.create();
+ QQmlApplicationEngine engine(QUrl("qrc:/qml/main.qml"));
+ QObject *topLevel = engine.rootObjects().value(0);
QQuickWindow *window = qobject_cast<QQuickWindow *>(topLevel);
if ( !window ) {
qWarning("Error: Your root item has to be a Window.");
return -1;
}
-
- QObject::connect(&engine, SIGNAL(quit()), &app, SLOT(quit()));
window->show();
return app.exec();
}
diff --git a/examples/quick/controls/text/text.pro b/examples/quick/controls/text/text.pro
index ce6d5f33..864ce0bb 100644
--- a/examples/quick/controls/text/text.pro
+++ b/examples/quick/controls/text/text.pro
@@ -7,7 +7,8 @@ qtHaveModule(widgets) {
include(src/src.pri)
OTHER_FILES += \
- qml/main.qml
+ qml/main.qml \
+ qml/ToolBarSeparator.qml
RESOURCES += \
resources.qrc