1
0
mirror of https://github.com/jaredtao/TaoQuick.git synced 2025-01-17 20:12:54 +08:00
This commit is contained in:
jared 2021-04-26 17:47:19 +08:00
commit ac13d2ed64
2 changed files with 107 additions and 0 deletions

View File

@ -67,6 +67,84 @@ Item {
}
}
//12 items in one page
property int itemCountPerPage:12
property int currentPage:1
//Pages round down
property int page:cusView.count/itemCountPerPage
//Actual number of pages (exactly divide pageCount = page, otherwise pageCount is 1 page more than page)
property int pageCount: page*itemCountPerPage<cusView.count?page+1:page
//--listView Page turning function
function changePage(next){
var currentViewIndex = cusView.indexAt(cusView.contentX,cusView.contentY)
if(currentViewIndex%itemCountPerPage!==0)
{ //the last page
if(!next){//Page forward
cusView.positionViewAtIndex((page-1)*itemCountPerPage,ListView.Beginning)
}
}
else
{
var i = 0
for(; i<pageCount;i++){
if(i*itemCountPerPage<=currentViewIndex&&currentViewIndex<(i+1)*itemCountPerPage){
//Find which page the current ViewIndex belongs to
break
}
}
console.log("currentViewIndex ",currentViewIndex)
//Page forward and backward
currentViewIndex =(next?(i+1):(i-1))*itemCountPerPage
//Ranges
currentViewIndex = currentViewIndex<0?0:currentViewIndex
currentViewIndex = currentViewIndex>=cusView.count - 1?cusView.count - 1:currentViewIndex
console.log("nextViewIndex ",currentViewIndex)
cusView.positionViewAtIndex(currentViewIndex,ListView.Beginning)
}
}
//--Calculate page number
function showPage(){
var currentViewIndex = cusView.indexAt(cusView.contentX,cusView.contentY)
if(currentViewIndex%itemCountPerPage!==0){
//the last page
console.log("final")
currentPage = pageCount
}else{
for(var i = 0; i<pageCount;i++){
if(i*itemCountPerPage<=currentViewIndex&&currentViewIndex<(i+1)*itemCountPerPage){
//Find which page the current ViewIndex belongs to
currentPage = i + 1
break
}
}
}
console.log("currentPage",currentPage)
console.log("page",page)
console.log("pageCount",pageCount)
}
signal lastpage()
onLastpage:{
changePage(false)
showPage()
}
signal nextpage()
onNextpage:{
changePage(true)
showPage()
}
CusTableView {
id: cusView
y: cusHeader.y + cusHeader.height
@ -169,6 +247,7 @@ Item {
}
}
}
Column {
x: cusHeader.splitingIndex > 0 ? (cusHeader.x + cusHeader.xList[cusHeader.splitingIndex + 1]) : 0
y: cusView.y
@ -290,6 +369,26 @@ Item {
deviceAddModel.deselectAll()
}
}
CusButton_Blue {
width: 120
text: qsTr("Last Page") + trans.transString
onClicked: {
mainItem.lastpage()
// changePage(false)
// showPage()
}
}
CusButton_Blue {
width: 120
text: qsTr("Next Page") + trans.transString
onClicked: {
mainItem.nextpage()
// changePage(true)
// showPage()
}
}
}
}
CusTextField {

View File

@ -601,6 +601,14 @@
{
"key": "Clear All",
"value": "清空"
},
{
"key": "Last Page",
"value": "上一页"
},
{
"key": "Next Page",
"value": "下一页"
}
]
}