Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Use a list of items instead of QML children with FolderLayout

  • Loading branch information...
commit 6832c01a0b1bba1cf99b508d65379ad2b2fbbd97 1 parent 8d1ba25
@special authored
Showing with 19 additions and 16 deletions.
  1. +19 −16 qml/cascade/FolderLayout.qml
View
35 qml/cascade/FolderLayout.qml
@@ -5,9 +5,9 @@ Item {
id: layoutRoot
property QtObject directory
- property int itemCount: 16
property int padding: 8
property int desiredHeight: 250
+ property list<Item> items
Component {
id: imageItem
@@ -42,42 +42,45 @@ Item {
if (directory == null)
return
- itemCount = Math.min(directory.fileCount, 16)
+ items = []
+ var itemCount = Math.min(directory.fileCount, 16)
+ var tmpItems = new Array()
for (var i = 0; i < itemCount; i++) {
- imageItem.createObject(layoutRoot, {
+ var obj = imageItem.createObject(layoutRoot, {
"file": directory.at(i),
"visible": false
});
+ tmpItems.push(obj)
}
+ items = tmpItems
}
onWidthChanged: layout()
onPaddingChanged: layout()
onDesiredHeightChanged: layout()
- onItemCountChanged: console.log("Item count reload is not implemented")
function updateItem(item) {
- var lastLoaded = itemCount-1
- for (var i = 0; i < itemCount; i++) {
- if (!children[i].isLoaded) {
+ var lastLoaded = items.length-1
+ for (var i = 0; i < items.length; i++) {
+ if (!items[i].isLoaded) {
lastLoaded = i - 1
break
}
}
- console.log("loaded ", lastLoaded+1, "/", itemCount);
+ console.log("loaded ", lastLoaded+1, "/", items.length);
layout(0, lastLoaded+1)
}
/* This should probably be an invalidate-and-delayed-layout setup */
function layout(first, count) {
/* QML list lacks any usable functions, so convert to an Array */
- var childList = new Array()
- for (var i = 0; i < children.length; i++)
- childList.push(children[i])
+ var itemList = new Array()
+ for (var i = 0; i < items.length; i++)
+ itemList.push(items[i])
first = typeof first !== 'undefined' ? first : 0
- count = typeof count !== 'undefined' ? count : itemCount
+ count = typeof count !== 'undefined' ? count : items.length
var sumAspect = 0
var rowHeight = 0
@@ -85,20 +88,20 @@ Item {
var y = padding
for (var i = first; i < first+count; i++) {
- var c = childList[i]
+ var c = itemList[i]
sumAspect += c.sourceSize.width / c.sourceSize.height
// i+2 is number of items + 1 for the right edge pad
rowHeight = (width - padding * ((i-rowStart)+2)) / sumAspect
if (rowHeight <= desiredHeight) {
- layoutRow(childList.slice(rowStart, i+1), y, rowHeight)
+ layoutRow(itemList.slice(rowStart, i+1), y, rowHeight)
y += rowHeight + padding
sumAspect = rowHeight = 0
rowStart = i+1
}
}
- if (first + count >= itemCount && rowStart < itemCount)
- layoutRow(childList.slice(rowStart), y, Math.min(rowHeight, desiredHeight))
+ if (first + count >= items.length && rowStart < items.length)
+ layoutRow(itemList.slice(rowStart), y, Math.min(rowHeight, desiredHeight))
}
function layoutRow(items, y, height) {
Please sign in to comment.
Something went wrong with that request. Please try again.