diff options
author | Zeno Albisser <zeno.albisser@nokia.com> | 2010-08-17 04:14:56 -0400 |
---|---|---|
committer | Zeno Albisser <zeno.albisser@nokia.com> | 2010-08-17 04:14:56 -0400 |
commit | 67fb52c95ff8925057cd4d1d86a9221af3482a22 (patch) | |
tree | 9a4be64560329771f3d562e08bcac24c2b76359c | |
parent | d60d1c109d07e5a820afce632a872c31c1a87565 (diff) |
integrated StrokeList into qml-dashboard
-rw-r--r-- | multilayer-dashboard/Button.qml | 155 | ||||
-rw-r--r-- | multilayer-dashboard/MainWidget.qml | 13 | ||||
-rw-r--r-- | multilayer-dashboard/RowFour.qml | 111 | ||||
-rw-r--r-- | multilayer-dashboard/RowOne.qml | 111 | ||||
-rw-r--r-- | multilayer-dashboard/RowThree.qml (renamed from multilayer-dashboard/RowWidget.qml) | 2 | ||||
-rw-r--r-- | multilayer-dashboard/RowTwo.qml | 103 | ||||
-rw-r--r-- | multilayer-dashboard/StrokeList.qml | 49 | ||||
-rw-r--r-- | multilayer-dashboard/TapWidget.qml | 6 | ||||
-rw-r--r-- | stroke-list/StrokeList.qml (renamed from stroke-list/main.qml) | 0 |
9 files changed, 543 insertions, 7 deletions
diff --git a/multilayer-dashboard/Button.qml b/multilayer-dashboard/Button.qml new file mode 100644 index 0000000..0277854 --- /dev/null +++ b/multilayer-dashboard/Button.qml @@ -0,0 +1,155 @@ +import Qt 4.7 +import Qt.labs.gestures 1.0 + +Rectangle { + id: button + + property string text : "Press me, Hold me, Strike me" + property int counter : 0 + property string bgColor: "steelblue" + property bool marked : false + + property bool enabled : state != "disabled" + + width: 160 + height: 40 + radius: 10 + + Rectangle { + id: background + anchors.fill: parent + radius: 10 + opacity: 0.3 + color: parent.bgColor + } + + Rectangle { + id: mark + x: 10 + y: 5 + width: 0 + height: 0 + radius: 30 + color: "black" + opacity: 1.0 + smooth: true + } + + function toggleMark() { + button.marked = !button.marked + if (button.marked) { + mark.width = 30 + mark.height = 30 + } else { + mark.width = 0 + mark.height = 0 + } + } + + function increaseCounter() { + counter = counter + 1 + } + + Text { + id: labelText + text: parent.text + (counter ? " "+counter : "") + anchors.centerIn: parent + } + + Rectangle { + id: stroke + + x: parent.width * 0.3 / 2 + anchors.verticalCenter: parent.verticalCenter + width: 0 + height : 10 + + color: "red" + opacity: 1.0 + } + + + states: [ + State { + name: "" + PropertyChanges { target: background; opacity: 0.3 } + PropertyChanges { target: labelText; opacity: 1.0 } + PropertyChanges { target: stroke; width: 0 } + }, + State { + name: "pressed" + PropertyChanges { target: background; opacity: 1.0 } + }, + State { + name: "disabled" + PropertyChanges { target: background; opacity: 0.3 } + PropertyChanges { target: mark; opacity: 0.3 } + PropertyChanges { target: labelText; opacity: 0.3 } + PropertyChanges { target: stroke; width: stroke.parent.width * 0.7 } + } + ] + transitions: [ + Transition { + from: "*" + to: "disabled" + PropertyAnimation { target: stroke; duration: 1000; property: "width" } + }, + Transition { + from: "disabled" + to: "" + PropertyAnimation { target: stroke; duration: 1000; property: "width" } + } + ] + + property bool handled: false + + function isHorizontalSwipe(angle) { + if (angle > 150 && angle < 210) + return true; + if (angle > 330 || angle < 30) + return true; + return false; + } + + GestureArea { + anchors.fill: parent + + Tap { + when: button.enabled + onStarted: { button.state = "pressed" } + onCanceled: { + if (!button.handled) { + button.state = ""; + } + } + onFinished: { + if (!button.handled) { + button.state = ""; + button.increaseCounter(); + } + button.handled = false; + } + } + + TapAndHold { + when: button.enabled + onFinished: { console.log("tap-and-hold"); button.toggleMark() } + } + + Swipe { + when: gesture.speed > 25 + onStarted: button.handled = true + onFinished: { + if (isHorizontalSwipe(gesture.swipeAngle)) { + if (gesture.horizontalDirection == SwipeGesture.Right) { + button.state = "disabled" + } else if (gesture.horizontalDirection == SwipeGesture.Left) { + script: button.state = "" + } + } + button.handled = false + } + } + } +} + diff --git a/multilayer-dashboard/MainWidget.qml b/multilayer-dashboard/MainWidget.qml index 96003b6..2b46787 100644 --- a/multilayer-dashboard/MainWidget.qml +++ b/multilayer-dashboard/MainWidget.qml @@ -49,26 +49,33 @@ Rectangle { Rectangle { id: rowWidgetContainer - RowWidget { + RowOne { id: firstRow reparentWidget: dashboard topLevel: dashboard } - RowWidget { + RowTwo { id: secondRow anchors.left : firstRow.right reparentWidget: dashboard topLevel: dashboard } - RowWidget { + RowThree { id: thirdRow anchors.left : secondRow.right //reparentWidget: dashboard topLevel: dashboard } + RowFour { + id: fourthRow + anchors.left : thirdRow.right + //reparentWidget: dashboard + topLevel: dashboard + } + property int maxX : (dashboard.width < rowWidgetContainer.childrenRect.width) ? 0 : (dashboard.width - rowWidgetContainer.childrenRect.width) diff --git a/multilayer-dashboard/RowFour.qml b/multilayer-dashboard/RowFour.qml new file mode 100644 index 0000000..e3f2db6 --- /dev/null +++ b/multilayer-dashboard/RowFour.qml @@ -0,0 +1,111 @@ +/**************************************************************************** +** +** 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 Qt.labs.gestures 1.0 + +Rectangle { + width: 200 + height: 340 + id: myRow + property variant reparentWidget: myRow + property variant topLevel: myRow + + Rectangle { + id: tapWidgetContainer + + TapWidget { + x: 10 + id: firstWidget + color: "green" + reparentWidget: myRow.reparentWidget + } + StrokeList { + x:10 + anchors.top : firstWidget.bottom + anchors.topMargin: 2.0 + id: strokeList +// reparentWidget: myRow.reparentWidget + } + TapWidget { + x:10 + anchors.top : strokeList.bottom + anchors.topMargin : 2.0 + id: secondWidget + color: "blue" + reparentWidget: myRow.reparentWidget + } + TapWidget { + x:10 + anchors.top : secondWidget.bottom + anchors.topMargin : 2.0 + id: thirdWidget + reparentWidget: myRow.reparentWidget + } + + + property int maxY : (tapWidgetContainer.childrenRect.height > topLevel.height) ? + 0 : + (topLevel.height - tapWidgetContainer.childrenRect.height) + property int minY : (tapWidgetContainer.childrenRect.height > topLevel.height) ? + -(tapWidgetContainer.childrenRect.height - topLevel.height) : + 0 + } // end Rectangle + + GestureArea { + id: rowGestureArea + anchors.fill: parent + + Pan { + when: Math.abs(gesture.delta.y) > Math.abs(gesture.delta.x) + onUpdated: { + tapWidgetContainer.pos.y = tapWidgetContainer.pos.y + gesture.delta.y; + + if (tapWidgetContainer.pos.y > tapWidgetContainer.maxY) { // limit pan down + tapWidgetContainer.pos.y = tapWidgetContainer.maxY; + } + else if (tapWidgetContainer.pos.y < tapWidgetContainer.minY) {// limit pan up + tapWidgetContainer.pos.y = tapWidgetContainer.minY; + } + } + } + } // end GestureArea + +} diff --git a/multilayer-dashboard/RowOne.qml b/multilayer-dashboard/RowOne.qml new file mode 100644 index 0000000..60badf3 --- /dev/null +++ b/multilayer-dashboard/RowOne.qml @@ -0,0 +1,111 @@ +/**************************************************************************** +** +** 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 Qt.labs.gestures 1.0 + +Rectangle { + width: 200 + height: 340 + id: myRow + property variant reparentWidget: myRow + property variant topLevel: myRow + + Rectangle { + id: tapWidgetContainer + + TapWidget { + x: 10 + id: firstWidget + color: "green" + reparentWidget: myRow.reparentWidget + } + TapWidget { + x:10 + anchors.top : firstWidget.bottom + anchors.topMargin : 2.0 + id: secondWidget + color: "blue" + reparentWidget: myRow.reparentWidget + } + TapWidget { + x:10 + anchors.top : secondWidget.bottom + anchors.topMargin : 2.0 + id: thirdWidget + reparentWidget: myRow.reparentWidget + } + StrokeList { + x:10 + anchors.top : thirdWidget.bottom + anchors.topMargin: 2.0 + id: strokeList +// reparentWidget: myRow.reparentWidget + } + + + property int maxY : (tapWidgetContainer.childrenRect.height > topLevel.height) ? + 0 : + (topLevel.height - tapWidgetContainer.childrenRect.height) + property int minY : (tapWidgetContainer.childrenRect.height > topLevel.height) ? + -(tapWidgetContainer.childrenRect.height - topLevel.height) : + 0 + } // end Rectangle + + GestureArea { + id: rowGestureArea + anchors.fill: parent + + Pan { + when: Math.abs(gesture.delta.y) > Math.abs(gesture.delta.x) + onUpdated: { + tapWidgetContainer.pos.y = tapWidgetContainer.pos.y + gesture.delta.y; + + if (tapWidgetContainer.pos.y > tapWidgetContainer.maxY) { // limit pan down + tapWidgetContainer.pos.y = tapWidgetContainer.maxY; + } + else if (tapWidgetContainer.pos.y < tapWidgetContainer.minY) {// limit pan up + tapWidgetContainer.pos.y = tapWidgetContainer.minY; + } + } + } + } // end GestureArea + +} diff --git a/multilayer-dashboard/RowWidget.qml b/multilayer-dashboard/RowThree.qml index fed0681..98b7d0f 100644 --- a/multilayer-dashboard/RowWidget.qml +++ b/multilayer-dashboard/RowThree.qml @@ -42,7 +42,7 @@ import Qt 4.7 import Qt.labs.gestures 1.0 Rectangle { - width: 180 + width: 200 height: 340 id: myRow property variant reparentWidget: myRow diff --git a/multilayer-dashboard/RowTwo.qml b/multilayer-dashboard/RowTwo.qml new file mode 100644 index 0000000..98b7d0f --- /dev/null +++ b/multilayer-dashboard/RowTwo.qml @@ -0,0 +1,103 @@ +/**************************************************************************** +** +** 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 Qt.labs.gestures 1.0 + +Rectangle { + width: 200 + height: 340 + id: myRow + property variant reparentWidget: myRow + property variant topLevel: myRow + + Rectangle { + id: tapWidgetContainer + + TapWidget { + x: 10 + id: firstWidget + color: "green" + reparentWidget: myRow.reparentWidget + } + TapWidget { + x:10 + anchors.top : firstWidget.bottom + anchors.topMargin : 2.0 + id: secondWidget + color: "blue" + reparentWidget: myRow.reparentWidget + } + TapWidget { + x:10 + anchors.top : secondWidget.bottom + anchors.topMargin : 2.0 + id: thirdWidget + reparentWidget: myRow.reparentWidget + } + + property int maxY : (tapWidgetContainer.childrenRect.height > topLevel.height) ? + 0 : + (topLevel.height - tapWidgetContainer.childrenRect.height) + property int minY : (tapWidgetContainer.childrenRect.height > topLevel.height) ? + -(tapWidgetContainer.childrenRect.height - topLevel.height) : + 0 + } // end Rectangle + + GestureArea { + id: rowGestureArea + anchors.fill: parent + + Pan { + when: Math.abs(gesture.delta.y) > Math.abs(gesture.delta.x) + onUpdated: { + tapWidgetContainer.pos.y = tapWidgetContainer.pos.y + gesture.delta.y; + + if (tapWidgetContainer.pos.y > tapWidgetContainer.maxY) { // limit pan down + tapWidgetContainer.pos.y = tapWidgetContainer.maxY; + } + else if (tapWidgetContainer.pos.y < tapWidgetContainer.minY) {// limit pan up + tapWidgetContainer.pos.y = tapWidgetContainer.minY; + } + } + } + } // end GestureArea + +} diff --git a/multilayer-dashboard/StrokeList.qml b/multilayer-dashboard/StrokeList.qml new file mode 100644 index 0000000..491c761 --- /dev/null +++ b/multilayer-dashboard/StrokeList.qml @@ -0,0 +1,49 @@ +import Qt 4.7 +import Qt.labs.gestures 1.0 + +Rectangle { + + id: mainrect + + width: 180 + height: 334 + + function foo(index) { + var colors = ["blue", "green", "grey", "red", "lightgreen"]; + return colors[index % colors.length] + } + + Rectangle { + id: list + anchors.left: parent.left + anchors.right: parent.right + height: parent.height + + Repeater { + model: [ "apple", "orange", "pineapple", "coconut", "foo", "bar", "baz", "zealot" ] + + Button { + x: 0 + y: 0 + (height + 2) * index + bgColor: foo(index) + text: modelData + } + } + } + GestureArea { + anchors.fill: parent + property bool panEnabled : false + + Pan { + onUpdated: { + if (parent.panEnabled) + list.y += gesture.delta.y + else if (Math.abs(gesture.offset.y) >= 10 && Math.abs(gesture.offset.x) < 10) + parent.panEnabled = true + } + onFinished: { + parent.panEnabled = false + } + } + } +} diff --git a/multilayer-dashboard/TapWidget.qml b/multilayer-dashboard/TapWidget.qml index b80787f..8c622e2 100644 --- a/multilayer-dashboard/TapWidget.qml +++ b/multilayer-dashboard/TapWidget.qml @@ -59,7 +59,7 @@ Rectangle { Text { id: labelText - text: "Press me, Hold me!!!" + text: "Tap me!!!" anchors.centerIn: parent } @@ -73,7 +73,7 @@ Rectangle { GestureArea { id: tapGestureArea anchors.fill: parent - TapAndHold { + Tap { onFinished: { if (!innerWidget.fullScreen) { innerWidget.opacity = 1.0 @@ -88,7 +88,7 @@ Rectangle { innerWidget.parent = testWidget innerWidget.anchors.fill = testWidget innerWidget.fullScreen = false - labelText.text = "Press me, Hold me!!!" + labelText.text = "Tap me!!!" } } } diff --git a/stroke-list/main.qml b/stroke-list/StrokeList.qml index edf1fed..edf1fed 100644 --- a/stroke-list/main.qml +++ b/stroke-list/StrokeList.qml |