添加自定义控件,通过header和footer属性添加控件

添加自定义控件,通过header和footer属性添加控件
This commit is contained in:
w-jt 2024-04-27 11:48:19 +08:00 committed by GitHub
parent 24fdff7e35
commit aecc3fe3b4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,100 +1,111 @@
import QtQuick import QtQuick
import QtQuick.Controls import QtQuick.Controls
import QtQuick.Layouts import QtQuick.Layouts
import FluentUI import FluentUI
Item { Item {
signal requestPage(int page,int count) signal requestPage(int page, int count)
property string previousText: qsTr("<Previous")
property string nextText: qsTr("Next>") property string previousText: qsTr("<Previous")
property int pageCurrent: 0 property string nextText: qsTr("Next>")
property int itemCount: 0 property int pageCurrent: 0
property int pageButtonCount: 5 property int itemCount: 0
property int pageCount: itemCount>0?Math.ceil(itemCount/__itemPerPage):0 property int pageButtonCount: 5
property int __itemPerPage: 10 property int pageCount: itemCount > 0 ? Math.ceil(itemCount / __itemPerPage) : 0
property int __pageButtonHalf: Math.floor(pageButtonCount/2)+1 property int __itemPerPage: 10
id: control property int __pageButtonHalf: Math.floor(pageButtonCount / 2) + 1
implicitHeight: 40 property Component header: null
implicitWidth: content.width property Component footer: null
Row{ id: control
id: content implicitHeight: 40
height: control.height implicitWidth: content.width
spacing: 10 Row {
padding: 10 id: content
FluToggleButton{ height: control.height
visible: control.pageCount>1 spacing: 10
disabled: control.pageCurrent<=1 padding: 10
text:control.previousText Loader {
clickListener:function() { sourceComponent: header
control.calcNewPage(control.pageCurrent-1); }
} FluToggleButton {
} visible: control.pageCount > 1
Row{ disabled: control.pageCurrent <= 1
spacing: 5 text: control.previousText
FluToggleButton{ clickListener: function () {
property int pageNumber:1 control.calcNewPage(control.pageCurrent - 1);
visible: control.pageCount>0 }
checked: pageNumber === control.pageCurrent }
text:String(pageNumber) Row {
clickListener:function() { spacing: 5
control.calcNewPage(pageNumber);
} FluToggleButton {
} property int pageNumber: 1
FluText{ visible: control.pageCount > 0
visible: (control.pageCount>control.pageButtonCount&& checked: pageNumber === control.pageCurrent
control.pageCurrent>control.__pageButtonHalf) text: String(pageNumber)
text: "..." clickListener: function () {
} control.calcNewPage(pageNumber);
Repeater{ }
id: button_repeator }
model: (control.pageCount<2)?0:(control.pageCount>=control.pageButtonCount)?(control.pageButtonCount-2):(control.pageCount-2) FluText {
delegate:FluToggleButton{ visible: (control.pageCount > control.pageButtonCount &&
property int pageNumber: { control.pageCurrent > control.__pageButtonHalf)
return (control.pageCurrent<=control.__pageButtonHalf) text: "..."
?(2+index) }
:(control.pageCount-control.pageCurrent<=control.pageButtonCount-control.__pageButtonHalf) Repeater {
?(control.pageCount-button_repeator.count+index) id: button_repeator
:(control.pageCurrent+2+index-control.__pageButtonHalf) model: (control.pageCount < 2) ? 0 : (control.pageCount >= control.pageButtonCount) ? (control.pageButtonCount - 2) : (control.pageCount - 2)
} delegate: FluToggleButton {
text:String(pageNumber) property int pageNumber: {
checked: pageNumber === control.pageCurrent return (control.pageCurrent <= control.__pageButtonHalf)
clickListener:function(){ ? (2 + index)
control.calcNewPage(pageNumber); : (control.pageCount - control.pageCurrent <= control.pageButtonCount - control.__pageButtonHalf)
} ? (control.pageCount - button_repeator.count + index)
} : (control.pageCurrent + 2 + index - control.__pageButtonHalf)
} }
FluText{ text: String(pageNumber)
visible: (control.pageCount>control.pageButtonCount&& checked: pageNumber === control.pageCurrent
control.pageCount-control.pageCurrent>control.pageButtonCount-control.__pageButtonHalf) clickListener: function () {
text: "..." control.calcNewPage(pageNumber);
} }
FluToggleButton{ }
property int pageNumber:control.pageCount }
visible: control.pageCount>1 FluText {
checked: pageNumber === control.pageCurrent visible: (control.pageCount > control.pageButtonCount &&
text:String(pageNumber) control.pageCount - control.pageCurrent > control.pageButtonCount - control.__pageButtonHalf)
clickListener:function(){ text: "..."
control.calcNewPage(pageNumber); }
} FluToggleButton {
} property int pageNumber: control.pageCount
} visible: control.pageCount > 1
FluToggleButton{ checked: pageNumber === control.pageCurrent
visible: control.pageCount>1 text: String(pageNumber)
disabled: control.pageCurrent>=control.pageCount clickListener: function () {
text:control.nextText control.calcNewPage(pageNumber);
clickListener:function() { }
control.calcNewPage(control.pageCurrent+1); }
} }
} FluToggleButton {
} visible: control.pageCount > 1
function calcNewPage(page) disabled: control.pageCurrent >= control.pageCount
{ text: control.nextText
if(!page) clickListener: function () {
return control.calcNewPage(control.pageCurrent + 1);
let page_num=Number(page) }
if(page_num<1||page_num>control.pageCount||page_num===control.pageCurrent) }
return Loader {
control.pageCurrent=page_num sourceComponent: footer
control.requestPage(page_num,control.__itemPerPage) }
} }
}
function calcNewPage(page) {
if (!page)
return
let page_num = Number(page)
if (page_num < 1 || page_num > control.pageCount || page_num === control.pageCurrent)
return
control.pageCurrent = page_num
control.requestPage(page_num, control.__itemPerPage)
}
}