rendered paste bodyimport QtQuick 1.0
import MeeGo.App.socialdemo 0.1
import Qt 4.7
Flickable {
id: flickable
clip: true
contentWidth: root.width; contentHeight: root.height
property variant model: null
property Component delegateItem: null
Connections {
id: connectionManager
target: model
onRowsInserted: {
root.clear()
root.fill()
}
}
function getItem(index) {
return root.children[index];
}
Item {
id: root
width: 100
height: 100
property Item selectedItem: null
function clear() {
for (var i = 0; i < root.children.length; i++) {
console.log("destroying object "+i+root.children[i]);
root.children[i].destroy();
root.children[i] = null;
}
}
function fill () {
console.log("fill called");
var lx = 0
var ly = 0
var hx = 0
var hy = 0
var T = 0;
var R = 0;
var newlist = new Array();
for (var i = 0; i < model.rowCount(); i++) {
if (delegateItem.status == Component.Ready) {
var obj = delegateItem.createObject(root);
newlist.push(obj);
// XXX: Unfornutly, we should pass properties by hand
obj["displayName"] = (model.data(i, ContactModel.DisplayNameRole))
obj["presenceMessage"] = (model.data(i, ContactModel.PresenceMessageRole))
obj["avatarImage"] = (model.data(i, ContactModel.AvatarImageRole))
obj["uuid"] = (model.data(i, ContactModel.UuidRole))
obj["index"] = i
var divs = (1 + 3*Math.log(i))
T += Math.PI / divs
R = 20 + 20*T;
obj.x = - R*Math.cos(T)
obj.y = + R*Math.sin(T)
if (obj.x < lx)
lx = obj.x
if (obj.x > hx)
hx = obj.x
if (obj.y < ly)
ly = obj.y
if (obj.y > hy)
hy = obj.y
}
}
width = hx - lx + 80;
height = hy - ly + 120;
// Repositioning elements
// It should be done on the latest loop, however I couldn't find a way
// to do that there.
for (var i = 0; i< model.rowCount(); i++) {
var object = newlist[i];
object.x = object.x + width / 2;
object.y = object.y + height / 2;
}
contentX = width / 2
contentY = height / 2
console.log("fill done"+root.children.length);
}
}
}