mirror of
https://github.com/zhuzichu520/FluentUI.git
synced 2024-11-22 10:40:10 +08:00
Merge pull request #489 from w-jt/main
FluPagination.qml 添加自定义控件,通过header和footer属性添加控件
This commit is contained in:
commit
cc79854191
@ -3,98 +3,110 @@ import QtQuick.Controls 2.15
|
||||
import QtQuick.Layouts 1.15
|
||||
import FluentUI 1.0
|
||||
|
||||
|
||||
Item {
|
||||
signal requestPage(int page,int count)
|
||||
signal requestPage(int page, int count)
|
||||
|
||||
property string previousText: qsTr("<Previous")
|
||||
property string nextText: qsTr("Next>")
|
||||
property int pageCurrent: 0
|
||||
property int itemCount: 0
|
||||
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 __pageButtonHalf: Math.floor(pageButtonCount/2)+1
|
||||
property int __pageButtonHalf: Math.floor(pageButtonCount / 2) + 1
|
||||
property Component header: null
|
||||
property Component footer: null
|
||||
id: control
|
||||
implicitHeight: 40
|
||||
implicitWidth: content.width
|
||||
Row{
|
||||
Row {
|
||||
id: content
|
||||
height: control.height
|
||||
spacing: 10
|
||||
padding: 10
|
||||
FluToggleButton{
|
||||
visible: control.pageCount>1
|
||||
disabled: control.pageCurrent<=1
|
||||
text:control.previousText
|
||||
clickListener:function() {
|
||||
control.calcNewPage(control.pageCurrent-1);
|
||||
Loader {
|
||||
sourceComponent: header
|
||||
}
|
||||
FluToggleButton {
|
||||
visible: control.pageCount > 1
|
||||
disabled: control.pageCurrent <= 1
|
||||
text: control.previousText
|
||||
clickListener: function () {
|
||||
control.calcNewPage(control.pageCurrent - 1);
|
||||
}
|
||||
}
|
||||
Row{
|
||||
Row {
|
||||
spacing: 5
|
||||
FluToggleButton{
|
||||
property int pageNumber:1
|
||||
visible: control.pageCount>0
|
||||
|
||||
FluToggleButton {
|
||||
property int pageNumber: 1
|
||||
visible: control.pageCount > 0
|
||||
checked: pageNumber === control.pageCurrent
|
||||
text:String(pageNumber)
|
||||
clickListener:function() {
|
||||
text: String(pageNumber)
|
||||
clickListener: function () {
|
||||
control.calcNewPage(pageNumber);
|
||||
}
|
||||
}
|
||||
FluText{
|
||||
visible: (control.pageCount>control.pageButtonCount&&
|
||||
control.pageCurrent>control.__pageButtonHalf)
|
||||
FluText {
|
||||
visible: (control.pageCount > control.pageButtonCount &&
|
||||
control.pageCurrent > control.__pageButtonHalf)
|
||||
text: "..."
|
||||
}
|
||||
Repeater{
|
||||
Repeater {
|
||||
id: button_repeator
|
||||
model: (control.pageCount<2)?0:(control.pageCount>=control.pageButtonCount)?(control.pageButtonCount-2):(control.pageCount-2)
|
||||
delegate:FluToggleButton{
|
||||
model: (control.pageCount < 2) ? 0 : (control.pageCount >= control.pageButtonCount) ? (control.pageButtonCount - 2) : (control.pageCount - 2)
|
||||
delegate: FluToggleButton {
|
||||
property int pageNumber: {
|
||||
return (control.pageCurrent<=control.__pageButtonHalf)
|
||||
?(2+index)
|
||||
:(control.pageCount-control.pageCurrent<=control.pageButtonCount-control.__pageButtonHalf)
|
||||
?(control.pageCount-button_repeator.count+index)
|
||||
:(control.pageCurrent+2+index-control.__pageButtonHalf)
|
||||
return (control.pageCurrent <= control.__pageButtonHalf)
|
||||
? (2 + index)
|
||||
: (control.pageCount - control.pageCurrent <= control.pageButtonCount - control.__pageButtonHalf)
|
||||
? (control.pageCount - button_repeator.count + index)
|
||||
: (control.pageCurrent + 2 + index - control.__pageButtonHalf)
|
||||
}
|
||||
text:String(pageNumber)
|
||||
text: String(pageNumber)
|
||||
checked: pageNumber === control.pageCurrent
|
||||
clickListener:function(){
|
||||
clickListener: function () {
|
||||
control.calcNewPage(pageNumber);
|
||||
}
|
||||
}
|
||||
}
|
||||
FluText{
|
||||
visible: (control.pageCount>control.pageButtonCount&&
|
||||
control.pageCount-control.pageCurrent>control.pageButtonCount-control.__pageButtonHalf)
|
||||
FluText {
|
||||
visible: (control.pageCount > control.pageButtonCount &&
|
||||
control.pageCount - control.pageCurrent > control.pageButtonCount - control.__pageButtonHalf)
|
||||
text: "..."
|
||||
}
|
||||
FluToggleButton{
|
||||
property int pageNumber:control.pageCount
|
||||
visible: control.pageCount>1
|
||||
FluToggleButton {
|
||||
property int pageNumber: control.pageCount
|
||||
visible: control.pageCount > 1
|
||||
checked: pageNumber === control.pageCurrent
|
||||
text:String(pageNumber)
|
||||
clickListener:function(){
|
||||
text: String(pageNumber)
|
||||
clickListener: function () {
|
||||
control.calcNewPage(pageNumber);
|
||||
}
|
||||
}
|
||||
}
|
||||
FluToggleButton{
|
||||
visible: control.pageCount>1
|
||||
disabled: control.pageCurrent>=control.pageCount
|
||||
text:control.nextText
|
||||
clickListener:function() {
|
||||
control.calcNewPage(control.pageCurrent+1);
|
||||
FluToggleButton {
|
||||
visible: control.pageCount > 1
|
||||
disabled: control.pageCurrent >= control.pageCount
|
||||
text: control.nextText
|
||||
clickListener: function () {
|
||||
control.calcNewPage(control.pageCurrent + 1);
|
||||
}
|
||||
}
|
||||
Loader {
|
||||
sourceComponent: footer
|
||||
}
|
||||
function calcNewPage(page)
|
||||
{
|
||||
if(!page)
|
||||
}
|
||||
|
||||
function calcNewPage(page) {
|
||||
if (!page)
|
||||
return
|
||||
let page_num=Number(page)
|
||||
if(page_num<1||page_num>control.pageCount||page_num===control.pageCurrent)
|
||||
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)
|
||||
control.pageCurrent = page_num
|
||||
control.requestPage(page_num, control.__itemPerPage)
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,100 +1,111 @@
|
||||
import QtQuick
|
||||
import QtQuick.Controls
|
||||
import QtQuick.Layouts
|
||||
import FluentUI
|
||||
import QtQuick 2.15
|
||||
import QtQuick.Controls 2.15
|
||||
import QtQuick.Layouts 1.15
|
||||
import FluentUI 1.0
|
||||
|
||||
Item {
|
||||
signal requestPage(int page,int count)
|
||||
signal requestPage(int page, int count)
|
||||
|
||||
property string previousText: qsTr("<Previous")
|
||||
property string nextText: qsTr("Next>")
|
||||
property int pageCurrent: 0
|
||||
property int itemCount: 0
|
||||
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 __pageButtonHalf: Math.floor(pageButtonCount/2)+1
|
||||
property int __pageButtonHalf: Math.floor(pageButtonCount / 2) + 1
|
||||
property Component header: null
|
||||
property Component footer: null
|
||||
id: control
|
||||
implicitHeight: 40
|
||||
implicitWidth: content.width
|
||||
Row{
|
||||
Row {
|
||||
id: content
|
||||
height: control.height
|
||||
spacing: 10
|
||||
padding: 10
|
||||
FluToggleButton{
|
||||
visible: control.pageCount>1
|
||||
disabled: control.pageCurrent<=1
|
||||
text:control.previousText
|
||||
clickListener:function() {
|
||||
control.calcNewPage(control.pageCurrent-1);
|
||||
Loader {
|
||||
sourceComponent: header
|
||||
}
|
||||
FluToggleButton {
|
||||
visible: control.pageCount > 1
|
||||
disabled: control.pageCurrent <= 1
|
||||
text: control.previousText
|
||||
clickListener: function () {
|
||||
control.calcNewPage(control.pageCurrent - 1);
|
||||
}
|
||||
}
|
||||
Row{
|
||||
Row {
|
||||
spacing: 5
|
||||
FluToggleButton{
|
||||
property int pageNumber:1
|
||||
visible: control.pageCount>0
|
||||
|
||||
FluToggleButton {
|
||||
property int pageNumber: 1
|
||||
visible: control.pageCount > 0
|
||||
checked: pageNumber === control.pageCurrent
|
||||
text:String(pageNumber)
|
||||
clickListener:function() {
|
||||
text: String(pageNumber)
|
||||
clickListener: function () {
|
||||
control.calcNewPage(pageNumber);
|
||||
}
|
||||
}
|
||||
FluText{
|
||||
visible: (control.pageCount>control.pageButtonCount&&
|
||||
control.pageCurrent>control.__pageButtonHalf)
|
||||
FluText {
|
||||
visible: (control.pageCount > control.pageButtonCount &&
|
||||
control.pageCurrent > control.__pageButtonHalf)
|
||||
text: "..."
|
||||
}
|
||||
Repeater{
|
||||
Repeater {
|
||||
id: button_repeator
|
||||
model: (control.pageCount<2)?0:(control.pageCount>=control.pageButtonCount)?(control.pageButtonCount-2):(control.pageCount-2)
|
||||
delegate:FluToggleButton{
|
||||
model: (control.pageCount < 2) ? 0 : (control.pageCount >= control.pageButtonCount) ? (control.pageButtonCount - 2) : (control.pageCount - 2)
|
||||
delegate: FluToggleButton {
|
||||
property int pageNumber: {
|
||||
return (control.pageCurrent<=control.__pageButtonHalf)
|
||||
?(2+index)
|
||||
:(control.pageCount-control.pageCurrent<=control.pageButtonCount-control.__pageButtonHalf)
|
||||
?(control.pageCount-button_repeator.count+index)
|
||||
:(control.pageCurrent+2+index-control.__pageButtonHalf)
|
||||
return (control.pageCurrent <= control.__pageButtonHalf)
|
||||
? (2 + index)
|
||||
: (control.pageCount - control.pageCurrent <= control.pageButtonCount - control.__pageButtonHalf)
|
||||
? (control.pageCount - button_repeator.count + index)
|
||||
: (control.pageCurrent + 2 + index - control.__pageButtonHalf)
|
||||
}
|
||||
text:String(pageNumber)
|
||||
text: String(pageNumber)
|
||||
checked: pageNumber === control.pageCurrent
|
||||
clickListener:function(){
|
||||
clickListener: function () {
|
||||
control.calcNewPage(pageNumber);
|
||||
}
|
||||
}
|
||||
}
|
||||
FluText{
|
||||
visible: (control.pageCount>control.pageButtonCount&&
|
||||
control.pageCount-control.pageCurrent>control.pageButtonCount-control.__pageButtonHalf)
|
||||
FluText {
|
||||
visible: (control.pageCount > control.pageButtonCount &&
|
||||
control.pageCount - control.pageCurrent > control.pageButtonCount - control.__pageButtonHalf)
|
||||
text: "..."
|
||||
}
|
||||
FluToggleButton{
|
||||
property int pageNumber:control.pageCount
|
||||
visible: control.pageCount>1
|
||||
FluToggleButton {
|
||||
property int pageNumber: control.pageCount
|
||||
visible: control.pageCount > 1
|
||||
checked: pageNumber === control.pageCurrent
|
||||
text:String(pageNumber)
|
||||
clickListener:function(){
|
||||
text: String(pageNumber)
|
||||
clickListener: function () {
|
||||
control.calcNewPage(pageNumber);
|
||||
}
|
||||
}
|
||||
}
|
||||
FluToggleButton{
|
||||
visible: control.pageCount>1
|
||||
disabled: control.pageCurrent>=control.pageCount
|
||||
text:control.nextText
|
||||
clickListener:function() {
|
||||
control.calcNewPage(control.pageCurrent+1);
|
||||
FluToggleButton {
|
||||
visible: control.pageCount > 1
|
||||
disabled: control.pageCurrent >= control.pageCount
|
||||
text: control.nextText
|
||||
clickListener: function () {
|
||||
control.calcNewPage(control.pageCurrent + 1);
|
||||
}
|
||||
}
|
||||
Loader {
|
||||
sourceComponent: footer
|
||||
}
|
||||
function calcNewPage(page)
|
||||
{
|
||||
if(!page)
|
||||
}
|
||||
|
||||
function calcNewPage(page) {
|
||||
if (!page)
|
||||
return
|
||||
let page_num=Number(page)
|
||||
if(page_num<1||page_num>control.pageCount||page_num===control.pageCurrent)
|
||||
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)
|
||||
control.pageCurrent = page_num
|
||||
control.requestPage(page_num, control.__itemPerPage)
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user