harbour-tooter/qml/pages/components/MediaBlock.qml

167 lines
5.3 KiB
QML
Raw Normal View History

2017-06-16 17:45:04 +03:00
import QtQuick 2.0
import Sailfish.Silica 1.0
import QtMultimedia 5.0
Item {
id: holder
2017-06-16 17:45:04 +03:00
property ListModel model
property double wRatio : 16/9
property double hRatio : 9/16
property bool debug: true
2017-06-16 17:45:04 +03:00
width: width
height: height
Component.onCompleted: {
console.log("MB: " + JSON.stringify(model.get(0)))
2017-06-16 17:45:04 +03:00
if (model && model.count && model.get(0).type === "video") {
//console.log("Mediablock")
//console.log(JSON.stringify(model.get(0).type))
2020-07-06 11:28:42 +03:00
while (model.count>1) {
2017-06-16 17:45:04 +03:00
model.remove(model.count-1)
}
}
var count = 0
if (model && model.count)
count = model.count
switch(count){
2017-06-16 17:45:04 +03:00
case 1:
placeholder1.width = holder.width
placeholder1.height = placeholder1.width*hRatio
placeholder1.visible = true;
holder.height = placeholder1.height
break;
2017-06-16 17:45:04 +03:00
case 2:
placeholder1.visible = true
placeholder2.visible = true
2017-06-16 17:45:04 +03:00
placeholder1.width = (holder.width-Theme.paddingSmall)/2
placeholder1.height = placeholder1.width
placeholder2.width = placeholder1.width
placeholder2.height = placeholder1.width
placeholder2.x = placeholder1.width + placeholder2.x + Theme.paddingSmall
holder.height = placeholder1.height
break;
2017-06-16 17:45:04 +03:00
case 3:
placeholder1.visible = true
placeholder2.visible = true
placeholder3.visible = true
placeholder4.visible = false
2017-06-16 17:45:04 +03:00
placeholder1.width = holder.width - Theme.paddingSmall - Theme.itemSizeLarge;
placeholder1.height = Theme.itemSizeLarge*2+Theme.paddingSmall
2017-07-04 02:07:39 +03:00
holder.height = placeholder1.height
2017-06-16 17:45:04 +03:00
placeholder2.width = Theme.itemSizeLarge;
2017-07-04 02:07:39 +03:00
placeholder3.height = placeholder3.width = placeholder2.height = placeholder2.width
placeholder3.x = placeholder2.x = placeholder1.x + placeholder1.width + Theme.paddingSmall;
placeholder3.y = placeholder2.y + placeholder2.height + Theme.paddingSmall;
2017-06-16 17:45:04 +03:00
break;
2017-06-16 17:45:04 +03:00
case 4:
placeholder1.visible = true
placeholder2.visible = true
placeholder3.visible = true
placeholder4.visible = true
2017-06-16 17:45:04 +03:00
placeholder1.width = placeholder2.width = placeholder3.width = placeholder4.width = (holder.width - 3*Theme.paddingSmall)/4
placeholder1.height = placeholder2.height = placeholder3.height = placeholder4.height = Theme.itemSizeLarge*2+Theme.paddingSmall
placeholder2.x = 1*(placeholder1.width)+ 1*Theme.paddingSmall
placeholder3.x = 2*(placeholder1.width)+ 2*Theme.paddingSmall
placeholder4.x = 3*(placeholder1.width)+ 3*Theme.paddingSmall
2017-06-16 17:45:04 +03:00
holder.height = placeholder1.height
2017-06-16 17:45:04 +03:00
break;
2017-06-16 17:45:04 +03:00
default:
holder.height = 0
2017-07-04 02:07:39 +03:00
placeholder1.visible = placeholder2.visible = placeholder3.visible = placeholder4.visible = false;
2017-06-16 17:45:04 +03:00
}
}
2020-06-29 11:48:06 +03:00
MyMedia {
2017-06-16 17:45:04 +03:00
id: placeholder1
width: 2
height: 1
opacity: pressed ? 0.6 : 1
visible: {
if (model && model.count){
type = model.get(0).type
previewURL = model.get(0).preview_url
mediaURL = model.get(0).url
url = model.get(0).url
if(debug) console.log( model.get(0).url )
height = Theme.itemSizeLarge
2017-06-16 17:45:04 +03:00
return true
} else {
height = 0
return false
}
}
}
2020-06-29 11:48:06 +03:00
MyMedia {
2017-06-16 17:45:04 +03:00
id: placeholder2
width: 2
height: 1
opacity: pressed ? 0.6 : 1
visible: {
if (model && model.count && model.get(1)){
type = model.get(1).type
previewURL = model.get(1).preview_url
mediaURL = model.get(1).url
url = model.get(0).url
if(debug) console.log( model.get(1).url )
height = Theme.itemSizeLarge
2017-06-16 17:45:04 +03:00
return true
} else {
height = 0
return false
}
}
}
2020-06-29 11:48:06 +03:00
MyMedia {
2017-06-16 17:45:04 +03:00
id: placeholder3
width: 2
height: 1
opacity: pressed ? 0.6 : 1
visible: {
if (model && model.count && model.get(2)){
type = model.get(2).type
previewURL = model.get(2).preview_url
mediaURL = model.get(2).url
url = model.get(0).url
height = Theme.itemSizeLarge
2017-06-16 17:45:04 +03:00
return true
} else {
height = 0
return false
}
}
}
2020-06-29 11:48:06 +03:00
MyMedia {
2017-06-16 17:45:04 +03:00
id: placeholder4
width: 2
height: 1
opacity: pressed ? 0.6 : 1
visible: {
if (model && model.count && model.get(3)){
type = model.get(3).type
previewURL = model.get(3).preview_url
mediaURL = model.get(3).url
url = model.get(0).url
height = Theme.itemSizeLarge
2017-06-16 17:45:04 +03:00
return true
} else {
height = 0
return false
}
}
}
}