summaryrefslogtreecommitdiff
path: root/examples/quick/controls/text/qml/main.qml
diff options
context:
space:
mode:
Diffstat (limited to 'examples/quick/controls/text/qml/main.qml')
-rw-r--r--examples/quick/controls/text/qml/main.qml199
1 files changed, 141 insertions, 58 deletions
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
+ }
}
}
}