diff options
author | Martin Jones <martin.jones@nokia.com> | 2010-04-08 23:54:12 (GMT) |
---|---|---|
committer | Martin Jones <martin.jones@nokia.com> | 2010-04-08 23:54:12 (GMT) |
commit | bb07e7d2f4f3e8940ebcc12334b4b723e450d374 (patch) | |
tree | dc826dd6f3a1638a9ccaf014d2cb28d28f00a7b3 | |
parent | 8f1cb90d810fcff31447b4fbcef59b1bf289aa67 (diff) | |
parent | a7d29653c73347f90d8c9628321b9ec7cadb9ce7 (diff) | |
download | Qt-bb07e7d2f4f3e8940ebcc12334b4b723e450d374.zip Qt-bb07e7d2f4f3e8940ebcc12334b4b723e450d374.tar.gz Qt-bb07e7d2f4f3e8940ebcc12334b4b723e450d374.tar.bz2 |
Merge branch '4.7' of scm.dev.nokia.troll.no:qt/qt-qml into 4.7
108 files changed, 1308 insertions, 552 deletions
diff --git a/demos/declarative/minehunt/minehunt.qml b/demos/declarative/minehunt/minehunt.qml index 299e722..4e384c0 100644 --- a/demos/declarative/minehunt/minehunt.qml +++ b/demos/declarative/minehunt/minehunt.qml @@ -141,4 +141,11 @@ Item { MouseArea { anchors.fill: parent; onPressed: reset() } } + Text { + anchors.fill: parent; wrap: true + text: "Minehunt will not run properly if the C++ plugin is not compiled.\nPlease see README." + color: "white"; font.bold: true; font.pixelSize: 14 + visible: tiles == undefined + } + } diff --git a/demos/declarative/photoviewer/photoviewer.qml b/demos/declarative/photoviewer/photoviewer.qml index 569e1ba..4094294 100644 --- a/demos/declarative/photoviewer/photoviewer.qml +++ b/demos/declarative/photoviewer/photoviewer.qml @@ -1,5 +1,5 @@ import Qt 4.7 -import "PhotoViewerCore" 1.0 +import "PhotoViewerCore" Rectangle { id: mainWindow diff --git a/demos/declarative/samegame/SamegameCore/BoomBlock.qml b/demos/declarative/samegame/SamegameCore/BoomBlock.qml index 838b346..db43182 100644 --- a/demos/declarative/samegame/SamegameCore/BoomBlock.qml +++ b/demos/declarative/samegame/SamegameCore/BoomBlock.qml @@ -8,8 +8,8 @@ Item { id:block property int targetX: 0 property int targetY: 0 - SpringFollow on x { enabled: spawned; source: targetX; spring: 2; damping: 0.2 } - SpringFollow on y { source: targetY; spring: 2; damping: 0.2 } + SpringFollow on x { enabled: spawned; to: targetX; spring: 2; damping: 0.2 } + SpringFollow on y { to: targetY; spring: 2; damping: 0.2 } Image { id: img source: { diff --git a/demos/declarative/samegame/samegame.qml b/demos/declarative/samegame/samegame.qml index 9c3e26d..94f5c24 100644 --- a/demos/declarative/samegame/samegame.qml +++ b/demos/declarative/samegame/samegame.qml @@ -1,5 +1,5 @@ import Qt 4.7 -import "SamegameCore" 1.0 +import "SamegameCore" import "SamegameCore/samegame.js" as Logic Rectangle { diff --git a/demos/declarative/twitter/TwitterCore/AuthView.qml b/demos/declarative/twitter/TwitterCore/AuthView.qml index 9d9341a..7986e74 100644 --- a/demos/declarative/twitter/TwitterCore/AuthView.qml +++ b/demos/declarative/twitter/TwitterCore/AuthView.qml @@ -24,7 +24,8 @@ Item { font.pixelSize: 16; font.bold: true color: "#151515"; selectionColor: "green" - KeyNavigation.down: passIn + KeyNavigation.tab: passIn + KeyNavigation.backtab: guest focus: true } } @@ -49,8 +50,8 @@ Item { font.pixelSize: 16; font.bold: true color: "#151515"; selectionColor: "green" - KeyNavigation.down: login - KeyNavigation.up: nameIn + KeyNavigation.tab: login + KeyNavigation.backtab: nameIn } } } @@ -69,7 +70,8 @@ Item { } text: "Log in" KeyNavigation.right: guest - KeyNavigation.up: passIn + KeyNavigation.tab: guest + KeyNavigation.backtab: passIn Keys.onReturnPressed: login.doLogin(); Keys.onSelectPressed: login.doLogin(); Keys.onSpacePressed: login.doLogin(); @@ -88,7 +90,8 @@ Item { } text: "Guest" KeyNavigation.left: login - KeyNavigation.up: passIn + KeyNavigation.tab: nameIn + KeyNavigation.backtab: login Keys.onReturnPressed: guest.doGuest(); Keys.onSelectPressed: guest.doGuest(); Keys.onSpacePressed: guest.doGuest(); diff --git a/doc/src/declarative/modules.qdoc b/doc/src/declarative/modules.qdoc index 68e58fb..0e332d4 100644 --- a/doc/src/declarative/modules.qdoc +++ b/doc/src/declarative/modules.qdoc @@ -86,7 +86,7 @@ The second exception is explained in more detail in the section below on Namespa \section2 The Import Path Installed modules are searched for on the import path. -The \c -L option to the \l {Qt Declarative UI Runtime}{qml} runtime adds paths to the import path. +The \c -I option to the \l {Qt Declarative UI Runtime}{qml} runtime adds paths to the import path. From C++, the path is available via \l QDeclarativeEngine::importPathList() and can be prepended to using \l QDeclarativeEngine::addImportPath(). @@ -114,19 +114,7 @@ Installed files do not need to import the module of which they are a part, as th to the other QML files in the module as relative (local) files, but if the module is imported from a remote location, those files must nevertheless be listed in the \c qmldir file. Types which you do not wish to export to users of your module -may be marked with the \c internal keyword: - -\code -internal <TypeName> <File> -\endcode - -\c plugin <Name> [<Path>] lines are used to add \l{QDeclarativeExtensionPlugin}{QML C++ plugins} -to the module. <Name> is the -name of the library. <Path> is an optional argument specifying the full path to the directory -containing the plugin file; if it is omitted then the directory is assumed to be the same as -the directory of the \c qmldir file. Note that <Name> is not usually the same as the file name -of the plugin binary, which is platform dependent; e.g. the library MyAppTypes would produce -a libMyAppTypes.so on Linux and MyAppTypes.dll on Windows. +may be marked with the \c internal keyword: \c internal <TypeName> <File>. The same type can be provided by different files in different versions, in which case later earlier versions (eg. 1.2) must precede earlier versions (eg. 1.0), @@ -141,6 +129,23 @@ of installed software, since a versioned import \e only imports types for that v leaving other identifiers available, even if the actual installed version might otherwise provide those identifiers. +\c plugin <Name> [<Path>] lines are used to add \l{QDeclarativeExtensionPlugin}{QML C++ plugins} +to the module. + +<Name> is the name of the library. It is usually not the same as the file name +of the plugin binary, which is platform dependent; e.g. the library MyAppTypes would produce +a libMyAppTypes.so on Linux and MyAppTypes.dll on Windows. +By default the engine searches for the plugin library in the directory containing the \c qmldir +file. The \c -P option to the \l {Qt Declarative UI Runtime}{qml} runtime adds paths to the +plugin search path. +From C++, the path is available via \l QDeclarativeEngine::pluginPathList() and can be prepended to +using \l QDeclarativeEngine::addPluginPath(). + +<Path> is an optional argument specifying either an absolute path to the directory containing the +plugin file, or a relative path from the directory containing the \c qmldir file to the directory +containing the plugin file. + + \section2 Namespaces - Named Imports When importing content it by default imports types into the global namespace. diff --git a/doc/src/deployment/qt-conf.qdoc b/doc/src/deployment/qt-conf.qdoc index b195889..298f539 100644 --- a/doc/src/deployment/qt-conf.qdoc +++ b/doc/src/deployment/qt-conf.qdoc @@ -87,6 +87,7 @@ \row \o Libraries \o \c lib \row \o Binaries \o \c bin \row \o Plugins \o \c plugins + \row \o Imports \o \c imports \row \o Data \o \c . \row \o Translations \o \c translations \row \o Settings \o \c . diff --git a/doc/src/snippets/declarative/listview/highlight.qml b/doc/src/snippets/declarative/listview/highlight.qml index 6a9d215..fe5cc53 100644 --- a/doc/src/snippets/declarative/listview/highlight.qml +++ b/doc/src/snippets/declarative/listview/highlight.qml @@ -45,7 +45,7 @@ Rectangle { width: 180; height: 40 color: "lightsteelblue"; radius: 5 SpringFollow on y { - source: list.currentItem.y + to: list.currentItem.y spring: 3 damping: 0.2 } diff --git a/examples/declarative/aspectratio/face_fit_animated.qml b/examples/declarative/aspectratio/face_fit_animated.qml index 97f4791..63fc9c6 100644 --- a/examples/declarative/aspectratio/face_fit_animated.qml +++ b/examples/declarative/aspectratio/face_fit_animated.qml @@ -19,8 +19,8 @@ Rectangle { x: (parent.width-width*scale)/2 y: (parent.height-height*scale)/2 SpringFollow on scale { - source: Math.max(Math.min(face.parent.width/face.width*1.333,face.parent.height/face.height), - Math.min(face.parent.width/face.width,face.parent.height/face.height*1.333)) + to: Math.max(Math.min(face.parent.width/face.width*1.333,face.parent.height/face.height), + Math.min(face.parent.width/face.width,face.parent.height/face.height*1.333)) spring: 1 damping: 0.05 } diff --git a/examples/declarative/clocks/content/Clock.qml b/examples/declarative/clocks/content/Clock.qml index a315ccc..c853174 100644 --- a/examples/declarative/clocks/content/Clock.qml +++ b/examples/declarative/clocks/content/Clock.qml @@ -36,7 +36,7 @@ Item { origin.x: 7.5; origin.y: 73; angle: 0 SpringFollow on angle { spring: 2; damping: 0.2; modulus: 360 - source: (clock.hours * 30) + (clock.minutes * 0.5) + to: (clock.hours * 30) + (clock.minutes * 0.5) } } } @@ -50,7 +50,7 @@ Item { origin.x: 6.5; origin.y: 83; angle: 0 SpringFollow on angle { spring: 2; damping: 0.2; modulus: 360 - source: clock.minutes * 6 + to: clock.minutes * 6 } } } @@ -64,7 +64,7 @@ Item { origin.x: 2.5; origin.y: 80; angle: 0 SpringFollow on angle { spring: 5; damping: 0.25; modulus: 360 - source: clock.seconds * 6 + to: clock.seconds * 6 } } } diff --git a/examples/declarative/dial/content/Dial.qml b/examples/declarative/dial/content/Dial.qml index 7fd638a..f9ab3e3 100644 --- a/examples/declarative/dial/content/Dial.qml +++ b/examples/declarative/dial/content/Dial.qml @@ -29,7 +29,7 @@ Item { SpringFollow on angle { spring: 1.4 damping: .15 - source: Math.min(Math.max(-130, root.value*2.6 - 130), 133) + to: Math.min(Math.max(-130, root.value*2.6 - 130), 133) } } } diff --git a/examples/declarative/focus/Core/qmldir b/examples/declarative/focus/Core/qmldir index 0460d9c..e25d63c 100644 --- a/examples/declarative/focus/Core/qmldir +++ b/examples/declarative/focus/Core/qmldir @@ -1,4 +1,4 @@ ContextMenu ContextMenu.qml GridMenu GridMenu.qml -ListViews Listviews.qml +ListViews ListViews.qml ListViewDelegate ListViewDelegate.qml diff --git a/examples/declarative/focus/focus.qml b/examples/declarative/focus/focus.qml index b9a11a6..d9b6549 100644 --- a/examples/declarative/focus/focus.qml +++ b/examples/declarative/focus/focus.qml @@ -1,5 +1,5 @@ import Qt 4.7 -import "Core" 1.0 +import "Core" Rectangle { id: window; width: 800; height: 480; color: "#3E606F" diff --git a/examples/declarative/listview/highlight.qml b/examples/declarative/listview/highlight.qml index 5493f99..2b54dd8 100644 --- a/examples/declarative/listview/highlight.qml +++ b/examples/declarative/listview/highlight.qml @@ -44,7 +44,7 @@ Rectangle { id: petHighlight Rectangle { width: 200; height: 50; color: "#FFFF88" - SpringFollow on y { source: list1.currentItem.y; spring: 3; damping: 0.1 } + SpringFollow on y { to: list1.currentItem.y; spring: 3; damping: 0.1 } } } ListView { diff --git a/examples/declarative/plugins/com/nokia/TimeExample/Clock.qml b/examples/declarative/plugins/com/nokia/TimeExample/Clock.qml index 3ebbeab..ce1dd69 100644 --- a/examples/declarative/plugins/com/nokia/TimeExample/Clock.qml +++ b/examples/declarative/plugins/com/nokia/TimeExample/Clock.qml @@ -20,7 +20,7 @@ Rectangle { origin.x: 7.5; origin.y: 73; angle: 0 SpringFollow on angle { spring: 2; damping: 0.2; modulus: 360 - source: (clock.hours * 30) + (clock.minutes * 0.5) + to: (clock.hours * 30) + (clock.minutes * 0.5) } } } @@ -34,7 +34,7 @@ Rectangle { origin.x: 6.5; origin.y: 83; angle: 0 SpringFollow on angle { spring: 2; damping: 0.2; modulus: 360 - source: clock.minutes * 6 + to: clock.minutes * 6 } } } diff --git a/examples/declarative/tic-tac-toe/content/tic-tac-toe.js b/examples/declarative/tic-tac-toe/content/tic-tac-toe.js new file mode 100644 index 0000000..f8d6d9f --- /dev/null +++ b/examples/declarative/tic-tac-toe/content/tic-tac-toe.js @@ -0,0 +1,145 @@ +function winner(board) +{ + for (var i=0; i<3; ++i) { + if (board.children[i].state!="" + && board.children[i].state==board.children[i+3].state + && board.children[i].state==board.children[i+6].state) + return true + + if (board.children[i*3].state!="" + && board.children[i*3].state==board.children[i*3+1].state + && board.children[i*3].state==board.children[i*3+2].state) + return true + } + + if (board.children[0].state!="" + && board.children[0].state==board.children[4].state!="" + && board.children[0].state==board.children[8].state!="") + return true + + if (board.children[2].state!="" + && board.children[2].state==board.children[4].state!="" + && board.children[2].state==board.children[6].state!="") + return true + + return false +} + +function restart() +{ + // No moves left - start again + for (var i=0; i<9; ++i) + board.children[i].state = "" +} + +function makeMove(pos,player) +{ + board.children[pos].state = player + if (winner(board)) { + win(player + " wins") + return true + } else { + return false + } +} + +function computerTurn() +{ + var r = Math.random(); + if(r < game.difficulty){ + smartAI(); + }else{ + randAI(); + } +} + +function smartAI() +{ + function boardCopy(a){ + var ret = new Object; + ret.children = new Array(9); + for(var i = 0; i<9; i++){ + ret.children[i] = new Object; + ret.children[i].state = a.children[i].state; + } + return ret; + } + for(var i=0; i<9; i++){ + var simpleBoard = boardCopy(board); + if (board.children[i].state == "") { + simpleBoard.children[i].state = "O"; + if(winner(simpleBoard)){ + makeMove(i,"O") + return + } + } + } + for(var i=0; i<9; i++){ + var simpleBoard = boardCopy(board); + if (board.children[i].state == "") { + simpleBoard.children[i].state = "X"; + if(winner(simpleBoard)){ + makeMove(i,"O") + return + } + } + } + function thwart(a,b,c){//If they are at a, try b or c + if (board.children[a].state == "X") { + if (board.children[b].state == "") { + makeMove(b,"O") + return true + }else if (board.children[c].state == "") { + makeMove(c,"O") + return true + } + } + return false; + } + if(thwart(4,0,2)) return; + if(thwart(0,4,3)) return; + if(thwart(2,4,1)) return; + if(thwart(6,4,7)) return; + if(thwart(8,4,5)) return; + if(thwart(1,4,2)) return; + if(thwart(3,4,0)) return; + if(thwart(5,4,8)) return; + if(thwart(7,4,6)) return; + for(var i =0; i<9; i++){//Backup + if (board.children[i].state == "") { + makeMove(i,"O") + return + } + } + restart(); +} + +function randAI() +{ + var open = 0; + for (var i=0; i<9; ++i) + if (board.children[i].state == "") { + open += 1; + } + if(open == 0){ + restart(); + return; + } + var openA = new Array(open);//JS doesn't have lists I can append to (i think) + var acc = 0; + for (var i=0; i<9; ++i) + if (board.children[i].state == "") { + openA[acc] = i; + acc += 1; + } + var choice = openA[Math.floor(Math.random() * open)]; + makeMove(choice, "O"); +} + +function win(s) +{ + msg.text = s + msg.opacity = 1 + endtimer.running = true +} + diff --git a/examples/declarative/tic-tac-toe/tic-tac-toe.qml b/examples/declarative/tic-tac-toe/tic-tac-toe.qml index 1857a28..ca66a46 100644 --- a/examples/declarative/tic-tac-toe/tic-tac-toe.qml +++ b/examples/declarative/tic-tac-toe/tic-tac-toe.qml @@ -1,6 +1,6 @@ import Qt 4.7 import "content" -import "tic-tac-toe.js" as Logic +import "content/tic-tac-toe.js" as Logic Item { id: game diff --git a/examples/declarative/tutorials/samegame/samegame1/Button.qml b/examples/declarative/tutorials/samegame/samegame1/Button.qml index 8eee2ad..6798c32 100644 --- a/examples/declarative/tutorials/samegame/samegame1/Button.qml +++ b/examples/declarative/tutorials/samegame/samegame1/Button.qml @@ -8,12 +8,12 @@ Rectangle { property string text: "Button" color: activePalette.button; smooth: true - width: txtItem.width + 20; height: txtItem.height + 6 + width: buttonLabel.width + 20; height: buttonLabel.height + 6 border.width: 1; border.color: Qt.darker(activePalette.button); radius: 8; gradient: Gradient { GradientStop { - id: topGrad; position: 0.0 + position: 0.0 color: if (mouseArea.pressed) { activePalette.dark } else { activePalette.light } } GradientStop { position: 1.0; color: activePalette.button } } @@ -21,7 +21,7 @@ Rectangle { MouseArea { id: mouseArea; anchors.fill: parent; onClicked: container.clicked() } Text { - id: txtItem; text: container.text; anchors.centerIn: container; color: activePalette.buttonText + id: buttonLabel; text: container.text; anchors.centerIn: container; color: activePalette.buttonText } } //![0] diff --git a/examples/declarative/tutorials/samegame/samegame1/samegame.qml b/examples/declarative/tutorials/samegame/samegame1/samegame.qml index 23a25f3..ae881ba 100644 --- a/examples/declarative/tutorials/samegame/samegame1/samegame.qml +++ b/examples/declarative/tutorials/samegame/samegame1/samegame.qml @@ -24,7 +24,7 @@ Rectangle { anchors.bottom: screen.bottom Button { - id: btnA; text: "New Game"; onClicked: console.log("Starting a new game..."); + text: "New Game"; onClicked: console.log("Starting a new game..."); anchors.left: parent.left; anchors.leftMargin: 3 anchors.verticalCenter: parent.verticalCenter } diff --git a/examples/declarative/tutorials/samegame/samegame2/Button.qml b/examples/declarative/tutorials/samegame/samegame2/Button.qml index 64a8a5a..04d1d1f 100644 --- a/examples/declarative/tutorials/samegame/samegame2/Button.qml +++ b/examples/declarative/tutorials/samegame/samegame2/Button.qml @@ -7,12 +7,12 @@ Rectangle { property string text: "Button" color: activePalette.button; smooth: true - width: txtItem.width + 20; height: txtItem.height + 6 + width: buttonLabel.width + 20; height: buttonLabel.height + 6 border.width: 1; border.color: Qt.darker(activePalette.button); radius: 8; gradient: Gradient { GradientStop { - id: topGrad; position: 0.0 + position: 0.0 color: if (mouseArea.pressed) { activePalette.dark } else { activePalette.light } } GradientStop { position: 1.0; color: activePalette.button } } @@ -20,6 +20,6 @@ Rectangle { MouseArea { id: mouseArea; anchors.fill: parent; onClicked: container.clicked() } Text { - id: txtItem; text: container.text; anchors.centerIn: container; color: activePalette.buttonText + id: buttonLabel; text: container.text; anchors.centerIn: container; color: activePalette.buttonText } } diff --git a/examples/declarative/tutorials/samegame/samegame2/samegame.js b/examples/declarative/tutorials/samegame/samegame2/samegame.js index 0ec3a8b..d7cbd8d 100644 --- a/examples/declarative/tutorials/samegame/samegame2/samegame.js +++ b/examples/declarative/tutorials/samegame/samegame2/samegame.js @@ -1,16 +1,16 @@ //![0] //Note that X/Y referred to here are in game coordinates -var maxX = 10;//Nums are for tileSize 40 -var maxY = 15; +var maxColumn = 10;//Nums are for tileSize 40 +var maxRow = 15; var tileSize = 40; -var maxIndex = maxX*maxY; +var maxIndex = maxColumn*maxRow; var board = new Array(maxIndex); var tileSrc = "Block.qml"; var component; //Index function used instead of a 2D array -function index(xIdx,yIdx) { - return xIdx + (yIdx * maxX); +function index(column,row) { + return column + (row * maxColumn); } function initBoard() @@ -22,21 +22,21 @@ function initBoard() } //Calculate board size - maxX = Math.floor(background.width/tileSize); - maxY = Math.floor(background.height/tileSize); - maxIndex = maxY*maxX; + maxColumn = Math.floor(background.width/tileSize); + maxRow = Math.floor(background.height/tileSize); + maxIndex = maxRow*maxColumn; //Initialize Board board = new Array(maxIndex); - for(var xIdx=0; xIdx<maxX; xIdx++){ - for(var yIdx=0; yIdx<maxY; yIdx++){ - board[index(xIdx,yIdx)] = null; - createBlock(xIdx,yIdx); + for(var column=0; column<maxColumn; column++){ + for(var row=0; row<maxRow; row++){ + board[index(column,row)] = null; + createBlock(column,row); } } } -function createBlock(xIdx,yIdx){ +function createBlock(column,row){ if(component==null) component = createComponent(tileSrc); @@ -52,11 +52,11 @@ function createBlock(xIdx,yIdx){ return false; } dynamicObject.parent = background; - dynamicObject.x = xIdx*tileSize; - dynamicObject.y = yIdx*tileSize; + dynamicObject.x = column*tileSize; + dynamicObject.y = row*tileSize; dynamicObject.width = tileSize; dynamicObject.height = tileSize; - board[index(xIdx,yIdx)] = dynamicObject; + board[index(column,row)] = dynamicObject; }else{//isError or isLoading print("error loading block component"); print(component.errorsString()); diff --git a/examples/declarative/tutorials/samegame/samegame2/samegame.qml b/examples/declarative/tutorials/samegame/samegame2/samegame.qml index a8a58ba..d98d383 100644 --- a/examples/declarative/tutorials/samegame/samegame2/samegame.qml +++ b/examples/declarative/tutorials/samegame/samegame2/samegame.qml @@ -27,7 +27,7 @@ Rectangle { //![1] Button { - id: btnA; text: "New Game"; onClicked: SameGame.initBoard(); + text: "New Game"; onClicked: SameGame.initBoard(); anchors.left: parent.left; anchors.leftMargin: 3 anchors.verticalCenter: parent.verticalCenter } diff --git a/examples/declarative/tutorials/samegame/samegame3/Button.qml b/examples/declarative/tutorials/samegame/samegame3/Button.qml index 64a8a5a..04d1d1f 100644 --- a/examples/declarative/tutorials/samegame/samegame3/Button.qml +++ b/examples/declarative/tutorials/samegame/samegame3/Button.qml @@ -7,12 +7,12 @@ Rectangle { property string text: "Button" color: activePalette.button; smooth: true - width: txtItem.width + 20; height: txtItem.height + 6 + width: buttonLabel.width + 20; height: buttonLabel.height + 6 border.width: 1; border.color: Qt.darker(activePalette.button); radius: 8; gradient: Gradient { GradientStop { - id: topGrad; position: 0.0 + position: 0.0 color: if (mouseArea.pressed) { activePalette.dark } else { activePalette.light } } GradientStop { position: 1.0; color: activePalette.button } } @@ -20,6 +20,6 @@ Rectangle { MouseArea { id: mouseArea; anchors.fill: parent; onClicked: container.clicked() } Text { - id: txtItem; text: container.text; anchors.centerIn: container; color: activePalette.buttonText + id: buttonLabel; text: container.text; anchors.centerIn: container; color: activePalette.buttonText } } diff --git a/examples/declarative/tutorials/samegame/samegame3/Dialog.qml b/examples/declarative/tutorials/samegame/samegame3/Dialog.qml index 69bae7c..6c358d6 100644 --- a/examples/declarative/tutorials/samegame/samegame3/Dialog.qml +++ b/examples/declarative/tutorials/samegame/samegame3/Dialog.qml @@ -8,16 +8,16 @@ Rectangle { page.opacity = 0; } function show(txt) { - myText.text = txt; + dialogText.text = txt; page.opacity = 1; } signal closed(); - color: "white"; border.width: 1; width: myText.width + 20; height: 60; + color: "white"; border.width: 1; width: dialogText.width + 20; height: 60; opacity: 0 Behavior on opacity { NumberAnimation { duration: 1000 } } - Text { id: myText; anchors.centerIn: parent; text: "Hello World!" } - MouseArea { id: mouseArea; anchors.fill: parent; onClicked: forceClose(); } + Text { id: dialogText; anchors.centerIn: parent; text: "Hello World!" } + MouseArea { anchors.fill: parent; onClicked: forceClose(); } } //![0] diff --git a/examples/declarative/tutorials/samegame/samegame3/samegame.js b/examples/declarative/tutorials/samegame/samegame3/samegame.js index 33449fa..432e88f 100644 --- a/examples/declarative/tutorials/samegame/samegame3/samegame.js +++ b/examples/declarative/tutorials/samegame/samegame3/samegame.js @@ -1,23 +1,23 @@ /* This script file handles the game logic */ //Note that X/Y referred to here are in game coordinates -var maxX = 10;//Nums are for tileSize 40 -var maxY = 15; -var maxIndex = maxX*maxY; +var maxColumn = 10;//Nums are for tileSize 40 +var maxRow = 15; +var maxIndex = maxColumn*maxRow; var board = new Array(maxIndex); var tileSrc = "Block.qml"; var component; //Index function used instead of a 2D array -function index(xIdx,yIdx) { - return xIdx + (yIdx * maxX); +function index(column,row) { + return column + (row * maxColumn); } function initBoard() { //Calculate board size - maxX = Math.floor(gameCanvas.width/gameCanvas.tileSize); - maxY = Math.floor(gameCanvas.height/gameCanvas.tileSize); - maxIndex = maxY*maxX; + maxColumn = Math.floor(gameCanvas.width/gameCanvas.tileSize); + maxRow = Math.floor(gameCanvas.height/gameCanvas.tileSize); + maxIndex = maxRow*maxColumn; //Close dialogs dialog.forceClose(); @@ -25,15 +25,15 @@ function initBoard() //Initialize Board board = new Array(maxIndex); gameCanvas.score = 0; - for(var xIdx=0; xIdx<maxX; xIdx++){ - for(var yIdx=0; yIdx<maxY; yIdx++){ - board[index(xIdx,yIdx)] = null; - createBlock(xIdx,yIdx); + for(var column=0; column<maxColumn; column++){ + for(var row=0; row<maxRow; row++){ + board[index(column,row)] = null; + createBlock(column,row); } } } -function createBlock(xIdx,yIdx){ +function createBlock(column,row){ if(component==null) component = createComponent(tileSrc); @@ -50,11 +50,11 @@ function createBlock(xIdx,yIdx){ } dynamicObject.type = Math.floor(Math.random() * 3); dynamicObject.parent = gameCanvas; - dynamicObject.x = xIdx*gameCanvas.tileSize; - dynamicObject.y = yIdx*gameCanvas.tileSize; + dynamicObject.x = column*gameCanvas.tileSize; + dynamicObject.y = row*gameCanvas.tileSize; dynamicObject.width = gameCanvas.tileSize; dynamicObject.height = gameCanvas.tileSize; - board[index(xIdx,yIdx)] = dynamicObject; + board[index(column,row)] = dynamicObject; }else{//isError or isLoading print("error loading block component"); print(component.errorsString()); @@ -69,14 +69,14 @@ var floodBoard;//Set to 1 if the floodFill reaches off that node //![1] function handleClick(x,y) { - var xIdx = Math.floor(x/gameCanvas.tileSize); - var yIdx = Math.floor(y/gameCanvas.tileSize); - if(xIdx >= maxX || xIdx < 0 || yIdx >= maxY || yIdx < 0) + var column = Math.floor(x/gameCanvas.tileSize); + var row = Math.floor(y/gameCanvas.tileSize); + if(column >= maxColumn || column < 0 || row >= maxRow || row < 0) return; - if(board[index(xIdx, yIdx)] == null) + if(board[index(column, row)] == null) return; //If it's a valid tile, remove it and all connected (does nothing if it's not connected) - floodFill(xIdx,yIdx, -1); + floodFill(column,row, -1); if(fillFound <= 0) return; gameCanvas.score += (fillFound - 1) * (fillFound - 1); @@ -85,67 +85,67 @@ function handleClick(x,y) } //![1] -function floodFill(xIdx,yIdx,type) +function floodFill(column,row,type) { - if(board[index(xIdx, yIdx)] == null) + if(board[index(column, row)] == null) return; var first = false; if(type == -1){ first = true; - type = board[index(xIdx,yIdx)].type; + type = board[index(column,row)].type; //Flood fill initialization fillFound = 0; floodBoard = new Array(maxIndex); } - if(xIdx >= maxX || xIdx < 0 || yIdx >= maxY || yIdx < 0) + if(column >= maxColumn || column < 0 || row >= maxRow || row < 0) return; - if(floodBoard[index(xIdx, yIdx)] == 1 || (!first && type != board[index(xIdx,yIdx)].type)) + if(floodBoard[index(column, row)] == 1 || (!first && type != board[index(column,row)].type)) return; - floodBoard[index(xIdx, yIdx)] = 1; - floodFill(xIdx+1,yIdx,type); - floodFill(xIdx-1,yIdx,type); - floodFill(xIdx,yIdx+1,type); - floodFill(xIdx,yIdx-1,type); + floodBoard[index(column, row)] = 1; + floodFill(column+1,row,type); + floodFill(column-1,row,type); + floodFill(column,row+1,type); + floodFill(column,row-1,type); if(first==true && fillFound == 0) return;//Can't remove single tiles - board[index(xIdx,yIdx)].opacity = 0; - board[index(xIdx,yIdx)] = null; + board[index(column,row)].opacity = 0; + board[index(column,row)] = null; fillFound += 1; } function shuffleDown() { //Fall down - for(var xIdx=0; xIdx<maxX; xIdx++){ + for(var column=0; column<maxColumn; column++){ var fallDist = 0; - for(var yIdx=maxY-1; yIdx>=0; yIdx--){ - if(board[index(xIdx,yIdx)] == null){ + for(var row=maxRow-1; row>=0; row--){ + if(board[index(column,row)] == null){ fallDist += 1; }else{ if(fallDist > 0){ - var obj = board[index(xIdx,yIdx)]; + var obj = board[index(column,row)]; obj.y += fallDist * gameCanvas.tileSize; - board[index(xIdx,yIdx+fallDist)] = obj; - board[index(xIdx,yIdx)] = null; + board[index(column,row+fallDist)] = obj; + board[index(column,row)] = null; } } } } //Fall to the left var fallDist = 0; - for(var xIdx=0; xIdx<maxX; xIdx++){ - if(board[index(xIdx, maxY - 1)] == null){ + for(var column=0; column<maxColumn; column++){ + if(board[index(column, maxRow - 1)] == null){ fallDist += 1; }else{ if(fallDist > 0){ - for(var yIdx=0; yIdx<maxY; yIdx++){ - var obj = board[index(xIdx,yIdx)]; + for(var row=0; row<maxRow; row++){ + var obj = board[index(column,row)]; if(obj == null) continue; obj.x -= fallDist * gameCanvas.tileSize; - board[index(xIdx-fallDist,yIdx)] = obj; - board[index(xIdx,yIdx)] = null; + board[index(column-fallDist,row)] = obj; + board[index(column,row)] = null; } } } @@ -157,27 +157,27 @@ function victoryCheck() { //awards bonuses for no tiles left var deservesBonus = true; - for(var xIdx=maxX-1; xIdx>=0; xIdx--) - if(board[index(xIdx, maxY - 1)] != null) + for(var column=maxColumn-1; column>=0; column--) + if(board[index(column, maxRow - 1)] != null) deservesBonus = false; if(deservesBonus) gameCanvas.score += 500; //Checks for game over - if(deservesBonus || !(floodMoveCheck(0,maxY-1, -1))) + if(deservesBonus || !(floodMoveCheck(0,maxRow-1, -1))) dialog.show("Game Over. Your score is " + gameCanvas.score); } //![2] //only floods up and right, to see if it can find adjacent same-typed tiles -function floodMoveCheck(xIdx, yIdx, type) +function floodMoveCheck(column, row, type) { - if(xIdx >= maxX || xIdx < 0 || yIdx >= maxY || yIdx < 0) + if(column >= maxColumn || column < 0 || row >= maxRow || row < 0) return false; - if(board[index(xIdx, yIdx)] == null) + if(board[index(column, row)] == null) return false; - var myType = board[index(xIdx, yIdx)].type; + var myType = board[index(column, row)].type; if(type == myType) return true; - return floodMoveCheck(xIdx + 1, yIdx, myType) || - floodMoveCheck(xIdx, yIdx - 1, board[index(xIdx,yIdx)].type); + return floodMoveCheck(column + 1, row, myType) || + floodMoveCheck(column, row - 1, board[index(column,row)].type); } diff --git a/examples/declarative/tutorials/samegame/samegame3/samegame.qml b/examples/declarative/tutorials/samegame/samegame3/samegame.qml index cd9dca5..9623932 100644 --- a/examples/declarative/tutorials/samegame/samegame3/samegame.qml +++ b/examples/declarative/tutorials/samegame/samegame3/samegame.qml @@ -45,7 +45,7 @@ Rectangle { anchors.bottom: screen.bottom Button { - id: btnA; text: "New Game"; onClicked: SameGame.initBoard(); + text: "New Game"; onClicked: SameGame.initBoard(); anchors.left: parent.left; anchors.leftMargin: 3 anchors.verticalCenter: parent.verticalCenter } diff --git a/examples/declarative/tutorials/samegame/samegame4/content/BoomBlock.qml b/examples/declarative/tutorials/samegame/samegame4/content/BoomBlock.qml index b598b3f..243df75 100644 --- a/examples/declarative/tutorials/samegame/samegame4/content/BoomBlock.qml +++ b/examples/declarative/tutorials/samegame/samegame4/content/BoomBlock.qml @@ -9,8 +9,8 @@ Item { id:block property int targetX: 0 property int targetY: 0 - SpringFollow on x { source: targetX; spring: 2; damping: 0.2; enabled: spawned } - SpringFollow on y { source: targetY; spring: 2; damping: 0.2 } + SpringFollow on x { to: targetX; spring: 2; damping: 0.2; enabled: spawned } + SpringFollow on y { to: targetY; spring: 2; damping: 0.2 } //![1] //![2] diff --git a/examples/declarative/tutorials/samegame/samegame4/content/Button.qml b/examples/declarative/tutorials/samegame/samegame4/content/Button.qml index 64a8a5a..04d1d1f 100644 --- a/examples/declarative/tutorials/samegame/samegame4/content/Button.qml +++ b/examples/declarative/tutorials/samegame/samegame4/content/Button.qml @@ -7,12 +7,12 @@ Rectangle { property string text: "Button" color: activePalette.button; smooth: true - width: txtItem.width + 20; height: txtItem.height + 6 + width: buttonLabel.width + 20; height: buttonLabel.height + 6 border.width: 1; border.color: Qt.darker(activePalette.button); radius: 8; gradient: Gradient { GradientStop { - id: topGrad; position: 0.0 + position: 0.0 color: if (mouseArea.pressed) { activePalette.dark } else { activePalette.light } } GradientStop { position: 1.0; color: activePalette.button } } @@ -20,6 +20,6 @@ Rectangle { MouseArea { id: mouseArea; anchors.fill: parent; onClicked: container.clicked() } Text { - id: txtItem; text: container.text; anchors.centerIn: container; color: activePalette.buttonText + id: buttonLabel; text: container.text; anchors.centerIn: container; color: activePalette.buttonText } } diff --git a/examples/declarative/tutorials/samegame/samegame4/content/Dialog.qml b/examples/declarative/tutorials/samegame/samegame4/content/Dialog.qml index 49fd5f6..0716bb3 100644 --- a/examples/declarative/tutorials/samegame/samegame4/content/Dialog.qml +++ b/examples/declarative/tutorials/samegame/samegame4/content/Dialog.qml @@ -7,15 +7,15 @@ Rectangle { page.opacity = 0; } function show(txt) { - myText.text = txt; + dialogText.text = txt; page.opacity = 1; } signal closed(); - color: "white"; border.width: 1; width: myText.width + 20; height: 60; + color: "white"; border.width: 1; width: dialogText.width + 20; height: 60; opacity: 0 Behavior on opacity { NumberAnimation { duration: 1000 } } - Text { id: myText; anchors.centerIn: parent; text: "Hello World!" } - MouseArea { id: mouseArea; anchors.fill: parent; onClicked: forceClose(); } + Text { id: dialogText; anchors.centerIn: parent; text: "Hello World!" } + MouseArea { anchors.fill: parent; onClicked: forceClose(); } } diff --git a/examples/declarative/tutorials/samegame/samegame4/content/samegame.js b/examples/declarative/tutorials/samegame/samegame4/content/samegame.js index 2a0d718..a905f7d 100755 --- a/examples/declarative/tutorials/samegame/samegame4/content/samegame.js +++ b/examples/declarative/tutorials/samegame/samegame4/content/samegame.js @@ -1,8 +1,8 @@ /* This script file handles the game logic */ //Note that X/Y referred to here are in game coordinates -var maxX = 10;//Nums are for gameCanvas.tileSize 40 -var maxY = 15; -var maxIndex = maxX*maxY; +var maxColumn = 10;//Nums are for gameCanvas.tileSize 40 +var maxRow = 15; +var maxIndex = maxColumn*maxRow; var board = new Array(maxIndex); var tileSrc = "content/BoomBlock.qml"; //var scoresURL = "http://qtfx-nokia.trolltech.com.au/samegame/scores.php"; @@ -11,8 +11,8 @@ var timer; var component = createComponent(tileSrc); //Index function used instead of a 2D array -function index(xIdx,yIdx) { - return xIdx + (yIdx * maxX); +function index(column,row) { + return column + (row * maxColumn); } function timeStr(msecs) { @@ -22,11 +22,6 @@ function timeStr(msecs) { return ret; } -function getTileSize() -{ - return tileSize; -} - function initBoard() { for(var i = 0; i<maxIndex; i++){ @@ -36,27 +31,25 @@ function initBoard() } //Calculate board size - maxX = Math.floor(gameCanvas.width/gameCanvas.tileSize); - maxY = Math.floor(gameCanvas.height/gameCanvas.tileSize); - maxIndex = maxY*maxX; + maxColumn = Math.floor(gameCanvas.width/gameCanvas.tileSize); + maxRow = Math.floor(gameCanvas.height/gameCanvas.tileSize); + maxIndex = maxRow*maxColumn; //Close dialogs - scoreName.forceClose(); + nameInputDialog.forceClose(); dialog.forceClose(); - var a = new Date(); //Initialize Board board = new Array(maxIndex); gameCanvas.score = 0; - for(var xIdx=0; xIdx<maxX; xIdx++){ - for(var yIdx=0; yIdx<maxY; yIdx++){ - board[index(xIdx,yIdx)] = null; - createBlock(xIdx,yIdx); + for(var column=0; column<maxColumn; column++){ + for(var row=0; row<maxRow; row++){ + board[index(column,row)] = null; + createBlock(column,row); } } - timer = new Date(); - print(timer.valueOf() - a.valueOf()); + timer = new Date(); } var fillFound;//Set after a floodFill call to the number of tiles found @@ -64,14 +57,14 @@ var floodBoard;//Set to 1 if the floodFill reaches off that node //NOTE: Be careful with vars named x,y, as the calling object's x,y are still in scope function handleClick(x,y) { - var xIdx = Math.floor(x/gameCanvas.tileSize); - var yIdx = Math.floor(y/gameCanvas.tileSize); - if(xIdx >= maxX || xIdx < 0 || yIdx >= maxY || yIdx < 0) + var column = Math.floor(x/gameCanvas.tileSize); + var row = Math.floor(y/gameCanvas.tileSize); + if(column >= maxColumn || column < 0 || row >= maxRow || row < 0) return; - if(board[index(xIdx, yIdx)] == null) + if(board[index(column, row)] == null) return; //If it's a valid tile, remove it and all connected (does nothing if it's not connected) - floodFill(xIdx,yIdx, -1); + floodFill(column,row, -1); if(fillFound <= 0) return; gameCanvas.score += (fillFound - 1) * (fillFound - 1); @@ -79,67 +72,67 @@ function handleClick(x,y) victoryCheck(); } -function floodFill(xIdx,yIdx,type) +function floodFill(column,row,type) { - if(board[index(xIdx, yIdx)] == null) + if(board[index(column, row)] == null) return; var first = false; if(type == -1){ first = true; - type = board[index(xIdx,yIdx)].type; - + type = board[index(column,row)].type; + //Flood fill initialization fillFound = 0; floodBoard = new Array(maxIndex); } - if(xIdx >= maxX || xIdx < 0 || yIdx >= maxY || yIdx < 0) + if(column >= maxColumn || column < 0 || row >= maxRow || row < 0) return; - if(floodBoard[index(xIdx, yIdx)] == 1 || (!first && type != board[index(xIdx,yIdx)].type)) + if(floodBoard[index(column, row)] == 1 || (!first && type != board[index(column,row)].type)) return; - floodBoard[index(xIdx, yIdx)] = 1; - floodFill(xIdx+1,yIdx,type); - floodFill(xIdx-1,yIdx,type); - floodFill(xIdx,yIdx+1,type); - floodFill(xIdx,yIdx-1,type); + floodBoard[index(column, row)] = 1; + floodFill(column+1,row,type); + floodFill(column-1,row,type); + floodFill(column,row+1,type); + floodFill(column,row-1,type); if(first==true && fillFound == 0) return;//Can't remove single tiles - board[index(xIdx,yIdx)].dying = true; - board[index(xIdx,yIdx)] = null; + board[index(column,row)].dying = true; + board[index(column,row)] = null; fillFound += 1; } function shuffleDown() { //Fall down - for(var xIdx=0; xIdx<maxX; xIdx++){ + for(var column=0; column<maxColumn; column++){ var fallDist = 0; - for(var yIdx=maxY-1; yIdx>=0; yIdx--){ - if(board[index(xIdx,yIdx)] == null){ + for(var row=maxRow-1; row>=0; row--){ + if(board[index(column,row)] == null){ fallDist += 1; }else{ if(fallDist > 0){ - var obj = board[index(xIdx,yIdx)]; + var obj = board[index(column,row)]; obj.targetY += fallDist * gameCanvas.tileSize; - board[index(xIdx,yIdx+fallDist)] = obj; - board[index(xIdx,yIdx)] = null; + board[index(column,row+fallDist)] = obj; + board[index(column,row)] = null; } } } } //Fall to the left fallDist = 0; - for(xIdx=0; xIdx<maxX; xIdx++){ - if(board[index(xIdx, maxY - 1)] == null){ + for(column=0; column<maxColumn; column++){ + if(board[index(column, maxRow - 1)] == null){ fallDist += 1; }else{ if(fallDist > 0){ - for(yIdx=0; yIdx<maxY; yIdx++){ - obj = board[index(xIdx,yIdx)]; + for(row=0; row<maxRow; row++){ + obj = board[index(column,row)]; if(obj == null) continue; obj.targetX -= fallDist * gameCanvas.tileSize; - board[index(xIdx-fallDist,yIdx)] = obj; - board[index(xIdx,yIdx)] = null; + board[index(column-fallDist,row)] = obj; + board[index(column,row)] = null; } } } @@ -150,34 +143,33 @@ function victoryCheck() { //awards bonuses for no tiles left var deservesBonus = true; - for(var xIdx=maxX-1; xIdx>=0; xIdx--) - if(board[index(xIdx, maxY - 1)] != null) + for(var column=maxColumn-1; column>=0; column--) + if(board[index(column, maxRow - 1)] != null) deservesBonus = false; if(deservesBonus) gameCanvas.score += 500; //Checks for game over - if(deservesBonus || !(floodMoveCheck(0,maxY-1, -1))){ + if(deservesBonus || !(floodMoveCheck(0,maxRow-1, -1))){ timer = new Date() - timer; - scoreName.show("You won! Please enter your name: "); - //dialog.show("Game Over. Your score is " + gameCanvas.score); + nameInputDialog.show("You won! Please enter your name: "); } } //only floods up and right, to see if it can find adjacent same-typed tiles -function floodMoveCheck(xIdx, yIdx, type) +function floodMoveCheck(column, row, type) { - if(xIdx >= maxX || xIdx < 0 || yIdx >= maxY || yIdx < 0) + if(column >= maxColumn || column < 0 || row >= maxRow || row < 0) return false; - if(board[index(xIdx, yIdx)] == null) + if(board[index(column, row)] == null) return false; - var myType = board[index(xIdx, yIdx)].type; + var myType = board[index(column, row)].type; if(type == myType) return true; - return floodMoveCheck(xIdx + 1, yIdx, myType) || - floodMoveCheck(xIdx, yIdx - 1, board[index(xIdx,yIdx)].type); + return floodMoveCheck(column + 1, row, myType) || + floodMoveCheck(column, row - 1, board[index(column,row)].type); } -function createBlock(xIdx,yIdx){ +function createBlock(column,row){ // 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 @@ -191,13 +183,13 @@ function createBlock(xIdx,yIdx){ } dynamicObject.type = Math.floor(Math.random() * 3); dynamicObject.parent = gameCanvas; - dynamicObject.x = xIdx*gameCanvas.tileSize; - dynamicObject.targetX = xIdx*gameCanvas.tileSize; - dynamicObject.targetY = yIdx*gameCanvas.tileSize; + dynamicObject.x = column*gameCanvas.tileSize; + dynamicObject.targetX = column*gameCanvas.tileSize; + dynamicObject.targetY = row*gameCanvas.tileSize; dynamicObject.width = gameCanvas.tileSize; dynamicObject.height = gameCanvas.tileSize; dynamicObject.spawned = true; - board[index(xIdx,yIdx)] = dynamicObject; + board[index(column,row)] = dynamicObject; }else{//isError or isLoading print("error loading block component"); print(component.errorsString()); @@ -213,7 +205,7 @@ function saveHighScore(name) { //OfflineStorage var db = openDatabaseSync("SameGameScores", "1.0", "Local SameGame High Scores",100); var dataStr = "INSERT INTO Scores VALUES(?, ?, ?, ?)"; - var data = [name, gameCanvas.score, maxX+"x"+maxY ,Math.floor(timer/1000)]; + var data = [name, gameCanvas.score, maxColumn+"x"+maxRow ,Math.floor(timer/1000)]; db.transaction( function(tx) { tx.executeSql('CREATE TABLE IF NOT EXISTS Scores(name TEXT, score NUMBER, gridSize TEXT, time NUMBER)'); @@ -236,7 +228,7 @@ function saveHighScore(name) { function sendHighScore(name) { var postman = new XMLHttpRequest() var postData = "name="+name+"&score="+gameCanvas.score - +"&gridSize="+maxX+"x"+maxY +"&time="+Math.floor(timer/1000); + +"&gridSize="+maxColumn+"x"+maxRow +"&time="+Math.floor(timer/1000); postman.open("POST", scoresURL, true); postman.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); postman.onreadystatechange = function() { diff --git a/examples/declarative/tutorials/samegame/samegame4/highscores/scores.php b/examples/declarative/tutorials/samegame/samegame4/highscores/scores.php index 3cceb2d..daf480e 100755 --- a/examples/declarative/tutorials/samegame/samegame4/highscores/scores.php +++ b/examples/declarative/tutorials/samegame/samegame4/highscores/scores.php @@ -8,10 +8,7 @@ $time = $_POST["time"]; if($name == "") $name = "Anonymous"; - //if($grid != "10x10"){ - //Need a standard, so as to reject others? - //} - $file = fopen("score_data.xml", "a"); #It's XML. Happy? + $file = fopen("score_data.xml", "a"); $ret = fwrite($file, "<record><score>". $score . "</score><name>" . $name . "</name><gridSize>" . $grid . "</gridSize><seconds>" . $time . "</seconds></record>\n"); diff --git a/examples/declarative/tutorials/samegame/samegame4/samegame.qml b/examples/declarative/tutorials/samegame/samegame4/samegame.qml index 3c66fbf..fe35e3b 100644 --- a/examples/declarative/tutorials/samegame/samegame4/samegame.qml +++ b/examples/declarative/tutorials/samegame/samegame4/samegame.qml @@ -23,8 +23,8 @@ Rectangle { property int tileSize: 40 z: 20; anchors.centerIn: parent - width: parent.width - (parent.width % getTileSize()); - height: parent.height - (parent.height % getTileSize()); + width: parent.width - (parent.width % tileSize); + height: parent.height - (parent.height % tileSize); MouseArea { anchors.fill: parent; onClicked: SameGame.handleClick(mouse.x,mouse.y); @@ -36,7 +36,7 @@ Rectangle { //![0] Dialog { - id: scoreName; anchors.centerIn: parent; z: 22; + id: nameInputDialog; anchors.centerIn: parent; z: 22; Text { id: spacer opacity: 0 @@ -45,9 +45,9 @@ Rectangle { TextInput { id: editor onAccepted: { - if(scoreName.opacity==1&&editor.text!="") - saveHighScore(editor.text); - scoreName.forceClose(); + if(nameInputDialog.opacity==1&&editor.text!="") + SameGame.saveHighScore(editor.text); + nameInputDialog.forceClose(); } anchors.verticalCenter: parent.verticalCenter width: 72; focus: true @@ -63,7 +63,7 @@ Rectangle { anchors.bottom: screen.bottom Button { - id: btnA; text: "New Game"; onClicked: {SameGame.initBoard();} + text: "New Game"; onClicked: SameGame.initBoard(); anchors.left: parent.left; anchors.leftMargin: 3 anchors.verticalCenter: parent.verticalCenter } diff --git a/examples/declarative/tvtennis/tvtennis.qml b/examples/declarative/tvtennis/tvtennis.qml index 7c98c69..240183f 100644 --- a/examples/declarative/tvtennis/tvtennis.qml +++ b/examples/declarative/tvtennis/tvtennis.qml @@ -31,7 +31,7 @@ Rectangle { } // Make y follow the target y coordinate, with a velocity of 200 - SpringFollow on y { source: ball.targetY; velocity: 200 } + SpringFollow on y { to: ball.targetY; velocity: 200 } // Detect the ball hitting the top or bottom of the view and bounce it onYChanged: { @@ -52,7 +52,7 @@ Rectangle { color: "Lime" x: 2; width: 20; height: 90 SpringFollow on y { - source: ball.y - 45; velocity: 300 + to: ball.y - 45; velocity: 300 enabled: ball.direction == 'left' } } @@ -61,7 +61,7 @@ Rectangle { color: "Lime" x: page.width - 22; width: 20; height: 90 SpringFollow on y { - source: ball.y-45; velocity: 300 + to: ball.y-45; velocity: 300 enabled: ball.direction == 'right' } } diff --git a/examples/declarative/velocity/Day.qml b/examples/declarative/velocity/Day.qml index 8c33299..724fcc8 100644 --- a/examples/declarative/velocity/Day.qml +++ b/examples/declarative/velocity/Day.qml @@ -1,78 +1,92 @@ import Qt 4.7 -Rectangle { - property alias day: dayText.text - property var stickies +Component { + Item { + property var stickies - id: page - width: 400; height: 500; radius: 7 - border.color: "black" + id: page + width: 840; height: 480 - Image { x: 10; y: 10; source: "cork.jpg" } + Image { source: "cork.jpg" } - Text { - id: dayText; x: 20; y: 20 - height: 40; width: 370 - font.pointSize: 14; font.bold: true - style: Text.Outline; styleColor: "#dedede" - } - - Repeater { - model: page.stickies - - Item { - id: stickyPage - x: Math.random() * 200 + 100 - y: Math.random() * 300 + 50 - SpringFollow on rotation { - source: -flickable.horizontalVelocity / 100 - spring: 2.0; damping: 0.1 - } + Text { + text: name; x: 15; y: 8; height: 40; width: 370 + font.pixelSize: 18; font.bold: true; color: "white" + style: Text.Outline; styleColor: "black" + } + Repeater { + model: notes Item { - id: sticky - scale: 0.5 - Image { - id: stickyImage; source: "sticky.png"; transformOrigin: Item.TopLeft - smooth: true; y: -20; x: 8 + -width * 0.6 / 2; scale: 0.6 - } + property int randomX: Math.random() * 500 + 100 + property int randomY: Math.random() * 200 + 50 - TextEdit { - id: myText; smooth: true; font.pointSize: 28 - readOnly: false; x: -104; y: 36; wrap: true - rotation: -8; text: noteText; width: 195; height: 172 + id: stickyPage + x: randomX; y: randomY + + SpringFollow on rotation { + to: -flickable.horizontalVelocity / 100 + spring: 2.0; damping: 0.15 } Item { - y: -20 - x: stickyImage.x - width: stickyImage.width * stickyImage.scale - height: stickyImage.height * stickyImage.scale - MouseArea { - id: mouse - onClicked: { myText.focus = true } - anchors.fill: parent - drag.target: stickyPage; drag.axis: MouseArea.XandYAxis; drag.minimumY: 0; drag.maximumY: 500 - drag.minimumX: 0; drag.maximumX: 400 + id: sticky + scale: 0.7 + Image { + id: stickyImage + source: "note-yellow.png"; transformOrigin: Item.TopLeft + smooth: true; y: -20; x: 8 + -width * 0.6 / 2; scale: 0.6 + } + + TextEdit { + id: myText; smooth: true; font.pixelSize: 24 + readOnly: false; x: -104; y: 36 + rotation: -8; text: noteText; width: 215; height: 200 + } + + Item { + y: -20 + x: stickyImage.x + width: stickyImage.width * stickyImage.scale + height: stickyImage.height * stickyImage.scale + MouseArea { + id: mouse + onClicked: { myText.focus = true } + anchors.fill: parent + drag.target: stickyPage + drag.axis: "XandYAxis" + drag.minimumY: 0 + drag.maximumY: page.height - 80 + drag.minimumX: 100 + drag.maximumX: page.width - 140 + } } } - } - Image { - source: "tack.png"; transformOrigin: Item.TopLeft - x: -width / 2; y: -height * 0.7 / 2; scale: 0.7 - } + Image { + source: "tack.png"; transformOrigin: Item.TopLeft + x: -width / 2; y: -height * 0.5 / 2; scale: 0.7 + } - states: State { - name: "pressed" - when: mouse.pressed - PropertyChanges { target: sticky; rotation: 8; scale: 1 } - PropertyChanges { target: page; z: 8 } - } + states: State { + name: "pressed" + when: mouse.pressed + PropertyChanges { target: sticky; rotation: 8; scale: 1 } + PropertyChanges { target: page; z: 8 } + } - transitions: Transition { - NumberAnimation { properties: "rotation,scale"; duration: 200 } + transitions: Transition { + NumberAnimation { properties: "rotation,scale"; duration: 200 } + } } } } } + + + + + + + + diff --git a/examples/declarative/velocity/cork.jpg b/examples/declarative/velocity/cork.jpg Binary files differindex d4d706c..160bc00 100644 --- a/examples/declarative/velocity/cork.jpg +++ b/examples/declarative/velocity/cork.jpg diff --git a/examples/declarative/velocity/note-yellow.png b/examples/declarative/velocity/note-yellow.png Binary files differnew file mode 100644 index 0000000..8ddecc8 --- /dev/null +++ b/examples/declarative/velocity/note-yellow.png diff --git a/examples/declarative/velocity/sticky.png b/examples/declarative/velocity/sticky.png Binary files differdeleted file mode 100644 index 73df3cd..0000000 --- a/examples/declarative/velocity/sticky.png +++ /dev/null diff --git a/examples/declarative/velocity/velocity.qml b/examples/declarative/velocity/velocity.qml index a091c4e..20821d6 100644 --- a/examples/declarative/velocity/velocity.qml +++ b/examples/declarative/velocity/velocity.qml @@ -1,108 +1,46 @@ import Qt 4.7 Rectangle { - color: "lightSteelBlue" - width: 800; height: 600 + width: 800; height: 480; color: "#464646" ListModel { id: list ListElement { name: "Sunday" - dayColor: "#808080" - notes: [ - ListElement { - noteText: "Lunch" - }, - ListElement { - noteText: "Party" - } - ] + notes: [ ListElement { noteText: "Lunch" }, ListElement { noteText: "Birthday Party" } ] } ListElement { name: "Monday" - dayColor: "blue" - notes: [ - ListElement { - noteText: "Pickup kids" - }, - ListElement { - noteText: "Checkout kinetic" - }, - ListElement { - noteText: "Read email" - } - ] + notes: [ ListElement { noteText: "Pickup kids from\nschool\n4.30pm" }, + ListElement { noteText: "Checkout Qt" }, ListElement { noteText: "Read email" } ] } ListElement { name: "Tuesday" - dayColor: "yellow" - notes: [ - ListElement { - noteText: "Walk dog" - }, - ListElement { - noteText: "Buy newspaper" - } - ] + notes: [ ListElement { noteText: "Walk dog" }, ListElement { noteText: "Buy newspaper" } ] } ListElement { - name: "Wednesday" - dayColor: "purple" - notes: [ - ListElement { - noteText: "Cook dinner" - }, - ListElement { - noteText: "Eat dinner" - } - ] + name: "Wednesday"; notes: [ ListElement { noteText: "Cook dinner" } ] } ListElement { name: "Thursday" - dayColor: "blue" - notes: [ - ListElement { - noteText: "5:30pm Meeting" - }, - ListElement { - noteText: "Weed garden" - } - ] + notes: [ ListElement { noteText: "Meeting\n5.30pm" }, ListElement { noteText: "Weed garden" } ] } ListElement { name: "Friday" - dayColor: "green" - notes: [ - ListElement { - noteText: "Still work" - }, - ListElement { - noteText: "Drink" - } - ] + notes: [ ListElement { noteText: "More work" }, ListElement { noteText: "Grocery shopping" } ] } ListElement { name: "Saturday" - dayColor: "orange" - notes: [ - ListElement { - noteText: "Drink" - }, - ListElement { - noteText: "Drink" - } - ] + notes: [ ListElement { noteText: "Drink" }, ListElement { noteText: "Download Qt\nPlay with QML" } ] } } - Flickable { + + ListView { id: flickable - anchors.fill: parent; contentWidth: lay.width - Row { - id: lay - Repeater { - model: list - Component { Day { day: name; color: dayColor; stickies: notes } } - } - } + anchors.fill: parent; focus: true + model: list; delegate: Day { } + highlightRangeMode: ListView.StrictlyEnforceRange + orientation: ListView.Horizontal + snapMode: ListView.SnapOneItem } } diff --git a/src/corelib/global/qlibraryinfo.cpp b/src/corelib/global/qlibraryinfo.cpp index 9490225..3515777 100644 --- a/src/corelib/global/qlibraryinfo.cpp +++ b/src/corelib/global/qlibraryinfo.cpp @@ -329,6 +329,10 @@ QLibraryInfo::location(LibraryLocation loc) key = QLatin1String("Plugins"); defaultValue = QLatin1String("plugins"); break; + case ImportsPath: + key = QLatin1String("Imports"); + defaultValue = QLatin1String("imports"); + break; case DataPath: key = QLatin1String("Data"); break; diff --git a/src/declarative/QmlChanges.txt b/src/declarative/QmlChanges.txt index d3737b0..079aacb 100644 --- a/src/declarative/QmlChanges.txt +++ b/src/declarative/QmlChanges.txt @@ -33,12 +33,20 @@ syntax has been introduced: Item { Behavior on x {}; NumberAnimation on y {} } Only the syntax has changed, the behavior is identical. +EaseFollow renamed to SmoothedFollow +--------------------------------------- +This element shares the internal implementation with SmoothedAnimation, +both providing the same easing function, but with SmoothedFollow it's +easier to set a start value to animate intially and then start to follow, +while SmoothedAnimation is still convenient for using inside Behaviors +and Transitions. + -EaseFollow changed to SmoothedAnimation +Add SmoothedAnimation element --------------------------------------- -EaseFollow was renamed to SmoothedAnimation and now it inherits from -NumberAnimaton and as a consequence SmoothedAnimation can be used inside -Behaviors, as PropertySourceValues or in state transitions, like any other animation. +SmoothedAnimation inherits from NumberAnimaton and as a +consequence SmoothedAnimation can be used inside Behaviors, +as PropertySourceValues or in state transitions, like any other animation. The old EaseFollow properties changed to comply with the other declarative animations ('source' changed to 'to'), so now 'to' changes are not diff --git a/src/declarative/graphicsitems/qdeclarativeanimatedimage.cpp b/src/declarative/graphicsitems/qdeclarativeanimatedimage.cpp index f14f773..cc062f0 100644 --- a/src/declarative/graphicsitems/qdeclarativeanimatedimage.cpp +++ b/src/declarative/graphicsitems/qdeclarativeanimatedimage.cpp @@ -312,7 +312,7 @@ void QDeclarativeAnimatedImage::playingStatusChanged() void QDeclarativeAnimatedImage::componentComplete() { Q_D(QDeclarativeAnimatedImage); - QDeclarativeImage::componentComplete(); + QDeclarativeItem::componentComplete(); // NOT QDeclarativeImage if (!d->reply) { setCurrentFrame(d->preset_currentframe); d->preset_currentframe = 0; diff --git a/src/declarative/graphicsitems/qdeclarativeanimatedimage_p.h b/src/declarative/graphicsitems/qdeclarativeanimatedimage_p.h index 6ab66b3..9d8087c 100644 --- a/src/declarative/graphicsitems/qdeclarativeanimatedimage_p.h +++ b/src/declarative/graphicsitems/qdeclarativeanimatedimage_p.h @@ -61,6 +61,10 @@ class Q_DECLARATIVE_EXPORT QDeclarativeAnimatedImage : public QDeclarativeImage Q_PROPERTY(bool paused READ isPaused WRITE setPaused NOTIFY pausedChanged) Q_PROPERTY(int currentFrame READ currentFrame WRITE setCurrentFrame NOTIFY frameChanged) Q_PROPERTY(int frameCount READ frameCount) + + // read-only for AnimatedImage + Q_PROPERTY(QSize sourceSize READ sourceSize NOTIFY sourceSizeChanged) + public: QDeclarativeAnimatedImage(QDeclarativeItem *parent=0); ~QDeclarativeAnimatedImage(); @@ -83,6 +87,7 @@ Q_SIGNALS: void playingChanged(); void pausedChanged(); void frameChanged(); + void sourceSizeChanged(); private Q_SLOTS: void movieUpdate(); diff --git a/src/declarative/graphicsitems/qdeclarativeimagebase_p.h b/src/declarative/graphicsitems/qdeclarativeimagebase_p.h index 6c84456..49b1c58 100644 --- a/src/declarative/graphicsitems/qdeclarativeimagebase_p.h +++ b/src/declarative/graphicsitems/qdeclarativeimagebase_p.h @@ -73,7 +73,7 @@ public: bool asynchronous() const; void setAsynchronous(bool); - void setSourceSize(const QSize&); + virtual void setSourceSize(const QSize&); QSize sourceSize() const; Q_SIGNALS: diff --git a/src/declarative/qml/qdeclarativebinding.cpp b/src/declarative/qml/qdeclarativebinding.cpp index 71cf3cb..6a99855 100644 --- a/src/declarative/qml/qdeclarativebinding.cpp +++ b/src/declarative/qml/qdeclarativebinding.cpp @@ -126,7 +126,7 @@ void QDeclarativeBinding::update(QDeclarativePropertyPrivate::WriteFlags flags) QDeclarativeBindingData *data = d->bindingData(); - if (!data->enabled) + if (!data->enabled || !data->context() || !data->context()->engine) return; data->addref(); @@ -148,14 +148,46 @@ void QDeclarativeBinding::update(QDeclarativePropertyPrivate::WriteFlags flags) idx, a); } else { + QDeclarativeEnginePrivate *ep = QDeclarativeEnginePrivate::get(data->context()->engine); + bool isUndefined = false; - QVariant value = this->value(&isUndefined); + QVariant value; + + QScriptValue scriptValue = d->scriptValue(0, &isUndefined); + if (data->property.propertyTypeCategory() == QDeclarativeProperty::List) { + value = ep->scriptValueToVariant(scriptValue, qMetaTypeId<QList<QObject *> >()); + } else { + value = ep->scriptValueToVariant(scriptValue, data->property.propertyType()); + if (value.userType() == QMetaType::QObjectStar && !qvariant_cast<QObject*>(value)) { + // If the object is null, we extract the predicted type. While this isn't + // 100% reliable, in many cases it gives us better error messages if we + // assign this null-object to an incompatible property + int type = ep->objectClass->objectType(scriptValue); + QObject *o = 0; + value = QVariant(type, (void *)&o); + } + } + + if (data->error.isValid()) { + + } else if (!scriptValue.isVariant() && value.userType() == QMetaType::QVariantList && + data->property.propertyType() == qMetaTypeId<QVariant>()) { + + // This case catches QtScript's automatic conversion to QVariantList for arrays + QUrl url = QUrl(data->url); + int line = data->line; + if (url.isEmpty()) url = QUrl(QLatin1String("<Unknown File>")); + + data->error.setUrl(url); + data->error.setLine(line); + data->error.setColumn(-1); + data->error.setDescription(QLatin1String("Unable to assign JavaScript array to QML variant property")); - if (isUndefined && !data->error.isValid() && data->property.isResettable()) { + } else if (isUndefined && data->property.isResettable()) { data->property.reset(); - } else if (isUndefined && !data->error.isValid()) { + } else if (isUndefined) { QUrl url = QUrl(data->url); int line = data->line; @@ -166,7 +198,7 @@ void QDeclarativeBinding::update(QDeclarativePropertyPrivate::WriteFlags flags) data->error.setColumn(-1); data->error.setDescription(QLatin1String("Unable to assign [undefined] to ") + QLatin1String(QMetaType::typeName(data->property.propertyType()))); - } else if (!isUndefined && data->property.object() && + } else if (data->property.object() && !QDeclarativePropertyPrivate::write(data->property, value, flags)) { QUrl url = QUrl(data->url); @@ -187,9 +219,7 @@ void QDeclarativeBinding::update(QDeclarativePropertyPrivate::WriteFlags flags) } if (data->error.isValid()) { - QDeclarativeEnginePrivate *p = (data->context() && data->context()->engine)? - QDeclarativeEnginePrivate::get(data->context()->engine):0; - if (!data->addError(p)) + if (!data->addError(ep)) qWarning().nospace() << qPrintable(this->error().toString()); } else { data->removeError(); diff --git a/src/declarative/qml/qdeclarativecompiler.cpp b/src/declarative/qml/qdeclarativecompiler.cpp index f20ffa6..d2b2024 100644 --- a/src/declarative/qml/qdeclarativecompiler.cpp +++ b/src/declarative/qml/qdeclarativecompiler.cpp @@ -342,9 +342,22 @@ void QDeclarativeCompiler::genLiteralAssignment(const QMetaProperty &prop, switch(type) { case -1: { - instr.type = QDeclarativeInstruction::StoreVariant; - instr.storeString.propertyIndex = prop.propertyIndex(); - instr.storeString.value = output->indexForString(string); + if (v->value.isNumber()) { + double n = v->value.asNumber(); + if (double(int(n)) == n) { + instr.type = QDeclarativeInstruction::StoreVariantInteger; + instr.storeInteger.propertyIndex = prop.propertyIndex(); + instr.storeInteger.value = int(n); + } else { + instr.type = QDeclarativeInstruction::StoreVariantDouble; + instr.storeDouble.propertyIndex = prop.propertyIndex(); + instr.storeDouble.value = n; + } + } else { + instr.type = QDeclarativeInstruction::StoreVariant; + instr.storeString.propertyIndex = prop.propertyIndex(); + instr.storeString.value = output->indexForString(string); + } } break; case QVariant::String: @@ -2520,7 +2533,7 @@ bool QDeclarativeCompiler::buildDynamicMeta(QDeclarativeParser::Object *obj, Dyn ((QDeclarativeVMEMetaData *)dynamicData.data())->methodCount++; QDeclarativeVMEMetaData::MethodData methodData = - { s.parameterNames.count(), 0, funcScript.length(), 0 }; + { s.parameterNames.count(), 0, funcScript.length(), s.location.start.line }; dynamicData.append((char *)&methodData, sizeof(methodData)); } diff --git a/src/declarative/qml/qdeclarativecompositetypemanager.cpp b/src/declarative/qml/qdeclarativecompositetypemanager.cpp index 61978a4..ccf10c6 100644 --- a/src/declarative/qml/qdeclarativecompositetypemanager.cpp +++ b/src/declarative/qml/qdeclarativecompositetypemanager.cpp @@ -634,7 +634,7 @@ int QDeclarativeCompositeTypeManager::resolveTypes(QDeclarativeCompositeTypeData QDeclarativeError error; error.setUrl(unit->imports.baseUrl()); QString userTypeName = QString::fromUtf8(typeName); - userTypeName.replace('/','.'); + userTypeName.replace(QLatin1Char('/'),QLatin1Char('.')); if (typeNamespace) error.setDescription(tr("Namespace %1 cannot be used as a type").arg(userTypeName)); else diff --git a/src/declarative/qml/qdeclarativecontextscriptclass.cpp b/src/declarative/qml/qdeclarativecontextscriptclass.cpp index 6d31c22..461fab5 100644 --- a/src/declarative/qml/qdeclarativecontextscriptclass.cpp +++ b/src/declarative/qml/qdeclarativecontextscriptclass.cpp @@ -295,7 +295,7 @@ void QDeclarativeContextScriptClass::setProperty(Object *object, const Identifie QDeclarativeEnginePrivate *ep = QDeclarativeEnginePrivate::get(engine); - ep->objectClass->setProperty(lastScopeObject, name, value, bindContext); + ep->objectClass->setProperty(lastScopeObject, name, value, context(), bindContext); } QT_END_NAMESPACE diff --git a/src/declarative/qml/qdeclarativeengine.cpp b/src/declarative/qml/qdeclarativeengine.cpp index ee0bd18..68ce953 100644 --- a/src/declarative/qml/qdeclarativeengine.cpp +++ b/src/declarative/qml/qdeclarativeengine.cpp @@ -188,6 +188,8 @@ QDeclarativeEnginePrivate::QDeclarativeEnginePrivate(QDeclarativeEngine *e) fileImportPath += builtinPath; #endif + filePluginPath += QLatin1String("."); + } QUrl QDeclarativeScriptEngine::resolvedUrl(QScriptContext *context, const QUrl& url) @@ -1323,7 +1325,6 @@ QScriptValue QDeclarativeEnginePrivate::tint(QScriptContext *ctxt, QScriptEngine return qScriptValueFromValue(engine, qVariantFromValue(finalColor)); } - QScriptValue QDeclarativeEnginePrivate::scriptValueFromVariant(const QVariant &val) { if (val.userType() == qMetaTypeId<QDeclarativeListReference>()) { @@ -1334,6 +1335,14 @@ QScriptValue QDeclarativeEnginePrivate::scriptValueFromVariant(const QVariant &v } else { return scriptEngine.nullValue(); } + } else if (val.userType() == qMetaTypeId<QList<QObject *> >()) { + const QList<QObject *> &list = *(QList<QObject *>*)val.constData(); + QScriptValue rv = scriptEngine.newArray(list.count()); + for (int ii = 0; ii < list.count(); ++ii) { + QObject *object = list.at(ii); + rv.setProperty(ii, objectClass->newQObject(object)); + } + return rv; } bool objOk; @@ -1345,22 +1354,29 @@ QScriptValue QDeclarativeEnginePrivate::scriptValueFromVariant(const QVariant &v } } -QVariant QDeclarativeEnginePrivate::scriptValueToVariant(const QScriptValue &val) +QVariant QDeclarativeEnginePrivate::scriptValueToVariant(const QScriptValue &val, int hint) { QScriptDeclarativeClass *dc = QScriptDeclarativeClass::scriptClass(val); if (dc == objectClass) return QVariant::fromValue(objectClass->toQObject(val)); + else if (dc == valueTypeClass) + return valueTypeClass->toVariant(val); else if (dc == contextClass) return QVariant(); - QScriptDeclarativeClass *sc = QScriptDeclarativeClass::scriptClass(val); - if (!sc) { - return val.toVariant(); - } else if (sc == valueTypeClass) { - return valueTypeClass->toVariant(val); - } else { - return QVariant(); + // Convert to a QList<QObject*> only if val is an array and we were explicitly hinted + if (hint == qMetaTypeId<QList<QObject *> >() && val.isArray()) { + QList<QObject *> list; + int length = val.property(QLatin1String("length")).toInt32(); + for (int ii = 0; ii < length; ++ii) { + QScriptValue arrayItem = val.property(ii); + QObject *d = arrayItem.toQObject(); + list << d; + } + return QVariant::fromValue(list); } + + return val.toVariant(); } // XXX this beyonds in QUrl::toLocalFile() @@ -1483,19 +1499,13 @@ public: foreach (const QDeclarativeDirParser::Plugin &plugin, qmldirParser.plugins()) { - QDir pluginDir = dir.absoluteFilePath(plugin.path); - - // hack for resources, should probably go away - if (absoluteFilePath.startsWith(QLatin1Char(':'))) - pluginDir = QDir(QCoreApplication::applicationDirPath()); - QString resolvedFilePath = QDeclarativeEnginePrivate::get(engine) - ->resolvePlugin(pluginDir, + ->resolvePlugin(dir, plugin.path, plugin.name); if (!resolvedFilePath.isEmpty()) { - engine->importExtension(resolvedFilePath, uri); + engine->importPlugin(resolvedFilePath, uri); } } } @@ -1790,8 +1800,8 @@ QUrl QDeclarativeEnginePrivate::Imports::baseUrl() const } /*! - Adds \a path as a directory where installed QML components are - defined in a URL-based directory structure. + Adds \a path as a directory where the engine searches for + installed modules in a URL-based directory structure. The newly added \a path will be first in the importPathList(). @@ -1814,7 +1824,7 @@ void QDeclarativeEngine::addImportPath(const QString& path) /*! Returns the list of directories where the engine searches for - installed modules. + installed modules in a URL-based directory structure. For example, if \c /opt/MyApp/lib/imports is in the path, then QML that imports \c com.mycompany.Feature will cause the QDeclarativeEngine to look @@ -1835,7 +1845,7 @@ QStringList QDeclarativeEngine::importPathList() const /*! Sets the list of directories where the engine searches for - installed modules. + installed modules in a URL-based directory structure. By default, the list contains the paths specified in the \c QML_IMPORT_PATH environment variable, then the builtin \c ImportsPath from QLibraryInfo. @@ -1848,15 +1858,73 @@ void QDeclarativeEngine::setImportPathList(const QStringList &paths) d->fileImportPath = paths; } + /*! - Imports the extension named \a fileName from the \a uri provided. - Returns true if the extension was successfully imported. + Adds \a path as a directory where the engine searches for + native plugins for imported modules (referenced in the \c qmldir file). + + By default, the list contains only \c ., i.e. the engine searches + in the directory of the \c qmldir file itself. + + The newly added \a path will be first in the pluginPathList(). + + \sa setPluginPathList() */ -bool QDeclarativeEngine::importExtension(const QString &fileName, const QString &uri) +void QDeclarativeEngine::addPluginPath(const QString& path) { if (qmlImportTrace()) - qDebug() << "QDeclarativeEngine::importExtension" << uri << "from" << fileName; - QFileInfo fileInfo(fileName); + qDebug() << "QDeclarativeEngine::addPluginPath" << path; + Q_D(QDeclarativeEngine); + QUrl url = QUrl(path); + if (url.isRelative() || url.scheme() == QString::fromLocal8Bit("file")) { + QDir dir = QDir(path); + d->filePluginPath.prepend(dir.canonicalPath()); + } else { + d->filePluginPath.prepend(path); + } +} + + +/*! + Returns the list of directories where the engine searches for + native plugins for imported modules (referenced in the \c qmldir file). + + By default, the list contains only \c ., i.e. the engine searches + in the directory of the \c qmldir file itself. + + \sa addPluginPath() setPluginPathList() +*/ +QStringList QDeclarativeEngine::pluginPathList() const +{ + Q_D(const QDeclarativeEngine); + return d->filePluginPath; +} + +/*! + Sets the list of directories where the engine searches for + native plugins for imported modules (referenced in the \c qmldir file). + + By default, the list contains only \c ., i.e. the engine searches + in the directory of the \c qmldir file itself. + + \sa pluginPathList() addPluginPath() + */ +void QDeclarativeEngine::setPluginPathList(const QStringList &paths) +{ + Q_D(QDeclarativeEngine); + d->filePluginPath = paths; +} + + +/*! + Imports the plugin named \a filePath with the \a uri provided. + Returns true if the plugin was successfully imported; otherwise returns false. +*/ +bool QDeclarativeEngine::importPlugin(const QString &filePath, const QString &uri) +{ + if (qmlImportTrace()) + qDebug() << "QDeclarativeEngine::importPlugin" << uri << "from" << filePath; + QFileInfo fileInfo(filePath); const QString absoluteFilePath = fileInfo.absoluteFilePath(); QDeclarativeEnginePrivate *d = QDeclarativeEnginePrivate::get(this); @@ -1929,27 +1997,53 @@ QString QDeclarativeEngine::offlineStoragePath() const /*! \internal - Returns the result of the merge of \a baseName with \a dir, \a suffixes, and \a prefix. + Returns the result of the merge of \a baseName with \a path, \a suffixes, and \a prefix. The \a prefix must contain the dot. + + \a qmldirPath is the location of the qmldir file. */ -QString QDeclarativeEnginePrivate::resolvePlugin(const QDir &dir, const QString &baseName, +QString QDeclarativeEnginePrivate::resolvePlugin(const QDir &qmldirPath, const QString &qmldirPluginPath, const QString &baseName, const QStringList &suffixes, const QString &prefix) { - foreach (const QString &suffix, suffixes) { - QString pluginFileName = prefix; + QStringList searchPaths = filePluginPath; + bool qmldirPluginPathIsRelative = QDir::isRelativePath(qmldirPluginPath); + if (!qmldirPluginPathIsRelative) + searchPaths.prepend(qmldirPluginPath); + + foreach (const QString &pluginPath, searchPaths) { - pluginFileName += baseName; - pluginFileName += suffix; + QString resolvedPath; - QFileInfo fileInfo(dir, pluginFileName); + if (pluginPath == QLatin1String(".")) { + if (qmldirPluginPathIsRelative) + resolvedPath = qmldirPath.absoluteFilePath(qmldirPluginPath); + else + resolvedPath = qmldirPath.absolutePath(); + } else { + resolvedPath = pluginPath; + } + + // hack for resources, should probably go away + if (resolvedPath.startsWith(QLatin1Char(':'))) + resolvedPath = QCoreApplication::applicationDirPath(); + + QDir dir(resolvedPath); + foreach (const QString &suffix, suffixes) { + QString pluginFileName = prefix; - if (fileInfo.exists()) - return fileInfo.absoluteFilePath(); + pluginFileName += baseName; + pluginFileName += suffix; + + QFileInfo fileInfo(dir, pluginFileName); + + if (fileInfo.exists()) + return fileInfo.absoluteFilePath(); + } } if (qmlImportTrace()) - qDebug() << "QDeclarativeEngine::resolvePlugin: Could not resolve plugin" << baseName << "in" << dir.absolutePath(); + qDebug() << "QDeclarativeEngine::resolvePlugin: Could not resolve plugin" << baseName << "in" << qmldirPath.absolutePath(); return QString(); } @@ -1970,17 +2064,17 @@ QString QDeclarativeEnginePrivate::resolvePlugin(const QDir &dir, const QString Version number on unix are ignored. */ -QString QDeclarativeEnginePrivate::resolvePlugin(const QDir &dir, const QString &baseName) +QString QDeclarativeEnginePrivate::resolvePlugin(const QDir &qmldirPath, const QString &qmldirPluginPath, const QString &baseName) { #if defined(Q_OS_WIN32) || defined(Q_OS_WINCE) - return resolvePlugin(dir, baseName, + return resolvePlugin(qmldirPath, qmldirPluginPath, baseName, QStringList() # ifdef QT_DEBUG << QLatin1String("d.dll") // try a qmake-style debug build first # endif << QLatin1String(".dll")); #elif defined(Q_OS_SYMBIAN) - return resolvePlugin(dir, baseName, + return resolvePlugin(qmldirPath, qmldirPluginPath, baseName, QStringList() << QLatin1String(".dll") << QLatin1String(".qtplugin")); @@ -1988,7 +2082,7 @@ QString QDeclarativeEnginePrivate::resolvePlugin(const QDir &dir, const QString # if defined(Q_OS_DARWIN) - return resolvePlugin(dir, baseName, + return resolvePlugin(qmldirPath, qmldirPluginPath, baseName, QStringList() # ifdef QT_DEBUG << QLatin1String("_debug.dylib") // try a qmake-style debug build first @@ -2022,7 +2116,7 @@ QString QDeclarativeEnginePrivate::resolvePlugin(const QDir &dir, const QString // Examples of valid library names: // libfoo.so - return resolvePlugin(dir, baseName, validSuffixList, QLatin1String("lib")); + return resolvePlugin(qmldirPath, qmldirPluginPath, baseName, validSuffixList, QLatin1String("lib")); # endif #endif diff --git a/src/declarative/qml/qdeclarativeengine.h b/src/declarative/qml/qdeclarativeengine.h index b861c1b..fcaddcf 100644 --- a/src/declarative/qml/qdeclarativeengine.h +++ b/src/declarative/qml/qdeclarativeengine.h @@ -81,7 +81,11 @@ public: void setImportPathList(const QStringList &paths); void addImportPath(const QString& dir); - bool importExtension(const QString &fileName, const QString &uri); + QStringList pluginPathList() const; + void setPluginPathList(const QStringList &paths); + void addPluginPath(const QString& dir); + + bool importPlugin(const QString &filePath, const QString &uri); void setNetworkAccessManagerFactory(QDeclarativeNetworkAccessManagerFactory *); QDeclarativeNetworkAccessManagerFactory *networkAccessManagerFactory() const; diff --git a/src/declarative/qml/qdeclarativeengine_p.h b/src/declarative/qml/qdeclarativeengine_p.h index 45089d0..6bcd0d1 100644 --- a/src/declarative/qml/qdeclarativeengine_p.h +++ b/src/declarative/qml/qdeclarativeengine_p.h @@ -231,6 +231,7 @@ public: QDeclarativeCompositeTypeManager typeManager; QStringList fileImportPath; + QStringList filePluginPath; QString offlineStoragePath; mutable quint32 uniqueId; @@ -274,10 +275,10 @@ public: QSet<QString> initializedPlugins; - QString resolvePlugin(const QDir &dir, const QString &baseName, + QString resolvePlugin(const QDir &qmldirPath, const QString &qmldirPluginPath, const QString &baseName, const QStringList &suffixes, const QString &prefix = QString()); - QString resolvePlugin(const QDir &dir, const QString &baseName); + QString resolvePlugin(const QDir &qmldirPath, const QString &qmldirPluginPath, const QString &baseName); bool addToImport(Imports*, const QDeclarativeDirComponents &qmldircomponentsnetwork, @@ -308,7 +309,7 @@ public: QHash<QString, QScriptValue> m_sharedScriptImports; QScriptValue scriptValueFromVariant(const QVariant &); - QVariant scriptValueToVariant(const QScriptValue &); + QVariant scriptValueToVariant(const QScriptValue &, int hint = QVariant::Invalid); void sendQuit (); diff --git a/src/declarative/qml/qdeclarativeexpression.cpp b/src/declarative/qml/qdeclarativeexpression.cpp index a250f21..2a3e557 100644 --- a/src/declarative/qml/qdeclarativeexpression.cpp +++ b/src/declarative/qml/qdeclarativeexpression.cpp @@ -175,7 +175,8 @@ void QDeclarativeExpressionPrivate::init(QDeclarativeContextData *ctxt, void *ex } QScriptValue QDeclarativeExpressionPrivate::evalInObjectScope(QDeclarativeContextData *context, QObject *object, - const QString &program, QScriptValue *contextObject) + const QString &program, const QString &fileName, + int lineNumber, QScriptValue *contextObject) { QDeclarativeEnginePrivate *ep = QDeclarativeEnginePrivate::get(context->engine); QScriptContext *scriptContext = QScriptDeclarativeClass::pushCleanContext(&ep->scriptEngine); @@ -186,7 +187,7 @@ QScriptValue QDeclarativeExpressionPrivate::evalInObjectScope(QDeclarativeContex scriptContext->pushScope(ep->contextClass->newContext(context, object)); } scriptContext->pushScope(ep->globalClass->globalObject()); - QScriptValue rv = ep->scriptEngine.evaluate(program); + QScriptValue rv = ep->scriptEngine.evaluate(program, fileName, lineNumber); ep->scriptEngine.popContext(); return rv; } @@ -351,7 +352,7 @@ void QDeclarativeExpressionPrivate::exceptionToError(QScriptEngine *scriptEngine } } -QVariant QDeclarativeExpressionPrivate::evalQtScript(QObject *secondaryScope, bool *isUndefined) +QScriptValue QDeclarativeExpressionPrivate::eval(QObject *secondaryScope, bool *isUndefined) { QDeclarativeExpressionData *data = this->data; QDeclarativeEngine *engine = data->context()->engine; @@ -376,7 +377,7 @@ QVariant QDeclarativeExpressionPrivate::evalQtScript(QObject *secondaryScope, bo const QString code = rewriteBinding(data->expression, &ok); if (!ok) { scriptEngine->popContext(); - return QVariant(); + return QScriptValue(); } data->expressionFunction = scriptEngine->evaluate(code, data->url, data->line); } @@ -413,54 +414,20 @@ QVariant QDeclarativeExpressionPrivate::evalQtScript(QObject *secondaryScope, bo if (scriptEngine->hasUncaughtException()) { exceptionToError(scriptEngine, data->error); scriptEngine->clearExceptions(); - return QVariant(); + return QScriptValue(); } else { data->error = QDeclarativeError(); + return svalue; } - - QVariant rv; - - if (svalue.isArray()) { - int length = svalue.property(QLatin1String("length")).toInt32(); - if (length && svalue.property(0).isObject()) { - QList<QObject *> list; - for (int ii = 0; ii < length; ++ii) { - QScriptValue arrayItem = svalue.property(ii); - QObject *d = arrayItem.toQObject(); - list << d; - } - rv = QVariant::fromValue(list); - } - } else if (svalue.isObject() && - ep->objectClass->scriptClass(svalue) == ep->objectClass) { - QObject *o = svalue.toQObject(); - int type = QMetaType::QObjectStar; - // If the object is null, we extract the predicted type. While this isn't - // 100% reliable, in many cases it gives us better error messages if we - // assign this null-object to an incompatible property - if (!o) type = ep->objectClass->objectType(svalue); - - return QVariant(type, &o); - } - - if (rv.isNull()) - rv = svalue.toVariant(); - - return rv; } -QVariant QDeclarativeExpressionPrivate::value(QObject *secondaryScope, bool *isUndefined) +QScriptValue QDeclarativeExpressionPrivate::scriptValue(QObject *secondaryScope, bool *isUndefined) { Q_Q(QDeclarativeExpression); - - QVariant rv; - if (!q->engine()) { - qWarning("QDeclarativeExpression: Attempted to evaluate an expression in an invalid context"); - return rv; - } + Q_ASSERT(q->engine()); if (data->expression.isEmpty()) - return rv; + return QScriptValue(); QDeclarativeEnginePrivate *ep = QDeclarativeEnginePrivate::get(q->engine()); @@ -476,7 +443,7 @@ QVariant QDeclarativeExpressionPrivate::value(QObject *secondaryScope, bool *isU QDeclarativeExpressionData *localData = data; localData->addref(); - rv = evalQtScript(secondaryScope, isUndefined); + QScriptValue value = eval(secondaryScope, isUndefined); ep->currentExpression = lastCurrentExpression; ep->captureProperties = lastCaptureProperties; @@ -494,7 +461,21 @@ QVariant QDeclarativeExpressionPrivate::value(QObject *secondaryScope, bool *isU lastCapturedProperties.copyAndClear(ep->capturedProperties); - return rv; + return value; +} + +QVariant QDeclarativeExpressionPrivate::value(QObject *secondaryScope, bool *isUndefined) +{ + Q_Q(QDeclarativeExpression); + + if (!q->engine()) { + qWarning("QDeclarativeExpression: Attempted to evaluate an expression in an invalid context"); + return QVariant(); + } + + QDeclarativeEnginePrivate *ep = QDeclarativeEnginePrivate::get(q->engine()); + + return ep->scriptValueToVariant(scriptValue(secondaryScope, isUndefined), qMetaTypeId<QList<QObject*> >()); } /*! diff --git a/src/declarative/qml/qdeclarativeexpression_p.h b/src/declarative/qml/qdeclarativeexpression_p.h index 9a90fb6..d39aa2c 100644 --- a/src/declarative/qml/qdeclarativeexpression_p.h +++ b/src/declarative/qml/qdeclarativeexpression_p.h @@ -150,7 +150,9 @@ public: QDeclarativeExpressionData *data; QVariant value(QObject *secondaryScope = 0, bool *isUndefined = 0); - QVariant evalQtScript(QObject *secondaryScope, bool *isUndefined = 0); + QScriptValue scriptValue(QObject *secondaryScope = 0, bool *isUndefined = 0); + + QScriptValue eval(QObject *secondaryScope, bool *isUndefined = 0); void updateGuards(const QPODVector<QDeclarativeEnginePrivate::CapturedProperty> &properties); void clearGuards(); @@ -165,8 +167,10 @@ public: virtual void emitValueChanged(); static void exceptionToError(QScriptEngine *, QDeclarativeError &); - static QScriptValue evalInObjectScope(QDeclarativeContextData *, QObject *, const QString &, QScriptValue * = 0); - static QScriptValue evalInObjectScope(QDeclarativeContextData *, QObject *, const QScriptProgram &, QScriptValue * = 0); + static QScriptValue evalInObjectScope(QDeclarativeContextData *, QObject *, const QString &, const QString &, + int, QScriptValue *); + static QScriptValue evalInObjectScope(QDeclarativeContextData *, QObject *, const QScriptProgram &, + QScriptValue *); }; QT_END_NAMESPACE diff --git a/src/declarative/qml/qdeclarativeinstruction.cpp b/src/declarative/qml/qdeclarativeinstruction.cpp index 1f8b8af..d88d06a 100644 --- a/src/declarative/qml/qdeclarativeinstruction.cpp +++ b/src/declarative/qml/qdeclarativeinstruction.cpp @@ -130,6 +130,12 @@ void QDeclarativeCompiledData::dump(QDeclarativeInstruction *instr, int idx) case QDeclarativeInstruction::StoreVariant: qWarning().nospace() << idx << "\t\t" << line << "\t" << "STORE_VARIANT\t\t" << instr->storeString.propertyIndex << "\t" << instr->storeString.value << "\t\t" << primitives.at(instr->storeString.value); break; + case QDeclarativeInstruction::StoreVariantInteger: + qWarning().nospace() << idx << "\t\t" << line << "\t" << "STORE_VARIANT_INTEGER\t\t" << instr->storeInteger.propertyIndex << "\t" << instr->storeInteger.value; + break; + case QDeclarativeInstruction::StoreVariantDouble: + qWarning().nospace() << idx << "\t\t" << line << "\t" << "STORE_VARIANT_DOUBLE\t\t" << instr->storeDouble.propertyIndex << "\t" << instr->storeDouble.value; + break; case QDeclarativeInstruction::StoreObject: qWarning().nospace() << idx << "\t\t" << line << "\t" << "STORE_OBJECT\t\t" << instr->storeObject.propertyIndex; break; diff --git a/src/declarative/qml/qdeclarativeinstruction_p.h b/src/declarative/qml/qdeclarativeinstruction_p.h index 1f3c964..e8287c0 100644 --- a/src/declarative/qml/qdeclarativeinstruction_p.h +++ b/src/declarative/qml/qdeclarativeinstruction_p.h @@ -114,6 +114,8 @@ public: StoreRectF, /* storeRect */ StoreVector3D, /* storeVector3D */ StoreVariant, /* storeString */ + StoreVariantInteger, /* storeInteger */ + StoreVariantDouble, /* storeDouble */ StoreObject, /* storeObject */ StoreVariantObject, /* storeObject */ StoreInterface, /* storeObject */ diff --git a/src/declarative/qml/qdeclarativeobjectscriptclass.cpp b/src/declarative/qml/qdeclarativeobjectscriptclass.cpp index 32ba2c3..ec84da9 100644 --- a/src/declarative/qml/qdeclarativeobjectscriptclass.cpp +++ b/src/declarative/qml/qdeclarativeobjectscriptclass.cpp @@ -52,6 +52,7 @@ #include <QtCore/qtimer.h> #include <QtCore/qvarlengtharray.h> +#include <QtScript/qscriptcontextinfo.h> Q_DECLARE_METATYPE(QScriptValue); @@ -225,15 +226,10 @@ QDeclarativeObjectScriptClass::property(QObject *obj, const Identifier &name) if (lastData->flags & QDeclarativePropertyCache::Data::IsVMEFunction) { return Value(scriptEngine, ((QDeclarativeVMEMetaObject *)(obj->metaObject()))->vmeMethod(lastData->coreIndex)); } else { -#if (QT_VERSION > QT_VERSION_CHECK(4, 6, 2)) || defined(QT_HAVE_QSCRIPTDECLARATIVECLASS_VALUE) // Uncomment to use QtScript method call logic // QScriptValue sobj = scriptEngine->newQObject(obj); // return Value(scriptEngine, sobj.property(toString(name))); return Value(scriptEngine, methods.newMethod(obj, lastData)); -#else - QScriptValue sobj = scriptEngine->newQObject(obj); - return Value(scriptEngine, sobj.property(toString(name))); -#endif } } else { if (enginePriv->captureProperties && !(lastData->flags & QDeclarativePropertyCache::Data::IsConstant)) { @@ -298,7 +294,6 @@ QDeclarativeObjectScriptClass::property(QObject *obj, const Identifier &name) QVariant var = obj->metaObject()->property(lastData->coreIndex).read(obj); return Value(scriptEngine, enginePriv->scriptValueFromVariant(var)); } - } } @@ -306,40 +301,40 @@ void QDeclarativeObjectScriptClass::setProperty(Object *object, const Identifier &name, const QScriptValue &value) { - return setProperty(toQObject(object), name, value); + return setProperty(toQObject(object), name, value, context()); } void QDeclarativeObjectScriptClass::setProperty(QObject *obj, - const Identifier &name, - const QScriptValue &value, - QDeclarativeContextData *evalContext) + const Identifier &name, + const QScriptValue &value, + QScriptContext *context, + QDeclarativeContextData *evalContext) { Q_UNUSED(name); Q_ASSERT(obj); Q_ASSERT(lastData); + Q_ASSERT(context); if (!lastData->isValid()) { QString error = QLatin1String("Cannot assign to non-existent property \"") + toString(name) + QLatin1Char('\"'); - if (context()) - context()->throwError(error); + context->throwError(error); return; } if (!(lastData->flags & QDeclarativePropertyCache::Data::IsWritable)) { QString error = QLatin1String("Cannot assign to read-only property \"") + toString(name) + QLatin1Char('\"'); - if (context()) - context()->throwError(error); + context->throwError(error); return; } QDeclarativeEnginePrivate *enginePriv = QDeclarativeEnginePrivate::get(engine); - if (!evalContext && context()) { + if (!evalContext) { // Global object, QScriptContext activation object, QDeclarativeContext object - QScriptValue scopeNode = scopeChainValue(context(), -3); + QScriptValue scopeNode = scopeChainValue(context, -3); if (scopeNode.isValid()) { Q_ASSERT(scriptClass(scopeNode) == enginePriv->contextClass); @@ -355,10 +350,33 @@ void QDeclarativeObjectScriptClass::setProperty(QObject *obj, if (value.isUndefined() && lastData->flags & QDeclarativePropertyCache::Data::IsResettable) { void *a[] = { 0 }; QMetaObject::metacall(obj, QMetaObject::ResetProperty, lastData->coreIndex, a); + } else if (value.isUndefined()) { + QString error = QLatin1String("Cannot assign [undefined] to ") + + QLatin1String(QMetaType::typeName(lastData->propType)); + context->throwError(error); } else { - // ### Can well known types be optimized? - QVariant v = enginePriv->scriptValueToVariant(value); - QDeclarativePropertyPrivate::write(obj, *lastData, v, evalContext); + QVariant v; + if (lastData->flags & QDeclarativePropertyCache::Data::IsQList) + v = enginePriv->scriptValueToVariant(value, qMetaTypeId<QList<QObject *> >()); + else + v = enginePriv->scriptValueToVariant(value, lastData->propType); + + if (!value.isVariant() && v.userType() == QMetaType::QVariantList && + lastData->propType == qMetaTypeId<QVariant>()) { + + QString error = QLatin1String("Cannot assign JavaScript array to QML variant property"); + context->throwError(error); + } else if (!QDeclarativePropertyPrivate::write(obj, *lastData, v, evalContext)) { + const char *valueType = 0; + if (v.userType() == QVariant::Invalid) valueType = "null"; + else valueType = QMetaType::typeName(v.userType()); + + QString error = QLatin1String("Cannot assign ") + + QLatin1String(valueType) + + QLatin1String(" to ") + + QLatin1String(QMetaType::typeName(lastData->propType)); + context->throwError(error); + } } } @@ -459,8 +477,6 @@ bool QDeclarativeObjectScriptClass::compare(Object *o1, Object *o2) return d1 == d2 || d1->object == d2->object; } -#if (QT_VERSION > QT_VERSION_CHECK(4, 6, 2)) || defined(QT_HAVE_QSCRIPTDECLARATIVECLASS_VALUE) - struct MethodData : public QScriptDeclarativeClass::Object { MethodData(QObject *o, const QDeclarativePropertyCache::Data &d) : object(o), data(d) {} @@ -690,7 +706,17 @@ void MetaCallArgument::fromScriptValue(int callType, QDeclarativeEngine *engine, new (&data) QVariant(QDeclarativeEnginePrivate::get(engine)->scriptValueToVariant(value)); type = callType; } else if (callType == qMetaTypeId<QList<QObject*> >()) { - new (&data) QList<QObject *>(); // We don't support passing in QList<QObject*> + QList<QObject *> *list = new (&data) QList<QObject *>(); + if (value.isArray()) { + int length = value.property(QLatin1String("length")).toInt32(); + for (int ii = 0; ii < length; ++ii) { + QScriptValue arrayItem = value.property(ii); + QObject *d = arrayItem.toQObject(); + list->append(d); + } + } else if (QObject *d = value.toQObject()) { + list->append(d); + } type = callType; } else { new (&data) QVariant(); @@ -803,7 +829,5 @@ QDeclarativeObjectMethodScriptClass::Value QDeclarativeObjectMethodScriptClass:: return Value(); } -#endif - QT_END_NAMESPACE diff --git a/src/declarative/qml/qdeclarativeobjectscriptclass_p.h b/src/declarative/qml/qdeclarativeobjectscriptclass_p.h index 8a2f7c7..5a59ef8 100644 --- a/src/declarative/qml/qdeclarativeobjectscriptclass_p.h +++ b/src/declarative/qml/qdeclarativeobjectscriptclass_p.h @@ -118,7 +118,7 @@ public: Value property(QObject *, const Identifier &); void setProperty(QObject *, const Identifier &name, const QScriptValue &, - QDeclarativeContextData *evalContext = 0); + QScriptContext *context, QDeclarativeContextData *evalContext = 0); virtual QStringList propertyNames(Object *); virtual bool compare(Object *, Object *); diff --git a/src/declarative/qml/qdeclarativeparser.cpp b/src/declarative/qml/qdeclarativeparser.cpp index 69186b6..d1f209a 100644 --- a/src/declarative/qml/qdeclarativeparser.cpp +++ b/src/declarative/qml/qdeclarativeparser.cpp @@ -200,7 +200,7 @@ QDeclarativeParser::Object::DynamicSlot::DynamicSlot() } QDeclarativeParser::Object::DynamicSlot::DynamicSlot(const DynamicSlot &o) -: name(o.name), body(o.body), parameterNames(o.parameterNames) +: name(o.name), body(o.body), parameterNames(o.parameterNames), location(o.location) { } diff --git a/src/declarative/qml/qdeclarativeparser_p.h b/src/declarative/qml/qdeclarativeparser_p.h index 57df04c..00fc65b 100644 --- a/src/declarative/qml/qdeclarativeparser_p.h +++ b/src/declarative/qml/qdeclarativeparser_p.h @@ -227,6 +227,7 @@ namespace QDeclarativeParser QByteArray name; QString body; QList<QByteArray> parameterNames; + LocationSpan location; }; // The list of dynamic properties diff --git a/src/declarative/qml/qdeclarativescriptparser.cpp b/src/declarative/qml/qdeclarativescriptparser.cpp index b4938bb..507ff5b 100644 --- a/src/declarative/qml/qdeclarativescriptparser.cpp +++ b/src/declarative/qml/qdeclarativescriptparser.cpp @@ -828,6 +828,7 @@ bool ProcessAST::visit(AST::UiSourceElement *node) if (AST::FunctionDeclaration *funDecl = AST::cast<AST::FunctionDeclaration *>(node->sourceElement)) { Object::DynamicSlot slot; + slot.location = location(funDecl->firstSourceLocation(), funDecl->lastSourceLocation()); AST::FormalParameterList *f = funDecl->formals; while (f) { diff --git a/src/declarative/qml/qdeclarativestringconverters.cpp b/src/declarative/qml/qdeclarativestringconverters.cpp index 5c88b9a..bbcc00b 100644 --- a/src/declarative/qml/qdeclarativestringconverters.cpp +++ b/src/declarative/qml/qdeclarativestringconverters.cpp @@ -82,10 +82,6 @@ QVariant QDeclarativeStringConverters::variantFromString(const QString &s) { if (s.isEmpty()) return QVariant(s); - if (s.startsWith(QLatin1Char('\'')) && s.endsWith(QLatin1Char('\''))) { - QString data = s.mid(1, s.length() - 2); - return QVariant(data); - } bool ok = false; QRectF r = rectFFromString(s, &ok); if (ok) return QVariant(r); @@ -104,6 +100,10 @@ QVariant QDeclarativeStringConverters::variantFromString(const QString &s) QVariant QDeclarativeStringConverters::variantFromString(const QString &s, int preferredType, bool *ok) { switch (preferredType) { + case QMetaType::Int: + return QVariant(int(qRound(s.toDouble(ok)))); + case QMetaType::UInt: + return QVariant(uint(qRound(s.toDouble(ok)))); case QMetaType::QColor: return QVariant::fromValue(colorFromString(s, ok)); case QMetaType::QDate: diff --git a/src/declarative/qml/qdeclarativetypenamescriptclass.cpp b/src/declarative/qml/qdeclarativetypenamescriptclass.cpp index 324b3de..2a3417a 100644 --- a/src/declarative/qml/qdeclarativetypenamescriptclass.cpp +++ b/src/declarative/qml/qdeclarativetypenamescriptclass.cpp @@ -159,7 +159,7 @@ void QDeclarativeTypeNameScriptClass::setProperty(Object *o, const Identifier &n Q_ASSERT(!type); QDeclarativeEnginePrivate *ep = QDeclarativeEnginePrivate::get(engine); - ep->objectClass->setProperty(((TypeNameData *)o)->object, n, v); + ep->objectClass->setProperty(((TypeNameData *)o)->object, n, v, context()); } QT_END_NAMESPACE diff --git a/src/declarative/qml/qdeclarativevme.cpp b/src/declarative/qml/qdeclarativevme.cpp index 2d1a549..0addfabd 100644 --- a/src/declarative/qml/qdeclarativevme.cpp +++ b/src/declarative/qml/qdeclarativevme.cpp @@ -345,6 +345,26 @@ QObject *QDeclarativeVME::run(QDeclarativeVMEStack<QObject *> &stack, } break; + case QDeclarativeInstruction::StoreVariantInteger: + { + QObject *target = stack.top(); + QVariant v(instr.storeInteger.value); + void *a[] = { &v, 0, &status, &flags }; + QMetaObject::metacall(target, QMetaObject::WriteProperty, + instr.storeString.propertyIndex, a); + } + break; + + case QDeclarativeInstruction::StoreVariantDouble: + { + QObject *target = stack.top(); + QVariant v(instr.storeDouble.value); + void *a[] = { &v, 0, &status, &flags }; + QMetaObject::metacall(target, QMetaObject::WriteProperty, + instr.storeString.propertyIndex, a); + } + break; + case QDeclarativeInstruction::StoreString: { QObject *target = stack.top(); diff --git a/src/declarative/qml/qdeclarativevmemetaobject.cpp b/src/declarative/qml/qdeclarativevmemetaobject.cpp index 2644ecf..2e2a8e8 100644 --- a/src/declarative/qml/qdeclarativevmemetaobject.cpp +++ b/src/declarative/qml/qdeclarativevmemetaobject.cpp @@ -671,7 +671,8 @@ QScriptValue QDeclarativeVMEMetaObject::method(int index) // XXX We should evaluate all methods in a single big script block to // improve the call time between dynamic methods defined on the same // object - methods[index] = QDeclarativeExpressionPrivate::evalInObjectScope(ctxt, object, code); + methods[index] = QDeclarativeExpressionPrivate::evalInObjectScope(ctxt, object, code, ctxt->url.toString(), + data->lineNumber, 0); } return methods[index]; diff --git a/src/declarative/qml/qdeclarativevmemetaobject_p.h b/src/declarative/qml/qdeclarativevmemetaobject_p.h index f13dd34..76390c9 100644 --- a/src/declarative/qml/qdeclarativevmemetaobject_p.h +++ b/src/declarative/qml/qdeclarativevmemetaobject_p.h @@ -94,7 +94,7 @@ struct QDeclarativeVMEMetaData int parameterCount; int bodyOffset; int bodyLength; - int scriptProgram; + int lineNumber; }; PropertyData *propertyData() const { diff --git a/src/declarative/util/qdeclarativespringfollow.cpp b/src/declarative/util/qdeclarativespringfollow.cpp index c42261d..7921735 100644 --- a/src/declarative/util/qdeclarativespringfollow.cpp +++ b/src/declarative/util/qdeclarativespringfollow.cpp @@ -59,13 +59,13 @@ class QDeclarativeSpringFollowPrivate : public QObjectPrivate Q_DECLARE_PUBLIC(QDeclarativeSpringFollow) public: QDeclarativeSpringFollowPrivate() - : currentValue(0), sourceValue(0), maxVelocity(0), lastTime(0) + : currentValue(0), to(0), maxVelocity(0), lastTime(0) , mass(1.0), spring(0.), damping(0.), velocity(0), epsilon(0.01) , modulus(0.0), useMass(false), haveModulus(false), enabled(true), mode(Track), clock(this) {} QDeclarativeProperty property; qreal currentValue; - qreal sourceValue; + qreal to; qreal maxVelocity; qreal velocityms; int lastTime; @@ -102,7 +102,7 @@ void QDeclarativeSpringFollowPrivate::tick(int time) int elapsed = time - lastTime; if (!elapsed) return; - qreal srcVal = sourceValue; + qreal srcVal = to; if (haveModulus) { currentValue = fmod(currentValue, modulus); srcVal = fmod(srcVal, modulus); @@ -158,16 +158,16 @@ void QDeclarativeSpringFollowPrivate::tick(int time) currentValue += moveBy; if (haveModulus) currentValue = fmod(currentValue, modulus); - if (currentValue > sourceValue) { - currentValue = sourceValue; + if (currentValue > to) { + currentValue = to; clock.stop(); } } else { currentValue -= moveBy; if (haveModulus && currentValue < 0.0) currentValue = fmod(currentValue, modulus) + modulus; - if (currentValue < sourceValue) { - currentValue = sourceValue; + if (currentValue < to) { + currentValue = to; clock.stop(); } } @@ -196,9 +196,9 @@ void QDeclarativeSpringFollowPrivate::start() Q_Q(QDeclarativeSpringFollow); if (mode == QDeclarativeSpringFollowPrivate::Track) { - currentValue = sourceValue; + currentValue = to; property.write(currentValue); - } else if (sourceValue != currentValue && clock.state() != QAbstractAnimation::Running) { + } else if (to != currentValue && clock.state() != QAbstractAnimation::Running) { lastTime = 0; currentValue = property.read().toReal(); clock.start(); // infinity?? @@ -239,7 +239,7 @@ void QDeclarativeSpringFollowPrivate::stop() x: rect1.width width: 20; height: 20 color: "#ff0000" - SpringFollow on y { source: rect1.y; velocity: 200 } + SpringFollow on y { to: rect1.y; velocity: 200 } } \endcode */ @@ -260,26 +260,26 @@ void QDeclarativeSpringFollow::setTarget(const QDeclarativeProperty &property) d->currentValue = property.read().toReal(); } -qreal QDeclarativeSpringFollow::sourceValue() const +qreal QDeclarativeSpringFollow::to() const { Q_D(const QDeclarativeSpringFollow); - return d->sourceValue; + return d->to; } /*! - \qmlproperty qreal SpringFollow::source - This property holds the source value which will be tracked. + \qmlproperty qreal SpringFollow::to + This property holds the target value which will be tracked. Bind to a property in order to track its changes. */ -void QDeclarativeSpringFollow::setSourceValue(qreal value) +void QDeclarativeSpringFollow::setTo(qreal value) { Q_D(QDeclarativeSpringFollow); - if (d->clock.state() == QAbstractAnimation::Running && d->sourceValue == value) + if (d->clock.state() == QAbstractAnimation::Running && d->to == value) return; - d->sourceValue = value; + d->to = value; d->start(); } @@ -307,7 +307,7 @@ void QDeclarativeSpringFollow::setVelocity(qreal velocity) This property holds the spring constant The spring constant describes how strongly the target is pulled towards the - source. Setting spring to 0 turns off spring tracking. Useful values 0 - 5.0 + source. Setting spring to 0 turns off spring tracking. Useful values 0 - 5.0 When a spring constant is set and the velocity property is greater than 0, velocity limits the maximum speed. @@ -417,13 +417,10 @@ void QDeclarativeSpringFollow::setMass(qreal mass) } /*! - \qmlproperty qreal SpringFollow::value - The current value. -*/ - -/*! \qmlproperty bool SpringFollow::enabled This property holds whether the target will track the source. + + The default value of this property is 'true'. */ bool QDeclarativeSpringFollow::enabled() const { @@ -454,6 +451,10 @@ bool QDeclarativeSpringFollow::inSync() const return d->enabled && d->clock.state() != QAbstractAnimation::Running; } +/*! + \qmlproperty qreal SpringFollow::value + The current value. +*/ qreal QDeclarativeSpringFollow::value() const { Q_D(const QDeclarativeSpringFollow); diff --git a/src/declarative/util/qdeclarativespringfollow_p.h b/src/declarative/util/qdeclarativespringfollow_p.h index 2ac0d82..b829c57 100644 --- a/src/declarative/util/qdeclarativespringfollow_p.h +++ b/src/declarative/util/qdeclarativespringfollow_p.h @@ -59,7 +59,7 @@ class Q_DECLARATIVE_EXPORT QDeclarativeSpringFollow : public QObject, Q_DECLARE_PRIVATE(QDeclarativeSpringFollow) Q_INTERFACES(QDeclarativePropertyValueSource) - Q_PROPERTY(qreal source READ sourceValue WRITE setSourceValue) + Q_PROPERTY(qreal to READ to WRITE setTo) Q_PROPERTY(qreal velocity READ velocity WRITE setVelocity) Q_PROPERTY(qreal spring READ spring WRITE setSpring) Q_PROPERTY(qreal damping READ damping WRITE setDamping) @@ -76,22 +76,30 @@ public: virtual void setTarget(const QDeclarativeProperty &); - qreal sourceValue() const; - void setSourceValue(qreal value); + qreal to() const; + void setTo(qreal value); + qreal velocity() const; void setVelocity(qreal velocity); + qreal spring() const; void setSpring(qreal spring); + qreal damping() const; void setDamping(qreal damping); + qreal epsilon() const; void setEpsilon(qreal epsilon); + qreal mass() const; void setMass(qreal modulus); + qreal modulus() const; void setModulus(qreal modulus); + bool enabled() const; void setEnabled(bool enabled); + bool inSync() const; qreal value() const; diff --git a/src/declarative/util/qdeclarativexmllistmodel.cpp b/src/declarative/util/qdeclarativexmllistmodel.cpp index b33af06..7f8b962 100644 --- a/src/declarative/util/qdeclarativexmllistmodel.cpp +++ b/src/declarative/util/qdeclarativexmllistmodel.cpp @@ -160,7 +160,7 @@ public: for (int i=0; i<roleObjects->count(); i++) { if (!roleObjects->at(i)->isValid()) { - job.roleQueries << ""; + job.roleQueries << QString(); continue; } job.roleQueries << roleObjects->at(i)->query(); diff --git a/tests/auto/declarative/declarative.pro b/tests/auto/declarative/declarative.pro index 11d7c13..5441311 100644 --- a/tests/auto/declarative/declarative.pro +++ b/tests/auto/declarative/declarative.pro @@ -1,5 +1,6 @@ TEMPLATE = subdirs SUBDIRS += \ + examples \ graphicswidgets \ # Cover parserstress \ # Cover qmetaobjectbuilder \ # Cover @@ -62,7 +63,7 @@ SUBDIRS += \ qdeclarativeimageprovider \ # Cover qdeclarativestyledtext \ # Cover sql \ # Cover - qmlvisual + qmlvisual # Cover contains(QT_CONFIG, webkit) { SUBDIRS += \ diff --git a/tests/auto/declarative/examples/tst_examples.cpp b/tests/auto/declarative/examples/tst_examples.cpp index 678dd59..dbd1f92 100644 --- a/tests/auto/declarative/examples/tst_examples.cpp +++ b/tests/auto/declarative/examples/tst_examples.cpp @@ -185,10 +185,10 @@ void tst_examples::examples() QFileInfo fi(file); QFileInfo dir(fi.path()); - QString script = "data/"+dir.baseName()+"/"+fi.baseName(); + QString script = SRCDIR "/data/"+dir.baseName()+"/"+fi.baseName(); QFileInfo testdata(script+".qml"); QStringList arguments; - arguments << "-script" << (testdata.exists() ? script : QLatin1String("data/dummytest")) + arguments << "-script" << (testdata.exists() ? script : QLatin1String(SRCDIR "/data/dummytest")) << "-scriptopts" << "play,testerror,exitoncomplete,exitonfailure" << file; QProcess p; diff --git a/tests/auto/declarative/qdeclarativeanchors/tst_qdeclarativeanchors.cpp b/tests/auto/declarative/qdeclarativeanchors/tst_qdeclarativeanchors.cpp index 16ae7fc..9eaa400 100644 --- a/tests/auto/declarative/qdeclarativeanchors/tst_qdeclarativeanchors.cpp +++ b/tests/auto/declarative/qdeclarativeanchors/tst_qdeclarativeanchors.cpp @@ -372,6 +372,16 @@ void tst_qdeclarativeanchors::crash1() QUrl source(QUrl::fromLocalFile(SRCDIR "/data/crash1.qml")); QString expect = "QML Text (" + source.toString() + ":4:5" + ") Possible anchor loop detected on fill."; + + QTest::ignoreMessage(QtWarningMsg, expect.toLatin1()); + + // QT-3245 ... anchor loop detection needs improving. + QTest::ignoreMessage(QtWarningMsg, expect.toLatin1()); + QTest::ignoreMessage(QtWarningMsg, expect.toLatin1()); + QTest::ignoreMessage(QtWarningMsg, expect.toLatin1()); + QTest::ignoreMessage(QtWarningMsg, expect.toLatin1()); + QTest::ignoreMessage(QtWarningMsg, expect.toLatin1()); + QTest::ignoreMessage(QtWarningMsg, expect.toLatin1()); QTest::ignoreMessage(QtWarningMsg, expect.toLatin1()); QDeclarativeView *view = new QDeclarativeView(source); diff --git a/tests/auto/declarative/qdeclarativeanimatedimage/data/stickmanerror1.qml b/tests/auto/declarative/qdeclarativeanimatedimage/data/stickmanerror1.qml new file mode 100644 index 0000000..5b0bdcb --- /dev/null +++ b/tests/auto/declarative/qdeclarativeanimatedimage/data/stickmanerror1.qml @@ -0,0 +1,6 @@ +import Qt 4.6 + +AnimatedImage { + sourceSize: "240x180" + source: "stickman.gif" +} diff --git a/tests/auto/declarative/qdeclarativeanimatedimage/data/stickmanscaled.qml b/tests/auto/declarative/qdeclarativeanimatedimage/data/stickmanscaled.qml new file mode 100644 index 0000000..f4d277a --- /dev/null +++ b/tests/auto/declarative/qdeclarativeanimatedimage/data/stickmanscaled.qml @@ -0,0 +1,7 @@ +import Qt 4.6 + +AnimatedImage { + width: 240 + height: 180 + source: "stickman.gif" +} diff --git a/tests/auto/declarative/qdeclarativeanimatedimage/tst_qdeclarativeanimatedimage.cpp b/tests/auto/declarative/qdeclarativeanimatedimage/tst_qdeclarativeanimatedimage.cpp index 31efc64..39ce9eb 100644 --- a/tests/auto/declarative/qdeclarativeanimatedimage/tst_qdeclarativeanimatedimage.cpp +++ b/tests/auto/declarative/qdeclarativeanimatedimage/tst_qdeclarativeanimatedimage.cpp @@ -72,6 +72,8 @@ private slots: void frameCount(); void remote(); void remote_data(); + void sourceSize(); + void sourceSizeReadOnly(); void invalidSource(); }; @@ -155,10 +157,32 @@ void tst_qdeclarativeanimatedimage::remote() TRY_WAIT(anim->isPaused()); QCOMPARE(anim->currentFrame(), 2); } + QVERIFY(anim->status() != QDeclarativeAnimatedImage::Error); delete anim; } +void tst_qdeclarativeanimatedimage::sourceSize() +{ + QDeclarativeEngine engine; + QDeclarativeComponent component(&engine, QUrl::fromLocalFile(SRCDIR "/data/stickmanscaled.qml")); + QDeclarativeAnimatedImage *anim = qobject_cast<QDeclarativeAnimatedImage *>(component.create()); + QVERIFY(anim); + QCOMPARE(anim->width(),240.0); + QCOMPARE(anim->height(),180.0); + QCOMPARE(anim->sourceSize(),QSize(160,120)); + + delete anim; +} + +void tst_qdeclarativeanimatedimage::sourceSizeReadOnly() +{ + QDeclarativeEngine engine; + QDeclarativeComponent component(&engine, QUrl::fromLocalFile(SRCDIR "/data/stickmanerror1.qml")); + QVERIFY(component.isError()); + QCOMPARE(component.errors().at(0).description(), QString("Invalid property assignment: \"sourceSize\" is a read-only property")); +} + void tst_qdeclarativeanimatedimage::remote_data() { QTest::addColumn<QString>("fileName"); diff --git a/tests/auto/declarative/qdeclarativedom/tst_qdeclarativedom.cpp b/tests/auto/declarative/qdeclarativedom/tst_qdeclarativedom.cpp index e8bbb86..1cbe2ac 100644 --- a/tests/auto/declarative/qdeclarativedom/tst_qdeclarativedom.cpp +++ b/tests/auto/declarative/qdeclarativedom/tst_qdeclarativedom.cpp @@ -274,7 +274,7 @@ void tst_qdeclarativedom::loadComposite() void tst_qdeclarativedom::testValueSource() { QByteArray qml = "import Qt 4.6\n" - "Rectangle { SpringFollow on height { spring: 1.4; damping: .15; source: Math.min(Math.max(-130, value*2.2 - 130), 133); }}"; + "Rectangle { SpringFollow on height { spring: 1.4; damping: .15; to: Math.min(Math.max(-130, value*2.2 - 130), 133); }}"; QDeclarativeEngine freshEngine; QDeclarativeDomDocument document; @@ -297,7 +297,7 @@ void tst_qdeclarativedom::testValueSource() QVERIFY(springValue.isLiteral()); QVERIFY(springValue.toLiteral().literal() == "1.4"); - const QDeclarativeDomValue sourceValue = valueSourceObject.property("source").value(); + const QDeclarativeDomValue sourceValue = valueSourceObject.property("to").value(); QVERIFY(!sourceValue.isInvalid()); QVERIFY(sourceValue.isBinding()); QVERIFY(sourceValue.toBinding().binding() == "Math.min(Math.max(-130, value*2.2 - 130), 133)"); diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/deletedEngine.qml b/tests/auto/declarative/qdeclarativeecmascript/data/deletedEngine.qml new file mode 100644 index 0000000..6c538fe --- /dev/null +++ b/tests/auto/declarative/qdeclarativeecmascript/data/deletedEngine.qml @@ -0,0 +1,11 @@ +import Qt 4.6 + +QtObject { + function calculate() { + return b * 13; + } + + property int a: calculate() + property int b: 3 +} + diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/functionErrors.qml b/tests/auto/declarative/qdeclarativeecmascript/data/functionErrors.qml new file mode 100644 index 0000000..4aca111 --- /dev/null +++ b/tests/auto/declarative/qdeclarativeecmascript/data/functionErrors.qml @@ -0,0 +1,10 @@ +import Qt 4.6 + +QtObject { + function myFunction() { + a = 10; + } + + Component.onCompleted: myFunction(); +} + diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/nullObjectBinding.qml b/tests/auto/declarative/qdeclarativeecmascript/data/nullObjectBinding.qml new file mode 100644 index 0000000..1bf0b81 --- /dev/null +++ b/tests/auto/declarative/qdeclarativeecmascript/data/nullObjectBinding.qml @@ -0,0 +1,8 @@ +import Qt 4.6 + +QtObject { + property QtObject test + test: if (1) model + property ListModel model +} + diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/numberAssignment.qml b/tests/auto/declarative/qdeclarativeecmascript/data/numberAssignment.qml new file mode 100644 index 0000000..30a77e8 --- /dev/null +++ b/tests/auto/declarative/qdeclarativeecmascript/data/numberAssignment.qml @@ -0,0 +1,18 @@ +import Qt.test 1.0 + +NumberAssignment { + test1: if (1) 6.7 + test2: if (1) "6.7" + test3: if (1) 6 + test4: if (1) "6" + + test5: if (1) 6.7 + test6: if (1) "6.7" + test7: if (1) 6 + test8: if (1) "6" + + test9: if (1) 6.7 + test10: if (1) "6.7" + test11: if (1) 6 + test12: if (1) "6" +} diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/propertyAssignmentErrors.qml b/tests/auto/declarative/qdeclarativeecmascript/data/propertyAssignmentErrors.qml new file mode 100644 index 0000000..483179a --- /dev/null +++ b/tests/auto/declarative/qdeclarativeecmascript/data/propertyAssignmentErrors.qml @@ -0,0 +1,28 @@ +import Qt 4.6 + +QtObject { + id: root + + property int a + property var b + + Component.onCompleted: { + try { + root.a = undefined; + } catch(e) { + console.log (e.fileName + ":" + e.lineNumber + ":" + e); + } + + try { + root.b = [ 10, root ] + } catch(e) { + console.log (e.fileName + ":" + e.lineNumber + ":" + e); + } + + try { + root.a = "Hello"; + } catch(e) { + console.log (e.fileName + ":" + e.lineNumber + ":" + e); + } + } +} diff --git a/tests/auto/declarative/qdeclarativeecmascript/testtypes.cpp b/tests/auto/declarative/qdeclarativeecmascript/testtypes.cpp index a3bcb6a..0d07055 100644 --- a/tests/auto/declarative/qdeclarativeecmascript/testtypes.cpp +++ b/tests/auto/declarative/qdeclarativeecmascript/testtypes.cpp @@ -80,6 +80,7 @@ void registerTypes() qmlRegisterExtendedType<MyBaseExtendedObject, BaseExtensionObject>("Qt.test", 1,0, "MyBaseExtendedObject"); qmlRegisterExtendedType<MyExtendedObject, ExtensionObject>("Qt.test", 1,0, "MyExtendedObject"); qmlRegisterType<MyTypeObject>("Qt.test", 1,0, "MyTypeObject"); + qmlRegisterType<NumberAssignment>("Qt.test", 1,0, "NumberAssignment"); } #include "testtypes.moc" diff --git a/tests/auto/declarative/qdeclarativeecmascript/testtypes.h b/tests/auto/declarative/qdeclarativeecmascript/testtypes.h index faad8b7..4424419 100644 --- a/tests/auto/declarative/qdeclarativeecmascript/testtypes.h +++ b/tests/auto/declarative/qdeclarativeecmascript/testtypes.h @@ -600,6 +600,71 @@ private: QVariantList m_actuals; }; +class NumberAssignment : public QObject +{ + Q_OBJECT +public: + Q_PROPERTY(qreal test1 READ test1 WRITE setTest1); + qreal _test1; + qreal test1() const { return _test1; } + void setTest1(qreal v) { _test1 = v; } + + Q_PROPERTY(qreal test2 READ test2 WRITE setTest2); + qreal _test2; + qreal test2() const { return _test2; } + void setTest2(qreal v) { _test2 = v; } + + Q_PROPERTY(qreal test3 READ test3 WRITE setTest3); + qreal _test3; + qreal test3() const { return _test3; } + void setTest3(qreal v) { _test3 = v; } + + Q_PROPERTY(qreal test4 READ test4 WRITE setTest4); + qreal _test4; + qreal test4() const { return _test4; } + void setTest4(qreal v) { _test4 = v; } + + Q_PROPERTY(int test5 READ test5 WRITE setTest5); + int _test5; + int test5() const { return _test5; } + void setTest5(int v) { _test5 = v; } + + Q_PROPERTY(int test6 READ test6 WRITE setTest6); + int _test6; + int test6() const { return _test6; } + void setTest6(int v) { _test6 = v; } + + Q_PROPERTY(int test7 READ test7 WRITE setTest7); + int _test7; + int test7() const { return _test7; } + void setTest7(int v) { _test7 = v; } + + Q_PROPERTY(int test8 READ test8 WRITE setTest8); + int _test8; + int test8() const { return _test8; } + void setTest8(int v) { _test8 = v; } + + Q_PROPERTY(unsigned int test9 READ test9 WRITE setTest9); + unsigned int _test9; + unsigned int test9() const { return _test9; } + void setTest9(unsigned int v) { _test9 = v; } + + Q_PROPERTY(unsigned int test10 READ test10 WRITE setTest10); + unsigned int _test10; + unsigned int test10() const { return _test10; } + void setTest10(unsigned int v) { _test10 = v; } + + Q_PROPERTY(unsigned int test11 READ test11 WRITE setTest11); + unsigned int _test11; + unsigned int test11() const { return _test11; } + void setTest11(unsigned int v) { _test11 = v; } + + Q_PROPERTY(unsigned int test12 READ test12 WRITE setTest12); + unsigned int _test12; + unsigned int test12() const { return _test12; } + void setTest12(unsigned int v) { _test12 = v; } +}; + void registerTypes(); #endif // TESTTYPES_H diff --git a/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp b/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp index 8e73afa..72f14f9 100644 --- a/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp +++ b/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp @@ -108,6 +108,8 @@ private slots: void selfDeletingBinding(); void extendedObjectPropertyLookup(); void scriptErrors(); + void functionErrors(); + void propertyAssignmentErrors(); void signalTriggeredBindings(); void listProperties(); void exceptionClearsOnReeval(); @@ -130,10 +132,13 @@ private slots: void qlistqobjectMethods(); void strictlyEquals(); void compiled(); + void numberAssignment(); void bug1(); void dynamicCreationCrash(); void regExpBug(); + void nullObjectBinding(); + void deletedEngine(); void callQtInvokables(); private: @@ -995,6 +1000,46 @@ void tst_qdeclarativeecmascript::scriptErrors() } /* +Test file/lineNumbers for inline functions. +*/ +void tst_qdeclarativeecmascript::functionErrors() +{ + QDeclarativeComponent component(&engine, TEST_FILE("functionErrors.qml")); + QString url = component.url().toString(); + + QString warning = url + ":5: Error: Invalid write to global property \"a\""; + + QTest::ignoreMessage(QtWarningMsg, warning.toLatin1().constData()); + + QObject *object = component.create(); + QVERIFY(object != 0); + delete object; +} + +/* +Test various errors that can occur when assigning a property from script +*/ +void tst_qdeclarativeecmascript::propertyAssignmentErrors() +{ + QDeclarativeComponent component(&engine, TEST_FILE("propertyAssignmentErrors.qml")); + + QString url = component.url().toString(); + + QString warning1 = url + ":11:Error: Cannot assign [undefined] to int"; + QString warning2 = url + ":17:Error: Cannot assign JavaScript array to QML variant property"; + QString warning3 = url + ":23:Error: Cannot assign QString to int"; + + QTest::ignoreMessage(QtDebugMsg, warning1.toLatin1().constData()); + QTest::ignoreMessage(QtDebugMsg, warning2.toLatin1().constData()); + QTest::ignoreMessage(QtDebugMsg, warning3.toLatin1().constData()); + + QObject *object = component.create(); + QVERIFY(object != 0); + + delete object; +} + +/* Test bindings still work when the reeval is triggered from within a signal script. */ @@ -2074,6 +2119,68 @@ void tst_qdeclarativeecmascript::compiled() delete object; } +// Test that numbers assigned in bindings as strings work consistently +void tst_qdeclarativeecmascript::numberAssignment() +{ + QDeclarativeComponent component(&engine, TEST_FILE("numberAssignment.qml")); + + QObject *object = component.create(); + QVERIFY(object != 0); + + QVERIFY(object->property("test1") == QVariant((qreal)6.7)); + QVERIFY(object->property("test2") == QVariant((qreal)6.7)); + QVERIFY(object->property("test3") == QVariant((qreal)6)); + QVERIFY(object->property("test4") == QVariant((qreal)6)); + + QVERIFY(object->property("test5") == QVariant((int)7)); + QVERIFY(object->property("test6") == QVariant((int)7)); + QVERIFY(object->property("test7") == QVariant((int)6)); + QVERIFY(object->property("test8") == QVariant((int)6)); + + QVERIFY(object->property("test9") == QVariant((unsigned int)7)); + QVERIFY(object->property("test10") == QVariant((unsigned int)7)); + QVERIFY(object->property("test11") == QVariant((unsigned int)6)); + QVERIFY(object->property("test12") == QVariant((unsigned int)6)); + + delete object; +} + +// Test that assigning a null object works +// Regressed with: df1788b4dbbb2826ae63f26bdf166342595343f4 +void tst_qdeclarativeecmascript::nullObjectBinding() +{ + QDeclarativeComponent component(&engine, TEST_FILE("nullObjectBinding.qml")); + + QObject *object = component.create(); + QVERIFY(object != 0); + + QVERIFY(object->property("test") == QVariant::fromValue((QObject *)0)); + + delete object; +} + +// Test that bindings don't evaluate once the engine has been destroyed +void tst_qdeclarativeecmascript::deletedEngine() +{ + QDeclarativeEngine *engine = new QDeclarativeEngine; + QDeclarativeComponent component(engine, TEST_FILE("deletedEngine.qml")); + + QObject *object = component.create(); + QVERIFY(object != 0); + + QCOMPARE(object->property("a").toInt(), 39); + object->setProperty("b", QVariant(9)); + QCOMPARE(object->property("a").toInt(), 117); + + delete engine; + + QCOMPARE(object->property("a").toInt(), 117); + object->setProperty("b", QVariant(10)); + QCOMPARE(object->property("a").toInt(), 117); + + delete object; +} + QTEST_MAIN(tst_qdeclarativeecmascript) #include "tst_qdeclarativeecmascript.moc" diff --git a/tests/auto/declarative/qdeclarativeinstruction/tst_qdeclarativeinstruction.cpp b/tests/auto/declarative/qdeclarativeinstruction/tst_qdeclarativeinstruction.cpp index a1aceb7..f4df130 100644 --- a/tests/auto/declarative/qdeclarativeinstruction/tst_qdeclarativeinstruction.cpp +++ b/tests/auto/declarative/qdeclarativeinstruction/tst_qdeclarativeinstruction.cpp @@ -520,6 +520,24 @@ void tst_qdeclarativeinstruction::dump() data->bytecode << i; } + { + QDeclarativeInstruction i; + i.line = 51; + i.type = QDeclarativeInstruction::StoreVariantInteger; + i.storeInteger.value = 11; + i.storeInteger.propertyIndex = 32; + data->bytecode << i; + } + + { + QDeclarativeInstruction i; + i.line = 52; + i.type = QDeclarativeInstruction::StoreVariantDouble; + i.storeDouble.value = 33.7; + i.storeDouble.propertyIndex = 19; + data->bytecode << i; + } + QStringList expect; expect << "Index\tLine\tOperation\t\tData1\tData2\tData3\tComments" @@ -575,6 +593,8 @@ void tst_qdeclarativeinstruction::dump() << "47\t\tNA\tDEFER\t\t\t7" << "48\t\t48\tSTORE_IMPORTED_SCRIPT\t2" << "49\t\t50\tXXX UNKOWN INSTRUCTION\t1234" + << "50\t\t51\tSTORE_VARIANT_INTEGER\t\t32\t11" + << "51\t\t52\tSTORE_VARIANT_DOUBLE\t\t19\t33.7" << "-------------------------------------------------------------------------------"; messages = QStringList(); diff --git a/tests/auto/declarative/qdeclarativelanguage/data/assignLiteralToVariant.qml b/tests/auto/declarative/qdeclarativelanguage/data/assignLiteralToVariant.qml new file mode 100644 index 0000000..a1d33ef --- /dev/null +++ b/tests/auto/declarative/qdeclarativelanguage/data/assignLiteralToVariant.qml @@ -0,0 +1,14 @@ +import Qt 4.6 + +QtObject { + property var test1: 1 + property var test2: 1.7 + property var test3: "Hello world!" + property var test4: "#FF008800" + property var test5: "10,10,10x10" + property var test6: "10,10" + property var test7: "10x10" + property var test8: "100,100,100" + property var test9: String("#FF008800") +} + diff --git a/tests/auto/declarative/qdeclarativelanguage/tst_qdeclarativelanguage.cpp b/tests/auto/declarative/qdeclarativelanguage/tst_qdeclarativelanguage.cpp index bf10a01..bfb56ba 100644 --- a/tests/auto/declarative/qdeclarativelanguage/tst_qdeclarativelanguage.cpp +++ b/tests/auto/declarative/qdeclarativelanguage/tst_qdeclarativelanguage.cpp @@ -87,6 +87,7 @@ private slots: void assignBasicTypes(); void assignTypeExtremes(); void assignCompositeToType(); + void assignLiteralToVariant(); void customParserTypes(); void rootAsQmlComponent(); void inlineQmlComponents(); @@ -479,6 +480,37 @@ void tst_qdeclarativelanguage::assignCompositeToType() QVERIFY(object != 0); } +// Test that literals are stored correctly in variant properties +void tst_qdeclarativelanguage::assignLiteralToVariant() +{ + QDeclarativeComponent component(&engine, TEST_FILE("assignLiteralToVariant.qml")); + VERIFY_ERRORS(0); + QObject *object = component.create(); + QVERIFY(object != 0); + + QCOMPARE(object->property("test1").userType(), (int)QVariant::Int); + QCOMPARE(object->property("test2").userType(), (int)QMetaType::Double); + QCOMPARE(object->property("test3").userType(), (int)QVariant::String); + QCOMPARE(object->property("test4").userType(), (int)QVariant::Color); + QCOMPARE(object->property("test5").userType(), (int)QVariant::RectF); + QCOMPARE(object->property("test6").userType(), (int)QVariant::PointF); + QCOMPARE(object->property("test7").userType(), (int)QVariant::SizeF); + QCOMPARE(object->property("test8").userType(), (int)QVariant::Vector3D); + QCOMPARE(object->property("test9").userType(), (int)QVariant::String); + + QVERIFY(object->property("test1") == QVariant(1)); + QVERIFY(object->property("test2") == QVariant((double)1.7)); + QVERIFY(object->property("test3") == QVariant(QString(QLatin1String("Hello world!")))); + QVERIFY(object->property("test4") == QVariant(QColor::fromRgb(0xFF008800))); + QVERIFY(object->property("test5") == QVariant(QRectF(10, 10, 10, 10))); + QVERIFY(object->property("test6") == QVariant(QPointF(10, 10))); + QVERIFY(object->property("test7") == QVariant(QSizeF(10, 10))); + QVERIFY(object->property("test8") == QVariant(QVector3D(100, 100, 100))); + QVERIFY(object->property("test9") == QVariant(QString(QLatin1String("#FF008800")))); + + delete object; +} + // Tests that custom parser types can be instantiated void tst_qdeclarativelanguage::customParserTypes() { diff --git a/tests/auto/declarative/qdeclarativespringfollow/data/springfollow2.qml b/tests/auto/declarative/qdeclarativespringfollow/data/springfollow2.qml index 7c81fb5..ffbf7d5 100644 --- a/tests/auto/declarative/qdeclarativespringfollow/data/springfollow2.qml +++ b/tests/auto/declarative/qdeclarativespringfollow/data/springfollow2.qml @@ -1,7 +1,7 @@ import Qt 4.6 SpringFollow { - source: 1.44; velocity: 0.9 + to: 1.44; velocity: 0.9 spring: 1.0; damping: 0.5 epsilon: 0.25; modulus: 360.0 mass: 2.0; enabled: true diff --git a/tests/auto/declarative/qdeclarativespringfollow/data/springfollow3.qml b/tests/auto/declarative/qdeclarativespringfollow/data/springfollow3.qml index 6fec55b..9a8f6f3 100644 --- a/tests/auto/declarative/qdeclarativespringfollow/data/springfollow3.qml +++ b/tests/auto/declarative/qdeclarativespringfollow/data/springfollow3.qml @@ -1,7 +1,7 @@ import Qt 4.6 SpringFollow { - source: 1.44; velocity: 0.9 + to: 1.44; velocity: 0.9 spring: 1.0; damping: 0.5 epsilon: 0.25; modulus: 360.0 mass: 2.0; enabled: false diff --git a/tests/auto/declarative/qdeclarativespringfollow/tst_qdeclarativespringfollow.cpp b/tests/auto/declarative/qdeclarativespringfollow/tst_qdeclarativespringfollow.cpp index 7a60e78..8a07d6b 100644 --- a/tests/auto/declarative/qdeclarativespringfollow/tst_qdeclarativespringfollow.cpp +++ b/tests/auto/declarative/qdeclarativespringfollow/tst_qdeclarativespringfollow.cpp @@ -72,7 +72,7 @@ void tst_qdeclarativespringfollow::defaultValues() QVERIFY(obj != 0); - QCOMPARE(obj->sourceValue(), 0.); + QCOMPARE(obj->to(), 0.); QCOMPARE(obj->velocity(), 0.); QCOMPARE(obj->spring(), 0.); QCOMPARE(obj->damping(), 0.); @@ -94,7 +94,7 @@ void tst_qdeclarativespringfollow::values() QVERIFY(obj != 0); - QCOMPARE(obj->sourceValue(), 1.44); + QCOMPARE(obj->to(), 1.44); QCOMPARE(obj->velocity(), 0.9); QCOMPARE(obj->spring(), 1.0); QCOMPARE(obj->damping(), 0.5); @@ -117,7 +117,7 @@ void tst_qdeclarativespringfollow::disabled() QVERIFY(obj != 0); - QCOMPARE(obj->sourceValue(), 1.44); + QCOMPARE(obj->to(), 1.44); QCOMPARE(obj->velocity(), 0.9); QCOMPARE(obj->spring(), 1.0); QCOMPARE(obj->damping(), 0.5); diff --git a/tests/auto/declarative/qdeclarativevaluetypes/data/sizereadonly_read.qml b/tests/auto/declarative/qdeclarativevaluetypes/data/sizereadonly_read.qml new file mode 100644 index 0000000..7abe359 --- /dev/null +++ b/tests/auto/declarative/qdeclarativevaluetypes/data/sizereadonly_read.qml @@ -0,0 +1,8 @@ +import Test 1.0 + +MyTypeObject { + property int s_width: sizereadonly.width + property int s_height: sizereadonly.height + property var copy: sizereadonly +} + diff --git a/tests/auto/declarative/qdeclarativevaluetypes/data/sizereadonly_writeerror.qml b/tests/auto/declarative/qdeclarativevaluetypes/data/sizereadonly_writeerror.qml new file mode 100644 index 0000000..3254557 --- /dev/null +++ b/tests/auto/declarative/qdeclarativevaluetypes/data/sizereadonly_writeerror.qml @@ -0,0 +1,6 @@ +import Test 1.0 + +MyTypeObject { + sizereadonly: "13x88" +} + diff --git a/tests/auto/declarative/qdeclarativevaluetypes/data/sizereadonly_writeerror2.qml b/tests/auto/declarative/qdeclarativevaluetypes/data/sizereadonly_writeerror2.qml new file mode 100644 index 0000000..656d718 --- /dev/null +++ b/tests/auto/declarative/qdeclarativevaluetypes/data/sizereadonly_writeerror2.qml @@ -0,0 +1,7 @@ +import Test 1.0 + +MyTypeObject { + sizereadonly.width: if (true) 13 + sizereadonly.height: if (true) 88 +} + diff --git a/tests/auto/declarative/qdeclarativevaluetypes/testtypes.h b/tests/auto/declarative/qdeclarativevaluetypes/testtypes.h index 0ad8449..9057b4f 100644 --- a/tests/auto/declarative/qdeclarativevaluetypes/testtypes.h +++ b/tests/auto/declarative/qdeclarativevaluetypes/testtypes.h @@ -63,6 +63,7 @@ class MyTypeObject : public QObject Q_PROPERTY(QPointF pointf READ pointf WRITE setPointf NOTIFY changed) Q_PROPERTY(QSize size READ size WRITE setSize NOTIFY changed) Q_PROPERTY(QSizeF sizef READ sizef WRITE setSizef NOTIFY changed) + Q_PROPERTY(QSize sizereadonly READ size NOTIFY changed) Q_PROPERTY(QRect rect READ rect WRITE setRect NOTIFY changed) Q_PROPERTY(QRectF rectf READ rectf WRITE setRectf NOTIFY changed) Q_PROPERTY(QVector3D vector READ vector WRITE setVector NOTIFY changed) @@ -134,6 +135,7 @@ QML_DECLARE_TYPE(MyTypeObject); class MyConstantValueSource : public QObject, public QDeclarativePropertyValueSource { Q_OBJECT + Q_INTERFACES(QDeclarativePropertyValueSource) public: virtual void setTarget(const QDeclarativeProperty &p) { p.write(3345); } }; @@ -142,6 +144,7 @@ QML_DECLARE_TYPE(MyConstantValueSource); class MyOffsetValueInterceptor : public QObject, public QDeclarativePropertyValueInterceptor { Q_OBJECT + Q_INTERFACES(QDeclarativePropertyValueInterceptor) public: virtual void setTarget(const QDeclarativeProperty &p) { prop = p; } virtual void write(const QVariant &value) { QDeclarativePropertyPrivate::write(prop, value.toInt() + 13, QDeclarativePropertyPrivate::BypassInterceptor); } diff --git a/tests/auto/declarative/qdeclarativevaluetypes/tst_qdeclarativevaluetypes.cpp b/tests/auto/declarative/qdeclarativevaluetypes/tst_qdeclarativevaluetypes.cpp index fb487f0..c74199f 100644 --- a/tests/auto/declarative/qdeclarativevaluetypes/tst_qdeclarativevaluetypes.cpp +++ b/tests/auto/declarative/qdeclarativevaluetypes/tst_qdeclarativevaluetypes.cpp @@ -59,6 +59,7 @@ private slots: void pointf(); void size(); void sizef(); + void sizereadonly(); void rect(); void rectf(); void vector3d(); @@ -193,6 +194,34 @@ void tst_qdeclarativevaluetypes::sizef() } } +void tst_qdeclarativevaluetypes::sizereadonly() +{ + { + QDeclarativeComponent component(&engine, TEST_FILE("sizereadonly_read.qml")); + MyTypeObject *object = qobject_cast<MyTypeObject *>(component.create()); + QVERIFY(object != 0); + + QCOMPARE(object->property("s_width").toInt(), 1912); + QCOMPARE(object->property("s_height").toInt(), 1913); + QCOMPARE(object->property("copy"), QVariant(QSize(1912, 1913))); + + delete object; + } + + { + QDeclarativeComponent component(&engine, TEST_FILE("sizereadonly_writeerror.qml")); + QVERIFY(component.isError()); + QCOMPARE(component.errors().at(0).description(), QLatin1String("Invalid property assignment: \"sizereadonly\" is a read-only property")); + } + + { + QDeclarativeComponent component(&engine, TEST_FILE("sizereadonly_writeerror2.qml")); + QEXPECT_FAIL("", "QTBUG-9685", Abort); + QVERIFY(component.isError()); + QCOMPARE(component.errors().at(0).description(), QLatin1String("Invalid property assignment: \"sizereadonly\" is a read-only property")); + } +} + void tst_qdeclarativevaluetypes::rect() { { diff --git a/tests/auto/declarative/qmlvisual/qdeclarativemousearea/data/drag.0.png b/tests/auto/declarative/qmlvisual/qdeclarativemousearea/data/drag.0.png Binary files differindex cf36d60..5b7b426 100644 --- a/tests/auto/declarative/qmlvisual/qdeclarativemousearea/data/drag.0.png +++ b/tests/auto/declarative/qmlvisual/qdeclarativemousearea/data/drag.0.png diff --git a/tests/auto/declarative/qmlvisual/qdeclarativemousearea/data/drag.1.png b/tests/auto/declarative/qmlvisual/qdeclarativemousearea/data/drag.1.png Binary files differindex 6069df8..7c27310 100644 --- a/tests/auto/declarative/qmlvisual/qdeclarativemousearea/data/drag.1.png +++ b/tests/auto/declarative/qmlvisual/qdeclarativemousearea/data/drag.1.png diff --git a/tests/auto/declarative/qmlvisual/qdeclarativemousearea/data/drag.2.png b/tests/auto/declarative/qmlvisual/qdeclarativemousearea/data/drag.2.png Binary files differindex b8bd5f3..cbfdb23 100644 --- a/tests/auto/declarative/qmlvisual/qdeclarativemousearea/data/drag.2.png +++ b/tests/auto/declarative/qmlvisual/qdeclarativemousearea/data/drag.2.png diff --git a/tests/auto/declarative/qmlvisual/qdeclarativemousearea/data/drag.3.png b/tests/auto/declarative/qmlvisual/qdeclarativemousearea/data/drag.3.png Binary files differindex cf36d60..5b7b426 100644 --- a/tests/auto/declarative/qmlvisual/qdeclarativemousearea/data/drag.3.png +++ b/tests/auto/declarative/qmlvisual/qdeclarativemousearea/data/drag.3.png diff --git a/tests/auto/declarative/qmlvisual/qdeclarativemousearea/data/drag.4.png b/tests/auto/declarative/qmlvisual/qdeclarativemousearea/data/drag.4.png Binary files differindex 831d6b4..5af705e 100644 --- a/tests/auto/declarative/qmlvisual/qdeclarativemousearea/data/drag.4.png +++ b/tests/auto/declarative/qmlvisual/qdeclarativemousearea/data/drag.4.png diff --git a/tests/auto/declarative/qmlvisual/qdeclarativemousearea/data/drag.5.png b/tests/auto/declarative/qmlvisual/qdeclarativemousearea/data/drag.5.png Binary files differindex f7079dc..af4395e 100644 --- a/tests/auto/declarative/qmlvisual/qdeclarativemousearea/data/drag.5.png +++ b/tests/auto/declarative/qmlvisual/qdeclarativemousearea/data/drag.5.png diff --git a/tests/auto/declarative/qmlvisual/qdeclarativemousearea/data/drag.6.png b/tests/auto/declarative/qmlvisual/qdeclarativemousearea/data/drag.6.png Binary files differindex a5f4451..cd12bc9 100644 --- a/tests/auto/declarative/qmlvisual/qdeclarativemousearea/data/drag.6.png +++ b/tests/auto/declarative/qmlvisual/qdeclarativemousearea/data/drag.6.png diff --git a/tests/auto/declarative/qmlvisual/qdeclarativemousearea/data/drag.7.png b/tests/auto/declarative/qmlvisual/qdeclarativemousearea/data/drag.7.png Binary files differindex e1261d0..471c86b 100644 --- a/tests/auto/declarative/qmlvisual/qdeclarativemousearea/data/drag.7.png +++ b/tests/auto/declarative/qmlvisual/qdeclarativemousearea/data/drag.7.png diff --git a/tests/auto/declarative/qmlvisual/qdeclarativemousearea/data/drag.qml b/tests/auto/declarative/qmlvisual/qdeclarativemousearea/data/drag.qml index 5a131e9..f3071e4 100644 --- a/tests/auto/declarative/qmlvisual/qdeclarativemousearea/data/drag.qml +++ b/tests/auto/declarative/qmlvisual/qdeclarativemousearea/data/drag.qml @@ -486,7 +486,7 @@ VisualTest { } Frame { msec: 1840 - hash: "b6b4b2c7acddd23609caa9727911b981" + hash: "668cc6d9d699b947a7c0f3ff4b26853f" } Mouse { type: 5 @@ -498,7 +498,7 @@ VisualTest { } Frame { msec: 1856 - hash: "b6b4b2c7acddd23609caa9727911b981" + hash: "668cc6d9d699b947a7c0f3ff4b26853f" } Mouse { type: 5 @@ -510,7 +510,7 @@ VisualTest { } Frame { msec: 1872 - hash: "022610222cfbcf9e9a8991cdb60c7bbb" + hash: "668cc6d9d699b947a7c0f3ff4b26853f" } Mouse { type: 5 @@ -522,7 +522,7 @@ VisualTest { } Frame { msec: 1888 - hash: "9b5201a3201a102b20592d81218b5e74" + hash: "668cc6d9d699b947a7c0f3ff4b26853f" } Mouse { type: 5 diff --git a/tests/auto/declarative/qmlvisual/qdeclarativespringfollow/clock.qml b/tests/auto/declarative/qmlvisual/qdeclarativespringfollow/clock.qml index 21bbc7f..fbab4b7 100644 --- a/tests/auto/declarative/qmlvisual/qdeclarativespringfollow/clock.qml +++ b/tests/auto/declarative/qmlvisual/qdeclarativespringfollow/clock.qml @@ -25,7 +25,7 @@ Rectangle { origin.x: 7.5; origin.y: 73; angle: 0 SpringFollow on angle { spring: 2; damping: 0.2; modulus: 360 - source: (clock.hours * 30) + (clock.minutes * 0.5) + to: (clock.hours * 30) + (clock.minutes * 0.5) } } } @@ -39,7 +39,7 @@ Rectangle { origin.x: 6.5; origin.y: 83; angle: 0 SpringFollow on angle { spring: 2; damping: 0.2; modulus: 360 - source: clock.minutes * 6 + to: clock.minutes * 6 } } } @@ -53,7 +53,7 @@ Rectangle { origin.x: 2.5; origin.y: 80; angle: 0 SpringFollow on angle { spring: 5; damping: 0.25; modulus: 360 - source: clock.seconds * 6 + to: clock.seconds * 6 } } } diff --git a/tests/auto/declarative/qmlvisual/qdeclarativespringfollow/follow.qml b/tests/auto/declarative/qmlvisual/qdeclarativespringfollow/follow.qml index 1659bb7..5368349 100644 --- a/tests/auto/declarative/qmlvisual/qdeclarativespringfollow/follow.qml +++ b/tests/auto/declarative/qmlvisual/qdeclarativespringfollow/follow.qml @@ -26,7 +26,7 @@ Rectangle { color: "#ff0000" x: rect.width; width: rect.width; height: 20 y: 200 - SpringFollow on y { source: rect.y; velocity: 200 } + SpringFollow on y { to: rect.y; velocity: 200 } } // Spring @@ -34,13 +34,13 @@ Rectangle { color: "#ff0000" x: rect.width * 2; width: rect.width/2; height: 20 y: 200 - SpringFollow on y { source: rect.y; spring: 1.0; damping: 0.2 } + SpringFollow on y { to: rect.y; spring: 1.0; damping: 0.2 } } Rectangle { color: "#880000" x: rect.width * 2.5; width: rect.width/2; height: 20 y: 200 - SpringFollow on y { source: rect.y; spring: 1.0; damping: 0.2; mass: 3.0 } // "heavier" object + SpringFollow on y { to: rect.y; spring: 1.0; damping: 0.2; mass: 3.0 } // "heavier" object } // Follow mouse @@ -52,8 +52,8 @@ Rectangle { width: 20; height: 20 radius: 10 color: "#0000ff" - SpringFollow on x { id: f1; source: mouseRegion.mouseX-10; spring: 1.0; damping: 0.05; epsilon: 0.25 } - SpringFollow on y { id: f2; source: mouseRegion.mouseY-10; spring: 1.0; damping: 0.05; epsilon: 0.25 } + SpringFollow on x { id: f1; to: mouseRegion.mouseX-10; spring: 1.0; damping: 0.05; epsilon: 0.25 } + SpringFollow on y { id: f2; to: mouseRegion.mouseY-10; spring: 1.0; damping: 0.05; epsilon: 0.25 } states: [ State { name: "following" diff --git a/tests/benchmarks/declarative/qdeclarativecomponent/data/samegame/BoomBlock.qml b/tests/benchmarks/declarative/qdeclarativecomponent/data/samegame/BoomBlock.qml index b14531d..9b88b53 100644 --- a/tests/benchmarks/declarative/qdeclarativecomponent/data/samegame/BoomBlock.qml +++ b/tests/benchmarks/declarative/qdeclarativecomponent/data/samegame/BoomBlock.qml @@ -8,8 +8,8 @@ Item { id:block property int targetX: 0 property int targetY: 0 - SpringFollow on x { enabled: spawned; source: targetX; spring: 2; damping: 0.2 } - SpringFollow on y { source: targetY; spring: 2; damping: 0.2 } + SpringFollow on x { enabled: spawned; to: targetX; spring: 2; damping: 0.2 } + SpringFollow on y { to: targetY; spring: 2; damping: 0.2 } Image { id: img source: { diff --git a/tools/qml/main.cpp b/tools/qml/main.cpp index 5099e49..01b3912 100644 --- a/tools/qml/main.cpp +++ b/tools/qml/main.cpp @@ -101,8 +101,9 @@ void usage() qWarning(" -dragthreshold <size> .................... set mouse drag threshold size"); qWarning(" -netcache <size> ......................... set disk cache to size bytes"); qWarning(" -translation <translationfile> ........... set the language to run in"); - qWarning(" -L <directory> ........................... prepend to the library search path,"); + qWarning(" -I <directory> ........................... prepend to the module import search path,"); qWarning(" display path if <directory> is empty"); + qWarning(" -P <directory> ........................... prepend to the plugin search path"); qWarning(" -opengl .................................. use a QGLWidget for the viewport"); qWarning(" -script <path> ........................... set the script to use"); qWarning(" -scriptopts <options>|help ............... set the script options to use"); @@ -167,7 +168,8 @@ int main(int argc, char ** argv) QString dither = "none"; QString recordfile; QStringList recordargs; - QStringList libraries; + QStringList imports; + QStringList plugins; QString skin; QString script; QString scriptopts; @@ -239,14 +241,19 @@ int main(int argc, char ** argv) useGL = true; } else if (arg == "-qmlbrowser") { useNativeFileBrowser = false; - } else if (arg == "-L") { + } else if (arg == "-I" || arg == "-L") { + if (arg == "-L") + fprintf(stderr, "-L option provided for compatibility only, use -I instead"); if (lastArg) { QDeclarativeEngine tmpEngine; QString paths = tmpEngine.importPathList().join(QLatin1String(":")); fprintf(stderr, "Current search path: %s\n", paths.toLocal8Bit().constData()); return 0; } - libraries << QString(argv[++i]); + imports << QString(argv[++i]); + } else if (arg == "-P") { + if (lastArg) usage(); + plugins << QString(argv[++i]); } else if (arg == "-script") { if (lastArg) usage(); script = QString(argv[++i]); @@ -320,9 +327,12 @@ int main(int argc, char ** argv) viewer.addLibraryPath(QCoreApplication::applicationDirPath()); - foreach (QString lib, libraries) + foreach (QString lib, imports) viewer.addLibraryPath(lib); + foreach (QString plugin, plugins) + viewer.addPluginPath(plugin); + viewer.setNetworkCacheSize(cache); viewer.setRecordFile(recordfile); if (resizeview) @@ -349,6 +359,21 @@ int main(int argc, char ** argv) viewer.setUseNativeFileBrowser(useNativeFileBrowser); if (fullScreen && maximized) qWarning() << "Both -fullscreen and -maximized specified. Using -fullscreen."; + + if (fileName.isEmpty()) { + QFile qmlapp(QLatin1String("qmlapp")); + if (qmlapp.exists() && qmlapp.open(QFile::ReadOnly)) { + QString content = QString::fromUtf8(qmlapp.readAll()); + qmlapp.close(); + + int newline = content.indexOf(QLatin1Char('\n')); + if (newline >= 0) + fileName = content.left(newline); + else + fileName = content; + } + } + if (!fileName.isEmpty()) { viewer.open(fileName); fullScreen ? viewer.showFullScreen() : maximized ? viewer.showMaximized() : viewer.show(); diff --git a/tools/qml/qmlruntime.cpp b/tools/qml/qmlruntime.cpp index 1ab528e..c4ebd80 100644 --- a/tools/qml/qmlruntime.cpp +++ b/tools/qml/qmlruntime.cpp @@ -870,6 +870,11 @@ void QDeclarativeViewer::addLibraryPath(const QString& lib) canvas->engine()->addImportPath(lib); } +void QDeclarativeViewer::addPluginPath(const QString& plugin) +{ + canvas->engine()->addPluginPath(plugin); +} + void QDeclarativeViewer::reload() { openQml(currentFileOrUrl); diff --git a/tools/qml/qmlruntime.h b/tools/qml/qmlruntime.h index 01777bd..6f1e425 100644 --- a/tools/qml/qmlruntime.h +++ b/tools/qml/qmlruntime.h @@ -96,6 +96,7 @@ public: void setDeviceKeys(bool); void setNetworkCacheSize(int size); void addLibraryPath(const QString& lib); + void addPluginPath(const QString& plugin); void setUseGL(bool use); void setUseNativeFileBrowser(bool); |