添加自定义控件,通过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

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