From 8beda08087effd684cfcb325855c9f4b47186135 Mon Sep 17 00:00:00 2001 From: Jens Bache-Wiig Date: Thu, 30 May 2013 16:51:34 +0200 Subject: Cleaning up some examples and removing clutter We want to use more layouts in our examples as it is the recommended way to create tool bars etc. Change-Id: Ib3b1e8e907cc5277d522557a19d2c294a7d251b1 Reviewed-by: J-P Nurmi --- examples/quick/controls/text/qml/main.qml | 77 +++++++++++++++++-------------- 1 file changed, 43 insertions(+), 34 deletions(-) (limited to 'examples/quick/controls/text/qml/main.qml') diff --git a/examples/quick/controls/text/qml/main.qml b/examples/quick/controls/text/qml/main.qml index dd8b1848..ec6bff7b 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,6 +53,37 @@ 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 text: "Cut" @@ -142,12 +174,6 @@ ApplicationWindow { checkable: true checked: document.underline } - Action { - id: color - text: "&Color ..." - iconSource: "images/textcolor.png" - iconName: "format-text-color" - } FileDialog { id: file @@ -185,13 +211,10 @@ ApplicationWindow { MenuItem { action: alignCenter } MenuItem { action: alignRight } MenuItem { action: alignJustify } - MenuSeparator {} - MenuItem { action: color } } Menu { title: "&Help" - MenuItem { text: "About..." } - MenuItem { text: "About Qt" } + MenuItem { text: "About..." ; onTriggered: aboutBox.show() } } } @@ -200,19 +223,23 @@ ApplicationWindow { width: parent.width RowLayout { anchors.fill: parent - spacing: 1 + spacing: 0 ToolButton { action: fileOpen } - Item { width: 4 } + ToolBarSeparator {} + ToolButton { action: copy } ToolButton { action: cut } ToolButton { action: paste } - Item { width: 4 } + + ToolBarSeparator {} + ToolButton { action: bold } ToolButton { action: italic } ToolButton { action: underline } - Item { width: 4 } + ToolBarSeparator {} + ToolButton { action: alignLeft } ToolButton { action: alignCenter } ToolButton { action: alignRight } @@ -220,28 +247,13 @@ ApplicationWindow { 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 + "") - } - TextField { id: fontEdit; enabled: false } - Item { Layout.fillWidth: true } - } - } TextArea { Accessible.name: "document" id: textArea + frameVisible: false width: parent.width - anchors.top: secondaryToolBar.bottom + anchors.top: parent.top anchors.bottom: parent.bottom text: document.text textFormat: Qt.RichText @@ -254,8 +266,5 @@ ApplicationWindow { cursorPosition: textArea.cursorPosition selectionStart: textArea.selectionStart selectionEnd: textArea.selectionEnd - onCurrentFontChanged: { - fontEdit.text = currentFont.family - } } } -- cgit v1.2.1 From e67d67d0ad0c5c4549047f13be1999c65a9efb42 Mon Sep 17 00:00:00 2001 From: Liang Qi Date: Tue, 4 Jun 2013 13:36:18 +0200 Subject: Examples: several fixes for text * Cut/Copy/Paste works * The initial status for b/i/u and alignment works * Font size and family works * Text color works Task-number: QTBUG-31482 Change-Id: I299931dede9defbb1d3eb927f867e77d20ded5ae Reviewed-by: Caroline Chao Reviewed-by: Gabriel de Dietrich --- examples/quick/controls/text/qml/main.qml | 152 ++++++++++++++++++++++-------- 1 file changed, 113 insertions(+), 39 deletions(-) (limited to 'examples/quick/controls/text/qml/main.qml') diff --git a/examples/quick/controls/text/qml/main.qml b/examples/quick/controls/text/qml/main.qml index ec6bff7b..d8f175ed 100644 --- a/examples/quick/controls/text/qml/main.qml +++ b/examples/quick/controls/text/qml/main.qml @@ -85,32 +85,34 @@ ApplicationWindow { } 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" @@ -120,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" @@ -138,7 +140,7 @@ ApplicationWindow { checked: document.alignment == Qt.AlignRight } Action { - id: alignJustify + id: alignJustifyAction text: "&Justify" iconSource: "images/textjustify.png" iconName: "format-justify-fill" @@ -148,7 +150,7 @@ ApplicationWindow { } Action { - id: bold + id: boldAction text: "&Bold" iconSource: "images/textbold.png" iconName: "format-text-bold" @@ -156,8 +158,9 @@ ApplicationWindow { checkable: true checked: document.bold } + Action { - id: italic + id: italicAction text: "&Italic" iconSource: "images/textitalic.png" iconName: "format-text-italic" @@ -166,7 +169,7 @@ ApplicationWindow { checked: document.italic } Action { - id: underline + id: underlineAction text: "&Underline" iconSource: "images/textunder.png" iconName: "format-text-underline" @@ -176,41 +179,55 @@ ApplicationWindow { } 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: alignLeftAction } + MenuItem { action: alignCenterAction } + MenuItem { action: alignRightAction } + MenuItem { action: alignJustifyAction } MenuSeparator {} - MenuItem { action: alignLeft } - MenuItem { action: alignCenter } - MenuItem { action: alignRight } - MenuItem { action: alignJustify } + MenuItem { + text: "&Color ..." + onTriggered: { + colorDialog.color = document.textColor + colorDialog.open() + } + } } Menu { title: "&Help" @@ -224,26 +241,71 @@ ApplicationWindow { RowLayout { anchors.fill: parent spacing: 0 - ToolButton { action: fileOpen } + ToolButton { action: fileOpenAction } ToolBarSeparator {} - ToolButton { action: copy } - ToolButton { action: cut } - ToolButton { action: paste } + ToolButton { action: copyAction } + ToolButton { action: cutAction } + ToolButton { action: pasteAction } ToolBarSeparator {} - ToolButton { action: bold } - ToolButton { action: italic } - ToolButton { action: underline } + ToolButton { action: boldAction } + ToolButton { action: italicAction } + ToolButton { action: underlineAction } ToolBarSeparator {} - 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 + ComboBox { + 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 + } Item { Layout.fillWidth: true } } } @@ -253,7 +315,7 @@ ApplicationWindow { id: textArea frameVisible: false width: parent.width - anchors.top: parent.top + anchors.top: secondaryToolBar.bottom anchors.bottom: parent.bottom text: document.text textFormat: Qt.RichText @@ -266,5 +328,17 @@ ApplicationWindow { cursorPosition: textArea.cursorPosition selectionStart: textArea.selectionStart selectionEnd: textArea.selectionEnd + 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 + } + } } } -- cgit v1.2.1 From 41e13d3746c8b7b5cd550091c63fd8ab066422cf Mon Sep 17 00:00:00 2001 From: Caroline Chao Date: Tue, 11 Jun 2013 09:13:44 +0200 Subject: Add qml/js files in resource files To make deployment of Qt Quick Controls based applications easier. Task-number: QTBUG-31565 Change-Id: I0b8af2864ef0dc9121eed3189ced64712bdb3d20 Reviewed-by: Friedemann Kleint Reviewed-by: Jens Bache-Wiig --- examples/quick/controls/text/qml/main.qml | 1 + 1 file changed, 1 insertion(+) (limited to 'examples/quick/controls/text/qml/main.qml') diff --git a/examples/quick/controls/text/qml/main.qml b/examples/quick/controls/text/qml/main.qml index d8f175ed..b2b863e2 100644 --- a/examples/quick/controls/text/qml/main.qml +++ b/examples/quick/controls/text/qml/main.qml @@ -319,6 +319,7 @@ ApplicationWindow { anchors.bottom: parent.bottom text: document.text textFormat: Qt.RichText + baseUrl: "qrc:/" Component.onCompleted: forceActiveFocus() } -- cgit v1.2.1 From 03c7e64ef5f3dfd10d61fd2473fb9f09b124c6e6 Mon Sep 17 00:00:00 2001 From: Caroline Chao Date: Fri, 14 Jun 2013 15:01:34 +0200 Subject: Revert "Add qml/js files in resource files" We need to investigate more this solution. Deployment issue for Qt Quick Controls will be a known limitation in 5.1.0. This reverts commit 41e13d3746c8b7b5cd550091c63fd8ab066422cf. Change-Id: I501be7494bdbdfbb799d31c612d0c20e7f87ffc7 Reviewed-by: Friedemann Kleint Reviewed-by: Jens Bache-Wiig Reviewed-by: Liang Qi --- examples/quick/controls/text/qml/main.qml | 1 - 1 file changed, 1 deletion(-) (limited to 'examples/quick/controls/text/qml/main.qml') diff --git a/examples/quick/controls/text/qml/main.qml b/examples/quick/controls/text/qml/main.qml index b2b863e2..d8f175ed 100644 --- a/examples/quick/controls/text/qml/main.qml +++ b/examples/quick/controls/text/qml/main.qml @@ -319,7 +319,6 @@ ApplicationWindow { anchors.bottom: parent.bottom text: document.text textFormat: Qt.RichText - baseUrl: "qrc:/" Component.onCompleted: forceActiveFocus() } -- cgit v1.2.1