diff options
author | Warwick Allison <warwick.allison@nokia.com> | 2009-08-24 01:17:38 (GMT) |
---|---|---|
committer | Warwick Allison <warwick.allison@nokia.com> | 2009-08-24 01:17:38 (GMT) |
commit | df432c12585e00b682776f5c8a879611a0f07ef7 (patch) | |
tree | 9e7e6ed4d2ae790310ddec0a2a8f6eefebe07e5f /examples/declarative | |
parent | 9c6472491c9d5ac23696767388bdeb8337e2e0ee (diff) | |
download | Qt-df432c12585e00b682776f5c8a879611a0f07ef7.zip Qt-df432c12585e00b682776f5c8a879611a0f07ef7.tar.gz Qt-df432c12585e00b682776f5c8a879611a0f07ef7.tar.bz2 |
Fix WebViewSettings
More QML <-> JavaScript integration, with example.
From Tapani Mikola
Diffstat (limited to 'examples/declarative')
-rw-r--r-- | examples/declarative/webview/content/FieldText.qml | 163 | ||||
-rw-r--r-- | examples/declarative/webview/content/SpinSquare.qml | 4 | ||||
-rw-r--r-- | examples/declarative/webview/content/pics/cancel.png | bin | 0 -> 1038 bytes | |||
-rw-r--r-- | examples/declarative/webview/content/pics/ok.png | bin | 0 -> 655 bytes |
4 files changed, 165 insertions, 2 deletions
diff --git a/examples/declarative/webview/content/FieldText.qml b/examples/declarative/webview/content/FieldText.qml new file mode 100644 index 0000000..fe55185 --- /dev/null +++ b/examples/declarative/webview/content/FieldText.qml @@ -0,0 +1,163 @@ +import Qt 4.6 + +Item { + id: fieldText + height: 30 + property string text: "" + property string label: "" + property bool mouseGrabbed: false + signal confirmed + signal cancelled + signal startEdit + + resources: [ + Script { + + function edit() { + if (!mouseGrabbed) { + fieldText.startEdit(); + fieldText.state='editing'; + mouseGrabbed=true; + } + } + + function confirm() { + fieldText.state=''; + fieldText.text = textEdit.text; + mouseGrabbed=false; + fieldText.confirmed(); + } + + function reset() { + textEdit.text = fieldText.text; + fieldText.state=''; + mouseGrabbed=false; + fieldText.cancelled(); + } + + } + ] + + Image { + id: cancelIcon + width: 22 + height: 22 + anchors.right: parent.right + anchors.rightMargin: 4 + anchors.verticalCenter: parent.verticalCenter + source: "pics/cancel.png" + opacity: 0 + } + + Image { + id: confirmIcon + width: 22 + height: 22 + anchors.left: parent.left + anchors.leftMargin: 4 + anchors.verticalCenter: parent.verticalCenter + source: "pics/ok.png" + opacity: 0 + } + + TextInput { + id: textEdit + text: fieldText.text + focus: false + anchors.left: parent.left + anchors.leftMargin: 0 + anchors.right: parent.right + anchors.rightMargin: 0 + anchors.verticalCenter: parent.verticalCenter + color: "black" + font.bold: true + readOnly: true + onAccepted: confirm() + Keys.onEscapePressed: reset() + } + + Text { + id: textLabel + x: 5 + width: parent.width-10 + anchors.verticalCenter: parent.verticalCenter + horizontalAlignment: "AlignHCenter" + color: fieldText.state == "editing" ? "#505050" : "#AAAAAA" + font.italic: true + font.bold: true + text: label + opacity: textEdit.text == '' ? 1 : 0 + opacity: Behavior { + NumberAnimation { + property: "opacity" + duration: 250 + } + } + } + + MouseRegion { + anchors.fill: cancelIcon + onClicked: { reset() } + } + + MouseRegion { + anchors.fill: confirmIcon + onClicked: { confirm() } + } + + MouseRegion { + id: editRegion + anchors.fill: textEdit + onClicked: { edit() } + } + + states: [ + State { + name: "editing" + PropertyChanges { + target: confirmIcon + opacity: 1 + } + PropertyChanges { + target: cancelIcon + opacity: 1 + } + PropertyChanges { + target: textEdit + color: "black" + readOnly: false + focus: true + selectionStart: 0 + selectionEnd: -1 + } + PropertyChanges { + target: editRegion + opacity: 0 + } + PropertyChanges { + target: textEdit.anchors + leftMargin: 34 + } + PropertyChanges { + target: textEdit.anchors + rightMargin: 34 + } + } + ] + + transitions: [ + Transition { + from: "" + to: "*" + reversible: true + NumberAnimation { + properties: "opacity,leftMargin,rightMargin" + duration: 200 + } + ColorAnimation { + property: "color" + duration: 150 + } + } + ] +} diff --git a/examples/declarative/webview/content/SpinSquare.qml b/examples/declarative/webview/content/SpinSquare.qml index 57ad697..6d5ada3 100644 --- a/examples/declarative/webview/content/SpinSquare.qml +++ b/examples/declarative/webview/content/SpinSquare.qml @@ -1,8 +1,8 @@ import Qt 4.6 Item { - properties var period : 250 - properties var color : "black" + property var period : 250 + propert var color : "black" id: Root Item { diff --git a/examples/declarative/webview/content/pics/cancel.png b/examples/declarative/webview/content/pics/cancel.png Binary files differnew file mode 100644 index 0000000..ecc9533 --- /dev/null +++ b/examples/declarative/webview/content/pics/cancel.png diff --git a/examples/declarative/webview/content/pics/ok.png b/examples/declarative/webview/content/pics/ok.png Binary files differnew file mode 100644 index 0000000..5795f04 --- /dev/null +++ b/examples/declarative/webview/content/pics/ok.png |