From 1f277281ea853fb99a4187f30ec1ddaaf8b86ed2 Mon Sep 17 00:00:00 2001 From: Alan Alpert Date: Wed, 29 Jul 2009 15:53:05 +1000 Subject: Fix layout sizing Conflicts: src/declarative/fx/qfxlayouts.cpp --- src/declarative/fx/qfxlayouts.cpp | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/src/declarative/fx/qfxlayouts.cpp b/src/declarative/fx/qfxlayouts.cpp index 0546845..da34b8c 100644 --- a/src/declarative/fx/qfxlayouts.cpp +++ b/src/declarative/fx/qfxlayouts.cpp @@ -354,11 +354,14 @@ void QFxBaseLayout::preLayout() d->_animated.clear(); doLayout(); //Set the layout's size to be the rect containing all children - //Also set the margin + //d->aut determines whether a dimension is sum or max + //Also sets the margin qreal width=0; qreal height=0; + qreal maxWidth=0; + qreal maxHeight=0; foreach(QFxItem *item, d->_items){ - if (item->opacity() == 0.0){ + if (item->opacity() != 0.0){ if (!d->_animated.contains(item)){ setMovingItem(item); QPointF p(item->x(), item->y()); @@ -369,6 +372,8 @@ void QFxBaseLayout::preLayout() item->setPos(p); setMovingItem(0); } + maxWidth = qMax(maxWidth, item->width()); + maxHeight = qMax(maxHeight, item->height()); width = qMax(width, item->x() + item->width()); height = qMax(height, item->y() + item->height()); } @@ -376,14 +381,19 @@ void QFxBaseLayout::preLayout() width += d->_margin; height+= d->_margin; - if (d->aut & Horizontal) - setWidth(int(width)); - else if (parentItem()) - setImplicitWidth(parentItem()->width()); - if (d->aut & Vertical) - setHeight(int(height)); - else if (parentItem()) - setImplicitHeight(parentItem()->height()); + if(d->aut & Both){ + setImplicitHeight(int(height)); + setImplicitWidth(int(width)); + }else if (d->aut & Horizontal){ + setImplicitWidth(int(width)); + setImplicitHeight(int(maxHeight)); + } else if (d->aut & Vertical){ + setImplicitHeight(int(height)); + setImplicitWidth(int(maxWidth)); + }else{ + setImplicitHeight(int(maxHeight)); + setImplicitWidth(int(maxWidth)); + } setLayoutItem(0); } @@ -656,7 +666,6 @@ void QFxVerticalLayout::doLayout() } finishApplyTransitions(); setMovingItem(this); - setHeight(voffset); setMovingItem(0); } @@ -823,7 +832,6 @@ void QFxHorizontalLayout::doLayout() hoffset += spacing(); } finishApplyTransitions(); - setWidth(hoffset); } QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,GridLayout,QFxGridLayout) -- cgit v0.12 From 10f3d112fb61f249fc7736da85ee90ef42583fb1 Mon Sep 17 00:00:00 2001 From: Alan Alpert Date: Wed, 29 Jul 2009 16:25:45 +1000 Subject: Make SameGame Scalable Resize your window and hit new game This may invalidate high scores. --- demos/declarative/samegame/SameGame.qml | 13 +++---------- demos/declarative/samegame/content/samegame.js | 4 ++++ 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/demos/declarative/samegame/SameGame.qml b/demos/declarative/samegame/SameGame.qml index 3b80692..9e1b1ae 100644 --- a/demos/declarative/samegame/SameGame.qml +++ b/demos/declarative/samegame/SameGame.qml @@ -9,7 +9,9 @@ Rect { Rect { id: gameCanvas property int score: 0 - z:20; y:20; width:400; height:600; color: "white"; pen.width: 1 + z:20; y:20; color: "white"; pen.width: 1 + width:parent.width - tileSize - (parent.width % tileSize); + height:parent.height - tileSize - (parent.height % tileSize); anchors.horizontalCenter: parent.horizontalCenter Image { id:background; source: "content/pics/background.png" @@ -29,13 +31,4 @@ Rect { text: "Score: " + gameCanvas.score; width:100; font.size:14 anchors.top: gameCanvas.bottom; anchors.topMargin: 4; anchors.right: gameCanvas.right; } - Text { - text: "Just over 300 lines of QML/JS code!" - anchors.horizontalCenter: parent.horizontalCenter - anchors.bottom: parent.bottom; anchors.bottomMargin: 16; - opacity: SequentialAnimation{ running: true; repeat: true; - NumberAnimation { from: 0; to: 1; duration: 1000; easing: "easeInQuad" } - NumberAnimation { from: 1; to: 0; duration: 1000; easing: "easeInQuad" } - } - } } diff --git a/demos/declarative/samegame/content/samegame.js b/demos/declarative/samegame/content/samegame.js index a7dd82b..f04fb4c 100755 --- a/demos/declarative/samegame/content/samegame.js +++ b/demos/declarative/samegame/content/samegame.js @@ -21,6 +21,10 @@ function initBoard() board[i].destroy(); } + maxX = Math.floor(gameCanvas.width/tileSize); + maxY = Math.floor(gameCanvas.height/tileSize); + maxIndex = maxY*maxX; + //Initialize Board board = new Array(maxIndex); gameCanvas.score = 0; -- cgit v0.12