import QtQuick 2.7
import QtQuick.Controls 2.0
import QtQuick.Layouts 1.0
ApplicationWindow {
visible: true
width: 640
height: 480
title: qsTr("Hello World")
id:root
property alias listmodel: listmodel
ListModel{
id:listmodel
Component.onCompleted: {
getSrc()
}
}
property int readCout: 4
ListView{
id:listview;
anchors.fill: parent
model:listmodel
clip: true
onCurrentIndexChanged: {
console.log(currentIndex)
}
delegate: Image{
property int bw: 40
property int bh: 40
id:img
width: bw
height: bh
source: model.pic
anchors.horizontalCenter: parent.horizontalCenter
onStatusChanged: {
if(status===Image.Ready)
{
by.running=false;
bw = root.width*0.8
bh=img.sourceSize.height/img.sourceSize.width *width
}
}
BusyIndicator{
id:by
visible: model.vs
running: img.status==Image.Ready?false:true
anchors.centerIn: parent
width: visible?50:0
height: visible?50:0
}
}
onFlickStarted: {
console.log(originY + ","+contentY +","+contentHeight+","+height+",");
if((contentY-originY +height*0.5)>(contentHeight-height))
{
getSrc();
}
}
}
property bool geting: false
function getSrc()
{
if(geting==true)
{
return;
}
geting= true;
var _begin=listmodel.count;
for(var z =0;z<readCout;z++)
{
if(z==0)
{
listmodel.append({"pic":"",vs:true});
}else{
listmodel.append({"pic":"",vs:false});
}
}
getimage(_begin,function(_src){
for(var x=0;x<readCout;x++)
{
listmodel.get(_begin + x).vs=true
}
loadimage(_begin,_src)
geting= false;
})
}
function loadimage(_begin,___src)
{
console.log(___src)
if(___src=="erro")
{
listmodel.remove(_begin,readCout)
return;
}
var obg = JSON.parse(___src);
for(var x=0;x<obg.length;x++)
{
console.log("obgL:"+obg[x])
listmodel.get(_begin + x).pic="http://192.168.0.105/"+obg[x]
}
if(obg.length<readCout)
{
for(var xx=0;xx<readCout-obg.length;xx++)
{
listmodel.remove(listmodel.count-1)
}
}
}
function getimage(data,back)
{
console.log("getimage")
var x = new XMLHttpRequest();
x.open("POST","http://192.168.0.105//mycode//test//getimage.php");
x.onreadystatechange =function()
{
if(x.readyState == 4) {
if(x.status == 200) {
console.log("The server replied with: " + x.responseText);
back(x.responseText);
}else
{
back("erro");
}
};
}
x.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
x.send("imageindex="+data+"&cout="+readCout);
}
}
<?php
$T = rand(1,1000000*2);
usleep($T);
$img = $_POST['imageindex'];
$cout = $_POST['cout'];
if ($img>5)
{
echo "erro";
return ;
}
$arr = array ();
for ($x=0;$x<$cout;$x++)
{
if($img+$x>5)
{
break;
}
$arr[$x]=$img+$x . ".png";
}
if(count($arr)==0)
{
echo "erro";
return ;
}
$str=json_encode($arr);
echo $str;
?>