summaryrefslogtreecommitdiff
path: root/examples/declarative/common/imports
diff options
context:
space:
mode:
authorAaron McCarthy <aaron.mccarthy@nokia.com>2012-03-23 12:55:35 +1000
committerQt by Nokia <qt-info@nokia.com>2012-03-26 07:17:32 +0200
commit7c3f383152f5c35df70a33b7dd60463786399a67 (patch)
tree8a43e7cf0739b0f158e7c56831ea77de97605a35 /examples/declarative/common/imports
parent946ce56da7ec2bc6bf054feaa8c2222d79749759 (diff)
downloadqtlocation-7c3f383152f5c35df70a33b7dd60463786399a67.tar.gz
Remove use of Loader element in Dialogs.
Simplify the code by removing the Loader element. There is really no need for it as a content item can be constructed directly. Factor out the code for text field entry dialogs into a separate InputDialog element. Dialogs that create a custom content item no longer carry around unneeded API. Account for the possibility of an on screen virtual keyboard. Change-Id: I808e040c264b8c8389a03070cc628e2e4518d118 Reviewed-by: Alex Wilson <alex.wilson@nokia.com> Reviewed-by: abcd <amos.choy@nokia.com>
Diffstat (limited to 'examples/declarative/common/imports')
-rw-r--r--examples/declarative/common/imports/QtLocation/examples/dialogs/Dialog.qml155
-rw-r--r--examples/declarative/common/imports/QtLocation/examples/dialogs/ErrorDialog.qml2
-rw-r--r--examples/declarative/common/imports/QtLocation/examples/dialogs/InputDialog.qml94
-rw-r--r--examples/declarative/common/imports/QtLocation/examples/qmldir1
4 files changed, 152 insertions, 100 deletions
diff --git a/examples/declarative/common/imports/QtLocation/examples/dialogs/Dialog.qml b/examples/declarative/common/imports/QtLocation/examples/dialogs/Dialog.qml
index 8abaf45f..a7592aba 100644
--- a/examples/declarative/common/imports/QtLocation/examples/dialogs/Dialog.qml
+++ b/examples/declarative/common/imports/QtLocation/examples/dialogs/Dialog.qml
@@ -43,134 +43,91 @@ import "../components"
Item {
id: dialog
+
signal goButtonClicked
signal cancelButtonClicked
signal clearButtonClicked
- anchors.fill: parent
-
property alias title: titleBar.text
- property alias dialogModel: dialogModel
- property alias length: dialogModel.count
+
property int gap: 10
- property int listItemHeight: titleBar.font.pixelSize * 1.5
- property alias customLoader: componentLoader
property bool showButtons: true
+ property Item item
opacity: 0
+ anchors.fill: parent
- function setModel(objects)
- {
- dialogModel.clear()
+ Fader {}
- for (var i=0; i< objects.length; i++){
- dialogModel.append({"labelText": objects[i][0], "inputText": objects[i][1]})
- }
+ onItemChanged: {
+ if (item)
+ item.parent = dataRect;
}
- Fader {}
-
Rectangle {
id: dialogRectangle
+ property int maximumDialogHeight: {
+ if (dialog.opacity === 0 ||
+ (Qt.inputMethod.keyboardRectangle.width === 0 && Qt.inputMethod.keyboardRectangle.height === 0)) {
+ return dialog.height;
+ } else {
+ return dialog.mapFromItem(null, Qt.inputMethod.keyboardRectangle.x, Qt.inputMethod.keyboardRectangle.y).y
+ }
+ }
+ property int maximumContentHeight: maximumDialogHeight - titleBar.height - buttons.height - gap*1.5
+
color: "#ECECEC"
opacity: parent.opacity
- width: parent.width - gap;
- height: dataRect.height + titleBar.height + buttons.height + gap*1.5
- anchors {
- verticalCenter: parent.verticalCenter
- left: parent.left
- leftMargin: gap/2
- }
+ height: dataRect.height + titleBar.height + buttons.height + gap*1.5
+ y: (maximumDialogHeight - height) / 2
+ anchors.left: parent.left
+ anchors.leftMargin: gap/2
+ anchors.right: parent.right
+ anchors.rightMargin: gap/2
radius: 5
TitleBar {
id: titleBar;
- width: parent.width; height: 40;
- anchors.top: parent.top; anchors.left: parent.left;
- opacity: 0.9
- onClicked: { dialog.cancelButtonClicked() }
- }
-
- ListModel {
- id: dialogModel
- }
-
- Component{
- id: listDelegate
- TextWithLabel {
- id: textWithLabel
- label: labelText
- text: inputText
- width: dataRect.width - gap
- labelWidth: 95
+ height: 40
+ anchors.top: parent.top
+ anchors.left: parent.left
+ anchors.right: parent.right
- onTextChanged:
- {
- dialogModel.set(index, {"inputText": text})
- }
+ opacity: 0.9
+ onClicked: {
+ Qt.inputMethod.hide();
+ dialog.cancelButtonClicked();
}
- }
- Rectangle {
- id: dataRect
- color: "#ECECEC"
- radius: 5
- width:dialogRectangle.width - gap
- height: childrenRect.height + gap
- anchors {
- top: titleBar.bottom
- topMargin: gap/2
- left: parent.left
- leftMargin: gap/2
}
- Loader {
- id: componentLoader;
- anchors {
- top: dataRect.top
- topMargin: gap/2
- left: parent.left
- leftMargin: gap/2
- right: parent.right
- rightMargin: gap/2
+ Rectangle {
+ id: dataRect
+ color: "#ECECEC"
+ radius: 5
+
+ anchors.top: titleBar.bottom
+ anchors.left: dialogRectangle.left
+ anchors.right: dialogRectangle.right
+ anchors.margins: gap/2
+ height: Math.min(dialogRectangle.maximumContentHeight, item ? item.implicitHeight : 0)
+
+ Binding {
+ target: item
+ property: "anchors.fill"
+ value: dataRect
}
-
- Component.onCompleted: {
- if (!sourceComponent)
- sourceComponent = listComponent;
+ Binding {
+ target: item
+ property: "anchors.margins"
+ value: gap/2
}
-
}
- Component {
- id: listComponent
-
- ListView {
- id: listview
- model: dialogModel
- delegate: listDelegate
- spacing: gap/2
- clip: true
- snapMode: ListView.SnapToItem
- interactive: height < (listItemHeight + gap/2)*length + gap/2
- width: parent.width
- height: Math.min(dialog.height * 0.7, (listItemHeight + gap/2)*length + gap/2)
-
- Connections {
- target: dialog
- onClearButtonClicked: {
- for (var i = 0; i<length; i++)
- dialogModel.set(i, {"inputText": ""})
- }
- }
- }
- }
- }
-
Row {
id: buttons
anchors.top: dataRect.bottom
@@ -182,16 +139,16 @@ Item {
Button {
id: buttonClearAll
text: "Clear"
- width: 80; height: parent.height
+ width: 80
+ height: parent.height
onClicked: dialog.clearButtonClicked()
}
Button {
id: buttonGo
text: "Go!"
- width: 80; height: parent.height
- onClicked: {
- dialog.goButtonClicked ()
- }
+ width: 80
+ height: parent.height
+ onClicked: dialog.goButtonClicked()
}
}
}
diff --git a/examples/declarative/common/imports/QtLocation/examples/dialogs/ErrorDialog.qml b/examples/declarative/common/imports/QtLocation/examples/dialogs/ErrorDialog.qml
index be94c2cd..1b312da5 100644
--- a/examples/declarative/common/imports/QtLocation/examples/dialogs/ErrorDialog.qml
+++ b/examples/declarative/common/imports/QtLocation/examples/dialogs/ErrorDialog.qml
@@ -47,7 +47,7 @@ Dialog {
opacity: 0
showButtons:false
- customLoader.sourceComponent: Text {
+ item: Text {
id: errorText
text: errorRoot.text
}
diff --git a/examples/declarative/common/imports/QtLocation/examples/dialogs/InputDialog.qml b/examples/declarative/common/imports/QtLocation/examples/dialogs/InputDialog.qml
new file mode 100644
index 00000000..6d9822ab
--- /dev/null
+++ b/examples/declarative/common/imports/QtLocation/examples/dialogs/InputDialog.qml
@@ -0,0 +1,94 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples 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 QtQuick 2.0
+import "../components"
+
+Dialog {
+ id: dialog
+
+ property alias dialogModel: dialogModel
+ property alias length: dialogModel.count
+
+ property int listItemHeight: 21
+
+ onClearButtonClicked: {
+ for (var i = 0; i < length; ++i)
+ dialogModel.set(i, { "inputText": "" });
+ }
+
+ item: ListView {
+ id: listview
+
+ model: dialogModel
+ delegate: listDelegate
+ spacing: gap/2
+ clip: true
+ snapMode: ListView.SnapToItem
+ implicitHeight: (listItemHeight + gap/2)*length + gap/2
+ interactive: height < implicitHeight
+ width: parent.width
+ }
+
+ function setModel(objects) {
+ dialogModel.clear();
+ for (var i = 0; i < objects.length; ++i) {
+ dialogModel.append({ "labelText": objects[i][0], "inputText": objects[i][1] });
+ }
+ }
+
+ ListModel {
+ id: dialogModel
+ }
+
+ Component {
+ id: listDelegate
+
+ TextWithLabel {
+ id: textWithLabel
+ label: labelText
+ text: inputText
+ width: parent ? parent.width : 0
+ labelWidth: 95
+
+ onTextChanged: dialogModel.set(index, {"inputText": text})
+ }
+ }
+}
diff --git a/examples/declarative/common/imports/QtLocation/examples/qmldir b/examples/declarative/common/imports/QtLocation/examples/qmldir
index 34469887..9089f6c0 100644
--- a/examples/declarative/common/imports/QtLocation/examples/qmldir
+++ b/examples/declarative/common/imports/QtLocation/examples/qmldir
@@ -10,3 +10,4 @@ TextWithLabel 5.0 components/TextWithLabel.qml
TitleBar 5.0 components/TitleBar.qml
Dialog 5.0 dialogs/Dialog.qml
ErrorDialog 5.0 dialogs/ErrorDialog.qml
+InputDialog 5.0 dialogs/InputDialog.qml