From dbf42fc0028acc0170bb0d0dad966c74b86a456e Mon Sep 17 00:00:00 2001 From: Jens Bache-Wiig Date: Mon, 27 May 2013 15:51:08 +0200 Subject: Make GroupBox size respect anchor margins and update Gallery We now implicitly add the margins to GroupBox so that you can easily add them to a layout. This also gets rid of the silly Sidebar example and adds a much more useful Layout tab for effective testing. Change-Id: I6026c32b2a198062d9b11a67245df0529aa61f8a Reviewed-by: J-P Nurmi --- .../quick/controls/gallery/content/Layouts.qml | 108 ++++++++++++++++ examples/quick/controls/gallery/content/Panel.qml | 140 --------------------- examples/quick/controls/gallery/images/page.png | Bin 639 -> 0 bytes examples/quick/controls/gallery/images/panel.png | Bin 1756 -> 0 bytes examples/quick/controls/gallery/main.qml | 4 +- examples/quick/controls/gallery/resources.qrc | 4 +- 6 files changed, 111 insertions(+), 145 deletions(-) create mode 100644 examples/quick/controls/gallery/content/Layouts.qml delete mode 100644 examples/quick/controls/gallery/content/Panel.qml delete mode 100644 examples/quick/controls/gallery/images/page.png delete mode 100644 examples/quick/controls/gallery/images/panel.png (limited to 'examples/quick/controls') diff --git a/examples/quick/controls/gallery/content/Layouts.qml b/examples/quick/controls/gallery/content/Layouts.qml new file mode 100644 index 00000000..1251947a --- /dev/null +++ b/examples/quick/controls/gallery/content/Layouts.qml @@ -0,0 +1,108 @@ +/**************************************************************************** +** +** 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 +import QtQuick.Controls 1.0 +import QtQuick.Layouts 1.0 + +Item { + id:root + anchors.fill: parent + anchors.margins: 8 + + ColumnLayout { + id: mainLayout + anchors.fill: parent + spacing: 4 + GroupBox { + id: rowBox + title: "Row layout" + Layout.fillWidth: true + RowLayout { + id: rowLayout + anchors.fill: parent + TextField { + placeholderText: "This wants to grow horizontally" + Layout.fillWidth: true + } + Button { + text: "Button" + } + } + } + + GroupBox { + id: gridBox + title: "Grid layout" + Layout.fillWidth: true + + GridLayout { + id: gridLayout + anchors.fill: parent + anchors.margins: 4 + rows: 3 + flow: GridLayout.TopToBottom + + Label { text: "Line 1" } + Label { text: "Line 2" } + Label { text: "Line 3" } + + TextField { } + TextField { } + TextField { } + + TextArea { + text: "This widget spans over three rows in the GridLayout.\n" + + "All items in the GridLayout are implicitly positioned from top to bottom." + Layout.rowSpan: 3 + Layout.fillHeight: true + Layout.fillWidth: true + } + } + } + TextArea { + id: t3 + text: "This fills the whole cell" + Layout.minimumHeight: 30 + Layout.fillHeight: true + Layout.fillWidth: true + } + } +} diff --git a/examples/quick/controls/gallery/content/Panel.qml b/examples/quick/controls/gallery/content/Panel.qml deleted file mode 100644 index bdb10f83..00000000 --- a/examples/quick/controls/gallery/content/Panel.qml +++ /dev/null @@ -1,140 +0,0 @@ -/**************************************************************************** -** -** 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 -import QtQuick.Controls 1.0 - -Rectangle { - id:root - - width: 540 - height: 340 - color:"#c3c3c3" - ScrollView { - frameVisible: false - anchors.fill: parent - - Item { - width:600 - height:600 - BorderImage { - id: page - source: "../images/page.png" - y:10; x:50 - width: 400; height: 400 - border.left: 12; border.top: 12 - border.right: 12; border.bottom: 12 - Text { - id:text - anchors.fill: parent - anchors.margins: 40 - text:textfield.text - } - Rectangle { - border.color: "#444" - anchors.centerIn: parent - color: Qt.rgba(s1.value, s2.value, s3.value) - width: 200 - height: width - } - - } - - BorderImage { - id: sidebar - source: "../images/panel.png" - anchors.left: parent.left - anchors.top: parent.top - width: show ? 160 : 40 - height:root.height - Behavior on width { NumberAnimation { easing.type: Easing.OutSine ; duration: 250 } } - property bool show: false - border.left: 0; - border.right: 26; - MouseArea { - id:mouseArea - anchors.fill: parent - onClicked: sidebar.show = !sidebar.show - } - Column { - id: panel1 - opacity: sidebar.show ? 1 : 0 - Behavior on opacity { NumberAnimation { easing.type:Easing.InCubic; duration: 600} } - - scale: sidebar.show ? 1 : 0 - Behavior on scale { NumberAnimation { easing.type:Easing.InCubic; duration: 200 } } - transformOrigin: Item.Top - - anchors.top: parent.top - anchors.left: parent.left - anchors.right: parent.right - anchors.margins: 12 - spacing:12 - - Button { width: parent.width - 12; text: "Close Panel"; onClicked: sidebar.show = false} - TextField { id: textfield; text: "Some text" ; width: parent.width - 12} - SpinBox { width: parent.width - 12} - CheckBox{ id: expander; text:"Sliders"} - } - - Column { - id: panel2 - opacity: expander.checked && sidebar.show ? 1 : 0 - scale: opacity - Behavior on opacity{ NumberAnimation { easing.type:Easing.OutSine; duration: 300}} - transformOrigin: Item.Top - anchors.top: panel1.bottom - anchors.left: parent.left - anchors.right: parent.right - anchors.margins: 12 - spacing: 12 - Slider { id: s1; width:parent.width - 12; value:0.5} - Slider { id: s2; width:parent.width - 12; value:0.5} - Slider { id: s3; width:parent.width - 12; value:0.5} - - } - } - } - } -} diff --git a/examples/quick/controls/gallery/images/page.png b/examples/quick/controls/gallery/images/page.png deleted file mode 100644 index b46f205d..00000000 Binary files a/examples/quick/controls/gallery/images/page.png and /dev/null differ diff --git a/examples/quick/controls/gallery/images/panel.png b/examples/quick/controls/gallery/images/panel.png deleted file mode 100644 index 02d655eb..00000000 Binary files a/examples/quick/controls/gallery/images/panel.png and /dev/null differ diff --git a/examples/quick/controls/gallery/main.qml b/examples/quick/controls/gallery/main.qml index 7da74031..e34858cd 100644 --- a/examples/quick/controls/gallery/main.qml +++ b/examples/quick/controls/gallery/main.qml @@ -281,8 +281,8 @@ ApplicationWindow { Styles { anchors.fill: parent } } Tab { - title: "Sidebar" - Panel { anchors.fill:parent } + title: "Layouts" + Layouts { anchors.fill:parent } } } } diff --git a/examples/quick/controls/gallery/resources.qrc b/examples/quick/controls/gallery/resources.qrc index 14e88e52..21362787 100644 --- a/examples/quick/controls/gallery/resources.qrc +++ b/examples/quick/controls/gallery/resources.qrc @@ -5,18 +5,16 @@ content/Controls.qml content/ImageViewer.qml content/ModelView.qml - content/Panel.qml + content/Layouts.qml content/Styles.qml images/document-open.png images/document-open@2x.png images/document-save-as.png images/document-save-as@2x.png images/folder_new.png - images/page.png images/tab.png images/tab_selected.png images/window-new.png images/window-new@2x.png - images/panel.png -- cgit v1.2.1 From bb64aef56bd43891bd6f91aee25bdfe6633c3a98 Mon Sep 17 00:00:00 2001 From: Jens Bache-Wiig Date: Mon, 27 May 2013 17:54:54 +0200 Subject: Refactor TableView styling API We don't want to directly expose the item properties in the namespace of the loader. Instead we standardize on styleData as a property container. Change-Id: Ib451e06ab393ba4945c96076d71dd3f96489e0c7 Reviewed-by: J-P Nurmi --- examples/quick/controls/tableview/main.qml | 86 ++++++++++++------------------ 1 file changed, 35 insertions(+), 51 deletions(-) (limited to 'examples/quick/controls') diff --git a/examples/quick/controls/tableview/main.qml b/examples/quick/controls/tableview/main.qml index 0e568314..02c7e6f0 100644 --- a/examples/quick/controls/tableview/main.qml +++ b/examples/quick/controls/tableview/main.qml @@ -183,7 +183,7 @@ Window { itemDelegate: Item { Rectangle{ - color: itemValue.get(0).color + color: styleData.value.get(0).color anchors.top:parent.top anchors.right:parent.right anchors.bottom:parent.bottom @@ -196,9 +196,9 @@ Window { anchors.margins: 4 anchors.left: parent.left anchors.verticalCenter: parent.verticalCenter - elide: itemElideMode - text: itemValue.get(0).description - color: itemTextColor + elide: styleData.elideMode + text: styleData.value.get(0).description + color: styleData.textColor } } @@ -251,32 +251,23 @@ Window { anchors.margins: 4 anchors.left: parent.left anchors.verticalCenter: parent.verticalCenter - elide: itemElideMode - text: itemValue !== undefined ? itemValue : "" - color: itemTextColor + elide: styleData.elideMode + text: styleData.value !== undefined ? styleData.value : "" + color: styleData.textColor } } } - Component { - id: slickRowDelegate - Rectangle { color: alternateBackground ? "#cef" : "white" } - } - Component { id: delegate2 - Item { - height: itemSelected? 60 : 20 - Behavior on height{ NumberAnimation{} } - Text { - width: parent.width - anchors.margins: 4 - anchors.left: parent.left - anchors.verticalCenter: parent.verticalCenter - elide: itemElideMode - text: itemValue !== undefined ? itemValue : "" - color: itemTextColor - } + Text { + width: parent.width + anchors.margins: 4 + anchors.left: parent.left + anchors.verticalCenter: parent.verticalCenter + elide: styleData.elideMode + text: styleData.value !== undefined ? styleData.value : "" + color: styleData.textColor } } @@ -289,10 +280,10 @@ Window { anchors.margins: 4 anchors.left: parent.left anchors.verticalCenter: parent.verticalCenter - elide: itemElideMode - text: itemValue !== undefined ? itemValue : "" - color: itemTextColor - visible: !itemSelected + elide: styleData.elideMode + text: styleData.value !== undefined ? styleData.value : "" + color: styleData.textColor + visible: !styleData.selected } Loader { // Initialize text editor lazily to improve performance id: loaderEditor @@ -301,19 +292,19 @@ Window { Connections { target: loaderEditor.item onAccepted: { - if (typeof itemValue === 'number') - model.setProperty(row, role, Number(parseFloat(loaderEditor.item.text).toFixed(0))) + if (typeof styleData.value === 'number') + model.setProperty(styleData.row, styleData.role, Number(parseFloat(loaderEditor.item.text).toFixed(0))) else - model.setProperty(row, role, loaderEditor.item.text) + model.setProperty(styleData.row, styleData.role, loaderEditor.item.text) } } - sourceComponent: itemSelected ? editor : null + sourceComponent: styleData.selected ? editor : null Component { id: editor TextInput { id: textinput - color: itemTextColor - text: itemValue + color: styleData.textColor + text: styleData.value MouseArea { id: mouseArea anchors.fill: parent @@ -354,25 +345,22 @@ Window { source: "images/header.png" border{left:2;right:2;top:2;bottom:2} Text { - text: itemValue + text: styleData.value anchors.centerIn:parent color:"#333" } } rowDelegate: Rectangle { - height: 20 - color: rowSelected ? "#448" : (alternateBackground ? "#eee" : "#fff") - border.color:"#ccc" - border.width: 1 - anchors.left: parent ? parent.left : undefined - anchors.leftMargin: -2 - anchors.rightMargin: -1 + height: (delegateChooser.currentIndex == 1 && styleData.selected) ? 30 : 20 + Behavior on height{ NumberAnimation{} } + + color: styleData.selected ? "#448" : (styleData.alternate? "#eee" : "#fff") BorderImage{ id: selected anchors.fill: parent source: "images/selectedrow.png" - visible: rowSelected + visible: styleData.selected border{left:2; right:2; top:2; bottom:2} SequentialAnimation { running: true; loops: Animation.Infinite @@ -383,14 +371,10 @@ Window { } itemDelegate: { - switch (delegateChooser.currentIndex) { - case 0: - return delegate1 - case 1: - return delegate2 - case 2: - return editableDelegate - } + if (delegateChooser.currentIndex == 2) + return editableDelegate; + else + return delegate1; } } } -- cgit v1.2.1 From e0c8035c3db5c3c68602a90a5addbb2d48c0733f Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Mon, 27 May 2013 18:34:37 +0200 Subject: Rename controlState to styleData Change-Id: I06c9f4b0d9b6eef7d2ca608827eee982d8d97027 Reviewed-by: Jens Bache-Wiig --- examples/quick/controls/tableview/main.qml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'examples/quick/controls') diff --git a/examples/quick/controls/tableview/main.qml b/examples/quick/controls/tableview/main.qml index 02c7e6f0..3ecf5ddb 100644 --- a/examples/quick/controls/tableview/main.qml +++ b/examples/quick/controls/tableview/main.qml @@ -104,9 +104,9 @@ Window { ListModel { id: nestedModel - ListElement{controlState: ListElement { description: "Core" ; color:"#ffaacc"}} - ListElement{controlState: ListElement { description: "Second" ; color:"#ffccaa"}} - ListElement{controlState: ListElement { description: "Third" ; color:"#ffffaa"}} + ListElement{content: ListElement { description: "Core" ; color:"#ffaacc"}} + ListElement{content: ListElement { description: "Second" ; color:"#ffccaa"}} + ListElement{content: ListElement { description: "Third" ; color:"#ffffaa"}} } ListModel { @@ -176,7 +176,7 @@ Window { anchors.margins: 12 TableViewColumn { - role: "controlState" + role: "content" title: "Text and Color" width: 220 } -- cgit v1.2.1 From 2f2933a2975d86bfb33e2250a03b2414fc207a09 Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Mon, 27 May 2013 18:43:37 +0200 Subject: TabViewStyle: rename 'tab' grouped property to 'styleData' Change-Id: If56b5ca4af119d7897425609dcaf04336f77e032 Reviewed-by: Jens Bache-Wiig --- examples/quick/controls/gallery/content/Styles.qml | 4 ++-- examples/quick/controls/touch/content/TabBarPage.qml | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'examples/quick/controls') diff --git a/examples/quick/controls/gallery/content/Styles.qml b/examples/quick/controls/gallery/content/Styles.qml index b5e98f80..a65f3024 100644 --- a/examples/quick/controls/gallery/content/Styles.qml +++ b/examples/quick/controls/gallery/content/Styles.qml @@ -258,13 +258,13 @@ Item { BorderImage { id: image anchors.fill: parent - source: tab.selected ? "../images/tab_selected.png" : "../images/tab.png" + source: styleData.selected ? "../images/tab_selected.png" : "../images/tab.png" border.left: 50 smooth: false border.right: 50 } Text { - text: tab.title + text: styleData.title anchors.centerIn: parent } } diff --git a/examples/quick/controls/touch/content/TabBarPage.qml b/examples/quick/controls/touch/content/TabBarPage.qml index c96314be..7651a3c1 100644 --- a/examples/quick/controls/touch/content/TabBarPage.qml +++ b/examples/quick/controls/touch/content/TabBarPage.qml @@ -80,11 +80,11 @@ Item { anchors.fill: parent border.bottom: 8 border.top: 8 - source: tab.selected ? "../images/tab_selected.png":"../images/tabs_standard.png" + source: styleData.selected ? "../images/tab_selected.png":"../images/tabs_standard.png" Text { anchors.centerIn: parent color: "white" - text: tab.title.toUpperCase() + text: styleData.title.toUpperCase() font.pixelSize: 16 } Rectangle { -- cgit v1.2.1 From d0eadc7b164d2f00cd19885907d57a4e1aa02d4b Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Mon, 27 May 2013 19:57:46 +0200 Subject: ButtonStyle: expose styleData.hovered Change-Id: I8f977a171ea18420e326b79181d634eeb43b1de8 Reviewed-by: Jens Bache-Wiig --- examples/quick/controls/gallery/content/Styles.qml | 24 +++++++++------------- 1 file changed, 10 insertions(+), 14 deletions(-) (limited to 'examples/quick/controls') diff --git a/examples/quick/controls/gallery/content/Styles.qml b/examples/quick/controls/gallery/content/Styles.qml index a65f3024..01b2646f 100644 --- a/examples/quick/controls/gallery/content/Styles.qml +++ b/examples/quick/controls/gallery/content/Styles.qml @@ -172,17 +172,13 @@ Item { // Style delegates: property Component buttonStyle: ButtonStyle { - panel: Rectangle { + background: Rectangle { implicitHeight: 20 implicitWidth: 100 color: control.pressed ? "darkGray" : "lightGray" antialiasing: true border.color: "gray" radius: height/2 - Text { - anchors.centerIn: parent - text: control.text - } } } @@ -220,21 +216,21 @@ Item { } property Component progressbarStyle: ProgressBarStyle { - panel: Rectangle { + background: Rectangle { implicitWidth: 100 implicitHeight: 20 color: "#f0f0f0" border.color: "gray" antialiasing: true radius: height/2 - Rectangle { - implicitWidth: 100 - implicitHeight: 20 - color: "#f0f0f0" - border.color: "gray" - antialiasing: true - radius: height/2 - } + } + progress: Rectangle { + implicitWidth: 100 + implicitHeight: 20 + color: "#c0c0c0" + border.color: "gray" + antialiasing: true + radius: height/2 } } -- cgit v1.2.1 From 44be216fda6590225dd45fb565361d6328a482f4 Mon Sep 17 00:00:00 2001 From: Caroline Chao Date: Tue, 28 May 2013 11:08:48 +0200 Subject: Gallery example: Increase minimumWidth Change-Id: I3f97de79c8afed44f7b01778d94cc40bed8cc603 Reviewed-by: Jens Bache-Wiig Reviewed-by: Caroline Chao --- examples/quick/controls/gallery/main.qml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'examples/quick/controls') diff --git a/examples/quick/controls/gallery/main.qml b/examples/quick/controls/gallery/main.qml index e34858cd..93502423 100644 --- a/examples/quick/controls/gallery/main.qml +++ b/examples/quick/controls/gallery/main.qml @@ -51,10 +51,11 @@ import "content" ApplicationWindow { title: "Component Gallery" - width: 580 + width: 600 height: 400 minimumHeight: 400 - minimumWidth: 340 + minimumWidth: 570 + property string loremIpsum: "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor "+ "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor "+ -- cgit v1.2.1 From 6e62a72c72abc5ad6e241541208a36378d448853 Mon Sep 17 00:00:00 2001 From: Jens Bache-Wiig Date: Tue, 28 May 2013 10:19:30 +0200 Subject: Improved size calculation of GroupBox This adds some pixel tweaks on mac, adds minimum size to fit the label and fixes dpi scaling on Windows Change-Id: I4c43ba4a7815be87356336a9dafc1a217437940b Reviewed-by: Gabriel de Dietrich --- examples/quick/controls/gallery/content/Layouts.qml | 1 - 1 file changed, 1 deletion(-) (limited to 'examples/quick/controls') diff --git a/examples/quick/controls/gallery/content/Layouts.qml b/examples/quick/controls/gallery/content/Layouts.qml index 1251947a..ac0a53a3 100644 --- a/examples/quick/controls/gallery/content/Layouts.qml +++ b/examples/quick/controls/gallery/content/Layouts.qml @@ -76,7 +76,6 @@ Item { GridLayout { id: gridLayout anchors.fill: parent - anchors.margins: 4 rows: 3 flow: GridLayout.TopToBottom -- cgit v1.2.1 From f6a716a11a26e2ce76f8ed71ad1733e939ca468b Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Wed, 29 May 2013 16:17:02 +0200 Subject: Remove remaining references to PageStack Change-Id: I59a9846c83340d0752659ef22cbb19a4be6a4129 Reviewed-by: Jens Bache-Wiig Reviewed-by: Gabriel de Dietrich --- examples/quick/controls/touch/content/ButtonPage.qml | 2 +- examples/quick/controls/touch/main.qml | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) (limited to 'examples/quick/controls') diff --git a/examples/quick/controls/touch/content/ButtonPage.qml b/examples/quick/controls/touch/content/ButtonPage.qml index 635ce3b9..f431a52e 100644 --- a/examples/quick/controls/touch/content/ButtonPage.qml +++ b/examples/quick/controls/touch/content/ButtonPage.qml @@ -86,7 +86,7 @@ Item { anchors.margins: 20 style: touchStyle text: "Dont press me" - onClicked: if (pageStack) pageStack.pop() + onClicked: if (stackView) stackView.pop() } } diff --git a/examples/quick/controls/touch/main.qml b/examples/quick/controls/touch/main.qml index 3058a0d3..9f93cb78 100644 --- a/examples/quick/controls/touch/main.qml +++ b/examples/quick/controls/touch/main.qml @@ -54,8 +54,8 @@ ApplicationWindow { // Implements back key navigation Keys.onReleased: { if (event.key === Qt.Key_Back) { - if (pageStack.depth > 1) { - pageStack.pop(); + if (stackView.depth > 1) { + stackView.pop(); event.accepted = true; } else { Qt.quit(); } } @@ -72,7 +72,7 @@ ApplicationWindow { width: opacity ? 60 : 0 anchors.left: parent.left anchors.leftMargin: 20 - opacity: pageStack.depth > 1 ? 1 : 0 + opacity: stackView.depth > 1 ? 1 : 0 anchors.verticalCenter: parent.verticalCenter antialiasing: true height: 60 @@ -87,7 +87,7 @@ ApplicationWindow { id: backmouse anchors.fill: parent anchors.margins: -10 - onClicked: pageStack.pop() + onClicked: stackView.pop() } } @@ -126,7 +126,7 @@ ApplicationWindow { } StackView { - id: pageStack + id: stackView anchors.fill: parent initialItem: Item { @@ -137,7 +137,7 @@ ApplicationWindow { anchors.fill: parent delegate: AndroidDelegate { text: title - onClicked: pageStack.push(Qt.resolvedUrl(page)) + onClicked: stackView.push(Qt.resolvedUrl(page)) } } } -- cgit v1.2.1 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 --- .../quick/controls/gallery/content/Controls.qml | 8 + examples/quick/controls/gallery/content/Styles.qml | 229 +++++++++++---------- examples/quick/controls/gallery/main.qml | 216 ++++++++----------- examples/quick/controls/splitview/main.qml | 8 - .../quick/controls/text/qml/ToolBarSeparator.qml | 61 ++++++ examples/quick/controls/text/qml/main.qml | 77 ++++--- examples/quick/controls/text/resources.qrc | 1 + .../quick/controls/text/src/documenthandler.cpp | 12 +- examples/quick/controls/text/text.pro | 3 +- 9 files changed, 325 insertions(+), 290 deletions(-) create mode 100644 examples/quick/controls/text/qml/ToolBarSeparator.qml (limited to 'examples/quick/controls') diff --git a/examples/quick/controls/gallery/content/Controls.qml b/examples/quick/controls/gallery/content/Controls.qml index 310eee59..c1403da5 100644 --- a/examples/quick/controls/gallery/content/Controls.qml +++ b/examples/quick/controls/gallery/content/Controls.qml @@ -180,6 +180,14 @@ Item { height: parent.height - group1.height - group2.height - 2 * parent.spacing anchors { right: parent.right } } + + MouseArea { + id: contextMenu + parent: area.viewport + anchors.fill: parent + acceptedButtons: Qt.RightButton + onPressed: editmenu.popup() + } } } } diff --git a/examples/quick/controls/gallery/content/Styles.qml b/examples/quick/controls/gallery/content/Styles.qml index 01b2646f..97797f83 100644 --- a/examples/quick/controls/gallery/content/Styles.qml +++ b/examples/quick/controls/gallery/content/Styles.qml @@ -45,127 +45,132 @@ import QtQuick 2.1 import QtQuick.Controls 1.0 import QtQuick.Controls.Styles 1.0 -import QtQuick.Dialogs 1.0 +import QtQuick.Layouts 1.0 Item { id: root width: 300 height: 200 - ColorDialog { - id: colorDialog - color: "#afe" - property color last: "#afe" - onRejected: color = last - onVisibleChanged: if (visible) last = color - } - - Column { - anchors.margins: 20 - anchors.horizontalCenter: parent.horizontalCenter + property int columnWidth: 120 + GridLayout { + rowSpacing: 12 + columnSpacing: 30 anchors.top: parent.top - spacing: 20 + anchors.horizontalCenter: parent.horizontalCenter + anchors.margins: 30 - Row { - spacing: 8 - Button { - text: "Set color…" - style: ButtonStyle { } - onClicked: colorDialog.open() - } - Button { - text: "Push me" - style: ButtonStyle { } - } - Button { - text: "Push me" - style: buttonStyle - } + Button { + text: "Push me" + style: ButtonStyle { } + onClicked: colorDialog.open() + implicitWidth: columnWidth } - Row { - spacing: 8 - TextField { - style: TextFieldStyle { } - } - TextField { - style: TextFieldStyle { } - } - TextField { - style: textfieldStyle - } + Button { + text: "Push me" + style: ButtonStyle { } + implicitWidth: columnWidth + } + Button { + text: "Push me" + style: buttonStyle + implicitWidth: columnWidth } - Row { - spacing: 8 - Slider { - value: 50 - maximumValue: 100 - width: 100 - style: SliderStyle { } - } - Slider { - value: 50 - maximumValue: 100 - width: 100 - style: SliderStyle { } - } - Slider { - value: 50 - maximumValue: 100 - width: 100 - style: sliderStyle - } + TextField { + Layout.row: 1 + style: TextFieldStyle { } + implicitWidth: columnWidth + } + TextField { + style: TextFieldStyle { } + implicitWidth: columnWidth + } + TextField { + style: textfieldStyle + implicitWidth: columnWidth } - Row { - spacing: 8 - ProgressBar { - value: 50 - maximumValue: 100 - width: 100 - style: ProgressBarStyle{ } - } - ProgressBar { - value: 50 - maximumValue: 100 - width: 100 - style: ProgressBarStyle{ } - } - ProgressBar { - value: 50 - maximumValue: 100 - width: 100 - style: progressbarStyle - } + Slider { + Layout.row: 2 + value: 50 + maximumValue: 100 + implicitWidth: columnWidth + style: SliderStyle { } + } + Slider { + value: 50 + maximumValue: 100 + implicitWidth: columnWidth + style: SliderStyle { } + } + Slider { + value: 50 + maximumValue: 100 + implicitWidth: columnWidth + style: sliderStyle } - Row { - spacing: 8 - CheckBox { - text: "CheckBox" - style: CheckBoxStyle{} - } - RadioButton { - style: RadioButtonStyle{} - text: "RadioButton" - } + ProgressBar { + Layout.row: 3 + value: 50 + maximumValue: 100 + implicitWidth: columnWidth + style: ProgressBarStyle{ } + } + ProgressBar { + value: 50 + maximumValue: 100 + implicitWidth: columnWidth + style: ProgressBarStyle{ } + } + ProgressBar { + value: 50 + maximumValue: 100 + implicitWidth: columnWidth + style: progressbarStyle + } - ComboBox { - model: ["Paris", "Oslo", "New York"] - style: ComboBoxStyle{} - } + CheckBox { + text: "CheckBox" + style: CheckBoxStyle{} + Layout.row: 4 + implicitWidth: columnWidth + } + RadioButton { + style: RadioButtonStyle{} + text: "RadioButton" + implicitWidth: columnWidth } - Row { - TabView { - width: 400 - height: 30 - Tab { title: "One" ; Item {}} - Tab { title: "Two" ; Item {}} - Tab { title: "Three" ; Item {}} - Tab { title: "Four" ; Item {}} - style: tabViewStyle - } + ComboBox { + model: ["Paris", "Oslo", "New York"] + style: ComboBoxStyle{} + implicitWidth: columnWidth + } + + TabView { + Layout.row: 5 + Layout.columnSpan: 3 + Layout.fillWidth: true + implicitHeight: 30 + Tab { title: "One" ; Item {}} + Tab { title: "Two" ; Item {}} + Tab { title: "Three" ; Item {}} + Tab { title: "Four" ; Item {}} + style: TabViewStyle {} + } + + TabView { + Layout.row: 6 + Layout.columnSpan: 3 + Layout.fillWidth: true + implicitHeight: 30 + Tab { title: "One" ; Item {}} + Tab { title: "Two" ; Item {}} + Tab { title: "Three" ; Item {}} + Tab { title: "Four" ; Item {}} + style: tabViewStyle } } @@ -174,7 +179,7 @@ Item { property Component buttonStyle: ButtonStyle { background: Rectangle { implicitHeight: 20 - implicitWidth: 100 + implicitWidth: columnWidth color: control.pressed ? "darkGray" : "lightGray" antialiasing: true border.color: "gray" @@ -184,7 +189,7 @@ Item { property Component textfieldStyle: TextFieldStyle { background: Rectangle { - implicitWidth: 100 + implicitWidth: columnWidth implicitHeight: 20 color: "#f0f0f0" antialiasing: true @@ -205,7 +210,7 @@ Item { groove: Rectangle { height: 8 - implicitWidth: 100 + implicitWidth: columnWidth implicitHeight: 20 antialiasing: true @@ -217,7 +222,7 @@ Item { property Component progressbarStyle: ProgressBarStyle { background: Rectangle { - implicitWidth: 100 + implicitWidth: columnWidth implicitHeight: 20 color: "#f0f0f0" border.color: "gray" @@ -225,7 +230,7 @@ Item { radius: height/2 } progress: Rectangle { - implicitWidth: 100 + implicitWidth: columnWidth implicitHeight: 20 color: "#c0c0c0" border.color: "gray" @@ -246,18 +251,18 @@ Item { } border.color: "#898989" Rectangle { anchors.fill: parent ; anchors.margins: 1 ; border.color: "white" ; color: "transparent" } - } tab: Item { - implicitWidth: image.sourceSize.width + property int totalOverlap: tabOverlap * (control.count - 1) + implicitWidth: Math.min ((styleData.availableWidth + totalOverlap)/control.count - 4, image.sourceSize.width) implicitHeight: image.sourceSize.height BorderImage { id: image anchors.fill: parent source: styleData.selected ? "../images/tab_selected.png" : "../images/tab.png" - border.left: 50 + border.left: 30 smooth: false - border.right: 50 + border.right: 30 } Text { text: styleData.title diff --git a/examples/quick/controls/gallery/main.qml b/examples/quick/controls/gallery/main.qml index 93502423..86dddbe2 100644 --- a/examples/quick/controls/gallery/main.qml +++ b/examples/quick/controls/gallery/main.qml @@ -70,150 +70,112 @@ ApplicationWindow { onAccepted: imageViewer.open(fileUrl) } - toolBar: ToolBar { - id: toolbar - RowLayout { - spacing: 2 - anchors.verticalCenter: parent.verticalCenter - ToolButton { - iconSource: "images/window-new.png" - anchors.verticalCenter: parent.verticalCenter - onClicked: window1.visible = !window1.visible - Accessible.name: "New window" - tooltip: "Toggle visibility of the second window" - } - ToolButton { - action: openAction - } - ToolButton { - iconSource: "images/document-save-as.png" - anchors.verticalCenter: parent.verticalCenter - tooltip: "(Pretend to) save as..." - } - } + Action { + id: openAction + text: "&Open" + shortcut: "Ctrl+O" + iconSource: "images/document-open.png" + onTriggered: fileDialog.open() + tooltip: "open an image" + } - ChildWindow { id: window1 } + Action { + id: copyAction + text: "&Copy" + shortcut: "Ctrl+C" + iconName: "edit-copy" + enabled: (!!activeFocusItem && !!activeFocusItem["copy"]) + onTriggered: activeFocusItem.copy() + } - Action { - id: openAction - text: "&Open" - shortcut: "Ctrl+O" - iconSource: "images/document-open.png" - onTriggered: fileDialog.open() - tooltip: "open an image" - } + Action { + id: cutAction + text: "Cu&t" + shortcut: "Ctrl+X" + iconName: "edit-cut" + enabled: (!!activeFocusItem && !!activeFocusItem["cut"]) + onTriggered: activeFocusItem.cut() + } + + Action { + id: pasteAction + text: "&Paste" + shortcut: "Ctrl+V" + iconName: "edit-paste" + enabled: (!!activeFocusItem && !!activeFocusItem["paste"]) + onTriggered: activeFocusItem.paste() + } + + ExclusiveGroup { + id: textFormatGroup Action { - id: copyAction - text: "&Copy" - shortcut: "Ctrl+C" - iconName: "edit-copy" - enabled: (!!activeFocusItem && !!activeFocusItem["copy"]) - onTriggered: activeFocusItem.copy() + id: a1 + text: "Align Left" + checkable: true + Component.onCompleted: checked = true } Action { - id: cutAction - text: "Cu&t" - shortcut: "Ctrl+X" - iconName: "edit-cut" - enabled: (!!activeFocusItem && !!activeFocusItem["cut"]) - onTriggered: activeFocusItem.cut() + id: a2 + text: "Center" + checkable: true } Action { - id: pasteAction - text: "&Paste" - shortcut: "Ctrl+V" - iconName: "edit-paste" - enabled: (!!activeFocusItem && !!activeFocusItem["paste"]) - onTriggered: activeFocusItem.paste() + id: a3 + text: "Align Right" + checkable: true } + } - ExclusiveGroup { - id: textFormatGroup - - Action { - id: a1 - text: "Align Left" - checkable: true - Component.onCompleted: checked = true - } - - Action { - id: a2 - text: "Center" - checkable: true - } - - Action { - id: a3 - text: "Align Right" - checkable: true - } - } + ChildWindow { id: window1 } + Menu { + id: editmenu + MenuItem { action: cutAction } + MenuItem { action: copyAction } + MenuItem { action: pasteAction } + MenuSeparator {} Menu { - id: editmenu - MenuItem { action: cutAction } - MenuItem { action: copyAction } - MenuItem { action: pasteAction } - MenuSeparator {} - Menu { - title: "Text Format" - MenuItem { action: a1 } - MenuItem { action: a2 } - MenuItem { action: a3 } - MenuSeparator { } - MenuItem { text: "Allow Hyphenation"; checkable: true } - MenuSeparator { } - Menu { - title: "More Stuff" - MenuItem { action: cutAction } - MenuItem { action: copyAction } - MenuItem { action: pasteAction } - MenuSeparator { } - Menu { - title: "More Stuff" - MenuItem { action: cutAction } - MenuItem { action: copyAction } - MenuItem { action: pasteAction } - MenuSeparator { } - Menu { - title: "More Stuff" - MenuItem { action: cutAction } - MenuItem { action: copyAction } - MenuItem { action: pasteAction } - MenuSeparator { } - Menu { - title: "More Stuff" - MenuItem { action: cutAction } - MenuItem { action: copyAction } - MenuItem { action: pasteAction } - } - } - } - } - } - Menu { - title: "Font Style" - MenuItem { text: "Bold"; checkable: true } - MenuItem { text: "Italic"; checkable: true } - MenuItem { text: "Underline"; checkable: true } - } + title: "Text Format" + MenuItem { action: a1 } + MenuItem { action: a2 } + MenuItem { action: a3 } + MenuSeparator { } + MenuItem { text: "Allow Hyphenation"; checkable: true } } - MouseArea { - anchors.fill: parent - acceptedButtons: Qt.RightButton - onPressed: editmenu.popup() + Menu { + title: "Font Style" + MenuItem { text: "Bold"; checkable: true } + MenuItem { text: "Italic"; checkable: true } + MenuItem { text: "Underline"; checkable: true } } + } - CheckBox { - id: enabledCheck - text: "Enabled" - checked: true - anchors.right: parent.right - anchors.verticalCenter: parent.verticalCenter + toolBar: ToolBar { + id: toolbar + RowLayout { + id: toolbarLayout + spacing: 0 + width: parent.width + ToolButton { + iconSource: "images/window-new.png" + onClicked: window1.visible = !window1.visible + Accessible.name: "New window" + tooltip: "Toggle visibility of the second window" + } + ToolButton { action: openAction } + ToolButton { + iconSource: "images/document-save-as.png" + tooltip: "(Pretend to) save as..." + } + Item { Layout.fillWidth: true } + CheckBox { + id: enabledCheck + text: "Enabled" + checked: true + } } } diff --git a/examples/quick/controls/splitview/main.qml b/examples/quick/controls/splitview/main.qml index f035e644..4fa8504a 100644 --- a/examples/quick/controls/splitview/main.qml +++ b/examples/quick/controls/splitview/main.qml @@ -61,14 +61,6 @@ ApplicationWindow { color: "lightsteelblue" } - Rectangle { - id: column1 - width: 200 - Layout.minimumWidth: 100 - Layout.maximumWidth: 300 - color: "lightsteelblue" - } - SplitView { orientation: Qt.Vertical Layout.fillWidth: true 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/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 - } } } diff --git a/examples/quick/controls/text/resources.qrc b/examples/quick/controls/text/resources.qrc index e67fac6a..4d137ff7 100644 --- a/examples/quick/controls/text/resources.qrc +++ b/examples/quick/controls/text/resources.qrc @@ -1,6 +1,7 @@ qml/main.qml + qml/ToolBarSeparator.qml qml/images/logo32.png qml/images/editcopy.png qml/images/editcut.png diff --git a/examples/quick/controls/text/src/documenthandler.cpp b/examples/quick/controls/text/src/documenthandler.cpp index 48b6d033..81eb744b 100644 --- a/examples/quick/controls/text/src/documenthandler.cpp +++ b/examples/quick/controls/text/src/documenthandler.cpp @@ -166,13 +166,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 +186,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 +195,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 +203,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 +211,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(); } 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 -- cgit v1.2.1 From eeb3c959334d1e6b4ea9f7538b603a711f8a8262 Mon Sep 17 00:00:00 2001 From: Gabriel de Dietrich Date: Mon, 3 Jun 2013 14:05:26 +0200 Subject: Buttons: Allow overriding of visual properties when 'action' is set Those properties are, text, tooltip, iconName, and iconSource. Also, properly capitalized gallery's tooltips. Change-Id: I1995a85565edd7aaa420279821d7c1a31ef18253 Reviewed-by: J-P Nurmi Reviewed-by: Jens Bache-Wiig --- examples/quick/controls/gallery/main.qml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'examples/quick/controls') diff --git a/examples/quick/controls/gallery/main.qml b/examples/quick/controls/gallery/main.qml index 86dddbe2..8ea3cf9e 100644 --- a/examples/quick/controls/gallery/main.qml +++ b/examples/quick/controls/gallery/main.qml @@ -76,7 +76,7 @@ ApplicationWindow { shortcut: "Ctrl+O" iconSource: "images/document-open.png" onTriggered: fileDialog.open() - tooltip: "open an image" + tooltip: "Open an image" } Action { @@ -168,7 +168,7 @@ ApplicationWindow { ToolButton { action: openAction } ToolButton { iconSource: "images/document-save-as.png" - tooltip: "(Pretend to) save as..." + tooltip: "(Pretend to) Save as..." } Item { Layout.fillWidth: true } CheckBox { -- cgit v1.2.1 From 86df745c940cd54ca9c7b11347ee4a80b7a5577c Mon Sep 17 00:00:00 2001 From: Caroline Chao Date: Mon, 3 Jun 2013 15:44:10 +0200 Subject: Gallery: remove reference to colorDialog Change-Id: I0433e350634b4a2bea6161f53e7c7363654e2cf6 Reviewed-by: Jens Bache-Wiig --- examples/quick/controls/gallery/content/Styles.qml | 1 - 1 file changed, 1 deletion(-) (limited to 'examples/quick/controls') diff --git a/examples/quick/controls/gallery/content/Styles.qml b/examples/quick/controls/gallery/content/Styles.qml index 97797f83..3a7d2bfd 100644 --- a/examples/quick/controls/gallery/content/Styles.qml +++ b/examples/quick/controls/gallery/content/Styles.qml @@ -63,7 +63,6 @@ Item { Button { text: "Push me" style: ButtonStyle { } - onClicked: colorDialog.open() implicitWidth: columnWidth } Button { -- cgit v1.2.1 From e6ea417c15aa760e8b1a88e5db362f9642d1589e Mon Sep 17 00:00:00 2001 From: Jens Bache-Wiig Date: Wed, 5 Jun 2013 15:46:48 +0200 Subject: Improve the Styles page and add missing SliderStyle property - I noticed we incorrectly exposed sliderPosition. - This adds some more custom style examples for the gallery and makes the second column actually different from the first. Change-Id: I73f0d613f51f6e75aaf734fd4e4c9fdb890e3e42 Reviewed-by: Caroline Chao --- examples/quick/controls/gallery/content/Styles.qml | 181 +++++++++++++++++---- examples/quick/controls/gallery/images/bubble.png | Bin 0 -> 214 bytes .../controls/gallery/images/button-pressed.png | Bin 0 -> 3094 bytes examples/quick/controls/gallery/images/button.png | Bin 0 -> 3164 bytes .../gallery/images/progress-background.png | Bin 0 -> 456 bytes .../controls/gallery/images/progress-fill.png | Bin 0 -> 507 bytes .../controls/gallery/images/slider-handle.png | Bin 0 -> 3523 bytes .../quick/controls/gallery/images/textfield.png | Bin 0 -> 3023 bytes examples/quick/controls/gallery/resources.qrc | 7 + 9 files changed, 154 insertions(+), 34 deletions(-) create mode 100644 examples/quick/controls/gallery/images/bubble.png create mode 100644 examples/quick/controls/gallery/images/button-pressed.png create mode 100644 examples/quick/controls/gallery/images/button.png create mode 100644 examples/quick/controls/gallery/images/progress-background.png create mode 100644 examples/quick/controls/gallery/images/progress-fill.png create mode 100644 examples/quick/controls/gallery/images/slider-handle.png create mode 100644 examples/quick/controls/gallery/images/textfield.png (limited to 'examples/quick/controls') diff --git a/examples/quick/controls/gallery/content/Styles.qml b/examples/quick/controls/gallery/content/Styles.qml index 3a7d2bfd..e46a9ea0 100644 --- a/examples/quick/controls/gallery/content/Styles.qml +++ b/examples/quick/controls/gallery/content/Styles.qml @@ -45,6 +45,7 @@ import QtQuick 2.1 import QtQuick.Controls 1.0 import QtQuick.Controls.Styles 1.0 +import QtQuick.Particles 2.0 import QtQuick.Layouts 1.0 Item { @@ -67,7 +68,12 @@ Item { } Button { text: "Push me" - style: ButtonStyle { } + style: ButtonStyle { + background: BorderImage { + source: control.pressed ? "../images/button-pressed.png" : "../images/button.png" + border.left: 4 ; border.right: 4 ; border.top: 4 ; border.bottom: 4 + } + } implicitWidth: columnWidth } Button { @@ -82,7 +88,12 @@ Item { implicitWidth: columnWidth } TextField { - style: TextFieldStyle { } + style: TextFieldStyle { + background: BorderImage { + source: "../images/textfield.png" + border.left: 4 ; border.right: 4 ; border.top: 4 ; border.bottom: 4 + } + } implicitWidth: columnWidth } TextField { @@ -91,43 +102,65 @@ Item { } Slider { + id: slider1 Layout.row: 2 - value: 50 - maximumValue: 100 + value: 0.5 implicitWidth: columnWidth style: SliderStyle { } } Slider { - value: 50 - maximumValue: 100 + id: slider2 + value: 0.5 implicitWidth: columnWidth - style: SliderStyle { } + style: SliderStyle { + groove: BorderImage { + height: 6 + border.top: 1 + border.bottom: 1 + source: "../images/progress-background.png" + border.left: 6 + border.right: 6 + BorderImage { + anchors.verticalCenter: parent.verticalCenter + source: "../images/progress-fill.png" + border.left: 5 ; border.top: 1 + border.right: 5 ; border.bottom: 1 + width: styleData.handlePosition + height: parent.height + } + } + handle: Item { + width: 13 + height: 13 + Image { + anchors.centerIn: parent + source: "../images/slider-handle.png" + } + } + } } Slider { - value: 50 - maximumValue: 100 + id: slider3 + value: 0.5 implicitWidth: columnWidth style: sliderStyle } ProgressBar { Layout.row: 3 - value: 50 - maximumValue: 100 + value: slider1.value implicitWidth: columnWidth style: ProgressBarStyle{ } } ProgressBar { - value: 50 - maximumValue: 100 + value: slider2.value implicitWidth: columnWidth - style: ProgressBarStyle{ } + style: progressBarStyle } ProgressBar { - value: 50 - maximumValue: 100 + value: slider3.value implicitWidth: columnWidth - style: progressbarStyle + style: progressBarStyle2 } CheckBox { @@ -177,64 +210,144 @@ Item { property Component buttonStyle: ButtonStyle { background: Rectangle { - implicitHeight: 20 + implicitHeight: 22 implicitWidth: columnWidth - color: control.pressed ? "darkGray" : "lightGray" + color: control.pressed ? "darkGray" : control.activeFocus ? "#cdd" : "#ccc" antialiasing: true border.color: "gray" radius: height/2 + Rectangle { + anchors.fill: parent + anchors.margins: 1 + color: "transparent" + antialiasing: true + visible: !control.pressed + border.color: "#aaffffff" + radius: height/2 + } } } property Component textfieldStyle: TextFieldStyle { background: Rectangle { implicitWidth: columnWidth - implicitHeight: 20 + implicitHeight: 22 color: "#f0f0f0" antialiasing: true border.color: "gray" radius: height/2 + Rectangle { + anchors.fill: parent + anchors.margins: 1 + color: "transparent" + antialiasing: true + border.color: "#aaffffff" + radius: height/2 + } } } property Component sliderStyle: SliderStyle { handle: Rectangle { - width: 14 - height: 14 + width: 18 + height: 18 color: control.pressed ? "darkGray" : "lightGray" border.color: "gray" antialiasing: true radius: height/2 + Rectangle { + anchors.fill: parent + anchors.margins: 1 + color: "transparent" + antialiasing: true + border.color: "#eee" + radius: height/2 + } } groove: Rectangle { height: 8 implicitWidth: columnWidth - implicitHeight: 20 + implicitHeight: 22 antialiasing: true - color: "darkGray" - border.color: "gray" + color: "#ccc" + border.color: "#777" radius: height/2 + Rectangle { + anchors.fill: parent + anchors.margins: 1 + color: "transparent" + antialiasing: true + border.color: "#66ffffff" + radius: height/2 + } } } - property Component progressbarStyle: ProgressBarStyle { + property Component progressBarStyle: ProgressBarStyle { + background: BorderImage { + source: "../images/progress-background.png" + border.left: 2 ; border.right: 2 ; border.top: 2 ; border.bottom: 2 + } + progress: Item { + clip: true + BorderImage { + anchors.fill: parent + anchors.rightMargin: (control.value < control.maximumValue) ? -4 : 0 + source: "../images/progress-fill.png" + border.left: 10 ; border.right: 10 + Rectangle { + width: 1 + color: "#a70" + opacity: 0.8 + anchors.top: parent.top + anchors.bottom: parent.bottom + anchors.bottomMargin: 1 + anchors.right: parent.right + visible: control.value < control.maximumValue + anchors.rightMargin: -parent.anchors.rightMargin + } + } + ParticleSystem{ id: bubbles } + ImageParticle{ + id: fireball + system: bubbles + source: "../images/bubble.png" + opacity: 0.7 + } + Emitter{ + system: bubbles + anchors.bottom: parent.bottom + anchors.margins: 4 + anchors.bottomMargin: -4 + anchors.left: parent.left + anchors.right: parent.right + size: 4 + sizeVariation: 4 + acceleration: PointDirection{ y: -6; xVariation: 3 } + emitRate: 6 * control.value + lifeSpan: 3000 + } + } + } + + property Component progressBarStyle2: ProgressBarStyle { background: Rectangle { implicitWidth: columnWidth - implicitHeight: 20 + implicitHeight: 24 color: "#f0f0f0" border.color: "gray" - antialiasing: true - radius: height/2 } progress: Rectangle { - implicitWidth: columnWidth - implicitHeight: 20 - color: "#c0c0c0" + color: "#ccc" border.color: "gray" - antialiasing: true - radius: height/2 + Rectangle { + color: "transparent" + border.color: "#44ffffff" + anchors.fill: parent + anchors.margins: 1 + } } } diff --git a/examples/quick/controls/gallery/images/bubble.png b/examples/quick/controls/gallery/images/bubble.png new file mode 100644 index 00000000..62aa1efe Binary files /dev/null and b/examples/quick/controls/gallery/images/bubble.png differ diff --git a/examples/quick/controls/gallery/images/button-pressed.png b/examples/quick/controls/gallery/images/button-pressed.png new file mode 100644 index 00000000..d64cdaa7 Binary files /dev/null and b/examples/quick/controls/gallery/images/button-pressed.png differ diff --git a/examples/quick/controls/gallery/images/button.png b/examples/quick/controls/gallery/images/button.png new file mode 100644 index 00000000..8ab41cc8 Binary files /dev/null and b/examples/quick/controls/gallery/images/button.png differ diff --git a/examples/quick/controls/gallery/images/progress-background.png b/examples/quick/controls/gallery/images/progress-background.png new file mode 100644 index 00000000..55a069df Binary files /dev/null and b/examples/quick/controls/gallery/images/progress-background.png differ diff --git a/examples/quick/controls/gallery/images/progress-fill.png b/examples/quick/controls/gallery/images/progress-fill.png new file mode 100644 index 00000000..b588c958 Binary files /dev/null and b/examples/quick/controls/gallery/images/progress-fill.png differ diff --git a/examples/quick/controls/gallery/images/slider-handle.png b/examples/quick/controls/gallery/images/slider-handle.png new file mode 100644 index 00000000..ac4d4a0d Binary files /dev/null and b/examples/quick/controls/gallery/images/slider-handle.png differ diff --git a/examples/quick/controls/gallery/images/textfield.png b/examples/quick/controls/gallery/images/textfield.png new file mode 100644 index 00000000..1d4a38ab Binary files /dev/null and b/examples/quick/controls/gallery/images/textfield.png differ diff --git a/examples/quick/controls/gallery/resources.qrc b/examples/quick/controls/gallery/resources.qrc index 21362787..6f487274 100644 --- a/examples/quick/controls/gallery/resources.qrc +++ b/examples/quick/controls/gallery/resources.qrc @@ -16,5 +16,12 @@ images/tab_selected.png images/window-new.png images/window-new@2x.png + images/bubble.png + images/button-pressed.png + images/button.png + images/progress-background.png + images/progress-fill.png + images/textfield.png + images/slider-handle.png -- 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 +++++++++++++++------ .../quick/controls/text/src/documenthandler.cpp | 48 ++++++- examples/quick/controls/text/src/documenthandler.h | 16 ++- 3 files changed, 166 insertions(+), 50 deletions(-) (limited to 'examples/quick/controls') 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 + } + } } } diff --git a/examples/quick/controls/text/src/documenthandler.cpp b/examples/quick/controls/text/src/documenthandler.cpp index 81eb744b..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 @@ -260,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; -- cgit v1.2.1 From 3edcc79bcf9259c77732a8ad15bd8ed6919d4983 Mon Sep 17 00:00:00 2001 From: Jens Bache-Wiig Date: Fri, 31 May 2013 16:07:00 +0200 Subject: Simplify example code by using QmlApplicationEngine Since QmlApplicationEngine does all the nasty bits including setting the incubation controller, we should use it in all of our examples. Task-number: QTBUG-31203 Change-Id: Ie4f2313b66ef1a460aa50559f5c0a6125d0c69f1 Reviewed-by: J-P Nurmi Reviewed-by: Caroline Chao Reviewed-by: Alan Alpert --- .../quick/controls/shared/qt_quick_controls_examplemain.h | 11 ++--------- examples/quick/controls/text/src/main.cpp | 14 ++------------ 2 files changed, 4 insertions(+), 21 deletions(-) (limited to 'examples/quick/controls') diff --git a/examples/quick/controls/shared/qt_quick_controls_examplemain.h b/examples/quick/controls/shared/qt_quick_controls_examplemain.h index e3cae9a0..324d7110 100644 --- a/examples/quick/controls/shared/qt_quick_controls_examplemain.h +++ b/examples/quick/controls/shared/qt_quick_controls_examplemain.h @@ -64,20 +64,13 @@ QT_BEGIN_NAMESPACE int main(int argc, char *argv[]) \ { \ Application app(argc, argv); \ - QQmlEngine engine; \ - QQmlComponent component(&engine); \ - component.loadUrl(QUrl(#url)); \ - if ( !component.isReady() ) { \ - qWarning("%s", qPrintable(component.errorString())); \ - return -1; \ - } \ - QObject *topLevel = component.create(); \ + QQmlApplicationEngine engine(QUrl(#url)); \ + QObject *topLevel = engine.rootObjects().value(0); \ QQuickWindow *window = qobject_cast(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/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("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(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(); } -- cgit v1.2.1 From 39ed137e71326411083c27c1d132769c33200df4 Mon Sep 17 00:00:00 2001 From: Caroline Chao Date: Wed, 5 Jun 2013 13:23:24 +0200 Subject: Text example: Update example.html Remove references to QTextEdit and adapt it to match TextArea instead. Update the Qt logo. Change-Id: I6939bf7418fbad883e1d967bea3688d9ccfd4885 Reviewed-by: Hanne Linaae Reviewed-by: J-P Nurmi --- examples/quick/controls/text/example.html | 22 ++++----- examples/quick/controls/text/qml/images/logo32.png | Bin 1410 -> 0 bytes .../quick/controls/text/qml/images/qt-logo.png | Bin 0 -> 3960 bytes examples/quick/controls/text/resources.qrc | 52 ++++++++++----------- 4 files changed, 37 insertions(+), 37 deletions(-) delete mode 100644 examples/quick/controls/text/qml/images/logo32.png create mode 100644 examples/quick/controls/text/qml/images/qt-logo.png (limited to 'examples/quick/controls') 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 @@ -QTextEdit Example -

QTextEdit

-

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.

-

If you are viewing this document in the textedit 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.

+

TextArea

+

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.

+

If you are viewing this document in the Text Editor 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.

Font and Paragraph Styles

-

QTextEdit supports bold, italic, and underlined font styles, and can display multicolored text. Font families such as Times New Roman and Courier can also be used directly. If you place the cursor in a region of styled text, the controls in the tool bars will change to reflect the current style.

+

TextArea supports bold, italic, and underlined font styles, and can display multicolored + text. Font families such as Helvetica and + Courier can also be used directly. 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.

Paragraphs can be formatted so that the text is left-aligned, right-aligned, centered, or fully justified.

Try changing the alignment of some text and resize the editor to see how the text layout changes.

Lists

@@ -13,7 +15,7 @@ p, li { white-space: pre-wrap; }
  • Disc symbols are typically used for top-level list items.
  • Circle symbols can be used to distinguish between items in lower-level lists.
  • Square symbols provide a reasonable alternative to discs and circles.
-

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:

+

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:

  1. Introduction
  2. Qt Tools
  1. Qt Assistant
  2. @@ -26,9 +28,9 @@ p, li { white-space: pre-wrap; }

    Images

    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.

    -

    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.

    +

    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.

    Tables

    -

    QTextEdit can arrange and format tables, supporting features such as row and column spans, text formatting within cells, and size constraints for columns.

    +

    TextArea can arrange and format tables, supporting features such as row and column spans, text formatting within cells, and size constraints for columns.

    @@ -72,8 +74,6 @@ p, li { white-space: pre-wrap; }

    Try adding text to the cells in the table and experiment with the alignment of the paragraphs.

    -

    Hyperlinks

    -

    QTextEdit is designed to support hyperlinks between documents, and this feature is used extensively in Qt Assistant. 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.

    Undo and Redo

    -

    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.

    +

    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.

    Try making changes to this document and press Ctrl+Z to undo them. You can always recover the original contents of the document.

    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 Binary files a/examples/quick/controls/text/qml/images/logo32.png and /dev/null 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 Binary files /dev/null and b/examples/quick/controls/text/qml/images/qt-logo.png differ diff --git a/examples/quick/controls/text/resources.qrc b/examples/quick/controls/text/resources.qrc index 4d137ff7..27c7b921 100644 --- a/examples/quick/controls/text/resources.qrc +++ b/examples/quick/controls/text/resources.qrc @@ -1,27 +1,27 @@ - - - qml/main.qml - qml/ToolBarSeparator.qml - qml/images/logo32.png - qml/images/editcopy.png - qml/images/editcut.png - qml/images/editpaste.png - qml/images/editredo.png - qml/images/editundo.png - qml/images/exportpdf.png - qml/images/filenew.png - qml/images/fileopen.png - qml/images/fileprint.png - qml/images/filesave.png - qml/images/textbold.png - qml/images/textcenter.png - qml/images/textitalic.png - qml/images/textjustify.png - qml/images/textleft.png - qml/images/textright.png - qml/images/textunder.png - qml/images/zoomin.png - qml/images/zoomout.png - example.html - + + + qml/main.qml + qml/ToolBarSeparator.qml + qml/images/editcopy.png + qml/images/editcut.png + qml/images/editpaste.png + qml/images/editredo.png + qml/images/editundo.png + qml/images/exportpdf.png + qml/images/filenew.png + qml/images/fileopen.png + qml/images/fileprint.png + qml/images/filesave.png + qml/images/textbold.png + qml/images/textcenter.png + qml/images/textitalic.png + qml/images/textjustify.png + qml/images/textleft.png + qml/images/textright.png + qml/images/textunder.png + qml/images/zoomin.png + qml/images/zoomout.png + example.html + qml/images/qt-logo.png + -- 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') 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') 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 From aa4ddfd8443f07badc0899d835027e46c6e0dfd8 Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Mon, 24 Jun 2013 14:05:56 +0200 Subject: Adapt to Qt.platform.os rename ("mac" -> "osx") Change-Id: I089a01bee10b92f85dcdd338c695a3b796b0ecd1 Reviewed-by: Jens Bache-Wiig Reviewed-by: Jake Petroules --- examples/quick/controls/gallery/content/ModelView.qml | 2 +- examples/quick/controls/gallery/main.qml | 2 +- examples/quick/controls/tableview/main.qml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) (limited to 'examples/quick/controls') diff --git a/examples/quick/controls/gallery/content/ModelView.qml b/examples/quick/controls/gallery/content/ModelView.qml index e6a6040f..483d99ee 100644 --- a/examples/quick/controls/gallery/content/ModelView.qml +++ b/examples/quick/controls/gallery/content/ModelView.qml @@ -51,7 +51,7 @@ Item { width: 600 height: 300 anchors.fill: parent - anchors.margins: Qt.platform.os === "mac" ? 12 : 6 + anchors.margins: Qt.platform.os === "osx" ? 12 : 6 // XmlListModel { // id: flickerModel diff --git a/examples/quick/controls/gallery/main.qml b/examples/quick/controls/gallery/main.qml index 8ea3cf9e..ec00627b 100644 --- a/examples/quick/controls/gallery/main.qml +++ b/examples/quick/controls/gallery/main.qml @@ -228,7 +228,7 @@ ApplicationWindow { enabled: enabledCheck.checked tabPosition: controlPage.item ? controlPage.item.tabPosition : Qt.TopEdge anchors.fill: parent - anchors.margins: Qt.platform.os === "mac" ? 12 : 2 + anchors.margins: Qt.platform.os === "osx" ? 12 : 2 Tab { id: controlPage diff --git a/examples/quick/controls/tableview/main.qml b/examples/quick/controls/tableview/main.qml index 3ecf5ddb..1a9246f8 100644 --- a/examples/quick/controls/tableview/main.qml +++ b/examples/quick/controls/tableview/main.qml @@ -129,7 +129,7 @@ Window { focus:true enabled: enabledCheck.checked - property int margins: Qt.platform.os === "mac" ? 16 : 0 + property int margins: Qt.platform.os === "osx" ? 16 : 0 height: parent.height - 34 anchors.right: parent.right -- cgit v1.2.1