diff options
111 files changed, 2580 insertions, 739 deletions
diff --git a/demos/declarative/flickr/common/qmldir b/demos/declarative/flickr/common/qmldir new file mode 100644 index 0000000..0c94f60 --- /dev/null +++ b/demos/declarative/flickr/common/qmldir @@ -0,0 +1,10 @@ +ImageDetails 0.0 ImageDetails.qml +LikeOMeter 0.0 LikeOMeter.qml +Loading 0.0 Loading.qml +MediaButton 0.0 MediaButton.qml +MediaLineEdit 0.0 MediaLineEdit.qml +Progress 0.0 Progress.qml +RssModel 0.0 RssModel.qml +ScrollBar 0.0 ScrollBar.qml +Slider 0.0 Slider.qml +Star 0.0 Star.qml diff --git a/demos/declarative/samegame/content/qmldir b/demos/declarative/samegame/content/qmldir new file mode 100644 index 0000000..a8f8a98 --- /dev/null +++ b/demos/declarative/samegame/content/qmldir @@ -0,0 +1,3 @@ +BoomBlock 0.0 BoomBlock.qml +Button 0.0 Button.qml +Dialog 0.0 Dialog.qml diff --git a/demos/declarative/samegame/content/samegame.js b/demos/declarative/samegame/content/samegame.js index 15bafc4..1b81f87 100755 --- a/demos/declarative/samegame/content/samegame.js +++ b/demos/declarative/samegame/content/samegame.js @@ -7,7 +7,7 @@ var board = new Array(maxIndex); var tileSrc = "content/BoomBlock.qml"; var scoresURL = "http://qtfx-nokia.trolltech.com.au/samegame/scores.php"; var timer; -var component; +var component = createComponent(tileSrc); //Index function used instead of a 2D array function index(xIdx,yIdx) { @@ -179,9 +179,6 @@ function floodMoveCheck(xIdx, yIdx, type) } function createBlock(xIdx,yIdx){ - if(component==null) - component = createComponent(tileSrc); - // Note that we don't wait for the component to become ready. This will // only work if the block QML is a local file. Otherwise the component will // not be ready immediately. There is a statusChanged signal on the diff --git a/doc/src/declarative/animation.qdoc b/doc/src/declarative/animation.qdoc index 2d98322..ef18de3 100644 --- a/doc/src/declarative/animation.qdoc +++ b/doc/src/declarative/animation.qdoc @@ -41,7 +41,6 @@ /*! \page qmlanimation.html -\target qmlanimation \title QML Animation Animation in QML is done by animating properties of objects. Properties of type diff --git a/doc/src/declarative/qmlreference.qdoc b/doc/src/declarative/qmlreference.qdoc index 76269c3..6a874b6 100644 --- a/doc/src/declarative/qmlreference.qdoc +++ b/doc/src/declarative/qmlreference.qdoc @@ -74,7 +74,7 @@ \o \l {qmlmodels}{Data Models} \o \l {anchor-layout}{Anchor-based Layout} \o \l {qmlstates}{States} - \o \l {qmlanimation}{Animation} + \o \l {qmlanimation.html}{Animation} \o \l {qmlmodules.html}{Modules} \o \l {qmlfocus}{Keyboard Focus} \o \l {Extending types from QML} diff --git a/doc/src/declarative/qtdeclarative.qdoc b/doc/src/declarative/qtdeclarative.qdoc index ba2d70e..5d8623b 100644 --- a/doc/src/declarative/qtdeclarative.qdoc +++ b/doc/src/declarative/qtdeclarative.qdoc @@ -89,7 +89,7 @@ completely new applications. QML is fully \l {Extending QML}{extensible from C+ \o \l {qmlmodels}{Data Models} \o \l {anchor-layout}{Anchor-based Layout} \o \l {qmlstates}{States} -\o \l {qmlanimation}{Animation} +\o \l {qmlanimation.html}{Animation} \o \l {qmlmodules.html}{Modules} \o \l {qmlfocus}{Keyboard Focus} \o \l {Extending types from QML} diff --git a/examples/declarative/animation/color-animation.qml b/examples/declarative/animation/color-animation.qml index 0cf8a44..edb0659 100644 --- a/examples/declarative/animation/color-animation.qml +++ b/examples/declarative/animation/color-animation.qml @@ -30,18 +30,18 @@ Item { // the sun, moon, and stars Item { width: parent.width; height: 2 * parent.height - transformOrigin: "Center" + transformOrigin: Item.Center rotation: SequentialAnimation { running: true; repeat: true NumberAnimation { from: 0; to: 360; duration: 10000 } } Image { source: "images/sun.png"; y: 10; anchors.horizontalCenter: parent.horizontalCenter - transformOrigin: "Center"; rotation: -3 * parent.rotation + transformOrigin: Item.Center; rotation: -3 * parent.rotation } Image { source: "images/moon.png"; y: parent.height - 74; anchors.horizontalCenter: parent.horizontalCenter - transformOrigin: "Center"; rotation: -parent.rotation + transformOrigin: Item.Center; rotation: -parent.rotation } Particles { x: 0; y: parent.height/2; width: parent.width; height: parent.height/2 diff --git a/examples/declarative/animation/easing.qml b/examples/declarative/animation/easing.qml index 9e0a0d6..59e9b17 100644 --- a/examples/declarative/animation/easing.qml +++ b/examples/declarative/animation/easing.qml @@ -92,7 +92,7 @@ Rectangle { anchors.fill: parent; viewportHeight: layout.height Column { id: layout - anchors.left: window.left; anchors.right: window.right + anchors.left: parent.left; anchors.right: parent.right Repeater { model: easingTypes; delegate: delegate } } } diff --git a/examples/declarative/animation/property-animation.qml b/examples/declarative/animation/property-animation.qml index 4e0f6f4..0256137 100644 --- a/examples/declarative/animation/property-animation.qml +++ b/examples/declarative/animation/property-animation.qml @@ -26,7 +26,7 @@ Item { Image { anchors.horizontalCenter: parent.horizontalCenter source: "images/shadow.png"; y: smiley.minHeight + 58 - transformOrigin: "Center" + transformOrigin: Item.Center // The scale property depends on the y position of the smiley face. scale: smiley.y * 0.5 / (smiley.minHeight - smiley.maxHeight) diff --git a/examples/declarative/connections/Button.qml b/examples/declarative/connections/Button.qml new file mode 100644 index 0000000..1d46acc --- /dev/null +++ b/examples/declarative/connections/Button.qml @@ -0,0 +1,12 @@ +import Qt 4.6 + +Item { + id: button + width: 48; height: 48 + + property alias image: icon.source + signal clicked + + Image { id: icon } + MouseRegion { anchors.fill: icon; onClicked: button.clicked() } +} diff --git a/examples/declarative/connections/bg1.jpg b/examples/declarative/connections/bg1.jpg Binary files differnew file mode 100644 index 0000000..dfc7cee --- /dev/null +++ b/examples/declarative/connections/bg1.jpg diff --git a/examples/declarative/connections/connections.qml b/examples/declarative/connections/connections.qml index b693b7e..5dc211e 100644 --- a/examples/declarative/connections/connections.qml +++ b/examples/declarative/connections/connections.qml @@ -1,32 +1,30 @@ import Qt 4.6 Rectangle { - id: rect - color: "blue" - width: 40 - height: 30 + id: window; color: "#343434" + width: 640; height: 480 - Rectangle { - id: dot - color: "red" - width: 3 - height: 3 - x: rect.width/2 - y: rect.height/2 + function turnLeft() { + image.rotation -= 90 + } + function turnRight() { + image.rotation += 90 } - MouseRegion { - id: mr - anchors.fill: rect + Image { + id: image; source: "bg1.jpg"; anchors.centerIn: parent; transformOrigin: Item.Center + rotation: Behavior { NumberAnimation { easing: "easeOutCubic"; duration: 300 } } } - Connection { - sender: mr - signal: "clicked(mouse)" - script: { - color = "green"; - dot.x = mouse.x-1; - dot.y = mouse.y-1; - } + Button { + id: leftButton; image: "rotate-left.png" + anchors { left: parent.left; bottom: parent.bottom; leftMargin: 10; bottomMargin: 10 } + } + Button { + id: rightButton; image: "rotate-right.png" + anchors { right: parent.right; bottom: parent.bottom; rightMargin: 10; bottomMargin: 10 } } + + Connection { sender: leftButton; signal: "clicked()"; script: window.turnLeft() } + Connection { sender: rightButton; signal: "clicked()"; script: window.turnRight() } } diff --git a/examples/declarative/connections/rotate-left.png b/examples/declarative/connections/rotate-left.png Binary files differnew file mode 100644 index 0000000..c30387e --- /dev/null +++ b/examples/declarative/connections/rotate-left.png diff --git a/examples/declarative/connections/rotate-right.png b/examples/declarative/connections/rotate-right.png Binary files differnew file mode 100644 index 0000000..1b05674 --- /dev/null +++ b/examples/declarative/connections/rotate-right.png diff --git a/examples/declarative/focusscope/test3.qml b/examples/declarative/focusscope/test3.qml index e5aa7b6..1b3181b 100644 --- a/examples/declarative/focusscope/test3.qml +++ b/examples/declarative/focusscope/test3.qml @@ -40,8 +40,8 @@ Rectangle { model: model delegate: verticalDelegate preferredHighlightBegin: 100 - preferredHighlightEnd: 101 - strictlyEnforceHighlightRange: true + preferredHighlightEnd: 100 + highlightRangeMode: "StrictlyEnforceRange" } diff --git a/examples/declarative/listview/content/ClickAutoRepeating.qml b/examples/declarative/listview/content/ClickAutoRepeating.qml index f0e7df1..796f9e3 100644 --- a/examples/declarative/listview/content/ClickAutoRepeating.qml +++ b/examples/declarative/listview/content/ClickAutoRepeating.qml @@ -4,25 +4,27 @@ Item { id: page property int repeatdelay: 300 property int repeatperiod: 75 - property bool pressed: false + property bool isPressed: false + signal pressed signal released signal clicked - pressed: SequentialAnimation { + + isPressed: SequentialAnimation { id: autoRepeat - PropertyAction { target: page; property: "pressed"; value: true } - ScriptAction { script: page.onPressed } - ScriptAction { script: page.onClicked } + PropertyAction { target: page; property: "isPressed"; value: true } + ScriptAction { script: page.pressed() } + ScriptAction { script: page.clicked() } PauseAnimation { duration: repeatdelay } SequentialAnimation { repeat: true - ScriptAction { script: page.onClicked } + ScriptAction { script: page.clicked() } PauseAnimation { duration: repeatperiod } } } MouseRegion { anchors.fill: parent onPressed: autoRepeat.start() - onReleased: { autoRepeat.stop(); parent.pressed = false; page.released } + onReleased: { autoRepeat.stop(); parent.isPressed = false; page.released() } } } diff --git a/examples/declarative/listview/content/pics/archive-insert.png b/examples/declarative/listview/content/pics/archive-insert.png Binary files differnew file mode 100644 index 0000000..b706248 --- /dev/null +++ b/examples/declarative/listview/content/pics/archive-insert.png diff --git a/examples/declarative/listview/content/pics/archive-remove.png b/examples/declarative/listview/content/pics/archive-remove.png Binary files differnew file mode 100644 index 0000000..9640f6b --- /dev/null +++ b/examples/declarative/listview/content/pics/archive-remove.png diff --git a/examples/declarative/listview/content/pics/go-down.png b/examples/declarative/listview/content/pics/go-down.png Binary files differnew file mode 100644 index 0000000..63331a5 --- /dev/null +++ b/examples/declarative/listview/content/pics/go-down.png diff --git a/examples/declarative/listview/content/pics/go-up.png b/examples/declarative/listview/content/pics/go-up.png Binary files differnew file mode 100644 index 0000000..4459024 --- /dev/null +++ b/examples/declarative/listview/content/pics/go-up.png diff --git a/examples/declarative/listview/content/pics/list-add.png b/examples/declarative/listview/content/pics/list-add.png Binary files differnew file mode 100644 index 0000000..e029787 --- /dev/null +++ b/examples/declarative/listview/content/pics/list-add.png diff --git a/examples/declarative/listview/content/pics/list-remove.png b/examples/declarative/listview/content/pics/list-remove.png Binary files differnew file mode 100644 index 0000000..2bb1a59 --- /dev/null +++ b/examples/declarative/listview/content/pics/list-remove.png diff --git a/examples/declarative/listview/dynamic.qml b/examples/declarative/listview/dynamic.qml index 4f8e483..78346f3 100644 --- a/examples/declarative/listview/dynamic.qml +++ b/examples/declarative/listview/dynamic.qml @@ -1,54 +1,48 @@ import Qt 4.6 import "content" -Item { - width: 320 - height: 500 +Rectangle { + width: 640; height: 480 + color: "#343434" ListModel { id: fruitModel ListElement { - name: "Apple" - cost: 2.45 + name: "Apple"; cost: 2.45 attributes: [ ListElement { description: "Core" }, ListElement { description: "Deciduous" } ] } ListElement { - name: "Banana" - cost: 1.95 + name: "Banana"; cost: 1.95 attributes: [ ListElement { description: "Tropical" }, ListElement { description: "Seedless" } ] } ListElement { - name: "Cumquat" - cost: 3.25 + name: "Cumquat"; cost: 3.25 types: [ "Small", "Smaller" ] attributes: [ ListElement { description: "Citrus" } ] } ListElement { - name: "Durian" - cost: 9.95 + name: "Durian"; cost: 9.95 attributes: [ ListElement { description: "Tropical" }, ListElement { description: "Smelly" } ] } ListElement { - name: "Elderberry" - cost: 0.05 + name: "Elderberry"; cost: 0.05 attributes: [ ListElement { description: "Berry" } ] } ListElement { - name: "Fig" - cost: 0.25 + name: "Fig"; cost: 0.25 attributes: [ ListElement { description: "Flower" } ] @@ -59,83 +53,85 @@ Item { id: fruitDelegate Item { width: parent.width; height: 55 - Text { id: label; font.pixelSize: 24; text: name; elide: "ElideRight"; anchors.right: cost.left; anchors.left:parent.left } - Text { id: cost; font.pixelSize: 24; text: '$'+Number(cost).toFixed(2); anchors.right: itemButtons.left } - Row { - anchors.top: label.bottom - spacing: 5 - Repeater { - model: attributes - Component { - Text { text: description } - } + + Column { + id: moveButtons; x: 5; width: childrenRect.width; anchors.verticalCenter: parent.verticalCenter + Image { source: "content/pics/go-up.png" + MouseRegion { anchors.fill: parent; onClicked: fruitModel.move(index,index-1,1) } + } + Image { source: "content/pics/go-down.png" + MouseRegion { 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; font.bold: true; text: name; elide: Text.ElideRight; font.pixelSize: 15 + width: parent.width; color: "White" + } + Row { + spacing: 5 + Repeater { model: attributes; Component { Text { text: description; color: "White" } } } } } + Row { id: itemButtons - anchors.right: parent.right - width: childrenRect.width - Image { source: "content/pics/add.png" + anchors.right: removeButton.left; anchors.rightMargin: 35; spacing: 10 + width: childrenRect.width; anchors.verticalCenter: parent.verticalCenter + Image { source: "content/pics/list-add.png" ClickAutoRepeating { id: clickUp; anchors.fill: parent; onClicked: fruitModel.set(index,"cost",Number(cost)+0.25) } - scale: clickUp.pressed ? 0.9 : 1 + scale: clickUp.isPressed ? 0.9 : 1; transformOrigin: Item.Center } - Image { source: "content/pics/del.png" + Text { id: costText; text: '$'+Number(cost).toFixed(2); font.pixelSize: 15; color: "White"; font.bold: true; } + Image { source: "content/pics/list-remove.png" ClickAutoRepeating { id: clickDown; anchors.fill: parent; onClicked: fruitModel.set(index,"cost",Math.max(0,Number(cost)-0.25)) } - scale: clickDown.pressed ? 0.9 : 1 - } - Image { source: "content/pics/trash.png" - MouseRegion { anchors.fill: parent; onClicked: fruitModel.remove(index) } - } - Column { - width: childrenRect.width - Image { source: "content/pics/moreUp.png" - MouseRegion { anchors.fill: parent; onClicked: fruitModel.move(index,index-1,1) } - } - Image { source: "content/pics/moreDown.png" - MouseRegion { anchors.fill: parent; onClicked: fruitModel.move(index,index+1,1) } - } + scale: clickDown.isPressed ? 0.9 : 1; transformOrigin: Item.Center } } + Image { + id: removeButton; source: "content/pics/archive-remove.png" + anchors { verticalCenter: parent.verticalCenter; right: parent.right; rightMargin: 10 } + MouseRegion { anchors.fill:parent; onClicked: fruitModel.remove(index) } + } } } ListView { - model: fruitModel - delegate: fruitDelegate - anchors.top: parent.top - anchors.left: parent.left - anchors.right: parent.right - anchors.bottom: buttons.top + model: fruitModel; delegate: fruitDelegate + anchors { top: parent.top; left: parent.left; right: parent.right; bottom: buttons.top } } Row { - width: childrenRect.width + x: 8; width: childrenRect.width height: childrenRect.height - anchors.bottom: parent.bottom + anchors { bottom: parent.bottom; bottomMargin: 8 } + spacing: 8 id: buttons - Image { source: "content/pics/add.png" + Image { source: "content/pics/archive-insert.png" MouseRegion { anchors.fill: parent; onClicked: { fruitModel.append({ "name":"Pizza Margarita", "cost":5.95, "attributes":[{"description": "Cheese"},{"description": "Tomato"}] - }) + }) } } } - Image { source: "content/pics/add.png" + Image { source: "content/pics/archive-insert.png" MouseRegion { 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/trash.png" + Image { source: "content/pics/archive-remove.png" MouseRegion { anchors.fill: parent; onClicked: fruitModel.clear() } } } diff --git a/examples/declarative/listview/itemlist.qml b/examples/declarative/listview/itemlist.qml index 6dfc90b..77f5c2d 100644 --- a/examples/declarative/listview/itemlist.qml +++ b/examples/declarative/listview/itemlist.qml @@ -30,8 +30,8 @@ Rectangle { anchors.bottomMargin: 30 model: itemModel preferredHighlightBegin: 0 - preferredHighlightEnd: 1 - strictlyEnforceHighlightRange: true + preferredHighlightEnd: 0 + highlightRangeMode: "StrictlyEnforceRange" orientation: "Horizontal" } diff --git a/examples/declarative/listview/listview.qml b/examples/declarative/listview/listview.qml index 98974fd..b614904 100644 --- a/examples/declarative/listview/listview.qml +++ b/examples/declarative/listview/listview.qml @@ -41,7 +41,7 @@ Rectangle { // 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. - // The third list sets strictlyEnforceHighlightRange to true + // The third list sets the highlightRangeMode to StrictlyEnforceRange // and sets a range smaller than the height of an item. This // forces the current item to change when the view is flicked, // since the highlight is unable to move. @@ -61,6 +61,7 @@ Rectangle { model: MyPetsModel; delegate: petDelegate; highlight: petHighlight preferredHighlightBegin: 80 preferredHighlightEnd: 220 + highlightRangeMode: "ApplyRange" currentIndex: list1.currentIndex } ListView { @@ -69,7 +70,7 @@ Rectangle { model: MyPetsModel; delegate: petDelegate; highlight: petHighlight currentIndex: list1.currentIndex preferredHighlightBegin: 125 - preferredHighlightEnd: 126 - strictlyEnforceHighlightRange: true + preferredHighlightEnd: 125 + highlightRangeMode: "StrictlyEnforceRange" } } diff --git a/examples/declarative/parallax/ParallaxView.qml b/examples/declarative/parallax/ParallaxView.qml new file mode 100644 index 0000000..1708ad1 --- /dev/null +++ b/examples/declarative/parallax/ParallaxView.qml @@ -0,0 +1,88 @@ +import Qt 4.6 + +Item { + id: root + + property alias background: background.source + default property alias content: visualModel.children + property int currentIndex: 0 + + Image { + id: background + fillMode: Image.TileHorizontally + x: -list.viewportX / 2 + width: Math.max(list.viewportWidth, parent.width) + } + + ListView { + id: list + + currentIndex: root.currentIndex + onCurrentIndexChanged: root.currentIndex = currentIndex + + orientation: "Horizontal" + overShoot: false + anchors.fill: parent + model: VisualItemModel { id: visualModel } + + highlight: Item { height: 1; width: 1} + preferredHighlightBegin: 0 + preferredHighlightEnd: 0 + highlightRangeMode: "StrictlyEnforceRange" + } + + ListView { + id: selector + + currentIndex: root.currentIndex + onCurrentIndexChanged: root.currentIndex = currentIndex + + height: 50 + anchors.bottom: parent.bottom + anchors.horizontalCenter: parent.horizontalCenter + width: Math.min(count * 50, parent.width - 20) + interactive: width == parent.width - 20 + orientation: "Horizontal" + + delegate: Item { + width: 50; height: 50 + id: delegateRoot + + Image { + id: image + source: modelData.icon + smooth: true + scale: 0.8 + transformOrigin: "Center" + } + + MouseRegion { + anchors.fill: parent + onClicked: { root.currentIndex = index } + } + + states: State { + name: "Selected" + when: delegateRoot.ListView.isCurrentItem == true + PropertyChanges { + target: image + scale: 1 + y: -5 + } + } + transitions: Transition { + NumberAnimation { + properties: "scale,y" + } + } + } + model: visualModel.children + + Rectangle { + color: "#40FFFFFF" + x: -10; + y: -10; + width: parent.width + 20; height: parent.height + 10 + } + } +} diff --git a/examples/declarative/parallax/Smiley.qml b/examples/declarative/parallax/Smiley.qml new file mode 100644 index 0000000..db87412 --- /dev/null +++ b/examples/declarative/parallax/Smiley.qml @@ -0,0 +1,47 @@ +import Qt 4.6 + +Item { + id: window + width: 320; height: 480 + + // The shadow for the smiley face + Image { + anchors.horizontalCenter: parent.horizontalCenter + source: "pics/shadow.png"; y: smiley.minHeight + 58 + transformOrigin: Item.Center + + // The scale property depends on the y position of the smiley face. + scale: smiley.y * 0.5 / (smiley.minHeight - smiley.maxHeight) + } + + Image { + id: smiley + property int maxHeight: window.height / 3 + property int minHeight: 2 * window.height / 3 + + anchors.horizontalCenter: parent.horizontalCenter + source: "pics/face-smile.png"; y: minHeight + + // Animate the y property. Setting repeat to true makes the + // animation repeat indefinitely, otherwise it would only run once. + y: SequentialAnimation { + running: true; repeat: true + + // Move from minHeight to maxHeight in 300ms, using the easeOutExpo easing function + NumberAnimation { + from: smiley.minHeight; to: smiley.maxHeight + easing: "easeOutExpo"; duration: 300 + } + + // Then move back to minHeight in 1 second, using the easeOutBounce easing function + NumberAnimation { + from: smiley.maxHeight; to: smiley.minHeight + easing: "easeOutBounce"; duration: 1000 + } + + // Then pause for 500ms + PauseAnimation { duration: 500 } + } + } +} + diff --git a/examples/declarative/parallax/parallax.qml b/examples/declarative/parallax/parallax.qml new file mode 100644 index 0000000..52bd210 --- /dev/null +++ b/examples/declarative/parallax/parallax.qml @@ -0,0 +1,55 @@ +import Qt 4.6 +import "../clock" + +Rectangle { + id: root + + width: 320 + height: 480 + + ParallaxView { + id: parallax + anchors.fill: parent + background: "pics/background.jpg" + + Item { + property url icon: "pics/yast-wol.png" + width: 320 + height: 480 + + Clock { + anchors.centerIn: parent + } + } + + Item { + property url icon: "pics/home-page.svg" + + width: 320 + height: 480 + + Smiley {} + } + + Item { + property url icon: "pics/yast-joystick.png" + + width: 320 + height: 480 + + Loader { + anchors.top: parent.top + anchors.topMargin: 10 + anchors.horizontalCenter: parent.horizontalCenter + + width: 300; height: 400 + clip: true + resizeMode: Loader.SizeItemToLoader + + source: "../../../demos/declarative/samegame/samegame.qml" + } + } + + currentIndex: root.currentIndex + } +} diff --git a/examples/declarative/parallax/pics/background.jpg b/examples/declarative/parallax/pics/background.jpg Binary files differnew file mode 100644 index 0000000..61cca2f --- /dev/null +++ b/examples/declarative/parallax/pics/background.jpg diff --git a/examples/declarative/parallax/pics/face-smile.png b/examples/declarative/parallax/pics/face-smile.png Binary files differnew file mode 100644 index 0000000..3d66d72 --- /dev/null +++ b/examples/declarative/parallax/pics/face-smile.png diff --git a/examples/declarative/parallax/pics/home-page.svg b/examples/declarative/parallax/pics/home-page.svg new file mode 100644 index 0000000..4f16958 --- /dev/null +++ b/examples/declarative/parallax/pics/home-page.svg @@ -0,0 +1,445 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<svg + xmlns:dc="http://purl.org/dc/elements/1.1/" + xmlns:cc="http://creativecommons.org/ns#" + xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" + xmlns:svg="http://www.w3.org/2000/svg" + xmlns="http://www.w3.org/2000/svg" + xmlns:xlink="http://www.w3.org/1999/xlink" + xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" + xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" + width="48" + height="48" + overflow="visible" + enable-background="new 0 0 128 129.396" + xml:space="preserve" + id="svg2" + sodipodi:version="0.32" + inkscape:version="0.46" + sodipodi:docname="go-home.svg" + sodipodi:docbase="/home/jimmac/src/cvs/tango-icon-theme/scalable/actions" + version="1.0" + inkscape:export-filename="/home/tigert/My Downloads/go-home.png" + inkscape:export-xdpi="90.000000" + inkscape:export-ydpi="90.000000" + inkscape:output_extension="org.inkscape.output.svg.inkscape"><metadata + id="metadata367"><rdf:RDF><cc:Work + rdf:about=""><dc:format>image/svg+xml</dc:format><dc:type + rdf:resource="http://purl.org/dc/dcmitype/StillImage" /><cc:license + rdf:resource="http://creativecommons.org/licenses/publicdomain/" /><dc:title>Go Home</dc:title><dc:creator><cc:Agent><dc:title>Jakub Steiner</dc:title></cc:Agent></dc:creator><dc:source>http://jimmac.musichall.cz</dc:source><dc:subject><rdf:Bag><rdf:li>home</rdf:li><rdf:li>return</rdf:li><rdf:li>go</rdf:li><rdf:li>default</rdf:li><rdf:li>user</rdf:li><rdf:li>directory</rdf:li></rdf:Bag></dc:subject><dc:contributor><cc:Agent><dc:title>Tuomas Kuosmanen</dc:title></cc:Agent></dc:contributor></cc:Work><cc:License + rdf:about="http://creativecommons.org/licenses/publicdomain/"><cc:permits + rdf:resource="http://creativecommons.org/ns#Reproduction" /><cc:permits + rdf:resource="http://creativecommons.org/ns#Distribution" /><cc:permits + rdf:resource="http://creativecommons.org/ns#DerivativeWorks" /></cc:License></rdf:RDF></metadata><defs + id="defs365"><inkscape:perspective + sodipodi:type="inkscape:persp3d" + inkscape:vp_x="0 : 24 : 1" + inkscape:vp_y="0 : 1000 : 0" + inkscape:vp_z="48 : 24 : 1" + inkscape:persp3d-origin="24 : 16 : 1" + id="perspective92" /><radialGradient + inkscape:collect="always" + xlink:href="#linearGradient5060" + id="radialGradient5031" + gradientUnits="userSpaceOnUse" + gradientTransform="matrix(-2.774389,0,0,1.969706,112.7623,-872.8854)" + cx="605.71429" + cy="486.64789" + fx="605.71429" + fy="486.64789" + r="117.14286" /><linearGradient + inkscape:collect="always" + id="linearGradient5060"><stop + style="stop-color:black;stop-opacity:1;" + offset="0" + id="stop5062" /><stop + style="stop-color:black;stop-opacity:0;" + offset="1" + id="stop5064" /></linearGradient><radialGradient + inkscape:collect="always" + xlink:href="#linearGradient5060" + id="radialGradient5029" + gradientUnits="userSpaceOnUse" + gradientTransform="matrix(2.774389,0,0,1.969706,-1891.633,-872.8854)" + cx="605.71429" + cy="486.64789" + fx="605.71429" + fy="486.64789" + r="117.14286" /><linearGradient + id="linearGradient5048"><stop + style="stop-color:black;stop-opacity:0;" + offset="0" + id="stop5050" /><stop + id="stop5056" + offset="0.5" + style="stop-color:black;stop-opacity:1;" /><stop + style="stop-color:black;stop-opacity:0;" + offset="1" + id="stop5052" /></linearGradient><linearGradient + inkscape:collect="always" + xlink:href="#linearGradient5048" + id="linearGradient5027" + gradientUnits="userSpaceOnUse" + gradientTransform="matrix(2.774389,0,0,1.969706,-1892.179,-872.8854)" + x1="302.85715" + y1="366.64789" + x2="302.85715" + y2="609.50507" /><linearGradient + id="linearGradient2406"><stop + style="stop-color:#7c7e79;stop-opacity:1;" + offset="0" + id="stop2408" /><stop + id="stop2414" + offset="0.1724138" + style="stop-color:#848681;stop-opacity:1;" /><stop + style="stop-color:#898c86;stop-opacity:1;" + offset="1" + id="stop2410" /></linearGradient><linearGradient + inkscape:collect="always" + id="linearGradient2390"><stop + style="stop-color:#919191;stop-opacity:1;" + offset="0" + id="stop2392" /><stop + style="stop-color:#919191;stop-opacity:0;" + offset="1" + id="stop2394" /></linearGradient><linearGradient + inkscape:collect="always" + id="linearGradient2378"><stop + style="stop-color:#575757;stop-opacity:1;" + offset="0" + id="stop2380" /><stop + style="stop-color:#575757;stop-opacity:0;" + offset="1" + id="stop2382" /></linearGradient><linearGradient + inkscape:collect="always" + id="linearGradient2368"><stop + style="stop-color:#ffffff;stop-opacity:1;" + offset="0" + id="stop2370" /><stop + style="stop-color:#ffffff;stop-opacity:0;" + offset="1" + id="stop2372" /></linearGradient><linearGradient + inkscape:collect="always" + id="linearGradient2349"><stop + style="stop-color:#000000;stop-opacity:1;" + offset="0" + id="stop2351" /><stop + style="stop-color:#000000;stop-opacity:0;" + offset="1" + id="stop2353" /></linearGradient><linearGradient + id="linearGradient2341"><stop + id="stop2343" + offset="0" + style="stop-color:#000000;stop-opacity:1;" /><stop + id="stop2345" + offset="1" + style="stop-color:#000000;stop-opacity:0;" /></linearGradient><linearGradient + id="linearGradient2329"><stop + style="stop-color:#000000;stop-opacity:0.18556701;" + offset="0" + id="stop2331" /><stop + style="stop-color:#ffffff;stop-opacity:1;" + offset="1" + id="stop2333" /></linearGradient><linearGradient + inkscape:collect="always" + id="linearGradient2319"><stop + style="stop-color:#000000;stop-opacity:1;" + offset="0" + id="stop2321" /><stop + style="stop-color:#000000;stop-opacity:0;" + offset="1" + id="stop2323" /></linearGradient><linearGradient + id="linearGradient2307"><stop + style="stop-color:#edd400;stop-opacity:1;" + offset="0" + id="stop2309" /><stop + style="stop-color:#998800;stop-opacity:1;" + offset="1" + id="stop2311" /></linearGradient><linearGradient + inkscape:collect="always" + id="linearGradient2299"><stop + style="stop-color:#ffffff;stop-opacity:1;" + offset="0" + id="stop2301" /><stop + style="stop-color:#ffffff;stop-opacity:0;" + offset="1" + id="stop2303" /></linearGradient><linearGradient + id="XMLID_2_" + gradientUnits="userSpaceOnUse" + x1="80.223602" + y1="117.5205" + x2="48.046001" + y2="59.7995" + gradientTransform="matrix(0.314683,0.000000,0.000000,0.314683,4.128264,3.742874)"> + <stop + offset="0" + style="stop-color:#CCCCCC" + id="stop17" /> + <stop + offset="0.9831" + style="stop-color:#FFFFFF" + id="stop19" /> + <midPointStop + offset="0" + style="stop-color:#CCCCCC" + id="midPointStop48" /> + <midPointStop + offset="0.5" + style="stop-color:#CCCCCC" + id="midPointStop50" /> + <midPointStop + offset="0.9831" + style="stop-color:#FFFFFF" + id="midPointStop52" /> + </linearGradient><linearGradient + inkscape:collect="always" + xlink:href="#XMLID_2_" + id="linearGradient1514" + gradientUnits="userSpaceOnUse" + gradientTransform="matrix(0.336922,0.000000,0.000000,0.166888,17.98288,15.46151)" + x1="52.006104" + y1="166.1331" + x2="14.049017" + y2="-42.218513" /><linearGradient + id="XMLID_39_" + gradientUnits="userSpaceOnUse" + x1="64.387703" + y1="65.124001" + x2="64.387703" + y2="35.569" + gradientTransform="matrix(0.354101,0.000000,0.000000,0.354101,1.638679,-8.364921e-2)"> + <stop + offset="0" + style="stop-color:#FFFFFF" + id="stop336" /> + <stop + offset="0.8539" + style="stop-color:#FF6200" + id="stop338" /> + <stop + offset="1" + style="stop-color:#F25D00" + id="stop340" /> + <midPointStop + offset="0" + style="stop-color:#FFFFFF" + id="midPointStop335" /> + <midPointStop + offset="0.5" + style="stop-color:#FFFFFF" + id="midPointStop337" /> + <midPointStop + offset="0.8539" + style="stop-color:#FF6200" + id="midPointStop339" /> + <midPointStop + offset="0.5" + style="stop-color:#FF6200" + id="midPointStop341" /> + <midPointStop + offset="1" + style="stop-color:#F25D00" + id="midPointStop343" /> + </linearGradient><radialGradient + inkscape:collect="always" + xlink:href="#linearGradient2299" + id="radialGradient2305" + cx="7.5326638" + cy="24.202574" + fx="7.5326638" + fy="24.202574" + r="8.2452128" + gradientTransform="matrix(4.100086,-1.627292e-17,2.125447e-14,4.201322,-25.41506,-78.53967)" + gradientUnits="userSpaceOnUse" /><radialGradient + inkscape:collect="always" + xlink:href="#linearGradient2307" + id="radialGradient2313" + cx="19.985598" + cy="36.77816" + fx="19.985598" + fy="36.77816" + r="1.0821035" + gradientTransform="matrix(1.125263,0.000000,0.000000,0.982744,-3.428678,0.565787)" + gradientUnits="userSpaceOnUse" /><radialGradient + inkscape:collect="always" + xlink:href="#linearGradient2319" + id="radialGradient2325" + cx="20.443665" + cy="37.425829" + fx="20.443665" + fy="37.425829" + r="1.0821035" + gradientTransform="matrix(1.125263,0.000000,0.000000,0.982744,-3.428678,0.731106)" + gradientUnits="userSpaceOnUse" /><linearGradient + inkscape:collect="always" + xlink:href="#linearGradient2329" + id="linearGradient2335" + x1="17.602522" + y1="26.057423" + x2="17.682528" + y2="32.654099" + gradientUnits="userSpaceOnUse" + gradientTransform="matrix(0.898789,0,0,1.071914,0.478025,-2.080838)" /><radialGradient + inkscape:collect="always" + xlink:href="#linearGradient2341" + id="radialGradient2339" + gradientUnits="userSpaceOnUse" + gradientTransform="matrix(4.100086,1.627292e-17,2.125447e-14,-4.201322,-5.198109,105.3535)" + cx="11.68129" + cy="19.554111" + fx="11.68129" + fy="19.554111" + r="8.2452126" /><radialGradient + inkscape:collect="always" + xlink:href="#linearGradient2349" + id="radialGradient2355" + cx="24.023088" + cy="40.56913" + fx="24.023088" + fy="40.56913" + r="16.28684" + gradientTransform="matrix(1.000000,0.000000,0.000000,0.431250,1.157278e-15,23.07369)" + gradientUnits="userSpaceOnUse" /><radialGradient + inkscape:collect="always" + xlink:href="#linearGradient2368" + id="radialGradient2374" + cx="29.913452" + cy="30.442923" + fx="29.913452" + fy="30.442923" + r="4.0018832" + gradientTransform="matrix(3.751495,-2.191984e-22,1.723265e-22,3.147818,-82.00907,-65.70704)" + gradientUnits="userSpaceOnUse" /><radialGradient + inkscape:collect="always" + xlink:href="#linearGradient2378" + id="radialGradient2384" + cx="24.195112" + cy="10.577631" + fx="24.195112" + fy="10.577631" + r="15.242914" + gradientTransform="matrix(1.125263,-3.585417e-8,4.269819e-8,1.340059,-3.006704,1.355395)" + gradientUnits="userSpaceOnUse" /><linearGradient + inkscape:collect="always" + xlink:href="#linearGradient2390" + id="linearGradient2396" + x1="30.603519" + y1="37.337803" + x2="30.603519" + y2="36.112415" + gradientUnits="userSpaceOnUse" + gradientTransform="matrix(1.263867,0,0,0.859794,-6.499556,8.390924)" /><linearGradient + inkscape:collect="always" + xlink:href="#linearGradient2406" + id="linearGradient2412" + x1="17.850183" + y1="28.939463" + x2="19.040216" + y2="41.03223" + gradientUnits="userSpaceOnUse" + gradientTransform="matrix(0.888785,0,0,1.08932,2.41099,-1.524336)" /></defs><sodipodi:namedview + inkscape:cy="-2.3755359" + inkscape:cx="25.234802" + inkscape:zoom="1" + inkscape:window-height="691" + inkscape:window-width="872" + inkscape:pageshadow="2" + inkscape:pageopacity="0.0" + borderopacity="0.21568627" + bordercolor="#666666" + pagecolor="#ffffff" + id="base" + inkscape:showpageshadow="false" + inkscape:window-x="466" + inkscape:window-y="157" + inkscape:current-layer="svg2" + fill="#555753" + showgrid="false" + stroke="#a40000" + showguides="true" + inkscape:guide-bbox="true" /> + <g + style="display:inline" + id="g5022" + transform="matrix(2.158196e-2,0,0,1.859457e-2,43.12251,41.63767)"><rect + y="-150.69685" + x="-1559.2523" + height="478.35718" + width="1339.6335" + id="rect4173" + style="opacity:0.40206185;color:black;fill:url(#linearGradient5027);fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:1;stroke-linecap:round;stroke-linejoin:miter;marker:none;marker-start:none;marker-mid:none;marker-end:none;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;visibility:visible;display:inline;overflow:visible" /><path + sodipodi:nodetypes="cccc" + id="path5058" + d="M -219.61876,-150.68038 C -219.61876,-150.68038 -219.61876,327.65041 -219.61876,327.65041 C -76.744594,328.55086 125.78146,220.48075 125.78138,88.454235 C 125.78138,-43.572302 -33.655436,-150.68036 -219.61876,-150.68038 z " + style="opacity:0.40206185;color:black;fill:url(#radialGradient5029);fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:1;stroke-linecap:round;stroke-linejoin:miter;marker:none;marker-start:none;marker-mid:none;marker-end:none;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;visibility:visible;display:inline;overflow:visible" /><path + style="opacity:0.40206185;color:black;fill:url(#radialGradient5031);fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:1;stroke-linecap:round;stroke-linejoin:miter;marker:none;marker-start:none;marker-mid:none;marker-end:none;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;visibility:visible;display:inline;overflow:visible" + d="M -1559.2523,-150.68038 C -1559.2523,-150.68038 -1559.2523,327.65041 -1559.2523,327.65041 C -1702.1265,328.55086 -1904.6525,220.48075 -1904.6525,88.454235 C -1904.6525,-43.572302 -1745.2157,-150.68036 -1559.2523,-150.68038 z " + id="path5018" + sodipodi:nodetypes="cccc" /></g><path + style="color:#000000;fill:url(#linearGradient1514);fill-opacity:1;fill-rule:nonzero;stroke:#757575;stroke-width:1.0000006;stroke-linecap:butt;stroke-linejoin:miter;marker:none;marker-start:none;marker-mid:none;marker-end:none;stroke-miterlimit:4;stroke-dashoffset:0;stroke-opacity:1;visibility:visible;display:inline;overflow:visible" + d="M 21.619576,8.1833733 L 27.577035,8.1833733 C 28.416767,8.1833733 41.46351,23.618701 41.46351,24.524032 L 41.019989,43.020777 C 41.019989,43.92611 40.343959,44.654954 39.504227,44.654954 L 8.0469496,44.654954 C 7.2072167,44.654954 6.5311871,43.92611 6.5311871,43.020777 L 6.5876651,24.524032 C 6.5876651,23.618701 20.779844,8.1833733 21.619576,8.1833733 z " + id="rect1512" + sodipodi:nodetypes="ccccccccc" /><path + style="fill:none" + id="path5" + d="M 46.963575,45.735573 L 1.6386762,45.735573 L 1.6386762,0.41067554 L 46.963575,0.41067554 L 46.963575,45.735573 z " /><path + style="fill:url(#linearGradient2335);fill-opacity:1;fill-rule:evenodd" + id="path2327" + d="M 23,29 L 22.954256,44.090942 L 11.111465,44.090942 L 11,29 L 23,29 z " + clip-rule="evenodd" + sodipodi:nodetypes="ccccc" /><path + sodipodi:nodetypes="ccccccccc" + id="path2357" + d="M 21.780459,9.405584 L 27.339556,9.405584 C 28.123138,9.405584 40.340425,23.805172 40.340425,24.649756 L 39.993267,42.862067 C 39.993267,43.321326 39.84953,43.515532 39.480892,43.515532 L 8.0936894,43.529812 C 7.7250517,43.529812 7.5097258,43.449894 7.5097258,43.076262 L 7.7250676,24.649756 C 7.7250676,23.805172 20.99688,9.405584 21.780459,9.405584 z " + style="opacity:0.3125;color:#000000;fill:none;fill-opacity:1;fill-rule:nonzero;stroke:#ffffff;stroke-width:1.00000012;stroke-linecap:butt;stroke-linejoin:miter;marker:none;marker-start:none;marker-mid:none;marker-end:none;stroke-miterlimit:4;stroke-dashoffset:0;stroke-opacity:1;visibility:visible;display:inline;overflow:visible" /><path + clip-rule="evenodd" + d="M 7.2075295,27.943053 L 7.1532728,30.538247 L 25.521437,17.358993 L 40.807832,28.513421 L 40.879142,28.201707 L 24.508686,12.297576 L 7.2075295,27.943053 z " + id="path23" + style="opacity:0.2;fill:url(#radialGradient2384);fill-opacity:1;fill-rule:evenodd" + sodipodi:nodetypes="ccccccc" /><path + clip-rule="evenodd" + d="M 22,30 L 22,44.090942 L 12.188971,44.090942 L 12,30 L 22,30 z " + id="path188" + style="fill:url(#linearGradient2412);fill-opacity:1;fill-rule:evenodd" + sodipodi:nodetypes="ccccc" /><path + style="opacity:0.40909089;fill:url(#radialGradient2325);fill-opacity:1;fill-rule:evenodd" + id="path2315" + d="M 19.576856,36.44767 C 20.249646,36.44767 20.793472,36.922275 20.793472,37.506177 C 20.793472,38.095988 20.249646,38.574532 19.576856,38.574532 C 18.904584,38.574532 18.35817,38.095988 18.35817,37.506177 C 18.358685,36.922275 18.904584,36.44767 19.576856,36.44767 z " + clip-rule="evenodd" /><path + clip-rule="evenodd" + d="M 19.462314,35.932229 C 20.135103,35.932229 20.678929,36.406834 20.678929,36.990736 C 20.678929,37.580545 20.135103,38.059089 19.462314,38.059089 C 18.790041,38.059089 18.243627,37.580545 18.243627,36.990736 C 18.244142,36.406834 18.790041,35.932229 19.462314,35.932229 z " + id="path217" + style="fill:url(#radialGradient2313);fill-opacity:1;fill-rule:evenodd" /><path + d="M 24.447748,11.559337 L 43.374808,28.729205 L 43.869487,29.121196 L 44.273163,28.949811 L 43.900293,28.188138 L 43.622679,27.964702 L 24.447748,12.392396 L 5.0582327,28.135731 L 4.8206309,28.279851 L 4.603921,28.986637 L 5.0373408,29.115885 L 5.4218948,28.807462 L 24.447748,11.559337 z " + id="path342" + style="fill:url(#XMLID_39_)" + sodipodi:nodetypes="ccccccccccccc" /><path + style="fill:#ef2929;stroke:#a40000" + id="path362" + d="M 24.330168,2.2713382 L 2.4484294,20.372675 L 1.8237005,27.538603 L 3.8236367,29.602926 C 3.8236367,29.602926 24.231018,12.445641 24.44773,12.274963 L 44.08027,29.818223 L 45.978694,27.494226 L 44.362903,20.382852 L 24.44773,2.1668788 L 24.330168,2.2713382 z " + sodipodi:nodetypes="cccccccccc" /> +<path + style="opacity:0.40909089;color:#000000;fill:url(#radialGradient2305);fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:1;stroke-linecap:butt;stroke-linejoin:miter;marker:none;marker-start:none;marker-mid:none;marker-end:none;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;visibility:visible;display:inline;overflow:visible" + d="M 2.8413446,20.613129 L 2.5497894,27.236494 L 24.369219,8.980075 L 24.298891,3.0867443 L 2.8413446,20.613129 z " + id="path1536" + sodipodi:nodetypes="ccccc" /><path + sodipodi:nodetypes="ccccc" + id="path2337" + d="M 24.483763,8.7509884 L 24.583223,2.9098867 L 43.912186,20.56184 L 45.403998,27.062652 L 24.483763,8.7509884 z " + style="opacity:0.13636367;color:#000000;fill:url(#radialGradient2339);fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:1;stroke-linecap:butt;stroke-linejoin:miter;marker:none;marker-start:none;marker-mid:none;marker-end:none;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;visibility:visible;display:inline;overflow:visible" /><path + style="opacity:0.31818183;color:#000000;fill:none;fill-opacity:1;fill-rule:nonzero;stroke:#ffffff;stroke-width:0.99999934;stroke-linecap:butt;stroke-linejoin:miter;marker:none;marker-start:none;marker-mid:none;marker-end:none;stroke-miterlimit:4;stroke-dashoffset:0;stroke-opacity:1;visibility:visible;display:inline;overflow:visible" + d="M 27.102228,27.719824 L 36.142223,27.719824 C 36.912818,27.719824 37.53319,28.340194 37.53319,29.110791 L 37.525229,38.190012 C 37.525229,38.960608 36.928907,39.455981 36.158311,39.455981 L 27.102228,39.455981 C 26.331631,39.455981 25.711261,38.835608 25.711261,38.065012 L 25.711261,29.110791 C 25.711261,28.340194 26.331631,27.719824 27.102228,27.719824 z " + id="rect2361" + sodipodi:nodetypes="ccccccccc" /><rect + style="opacity:1;color:#000000;fill:#3465a4;fill-opacity:1;fill-rule:nonzero;stroke:#757575;stroke-width:0.9999994;stroke-linecap:butt;stroke-linejoin:miter;marker:none;marker-start:none;marker-mid:none;marker-end:none;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;visibility:visible;display:inline;overflow:visible" + id="rect3263" + width="10.001333" + height="9.9624557" + x="26.507767" + y="28.514256" + rx="0.38128215" + ry="0.38128215" /><path + style="opacity:0.39772728;color:#000000;fill:url(#radialGradient2374);fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:0.99999958;stroke-linecap:butt;stroke-linejoin:miter;marker:none;marker-start:none;marker-mid:none;marker-end:none;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;visibility:visible;display:inline;overflow:visible" + d="M 27.107118,34.408261 C 30.725101,34.739438 32.634842,32.962557 35.97527,32.855521 L 36,29.00603 L 27.088388,29 L 27.107118,34.408261 z " + id="rect2363" + sodipodi:nodetypes="ccccc" /></svg>
\ No newline at end of file diff --git a/examples/declarative/parallax/pics/shadow.png b/examples/declarative/parallax/pics/shadow.png Binary files differnew file mode 100644 index 0000000..8270565 --- /dev/null +++ b/examples/declarative/parallax/pics/shadow.png diff --git a/examples/declarative/parallax/pics/yast-joystick.png b/examples/declarative/parallax/pics/yast-joystick.png Binary files differnew file mode 100644 index 0000000..858cea0 --- /dev/null +++ b/examples/declarative/parallax/pics/yast-joystick.png diff --git a/examples/declarative/parallax/pics/yast-wol.png b/examples/declarative/parallax/pics/yast-wol.png Binary files differnew file mode 100644 index 0000000..7712180 --- /dev/null +++ b/examples/declarative/parallax/pics/yast-wol.png diff --git a/examples/declarative/progressbar/ProgressBar.qml b/examples/declarative/progressbar/ProgressBar.qml index 48346ac..302caa9 100644 --- a/examples/declarative/progressbar/ProgressBar.qml +++ b/examples/declarative/progressbar/ProgressBar.qml @@ -21,7 +21,7 @@ Item { id: highlight; radius: 2 anchors.left: parent.left; anchors.top: parent.top; anchors.bottom: parent.bottom anchors.leftMargin: 3; anchors.topMargin: 3; anchors.bottomMargin: 3 - width: EaseFollow { source: highlight.widthDest; duration: 100 } + width: EaseFollow { source: highlight.widthDest; duration: 1000 } gradient: Gradient { GradientStop { id: g1; position: 0.0 } GradientStop { id: g2; position: 1.0 } diff --git a/examples/declarative/snow/ImageBatch.qml b/examples/declarative/snow/ImageBatch.qml index 3945087..dfe2a46 100644 --- a/examples/declarative/snow/ImageBatch.qml +++ b/examples/declarative/snow/ImageBatch.qml @@ -38,7 +38,7 @@ GridView { delegate: Item { id: root property bool isSelected: GridView.isCurrentItem && grid.isSelected - transformOrigin: "Center" + transformOrigin: Item.Center width: grid.imageWidth; height: grid.imageHeight; Image { id: flickrImage; source: url; fillMode: "PreserveAspectFit"; smooth: true; anchors.fill: parent; diff --git a/examples/declarative/snow/Loading.qml b/examples/declarative/snow/Loading.qml index 054656a..238d9c7 100644 --- a/examples/declarative/snow/Loading.qml +++ b/examples/declarative/snow/Loading.qml @@ -1,7 +1,7 @@ import Qt 4.6 Image { - id: loading; source: "pics/loading.png"; transformOrigin: "Center" + id: loading; source: "pics/loading.png"; transformOrigin: Item.Center rotation: NumberAnimation { id: rotationAnimation; from: 0; to: 360; running: loading.visible == true; repeat: true; duration: 900 } diff --git a/examples/declarative/states/states.qml b/examples/declarative/states/states.qml index acab2f0..6f6b40f 100644 --- a/examples/declarative/states/states.qml +++ b/examples/declarative/states/states.qml @@ -2,47 +2,49 @@ import Qt 4.6 Rectangle { id: page - width: 300; height: 300; color: "white" - // A target region. Clicking in here sets the state to '' - the default state + width: 640; height: 480; color: "#343434" + + // A target region. Clicking in here sets the state to the default state Rectangle { - x: 0; y: 0; width: 50; height: 50 - color: "transparent"; border.color: "black" - MouseRegion { anchors.fill: parent; onClicked: { page.state='' } } + id: initialPosition + anchors { left: parent.left; top: parent.top; leftMargin: 10; topMargin: 20 } + width: 64; height: 64; radius: 6 + color: "Transparent"; border.color: "Gray" + MouseRegion { anchors.fill: parent; onClicked: page.state = '' } } + // Another target region. Clicking in here sets the state to 'Position1' Rectangle { - x: 150; y: 50; width: 50; height: 50 - color: "transparent"; border.color: "black" - MouseRegion { anchors.fill: parent; onClicked: { page.state='Position1' } } + id: position1 + anchors { right: parent.right; verticalCenter: parent.verticalCenter; rightMargin: 20 } + width: 64; height: 64; radius: 6 + color: "Transparent"; border.color: "Gray" + MouseRegion { anchors.fill: parent; onClicked: page.state = 'Position1' } } + // Another target region. Clicking in here sets the state to 'Position2' Rectangle { - x: 0; y: 200; width: 50; height: 50 - color: "transparent"; border.color: "black" - MouseRegion { anchors.fill: parent; onClicked: { page.state='Position2' } } + id: position2 + anchors { left: parent.left; bottom: parent.bottom; leftMargin: 10; bottomMargin: 20 } + width: 64; height: 64; radius: 6 + color: "Transparent"; border.color: "Gray" + MouseRegion { anchors.fill: parent; onClicked: page.state = 'Position2' } } - // Rect which will be moved when my state changes - Rectangle { id: myrect; width: 50; height: 50; color: "red" } + + // The image which will be moved when my state changes + Image { id: user; source: "user.png"; x: initialPosition.x; y: initialPosition.y } states: [ - // In state 'Position1', change the 'myrect' item x, y to 150, 50. + // In state 'Position1', change the 'user' item position to rect2's position. State { name: "Position1" - PropertyChanges { - target: myrect - x: 150 - y: 50 - } + PropertyChanges { target: user; x: position1.x; y: position1.y } }, - // In state 'Position2', change y to 100. We do not specify 'x' here - - // it will therefore be restored to its default value of 0, if it - // had been changed. + + // In state 'Position2', change the 'user' item position to rect3's position. State { name: "Position2" - PropertyChanges { - target: myrect - y: 200 - } + PropertyChanges { target: user; x: position2.x; y: position2.y } } ] } diff --git a/examples/declarative/states/transitions.qml b/examples/declarative/states/transitions.qml index cc6894d..ba97d9be 100644 --- a/examples/declarative/states/transitions.qml +++ b/examples/declarative/states/transitions.qml @@ -2,47 +2,49 @@ import Qt 4.6 Rectangle { id: page - width: 300; height: 300; color: "white" - // A target region. Clicking in here sets the state to '' - the default state + width: 640; height: 480; color: "#343434" + + // A target region. Clicking in here sets the state to the default state Rectangle { - x: 0; y: 0; width: 50; height: 50 - color: "transparent"; border.color: "black" - MouseRegion { anchors.fill: parent; onClicked: { page.state='' } } + id: initialPosition + anchors { left: parent.left; top: parent.top; leftMargin: 10; topMargin: 20 } + width: 64; height: 64; radius: 6 + color: "Transparent"; border.color: "Gray" + MouseRegion { anchors.fill: parent; onClicked: page.state = '' } } + // Another target region. Clicking in here sets the state to 'Position1' Rectangle { - x: 150; y: 50; width: 50; height: 50 - color: "transparent"; border.color: "black" - MouseRegion { anchors.fill: parent; onClicked: { page.state='Position1' } } + id: position1 + anchors { right: parent.right; verticalCenter: parent.verticalCenter; rightMargin: 20 } + width: 64; height: 64; radius: 6 + color: "Transparent"; border.color: "Gray" + MouseRegion { anchors.fill: parent; onClicked: page.state = 'Position1' } } + // Another target region. Clicking in here sets the state to 'Position2' Rectangle { - x: 0; y: 200; width: 50; height: 50 - color: "transparent"; border.color: "black" - MouseRegion { anchors.fill: parent; onClicked: { page.state='Position2' } } + id: position2 + anchors { left: parent.left; bottom: parent.bottom; leftMargin: 10; bottomMargin: 20 } + width: 64; height: 64; radius: 6 + color: "Transparent"; border.color: "Gray" + MouseRegion { anchors.fill: parent; onClicked: page.state = 'Position2' } } - // Rect which will be moved when my state changes - Rectangle { id: myrect; width: 50; height: 50; color: "red" } + + // The image which will be moved when my state changes + Image { id: user; source: "user.png"; x: initialPosition.x; y: initialPosition.y } states: [ - // In state 'Position1', change the 'myrect' item x, y to 150, 50. + // In state 'Position1', change the 'user' item position to rect2's position. State { name: "Position1" - PropertyChanges { - target: myrect - x: 150 - y: 50 - } + PropertyChanges { target: user; x: position1.x; y: position1.y } }, - // In state 'Position2', change y to 100. We do not specify 'x' here - - // it will therefore be restored to its default value of 0, if it - // had been changed. + + // In state 'Position2', change the 'user' item position to rect3's position. State { name: "Position2" - PropertyChanges { - target: myrect - y: 200 - } + PropertyChanges { target: user; x: position2.x; y: position2.y } } ] diff --git a/examples/declarative/states/user.png b/examples/declarative/states/user.png Binary files differnew file mode 100644 index 0000000..dd7d7a2 --- /dev/null +++ b/examples/declarative/states/user.png diff --git a/examples/declarative/tutorials/helloworld/tutorial3.qml b/examples/declarative/tutorials/helloworld/tutorial3.qml index d641eba..534d663 100644 --- a/examples/declarative/tutorials/helloworld/tutorial3.qml +++ b/examples/declarative/tutorials/helloworld/tutorial3.qml @@ -11,7 +11,7 @@ Rectangle { text: "Hello world!" font.pointSize: 24; font.bold: true y: 30; anchors.horizontalCenter: page.horizontalCenter - transformOrigin: "Center" + transformOrigin: Item.Center //![1] MouseRegion { id: mouseRegion; anchors.fill: parent } diff --git a/src/declarative/extra/qmlbehavior.h b/src/declarative/extra/qmlbehavior.h index 994d85c..6508455 100644 --- a/src/declarative/extra/qmlbehavior.h +++ b/src/declarative/extra/qmlbehavior.h @@ -60,6 +60,7 @@ class Q_DECLARATIVE_EXPORT QmlBehavior : public QObject, public QmlPropertyValue Q_OBJECT Q_DECLARE_PRIVATE(QmlBehavior) + Q_INTERFACES(QmlPropertyValueInterceptor) Q_CLASSINFO("DefaultProperty", "animation") Q_PROPERTY(QmlAbstractAnimation *animation READ animation WRITE setAnimation) diff --git a/src/declarative/fx/qfxanchors.cpp b/src/declarative/fx/qfxanchors.cpp index 737aa63..8d4a8b8 100644 --- a/src/declarative/fx/qfxanchors.cpp +++ b/src/declarative/fx/qfxanchors.cpp @@ -181,7 +181,6 @@ void QFxAnchorsPrivate::centerInChanged() void QFxAnchorsPrivate::clearItem(QFxItem *item) { - Q_Q(QFxAnchors); if (!item) return; if (fill == item) diff --git a/src/declarative/fx/qfxflickable.cpp b/src/declarative/fx/qfxflickable.cpp index a83ee66..cbfe9f6 100644 --- a/src/declarative/fx/qfxflickable.cpp +++ b/src/declarative/fx/qfxflickable.cpp @@ -618,11 +618,18 @@ void QFxFlickablePrivate::handleMouseMoveEvent(QGraphicsSceneMouseEvent *event) newY = minY + (newY - minY) / 2; if (newY < maxY && maxY - minY < 0) newY = maxY + (newY - maxY) / 2; - if (q->overShoot() || (newY <= minY && newY >= maxY)) { + if (!q->overShoot() && (newY > minY || newY < maxY)) { + if (newY > minY) + newY = minY; + else if (newY < maxY) + newY = maxY; + else + rejectY = true; + } + if (!rejectY) { _moveY.setValue(newY); moved = true; - } else if (!q->overShoot()) - rejectY = true; + } if (qAbs(dy) > DragThreshold) stealMouse = true; } @@ -638,11 +645,19 @@ void QFxFlickablePrivate::handleMouseMoveEvent(QGraphicsSceneMouseEvent *event) newX = minX + (newX - minX) / 2; if (newX < maxX && maxX - minX < 0) newX = maxX + (newX - maxX) / 2; - if (q->overShoot() || (newX <= minX && newX >= maxX)) { + if (!q->overShoot() && (newX > minX || newX < maxX)) { + if (newX > minX) + newX = minX; + else if (newX < maxX) + newX = maxX; + else + rejectX = true; + } + if (!rejectX) { _moveX.setValue(newX); moved = true; - } else if (!q->overShoot()) - rejectX = true; + } + if (qAbs(dx) > DragThreshold) stealMouse = true; } diff --git a/src/declarative/fx/qfxitem.cpp b/src/declarative/fx/qfxitem.cpp index 51575cc..e714494 100644 --- a/src/declarative/fx/qfxitem.cpp +++ b/src/declarative/fx/qfxitem.cpp @@ -1361,6 +1361,7 @@ QFxItem::~QFxItem() if (anchor->d_func()->item && anchor->d_func()->item->parentItem() != this) //child will be deleted anyway anchor->d_func()->updateOnComplete(); } + d->dependantAnchors.clear(); delete d->_anchorLines; d->_anchorLines = 0; delete d->_anchors; d->_anchors = 0; } @@ -1377,7 +1378,7 @@ QFxItem::~QFxItem() \qml Image { source: "myimage.png" - transformOrigin: "Center" + transformOrigin: Item.Center scale: 4 } \endqml diff --git a/src/declarative/fx/qfxlistview.cpp b/src/declarative/fx/qfxlistview.cpp index 1a4a60c..28d2bb2 100644 --- a/src/declarative/fx/qfxlistview.cpp +++ b/src/declarative/fx/qfxlistview.cpp @@ -176,9 +176,9 @@ public: , highlightRangeStart(0), highlightRangeEnd(0) , highlightComponent(0), highlight(0), trackedItem(0) , moveReason(Other), buffer(0), highlightPosAnimator(0), highlightSizeAnimator(0), spacing(0.0) - , highlightMoveSpeed(400), highlightResizeSpeed(400) + , highlightMoveSpeed(400), highlightResizeSpeed(400), highlightRange(QFxListView::NoHighlightRange) , ownModel(false), wrap(false), autoHighlight(true) - , haveHighlightRange(false), strictHighlightRange(false) + , haveHighlightRange(false) {} void init(); @@ -392,12 +392,12 @@ public: qreal spacing; qreal highlightMoveSpeed; qreal highlightResizeSpeed; + QFxListView::HighlightRangeMode highlightRange; bool ownModel : 1; bool wrap : 1; bool autoHighlight : 1; bool haveHighlightRange : 1; - bool strictHighlightRange : 1; }; void QFxListViewPrivate::init() @@ -798,7 +798,7 @@ void QFxListViewPrivate::fixupY() if (orient == Qt::Horizontal) return; - if (haveHighlightRange && strictHighlightRange) { + if (haveHighlightRange && highlightRange == QFxListView::StrictlyEnforceRange) { if (currentItem && highlight && currentItem->position() != highlight->position()) { moveReason = Mouse; timeline.clear(); @@ -813,7 +813,7 @@ void QFxListViewPrivate::fixupX() if (orient == Qt::Vertical) return; - if (haveHighlightRange && strictHighlightRange) { + if (haveHighlightRange && highlightRange == QFxListView::StrictlyEnforceRange) { if (currentItem && highlight && currentItem->position() != highlight->position()) { moveReason = Mouse; timeline.clear(); @@ -1141,19 +1141,25 @@ void QFxListView::setHighlightFollowsCurrentItem(bool autoHighlight) /*! \qmlproperty real ListView::preferredHighlightBegin \qmlproperty real ListView::preferredHighlightEnd - \qmlproperty bool ListView::strictlyEnforceHighlightRange + \qmlproperty bool ListView::highlightRangeMode These properties set the preferred range of the highlight (current item) within the view. - If the strictlyEnforceHighlightRange property is false (default) + If highlightRangeMode is set to \e ApplyRange the view will + attempt to maintain the highlight within the range, however the highlight can move outside of the range at the ends of the list or due to a mouse interaction. - If strictlyEnforceHighlightRange is true then the highlight will never - move outside the range. This means that the current item will change + If highlightRangeMode is set to \e StrictlyEnforceRange the highlight will never + move outside of the range. This means that the current item will change if a keyboard or mouse action would cause the highlight to move outside of the range. + + The default value is \e NoHighlightRange. + + Note that a valid range requires preferredHighlightEnd to be greater + than or equal to preferredHighlightBegin. */ qreal QFxListView::preferredHighlightBegin() const { @@ -1165,7 +1171,7 @@ void QFxListView::setPreferredHighlightBegin(qreal start) { Q_D(QFxListView); d->highlightRangeStart = start; - d->haveHighlightRange = d->highlightRangeStart < d->highlightRangeEnd; + d->haveHighlightRange = d->highlightRange != NoHighlightRange && d->highlightRangeStart <= d->highlightRangeEnd; } qreal QFxListView::preferredHighlightEnd() const @@ -1178,19 +1184,20 @@ void QFxListView::setPreferredHighlightEnd(qreal end) { Q_D(QFxListView); d->highlightRangeEnd = end; - d->haveHighlightRange = d->highlightRangeStart < d->highlightRangeEnd; + d->haveHighlightRange = d->highlightRange != NoHighlightRange && d->highlightRangeStart <= d->highlightRangeEnd; } -bool QFxListView::strictlyEnforceHighlightRange() const +QFxListView::HighlightRangeMode QFxListView::highlightRangeMode() const { Q_D(const QFxListView); - return d->strictHighlightRange; + return d->highlightRange; } -void QFxListView::setStrictlyEnforceHighlightRange(bool strict) +void QFxListView::setHighlightRangeMode(HighlightRangeMode mode) { Q_D(QFxListView); - d->strictHighlightRange = strict; + d->highlightRange = mode; + d->haveHighlightRange = d->highlightRange != NoHighlightRange && d->highlightRangeStart <= d->highlightRangeEnd; } /*! @@ -1375,14 +1382,14 @@ void QFxListView::viewportMoved() if (isFlicking() || d->pressed) d->moveReason = QFxListViewPrivate::Mouse; if (d->moveReason == QFxListViewPrivate::Mouse) { - if (d->haveHighlightRange && d->strictHighlightRange && d->highlight) { + if (d->haveHighlightRange && d->highlightRange == StrictlyEnforceRange && d->highlight) { int idx = d->snapIndex(); if (idx >= 0 && idx != d->currentIndex) d->updateCurrent(idx); qreal pos = d->currentItem->position(); - if (pos > d->position() + d->highlightRangeEnd - d->highlight->size()) - pos = d->position() + d->highlightRangeEnd - d->highlight->size(); + if (pos > d->position() + d->highlightRangeEnd - 1 - d->highlight->size()) + pos = d->position() + d->highlightRangeEnd - 1 - d->highlight->size(); if (pos < d->position() + d->highlightRangeStart) pos = d->position() + d->highlightRangeStart; d->highlight->setPosition(pos); @@ -1396,7 +1403,7 @@ qreal QFxListView::minYExtent() const if (d->orient == Qt::Horizontal) return QFxFlickable::minYExtent(); qreal extent = -d->startPosition(); - if (d->haveHighlightRange && d->strictHighlightRange) + if (d->haveHighlightRange && d->highlightRange == StrictlyEnforceRange) extent += d->highlightRangeStart; return extent; @@ -1408,8 +1415,8 @@ qreal QFxListView::maxYExtent() const if (d->orient == Qt::Horizontal) return QFxFlickable::maxYExtent(); qreal extent; - if (d->haveHighlightRange && d->strictHighlightRange) - extent = -(d->endPosition() - d->highlightRangeEnd); + if (d->haveHighlightRange && d->highlightRange == StrictlyEnforceRange) + extent = -(d->positionAt(count()-1) - d->highlightRangeEnd); else extent = -(d->endPosition() - height()); qreal minY = minYExtent(); @@ -1424,7 +1431,7 @@ qreal QFxListView::minXExtent() const if (d->orient == Qt::Vertical) return QFxFlickable::minXExtent(); qreal extent = -d->startPosition(); - if (d->haveHighlightRange && d->strictHighlightRange) + if (d->haveHighlightRange && d->highlightRange == StrictlyEnforceRange) extent += d->highlightRangeStart; return extent; @@ -1436,8 +1443,8 @@ qreal QFxListView::maxXExtent() const if (d->orient == Qt::Vertical) return QFxFlickable::maxXExtent(); qreal extent; - if (d->haveHighlightRange && d->strictHighlightRange) - extent = -(d->endPosition() - d->highlightRangeEnd); + if (d->haveHighlightRange && d->highlightRange == StrictlyEnforceRange) + extent = -(d->positionAt(count()-1) - d->highlightRangeEnd); else extent = -(d->endPosition() - width()); qreal minX = minXExtent(); @@ -1536,7 +1543,7 @@ void QFxListView::trackedPositionChanged() if (!isFlicking() && !d->pressed && d->moveReason != QFxListViewPrivate::Mouse) { const qreal trackedPos = d->trackedItem->position(); if (d->haveHighlightRange) { - if (d->strictHighlightRange) { + if (d->highlightRange == StrictlyEnforceRange) { qreal pos = d->position(); if (trackedPos > pos + d->highlightRangeEnd - d->trackedItem->size()) pos = trackedPos - d->highlightRangeEnd + d->trackedItem->size(); diff --git a/src/declarative/fx/qfxlistview.h b/src/declarative/fx/qfxlistview.h index 1ff0e27..0fa0fa0 100644 --- a/src/declarative/fx/qfxlistview.h +++ b/src/declarative/fx/qfxlistview.h @@ -69,7 +69,7 @@ class Q_DECLARATIVE_EXPORT QFxListView : public QFxFlickable Q_PROPERTY(qreal preferredHighlightBegin READ preferredHighlightBegin WRITE setPreferredHighlightBegin) Q_PROPERTY(qreal preferredHighlightEnd READ preferredHighlightEnd WRITE setPreferredHighlightEnd) - Q_PROPERTY(bool strictlyEnforceHighlightRange READ strictlyEnforceHighlightRange WRITE setStrictlyEnforceHighlightRange) + Q_PROPERTY(HighlightRangeMode highlightRangeMode READ highlightRangeMode WRITE setHighlightRangeMode) Q_PROPERTY(qreal spacing READ spacing WRITE setSpacing NOTIFY spacingChanged) Q_PROPERTY(Qt::Orientation orientation READ orientation WRITE setOrientation NOTIFY orientationChanged) @@ -80,6 +80,7 @@ class Q_DECLARATIVE_EXPORT QFxListView : public QFxFlickable Q_PROPERTY(qreal highlightMoveSpeed READ highlightMoveSpeed WRITE setHighlightMoveSpeed NOTIFY highlightMoveSpeedChanged) Q_PROPERTY(qreal highlightResizeSpeed READ highlightResizeSpeed WRITE setHighlightResizeSpeed NOTIFY highlightResizeSpeedChanged) + Q_ENUMS(HighlightRangeMode) Q_CLASSINFO("DefaultProperty", "data") public: @@ -104,8 +105,9 @@ public: bool highlightFollowsCurrentItem() const; void setHighlightFollowsCurrentItem(bool); - bool strictlyEnforceHighlightRange() const; - void setStrictlyEnforceHighlightRange(bool strict); + enum HighlightRangeMode { NoHighlightRange, ApplyRange, StrictlyEnforceRange }; + HighlightRangeMode highlightRangeMode() const; + void setHighlightRangeMode(HighlightRangeMode mode); qreal preferredHighlightBegin() const; void setPreferredHighlightBegin(qreal); diff --git a/src/declarative/fx/qfxloader.cpp b/src/declarative/fx/qfxloader.cpp index d60c135..da4a280 100644 --- a/src/declarative/fx/qfxloader.cpp +++ b/src/declarative/fx/qfxloader.cpp @@ -351,6 +351,8 @@ void QFxLoader::setResizeMode(ResizeMode mode) connect(resizeItem, SIGNAL(widthChanged()), this, SLOT(_q_updateSize())); connect(resizeItem, SIGNAL(heightChanged()), this, SLOT(_q_updateSize())); } + + d->_q_updateSize(); } } diff --git a/src/declarative/fx/qfxvisualitemmodel.cpp b/src/declarative/fx/qfxvisualitemmodel.cpp index e1ac246..7ee6eea 100644 --- a/src/declarative/fx/qfxvisualitemmodel.cpp +++ b/src/declarative/fx/qfxvisualitemmodel.cpp @@ -123,6 +123,10 @@ public: emit q->countChanged(); } + void emitChildrenChanged() { + Q_Q(QFxVisualItemModel); + emit q->childrenChanged(); + } ItemList children; }; @@ -224,6 +228,8 @@ void QFxVisualItemModelPrivate::ItemList::append(QFxItem *item) QmlConcreteList<QFxItem*>::append(item); item->QObject::setParent(model->q_ptr); model->itemAppended(); + + model->emitChildrenChanged(); } QFxVisualItemModelAttached *QFxVisualItemModel::qmlAttachedProperties(QObject *obj) diff --git a/src/declarative/fx/qfxvisualitemmodel.h b/src/declarative/fx/qfxvisualitemmodel.h index 5b613d8..8e33279 100644 --- a/src/declarative/fx/qfxvisualitemmodel.h +++ b/src/declarative/fx/qfxvisualitemmodel.h @@ -108,7 +108,7 @@ class Q_DECLARATIVE_EXPORT QFxVisualItemModel : public QFxVisualModel Q_OBJECT Q_DECLARE_PRIVATE(QFxVisualItemModel) - Q_PROPERTY(QmlList<QFxItem *>* children READ children DESIGNABLE false) + Q_PROPERTY(QmlList<QFxItem *>* children READ children NOTIFY childrenChanged DESIGNABLE false) Q_CLASSINFO("DefaultProperty", "children") public: @@ -128,6 +128,9 @@ public: static QFxVisualItemModelAttached *qmlAttachedProperties(QObject *obj); +signals: + void childrenChanged(); + private: Q_DISABLE_COPY(QFxVisualItemModel) }; diff --git a/src/declarative/qml/parser/qmljsastvisitor.cpp b/src/declarative/qml/parser/qmljsastvisitor.cpp index 642bcee..d3a1d53 100644 --- a/src/declarative/qml/parser/qmljsastvisitor.cpp +++ b/src/declarative/qml/parser/qmljsastvisitor.cpp @@ -41,7 +41,7 @@ #include "qmljsastvisitor_p.h" -QT_BEGIN_NAMESPACE +QT_QML_BEGIN_NAMESPACE namespace QmlJS { namespace AST { @@ -55,4 +55,4 @@ Visitor::~Visitor() } } // namespace QmlJS::AST -QT_END_NAMESPACE +QT_QML_END_NAMESPACE diff --git a/src/declarative/qml/qbitfield_p.h b/src/declarative/qml/qbitfield_p.h index 70d5041..a8cc9dc 100644 --- a/src/declarative/qml/qbitfield_p.h +++ b/src/declarative/qml/qbitfield_p.h @@ -139,11 +139,11 @@ QBitField QBitField::united(const QBitField &o) rv.data = rv.ownData + 1; if (bits > o.bits) { ::memcpy((quint32 *)rv.data, data, length * sizeof(quint32)); - for (quint32 ii = 0; ii < (o.bits + 31) / 32; ++ii) + for (quint32 ii = 0; ii < (o.bits + quint32(31)) / 32; ++ii) ((quint32 *)rv.data)[ii] |= o.data[ii]; } else { ::memcpy((quint32 *)rv.data, o.data, length * sizeof(quint32)); - for (quint32 ii = 0; ii < (bits + 31) / 32; ++ii) + for (quint32 ii = 0; ii < (bits + quint32(31)) / 32; ++ii) ((quint32 *)rv.data)[ii] |= data[ii]; } return rv; diff --git a/src/declarative/qml/qmlbasicscript.cpp b/src/declarative/qml/qmlbasicscript.cpp index b7aac54..eba4307 100644 --- a/src/declarative/qml/qmlbasicscript.cpp +++ b/src/declarative/qml/qmlbasicscript.cpp @@ -658,7 +658,7 @@ QVariant QmlBasicScript::run(QmlContext *context, QObject *me) case ScriptInstruction::FetchRootConstant: { - QObject *obj = contextPrivate->defaultObjects.last(); + QObject *obj = contextPrivate->defaultObjects.at(0); stack.push(fetch_value(obj, instr.constant.idx, instr.constant.type)); if (obj && instr.constant.notify != 0) diff --git a/src/declarative/qml/qmlcompiler.cpp b/src/declarative/qml/qmlcompiler.cpp index 69ebf9c..60282dc 100644 --- a/src/declarative/qml/qmlcompiler.cpp +++ b/src/declarative/qml/qmlcompiler.cpp @@ -1687,7 +1687,7 @@ bool QmlCompiler::buildGroupedProperty(QmlParser::Property *prop, if (prop->type < (int)QVariant::UserType) { QmlEnginePrivate *ep = static_cast<QmlEnginePrivate *>(QObjectPrivate::get(engine)); - if (ep->valueTypes[prop->type]) { + if (prop->type >= 0 /* QVariant == -1 */ && ep->valueTypes[prop->type]) { COMPILE_CHECK(buildValueTypeProperty(ep->valueTypes[prop->type], prop->value, obj, ctxt.incr())); obj->addValueTypeProperty(prop); diff --git a/src/declarative/qml/qmlcomponent.cpp b/src/declarative/qml/qmlcomponent.cpp index 12fb120..0894758 100644 --- a/src/declarative/qml/qmlcomponent.cpp +++ b/src/declarative/qml/qmlcomponent.cpp @@ -390,8 +390,6 @@ valid for components created directly from QML. */ QmlContext *QmlComponent::creationContext() const { - Q_D(const QmlComponent); - QmlDeclarativeData *ddata = QmlDeclarativeData::get(this); if (ddata) return ddata->context; diff --git a/src/declarative/qml/qmlcomponent_p.h b/src/declarative/qml/qmlcomponent_p.h index 7eedfbd..f90502f 100644 --- a/src/declarative/qml/qmlcomponent_p.h +++ b/src/declarative/qml/qmlcomponent_p.h @@ -76,7 +76,7 @@ class QmlComponentPrivate : public QObjectPrivate Q_DECLARE_PUBLIC(QmlComponent) public: - QmlComponentPrivate() : typeData(0), progress(0.), start(-1), count(-1), cc(0), completePending(false), componentAttacheds(0), engine(0) {} + QmlComponentPrivate() : typeData(0), progress(0.), start(-1), count(-1), cc(0), componentAttacheds(0), completePending(false), engine(0) {} QObject *create(QmlContext *context, const QBitField &); diff --git a/src/declarative/qml/qmlcompositetypedata_p.h b/src/declarative/qml/qmlcompositetypedata_p.h index fa11137..ffcef4c 100644 --- a/src/declarative/qml/qmlcompositetypedata_p.h +++ b/src/declarative/qml/qmlcompositetypedata_p.h @@ -69,7 +69,8 @@ public: Invalid, Complete, Error, - Waiting + Waiting, + WaitingResources }; Status status; enum ErrorType { diff --git a/src/declarative/qml/qmlcompositetypemanager.cpp b/src/declarative/qml/qmlcompositetypemanager.cpp index 3c76344..075c359 100644 --- a/src/declarative/qml/qmlcompositetypemanager.cpp +++ b/src/declarative/qml/qmlcompositetypemanager.cpp @@ -352,18 +352,6 @@ void QmlCompositeTypeManager::setData(QmlCompositeTypeData *unit, if (!unit->data.parse(data, url)) { ok = false; unit->errors << unit->data.errors(); - } else { - foreach (QmlScriptParser::Import imp, unit->data.imports()) { - int dot = imp.version.indexOf(QLatin1Char('.')); - if (dot < 0) dot = imp.version.length(); - if (!QmlEnginePrivate::get(engine)->addToImport(&unit->imports, imp.uri, imp.qualifier, imp.version.left(dot).toInt(), imp.version.mid(dot+1).toInt(), imp.type)) { - QmlError error; - error.setUrl(url); - error.setDescription(tr("Import %1 unavailable").arg(imp.uri)); - unit->errors << error; - ok = false; - } - } } if (ok) { @@ -400,25 +388,11 @@ void QmlCompositeTypeManager::doComplete(QmlCompositeTypeResource *resource) void QmlCompositeTypeManager::checkComplete(QmlCompositeTypeData *unit) { - if (unit->status != QmlCompositeTypeData::Waiting) + if (unit->status != QmlCompositeTypeData::Waiting + && unit->status != QmlCompositeTypeData::WaitingResources) return; int waiting = 0; - for (int ii = 0; ii < unit->types.count(); ++ii) { - QmlCompositeTypeData *u = unit->types.at(ii).unit; - - if (!u) - continue; - - if (u->status == QmlCompositeTypeData::Error) { - unit->status = QmlCompositeTypeData::Error; - unit->errors = u->errors; - doComplete(unit); - return; - } else if (u->status == QmlCompositeTypeData::Waiting) { - waiting++; - } - } for (int ii = 0; ii < unit->resources.count(); ++ii) { QmlCompositeTypeResource *r = unit->resources.at(ii); @@ -429,28 +403,84 @@ void QmlCompositeTypeManager::checkComplete(QmlCompositeTypeData *unit) unit->status = QmlCompositeTypeData::Error; QmlError error; error.setUrl(unit->imports.baseUrl()); - error.setDescription(QLatin1String("Resource ") + r->url + - QLatin1String(" unavailable")); + error.setDescription(tr("Resource %1 unavailable").arg(r->url)); unit->errors << error; doComplete(unit); return; - } else if (r->status == QmlCompositeTypeData::Waiting) { + } else if (r->status == QmlCompositeTypeResource::Waiting) { waiting++; } } + if (waiting == 0) { + if (unit->status == QmlCompositeTypeData::WaitingResources) { + waiting += resolveTypes(unit); + if (unit->status != QmlCompositeTypeData::Error) { + if (waiting) + unit->status = QmlCompositeTypeData::Waiting; + } else { + return; + } + } else { + for (int ii = 0; ii < unit->types.count(); ++ii) { + QmlCompositeTypeData *u = unit->types.at(ii).unit; + + if (!u) + continue; + + if (u->status == QmlCompositeTypeData::Error) { + unit->status = QmlCompositeTypeData::Error; + unit->errors = u->errors; + doComplete(unit); + return; + } else if (u->status == QmlCompositeTypeData::Waiting) { + waiting++; + } + } + } + } + if (!waiting) { unit->status = QmlCompositeTypeData::Complete; doComplete(unit); } } -// ### Check ref counting in here -void QmlCompositeTypeManager::compile(QmlCompositeTypeData *unit) +int QmlCompositeTypeManager::resolveTypes(QmlCompositeTypeData *unit) { - QList<QmlScriptParser::TypeReference*> types = unit->data.referencedTypes(); + // not called until all resources are loaded (they include import URLs) int waiting = 0; + + foreach (QmlScriptParser::Import imp, unit->data.imports()) { + int dot = imp.version.indexOf(QLatin1Char('.')); + if (dot < 0) dot = imp.version.length(); + QString qmldir; + if (imp.type == QmlScriptParser::Import::File && imp.qualifier.isEmpty()) { + QUrl importUrl = unit->imports.baseUrl().resolved(QUrl(imp.uri + QLatin1String("/qmldir"))); + for (int ii = 0; ii < unit->resources.count(); ++ii) { + if (unit->resources.at(ii)->url == importUrl.toString()) { + qmldir = QString::fromUtf8(unit->resources.at(ii)->data); + break; + } + } + } + if (!QmlEnginePrivate::get(engine)->addToImport( + &unit->imports, qmldir, imp.uri, imp.qualifier, imp.version.left(dot).toInt(), imp.version.mid(dot+1).toInt(), imp.type)) + { + QmlError error; + error.setUrl(unit->imports.baseUrl()); + error.setDescription(tr("Import %1 unavailable").arg(imp.uri)); + unit->status = QmlCompositeTypeData::Error; + unit->errorType = QmlCompositeTypeData::GeneralError; + unit->errors << error; + doComplete(unit); + return 0; + } + } + + QList<QmlScriptParser::TypeReference*> types = unit->data.referencedTypes(); + for (int ii = 0; ii < types.count(); ++ii) { QmlScriptParser::TypeReference *parserRef = types.at(ii); QByteArray typeName = parserRef->name.toUtf8(); @@ -478,7 +508,7 @@ void QmlCompositeTypeManager::compile(QmlCompositeTypeData *unit) unit->errorType = QmlCompositeTypeData::GeneralError; unit->errors << error; doComplete(unit); - return; + return 0; } if (ref.type) { @@ -521,12 +551,13 @@ void QmlCompositeTypeManager::compile(QmlCompositeTypeData *unit) if (urlUnit->errorType != QmlCompositeTypeData::AccessError) unit->errors << urlUnit->errors; doComplete(unit); - return; + return 0; case QmlCompositeTypeData::Complete: break; case QmlCompositeTypeData::Waiting: + case QmlCompositeTypeData::WaitingResources: unit->addref(); ref.unit->dependants << unit; waiting++; @@ -535,8 +566,26 @@ void QmlCompositeTypeManager::compile(QmlCompositeTypeData *unit) unit->types << ref; } + return waiting; +} + +// ### Check ref counting in here +void QmlCompositeTypeManager::compile(QmlCompositeTypeData *unit) +{ + int waiting = 0; QList<QUrl> resourceList = unit->data.referencedResources(); + + foreach (QmlScriptParser::Import imp, unit->data.imports()) { + if (imp.type == QmlScriptParser::Import::File && imp.qualifier.isEmpty()) { + QUrl importUrl = unit->imports.baseUrl().resolved(QUrl(imp.uri + QLatin1String("/qmldir"))); + if (toLocalFileOrQrc(importUrl).isEmpty()) { + // Import requires remote qmldir + resourceList.prepend(importUrl); + } + } + } + for (int ii = 0; ii < resourceList.count(); ++ii) { QUrl url = unit->imports.baseUrl().resolved(resourceList.at(ii)); @@ -558,8 +607,7 @@ void QmlCompositeTypeManager::compile(QmlCompositeTypeData *unit) { QmlError error; error.setUrl(unit->imports.baseUrl()); - error.setDescription(QLatin1String("Resource ") + resource->url + - QLatin1String(" unavailable")); + error.setDescription(tr("Resource %1 unavailable").arg(resource->url)); unit->errors << error; } doComplete(unit); @@ -579,11 +627,18 @@ void QmlCompositeTypeManager::compile(QmlCompositeTypeData *unit) unit->resources << resource; } - if (waiting) { - unit->status = QmlCompositeTypeData::Waiting; + if (waiting == 0) { + waiting += resolveTypes(unit); + if (unit->status != QmlCompositeTypeData::Error) { + if (!waiting) { + unit->status = QmlCompositeTypeData::Complete; + doComplete(unit); + } else { + unit->status = QmlCompositeTypeData::Waiting; + } + } } else { - unit->status = QmlCompositeTypeData::Complete; - doComplete(unit); + unit->status = QmlCompositeTypeData::WaitingResources; } } diff --git a/src/declarative/qml/qmlcompositetypemanager_p.h b/src/declarative/qml/qmlcompositetypemanager_p.h index 843a9cf..b6f84db 100644 --- a/src/declarative/qml/qmlcompositetypemanager_p.h +++ b/src/declarative/qml/qmlcompositetypemanager_p.h @@ -101,6 +101,7 @@ private: void doComplete(QmlCompositeTypeData *); void doComplete(QmlCompositeTypeResource *); void checkComplete(QmlCompositeTypeData *); + int resolveTypes(QmlCompositeTypeData *); QmlEngine *engine; typedef QHash<QString, QmlCompositeTypeData *> Components; diff --git a/src/declarative/qml/qmlcontext.cpp b/src/declarative/qml/qmlcontext.cpp index 31d4e1f..2ebdf10 100644 --- a/src/declarative/qml/qmlcontext.cpp +++ b/src/declarative/qml/qmlcontext.cpp @@ -50,9 +50,6 @@ #include <private/qmlbindingoptimizations_p.h> #include <QtDeclarative/qmlinfo.h> -// 6-bits -#define MAXIMUM_DEFAULT_OBJECTS 63 - QT_BEGIN_NAMESPACE QmlContextPrivate::QmlContextPrivate() @@ -130,22 +127,6 @@ void QmlContextPrivate::init() parent->d_func()->childContexts.insert(q); } -void QmlContextPrivate::addDefaultObject(QObject *object, Priority priority) -{ - if (defaultObjects.count() >= (MAXIMUM_DEFAULT_OBJECTS - 1)) { - qWarning("QmlContext: Cannot have more than %d default objects on " - "one bind context.", MAXIMUM_DEFAULT_OBJECTS - 1); - return; - } - - if (priority == HighPriority) { - defaultObjects.insert(highPriorityCount++, object); - } else { - defaultObjects.append(object); - } -} - - /*! \class QmlContext \brief The QmlContext class defines a context within a QML engine. @@ -366,7 +347,7 @@ QmlContext *QmlContext::parentContext() const void QmlContext::addDefaultObject(QObject *defaultObject) { Q_D(QmlContext); - d->addDefaultObject(defaultObject, QmlContextPrivate::NormalPriority); + d->defaultObjects.prepend(defaultObject); } /*! @@ -396,8 +377,7 @@ void QmlContext::setContextProperty(const QString &name, const QVariant &value) } } -void QmlContextPrivate::setIdProperty(const QString &name, int idx, - QObject *obj) +void QmlContextPrivate::setIdProperty(int idx, QObject *obj) { if (notifyIndex == -1) { Q_Q(QmlContext); @@ -487,7 +467,6 @@ void QmlContext::setBaseUrl(const QUrl &baseUrl) */ QUrl QmlContext::baseUrl() const { - Q_D(const QmlContext); const QmlContext* p = this; while (p && p->d_func()->url.isEmpty()) { p = p->parentContext(); diff --git a/src/declarative/qml/qmlcontext_p.h b/src/declarative/qml/qmlcontext_p.h index 9a77e94..6af5f64 100644 --- a/src/declarative/qml/qmlcontext_p.h +++ b/src/declarative/qml/qmlcontext_p.h @@ -104,12 +104,6 @@ public: void dump(); void dump(int depth); - enum Priority { - HighPriority, - NormalPriority - }; - void addDefaultObject(QObject *, Priority); - void invalidateEngines(); QSet<QmlContext *> childContexts; @@ -129,7 +123,7 @@ public: }; ContextGuard *idValues; int idValueCount; - void setIdProperty(const QString &, int, QObject *); + void setIdProperty(int, QObject *); void setIdPropertyData(QmlIntegerCache *); void destroyed(ContextGuard *); diff --git a/src/declarative/qml/qmlcontextscriptclass.cpp b/src/declarative/qml/qmlcontextscriptclass.cpp index 4df23f0..a978df2 100644 --- a/src/declarative/qml/qmlcontextscriptclass.cpp +++ b/src/declarative/qml/qmlcontextscriptclass.cpp @@ -155,7 +155,7 @@ QmlContextScriptClass::queryProperty(QmlContext *bindContext, QObject *scopeObje } } - for (int ii = 0; ii < cp->defaultObjects.count(); ++ii) { + for (int ii = cp->defaultObjects.count() - 1; ii >= 0; --ii) { QScriptClass::QueryFlags rv = ep->objectClass->queryProperty(cp->defaultObjects.at(ii), name, flags, bindContext); diff --git a/src/declarative/qml/qmldom.cpp b/src/declarative/qml/qmldom.cpp index a0601d7..21eeb7c 100644 --- a/src/declarative/qml/qmldom.cpp +++ b/src/declarative/qml/qmldom.cpp @@ -1181,6 +1181,75 @@ QmlDomObject QmlDomValueValueSource::object() const return rv; } +/*! + \class QmlDomValueValueInterceptor + \internal + \brief The QmlDomValueValueInterceptor class represents a value interceptor assignment value. + + In QML, value interceptor are special write-intercepting types that may be + assigned to properties. Value interceptor inherit the QmlPropertyValueInterceptor + class. In the example below, the "x" property is being assigned the + Behavior value interceptor. + + \qml +Rectangle { + x: Behavior { NumberAnimation { duration: 500 } } +} + \endqml +*/ + +/*! + Construct an empty QmlDomValueValueInterceptor. +*/ +QmlDomValueValueInterceptor::QmlDomValueValueInterceptor(): + d(new QmlDomBasicValuePrivate) +{ +} + +/*! + Create a copy of \a other QmlDomValueValueInterceptor. +*/ +QmlDomValueValueInterceptor::QmlDomValueValueInterceptor(const QmlDomValueValueInterceptor &other) +: d(other.d) +{ +} + +/*! + Destroy the QmlDomValueValueInterceptor. +*/ +QmlDomValueValueInterceptor::~QmlDomValueValueInterceptor() +{ +} + +/*! + Assign \a other to this QmlDomValueValueInterceptor. +*/ +QmlDomValueValueInterceptor &QmlDomValueValueInterceptor::operator=(const QmlDomValueValueInterceptor &other) +{ + d = other.d; + return *this; +} + +/*! + Return the value interceptor object. + + In the example below, an object representing the Behavior will be + returned. + \qml +Rectangle { + x: Behavior { NumberAnimation { duration: 500 } } +} + \endqml +*/ +QmlDomObject QmlDomValueValueInterceptor::object() const +{ + QmlDomObject rv; + if (d->value) { + rv.d->object = d->value->object; + rv.d->object->addref(); + } + return rv; +} QmlDomValuePrivate::QmlDomValuePrivate() : property(0), value(0) @@ -1286,6 +1355,7 @@ QmlDomValue &QmlDomValue::operator=(const QmlDomValue &other) \value Literal The QmlDomValue is a literal value assignment. Use QmlDomValue::toLiteral() to access the type instance. \value PropertyBinding The QmlDomValue is a property binding. Use QmlDomValue::toBinding() to access the type instance. \value ValueSource The QmlDomValue is a property value source. Use QmlDomValue::toValueSource() to access the type instance. + \value ValueInterceptor The QmlDomValue is a property value interceptor. Use QmlDomValue::toValueInterceptor() to access the type instance. \value Object The QmlDomValue is an object assignment. Use QmlDomValue::toObject() to access the type instnace. \value List The QmlDomValue is a list of other values. Use QmlDomValue::toList() to access the type instance. */ @@ -1314,6 +1384,8 @@ QmlDomValue::Type QmlDomValue::type() const return PropertyBinding; case QmlParser::Value::ValueSource: return ValueSource; + case QmlParser::Value::ValueInterceptor: + return ValueInterceptor; case QmlParser::Value::CreatedObject: return Object; case QmlParser::Value::SignalObject: @@ -1359,6 +1431,14 @@ bool QmlDomValue::isValueSource() const } /*! + Returns true if this is a value interceptor value, otherwise false. +*/ +bool QmlDomValue::isValueInterceptor() const +{ + return type() == ValueInterceptor; +} + +/*! Returns true if this is an object value, otherwise false. */ bool QmlDomValue::isObject() const @@ -1423,6 +1503,22 @@ QmlDomValueValueSource QmlDomValue::toValueSource() const } /*! + Returns a QmlDomValueValueInterceptor if this value is a property value interceptor + type, otherwise returns an invalid QmlDomValueValueInterceptor. + + \sa QmlDomValue::type() +*/ +QmlDomValueValueInterceptor QmlDomValue::toValueInterceptor() const +{ + QmlDomValueValueInterceptor rv; + if (type() == ValueInterceptor) { + rv.d->value = d->value; + rv.d->value->addref(); + } + return rv; +} + +/*! Returns a QmlDomObject if this value is an object assignment type, otherwise returns an invalid QmlDomObject. diff --git a/src/declarative/qml/qmldom.h b/src/declarative/qml/qmldom.h index f344bb2..5816780 100644 --- a/src/declarative/qml/qmldom.h +++ b/src/declarative/qml/qmldom.h @@ -175,6 +175,7 @@ private: friend class QmlDomComponent; friend class QmlDomValue; friend class QmlDomValueValueSource; + friend class QmlDomValueValueInterceptor; QSharedDataPointer<QmlDomObjectPrivate> d; }; @@ -225,6 +226,22 @@ private: QSharedDataPointer<QmlDomBasicValuePrivate> d; }; +class Q_DECLARATIVE_EXPORT QmlDomValueValueInterceptor +{ +public: + QmlDomValueValueInterceptor(); + QmlDomValueValueInterceptor(const QmlDomValueValueInterceptor &); + ~QmlDomValueValueInterceptor(); + QmlDomValueValueInterceptor &operator=(const QmlDomValueValueInterceptor &); + + QmlDomObject object() const; + +private: + friend class QmlDomValue; + QSharedDataPointer<QmlDomBasicValuePrivate> d; +}; + + class Q_DECLARATIVE_EXPORT QmlDomComponent : public QmlDomObject { public: @@ -244,6 +261,7 @@ public: Literal, PropertyBinding, ValueSource, + ValueInterceptor, Object, List }; @@ -259,12 +277,14 @@ public: bool isLiteral() const; bool isBinding() const; bool isValueSource() const; + bool isValueInterceptor() const; bool isObject() const; bool isList() const; QmlDomValueLiteral toLiteral() const; QmlDomValueBinding toBinding() const; QmlDomValueValueSource toValueSource() const; + QmlDomValueValueInterceptor toValueInterceptor() const; QmlDomObject toObject() const; QmlDomList toList() const; diff --git a/src/declarative/qml/qmlengine.cpp b/src/declarative/qml/qmlengine.cpp index 4f3b2ba..0e239ce 100644 --- a/src/declarative/qml/qmlengine.cpp +++ b/src/declarative/qml/qmlengine.cpp @@ -39,8 +39,6 @@ ** ****************************************************************************/ -#undef QT3_SUPPORT // don't want it here - it just causes bugs (which is why we removed it) - #include <QtCore/qmetaobject.h> #include <private/qmlengine_p.h> #include <private/qmlcontext_p.h> @@ -478,6 +476,8 @@ QmlEngine *qmlEngine(const QObject *obj) QObject *qmlAttachedPropertiesObjectById(int id, const QObject *object, bool create) { QmlDeclarativeData *data = QmlDeclarativeData::get(object); + if (!data) + return 0; // Attached properties are only on objects created by QML QObject *rv = data->attachedProperties?data->attachedProperties->value(id):0; if (rv || !create) @@ -1036,6 +1036,7 @@ struct QmlEnginePrivate::ImportedNamespace { QList<int> minversions; QList<bool> isLibrary; QList<bool> isBuiltin; + QList<QString> qmlDirContent; bool find(const QByteArray& type, int *vmajor, int *vminor, QmlType** type_return, QUrl* url_return) const { @@ -1057,36 +1058,39 @@ struct QmlEnginePrivate::ImportedNamespace { } } else { QUrl url = QUrl(urls.at(i) + QLatin1String("/") + QString::fromUtf8(type) + QLatin1String(".qml")); - if (vmaj || vmin) { + QString qmldircontent = qmlDirContent.at(i); + if (vmaj || vmin || !qmldircontent.isEmpty()) { // Check version file - XXX cache these in QmlEngine! - QFile qmldir(toLocalFileOrQrc(QUrl(urls.at(i)+QLatin1String("/qmldir")))); - if (qmldir.open(QIODevice::ReadOnly)) { - do { - QByteArray lineba = qmldir.readLine(); - if (lineba.at(0) == '#') - continue; - int space1 = lineba.indexOf(' '); - if (qstrncmp(lineba,type,space1)==0) { - // eg. 1.2-5 - QString line = QString::fromUtf8(lineba); - space1 = line.indexOf(QLatin1Char(' ')); // refind in Unicode - int space2 = space1 >=0 ? line.indexOf(QLatin1Char(' '),space1+1) : -1; - QString mapversions = line.mid(space1+1,space2<0?line.length()-space1-2:space2-space1-1); - int dot = mapversions.indexOf(QLatin1Char('.')); - int dash = mapversions.indexOf(QLatin1Char('-')); - int mapvmaj = mapversions.left(dot).toInt(); - if (mapvmaj==vmaj) { - int mapvmin_from = (dash <= 0 ? mapversions.mid(dot+1) : mapversions.mid(dot+1,dash-dot-1)).toInt(); - int mapvmin_to = dash <= 0 ? mapvmin_from : mapversions.mid(dash+1).toInt(); - if (vmin >= mapvmin_from && vmin <= mapvmin_to) { - QStringRef mapfile = space2<0 ? QStringRef() : line.midRef(space2+1,line.length()-space2-2); - if (url_return) - *url_return = url.resolved(mapfile.toString()); - return true; - } + if (qmldircontent.isEmpty()) { + QFile qmldir(toLocalFileOrQrc(QUrl(urls.at(i)+QLatin1String("/qmldir")))); + if (qmldir.open(QIODevice::ReadOnly)) { + qmldircontent = QString::fromUtf8(qmldir.readAll()); + } + } + QString typespace = QString::fromUtf8(type)+QLatin1Char(' '); + QStringList lines = qmldircontent.split(QLatin1Char('\n')); + foreach (QString line, lines) { + if (line.isEmpty() || line.at(0) == QLatin1Char('#')) + continue; + if (line.startsWith(typespace)) { + // eg. 1.2-5 + int space1 = line.indexOf(QLatin1Char(' ')); + int space2 = space1 >=0 ? line.indexOf(QLatin1Char(' '),space1+1) : -1; + QString mapversions = line.mid(space1+1,space2<0?line.length()-space1-1:space2-space1-1); + int dot = mapversions.indexOf(QLatin1Char('.')); + int dash = mapversions.indexOf(QLatin1Char('-')); + int mapvmaj = mapversions.left(dot).toInt(); + if (mapvmaj==vmaj) { + int mapvmin_from = (dash <= 0 ? mapversions.mid(dot+1) : mapversions.mid(dot+1,dash-dot-1)).toInt(); + int mapvmin_to = dash <= 0 ? mapvmin_from : mapversions.mid(dash+1).toInt(); + if (vmin >= mapvmin_from && vmin <= mapvmin_to) { + QStringRef mapfile = space2<0 ? QStringRef() : line.midRef(space2+1,line.length()-space2-1); + if (url_return) + *url_return = url.resolved(mapfile.toString()); + return true; } } - } while (!qmldir.atEnd()); + } } } else { // XXX search non-files too! (eg. zip files, see QT-524) @@ -1115,7 +1119,7 @@ public: delete s; } - bool add(const QUrl& base, const QString& uri, const QString& prefix, int vmaj, int vmin, QmlScriptParser::Import::Type importType, const QStringList& importPath) + bool add(const QUrl& base, const QString& qmldircontent, const QString& uri, const QString& prefix, int vmaj, int vmin, QmlScriptParser::Import::Type importType, const QStringList& importPath) { QmlEnginePrivate::ImportedNamespace *s; if (prefix.isEmpty()) { @@ -1151,6 +1155,7 @@ public: s->minversions.prepend(vmin); s->isLibrary.prepend(importType == QmlScriptParser::Import::Library); s->isBuiltin.prepend(isbuiltin); + s->qmlDirContent.prepend(qmldircontent); return true; } @@ -1375,9 +1380,9 @@ QString QmlEngine::offlineStoragePath() const The base URL must already have been set with Import::setBaseUrl(). */ -bool QmlEnginePrivate::addToImport(Imports* imports, const QString& uri, const QString& prefix, int vmaj, int vmin, QmlScriptParser::Import::Type importType) const +bool QmlEnginePrivate::addToImport(Imports* imports, const QString& qmldircontent, const QString& uri, const QString& prefix, int vmaj, int vmin, QmlScriptParser::Import::Type importType) const { - bool ok = imports->d->add(imports->d->base,uri,prefix,vmaj,vmin,importType,fileImportPath); + bool ok = imports->d->add(imports->d->base,qmldircontent,uri,prefix,vmaj,vmin,importType,fileImportPath); if (qmlImportTrace()) qDebug() << "QmlEngine::addToImport(" << imports << uri << prefix << vmaj << "." << vmin << (importType==QmlScriptParser::Import::Library? "Library" : "File") << ": " << ok; return ok; diff --git a/src/declarative/qml/qmlengine_p.h b/src/declarative/qml/qmlengine_p.h index 29621c0..69b121e 100644 --- a/src/declarative/qml/qmlengine_p.h +++ b/src/declarative/qml/qmlengine_p.h @@ -227,7 +227,7 @@ public: QmlImportsPrivate *d; }; - bool addToImport(Imports*, const QString& uri, const QString& prefix, int vmaj, int vmin, QmlScriptParser::Import::Type importType) const; + bool addToImport(Imports*, const QString& qmlDirContent,const QString& uri, const QString& prefix, int vmaj, int vmin, QmlScriptParser::Import::Type importType) const; bool resolveType(const Imports&, const QByteArray& type, QmlType** type_return, QUrl* url_return, int *version_major, int *version_minor, diff --git a/src/declarative/qml/qmlenginedebug.cpp b/src/declarative/qml/qmlenginedebug.cpp index 7178e6c..664ca3f 100644 --- a/src/declarative/qml/qmlenginedebug.cpp +++ b/src/declarative/qml/qmlenginedebug.cpp @@ -104,7 +104,7 @@ QmlEngineDebugServer::propertyData(QObject *obj, int propIdx) rv.type = QmlObjectProperty::Unknown; rv.valueTypeName = QString::fromUtf8(prop.typeName()); - rv.name = prop.name(); + rv.name = QString::fromUtf8(prop.name()); rv.hasNotifySignal = prop.hasNotifySignal(); QmlAbstractBinding *binding = QmlMetaProperty(obj, rv.name).binding(); if (binding) @@ -229,7 +229,7 @@ QmlEngineDebugServer::objectData(QObject *object) } rv.objectName = object->objectName(); - rv.objectType = object->metaObject()->className(); + rv.objectType = QString::fromUtf8(object->metaObject()->className()); rv.objectId = QmlDebugService::idForObject(object); rv.contextId = QmlDebugService::idForObject(qmlContext(object)); diff --git a/src/declarative/qml/qmlexpression.cpp b/src/declarative/qml/qmlexpression.cpp index 3f531a3..c62756b 100644 --- a/src/declarative/qml/qmlexpression.cpp +++ b/src/declarative/qml/qmlexpression.cpp @@ -46,6 +46,7 @@ #include "qmlrewrite_p.h" #include "QtCore/qdebug.h" #include "qmlcompiler_p.h" +#include <QtScript/qscriptprogram.h> Q_DECLARE_METATYPE(QList<QObject *>); @@ -109,17 +110,17 @@ void QmlExpressionPrivate::init(QmlContext *ctxt, void *expr, QmlRefCount *rc, QmlEngine *engine = ctxt->engine(); QmlEnginePrivate *ep = QmlEnginePrivate::get(engine); QScriptEngine *scriptEngine = QmlEnginePrivate::getScriptEngine(engine); -#if !defined(Q_OS_SYMBIAN) && !defined(Q_OS_WIN32) //XXX Why doesn't this work? +#if !defined(Q_OS_SYMBIAN) //XXX Why doesn't this work? if (!dd->programs.at(progIdx)) { dd->programs[progIdx] = - new QScriptProgram(scriptEngine->compile(data->expression, data->fileName, data->line)); + new QScriptProgram(data->expression, data->fileName, data->line); } #endif QScriptContext *scriptContext = scriptEngine->pushCleanContext(); scriptContext->pushScope(ep->contextClass->newContext(ctxt, me)); -#if !defined(Q_OS_SYMBIAN) && !defined(Q_OS_WIN32) +#if !defined(Q_OS_SYMBIAN) data->expressionFunction = scriptEngine->evaluate(*dd->programs[progIdx]); #else data->expressionFunction = scriptEngine->evaluate(data->expression); @@ -292,8 +293,7 @@ QVariant QmlExpressionPrivate::evalQtScript(QObject *secondaryScope, bool *isUnd QmlEnginePrivate *ep = QmlEnginePrivate::get(engine); if (secondaryScope) - ctxtPriv->defaultObjects.insert(ctxtPriv->highPriorityCount, - secondaryScope); + ctxtPriv->defaultObjects.append(secondaryScope); QScriptEngine *scriptEngine = QmlEnginePrivate::getScriptEngine(engine); @@ -327,8 +327,11 @@ QVariant QmlExpressionPrivate::evalQtScript(QObject *secondaryScope, bool *isUnd return QVariant(); } - if (secondaryScope) - ctxtPriv->defaultObjects.removeAt(ctxtPriv->highPriorityCount); + if (secondaryScope) { + QObject *last = ctxtPriv->defaultObjects.takeLast(); + Q_ASSERT(last == secondaryScope); + Q_UNUSED(last); + } QVariant rv; diff --git a/src/declarative/qml/qmlglobalscriptclass.cpp b/src/declarative/qml/qmlglobalscriptclass.cpp index 0ade5ee..91187c7 100644 --- a/src/declarative/qml/qmlglobalscriptclass.cpp +++ b/src/declarative/qml/qmlglobalscriptclass.cpp @@ -70,6 +70,10 @@ QmlGlobalScriptClass::queryProperty(const QScriptValue &object, const QScriptString &name, QueryFlags flags, uint *id) { + Q_UNUSED(object) + Q_UNUSED(name) + Q_UNUSED(flags) + Q_UNUSED(id) return HandlesReadAccess | HandlesWriteAccess; } @@ -78,6 +82,9 @@ QmlGlobalScriptClass::property(const QScriptValue &object, const QScriptString &name, uint id) { + Q_UNUSED(object) + Q_UNUSED(name) + Q_UNUSED(id) return engine()->undefinedValue(); } @@ -85,6 +92,8 @@ void QmlGlobalScriptClass::setProperty(QScriptValue &object, const QScriptString &name, uint id, const QScriptValue &value) { + Q_UNUSED(object) + Q_UNUSED(value) QString error = QLatin1String("Invalid write to global property \"") + name.toString() + QLatin1String("\""); engine()->currentContext()->throwError(error); diff --git a/src/declarative/qml/qmlobjectscriptclass.cpp b/src/declarative/qml/qmlobjectscriptclass.cpp index a6edd3b..eac354d 100644 --- a/src/declarative/qml/qmlobjectscriptclass.cpp +++ b/src/declarative/qml/qmlobjectscriptclass.cpp @@ -134,7 +134,6 @@ QmlObjectScriptClass::queryProperty(QObject *obj, const Identifier &name, return 0; QmlEnginePrivate *enginePrivate = QmlEnginePrivate::get(engine); - QScriptEngine *scriptEngine = QmlEnginePrivate::getScriptEngine(engine); QmlPropertyCache *cache = 0; QmlDeclarativeData *ddata = QmlDeclarativeData::get(obj); diff --git a/src/declarative/qml/qmlpropertycache.cpp b/src/declarative/qml/qmlpropertycache.cpp index 3ede341..4c24cdd 100644 --- a/src/declarative/qml/qmlpropertycache.cpp +++ b/src/declarative/qml/qmlpropertycache.cpp @@ -48,7 +48,7 @@ QT_BEGIN_NAMESPACE void QmlPropertyCache::Data::load(const QMetaProperty &p) { propType = p.userType(); - if (propType == QVariant::LastType) + if (QVariant::Type(propType) == QVariant::LastType) propType = qMetaTypeId<QVariant>(); coreIndex = p.propertyIndex(); notifyIndex = p.notifySignalIndex(); diff --git a/src/declarative/qml/qmlrewrite.cpp b/src/declarative/qml/qmlrewrite.cpp index 43b2529..7cf8888 100644 --- a/src/declarative/qml/qmlrewrite.cpp +++ b/src/declarative/qml/qmlrewrite.cpp @@ -120,7 +120,7 @@ bool RewriteBinding::visit(AST::ExpressionStatement *ast) return false; } -bool RewriteBinding::visit(AST::DoWhileStatement *ast) +bool RewriteBinding::visit(AST::DoWhileStatement *) { ++_inLoop; return true; @@ -131,7 +131,7 @@ void RewriteBinding::endVisit(AST::DoWhileStatement *) --_inLoop; } -bool RewriteBinding::visit(AST::WhileStatement *ast) +bool RewriteBinding::visit(AST::WhileStatement *) { ++_inLoop; return true; @@ -142,7 +142,7 @@ void RewriteBinding::endVisit(AST::WhileStatement *) --_inLoop; } -bool RewriteBinding::visit(AST::ForStatement *ast) +bool RewriteBinding::visit(AST::ForStatement *) { ++_inLoop; return true; @@ -153,7 +153,7 @@ void RewriteBinding::endVisit(AST::ForStatement *) --_inLoop; } -bool RewriteBinding::visit(AST::LocalForStatement *ast) +bool RewriteBinding::visit(AST::LocalForStatement *) { ++_inLoop; return true; @@ -164,7 +164,7 @@ void RewriteBinding::endVisit(AST::LocalForStatement *) --_inLoop; } -bool RewriteBinding::visit(AST::ForEachStatement *ast) +bool RewriteBinding::visit(AST::ForEachStatement *) { ++_inLoop; return true; @@ -175,7 +175,7 @@ void RewriteBinding::endVisit(AST::ForEachStatement *) --_inLoop; } -bool RewriteBinding::visit(AST::LocalForEachStatement *ast) +bool RewriteBinding::visit(AST::LocalForEachStatement *) { ++_inLoop; return true; diff --git a/src/declarative/qml/qmlvme.cpp b/src/declarative/qml/qmlvme.cpp index 802a78f..b986b60 100644 --- a/src/declarative/qml/qmlvme.cpp +++ b/src/declarative/qml/qmlvme.cpp @@ -225,7 +225,7 @@ QObject *QmlVME::run(QStack<QObject *> &stack, QmlContext *ctxt, { QObject *target = stack.top(); // ctxt->setContextProperty(primitives.at(instr.setId.value), target); - cp->setIdProperty(primitives.at(instr.setId.value), instr.setId.index, target); + cp->setIdProperty(instr.setId.index, target); } break; diff --git a/src/declarative/qml/qmlvmemetaobject.cpp b/src/declarative/qml/qmlvmemetaobject.cpp index a627bf9..3e1d931 100644 --- a/src/declarative/qml/qmlvmemetaobject.cpp +++ b/src/declarative/qml/qmlvmemetaobject.cpp @@ -278,7 +278,7 @@ int QmlVMEMetaObject::metaCall(QMetaObject::Call c, int _id, void **a) QMetaMethod m = method(_id); QList<QByteArray> names = m.parameterNames(); for (int ii = 0; ii < names.count(); ++ii) - newCtxt.setContextProperty(names.at(ii), *(QVariant *)a[ii + 1]); + newCtxt.setContextProperty(QString::fromLatin1(names.at(ii)), *(QVariant *)a[ii + 1]); QmlExpression expr(&newCtxt, code, object); expr.setTrackChange(false); expr.value(); diff --git a/src/declarative/qml/qmlxmlhttprequest.cpp b/src/declarative/qml/qmlxmlhttprequest.cpp index 5117a00..eb7235b 100644 --- a/src/declarative/qml/qmlxmlhttprequest.cpp +++ b/src/declarative/qml/qmlxmlhttprequest.cpp @@ -1102,6 +1102,7 @@ void QmlXMLHttpRequest::abort() void QmlXMLHttpRequest::downloadProgress(qint64 bytes) { + Q_UNUSED(bytes) m_status = m_network->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(); m_statusText = @@ -1124,6 +1125,7 @@ void QmlXMLHttpRequest::downloadProgress(qint64 bytes) void QmlXMLHttpRequest::error(QNetworkReply::NetworkError error) { + Q_UNUSED(error) m_status = m_network->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(); m_statusText = @@ -1315,6 +1317,7 @@ static QScriptValue qmlxmlhttprequest_abort(QScriptContext *context, QScriptEngi static QScriptValue qmlxmlhttprequest_getResponseHeader(QScriptContext *context, QScriptEngine *engine) { + Q_UNUSED(engine) QmlXMLHttpRequest *request = qobject_cast<QmlXMLHttpRequest *>(context->thisObject().data().toQObject()); if (!request) return context->throwError(QScriptContext::ReferenceError, QLatin1String("Not an XMLHttpRequest object")); @@ -1333,6 +1336,7 @@ static QScriptValue qmlxmlhttprequest_getResponseHeader(QScriptContext *context, static QScriptValue qmlxmlhttprequest_getAllResponseHeaders(QScriptContext *context, QScriptEngine *engine) { + Q_UNUSED(engine) QmlXMLHttpRequest *request = qobject_cast<QmlXMLHttpRequest *>(context->thisObject().data().toQObject()); if (!request) return context->throwError(QScriptContext::ReferenceError, QLatin1String("Not an XMLHttpRequest object")); @@ -1350,6 +1354,7 @@ static QScriptValue qmlxmlhttprequest_getAllResponseHeaders(QScriptContext *cont // XMLHttpRequest properties static QScriptValue qmlxmlhttprequest_readyState(QScriptContext *context, QScriptEngine *engine) { + Q_UNUSED(engine) QmlXMLHttpRequest *request = qobject_cast<QmlXMLHttpRequest *>(context->thisObject().data().toQObject()); if (!request) return context->throwError(QScriptContext::ReferenceError, QLatin1String("Not an XMLHttpRequest object")); @@ -1358,6 +1363,7 @@ static QScriptValue qmlxmlhttprequest_readyState(QScriptContext *context, QScrip static QScriptValue qmlxmlhttprequest_status(QScriptContext *context, QScriptEngine *engine) { + Q_UNUSED(engine) QmlXMLHttpRequest *request = qobject_cast<QmlXMLHttpRequest *>(context->thisObject().data().toQObject()); if (!request) return context->throwError(QScriptContext::ReferenceError, QLatin1String("Not an XMLHttpRequest object")); @@ -1373,6 +1379,7 @@ static QScriptValue qmlxmlhttprequest_status(QScriptContext *context, QScriptEng static QScriptValue qmlxmlhttprequest_statusText(QScriptContext *context, QScriptEngine *engine) { + Q_UNUSED(engine) QmlXMLHttpRequest *request = qobject_cast<QmlXMLHttpRequest *>(context->thisObject().data().toQObject()); if (!request) return context->throwError(QScriptContext::ReferenceError, QLatin1String("Not an XMLHttpRequest object")); @@ -1388,6 +1395,7 @@ static QScriptValue qmlxmlhttprequest_statusText(QScriptContext *context, QScrip static QScriptValue qmlxmlhttprequest_responseText(QScriptContext *context, QScriptEngine *engine) { + Q_UNUSED(engine) QmlXMLHttpRequest *request = qobject_cast<QmlXMLHttpRequest *>(context->thisObject().data().toQObject()); if (!request) return context->throwError(QScriptContext::ReferenceError, QLatin1String("Not an XMLHttpRequest object")); @@ -1412,6 +1420,7 @@ static QScriptValue qmlxmlhttprequest_responseXML(QScriptContext *context, QScri static QScriptValue qmlxmlhttprequest_onreadystatechange(QScriptContext *context, QScriptEngine *engine) { + Q_UNUSED(engine) QmlXMLHttpRequest *request = qobject_cast<QmlXMLHttpRequest *>(context->thisObject().data().toQObject()); if (!request) return context->throwError(QScriptContext::ReferenceError, QLatin1String("Not an XMLHttpRequest object")); diff --git a/src/declarative/util/qmlanimation.h b/src/declarative/util/qmlanimation.h index 7898980..f4f9f38 100644 --- a/src/declarative/util/qmlanimation.h +++ b/src/declarative/util/qmlanimation.h @@ -65,6 +65,7 @@ class Q_AUTOTEST_EXPORT QmlAbstractAnimation : public QObject, public QmlPropert Q_DECLARE_PRIVATE(QmlAbstractAnimation) Q_INTERFACES(QmlParserStatus) + Q_INTERFACES(QmlPropertyValueSource) Q_PROPERTY(bool running READ isRunning WRITE setRunning NOTIFY runningChanged) Q_PROPERTY(bool paused READ isPaused WRITE setPaused NOTIFY pausedChanged) Q_PROPERTY(bool alwaysRunToEnd READ alwaysRunToEnd WRITE setAlwaysRunToEnd NOTIFY alwaysRunToEndChanged()) diff --git a/src/declarative/util/qmllistaccessor.cpp b/src/declarative/util/qmllistaccessor.cpp index 21007d6..3e4cb64 100644 --- a/src/declarative/util/qmllistaccessor.cpp +++ b/src/declarative/util/qmllistaccessor.cpp @@ -73,7 +73,7 @@ void QmlListAccessor::setList(const QVariant &v, QmlEngine *engine) m_type = Invalid; } else if (d.type() == QVariant::StringList) { m_type = StringList; - } else if (d.type() == QMetaType::QVariantList) { + } else if (d.type() == (QVariant::Type)QMetaType::QVariantList) { m_type = VariantList; } else if (d.canConvert(QVariant::Int)) { m_type = Integer; diff --git a/src/declarative/util/qmlpropertychanges.cpp b/src/declarative/util/qmlpropertychanges.cpp index bed27fe..7e1f15c 100644 --- a/src/declarative/util/qmlpropertychanges.cpp +++ b/src/declarative/util/qmlpropertychanges.cpp @@ -85,8 +85,7 @@ class QmlReplaceSignalHandler : public ActionEvent public: QmlReplaceSignalHandler() : expression(0), reverseExpression(0), ownedExpression(0) {} ~QmlReplaceSignalHandler() { - if (ownedExpression) - delete ownedExpression; + delete ownedExpression; } virtual QString typeName() const { return QLatin1String("ReplaceSignalHandler"); } diff --git a/src/declarative/util/qmlview.cpp b/src/declarative/util/qmlview.cpp index 14f8279..f91d0db 100644 --- a/src/declarative/util/qmlview.cpp +++ b/src/declarative/util/qmlview.cpp @@ -360,6 +360,8 @@ void QmlView::continueExecute() emit sceneResized(sz); resize(sz); } + updateGeometry(); + emit initialSize(d->initialSize); } else if (QWidget *wid = qobject_cast<QWidget *>(obj)) { window()->setAttribute(Qt::WA_OpaquePaintEvent, false); window()->setAttribute(Qt::WA_NoSystemBackground, false); @@ -374,6 +376,7 @@ void QmlView::continueExecute() } layout()->addWidget(wid); emit sceneResized(wid->size()); + emit initialSize(wid->size()); } } } @@ -382,6 +385,10 @@ void QmlView::continueExecute() This signal is emitted when the view is resized to \a size. */ +/*! \fn void QmlView::initialSize(QSize size) + This signal is emitted when the initial size of the root item is known. + */ + /*! \fn void QmlView::errors(const QList<QmlError> &errors) This signal is emitted when the qml loaded contains \a errors. */ @@ -425,7 +432,10 @@ void QmlView::timerEvent(QTimerEvent* e) automatically resize the root item. Regardless of this property, the sizeHint of the view - is the initial size of the root item. + is the initial size of the root item. Note though that + since QML may load dynamically, that size may change. + + \sa initialSize() */ void QmlView::setContentResizable(bool on) diff --git a/src/declarative/util/qmlview.h b/src/declarative/util/qmlview.h index faf2564..822827a 100644 --- a/src/declarative/util/qmlview.h +++ b/src/declarative/util/qmlview.h @@ -88,6 +88,7 @@ public: QSize sizeHint() const; Q_SIGNALS: + void initialSize(QSize size); void sceneResized(QSize size); void errors(const QList<QmlError> &error); diff --git a/src/gui/graphicsview/qgraphicstransform.cpp b/src/gui/graphicsview/qgraphicstransform.cpp index a0b5493..93dc196 100644 --- a/src/gui/graphicsview/qgraphicstransform.cpp +++ b/src/gui/graphicsview/qgraphicstransform.cpp @@ -547,9 +547,7 @@ void QGraphicsRotation::applyTo(QMatrix4x4 *matrix) const return; matrix->translate(d->origin); - QMatrix4x4 m; - m.rotate(d->angle, d->axis.x(), d->axis.y(), d->axis.z()); - *matrix *= m.toTransform(1024.0f); // Project back to 2D. + matrix->projectedRotate(d->angle, d->axis.x(), d->axis.y(), d->axis.z()); matrix->translate(-d->origin); } diff --git a/src/gui/math3d/qmatrix4x4.cpp b/src/gui/math3d/qmatrix4x4.cpp index 00e8f15..5d624d8 100644 --- a/src/gui/math3d/qmatrix4x4.cpp +++ b/src/gui/math3d/qmatrix4x4.cpp @@ -58,6 +58,8 @@ QT_BEGIN_NAMESPACE \sa QVector3D, QGenericMatrix */ +static const qreal inv_dist_to_plane = 1. / 1024.; + /*! \fn QMatrix4x4::QMatrix4x4() @@ -1103,7 +1105,111 @@ QMatrix4x4& QMatrix4x4::rotate(qreal angle, qreal x, qreal y, qreal z) return *this; } -#ifndef QT_NO_VECTOR4D +/*! + \internal +*/ +QMatrix4x4& QMatrix4x4::projectedRotate(qreal angle, qreal x, qreal y, qreal z) +{ + // Used by QGraphicsRotation::applyTo() to perform a rotation + // and projection back to 2D in a single step. + if (angle == 0.0f) + return *this; + QMatrix4x4 m(1); // The "1" says to not load the identity. + qreal c, s, ic; + if (angle == 90.0f || angle == -270.0f) { + s = 1.0f; + c = 0.0f; + } else if (angle == -90.0f || angle == 270.0f) { + s = -1.0f; + c = 0.0f; + } else if (angle == 180.0f || angle == -180.0f) { + s = 0.0f; + c = -1.0f; + } else { + qreal a = angle * M_PI / 180.0f; + c = qCos(a); + s = qSin(a); + } + bool quick = false; + if (x == 0.0f) { + if (y == 0.0f) { + if (z != 0.0f) { + // Rotate around the Z axis. + m.setIdentity(); + m.m[0][0] = c; + m.m[1][1] = c; + if (z < 0.0f) { + m.m[1][0] = s; + m.m[0][1] = -s; + } else { + m.m[1][0] = -s; + m.m[0][1] = s; + } + m.flagBits = General; + quick = true; + } + } else if (z == 0.0f) { + // Rotate around the Y axis. + m.setIdentity(); + m.m[0][0] = c; + m.m[2][2] = 1.0f; + if (y < 0.0f) { + m.m[0][3] = -s * inv_dist_to_plane; + } else { + m.m[0][3] = s * inv_dist_to_plane; + } + m.flagBits = General; + quick = true; + } + } else if (y == 0.0f && z == 0.0f) { + // Rotate around the X axis. + m.setIdentity(); + m.m[1][1] = c; + m.m[2][2] = 1.0f; + if (x < 0.0f) { + m.m[1][3] = s * inv_dist_to_plane; + } else { + m.m[1][3] = -s * inv_dist_to_plane; + } + m.flagBits = General; + quick = true; + } + if (!quick) { + qreal len = x * x + y * y + z * z; + if (!qFuzzyIsNull(len - 1.0f) && !qFuzzyIsNull(len)) { + len = qSqrt(len); + x /= len; + y /= len; + z /= len; + } + ic = 1.0f - c; + m.m[0][0] = x * x * ic + c; + m.m[1][0] = x * y * ic - z * s; + m.m[2][0] = 0.0f; + m.m[3][0] = 0.0f; + m.m[0][1] = y * x * ic + z * s; + m.m[1][1] = y * y * ic + c; + m.m[2][1] = 0.0f; + m.m[3][1] = 0.0f; + m.m[0][2] = 0.0f; + m.m[1][2] = 0.0f; + m.m[2][2] = 1.0f; + m.m[3][2] = 0.0f; + m.m[0][3] = (x * z * ic - y * s) * -inv_dist_to_plane; + m.m[1][3] = (y * z * ic + x * s) * -inv_dist_to_plane; + m.m[2][3] = 0.0f; + m.m[3][3] = 1.0f; + } + int flags = flagBits; + *this *= m; + if (flags != Identity) + flagBits = flags | Rotation; + else + flagBits = Rotation; + return *this; +} + +#ifndef QT_NO_QUATERNION /*! Multiples this matrix by another that rotates coordinates according @@ -1448,8 +1554,6 @@ QTransform QMatrix4x4::toTransform() const m[3][0], m[3][1], m[3][3]); } -static const qreal inv_dist_to_plane = 1. / 1024.; - /*! Returns the conventional Qt 2D transformation matrix that corresponds to this matrix. diff --git a/src/gui/math3d/qmatrix4x4.h b/src/gui/math3d/qmatrix4x4.h index 42d992e..ba74b89 100644 --- a/src/gui/math3d/qmatrix4x4.h +++ b/src/gui/math3d/qmatrix4x4.h @@ -207,6 +207,10 @@ private: QMatrix4x4(int) { flagBits = General; } QMatrix4x4 orthonormalInverse() const; + + QMatrix4x4& projectedRotate(qreal angle, qreal x, qreal y, qreal z); + + friend class QGraphicsRotation; }; inline QMatrix4x4::QMatrix4x4 diff --git a/src/gui/text/qfontdatabase_x11.cpp b/src/gui/text/qfontdatabase_x11.cpp index b582e4a..f184811 100644 --- a/src/gui/text/qfontdatabase_x11.cpp +++ b/src/gui/text/qfontdatabase_x11.cpp @@ -1456,7 +1456,7 @@ void qt_addPatternProps(FcPattern *pattern, int screen, int script, const QFontD slant_value = FC_SLANT_OBLIQUE; FcPatternAddInteger(pattern, FC_SLANT, slant_value); - double size_value = qMax(1., request.pixelSize); + double size_value = qMax(qreal(1.), request.pixelSize); FcPatternAddDouble(pattern, FC_PIXEL_SIZE, size_value); int stretch = request.stretch; diff --git a/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp b/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp index bcc6bdb..a0810bc 100644 --- a/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp +++ b/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp @@ -1263,6 +1263,7 @@ void QGL2PaintEngineEx::stroke(const QVectorPath &path, const QPen &pen) QGLContext *ctx = d->ctx; + Q_UNUSED(ctx); if (opaque) { d->prepareForDraw(opaque); diff --git a/src/opengl/qglshaderprogram.cpp b/src/opengl/qglshaderprogram.cpp index 34114e4..d028522 100644 --- a/src/opengl/qglshaderprogram.cpp +++ b/src/opengl/qglshaderprogram.cpp @@ -42,6 +42,7 @@ #include "qglshaderprogram.h" #include "qglextensions_p.h" #include "qgl_p.h" +#include <QtCore/private/qobject_p.h> #include <QtCore/qdebug.h> #include <QtCore/qfile.h> #include <QtCore/qvarlengtharray.h> @@ -200,8 +201,9 @@ QT_BEGIN_NAMESPACE #define GL_NUM_SHADER_BINARY_FORMATS 0x8DF9 #endif -class QGLShaderPrivate +class QGLShaderPrivate : public QObjectPrivate { + Q_DECLARE_PUBLIC(QGLShader) public: QGLShaderPrivate(const QGLContext *context, QGLShader::ShaderType type) : shaderGuard(context) @@ -211,6 +213,7 @@ public: , hasPartialSource(false) { } + ~QGLShaderPrivate(); QGLSharedResourceGuard shaderGuard; QGLShader::ShaderType shaderType; @@ -227,6 +230,14 @@ public: #define ctx shaderGuard.context() +QGLShaderPrivate::~QGLShaderPrivate() +{ + if (shaderGuard.id()) { + QGLShareContextScope scope(shaderGuard.context()); + glDeleteShader(shaderGuard.id()); + } +} + bool QGLShaderPrivate::create() { const QGLContext *context = shaderGuard.context(); @@ -306,9 +317,9 @@ void QGLShaderPrivate::deleteShader() \sa compile(), compileFile() */ QGLShader::QGLShader(QGLShader::ShaderType type, QObject *parent) - : QObject(parent) + : QObject(*new QGLShaderPrivate(QGLContext::currentContext(), type), parent) { - d = new QGLShaderPrivate(QGLContext::currentContext(), type); + Q_D(QGLShader); d->create(); } @@ -323,13 +334,21 @@ QGLShader::QGLShader(QGLShader::ShaderType type, QObject *parent) */ QGLShader::QGLShader (const QString& fileName, QGLShader::ShaderType type, QObject *parent) - : QObject(parent) + : QObject(*new QGLShaderPrivate(QGLContext::currentContext(), type), parent) { - d = new QGLShaderPrivate(QGLContext::currentContext(), type); + Q_D(QGLShader); if (d->create() && !compileFile(fileName)) d->deleteShader(); } +static inline const QGLContext *contextOrCurrent(const QGLContext *context) +{ + if (context) + return context; + else + return QGLContext::currentContext(); +} + /*! Constructs a new QGLShader object of the specified \a type and attaches it to \a parent. If shader programs are not supported, @@ -343,14 +362,12 @@ QGLShader::QGLShader \sa compile(), compileFile() */ QGLShader::QGLShader(QGLShader::ShaderType type, const QGLContext *context, QObject *parent) - : QObject(parent) + : QObject(*new QGLShaderPrivate(contextOrCurrent(context), type), parent) { - if (!context) - context = QGLContext::currentContext(); - d = new QGLShaderPrivate(context, type); + Q_D(QGLShader); #ifndef QT_NO_DEBUG if (context && !QGLContext::areSharing(context, QGLContext::currentContext())) { - qWarning("QGLShader::QGLShader: \'context\' must be the currect context or sharing with it."); + qWarning("QGLShader::QGLShader: \'context\' must be the current context or sharing with it."); return; } #endif @@ -368,14 +385,12 @@ QGLShader::QGLShader(QGLShader::ShaderType type, const QGLContext *context, QObj */ QGLShader::QGLShader (const QString& fileName, QGLShader::ShaderType type, const QGLContext *context, QObject *parent) - : QObject(parent) + : QObject(*new QGLShaderPrivate(contextOrCurrent(context), type), parent) { - if (!context) - context = QGLContext::currentContext(); - d = new QGLShaderPrivate(context, type); + Q_D(QGLShader); #ifndef QT_NO_DEBUG if (context && !QGLContext::areSharing(context, QGLContext::currentContext())) { - qWarning("QGLShader::QGLShader: \'context\' must be currect context or sharing with it."); + qWarning("QGLShader::QGLShader: \'context\' must be current context or sharing with it."); return; } #endif @@ -390,11 +405,6 @@ QGLShader::QGLShader */ QGLShader::~QGLShader() { - if (d->shaderGuard.id()) { - QGLShareContextScope scope(d->shaderGuard.context()); - glDeleteShader(d->shaderGuard.id()); - } - delete d; } /*! @@ -402,6 +412,7 @@ QGLShader::~QGLShader() */ QGLShader::ShaderType QGLShader::shaderType() const { + Q_D(const QGLShader); return d->shaderType; } @@ -439,12 +450,14 @@ static const char redefineHighp[] = */ bool QGLShader::compile(const char *source) { + Q_D(QGLShader); if (d->isPartial) { d->partialSource = QByteArray(source); d->hasPartialSource = true; return d->compile(this); } else if (d->shaderGuard.id()) { - QVarLengthArray<const char *> src; + QVarLengthArray<const char *, 4> src; + QVarLengthArray<GLint, 4> srclen; int headerLen = 0; while (source && source[headerLen] == '#') { // Skip #version and #extension directives at the start of @@ -459,21 +472,24 @@ bool QGLShader::compile(const char *source) if (source[headerLen] == '\n') ++headerLen; } - QByteArray header; if (headerLen > 0) { - header = QByteArray(source, headerLen); - src.append(header.constData()); + src.append(source); + srclen.append(GLint(headerLen)); } #ifdef QGL_DEFINE_QUALIFIERS src.append(qualifierDefines); + srclen.append(GLint(sizeof(qualifierDefines) - 1)); #endif #ifdef QGL_REDEFINE_HIGHP if (d->shaderType == FragmentShader || - d->shaderType == PartialFragmentShader) + d->shaderType == PartialFragmentShader) { src.append(redefineHighp); + srclen.append(GLint(sizeof(redefineHighp) - 1)); + } #endif src.append(source + headerLen); - glShaderSource(d->shaderGuard.id(), src.size(), src.data(), 0); + srclen.append(GLint(qstrlen(source + headerLen))); + glShaderSource(d->shaderGuard.id(), src.size(), src.data(), srclen.data()); return d->compile(this); } else { return false; @@ -481,6 +497,61 @@ bool QGLShader::compile(const char *source) } /*! + \internal +*/ +bool QGLShader::compile + (const QList<QGLShader *>& shaders, QGLShader::ShaderType type) +{ + Q_D(QGLShader); + QVarLengthArray<const char *, 16> src; + QVarLengthArray<GLint, 16> srclen; + if (!d->shaderGuard.id()) + return false; + foreach (QGLShader *shader, shaders) { + if (shader->shaderType() != type) + continue; + const char *source = shader->d_func()->partialSource.constData(); + int headerLen = 0; + if (src.isEmpty()) { + // First shader: handle the #version and #extension tags + // plus the precision qualifiers. + while (source && source[headerLen] == '#') { + // Skip #version and #extension directives at the start of + // the shader code. We need to insert the qualifierDefines + // and redefineHighp just after them. + if (qstrncmp(source + headerLen, "#version", 8) != 0 && + qstrncmp(source + headerLen, "#extension", 10) != 0) { + break; + } + while (source[headerLen] != '\0' && source[headerLen] != '\n') + ++headerLen; + if (source[headerLen] == '\n') + ++headerLen; + } + if (headerLen > 0) { + src.append(source); + srclen.append(GLint(headerLen)); + } +#ifdef QGL_DEFINE_QUALIFIERS + src.append(qualifierDefines); + srclen.append(GLint(sizeof(qualifierDefines) - 1)); +#endif +#ifdef QGL_REDEFINE_HIGHP + if (d->shaderType == FragmentShader || + d->shaderType == PartialFragmentShader) { + src.append(redefineHighp); + srclen.append(GLint(sizeof(redefineHighp) - 1)); + } +#endif + } + src.append(source + headerLen); + srclen.append(GLint(qstrlen(source + headerLen))); + } + glShaderSource(d->shaderGuard.id(), src.size(), src.data(), srclen.data()); + return d->compile(this); +} + +/*! \overload Sets the \a source code for this shader and compiles it. @@ -555,6 +626,7 @@ bool QGLShader::compileFile(const QString& fileName) */ bool QGLShader::setShaderBinary(GLenum format, const void *binary, int length) { + Q_D(QGLShader); #if !defined(QT_OPENGL_ES_2) if (!glShaderBinary) return false; @@ -588,21 +660,22 @@ bool QGLShader::setShaderBinary(GLenum format, const void *binary, int length) bool QGLShader::setShaderBinary (QGLShader& otherShader, GLenum format, const void *binary, int length) { + Q_D(QGLShader); #if !defined(QT_OPENGL_ES_2) if (!glShaderBinary) return false; #endif if (d->isPartial || !d->shaderGuard.id()) return false; - if (otherShader.d->isPartial || !otherShader.d->shaderGuard.id()) + if (otherShader.d_func()->isPartial || !otherShader.d_func()->shaderGuard.id()) return false; glGetError(); // Clear error state. GLuint shaders[2]; shaders[0] = d->shaderGuard.id(); - shaders[1] = otherShader.d->shaderGuard.id(); + shaders[1] = otherShader.d_func()->shaderGuard.id(); glShaderBinary(2, shaders, format, binary, length); d->compiled = (glGetError() == GL_NO_ERROR); - otherShader.d->compiled = d->compiled; + otherShader.d_func()->compiled = d->compiled; return d->compiled; } @@ -634,6 +707,7 @@ QList<GLenum> QGLShader::shaderBinaryFormats() */ QByteArray QGLShader::sourceCode() const { + Q_D(const QGLShader); if (d->isPartial) return d->partialSource; GLuint shader = d->shaderGuard.id(); @@ -658,6 +732,7 @@ QByteArray QGLShader::sourceCode() const */ bool QGLShader::isCompiled() const { + Q_D(const QGLShader); return d->compiled; } @@ -668,6 +743,7 @@ bool QGLShader::isCompiled() const */ QString QGLShader::log() const { + Q_D(const QGLShader); return d->log; } @@ -682,14 +758,16 @@ QString QGLShader::log() const */ GLuint QGLShader::shaderId() const { + Q_D(const QGLShader); return d->shaderGuard.id(); } #undef ctx #define ctx programGuard.context() -class QGLShaderProgramPrivate +class QGLShaderProgramPrivate : public QObjectPrivate { + Q_DECLARE_PUBLIC(QGLShaderProgram) public: QGLShaderProgramPrivate(const QGLContext *context) : programGuard(context) @@ -713,6 +791,8 @@ public: QList<QGLShader *> anonShaders; QGLShader *vertexShader; QGLShader *fragmentShader; + + bool hasShader(QGLShader::ShaderType type) const; }; QGLShaderProgramPrivate::~QGLShaderProgramPrivate() @@ -723,6 +803,15 @@ QGLShaderProgramPrivate::~QGLShaderProgramPrivate() } } +bool QGLShaderProgramPrivate::hasShader(QGLShader::ShaderType type) const +{ + foreach (QGLShader *shader, shaders) { + if (shader->shaderType() == type) + return true; + } + return false; +} + #undef ctx #define ctx d->programGuard.context() @@ -735,9 +824,8 @@ QGLShaderProgramPrivate::~QGLShaderProgramPrivate() \sa addShader() */ QGLShaderProgram::QGLShaderProgram(QObject *parent) - : QObject(parent) + : QObject(*new QGLShaderProgramPrivate(QGLContext::currentContext()), parent) { - d = new QGLShaderProgramPrivate(QGLContext::currentContext()); } /*! @@ -749,9 +837,8 @@ QGLShaderProgram::QGLShaderProgram(QObject *parent) \sa addShader() */ QGLShaderProgram::QGLShaderProgram(const QGLContext *context, QObject *parent) - : QObject(parent) + : QObject(*new QGLShaderProgramPrivate(context), parent) { - d = new QGLShaderProgramPrivate(context); } /*! @@ -759,11 +846,11 @@ QGLShaderProgram::QGLShaderProgram(const QGLContext *context, QObject *parent) */ QGLShaderProgram::~QGLShaderProgram() { - delete d; } bool QGLShaderProgram::init() { + Q_D(QGLShaderProgram); if (d->programGuard.id() || d->inited) return true; d->inited = true; @@ -801,22 +888,23 @@ bool QGLShaderProgram::init() */ bool QGLShaderProgram::addShader(QGLShader *shader) { + Q_D(QGLShaderProgram); if (!init()) return false; if (d->shaders.contains(shader)) return true; // Already added to this shader program. if (d->programGuard.id() && shader) { - if (!QGLContext::areSharing(shader->d->shaderGuard.context(), + if (!QGLContext::areSharing(shader->d_func()->shaderGuard.context(), d->programGuard.context())) { qWarning("QGLShaderProgram::addShader: Program and shader are not associated with same context."); return false; } - if (!shader->d->compiled) + if (!shader->d_func()->compiled) return false; - if (!shader->d->isPartial) { - if (!shader->d->shaderGuard.id()) + if (!shader->d_func()->isPartial) { + if (!shader->d_func()->shaderGuard.id()) return false; - glAttachShader(d->programGuard.id(), shader->d->shaderGuard.id()); + glAttachShader(d->programGuard.id(), shader->d_func()->shaderGuard.id()); } else { d->hasPartialShaders = true; } @@ -843,6 +931,7 @@ bool QGLShaderProgram::addShader(QGLShader *shader) */ bool QGLShaderProgram::addShader(QGLShader::ShaderType type, const char *source) { + Q_D(QGLShaderProgram); if (!init()) return false; QGLShader *shader = new QGLShader(type, this); @@ -908,6 +997,7 @@ bool QGLShaderProgram::addShader(QGLShader::ShaderType type, const QString& sour bool QGLShaderProgram::addShaderFromFile (QGLShader::ShaderType type, const QString& fileName) { + Q_D(QGLShaderProgram); if (!init()) return false; QGLShader *shader = new QGLShader(type, this); @@ -927,9 +1017,10 @@ bool QGLShaderProgram::addShaderFromFile */ void QGLShaderProgram::removeShader(QGLShader *shader) { - if (d->programGuard.id() && shader && shader->d->shaderGuard.id()) { + Q_D(QGLShaderProgram); + if (d->programGuard.id() && shader && shader->d_func()->shaderGuard.id()) { QGLShareContextScope scope(d->programGuard.context()); - glDetachShader(d->programGuard.id(), shader->d->shaderGuard.id()); + glDetachShader(d->programGuard.id(), shader->d_func()->shaderGuard.id()); } d->linked = false; // Program needs to be relinked. if (shader) { @@ -947,6 +1038,7 @@ void QGLShaderProgram::removeShader(QGLShader *shader) */ QList<QGLShader *> QGLShaderProgram::shaders() const { + Q_D(const QGLShaderProgram); return d->shaders; } @@ -960,10 +1052,11 @@ QList<QGLShader *> QGLShaderProgram::shaders() const */ void QGLShaderProgram::removeAllShaders() { + Q_D(QGLShaderProgram); d->removingShaders = true; foreach (QGLShader *shader, d->shaders) { - if (d->programGuard.id() && shader && shader->d->shaderGuard.id()) - glDetachShader(d->programGuard.id(), shader->d->shaderGuard.id()); + if (d->programGuard.id() && shader && shader->d_func()->shaderGuard.id()) + glDetachShader(d->programGuard.id(), shader->d_func()->shaderGuard.id()); } foreach (QGLShader *shader, d->anonShaders) { // Delete shader objects that were created anonymously. @@ -1009,6 +1102,7 @@ void QGLShaderProgram::removeAllShaders() QByteArray QGLShaderProgram::programBinary(int *format) const { #if defined(QT_OPENGL_ES_2) + Q_D(const QGLShaderProgram); if (!isLinked()) return QByteArray(); @@ -1044,6 +1138,7 @@ bool QGLShaderProgram::setProgramBinary(int format, const QByteArray& binary) { #if defined(QT_OPENGL_ES_2) // Load the binary and check that it was linked correctly. + Q_D(QGLShaderProgram); GLuint program = d->programGuard.id(); if (!program) return false; @@ -1113,52 +1208,47 @@ QList<int> QGLShaderProgram::programBinaryFormats() */ bool QGLShaderProgram::link() { + Q_D(QGLShaderProgram); GLuint program = d->programGuard.id(); if (!program) return false; if (d->hasPartialShaders) { // Compile the partial vertex and fragment shaders. - QByteArray vertexSource; - QByteArray fragmentSource; - foreach (QGLShader *shader, d->shaders) { - if (shader->shaderType() == QGLShader::PartialVertexShader) - vertexSource += shader->sourceCode(); - else if (shader->shaderType() == QGLShader::PartialFragmentShader) - fragmentSource += shader->sourceCode(); - } - if (vertexSource.isEmpty()) { - if (d->vertexShader) { - glDetachShader(program, d->vertexShader->d->shaderGuard.id()); - delete d->vertexShader; - d->vertexShader = 0; - } - } else { + if (d->hasShader(QGLShader::PartialVertexShader)) { if (!d->vertexShader) { d->vertexShader = new QGLShader(QGLShader::VertexShader, this); } - if (!d->vertexShader->compile(vertexSource)) { + if (!d->vertexShader->compile + (d->shaders, QGLShader::PartialVertexShader)) { d->log = d->vertexShader->log(); return false; } - glAttachShader(program, d->vertexShader->d->shaderGuard.id()); - } - if (fragmentSource.isEmpty()) { - if (d->fragmentShader) { - glDetachShader(program, d->fragmentShader->d->shaderGuard.id()); - delete d->fragmentShader; - d->fragmentShader = 0; - } + glAttachShader(program, d->vertexShader->d_func()->shaderGuard.id()); } else { + if (d->vertexShader) { + glDetachShader(program, d->vertexShader->d_func()->shaderGuard.id()); + delete d->vertexShader; + d->vertexShader = 0; + } + } + if (d->hasShader(QGLShader::PartialFragmentShader)) { if (!d->fragmentShader) { d->fragmentShader = new QGLShader(QGLShader::FragmentShader, this); } - if (!d->fragmentShader->compile(fragmentSource)) { + if (!d->fragmentShader->compile + (d->shaders, QGLShader::PartialFragmentShader)) { d->log = d->fragmentShader->log(); return false; } - glAttachShader(program, d->fragmentShader->d->shaderGuard.id()); + glAttachShader(program, d->fragmentShader->d_func()->shaderGuard.id()); + } else { + if (d->fragmentShader) { + glDetachShader(program, d->fragmentShader->d_func()->shaderGuard.id()); + delete d->fragmentShader; + d->fragmentShader = 0; + } } } glLinkProgram(program); @@ -1190,6 +1280,7 @@ bool QGLShaderProgram::link() */ bool QGLShaderProgram::isLinked() const { + Q_D(const QGLShaderProgram); return d->linked; } @@ -1201,6 +1292,7 @@ bool QGLShaderProgram::isLinked() const */ QString QGLShaderProgram::log() const { + Q_D(const QGLShaderProgram); return d->log; } @@ -1214,6 +1306,7 @@ QString QGLShaderProgram::log() const */ bool QGLShaderProgram::enable() { + Q_D(QGLShaderProgram); GLuint program = d->programGuard.id(); if (!program) return false; @@ -1252,6 +1345,7 @@ void QGLShaderProgram::disable() */ GLuint QGLShaderProgram::programId() const { + Q_D(const QGLShaderProgram); return d->programGuard.id(); } @@ -1265,6 +1359,7 @@ GLuint QGLShaderProgram::programId() const */ void QGLShaderProgram::bindAttributeLocation(const char *name, int location) { + Q_D(QGLShaderProgram); if (!d->linked) { glBindAttribLocation(d->programGuard.id(), location, name); } else { @@ -1312,6 +1407,7 @@ void QGLShaderProgram::bindAttributeLocation(const QString& name, int location) */ int QGLShaderProgram::attributeLocation(const char *name) const { + Q_D(const QGLShaderProgram); if (d->linked) { return glGetAttribLocation(d->programGuard.id(), name); } else { @@ -1356,6 +1452,8 @@ int QGLShaderProgram::attributeLocation(const QString& name) const */ void QGLShaderProgram::setAttributeValue(int location, GLfloat value) { + Q_D(QGLShaderProgram); + Q_UNUSED(d); if (location != -1) glVertexAttrib1fv(location, &value); } @@ -1380,6 +1478,8 @@ void QGLShaderProgram::setAttributeValue(const char *name, GLfloat value) */ void QGLShaderProgram::setAttributeValue(int location, GLfloat x, GLfloat y) { + Q_D(QGLShaderProgram); + Q_UNUSED(d); if (location != -1) { GLfloat values[2] = {x, y}; glVertexAttrib2fv(location, values); @@ -1408,6 +1508,8 @@ void QGLShaderProgram::setAttributeValue(const char *name, GLfloat x, GLfloat y) void QGLShaderProgram::setAttributeValue (int location, GLfloat x, GLfloat y, GLfloat z) { + Q_D(QGLShaderProgram); + Q_UNUSED(d); if (location != -1) { GLfloat values[3] = {x, y, z}; glVertexAttrib3fv(location, values); @@ -1437,6 +1539,8 @@ void QGLShaderProgram::setAttributeValue void QGLShaderProgram::setAttributeValue (int location, GLfloat x, GLfloat y, GLfloat z, GLfloat w) { + Q_D(QGLShaderProgram); + Q_UNUSED(d); if (location != -1) { GLfloat values[4] = {x, y, z, w}; glVertexAttrib4fv(location, values); @@ -1464,6 +1568,8 @@ void QGLShaderProgram::setAttributeValue */ void QGLShaderProgram::setAttributeValue(int location, const QVector2D& value) { + Q_D(QGLShaderProgram); + Q_UNUSED(d); if (location != -1) glVertexAttrib2fv(location, reinterpret_cast<const GLfloat *>(&value)); } @@ -1487,6 +1593,8 @@ void QGLShaderProgram::setAttributeValue(const char *name, const QVector2D& valu */ void QGLShaderProgram::setAttributeValue(int location, const QVector3D& value) { + Q_D(QGLShaderProgram); + Q_UNUSED(d); if (location != -1) glVertexAttrib3fv(location, reinterpret_cast<const GLfloat *>(&value)); } @@ -1510,6 +1618,8 @@ void QGLShaderProgram::setAttributeValue(const char *name, const QVector3D& valu */ void QGLShaderProgram::setAttributeValue(int location, const QVector4D& value) { + Q_D(QGLShaderProgram); + Q_UNUSED(d); if (location != -1) glVertexAttrib4fv(location, reinterpret_cast<const GLfloat *>(&value)); } @@ -1533,6 +1643,8 @@ void QGLShaderProgram::setAttributeValue(const char *name, const QVector4D& valu */ void QGLShaderProgram::setAttributeValue(int location, const QColor& value) { + Q_D(QGLShaderProgram); + Q_UNUSED(d); if (location != -1) { GLfloat values[4] = {value.redF(), value.greenF(), value.blueF(), value.alphaF()}; glVertexAttrib4fv(location, values); @@ -1563,6 +1675,8 @@ void QGLShaderProgram::setAttributeValue(const char *name, const QColor& value) void QGLShaderProgram::setAttributeValue (int location, const GLfloat *values, int columns, int rows) { + Q_D(QGLShaderProgram); + Q_UNUSED(d); if (rows < 1 || rows > 4) { qWarning() << "QGLShaderProgram::setAttributeValue: rows" << rows << "not supported"; return; @@ -1612,6 +1726,8 @@ void QGLShaderProgram::setAttributeValue void QGLShaderProgram::setAttributeArray (int location, const GLfloat *values, int size, int stride) { + Q_D(QGLShaderProgram); + Q_UNUSED(d); if (location != -1) { glVertexAttribPointer(location, size, GL_FLOAT, GL_FALSE, stride, values); @@ -1630,6 +1746,8 @@ void QGLShaderProgram::setAttributeArray void QGLShaderProgram::setAttributeArray (int location, const QVector2D *values, int stride) { + Q_D(QGLShaderProgram); + Q_UNUSED(d); if (location != -1) { glVertexAttribPointer(location, 2, GL_FLOAT, GL_FALSE, stride, values); @@ -1648,6 +1766,8 @@ void QGLShaderProgram::setAttributeArray void QGLShaderProgram::setAttributeArray (int location, const QVector3D *values, int stride) { + Q_D(QGLShaderProgram); + Q_UNUSED(d); if (location != -1) { glVertexAttribPointer(location, 3, GL_FLOAT, GL_FALSE, stride, values); @@ -1666,6 +1786,8 @@ void QGLShaderProgram::setAttributeArray void QGLShaderProgram::setAttributeArray (int location, const QVector4D *values, int stride) { + Q_D(QGLShaderProgram); + Q_UNUSED(d); if (location != -1) { glVertexAttribPointer(location, 4, GL_FLOAT, GL_FALSE, stride, values); @@ -1746,6 +1868,8 @@ void QGLShaderProgram::setAttributeArray */ void QGLShaderProgram::disableAttributeArray(int location) { + Q_D(QGLShaderProgram); + Q_UNUSED(d); if (location != -1) glDisableVertexAttribArray(location); } @@ -1772,6 +1896,8 @@ void QGLShaderProgram::disableAttributeArray(const char *name) */ int QGLShaderProgram::uniformLocation(const char *name) const { + Q_D(const QGLShaderProgram); + Q_UNUSED(d); if (d->linked) { return glGetUniformLocation(d->programGuard.id(), name); } else { @@ -1816,6 +1942,8 @@ int QGLShaderProgram::uniformLocation(const QString& name) const */ void QGLShaderProgram::setUniformValue(int location, GLfloat value) { + Q_D(QGLShaderProgram); + Q_UNUSED(d); if (location != -1) glUniform1fv(location, 1, &value); } @@ -1840,6 +1968,8 @@ void QGLShaderProgram::setUniformValue(const char *name, GLfloat value) */ void QGLShaderProgram::setUniformValue(int location, GLint value) { + Q_D(QGLShaderProgram); + Q_UNUSED(d); if (location != -1) glUniform1i(location, value); } @@ -1865,6 +1995,8 @@ void QGLShaderProgram::setUniformValue(const char *name, GLint value) */ void QGLShaderProgram::setUniformValue(int location, GLuint value) { + Q_D(QGLShaderProgram); + Q_UNUSED(d); if (location != -1) glUniform1i(location, value); } @@ -1890,6 +2022,8 @@ void QGLShaderProgram::setUniformValue(const char *name, GLuint value) */ void QGLShaderProgram::setUniformValue(int location, GLfloat x, GLfloat y) { + Q_D(QGLShaderProgram); + Q_UNUSED(d); if (location != -1) { GLfloat values[2] = {x, y}; glUniform2fv(location, 1, values); @@ -1918,6 +2052,8 @@ void QGLShaderProgram::setUniformValue(const char *name, GLfloat x, GLfloat y) void QGLShaderProgram::setUniformValue (int location, GLfloat x, GLfloat y, GLfloat z) { + Q_D(QGLShaderProgram); + Q_UNUSED(d); if (location != -1) { GLfloat values[3] = {x, y, z}; glUniform3fv(location, 1, values); @@ -1947,6 +2083,8 @@ void QGLShaderProgram::setUniformValue void QGLShaderProgram::setUniformValue (int location, GLfloat x, GLfloat y, GLfloat z, GLfloat w) { + Q_D(QGLShaderProgram); + Q_UNUSED(d); if (location != -1) { GLfloat values[4] = {x, y, z, w}; glUniform4fv(location, 1, values); @@ -1974,6 +2112,8 @@ void QGLShaderProgram::setUniformValue */ void QGLShaderProgram::setUniformValue(int location, const QVector2D& value) { + Q_D(QGLShaderProgram); + Q_UNUSED(d); if (location != -1) glUniform2fv(location, 1, reinterpret_cast<const GLfloat *>(&value)); } @@ -1998,6 +2138,8 @@ void QGLShaderProgram::setUniformValue(const char *name, const QVector2D& value) */ void QGLShaderProgram::setUniformValue(int location, const QVector3D& value) { + Q_D(QGLShaderProgram); + Q_UNUSED(d); if (location != -1) glUniform3fv(location, 1, reinterpret_cast<const GLfloat *>(&value)); } @@ -2022,6 +2164,8 @@ void QGLShaderProgram::setUniformValue(const char *name, const QVector3D& value) */ void QGLShaderProgram::setUniformValue(int location, const QVector4D& value) { + Q_D(QGLShaderProgram); + Q_UNUSED(d); if (location != -1) glUniform4fv(location, 1, reinterpret_cast<const GLfloat *>(&value)); } @@ -2047,6 +2191,8 @@ void QGLShaderProgram::setUniformValue(const char *name, const QVector4D& value) */ void QGLShaderProgram::setUniformValue(int location, const QColor& color) { + Q_D(QGLShaderProgram); + Q_UNUSED(d); if (location != -1) { GLfloat values[4] = {color.redF(), color.greenF(), color.blueF(), color.alphaF()}; glUniform4fv(location, 1, values); @@ -2074,6 +2220,8 @@ void QGLShaderProgram::setUniformValue(const char *name, const QColor& color) */ void QGLShaderProgram::setUniformValue(int location, const QPoint& point) { + Q_D(QGLShaderProgram); + Q_UNUSED(d); if (location != -1) { GLfloat values[4] = {point.x(), point.y()}; glUniform2fv(location, 1, values); @@ -2101,6 +2249,8 @@ void QGLShaderProgram::setUniformValue(const char *name, const QPoint& point) */ void QGLShaderProgram::setUniformValue(int location, const QPointF& point) { + Q_D(QGLShaderProgram); + Q_UNUSED(d); if (location != -1) { GLfloat values[4] = {point.x(), point.y()}; glUniform2fv(location, 1, values); @@ -2128,6 +2278,8 @@ void QGLShaderProgram::setUniformValue(const char *name, const QPointF& point) */ void QGLShaderProgram::setUniformValue(int location, const QSize& size) { + Q_D(QGLShaderProgram); + Q_UNUSED(d); if (location != -1) { GLfloat values[4] = {size.width(), size.width()}; glUniform2fv(location, 1, values); @@ -2155,6 +2307,8 @@ void QGLShaderProgram::setUniformValue(const char *name, const QSize& size) */ void QGLShaderProgram::setUniformValue(int location, const QSizeF& size) { + Q_D(QGLShaderProgram); + Q_UNUSED(d); if (location != -1) { GLfloat values[4] = {size.width(), size.height()}; glUniform2fv(location, 1, values); @@ -2234,6 +2388,8 @@ void QGLShaderProgram::setUniformValue(const char *name, const QSizeF& size) */ void QGLShaderProgram::setUniformValue(int location, const QMatrix2x2& value) { + Q_D(QGLShaderProgram); + Q_UNUSED(d); setUniformMatrix(glUniformMatrix2fv, location, value, 2, 2); } @@ -2258,6 +2414,8 @@ void QGLShaderProgram::setUniformValue(const char *name, const QMatrix2x2& value */ void QGLShaderProgram::setUniformValue(int location, const QMatrix2x3& value) { + Q_D(QGLShaderProgram); + Q_UNUSED(d); setUniformGenericMatrix (glUniformMatrix2x3fv, glUniform3fv, location, value, 2, 3); } @@ -2283,6 +2441,8 @@ void QGLShaderProgram::setUniformValue(const char *name, const QMatrix2x3& value */ void QGLShaderProgram::setUniformValue(int location, const QMatrix2x4& value) { + Q_D(QGLShaderProgram); + Q_UNUSED(d); setUniformGenericMatrix (glUniformMatrix2x4fv, glUniform4fv, location, value, 2, 4); } @@ -2308,6 +2468,8 @@ void QGLShaderProgram::setUniformValue(const char *name, const QMatrix2x4& value */ void QGLShaderProgram::setUniformValue(int location, const QMatrix3x2& value) { + Q_D(QGLShaderProgram); + Q_UNUSED(d); setUniformGenericMatrix (glUniformMatrix3x2fv, glUniform2fv, location, value, 3, 2); } @@ -2333,6 +2495,8 @@ void QGLShaderProgram::setUniformValue(const char *name, const QMatrix3x2& value */ void QGLShaderProgram::setUniformValue(int location, const QMatrix3x3& value) { + Q_D(QGLShaderProgram); + Q_UNUSED(d); setUniformMatrix(glUniformMatrix3fv, location, value, 3, 3); } @@ -2357,6 +2521,8 @@ void QGLShaderProgram::setUniformValue(const char *name, const QMatrix3x3& value */ void QGLShaderProgram::setUniformValue(int location, const QMatrix3x4& value) { + Q_D(QGLShaderProgram); + Q_UNUSED(d); setUniformGenericMatrix (glUniformMatrix3x4fv, glUniform4fv, location, value, 3, 4); } @@ -2382,6 +2548,8 @@ void QGLShaderProgram::setUniformValue(const char *name, const QMatrix3x4& value */ void QGLShaderProgram::setUniformValue(int location, const QMatrix4x2& value) { + Q_D(QGLShaderProgram); + Q_UNUSED(d); setUniformGenericMatrix (glUniformMatrix4x2fv, glUniform2fv, location, value, 4, 2); } @@ -2407,6 +2575,8 @@ void QGLShaderProgram::setUniformValue(const char *name, const QMatrix4x2& value */ void QGLShaderProgram::setUniformValue(int location, const QMatrix4x3& value) { + Q_D(QGLShaderProgram); + Q_UNUSED(d); setUniformGenericMatrix (glUniformMatrix4x3fv, glUniform3fv, location, value, 4, 3); } @@ -2432,6 +2602,8 @@ void QGLShaderProgram::setUniformValue(const char *name, const QMatrix4x3& value */ void QGLShaderProgram::setUniformValue(int location, const QMatrix4x4& value) { + Q_D(QGLShaderProgram); + Q_UNUSED(d); setUniformMatrix(glUniformMatrix4fv, location, value, 4, 4); } @@ -2459,6 +2631,8 @@ void QGLShaderProgram::setUniformValue(const char *name, const QMatrix4x4& value */ void QGLShaderProgram::setUniformValue(int location, const GLfloat value[4][4]) { + Q_D(QGLShaderProgram); + Q_UNUSED(d); if (location != -1) glUniformMatrix4fv(location, 1, GL_FALSE, value[0]); } @@ -2486,6 +2660,8 @@ void QGLShaderProgram::setUniformValue(const char *name, const GLfloat value[4][ */ void QGLShaderProgram::setUniformValue(int location, const QTransform& value) { + Q_D(QGLShaderProgram); + Q_UNUSED(d); if (location != -1) { GLfloat mat[3][3] = { {value.m11(), value.m12(), value.m13()}, @@ -2519,6 +2695,8 @@ void QGLShaderProgram::setUniformValue */ void QGLShaderProgram::setUniformValueArray(int location, const GLint *values, int count) { + Q_D(QGLShaderProgram); + Q_UNUSED(d); if (location != -1) glUniform1iv(location, count, values); } @@ -2546,6 +2724,8 @@ void QGLShaderProgram::setUniformValueArray */ void QGLShaderProgram::setUniformValueArray(int location, const GLuint *values, int count) { + Q_D(QGLShaderProgram); + Q_UNUSED(d); if (location != -1) glUniform1iv(location, count, reinterpret_cast<const GLint *>(values)); } @@ -2574,6 +2754,8 @@ void QGLShaderProgram::setUniformValueArray */ void QGLShaderProgram::setUniformValueArray(int location, const GLfloat *values, int count, int size) { + Q_D(QGLShaderProgram); + Q_UNUSED(d); if (location != -1) { if (size == 1) glUniform1fv(location, count, values); @@ -2611,6 +2793,8 @@ void QGLShaderProgram::setUniformValueArray */ void QGLShaderProgram::setUniformValueArray(int location, const QVector2D *values, int count) { + Q_D(QGLShaderProgram); + Q_UNUSED(d); if (location != -1) glUniform2fv(location, count, reinterpret_cast<const GLfloat *>(values)); } @@ -2636,6 +2820,8 @@ void QGLShaderProgram::setUniformValueArray(const char *name, const QVector2D *v */ void QGLShaderProgram::setUniformValueArray(int location, const QVector3D *values, int count) { + Q_D(QGLShaderProgram); + Q_UNUSED(d); if (location != -1) glUniform3fv(location, count, reinterpret_cast<const GLfloat *>(values)); } @@ -2661,6 +2847,8 @@ void QGLShaderProgram::setUniformValueArray(const char *name, const QVector3D *v */ void QGLShaderProgram::setUniformValueArray(int location, const QVector4D *values, int count) { + Q_D(QGLShaderProgram); + Q_UNUSED(d); if (location != -1) glUniform4fv(location, count, reinterpret_cast<const GLfloat *>(values)); } @@ -2747,6 +2935,8 @@ void QGLShaderProgram::setUniformValueArray(const char *name, const QVector4D *v */ void QGLShaderProgram::setUniformValueArray(int location, const QMatrix2x2 *values, int count) { + Q_D(QGLShaderProgram); + Q_UNUSED(d); setUniformMatrixArray (glUniformMatrix2fv, location, values, count, QMatrix2x2, 2, 2); } @@ -2772,6 +2962,8 @@ void QGLShaderProgram::setUniformValueArray(const char *name, const QMatrix2x2 * */ void QGLShaderProgram::setUniformValueArray(int location, const QMatrix2x3 *values, int count) { + Q_D(QGLShaderProgram); + Q_UNUSED(d); setUniformGenericMatrixArray (glUniformMatrix2x3fv, glUniform3fv, location, values, count, QMatrix2x3, 2, 3); @@ -2798,6 +2990,8 @@ void QGLShaderProgram::setUniformValueArray(const char *name, const QMatrix2x3 * */ void QGLShaderProgram::setUniformValueArray(int location, const QMatrix2x4 *values, int count) { + Q_D(QGLShaderProgram); + Q_UNUSED(d); setUniformGenericMatrixArray (glUniformMatrix2x4fv, glUniform4fv, location, values, count, QMatrix2x4, 2, 4); @@ -2824,6 +3018,8 @@ void QGLShaderProgram::setUniformValueArray(const char *name, const QMatrix2x4 * */ void QGLShaderProgram::setUniformValueArray(int location, const QMatrix3x2 *values, int count) { + Q_D(QGLShaderProgram); + Q_UNUSED(d); setUniformGenericMatrixArray (glUniformMatrix3x2fv, glUniform2fv, location, values, count, QMatrix3x2, 3, 2); @@ -2850,6 +3046,8 @@ void QGLShaderProgram::setUniformValueArray(const char *name, const QMatrix3x2 * */ void QGLShaderProgram::setUniformValueArray(int location, const QMatrix3x3 *values, int count) { + Q_D(QGLShaderProgram); + Q_UNUSED(d); setUniformMatrixArray (glUniformMatrix3fv, location, values, count, QMatrix3x3, 3, 3); } @@ -2875,6 +3073,8 @@ void QGLShaderProgram::setUniformValueArray(const char *name, const QMatrix3x3 * */ void QGLShaderProgram::setUniformValueArray(int location, const QMatrix3x4 *values, int count) { + Q_D(QGLShaderProgram); + Q_UNUSED(d); setUniformGenericMatrixArray (glUniformMatrix3x4fv, glUniform4fv, location, values, count, QMatrix3x4, 3, 4); @@ -2901,6 +3101,8 @@ void QGLShaderProgram::setUniformValueArray(const char *name, const QMatrix3x4 * */ void QGLShaderProgram::setUniformValueArray(int location, const QMatrix4x2 *values, int count) { + Q_D(QGLShaderProgram); + Q_UNUSED(d); setUniformGenericMatrixArray (glUniformMatrix4x2fv, glUniform2fv, location, values, count, QMatrix4x2, 4, 2); @@ -2927,6 +3129,8 @@ void QGLShaderProgram::setUniformValueArray(const char *name, const QMatrix4x2 * */ void QGLShaderProgram::setUniformValueArray(int location, const QMatrix4x3 *values, int count) { + Q_D(QGLShaderProgram); + Q_UNUSED(d); setUniformGenericMatrixArray (glUniformMatrix4x3fv, glUniform3fv, location, values, count, QMatrix4x3, 4, 3); @@ -2953,6 +3157,8 @@ void QGLShaderProgram::setUniformValueArray(const char *name, const QMatrix4x3 * */ void QGLShaderProgram::setUniformValueArray(int location, const QMatrix4x4 *values, int count) { + Q_D(QGLShaderProgram); + Q_UNUSED(d); setUniformMatrixArray (glUniformMatrix4fv, location, values, count, QMatrix4x4, 4, 4); } @@ -2998,6 +3204,7 @@ bool QGLShaderProgram::hasShaderPrograms(const QGLContext *context) */ void QGLShaderProgram::shaderDestroyed() { + Q_D(QGLShaderProgram); QGLShader *shader = qobject_cast<QGLShader *>(sender()); if (shader && !d->removingShaders) removeShader(shader); diff --git a/src/opengl/qglshaderprogram.h b/src/opengl/qglshaderprogram.h index f2d70fa..d8b9a0c 100644 --- a/src/opengl/qglshaderprogram.h +++ b/src/opengl/qglshaderprogram.h @@ -101,11 +101,12 @@ public: GLuint shaderId() const; private: - QGLShaderPrivate *d; - friend class QGLShaderProgram; Q_DISABLE_COPY(QGLShader) + Q_DECLARE_PRIVATE(QGLShader) + + bool compile(const QList<QGLShader *>& shaders, QGLShader::ShaderType type); }; Q_DECLARE_OPERATORS_FOR_FLAGS(QGLShader::ShaderType) @@ -286,9 +287,8 @@ private Q_SLOTS: void shaderDestroyed(); private: - QGLShaderProgramPrivate *d; - Q_DISABLE_COPY(QGLShaderProgram) + Q_DECLARE_PRIVATE(QGLShaderProgram) bool init(); }; diff --git a/src/opengl/qwindowsurface_gl.cpp b/src/opengl/qwindowsurface_gl.cpp index 4547416..42e1c1e 100644 --- a/src/opengl/qwindowsurface_gl.cpp +++ b/src/opengl/qwindowsurface_gl.cpp @@ -364,7 +364,7 @@ void QGLWindowSurface::hijackWindow(QWidget *widget) if (ctxpriv->eglSurface == EGL_NO_SURFACE) { qWarning() << "hijackWindow() could not create EGL surface"; } - qDebug("QGLWindowSurface - using EGLConfig %d", ctxpriv->eglContext->config()); + qDebug("QGLWindowSurface - using EGLConfig %d", reinterpret_cast<int>(ctxpriv->eglContext->config())); #endif widgetPrivate->extraData()->glContext = ctx; diff --git a/src/opengl/qwindowsurface_x11gl.cpp b/src/opengl/qwindowsurface_x11gl.cpp index 8ef239d..db81be2 100644 --- a/src/opengl/qwindowsurface_x11gl.cpp +++ b/src/opengl/qwindowsurface_x11gl.cpp @@ -124,6 +124,9 @@ void QX11GLWindowSurface::setGeometry(const QRect &rect) bool QX11GLWindowSurface::scroll(const QRegion &area, int dx, int dy) { + Q_UNUSED(area); + Q_UNUSED(dx); + Q_UNUSED(dy); return false; } diff --git a/src/script/api/api.pri b/src/script/api/api.pri index 17ec9b6..aebadd5 100644 --- a/src/script/api/api.pri +++ b/src/script/api/api.pri @@ -6,6 +6,7 @@ SOURCES += \ $$PWD/qscriptengine.cpp \ $$PWD/qscriptengineagent.cpp \ $$PWD/qscriptextensionplugin.cpp \ + $$PWD/qscriptprogram.cpp \ $$PWD/qscriptstring.cpp \ $$PWD/qscriptvalue.cpp \ $$PWD/qscriptvalueiterator.cpp \ @@ -23,6 +24,8 @@ HEADERS += \ $$PWD/qscriptengineagent_p.h \ $$PWD/qscriptextensioninterface.h \ $$PWD/qscriptextensionplugin.h \ + $$PWD/qscriptprogram.h \ + $$PWD/qscriptprogram_p.h \ $$PWD/qscriptstring.h \ $$PWD/qscriptstring_p.h \ $$PWD/qscriptvalue.h \ diff --git a/src/script/api/qscriptengine.cpp b/src/script/api/qscriptengine.cpp index 357254b..f695a77 100644 --- a/src/script/api/qscriptengine.cpp +++ b/src/script/api/qscriptengine.cpp @@ -51,6 +51,8 @@ #include "qscriptvalue_p.h" #include "qscriptvalueiterator.h" #include "qscriptclass.h" +#include "qscriptprogram.h" +#include "qscriptprogram_p.h" #include "qdebug.h" #include <QtCore/qstringlist.h> @@ -340,25 +342,6 @@ public: JSC::JSValue prototype; }; -class QScriptProgramPrivate -{ -public: - QScriptProgramPrivate() : refcount(1), hasException(false) { } - ~QScriptProgramPrivate() { if (evalNode) evalNode->destroyData(); } - - void addref() { ++refcount; } - void release() { if (--refcount) delete this; } - - int refcount; - - bool hasException; - QScriptValue exception; - - JSC::SourceCode source; - WTF::RefPtr<JSC::EvalNode> evalNode; -}; - - namespace QScript { @@ -1192,6 +1175,72 @@ void QScriptEnginePrivate::agentDeleted(QScriptEngineAgent *agent) } } +JSC::JSValue QScriptEnginePrivate::evaluateHelper(JSC::ExecState *exec, intptr_t sourceId, + JSC::EvalExecutable *executable, + bool &compile) +{ + JSC::JSLock lock(false); // ### hmmm + QBoolBlocker inEvalBlocker(inEval, true); + q_func()->currentContext()->activationObject(); //force the creation of a context for native function; + + JSC::Debugger* debugger = originalGlobalObject()->debugger(); + if (debugger) + debugger->evaluateStart(sourceId); + + exec->clearException(); + JSC::DynamicGlobalObjectScope dynamicGlobalObjectScope(exec, exec->scopeChain()->globalObject()); + + if (compile) { + JSC::JSObject* error = executable->compile(exec, exec->scopeChain()); + if (error) { + compile = false; + exec->setException(error); + + if (debugger) { + debugger->exceptionThrow(JSC::DebuggerCallFrame(exec, error), sourceId, false); + debugger->evaluateStop(error, sourceId); + } + + return error; + } + } + + JSC::JSValue thisValue = thisForContext(exec); + JSC::JSObject* thisObject = (!thisValue || thisValue.isUndefinedOrNull()) + ? exec->dynamicGlobalObject() : thisValue.toObject(exec); + JSC::JSValue exceptionValue; + timeoutChecker()->setShouldAbort(false); + if (processEventsInterval > 0) + timeoutChecker()->reset(); + + JSC::JSValue result = exec->interpreter()->execute(executable, exec, thisObject, exec->scopeChain(), &exceptionValue); + + if (timeoutChecker()->shouldAbort()) { + if (abortResult.isError()) + exec->setException(scriptValueToJSCValue(abortResult)); + + if (debugger) + debugger->evaluateStop(scriptValueToJSCValue(abortResult), sourceId); + + return scriptValueToJSCValue(abortResult); + } + + if (exceptionValue) { + exec->setException(exceptionValue); + + if (debugger) + debugger->evaluateStop(exceptionValue, sourceId); + + return exceptionValue; + } + + if (debugger) + debugger->evaluateStop(result, sourceId); + + Q_ASSERT(!exec->hadException()); + return result; +} + #ifndef QT_NO_QOBJECT JSC::JSValue QScriptEnginePrivate::newQObject( @@ -2119,121 +2168,7 @@ QScriptSyntaxCheckResult QScriptEnginePrivate::checkSyntax(const QString &progra return QScriptSyntaxCheckResult(p); } -QScriptProgram QScriptEngine::compile(const QString &program, const QString &fileName, int lineNumber) -{ - Q_D(QScriptEngine); - - QScriptProgram rv; - rv.d = new QScriptProgramPrivate; - - JSC::JSLock lock(false); // ### hmmm - QBoolBlocker inEval(d->inEval, true); - currentContext()->activationObject(); //force the creation of a context for native function; - - JSC::Debugger* debugger = d->originalGlobalObject()->debugger(); - - JSC::UString jscProgram = program; - JSC::UString jscFileName = fileName; - JSC::ExecState* exec = d->currentFrame; - WTF::PassRefPtr<QScript::UStringSourceProviderWithFeedback> provider - = QScript::UStringSourceProviderWithFeedback::create(jscProgram, jscFileName, lineNumber, d); - intptr_t sourceId = provider->asID(); - JSC::SourceCode &source = rv.d->source; - source = JSC::SourceCode(provider, lineNumber); //after construction of SourceCode provider variable will be null. - - if (debugger) - debugger->evaluateStart(sourceId); - - exec->clearException(); - JSC::DynamicGlobalObjectScope dynamicGlobalObjectScope(exec, exec->scopeChain()->globalObject()); - - int errorLine; - JSC::UString errorMessage; - WTF::RefPtr<JSC::EvalNode> &evalNode = rv.d->evalNode; - evalNode = exec->globalData().parser->parse<JSC::EvalNode>(&exec->globalData(), exec->lexicalGlobalObject()->debugger(), exec, source, &errorLine, &errorMessage); - if (!evalNode) { - JSC::JSValue exceptionValue = JSC::Error::create(exec, JSC::SyntaxError, errorMessage, errorLine, source.provider()->asID(), source.provider()->url()); - exec->setException(exceptionValue); - - if (debugger) { - debugger->exceptionThrow(JSC::DebuggerCallFrame(exec, exceptionValue), sourceId, false); - debugger->evaluateStop(exceptionValue, sourceId); - } - - rv.d->hasException = true; - rv.d->exception = d->scriptValueFromJSCValue(exceptionValue); - } else if (debugger) { - debugger->evaluateStop(JSC::JSValue(), sourceId); - } - - return rv; -} - -QScriptValue QScriptEngine::evaluate(const QScriptProgram &program) -{ - Q_D(QScriptEngine); - - if (0 == program.d) - return QScriptValue(); - else if (program.d->hasException) - return program.d->exception; - else if (!program.d->evalNode) - return QScriptValue(); - - JSC::JSLock lock(false); // ### hmmm - QBoolBlocker inEval(d->inEval, true); - currentContext()->activationObject(); //force the creation of a context for native function; - - JSC::Debugger* debugger = d->originalGlobalObject()->debugger(); - - JSC::ExecState* exec = d->currentFrame; - - intptr_t sourceId = program.d->source.provider()->asID(); - - if (debugger) - debugger->evaluateStart(sourceId); - - exec->clearException(); - JSC::DynamicGlobalObjectScope dynamicGlobalObjectScope(exec, exec->scopeChain()->globalObject()); - - WTF::RefPtr<JSC::EvalNode> &evalNode = program.d->evalNode; - - JSC::EvalExecutable executable(exec, program.d->source); - executable.compile(exec, evalNode, exec->scopeChain()); - JSC::JSValue thisValue = d->thisForContext(exec); - JSC::JSObject* thisObject = (!thisValue || thisValue.isUndefinedOrNull()) ? exec->dynamicGlobalObject() : thisValue.toObject(exec); - JSC::JSValue exceptionValue; - d->timeoutChecker()->setShouldAbort(false); - if (d->processEventsInterval > 0) - d->timeoutChecker()->reset(); - JSC::JSValue result = exec->interpreter()->execute(&executable, exec, thisObject, exec->scopeChain(), &exceptionValue); - - if (d->timeoutChecker()->shouldAbort()) { - if (d->abortResult.isError()) - exec->setException(d->scriptValueToJSCValue(d->abortResult)); - - if (debugger) - debugger->evaluateStop(d->scriptValueToJSCValue(d->abortResult), sourceId); - - return d->abortResult; - } - - if (exceptionValue) { - exec->setException(exceptionValue); - - if (debugger) - debugger->evaluateStop(exceptionValue, sourceId); - - return d->scriptValueFromJSCValue(exceptionValue); - } - - if (debugger) - debugger->evaluateStop(result, sourceId); - - Q_ASSERT(!exec->hadException()); - return d->scriptValueFromJSCValue(result); -} /*! Evaluates \a program, using \a lineNumber as the base line number, @@ -2266,75 +2201,38 @@ QScriptValue QScriptEngine::evaluate(const QScriptProgram &program) QScriptValue QScriptEngine::evaluate(const QString &program, const QString &fileName, int lineNumber) { Q_D(QScriptEngine); - - JSC::JSLock lock(false); // ### hmmm - QBoolBlocker inEval(d->inEval, true); - currentContext()->activationObject(); //force the creation of a context for native function; - - JSC::Debugger* debugger = d->originalGlobalObject()->debugger(); - - JSC::UString jscProgram = program; - JSC::UString jscFileName = fileName; - JSC::ExecState* exec = d->currentFrame; WTF::PassRefPtr<QScript::UStringSourceProviderWithFeedback> provider - = QScript::UStringSourceProviderWithFeedback::create(jscProgram, jscFileName, lineNumber, d); + = QScript::UStringSourceProviderWithFeedback::create(program, fileName, lineNumber, d); intptr_t sourceId = provider->asID(); JSC::SourceCode source(provider, lineNumber); //after construction of SourceCode provider variable will be null. - if (debugger) - debugger->evaluateStart(sourceId); - - clearExceptions(); - JSC::DynamicGlobalObjectScope dynamicGlobalObjectScope(exec, exec->scopeChain()->globalObject()); - + JSC::ExecState* exec = d->currentFrame; JSC::EvalExecutable executable(exec, source); - JSC::JSObject* error = executable.compile(exec, exec->scopeChain()); - if (error) { - exec->setException(error); - - if (debugger) { - debugger->exceptionThrow(JSC::DebuggerCallFrame(exec, error), sourceId, false); - debugger->evaluateStop(error, sourceId); - } - - return d->scriptValueFromJSCValue(error); - } - - JSC::JSValue thisValue = d->thisForContext(exec); - JSC::JSObject* thisObject = (!thisValue || thisValue.isUndefinedOrNull()) ? exec->dynamicGlobalObject() : thisValue.toObject(exec); - JSC::JSValue exceptionValue; - d->timeoutChecker()->setShouldAbort(false); - if (d->processEventsInterval > 0) - d->timeoutChecker()->reset(); - JSC::JSValue result = exec->interpreter()->execute(&executable, exec, thisObject, exec->scopeChain(), &exceptionValue); - - if (d->timeoutChecker()->shouldAbort()) { - if (d->abortResult.isError()) - exec->setException(d->scriptValueToJSCValue(d->abortResult)); - - if (debugger) - debugger->evaluateStop(d->scriptValueToJSCValue(d->abortResult), sourceId); - - return d->abortResult; - } - - if (exceptionValue) { - exec->setException(exceptionValue); - - if (debugger) - debugger->evaluateStop(exceptionValue, sourceId); - - return d->scriptValueFromJSCValue(exceptionValue); - } + bool compile = true; + return d->scriptValueFromJSCValue(d->evaluateHelper(exec, sourceId, &executable, compile)); +} - if (debugger) - debugger->evaluateStop(result, sourceId); +/*! + \internal + \since 4.6 +*/ +QScriptValue QScriptEngine::evaluate(const QScriptProgram &program) +{ + Q_D(QScriptEngine); + QScriptProgramPrivate *program_d = QScriptProgramPrivate::get(program); + if (!program_d) + return QScriptValue(); - Q_ASSERT(!exec->hadException()); + JSC::ExecState* exec = d->currentFrame; + JSC::EvalExecutable *executable = program_d->executable(exec, d); + bool compile = !program_d->isCompiled; + JSC::JSValue result = d->evaluateHelper(exec, program_d->sourceId, + executable, compile); + if (compile) + program_d->isCompiled = true; return d->scriptValueFromJSCValue(result); } - /*! Returns the current context. @@ -3857,9 +3755,6 @@ QScriptValue QScriptEngine::objectById(qint64 id) const return const_cast<QScriptEnginePrivate*>(d)->scriptValueFromJSCValue((JSC::JSCell*)id); } - - - /*! \since 4.5 \class QScriptSyntaxCheckResult @@ -3988,51 +3883,4 @@ Q_AUTOTEST_EXPORT bool qt_script_isJITEnabled() } #endif -QScriptProgram::QScriptProgram() -: d(0) -{ -} - -QScriptProgram::~QScriptProgram() -{ - if (d) d->release(); -} - -QScriptProgram::QScriptProgram(const QScriptProgram &c) -: d(c.d) -{ - if (d) d->addref(); -} - -QScriptProgram &QScriptProgram::operator=(const QScriptProgram &c) -{ - if (c.d) c.d->addref(); - if (d) d->release(); - d = c.d; - return *this; -} - -bool QScriptProgram::isNull() const -{ - return d == 0; -} - -bool QScriptProgram::hasSyntaxError() const -{ - if (d) return d->hasException; - else return false; -} - -QScriptValue QScriptProgram::syntaxError() const -{ - if (d) return d->exception; - else return QScriptValue(); -} - -QString QScriptProgram::programSource() const -{ - if (d) return d->source.toString(); - else return QString(); -} - QT_END_NAMESPACE diff --git a/src/script/api/qscriptengine.h b/src/script/api/qscriptengine.h index cd86aca..2fc8afe 100644 --- a/src/script/api/qscriptengine.h +++ b/src/script/api/qscriptengine.h @@ -67,6 +67,7 @@ class QDateTime; class QScriptClass; class QScriptEngineAgent; class QScriptEnginePrivate; +class QScriptProgram; #ifndef QT_NO_QOBJECT @@ -120,29 +121,6 @@ private: friend class QScriptEnginePrivate; }; -class QScriptProgramPrivate; -class Q_SCRIPT_EXPORT QScriptProgram -{ -public: - QScriptProgram(); - QScriptProgram(const QScriptProgram &); - ~QScriptProgram(); - - QScriptProgram &operator=(const QScriptProgram &); - - bool isNull() const; - - bool hasSyntaxError() const; - QScriptValue syntaxError() const; - - QString programSource() const; - -private: - friend class QScriptEngine; - QScriptProgramPrivate *d; -}; - -class QScriptCode; class Q_SCRIPT_EXPORT QScriptEngine #ifndef QT_NO_QOBJECT : public QObject @@ -188,11 +166,10 @@ public: bool canEvaluate(const QString &program) const; static QScriptSyntaxCheckResult checkSyntax(const QString &program); - QScriptProgram compile(const QString &program, const QString &fileName = QString(), int lineNumber = 1); - QScriptValue evaluate(const QScriptProgram &); - QScriptValue evaluate(const QString &program, const QString &fileName = QString(), int lineNumber = 1); + QScriptValue evaluate(const QScriptProgram &program); + bool isEvaluating() const; void abortEvaluation(const QScriptValue &result = QScriptValue()); diff --git a/src/script/api/qscriptengine_p.h b/src/script/api/qscriptengine_p.h index 9fd1674..e7cdcda 100644 --- a/src/script/api/qscriptengine_p.h +++ b/src/script/api/qscriptengine_p.h @@ -70,6 +70,7 @@ namespace JSC { + class EvalExecutable; class ExecState; typedef ExecState CallFrame; class JSCell; @@ -211,6 +212,10 @@ public: const QByteArray &targetType, void **result); + JSC::JSValue evaluateHelper(JSC::ExecState *exec, intptr_t sourceId, + JSC::EvalExecutable *executable, + bool &compile); + QScript::QObjectData *qobjectData(QObject *object); void disposeQObject(QObject *object); void emitSignalHandlerException(); diff --git a/src/script/api/qscriptprogram.cpp b/src/script/api/qscriptprogram.cpp new file mode 100644 index 0000000..aff9817 --- /dev/null +++ b/src/script/api/qscriptprogram.cpp @@ -0,0 +1,219 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtScript module 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 <QtCore/qglobal.h> +#ifdef Q_WS_WIN +#define max max +#define min min +#endif + +#include "qscriptprogram.h" +#include "qscriptprogram_p.h" +#include "qscriptengine.h" +#include "qscriptengine_p.h" + +#include "Executable.h" + +QT_BEGIN_NAMESPACE + +/*! + \internal + + \since 4.6 + \class QScriptProgram + + \ingroup script + +*/ + +QScriptProgramPrivate::QScriptProgramPrivate(const QString &src, + const QString &fn, + int ln) + : sourceCode(src), fileName(fn), lineNumber(ln), + engine(0), _executable(0), sourceId(-1), isCompiled(false) +{ + ref = 0; +} + +QScriptProgramPrivate::~QScriptProgramPrivate() +{ + delete _executable; +} + +QScriptProgramPrivate *QScriptProgramPrivate::get(const QScriptProgram &q) +{ + return const_cast<QScriptProgramPrivate*>(q.d_func()); +} + +JSC::EvalExecutable *QScriptProgramPrivate::executable(JSC::ExecState *exec, + QScriptEnginePrivate *eng) +{ + if (_executable) { + if (eng == engine) + return _executable; + delete _executable; + } + WTF::PassRefPtr<QScript::UStringSourceProviderWithFeedback> provider + = QScript::UStringSourceProviderWithFeedback::create(sourceCode, fileName, lineNumber, eng); + sourceId = provider->asID(); + JSC::SourceCode source(provider, lineNumber); //after construction of SourceCode provider variable will be null. + _executable = new JSC::EvalExecutable(exec, source); + engine = eng; + isCompiled = false; + return _executable; +} + +/*! + Constructs a null QScriptProgram. +*/ +QScriptProgram::QScriptProgram() + : d_ptr(0) +{ +} + +/*! + Constructs a new QScriptProgram with the given \a sourceCode, \a + fileName and \a lineNumber. +*/ +QScriptProgram::QScriptProgram(const QString &sourceCode, + const QString fileName, + int lineNumber) + : d_ptr(new QScriptProgramPrivate(sourceCode, fileName, lineNumber)) +{ +} + +/*! + Constructs a new QScriptProgram that is a copy of \a other. +*/ +QScriptProgram::QScriptProgram(const QScriptProgram &other) + : d_ptr(other.d_ptr) +{ +} + +/*! + Destroys this QScriptProgram. +*/ +QScriptProgram::~QScriptProgram() +{ + Q_D(QScriptProgram); + // if (d->engine && (d->ref == 1)) + // d->engine->unregisterScriptProgram(d); +} + +/*! + Assigns the \a other value to this QScriptProgram. +*/ +QScriptProgram &QScriptProgram::operator=(const QScriptProgram &other) +{ + // if (d_func() && d_func()->engine && (d_func()->ref == 1)) + // d_func()->engine->unregisterScriptProgram(d_func()); + // } + d_ptr = other.d_ptr; + return *this; +} + +/*! + Returns true if this QScriptProgram is null; otherwise + returns false. +*/ +bool QScriptProgram::isNull() const +{ + Q_D(const QScriptProgram); + return (d == 0); +} + +/*! + Returns the source code of this program. +*/ +QString QScriptProgram::sourceCode() const +{ + Q_D(const QScriptProgram); + if (!d) + return QString(); + return d->sourceCode; +} + +/*! + Returns the filename associated with this program. +*/ +QString QScriptProgram::fileName() const +{ + Q_D(const QScriptProgram); + if (!d) + return QString(); + return d->fileName; +} + +/*! + Returns the line number associated with this program. +*/ +int QScriptProgram::lineNumber() const +{ + Q_D(const QScriptProgram); + if (!d) + return -1; + return d->lineNumber; +} + +/*! + Returns true if this QScriptProgram is equal to \a other; + otherwise returns false. +*/ +bool QScriptProgram::operator==(const QScriptProgram &other) const +{ + Q_D(const QScriptProgram); + if (d == other.d_func()) + return true; + return (sourceCode() == other.sourceCode()) + && (fileName() == other.fileName()) + && (lineNumber() == other.lineNumber()); +} + +/*! + Returns true if this QScriptProgram is not equal to \a other; + otherwise returns false. +*/ +bool QScriptProgram::operator!=(const QScriptProgram &other) const +{ + return !operator==(other); +} + +QT_END_NAMESPACE diff --git a/src/script/api/qscriptprogram.h b/src/script/api/qscriptprogram.h new file mode 100644 index 0000000..6ab56dc --- /dev/null +++ b/src/script/api/qscriptprogram.h @@ -0,0 +1,86 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtScript module 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$ +** +****************************************************************************/ + +#ifndef QSCRIPTPROGRAM_H +#define QSCRIPTPROGRAM_H + +#include <QtCore/qsharedpointer.h> + +#include <QtCore/qstring.h> + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Script) + +class QScriptProgramPrivate; +class Q_SCRIPT_EXPORT QScriptProgram +{ +public: + QScriptProgram(); + QScriptProgram(const QString &sourceCode, + const QString fileName = QString(), + int lineNumber = 1); + QScriptProgram(const QScriptProgram &other); + ~QScriptProgram(); + + QScriptProgram &operator=(const QScriptProgram &other); + + bool isNull() const; + + QString sourceCode() const; + QString fileName() const; + int lineNumber() const; + + bool operator==(const QScriptProgram &other) const; + bool operator!=(const QScriptProgram &other) const; + +private: + QExplicitlySharedDataPointer<QScriptProgramPrivate> d_ptr; + Q_DECLARE_PRIVATE(QScriptProgram) +}; + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif // QSCRIPTPROGRAM_H diff --git a/src/script/api/qscriptprogram_p.h b/src/script/api/qscriptprogram_p.h new file mode 100644 index 0000000..861ef32 --- /dev/null +++ b/src/script/api/qscriptprogram_p.h @@ -0,0 +1,95 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtScript module 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$ +** +****************************************************************************/ + +#ifndef QSCRIPTPROGRAM_P_H +#define QSCRIPTPROGRAM_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include <QtCore/qobjectdefs.h> + +namespace JSC +{ + class EvalExecutable; + class ExecState; +} + +QT_BEGIN_NAMESPACE + +class QScriptEnginePrivate; + +class QScriptProgramPrivate +{ +public: + QScriptProgramPrivate(const QString &sourceCode, + const QString &fileName, + int lineNumber); + ~QScriptProgramPrivate(); + + static QScriptProgramPrivate *get(const QScriptProgram &q); + + JSC::EvalExecutable *executable(JSC::ExecState *exec, + QScriptEnginePrivate *engine); + + QBasicAtomicInt ref; + + QString sourceCode; + QString fileName; + int lineNumber; + + QScriptEnginePrivate *engine; + JSC::EvalExecutable *_executable; + intptr_t sourceId; + bool isCompiled; +}; + +QT_END_NAMESPACE + +#endif diff --git a/tests/auto/declarative/qmldom/tst_qmldom.cpp b/tests/auto/declarative/qmldom/tst_qmldom.cpp index 77c13c3..8079a23 100644 --- a/tests/auto/declarative/qmldom/tst_qmldom.cpp +++ b/tests/auto/declarative/qmldom/tst_qmldom.cpp @@ -20,6 +20,7 @@ private slots: void loadImports(); void testValueSource(); + void testValueInterceptor(); private: QmlEngine engine; @@ -30,7 +31,6 @@ void tst_qmldom::loadSimple() { QByteArray qml = "import Qt 4.6\n" "Item {}"; - //QByteArray qml = "<Item/>"; QmlDomDocument document; QVERIFY(document.load(&engine, qml)); @@ -49,7 +49,6 @@ void tst_qmldom::loadProperties() { QByteArray qml = "import Qt 4.6\n" "Item { id : item; x : 300; visible : true }"; - //QByteArray qml = "<Item id='item' x='300' visible='true'/>"; QmlDomDocument document; QVERIFY(document.load(&engine, qml)); @@ -74,7 +73,6 @@ void tst_qmldom::loadChildObject() { QByteArray qml = "import Qt 4.6\n" "Item { Item {} }"; - //QByteArray qml = "<Item> <Item/> </Item>"; QmlDomDocument document; QVERIFY(document.load(&engine, qml)); @@ -148,6 +146,32 @@ void tst_qmldom::testValueSource() QVERIFY(sourceValue.toBinding().binding() == "Math.min(Math.max(-130, value*2.2 - 130), 133)"); } +void tst_qmldom::testValueInterceptor() +{ + QByteArray qml = "import Qt 4.6\n" + "Rectangle { height: Behavior { NumberAnimation { duration: 100 } } }"; + + QmlEngine freshEngine; + QmlDomDocument document; + QVERIFY(document.load(&freshEngine, qml)); + + QmlDomObject rootItem = document.rootObject(); + QVERIFY(rootItem.isValid()); + QmlDomProperty heightProperty = rootItem.properties().at(0); + QVERIFY(heightProperty.propertyName() == "height"); + QVERIFY(heightProperty.value().isValueInterceptor()); + + const QmlDomValueValueInterceptor valueInterceptor = heightProperty.value().toValueInterceptor(); + QmlDomObject valueInterceptorObject = valueInterceptor.object(); + QVERIFY(valueInterceptorObject.isValid()); + + QVERIFY(valueInterceptorObject.objectType() == "Qt/Behavior"); + + const QmlDomValue animationValue = valueInterceptorObject.property("animation").value(); + QVERIFY(!animationValue.isInvalid()); + QVERIFY(animationValue.isObject()); +} + void tst_qmldom::loadImports() { QByteArray qml = "import Qt 4.6\n" diff --git a/tests/auto/declarative/qmllanguage/data/alias.7.qml b/tests/auto/declarative/qmllanguage/data/alias.7.qml new file mode 100644 index 0000000..d3cf5fe --- /dev/null +++ b/tests/auto/declarative/qmllanguage/data/alias.7.qml @@ -0,0 +1,14 @@ +import Qt 4.6 + +Object { + property Object object + property alias aliasedObject: target.object + + object: Object { + id: target + + property Object object + object: Object {} + } +} + diff --git a/tests/auto/declarative/qmllanguage/data/invalidGroupedProperty.1.errors.txt b/tests/auto/declarative/qmllanguage/data/invalidGroupedProperty.1.errors.txt new file mode 100644 index 0000000..7c00ce4 --- /dev/null +++ b/tests/auto/declarative/qmllanguage/data/invalidGroupedProperty.1.errors.txt @@ -0,0 +1 @@ +5:5:Invalid property access diff --git a/tests/auto/declarative/qmllanguage/data/invalidGroupedProperty.1.qml b/tests/auto/declarative/qmllanguage/data/invalidGroupedProperty.1.qml new file mode 100644 index 0000000..5e95c48 --- /dev/null +++ b/tests/auto/declarative/qmllanguage/data/invalidGroupedProperty.1.qml @@ -0,0 +1,6 @@ +import Qt 4.6 + +Object { + property var o; + o.blah: 10 +} diff --git a/tests/auto/declarative/qmllanguage/data/invalidGroupedProperty.2.errors.txt b/tests/auto/declarative/qmllanguage/data/invalidGroupedProperty.2.errors.txt new file mode 100644 index 0000000..7c00ce4 --- /dev/null +++ b/tests/auto/declarative/qmllanguage/data/invalidGroupedProperty.2.errors.txt @@ -0,0 +1 @@ +5:5:Invalid property access diff --git a/tests/auto/declarative/qmllanguage/data/invalidGroupedProperty.2.qml b/tests/auto/declarative/qmllanguage/data/invalidGroupedProperty.2.qml new file mode 100644 index 0000000..b11d34c --- /dev/null +++ b/tests/auto/declarative/qmllanguage/data/invalidGroupedProperty.2.qml @@ -0,0 +1,7 @@ +import Qt 4.6 + +Object { + property int o; + o.blah: 10 +} + diff --git a/tests/auto/declarative/qmllanguage/data/qmlAttachedPropertiesObjectMethod.1.qml b/tests/auto/declarative/qmllanguage/data/qmlAttachedPropertiesObjectMethod.1.qml new file mode 100644 index 0000000..99a9746 --- /dev/null +++ b/tests/auto/declarative/qmllanguage/data/qmlAttachedPropertiesObjectMethod.1.qml @@ -0,0 +1,5 @@ +import Test 1.0 +import Qt 4.6 +Object { +} + diff --git a/tests/auto/declarative/qmllanguage/data/qmlAttachedPropertiesObjectMethod.2.qml b/tests/auto/declarative/qmllanguage/data/qmlAttachedPropertiesObjectMethod.2.qml new file mode 100644 index 0000000..8179dbd --- /dev/null +++ b/tests/auto/declarative/qmllanguage/data/qmlAttachedPropertiesObjectMethod.2.qml @@ -0,0 +1,6 @@ +import Test 1.0 +import Qt 4.6 +Object { + MyQmlObject.value: 10 +} + diff --git a/tests/auto/declarative/qmllanguage/tst_qmllanguage.cpp b/tests/auto/declarative/qmllanguage/tst_qmllanguage.cpp index d51bbcc..2746e98 100644 --- a/tests/auto/declarative/qmllanguage/tst_qmllanguage.cpp +++ b/tests/auto/declarative/qmllanguage/tst_qmllanguage.cpp @@ -74,6 +74,8 @@ private slots: void importsOrder_data(); void importsOrder(); + void qmlAttachedPropertiesObjectMethod(); + // regression tests for crashes void crash1(); @@ -180,7 +182,6 @@ void tst_qmllanguage::errors_data() QTest::newRow("invalidID.5") << "invalidID.5.qml" << "invalidID.5.errors.txt" << false; QTest::newRow("invalidID.6") << "invalidID.6.qml" << "invalidID.6.errors.txt" << false; - QTest::newRow("unsupportedProperty") << "unsupportedProperty.qml" << "unsupportedProperty.errors.txt" << false; QTest::newRow("nullDotProperty") << "nullDotProperty.qml" << "nullDotProperty.errors.txt" << true; QTest::newRow("fakeDotProperty") << "fakeDotProperty.qml" << "fakeDotProperty.errors.txt" << false; @@ -191,12 +192,16 @@ void tst_qmllanguage::errors_data() QTest::newRow("failingComponent") << "failingComponentTest.qml" << "failingComponent.errors.txt" << false; QTest::newRow("missingSignal") << "missingSignal.qml" << "missingSignal.errors.txt" << false; QTest::newRow("finalOverride") << "finalOverride.qml" << "finalOverride.errors.txt" << false; + QTest::newRow("customParserIdNotAllowed") << "customParserIdNotAllowed.qml" << "customParserIdNotAllowed.errors.txt" << false; + QTest::newRow("invalidGroupedProperty.1") << "invalidGroupedProperty.1.qml" << "invalidGroupedProperty.1.errors.txt" << false; + QTest::newRow("invalidGroupedProperty.2") << "invalidGroupedProperty.2.qml" << "invalidGroupedProperty.2.errors.txt" << false; QTest::newRow("importNamespaceConflict") << "importNamespaceConflict.qml" << "importNamespaceConflict.errors.txt" << false; QTest::newRow("importVersionMissing (builtin)") << "importVersionMissingBuiltIn.qml" << "importVersionMissingBuiltIn.errors.txt" << false; QTest::newRow("importVersionMissing (installed)") << "importVersionMissingInstalled.qml" << "importVersionMissingInstalled.errors.txt" << false; - QTest::newRow("customParserIdNotAllowed") << "customParserIdNotAllowed.qml" << "customParserIdNotAllowed.errors.txt" << false; + + } void tst_qmllanguage::errors() @@ -690,6 +695,33 @@ void tst_qmllanguage::aliasProperties() QCOMPARE(object->property("a").toInt(), 1923); } + + // Ptr Alias Cleanup - check that aliases to ptr types return 0 + // if the object aliased to is removed + { + QmlComponent component(&engine, TEST_FILE("alias.7.qml")); + VERIFY_ERRORS(0); + + QObject *object = component.create(); + QVERIFY(object != 0); + + QObject *object1 = qvariant_cast<QObject *>(object->property("object")); + QVERIFY(object1 != 0); + QObject *object2 = qvariant_cast<QObject *>(object1->property("object")); + QVERIFY(object2 != 0); + + QObject *alias = qvariant_cast<QObject *>(object->property("aliasedObject")); + QVERIFY(alias == object2); + + delete object1; + + QObject *alias2 = object; // "Random" start value + int status = -1; + void *a[] = { &alias2, 0, &status }; + QMetaObject::metacall(object, QMetaObject::ReadProperty, + object->metaObject()->indexOfProperty("aliasedObject"), a); + QVERIFY(alias2 == 0); + } } // Test that the root element in a composite type can be a Component @@ -1009,6 +1041,34 @@ void tst_qmllanguage::importsOrder() testType(qml,type); } +void tst_qmllanguage::qmlAttachedPropertiesObjectMethod() +{ + QObject object; + + QCOMPARE(qmlAttachedPropertiesObject<MyQmlObject>(&object, false), (QObject *)0); + QCOMPARE(qmlAttachedPropertiesObject<MyQmlObject>(&object, true), (QObject *)0); + + { + QmlComponent component(&engine, TEST_FILE("qmlAttachedPropertiesObjectMethod.1.qml")); + VERIFY_ERRORS(0); + QObject *object = component.create(); + QVERIFY(object != 0); + + QCOMPARE(qmlAttachedPropertiesObject<MyQmlObject>(object, false), (QObject *)0); + QVERIFY(qmlAttachedPropertiesObject<MyQmlObject>(object, true) != 0); + } + + { + QmlComponent component(&engine, TEST_FILE("qmlAttachedPropertiesObjectMethod.2.qml")); + VERIFY_ERRORS(0); + QObject *object = component.create(); + QVERIFY(object != 0); + + QVERIFY(qmlAttachedPropertiesObject<MyQmlObject>(object, false) != 0); + QVERIFY(qmlAttachedPropertiesObject<MyQmlObject>(object, true) != 0); + } +} + void tst_qmllanguage::crash1() { QmlComponent component(&engine, "Component {}"); diff --git a/tests/auto/qgraphicstransform/tst_qgraphicstransform.cpp b/tests/auto/qgraphicstransform/tst_qgraphicstransform.cpp index eb5c099..d8ab06e 100644 --- a/tests/auto/qgraphicstransform/tst_qgraphicstransform.cpp +++ b/tests/auto/qgraphicstransform/tst_qgraphicstransform.cpp @@ -59,6 +59,8 @@ private slots: void rotation(); void rotation3d_data(); void rotation3d(); + void rotation3dArbitraryAxis_data(); + void rotation3dArbitraryAxis(); }; @@ -88,7 +90,7 @@ static QTransform transform2D(const QGraphicsTransform& t) { QMatrix4x4 m; t.applyTo(&m); - return m.toTransform(0); + return m.toTransform(); } void tst_QGraphicsTransform::scale() @@ -255,6 +257,19 @@ void tst_QGraphicsTransform::rotation3d() QVERIFY(fuzzyCompare(transform2D(rotation), expected)); + // Check that "rotation" produces the 4x4 form of the 3x3 matrix. + // i.e. third row and column are 0 0 1 0. + t.setIdentity(); + rotation.applyTo(&t); + QMatrix4x4 r(expected); + if (sizeof(qreal) == sizeof(float) && angle == 268) { + // This test fails, on only this angle, when qreal == float + // because the deg2rad value in QTransform is not accurate + // enough to match what QMatrix4x4 is doing. + } else { + QVERIFY(qFuzzyCompare(t, r)); + } + //now let's check that a null vector will not change the transform rotation.setAxis(QVector3D(0, 0, 0)); rotation.setOrigin(QVector3D(10, 10, 0)); @@ -276,6 +291,58 @@ void tst_QGraphicsTransform::rotation3d() QVERIFY(transform2D(rotation).isIdentity()); } +void tst_QGraphicsTransform::rotation3dArbitraryAxis_data() +{ + QTest::addColumn<QVector3D>("axis"); + QTest::addColumn<qreal>("angle"); + + QVector3D axis1 = QVector3D(1.0f, 1.0f, 1.0f); + QVector3D axis2 = QVector3D(2.0f, -3.0f, 0.5f); + QVector3D axis3 = QVector3D(-2.0f, 0.0f, -0.5f); + QVector3D axis4 = QVector3D(0.0001f, 0.0001f, 0.0001f); + QVector3D axis5 = QVector3D(0.01f, 0.01f, 0.01f); + + for (int angle = 0; angle <= 360; angle++) { + QTest::newRow("test rotation on (1, 1, 1)") << axis1 << qreal(angle); + QTest::newRow("test rotation on (2, -3, .5)") << axis2 << qreal(angle); + QTest::newRow("test rotation on (-2, 0, -.5)") << axis3 << qreal(angle); + QTest::newRow("test rotation on (.0001, .0001, .0001)") << axis4 << qreal(angle); + QTest::newRow("test rotation on (.01, .01, .01)") << axis5 << qreal(angle); + } +} + +void tst_QGraphicsTransform::rotation3dArbitraryAxis() +{ + QFETCH(QVector3D, axis); + QFETCH(qreal, angle); + + QGraphicsRotation rotation; + rotation.setAxis(axis); + + QMatrix4x4 t; + rotation.applyTo(&t); + + QVERIFY(t.isIdentity()); + QVERIFY(transform2D(rotation).isIdentity()); + + rotation.setAngle(angle); + + // Compute the expected answer using QMatrix4x4 and a projection. + // These two steps are performed in one hit by QGraphicsRotation. + QMatrix4x4 exp; + exp.rotate(angle, axis); + QTransform expected = exp.toTransform(1024.0f); + + QVERIFY(fuzzyCompare(transform2D(rotation), expected)); + + // Check that "rotation" produces the 4x4 form of the 3x3 matrix. + // i.e. third row and column are 0 0 1 0. + t.setIdentity(); + rotation.applyTo(&t); + QMatrix4x4 r(expected); + QVERIFY(qFuzzyCompare(t, r)); +} + QTEST_MAIN(tst_QGraphicsTransform) #include "tst_qgraphicstransform.moc" diff --git a/tests/auto/qscriptengine/tst_qscriptengine.cpp b/tests/auto/qscriptengine/tst_qscriptengine.cpp index 25ee00f..062cbfa 100644 --- a/tests/auto/qscriptengine/tst_qscriptengine.cpp +++ b/tests/auto/qscriptengine/tst_qscriptengine.cpp @@ -44,6 +44,7 @@ #include <qscriptengine.h> #include <qscriptengineagent.h> +#include <qscriptprogram.h> #include <qscriptvalueiterator.h> #include <qgraphicsitem.h> #include <qstandarditemmodel.h> @@ -151,6 +152,7 @@ private slots: void installTranslatorFunctions(); void functionScopes(); void nativeFunctionScopes(); + void evaluateProgram(); void qRegExpInport_data(); void qRegExpInport(); @@ -4289,6 +4291,110 @@ void tst_QScriptEngine::nativeFunctionScopes() } } +void tst_QScriptEngine::evaluateProgram() +{ + QScriptEngine eng; + + { + QString code("1 + 2"); + QString fileName("hello.js"); + int lineNumber(123); + QScriptProgram program(code, fileName, lineNumber); + QVERIFY(!program.isNull()); + QCOMPARE(program.sourceCode(), code); + QCOMPARE(program.fileName(), fileName); + QCOMPARE(program.lineNumber(), lineNumber); + + QScriptValue expected = eng.evaluate(code); + for (int x = 0; x < 10; ++x) { + QScriptValue ret = eng.evaluate(program); + QVERIFY(ret.equals(expected)); + } + } + + // Program that accesses variable in the scope + { + QScriptProgram program("a"); + QVERIFY(!program.isNull()); + { + QScriptValue ret = eng.evaluate(program); + QVERIFY(ret.isError()); + QCOMPARE(ret.toString(), QString::fromLatin1("ReferenceError: Can't find variable: a")); + } + + QScriptValue obj = eng.newObject(); + obj.setProperty("a", 123); + QScriptContext *ctx = eng.currentContext(); + ctx->pushScope(obj); + { + QScriptValue ret = eng.evaluate(program); + QVERIFY(!ret.isError()); + QVERIFY(ret.equals(obj.property("a"))); + } + + obj.setProperty("a", QScriptValue()); + { + QScriptValue ret = eng.evaluate(program); + QVERIFY(ret.isError()); + } + + QScriptValue obj2 = eng.newObject(); + obj2.setProperty("a", 456); + ctx->pushScope(obj2); + { + QScriptValue ret = eng.evaluate(program); + QVERIFY(!ret.isError()); + QVERIFY(ret.equals(obj2.property("a"))); + } + + ctx->popScope(); + } + + // Program that creates closure + { + QScriptProgram program("(function() { var count = 0; return function() { return count++; }; })"); + QVERIFY(!program.isNull()); + QScriptValue createCounter = eng.evaluate(program); + QVERIFY(createCounter.isFunction()); + QScriptValue counter = createCounter.call(); + QVERIFY(counter.isFunction()); + { + QScriptValue ret = counter.call(); + QVERIFY(ret.isNumber()); + } + QScriptValue counter2 = createCounter.call(); + QVERIFY(counter2.isFunction()); + QVERIFY(!counter2.equals(counter)); + { + QScriptValue ret = counter2.call(); + QVERIFY(ret.isNumber()); + } + } + + // Same program run in different engines + { + QString code("1 + 2"); + QScriptProgram program(code); + QVERIFY(!program.isNull()); + double expected = eng.evaluate(program).toNumber(); + for (int x = 0; x < 2; ++x) { + QScriptEngine eng2; + for (int y = 0; y < 2; ++y) { + double ret = eng2.evaluate(program).toNumber(); + QCOMPARE(ret, expected); + } + } + } + + // No program + { + QScriptProgram program; + QVERIFY(program.isNull()); + QScriptValue ret = eng.evaluate(program); + QVERIFY(!ret.isValid()); + } +} + static QRegExp minimal(QRegExp r) { r.setMinimal(true); return r; } void tst_QScriptEngine::qRegExpInport_data() diff --git a/tests/auto/qscriptengineagent/tst_qscriptengineagent.cpp b/tests/auto/qscriptengineagent/tst_qscriptengineagent.cpp index 82c8ccd..81f0ee5 100644 --- a/tests/auto/qscriptengineagent/tst_qscriptengineagent.cpp +++ b/tests/auto/qscriptengineagent/tst_qscriptengineagent.cpp @@ -44,6 +44,7 @@ #include <QtScript/qscriptengineagent.h> #include <QtScript/qscriptengine.h> +#include <QtScript/qscriptprogram.h> #include <qscriptvalueiterator.h> //TESTED_CLASS= @@ -109,6 +110,9 @@ private slots: void extension_invoctaion(); void extension(); void isEvaluatingInExtension(); + void evaluateProgram(); + void evaluateProgram_SyntaxError(); + void evaluateNullProgram(); void hasUncaughtException(); private: @@ -2183,6 +2187,89 @@ void tst_QScriptEngineAgent::isEvaluatingInExtension() QVERIFY(spy->wasEvaluating); } +void tst_QScriptEngineAgent::evaluateProgram() +{ + QScriptEngine eng; + QScriptProgram program("1 + 2", "foo.js", 123); + ScriptEngineSpy *spy = new ScriptEngineSpy(&eng); + qint64 scriptId = -1; + for (int x = 0; x < 10; ++x) { + spy->clear(); + (void)eng.evaluate(program); + QCOMPARE(spy->count(), (x == 0) ? 4 : 3); + + if (x == 0) { + // script is only loaded on first execution + QCOMPARE(spy->at(0).type, ScriptEngineEvent::ScriptLoad); + scriptId = spy->at(0).scriptId; + QVERIFY(scriptId != -1); + QCOMPARE(spy->at(0).script, program.sourceCode()); + QCOMPARE(spy->at(0).fileName, program.fileName()); + QCOMPARE(spy->at(0).lineNumber, program.lineNumber()); + spy->removeFirst(); + } + + QCOMPARE(spy->at(0).type, ScriptEngineEvent::FunctionEntry); // evaluate() + QCOMPARE(spy->at(0).scriptId, scriptId); + + QCOMPARE(spy->at(1).type, ScriptEngineEvent::PositionChange); + QCOMPARE(spy->at(1).scriptId, scriptId); + QCOMPARE(spy->at(1).lineNumber, program.lineNumber()); + + QCOMPARE(spy->at(2).type, ScriptEngineEvent::FunctionExit); // evaluate() + QCOMPARE(spy->at(2).scriptId, scriptId); + QVERIFY(spy->at(2).value.isNumber()); + QCOMPARE(spy->at(2).value.toNumber(), qsreal(3)); + } +} + +void tst_QScriptEngineAgent::evaluateProgram_SyntaxError() +{ + QScriptEngine eng; + QScriptProgram program("this is not valid syntax", "foo.js", 123); + ScriptEngineSpy *spy = new ScriptEngineSpy(&eng); + qint64 scriptId = -1; + for (int x = 0; x < 10; ++x) { + spy->clear(); + (void)eng.evaluate(program); + QCOMPARE(spy->count(), (x == 0) ? 8 : 7); + + if (x == 0) { + // script is only loaded on first execution + QCOMPARE(spy->at(0).type, ScriptEngineEvent::ScriptLoad); + scriptId = spy->at(0).scriptId; + QVERIFY(scriptId != -1); + QCOMPARE(spy->at(0).script, program.sourceCode()); + QCOMPARE(spy->at(0).fileName, program.fileName()); + QCOMPARE(spy->at(0).lineNumber, program.lineNumber()); + spy->removeFirst(); + } + + QCOMPARE(spy->at(0).type, ScriptEngineEvent::FunctionEntry); // evaluate() + QCOMPARE(spy->at(0).scriptId, scriptId); + + QCOMPARE(spy->at(1).type, ScriptEngineEvent::ContextPush); // SyntaxError constructor + QCOMPARE(spy->at(2).type, ScriptEngineEvent::FunctionEntry); // SyntaxError constructor + QCOMPARE(spy->at(3).type, ScriptEngineEvent::FunctionExit); // SyntaxError constructor + QCOMPARE(spy->at(4).type, ScriptEngineEvent::ContextPop); // SyntaxError constructor + + QCOMPARE(spy->at(5).type, ScriptEngineEvent::ExceptionThrow); + QVERIFY(spy->at(5).value.isError()); + QCOMPARE(spy->at(5).value.toString(), QString::fromLatin1("SyntaxError: Parse error")); + + QCOMPARE(spy->at(6).type, ScriptEngineEvent::FunctionExit); // evaluate() + QCOMPARE(spy->at(6).scriptId, scriptId); + } +} + +void tst_QScriptEngineAgent::evaluateNullProgram() +{ + QScriptEngine eng; + ScriptEngineSpy *spy = new ScriptEngineSpy(&eng); + (void)eng.evaluate(QScriptProgram()); + QCOMPARE(spy->count(), 0); +} + class NewSpy :public QScriptEngineAgent { bool m_result; @@ -2219,6 +2306,5 @@ void tst_QScriptEngineAgent::hasUncaughtException() QVERIFY2(spy->isPass(), "At least one of a functionExit event should set hasUncaughtException flag."); } - QTEST_MAIN(tst_QScriptEngineAgent) #include "tst_qscriptengineagent.moc" diff --git a/tests/benchmarks/qscriptengine/tst_qscriptengine.cpp b/tests/benchmarks/qscriptengine/tst_qscriptengine.cpp index 4f011c4..8d5f6e6 100644 --- a/tests/benchmarks/qscriptengine/tst_qscriptengine.cpp +++ b/tests/benchmarks/qscriptengine/tst_qscriptengine.cpp @@ -60,6 +60,8 @@ private slots: void constructor(); void evaluate_data(); void evaluate(); + void evaluateProgram_data(); + void evaluateProgram(); void connectAndDisconnect(); void newObject(); void newQObject(); @@ -153,6 +155,22 @@ void tst_QScriptEngine::connectAndDisconnect() } } +void tst_QScriptEngine::evaluateProgram_data() +{ + evaluate_data(); +} + +void tst_QScriptEngine::evaluateProgram() +{ + QFETCH(QString, code); + QScriptEngine engine; + QScriptProgram program(code); + + QBENCHMARK { + (void)engine.evaluate(program); + } +} + void tst_QScriptEngine::newObject() { QScriptEngine engine; @@ -241,6 +259,5 @@ void tst_QScriptEngine::nativeCall() } } - QTEST_MAIN(tst_QScriptEngine) #include "tst_qscriptengine.moc" diff --git a/tools/qmlviewer/qmlviewer.cpp b/tools/qmlviewer/qmlviewer.cpp index 60fa13a..3aeb0da 100644 --- a/tools/qmlviewer/qmlviewer.cpp +++ b/tools/qmlviewer/qmlviewer.cpp @@ -310,6 +310,7 @@ QmlViewer::QmlViewer(QWidget *parent, Qt::WindowFlags flags) canvas->setFocus(); QObject::connect(canvas, SIGNAL(sceneResized(QSize)), this, SLOT(sceneResized(QSize))); + QObject::connect(canvas, SIGNAL(initialSize(QSize)), this, SLOT(adjustSizeSlot())); QObject::connect(canvas, SIGNAL(errors(QList<QmlError>)), this, SLOT(executeErrors())); if (!(flags & Qt::FramelessWindowHint)) @@ -335,6 +336,11 @@ QmlViewer::QmlViewer(QWidget *parent, Qt::WindowFlags flags) recordTimer.setRepeating(true); } +void QmlViewer::adjustSizeSlot() +{ + adjustSize(); +} + QMenuBar *QmlViewer::menuBar() const { if (!mb) @@ -363,7 +369,7 @@ void QmlViewer::createMenu(QMenuBar *menu, QMenu *flatmenu) QMenu *recordMenu = flatmenu ? flatmenu : menu->addMenu(tr("&Recording")); - QAction *snapshotAction = new QAction(tr("&Take Snapsot\tF3"), parent); + QAction *snapshotAction = new QAction(tr("&Take Snapshot\tF3"), parent); connect(snapshotAction, SIGNAL(triggered()), this, SLOT(takeSnapShot())); recordMenu->addAction(snapshotAction); @@ -600,14 +606,17 @@ void QmlViewer::addLibraryPath(const QString& lib) void QmlViewer::reload() { - openQml(currentFileName); + openQml(currentFileOrUrl); } void QmlViewer::open() { - QString fileName = QFileDialog::getOpenFileName(this, tr("Open QML file"), currentFileName, tr("QML Files (*.qml)")); - if (!fileName.isEmpty()) - openQml(fileName); + QString cur = canvas->url().toLocalFile(); + QString fileName = QFileDialog::getOpenFileName(this, tr("Open QML file"), cur, tr("QML Files (*.qml)")); + if (!fileName.isEmpty()) { + QFileInfo fi(fileName); + openQml(fi.absoluteFilePath()); + } } void QmlViewer::executeErrors() @@ -615,55 +624,63 @@ void QmlViewer::executeErrors() if (tester) tester->executefailure(); } -void QmlViewer::openQml(const QString& fileName) +void QmlViewer::openQml(const QString& file_or_url) { - setWindowTitle(tr("%1 - Qt Declarative UI Viewer").arg(fileName)); + currentFileOrUrl = file_or_url; + + QUrl url; + QFileInfo fi(file_or_url); + if (fi.exists()) + url = QUrl::fromLocalFile(fi.absoluteFilePath()); + else + url = QUrl(file_or_url); + setWindowTitle(tr("%1 - Qt Declarative UI Viewer").arg(file_or_url)); if (!m_script.isEmpty()) tester = new QFxTester(m_script, m_scriptOptions, canvas); canvas->reset(); - currentFileName = fileName; - QUrl url(fileName); - QFileInfo fi(fileName); - if (fi.exists()) { - if (fi.suffix().toLower() != QLatin1String("qml")) { - qWarning() << "qmlviewer cannot open non-QML file" << fileName; - return; - } + QString fileName = url.toLocalFile(); + if (!fileName.isEmpty()) { + QFileInfo fi(fileName); + if (fi.exists()) { + if (fi.suffix().toLower() != QLatin1String("qml")) { + qWarning() << "qmlviewer cannot open non-QML file" << fileName; + return; + } - url = QUrl::fromLocalFile(fi.absoluteFilePath()); - QmlContext *ctxt = canvas->rootContext(); - QDir dir(fi.path()+"/dummydata", "*.qml"); - QStringList list = dir.entryList(); - for (int i = 0; i < list.size(); ++i) { - QString qml = list.at(i); - QFile f(dir.filePath(qml)); - f.open(QIODevice::ReadOnly); - QByteArray data = f.readAll(); - QmlComponent comp(canvas->engine()); - comp.setData(data, QUrl()); - QObject *dummyData = comp.create(); - - if(comp.isError()) { - QList<QmlError> errors = comp.errors(); - foreach (const QmlError &error, errors) { - qWarning() << error; + QmlContext *ctxt = canvas->rootContext(); + QDir dir(fi.path()+"/dummydata", "*.qml"); + QStringList list = dir.entryList(); + for (int i = 0; i < list.size(); ++i) { + QString qml = list.at(i); + QFile f(dir.filePath(qml)); + f.open(QIODevice::ReadOnly); + QByteArray data = f.readAll(); + QmlComponent comp(canvas->engine()); + comp.setData(data, QUrl()); + QObject *dummyData = comp.create(); + + if(comp.isError()) { + QList<QmlError> errors = comp.errors(); + foreach (const QmlError &error, errors) { + qWarning() << error; + } + if (tester) tester->executefailure(); } - if (tester) tester->executefailure(); - } - if (dummyData) { - qWarning() << "Loaded dummy data:" << dir.filePath(qml); - qml.truncate(qml.length()-4); - ctxt->setContextProperty(qml, dummyData); - dummyData->setParent(this); + if (dummyData) { + qWarning() << "Loaded dummy data:" << dir.filePath(qml); + qml.truncate(qml.length()-4); + ctxt->setContextProperty(qml, dummyData); + dummyData->setParent(this); + } } + } else { + qWarning() << "qmlviewer cannot find file:" << fileName; + return; } - } else { - qWarning() << "qmlviewer cannot find file:" << fileName; - return; } canvas->setUrl(url); @@ -677,7 +694,7 @@ void QmlViewer::openQml(const QString& fileName) canvas->updateGeometry(); if (mb) mb->updateGeometry(); - resize(sizeHint()); + adjustSize(); } else { if (scaleSkin) canvas->resize(canvas->sizeHint()); diff --git a/tools/qmlviewer/qmlviewer.h b/tools/qmlviewer/qmlviewer.h index 7f9dca0..e1f53f9 100644 --- a/tools/qmlviewer/qmlviewer.h +++ b/tools/qmlviewer/qmlviewer.h @@ -63,7 +63,7 @@ public: public slots: void sceneResized(QSize size); - void openQml(const QString& fileName); + void openQml(const QString&); void open(); void reload(); void takeSnapShot(); @@ -88,15 +88,16 @@ private slots: void chooseRecordingOptions(); void pickRecordingFile(); void setScaleSkin(); + void adjustSizeSlot(); private: void setupProxy(); QString getVideoFileName(); - QString currentFileName; PreviewDeviceSkin *skin; QSize skinscreensize; QmlView *canvas; + QString currentFileOrUrl; QmlTimer recordTimer; QString frame_fmt; QImage frame; |