Merge pull request #489 from w-jt/main

FluPagination.qml 添加自定义控件,通过header和footer属性添加控件
This commit is contained in:
zhuzichu 2024-04-28 10:46:47 +08:00 committed by GitHub
commit cc79854191
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 223 additions and 200 deletions

View File

@ -3,8 +3,10 @@ import QtQuick.Controls 2.15
import QtQuick.Layouts 1.15 import QtQuick.Layouts 1.15
import FluentUI 1.0 import FluentUI 1.0
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
@ -13,6 +15,8 @@ Item {
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
@ -21,6 +25,9 @@ Item {
height: control.height height: control.height
spacing: 10 spacing: 10
padding: 10 padding: 10
Loader {
sourceComponent: header
}
FluToggleButton { FluToggleButton {
visible: control.pageCount > 1 visible: control.pageCount > 1
disabled: control.pageCurrent <= 1 disabled: control.pageCurrent <= 1
@ -31,6 +38,7 @@ Item {
} }
Row { Row {
spacing: 5 spacing: 5
FluToggleButton { FluToggleButton {
property int pageNumber: 1 property int pageNumber: 1
visible: control.pageCount > 0 visible: control.pageCount > 0
@ -86,9 +94,12 @@ Item {
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)
@ -97,4 +108,5 @@ Item {
control.pageCurrent = page_num control.pageCurrent = page_num
control.requestPage(page_num, control.__itemPerPage) control.requestPage(page_num, control.__itemPerPage)
} }
} }

View File

@ -1,10 +1,11 @@
import QtQuick import QtQuick 2.15
import QtQuick.Controls import QtQuick.Controls 2.15
import QtQuick.Layouts import QtQuick.Layouts 1.15
import FluentUI import FluentUI 1.0
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
@ -13,6 +14,8 @@ Item {
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
@ -21,6 +24,9 @@ Item {
height: control.height height: control.height
spacing: 10 spacing: 10
padding: 10 padding: 10
Loader {
sourceComponent: header
}
FluToggleButton { FluToggleButton {
visible: control.pageCount > 1 visible: control.pageCount > 1
disabled: control.pageCurrent <= 1 disabled: control.pageCurrent <= 1
@ -31,6 +37,7 @@ Item {
} }
Row { Row {
spacing: 5 spacing: 5
FluToggleButton { FluToggleButton {
property int pageNumber: 1 property int pageNumber: 1
visible: control.pageCount > 0 visible: control.pageCount > 0
@ -86,9 +93,12 @@ Item {
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)
@ -97,4 +107,5 @@ Item {
control.pageCurrent = page_num control.pageCurrent = page_num
control.requestPage(page_num, control.__itemPerPage) control.requestPage(page_num, control.__itemPerPage)
} }
} }