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