diff options
Diffstat (limited to 'examples')
41 files changed, 668 insertions, 444 deletions
diff --git a/examples/activeqt/activeqt.pro b/examples/activeqt/activeqt.pro index 262e1a1..79d257a 100644 --- a/examples/activeqt/activeqt.pro +++ b/examples/activeqt/activeqt.pro @@ -11,7 +11,7 @@ contains(QT_CONFIG, opengl):SUBDIRS += opengl # For now only the contain examples with mingw, for the others you need # an IDL compiler -win32-g++|wince*:SUBDIRS = webbrowser +win32-g++*|wince*:SUBDIRS = webbrowser # install target.path = $$[QT_INSTALL_EXAMPLES]/activeqt diff --git a/examples/declarative/imageelements/image/ImageCell.qml b/examples/declarative/imageelements/image/ImageCell.qml new file mode 100644 index 0000000..bd232b9 --- /dev/null +++ b/examples/declarative/imageelements/image/ImageCell.qml @@ -0,0 +1,60 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtDeclarative 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 Nokia Corporation 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 Qt 4.7 + +Item { + property alias mode: image.fillMode + property alias caption: captionItem.text + + width: parent.cellWidth; height: parent.cellHeight + + Image { + id: image + width: parent.width; height: parent.height - captionItem.height + source: "face-smile.png" + clip: true // only makes a difference if mode is PreserveAspectCrop + smooth: true + } + + Text { + id: captionItem + anchors.horizontalCenter: parent.horizontalCenter; anchors.bottom: parent.bottom + } +} diff --git a/examples/declarative/imageelements/image/face-smile.png b/examples/declarative/imageelements/image/face-smile.png Binary files differnew file mode 100644 index 0000000..3d66d72 --- /dev/null +++ b/examples/declarative/imageelements/image/face-smile.png diff --git a/examples/declarative/imageelements/image/image.qml b/examples/declarative/imageelements/image/image.qml new file mode 100644 index 0000000..bc5ae37 --- /dev/null +++ b/examples/declarative/imageelements/image/image.qml @@ -0,0 +1,66 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtDeclarative 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 Nokia Corporation 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 Qt 4.7 + +Rectangle { + width: 490 + height: 285 + + Grid { + property int cellWidth: (width - (spacing * (columns - 1))) / columns + property int cellHeight: (height - (spacing * (rows - 1))) / rows + + anchors.fill: parent + anchors.margins: 30 + + columns: 3 + rows: 2 + spacing: 30 + + ImageCell { mode: Image.Stretch; caption: "Stretch" } + ImageCell { mode: Image.PreserveAspectFit; caption: "PreserveAspectFit" } + ImageCell { mode: Image.PreserveAspectCrop; caption: "PreserveAspectCrop" } + + ImageCell { mode: Image.Tile; caption: "Tile" } + ImageCell { mode: Image.TileHorizontally; caption: "TileHorizontally" } + ImageCell { mode: Image.TileVertically; caption: "TileVertically" } + } +} diff --git a/examples/declarative/imageelements/image/image.qmlproject b/examples/declarative/imageelements/image/image.qmlproject new file mode 100644 index 0000000..d4909f8 --- /dev/null +++ b/examples/declarative/imageelements/image/image.qmlproject @@ -0,0 +1,16 @@ +import QmlProject 1.0 + +Project { + /* Include .qml, .js, and image files from current directory and subdirectories */ + QmlFiles { + directory: "." + } + JavaScriptFiles { + directory: "." + } + ImageFiles { + directory: "." + } + /* List of plugin directories passed to QML runtime */ + // importPaths: [ " ../exampleplugin " ] +} diff --git a/examples/declarative/modelviews/listview/dummydata/MyPetsModel.qml b/examples/declarative/modelviews/listview/PetsModel.qml index 70cdcdd..70cdcdd 100644 --- a/examples/declarative/modelviews/listview/dummydata/MyPetsModel.qml +++ b/examples/declarative/modelviews/listview/PetsModel.qml diff --git a/examples/declarative/modelviews/listview/dummydata/Recipes.qml b/examples/declarative/modelviews/listview/RecipesModel.qml index 03ab961..03ab961 100644 --- a/examples/declarative/modelviews/listview/dummydata/Recipes.qml +++ b/examples/declarative/modelviews/listview/RecipesModel.qml diff --git a/examples/declarative/modelviews/listview/content/ClickAutoRepeating.qml b/examples/declarative/modelviews/listview/content/PressAndHoldButton.qml index dc23b78..7c174e3 100644 --- a/examples/declarative/modelviews/listview/content/ClickAutoRepeating.qml +++ b/examples/declarative/modelviews/listview/content/PressAndHoldButton.qml @@ -40,32 +40,40 @@ import Qt 4.7 -Item { - id: page - property int repeatdelay: 300 - property int repeatperiod: 75 - property bool isPressed: false +Image { + id: container + + property int repeatDelay: 300 + property int repeatDuration: 75 + property bool pressed: false - signal pressed - signal released signal clicked - SequentialAnimation on isPressed { + scale: pressed ? 0.9 : 1 + + SequentialAnimation on pressed { + id: autoRepeatClicks running: false - id: autoRepeat - PropertyAction { target: page; property: "isPressed"; value: true } - ScriptAction { script: page.pressed() } - ScriptAction { script: page.clicked() } - PauseAnimation { duration: repeatdelay } + + PropertyAction { target: container; property: "pressed"; value: true } + ScriptAction { script: container.clicked() } + PauseAnimation { duration: repeatDelay } + SequentialAnimation { loops: Animation.Infinite - ScriptAction { script: page.clicked() } - PauseAnimation { duration: repeatperiod } + ScriptAction { script: container.clicked() } + PauseAnimation { duration: repeatDuration } } } + MouseArea { anchors.fill: parent - onPressed: autoRepeat.start() - onReleased: { autoRepeat.stop(); parent.isPressed = false; page.released() } + + onPressed: autoRepeatClicks.start() + onReleased: { + autoRepeatClicks.stop() + container.pressed = false + } } } + diff --git a/examples/declarative/modelviews/listview/content/MediaButton.qml b/examples/declarative/modelviews/listview/content/TextButton.qml index 2aed6e0..ded7a11 100644 --- a/examples/declarative/modelviews/listview/content/MediaButton.qml +++ b/examples/declarative/modelviews/listview/content/TextButton.qml @@ -40,36 +40,39 @@ import Qt 4.7 -Item { - property variant text +Rectangle { + id: container + + property alias text: label.text + signal clicked - id: container - Image { - id: normal - source: "pics/button.png" - } - Image { - id: pressed - source: "pics/button-pressed.png" - opacity: 0 + width: label.width + 20; height: label.height + 6 + smooth: true + radius: 10 + + gradient: Gradient { + GradientStop { id: gradientStop; position: 0.0; color: palette.light } + GradientStop { position: 1.0; color: palette.button } } + + SystemPalette { id: palette } + MouseArea { - id: clickRegion - anchors.fill: normal - onClicked: { container.clicked(); } + id: mouseArea + anchors.fill: parent + onClicked: { container.clicked() } } + Text { - font.bold: true - color: "white" - anchors.centerIn: normal - text: container.text + id: label + anchors.centerIn: parent } - width: normal.width states: State { - name: "Pressed" - when: clickRegion.pressed == true - PropertyChanges { target: pressed; opacity: 1 } + name: "pressed" + when: mouseArea.pressed + PropertyChanges { target: gradientStop; color: palette.dark } } } + diff --git a/examples/declarative/modelviews/listview/content/pics/add.png b/examples/declarative/modelviews/listview/content/pics/add.png Binary files differdeleted file mode 100644 index f29d84b..0000000 --- a/examples/declarative/modelviews/listview/content/pics/add.png +++ /dev/null diff --git a/examples/declarative/modelviews/listview/content/pics/del.png b/examples/declarative/modelviews/listview/content/pics/del.png Binary files differdeleted file mode 100644 index 1d753a3..0000000 --- a/examples/declarative/modelviews/listview/content/pics/del.png +++ /dev/null diff --git a/examples/declarative/modelviews/listview/content/pics/trash.png b/examples/declarative/modelviews/listview/content/pics/trash.png Binary files differdeleted file mode 100644 index 2042595..0000000 --- a/examples/declarative/modelviews/listview/content/pics/trash.png +++ /dev/null diff --git a/examples/declarative/modelviews/listview/dynamic.qml b/examples/declarative/modelviews/listview/dynamic.qml deleted file mode 100644 index cf0e387..0000000 --- a/examples/declarative/modelviews/listview/dynamic.qml +++ /dev/null @@ -1,248 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtDeclarative 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 Nokia Corporation 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 Qt 4.7 -import "content" -import "../../ui-components/scrollbar" - -Rectangle { - id: container - width: 640; height: 480 - color: "#343434" - - ListModel { - id: fruitModel - - ListElement { - name: "Apple"; cost: 2.45 - attributes: [ - ListElement { description: "Core" }, - ListElement { description: "Deciduous" } - ] - } - ListElement { - name: "Banana"; cost: 1.95 - attributes: [ - ListElement { description: "Tropical" }, - ListElement { description: "Seedless" } - ] - } - ListElement { - name: "Cumquat"; cost: 3.25 - attributes: [ - ListElement { description: "Citrus" } - ] - } - ListElement { - name: "Durian"; cost: 9.95 - attributes: [ - ListElement { description: "Tropical" }, - ListElement { description: "Smelly" } - ] - } - ListElement { - name: "Elderberry"; cost: 0.05 - attributes: [ - ListElement { description: "Berry" } - ] - } - ListElement { - name: "Fig"; cost: 0.25 - attributes: [ - ListElement { description: "Flower" } - ] - } - } - - Component { - id: fruitDelegate - - Item { - width: container.width; height: 55 - - Column { - id: moveButtons - x: 5; width: childrenRect.width; anchors.verticalCenter: parent.verticalCenter - - Image { - source: "content/pics/go-up.png" - MouseArea { anchors.fill: parent; onClicked: fruitModel.move(index,index-1,1) } - } - Image { source: "content/pics/go-down.png" - MouseArea { anchors.fill: parent; onClicked: fruitModel.move(index,index+1,1) } - } - } - - Column { - anchors { right: itemButtons.left; verticalCenter: parent.verticalCenter; left: moveButtons.right; leftMargin: 10 } - - Text { - id: label - width: parent.width - color: "White" - font.bold: true; font.pixelSize: 15 - text: name; elide: Text.ElideRight - } - Row { - spacing: 5 - Repeater { - model: attributes - Component { - Text { text: description; color: "White" } - } - } - } - } - - Row { - id: itemButtons - - anchors { right: removeButton.left; rightMargin: 35; verticalCenter: parent.verticalCenter } - width: childrenRect.width - spacing: 10 - - Image { - source: "content/pics/list-add.png" - scale: clickUp.isPressed ? 0.9 : 1 - - ClickAutoRepeating { - id: clickUp - anchors.fill: parent - onClicked: fruitModel.setProperty(index, "cost", cost+0.25) - } - } - - Text { id: costText; text: '$'+Number(cost).toFixed(2); font.pixelSize: 15; color: "White"; font.bold: true; } - - Image { - source: "content/pics/list-remove.png" - scale: clickDown.isPressed ? 0.9 : 1 - - ClickAutoRepeating { - id: clickDown - anchors.fill: parent - onClicked: fruitModel.setProperty(index, "cost", Math.max(0,cost-0.25)) - } - } - } - Image { - id: removeButton - anchors { verticalCenter: parent.verticalCenter; right: parent.right; rightMargin: 10 } - source: "content/pics/archive-remove.png" - - MouseArea { anchors.fill:parent; onClicked: fruitModel.remove(index) } - } - } - } - - ListView { - id: view - anchors { top: parent.top; left: parent.left; right: parent.right; bottom: buttons.top } - model: fruitModel - delegate: fruitDelegate - } - - // Attach scrollbar to the right edge of the view. - ScrollBar { - id: verticalScrollBar - - width: 8; height: view.height; anchors.right: view.right - opacity: 0 - orientation: Qt.Vertical - position: view.visibleArea.yPosition - pageSize: view.visibleArea.heightRatio - - // Only show the scrollbar when the view is moving. - states: State { - name: "ShowBars"; when: view.movingVertically - PropertyChanges { target: verticalScrollBar; opacity: 1 } - } - transitions: Transition { - NumberAnimation { properties: "opacity"; duration: 400 } - } - } - - Row { - id: buttons - - x: 8; width: childrenRect.width; height: childrenRect.height - anchors { bottom: parent.bottom; bottomMargin: 8 } - spacing: 8 - - Image { - source: "content/pics/archive-insert.png" - - MouseArea { - anchors.fill: parent - onClicked: { - fruitModel.append({ - "name": "Pizza Margarita", - "cost": 5.95, - "attributes": [{"description": "Cheese"},{"description": "Tomato"}] - }) - } - } - } - - Image { - source: "content/pics/archive-insert.png" - - MouseArea { - anchors.fill: parent; - onClicked: { - fruitModel.insert(0, { - "name": "Pizza Supreme", - "cost": 9.95, - "attributes": [{"description": "Cheese"},{"description": "Tomato"},{"description": "The Works"}] - }) - } - } - } - - Image { - source: "content/pics/archive-remove.png" - - MouseArea { - anchors.fill: parent - onClicked: fruitModel.clear() - } - } - } -} diff --git a/examples/declarative/modelviews/listview/dynamiclist.qml b/examples/declarative/modelviews/listview/dynamiclist.qml new file mode 100644 index 0000000..0e290f5 --- /dev/null +++ b/examples/declarative/modelviews/listview/dynamiclist.qml @@ -0,0 +1,203 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtDeclarative 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 Nokia Corporation 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 Qt 4.7 +import "content" + +// This example shows how items can be dynamically added to and removed from +// a ListModel, and how these list modifications can be animated. + +Rectangle { + id: container + width: 640; height: 480 + color: "#343434" + + // The model: + ListModel { + id: fruitModel + + ListElement { + name: "Apple"; cost: 2.45 + attributes: [ + ListElement { description: "Core" }, + ListElement { description: "Deciduous" } + ] + } + ListElement { + name: "Banana"; cost: 1.95 + attributes: [ + ListElement { description: "Tropical" }, + ListElement { description: "Seedless" } + ] + } + ListElement { + name: "Cumquat"; cost: 3.25 + attributes: [ + ListElement { description: "Citrus" } + ] + } + ListElement { + name: "Durian"; cost: 9.95 + attributes: [ + ListElement { description: "Tropical" }, + ListElement { description: "Smelly" } + ] + } + } + + // The delegate for each fruit in the model: + Component { + id: listDelegate + + Item { + id: delegateItem + width: listView.width; height: 55 + clip: true + + Row { + anchors.verticalCenter: parent.verticalCenter + spacing: 10 + + Column { + Image { + source: "content/pics/go-up.png" + MouseArea { anchors.fill: parent; onClicked: fruitModel.move(index,index-1,1) } + } + Image { source: "content/pics/go-down.png" + MouseArea { anchors.fill: parent; onClicked: fruitModel.move(index,index+1,1) } + } + } + + Column { + anchors.verticalCenter: parent.verticalCenter + + Text { + text: name + font.pixelSize: 15 + color: "white" + } + Row { + spacing: 5 + Repeater { + model: attributes + Text { text: description; color: "White" } + } + } + } + } + + Row { + anchors.verticalCenter: parent.verticalCenter + anchors.right: parent.right + spacing: 10 + + PressAndHoldButton { + anchors.verticalCenter: parent.verticalCenter + source: "content/pics/list-add.png" + onClicked: fruitModel.setProperty(index, "cost", cost + 0.25) + } + + Text { + id: costText + anchors.verticalCenter: parent.verticalCenter + text: '$' + Number(cost).toFixed(2) + font.pixelSize: 15 + color: "white" + font.bold: true + } + + PressAndHoldButton { + anchors.verticalCenter: parent.verticalCenter + source: "content/pics/list-remove.png" + onClicked: fruitModel.setProperty(index, "cost", Math.max(0,cost-0.25)) + } + + Image { + source: "content/pics/archive-remove.png" + MouseArea { anchors.fill:parent; onClicked: fruitModel.remove(index) } + } + } + + // Animate adding and removing of items: + + ListView.onAdd: SequentialAnimation { + PropertyAction { target: delegateItem; property: "height"; value: 0 } + NumberAnimation { target: delegateItem; property: "height"; to: 55; duration: 250; easing.type: Easing.InOutQuad } + } + + ListView.onRemove: SequentialAnimation { + PropertyAction { target: delegateItem; property: "ListView.delayRemove"; value: true } + NumberAnimation { target: delegateItem; property: "height"; to: 0; duration: 250; easing.type: Easing.InOutQuad } + + // Make sure delayRemove is set back to false so that the item can be destroyed + PropertyAction { target: delegateItem; property: "ListView.delayRemove"; value: false } + } + } + } + + // The view: + ListView { + id: listView + anchors.fill: parent; anchors.margins: 20 + model: fruitModel + delegate: listDelegate + } + + Row { + anchors { left: parent.left; bottom: parent.bottom; margins: 20 } + spacing: 10 + + TextButton { + text: "Add an item" + onClicked: { + fruitModel.append({ + "name": "Pizza Margarita", + "cost": 5.95, + "attributes": [{"description": "Cheese"}, {"description": "Tomato"}] + }) + } + } + + TextButton { + text: "Remove all items" + onClicked: fruitModel.clear() + } + } +} + diff --git a/examples/declarative/modelviews/listview/recipes.qml b/examples/declarative/modelviews/listview/expandingdelegates.qml index f4b97ea..94ea48f 100644 --- a/examples/declarative/modelviews/listview/recipes.qml +++ b/examples/declarative/modelviews/listview/expandingdelegates.qml @@ -41,7 +41,7 @@ import Qt 4.7 import "content" -// This example illustrates expanding a list item to show a more detailed view +// This example illustrates expanding a list item to show a more detailed view. Rectangle { id: page @@ -49,13 +49,13 @@ Rectangle { color: "black" // Delegate for the recipes. This delegate has two modes: - // 1. the list mode (default), which just shows the picture and title of the recipe. - // 2. the details mode, which also shows the ingredients and method. + // 1. List mode (default), which just shows the picture and title of the recipe. + // 2. Details mode, which also shows the ingredients and method. Component { id: recipeDelegate Item { - id: wrapper + id: recipe // Create a property to contain the visibility of the details. // We can bind multiple element's opacity to this one property, @@ -63,14 +63,15 @@ Rectangle { // want to fade. property real detailsOpacity : 0 - width: list.width + width: listView.width + height: 70 // A simple rounded rectangle for the background Rectangle { id: background - x: 1; y: 2; width: parent.width - 2; height: parent.height - 4 - color: "#FEFFEE" - border.color: "#FFBE4F" + x: 2; y: 2; width: parent.width - x*2; height: parent.height - y*2 + color: "ivory" + border.color: "orange" radius: 5 } @@ -78,50 +79,53 @@ Rectangle { // When clicked it changes mode to 'Details'. If we are already // in Details mode, then no change will happen. MouseArea { - id: pageMouse anchors.fill: parent - onClicked: wrapper.state = 'Details'; + onClicked: recipe.state = 'Details'; } - // Layout the page. Picture, title and ingredients at the top, method at the + // Lay out the page: picture, title and ingredients at the top, and method at the // bottom. Note that elements that should not be visible in the list - // mode have their opacity set to wrapper.detailsOpacity. + // mode have their opacity set to recipe.detailsOpacity. Row { id: topLayout - x: 10; y: 10; height: recipePic.height; width: parent.width + x: 10; y: 10; height: recipeImage.height; width: parent.width spacing: 10 Image { - id: recipePic - source: picture; width: 48; height: 48 + id: recipeImage + width: 50; height: 50 + source: picture } Column { - width: background.width-recipePic.width-20; height: recipePic.height; + width: background.width - recipeImage.width - 20; height: recipeImage.height spacing: 5 - Text { id: name; text: title; font.bold: true; font.pointSize: 16 } + Text { + text: title + font.bold: true; font.pointSize: 16 + } Text { text: "Ingredients" font.pointSize: 12; font.bold: true - opacity: wrapper.detailsOpacity + opacity: recipe.detailsOpacity } Text { text: ingredients wrapMode: Text.WordWrap width: parent.width - opacity: wrapper.detailsOpacity + opacity: recipe.detailsOpacity } } } Item { id: details - x: 10; width: parent.width-20 + x: 10; width: parent.width - 20 anchors { top: topLayout.bottom; topMargin: 10; bottom: parent.bottom; bottomMargin: 10 } - opacity: wrapper.detailsOpacity + opacity: recipe.detailsOpacity Text { id: methodTitle @@ -153,30 +157,28 @@ Rectangle { } // A button to close the detailed view, i.e. set the state back to default (''). - MediaButton { - y: 10; anchors { right: background.right; rightMargin: 5 } - opacity: wrapper.detailsOpacity + TextButton { + y: 10 + anchors { right: background.right; rightMargin: 10 } + opacity: recipe.detailsOpacity text: "Close" - onClicked: wrapper.state = ''; + onClicked: recipe.state = ''; } - // Set the default height to the height of the picture, plus margin. - height: 68 - states: State { name: "Details" PropertyChanges { target: background; color: "white" } - PropertyChanges { target: recipePic; width: 128; height: 128 } // Make picture bigger - PropertyChanges { target: wrapper; detailsOpacity: 1; x: 0 } // Make details visible - PropertyChanges { target: wrapper; height: list.height } // Fill the entire list area with the detailed view + PropertyChanges { target: recipeImage; width: 130; height: 130 } // Make picture bigger + PropertyChanges { target: recipe; detailsOpacity: 1; x: 0 } // Make details visible + PropertyChanges { target: recipe; height: listView.height } // Fill the entire list area with the detailed view // Move the list so that this item is at the top. - PropertyChanges { target: wrapper.ListView.view; explicit: true; contentY: wrapper.y } + PropertyChanges { target: recipe.ListView.view; explicit: true; contentY: recipe.y } // Disallow flicking while we're in detailed view - PropertyChanges { target: wrapper.ListView.view; interactive: false } + PropertyChanges { target: recipe.ListView.view; interactive: false } } transitions: Transition { @@ -191,10 +193,10 @@ Rectangle { // The actual list ListView { - id: list + id: listView anchors.fill: parent - clip: true - model: Recipes + model: RecipesModel {} delegate: recipeDelegate + clip: true } } diff --git a/examples/declarative/modelviews/listview/highlight.qml b/examples/declarative/modelviews/listview/highlight.qml index 239272a..5748974 100644 --- a/examples/declarative/modelviews/listview/highlight.qml +++ b/examples/declarative/modelviews/listview/highlight.qml @@ -41,12 +41,7 @@ import Qt 4.7 Rectangle { - width: 400; height: 300 - - // MyPets model is defined in dummydata/MyPetsModel.qml - // The launcher automatically loads files in dummydata/* to assist - // development without a real data source. - // This one contains my pets. + width: 200; height: 300 // Define a delegate component. A component will be // instantiated for each visible item in the list. @@ -54,42 +49,45 @@ Rectangle { id: petDelegate Item { id: wrapper - width: 200; height: 50 + width: 200; height: 55 Column { Text { text: 'Name: ' + name } Text { text: 'Type: ' + type } Text { text: 'Age: ' + age } } - // Use the ListView.isCurrentItem attached property to - // indent the item if it is the current item. + // indent the item if it is the current item states: State { name: "Current" when: wrapper.ListView.isCurrentItem - PropertyChanges { target: wrapper; x: 10 } + PropertyChanges { target: wrapper; x: 20 } } transitions: Transition { NumberAnimation { properties: "x"; duration: 200 } } } } - // Specify a highlight with custom movement. Note that highlightFollowsCurrentItem - // is set to false in the ListView so that we can control how the - // highlight moves to the current item. + + // Define a highlight with customised movement between items. Component { - id: petHighlight + id: highlightBar Rectangle { width: 200; height: 50 color: "#FFFF88" - SpringFollow on y { to: list1.currentItem.y; spring: 3; damping: 0.1 } + SpringFollow on y { to: listView.currentItem.y; spring: 3; damping: 0.1 } } } ListView { - id: list1 + id: listView width: 200; height: parent.height - model: MyPetsModel + + model: PetsModel {} delegate: petDelegate - highlight: petHighlight; highlightFollowsCurrentItem: false focus: true + + // Set the highlight delegate. Note we must also set highlightFollowsCurrentItem + // to false so the highlight delegate can control how the highlight is moved. + highlight: highlightBar + highlightFollowsCurrentItem: false } } diff --git a/examples/declarative/modelviews/listview/listview-example.qml b/examples/declarative/modelviews/listview/highlightranges.qml index a8a95c4..162d8b7 100644 --- a/examples/declarative/modelviews/listview/listview-example.qml +++ b/examples/declarative/modelviews/listview/highlightranges.qml @@ -43,46 +43,20 @@ import Qt 4.7 Rectangle { width: 600; height: 300 - // MyPets model is defined in dummydata/MyPetsModel.qml - // The viewer automatically loads files in dummydata/* to assist - // development without a real data source. - // This one contains my pets. - - // Define a delegate component. A component will be - // instantiated for each visible item in the list. - Component { - id: petDelegate - Item { - width: 200; height: 50 - Column { - Text { text: 'Name: ' + name } - Text { text: 'Type: ' + type } - Text { text: 'Age: ' + age } - } - } - } - - // Define a highlight component. Just one of these will be instantiated - // by each ListView and placed behind the current item. - Component { - id: petHighlight - Rectangle { color: "#FFFF88" } - } - // Show the model in three lists, with different highlight ranges. // preferredHighlightBegin and preferredHighlightEnd set the // range in which to attempt to maintain the highlight. // - // Note that the second and third ListView - // set their currentIndex to be the same as the first, and that - // the first ListView is given keyboard focus. + // The second and third ListView set their currentIndex to be the + // same as the first, and the first ListView is given keyboard focus. // - // The default mode allows the currentItem to move freely - // within the visible area. If it would move outside the visible - // area, the view is scrolled to keep it visible. + // The first list does not set a highlight range, so its currentItem + // can move freely within the visible area. If it moves outside the + // visible area, the view is automatically scrolled to keep the current + // item visible. // // The second list sets a highlight range which attempts to keep the - // current item within the the bounds of the range, however + // current item within the the bounds of the range. However, // items will not scroll beyond the beginning or end of the view, // forcing the highlight to move outside the range at the ends. // @@ -98,21 +72,22 @@ Rectangle { ListView { id: list1 width: 200; height: parent.height - model: MyPetsModel + model: PetsModel {} delegate: petDelegate - highlight: petHighlight + highlight: Rectangle { color: "lightsteelblue" } currentIndex: list3.currentIndex focus: true } ListView { id: list2 - x: 200; width: 200; height: parent.height - model: MyPetsModel + x: list1.width + width: 200; height: parent.height + model: PetsModel {} delegate: petDelegate - highlight: petHighlight + highlight: Rectangle { color: "yellow" } currentIndex: list1.currentIndex preferredHighlightBegin: 80; preferredHighlightEnd: 220 highlightRangeMode: ListView.ApplyRange @@ -120,14 +95,25 @@ Rectangle { ListView { id: list3 - x: 400; width: 200; height: parent.height - model: MyPetsModel + x: list1.width + list2.width + width: 200; height: parent.height + model: PetsModel {} delegate: petDelegate - highlight: Rectangle { color: "lightsteelblue" } + highlight: Rectangle { color: "yellow" } currentIndex: list1.currentIndex preferredHighlightBegin: 125; preferredHighlightEnd: 125 highlightRangeMode: ListView.StrictlyEnforceRange - flickDeceleration: 1000 + } + + // The delegate for each list + Component { + id: petDelegate + Column { + width: 200 + Text { text: 'Name: ' + name } + Text { text: 'Type: ' + type } + Text { text: 'Age: ' + age } + } } } diff --git a/examples/declarative/modelviews/listview/sections.qml b/examples/declarative/modelviews/listview/sections.qml index d2f9aba..8c038a0 100644 --- a/examples/declarative/modelviews/listview/sections.qml +++ b/examples/declarative/modelviews/listview/sections.qml @@ -42,70 +42,43 @@ import Qt 4.7 //! [0] Rectangle { + id: container width: 200 - height: 240 + height: 250 - // MyPets model is defined in dummydata/MyPetsModel.qml - // The viewer automatically loads files in dummydata/* to assist - // development without a real data source. - // This one contains my pets. - - // Define a delegate component that includes a separator for sections. - Component { - id: petDelegate - - Item { - id: wrapper - width: 200 - height: desc.height // height is the combined height of the description and the section separator + ListModel { + id: animalsModel + ListElement { name: "Parrot"; size: "Small" } + ListElement { name: "Guinea pig"; size: "Small" } + ListElement { name: "Dog"; size: "Medium" } + ListElement { name: "Cat"; size: "Medium" } + ListElement { name: "Elephant"; size: "Large" } + } - Item { - id: desc - x: 5; height: layout.height + 4 + // The delegate for each section header + Component { + id: sectionHeading + Rectangle { + width: container.width + height: childrenRect.height + color: "lightsteelblue" - Column { - id: layout - y: 2 - Text { text: 'Name: ' + name } - Text { text: 'Type: ' + type } - Text { text: 'Age: ' + age } - } + Text { + text: section + font.bold: true } } } - // Define a highlight component. Just one of these will be instantiated - // by each ListView and placed behind the current item. - Component { - id: petHighlight - Rectangle { color: "#FFFF88" } - } - - // The list ListView { - id: myList + anchors.fill: parent + model: animalsModel + delegate: Text { text: name } - width: 200; height: parent.height - model: MyPetsModel - delegate: petDelegate - highlight: petHighlight - focus: true - - // The sectionExpression is simply the size of the pet. - // We use this to determine which section we are in above. section.property: "size" section.criteria: ViewSection.FullString - section.delegate: Rectangle { - color: "lightsteelblue" - width: 200 - height: 20 - Text { - x: 2; height: parent.height - verticalAlignment: Text.AlignVCenter - text: section - font.bold: true - } - } + section.delegate: sectionHeading } } //! [0] + diff --git a/examples/declarative/modelviews/listview/itemlist.qml b/examples/declarative/modelviews/visualitemmodel/visualitemmodel.qml index 1b44e05..1b44e05 100644 --- a/examples/declarative/modelviews/listview/itemlist.qml +++ b/examples/declarative/modelviews/visualitemmodel/visualitemmodel.qml diff --git a/examples/declarative/modelviews/visualitemmodel/visualitemmodel.qmlproject b/examples/declarative/modelviews/visualitemmodel/visualitemmodel.qmlproject new file mode 100644 index 0000000..d4909f8 --- /dev/null +++ b/examples/declarative/modelviews/visualitemmodel/visualitemmodel.qmlproject @@ -0,0 +1,16 @@ +import QmlProject 1.0 + +Project { + /* Include .qml, .js, and image files from current directory and subdirectories */ + QmlFiles { + directory: "." + } + JavaScriptFiles { + directory: "." + } + ImageFiles { + directory: "." + } + /* List of plugin directories passed to QML runtime */ + // importPaths: [ " ../exampleplugin " ] +} diff --git a/examples/declarative/text/edit/edit.qml b/examples/declarative/text/edit/edit.qml index 0be42e9..4668ab2 100644 --- a/examples/declarative/text/edit/edit.qml +++ b/examples/declarative/text/edit/edit.qml @@ -121,6 +121,9 @@ Rectangle { onClicked: { if (editor.state == "") { edit.cursorPosition = edit.positionAt(mouse.x+x,mouse.y+y); + if (!edit.focus) + edit.focus = true; + edit.openSoftwareInputPanel(); } } function hitHandle(h,x,y) { return x>=h.x+flick.contentX && x<h.x+flick.contentX+h.width && y>=h.y+flick.contentY && y<h.y+flick.contentY+h.height } diff --git a/examples/declarative/toys/clocks/content/center.png b/examples/declarative/toys/clocks/content/center.png Binary files differindex 7fbd802..7fbd802 100755..100644 --- a/examples/declarative/toys/clocks/content/center.png +++ b/examples/declarative/toys/clocks/content/center.png diff --git a/examples/declarative/toys/clocks/content/clock-night.png b/examples/declarative/toys/clocks/content/clock-night.png Binary files differindex cc7151a..cc7151a 100755..100644 --- a/examples/declarative/toys/clocks/content/clock-night.png +++ b/examples/declarative/toys/clocks/content/clock-night.png diff --git a/examples/declarative/toys/clocks/content/clock.png b/examples/declarative/toys/clocks/content/clock.png Binary files differindex 462edac..462edac 100755..100644 --- a/examples/declarative/toys/clocks/content/clock.png +++ b/examples/declarative/toys/clocks/content/clock.png diff --git a/examples/declarative/toys/clocks/content/hour.png b/examples/declarative/toys/clocks/content/hour.png Binary files differindex f8061a1..f8061a1 100755..100644 --- a/examples/declarative/toys/clocks/content/hour.png +++ b/examples/declarative/toys/clocks/content/hour.png diff --git a/examples/declarative/toys/clocks/content/minute.png b/examples/declarative/toys/clocks/content/minute.png Binary files differindex 1297ec7..1297ec7 100755..100644 --- a/examples/declarative/toys/clocks/content/minute.png +++ b/examples/declarative/toys/clocks/content/minute.png diff --git a/examples/declarative/toys/clocks/content/second.png b/examples/declarative/toys/clocks/content/second.png Binary files differindex 4aa9fb5..4aa9fb5 100755..100644 --- a/examples/declarative/toys/clocks/content/second.png +++ b/examples/declarative/toys/clocks/content/second.png diff --git a/examples/declarative/toys/corkboards/Day.qml b/examples/declarative/toys/corkboards/Day.qml index f9c901f..cc297b1 100644 --- a/examples/declarative/toys/corkboards/Day.qml +++ b/examples/declarative/toys/corkboards/Day.qml @@ -49,6 +49,11 @@ Component { Image { source: "cork.jpg" } + MouseArea { + anchors.fill: parent + onClicked: page.focus = false; + } + Text { text: name; x: 15; y: 8; height: 40; width: 370 font.pixelSize: 18; font.bold: true; color: "white" @@ -106,7 +111,7 @@ Component { drag.maximumY: page.height - 80 drag.minimumX: 100 drag.maximumX: page.width - 140 - onClicked: { myText.focus = true } + onClicked: { myText.focus = true; myText.openSoftwareInputPanel(); } } } } diff --git a/examples/declarative/toys/dynamicscene/dynamicscene.qml b/examples/declarative/toys/dynamicscene/dynamicscene.qml index 659a257..1edb841 100644 --- a/examples/declarative/toys/dynamicscene/dynamicscene.qml +++ b/examples/declarative/toys/dynamicscene/dynamicscene.qml @@ -50,7 +50,12 @@ Item { //This is a desktop-sized example width: 800; height: 480 - + + MouseArea { + anchors.fill: parent + onClicked: window.focus = false; + } + //This is the message box that pops up when there's an error Rectangle { id: dialog diff --git a/examples/declarative/tutorials/samegame/samegame4/content/Dialog.qml b/examples/declarative/tutorials/samegame/samegame4/content/Dialog.qml index d235d35..c216c08 100644 --- a/examples/declarative/tutorials/samegame/samegame4/content/Dialog.qml +++ b/examples/declarative/tutorials/samegame/samegame4/content/Dialog.qml @@ -58,10 +58,12 @@ Rectangle { function showWithInput(text) { show(text); textInput.opacity = 1; + textInput.focus = true; textInput.text = "" } function hide() { + textInput.focus = false; container.opacity = 0; container.closed(); } @@ -70,6 +72,7 @@ Rectangle { width: dialogText.width + textInput.width + 20 height: dialogText.height + 20 opacity: 0 + visible: opacity > 0 Text { id: dialogText @@ -82,7 +85,6 @@ Rectangle { id: textInput anchors { verticalCenter: parent.verticalCenter; left: dialogText.right } width: 80 - focus: true text: "" onAccepted: container.hide() // close dialog when Enter is pressed @@ -91,7 +93,13 @@ Rectangle { MouseArea { anchors.fill: parent - onClicked: hide(); + + onClicked: { + if (textInput.text == "" && textInput.opacity > 0) + textInput.openSoftwareInputPanel(); + else + hide(); + } } //![3] diff --git a/examples/declarative/ui-components/searchbox/SearchBox.qml b/examples/declarative/ui-components/searchbox/SearchBox.qml index c022626..eaa6b6b 100644 --- a/examples/declarative/ui-components/searchbox/SearchBox.qml +++ b/examples/declarative/ui-components/searchbox/SearchBox.qml @@ -66,7 +66,7 @@ FocusScope { font.italic: true } - MouseArea { anchors.fill: parent; onClicked: focusScope.focus = true } + MouseArea { anchors.fill: parent; onClicked: { focusScope.focus = true; textInput.openSoftwareInputPanel(); } } TextInput { id: textInput @@ -82,7 +82,7 @@ FocusScope { MouseArea { anchors.fill: parent - onClicked: { textInput.text = ''; focusScope.focus = true } + onClicked: { textInput.text = ''; focusScope.focus = true; textInput.openSoftwareInputPanel(); } } } diff --git a/examples/declarative/ui-components/searchbox/main.qml b/examples/declarative/ui-components/searchbox/main.qml index 0508d5a..bf3bed8 100644 --- a/examples/declarative/ui-components/searchbox/main.qml +++ b/examples/declarative/ui-components/searchbox/main.qml @@ -41,9 +41,14 @@ import Qt 4.7 Rectangle { + id: page width: 500; height: 250 color: "#edecec" + MouseArea { + anchors.fill: parent + onClicked: page.focus = false; + } Column { anchors { horizontalCenter: parent.horizontalCenter; verticalCenter: parent.verticalCenter } spacing: 10 diff --git a/examples/ja_JP/linguist/hellotr/hellotr.pro b/examples/ja_JP/linguist/hellotr/hellotr.pro new file mode 100644 index 0000000..3846bfb --- /dev/null +++ b/examples/ja_JP/linguist/hellotr/hellotr.pro @@ -0,0 +1,13 @@ +#! [0] +SOURCES = main.cpp +#! [0] #! [1] +TRANSLATIONS = hellotr_ja.ts +#! [1] + +# install +target.path = $$[QT_INSTALL_EXAMPLES]/linguist/hellotr +sources.files = $$SOURCES *.pro +sources.path = $$[QT_INSTALL_EXAMPLES]/linguist/hellotr +INSTALLS += target sources + +symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri) diff --git a/examples/ja_JP/linguist/hellotr/main.cpp b/examples/ja_JP/linguist/hellotr/main.cpp new file mode 100644 index 0000000..ad122e9 --- /dev/null +++ b/examples/ja_JP/linguist/hellotr/main.cpp @@ -0,0 +1,71 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QApplication> +#include <QPushButton> +//! [0] +#include <QTranslator> +//! [0] + +//! [1] //! [2] +int main(int argc, char *argv[]) +//! [1] //! [3] //! [4] +{ + QApplication app(argc, argv); +//! [3] + +//! [5] + QTranslator translator; +//! [5] //! [6] + translator.load("hellotr_ja"); +//! [6] //! [7] + app.installTranslator(&translator); +//! [4] //! [7] + +//! [8] + QPushButton hello(QPushButton::tr("Hello world!")); +//! [8] + hello.resize(100, 30); + + hello.show(); + return app.exec(); +} +//! [2] diff --git a/examples/multimedia/videographicsitem/videoplayer.cpp b/examples/multimedia/videographicsitem/videoplayer.cpp index 281cd6e..f98f542 100644 --- a/examples/multimedia/videographicsitem/videoplayer.cpp +++ b/examples/multimedia/videographicsitem/videoplayer.cpp @@ -115,7 +115,20 @@ VideoPlayer::~VideoPlayer() void VideoPlayer::openFile() { - QString fileName = QFileDialog::getOpenFileName(this, tr("Open Movie")); + QStringList supportedFormats; + foreach (QString fmt, QMovie::supportedFormats()) + supportedFormats << fmt; + foreach (QString fmt, QImageReader::supportedImageFormats()) + supportedFormats << fmt; + + QString filter = "Images ("; + foreach ( QString fmt, supportedFormats) { + filter.append(QString("*.%1 ").arg(fmt)); + } + filter.append(")"); + + QString fileName = QFileDialog::getOpenFileName(this, tr("Open Movie"), + QDir::homePath(), filter); if (!fileName.isEmpty()) { videoItem->stop(); diff --git a/examples/multimedia/videowidget/videoplayer.cpp b/examples/multimedia/videowidget/videoplayer.cpp index 87a2621..ad12069 100644 --- a/examples/multimedia/videowidget/videoplayer.cpp +++ b/examples/multimedia/videowidget/videoplayer.cpp @@ -96,7 +96,20 @@ VideoPlayer::~VideoPlayer() void VideoPlayer::openFile() { - QString fileName = QFileDialog::getOpenFileName(this, tr("Open Movie")); + QStringList supportedFormats; + foreach (QString fmt, QMovie::supportedFormats()) + supportedFormats << fmt; + foreach (QString fmt, QImageReader::supportedImageFormats()) + supportedFormats << fmt; + + QString filter = "Images ("; + foreach ( QString fmt, supportedFormats) { + filter.append(QString("*.%1 ").arg(fmt)); + } + filter.append(")"); + + QString fileName = QFileDialog::getOpenFileName(this, tr("Open Movie"), + QDir::homePath(), filter); if (!fileName.isEmpty()) { surface->stop(); diff --git a/examples/tutorials/addressbook/part3/addressbook.cpp b/examples/tutorials/addressbook/part3/addressbook.cpp index adb87ef..28a570a 100644 --- a/examples/tutorials/addressbook/part3/addressbook.cpp +++ b/examples/tutorials/addressbook/part3/addressbook.cpp @@ -125,6 +125,7 @@ void AddressBook::submitContact() if (name == "" || address == "") { QMessageBox::information(this, tr("Empty Field"), tr("Please enter a name and address.")); + return; } if (!contacts.contains(name)) { diff --git a/examples/tutorials/addressbook/part4/addressbook.cpp b/examples/tutorials/addressbook/part4/addressbook.cpp index 1b7a6c4..55d551f 100644 --- a/examples/tutorials/addressbook/part4/addressbook.cpp +++ b/examples/tutorials/addressbook/part4/addressbook.cpp @@ -134,6 +134,7 @@ void AddressBook::submitContact() if (name == "" || address == "") { QMessageBox::information(this, tr("Empty Field"), tr("Please enter a name and address.")); + return; } //! [submitContact() function part1] if (currentMode == AddingMode) { diff --git a/examples/tutorials/addressbook/part5/addressbook.cpp b/examples/tutorials/addressbook/part5/addressbook.cpp index 80c18c3..1b3f451 100644 --- a/examples/tutorials/addressbook/part5/addressbook.cpp +++ b/examples/tutorials/addressbook/part5/addressbook.cpp @@ -141,6 +141,7 @@ void AddressBook::submitContact() if (name == "" || address == "") { QMessageBox::information(this, tr("Empty Field"), tr("Please enter a name and address.")); + return; } if (currentMode == AddingMode) { diff --git a/examples/tutorials/addressbook/part6/addressbook.cpp b/examples/tutorials/addressbook/part6/addressbook.cpp index fc41190..724971c 100644 --- a/examples/tutorials/addressbook/part6/addressbook.cpp +++ b/examples/tutorials/addressbook/part6/addressbook.cpp @@ -147,6 +147,7 @@ void AddressBook::submitContact() if (name == "" || address == "") { QMessageBox::information(this, tr("Empty Field"), tr("Please enter a name and address.")); + return; } if (currentMode == AddingMode) { diff --git a/examples/tutorials/addressbook/part7/addressbook.cpp b/examples/tutorials/addressbook/part7/addressbook.cpp index 3ab8702..bf00298 100644 --- a/examples/tutorials/addressbook/part7/addressbook.cpp +++ b/examples/tutorials/addressbook/part7/addressbook.cpp @@ -149,6 +149,7 @@ void AddressBook::submitContact() if (name == "" || address == "") { QMessageBox::information(this, tr("Empty Field"), tr("Please enter a name and address.")); + return; } if (currentMode == AddingMode) { |