This commit is contained in:
朱子楚\zhuzi 2024-03-02 23:37:25 +08:00
parent 76aa9a87c5
commit 07de3b82b1
4 changed files with 108 additions and 154 deletions

View File

@ -77,6 +77,7 @@ FluScrollablePage{
MouseArea { MouseArea {
property point clickPos: Qt.point(0,0) property point clickPos: Qt.point(0,0)
id:drag_area id:drag_area
preventStealing: true
anchors.fill: parent anchors.fill: parent
onPressed: (mouse)=>{ onPressed: (mouse)=>{
clickPos = Qt.point(mouse.x, mouse.y) clickPos = Qt.point(mouse.x, mouse.y)

View File

@ -77,6 +77,7 @@ FluScrollablePage{
MouseArea { MouseArea {
property point clickPos: Qt.point(0,0) property point clickPos: Qt.point(0,0)
id:drag_area id:drag_area
preventStealing: true
anchors.fill: parent anchors.fill: parent
onPressed: (mouse)=>{ onPressed: (mouse)=>{
clickPos = Qt.point(mouse.x, mouse.y) clickPos = Qt.point(mouse.x, mouse.y)

View File

@ -39,17 +39,9 @@ Rectangle {
property int defaultItemWidth: 100 property int defaultItemWidth: 100
property int defaultItemHeight: 42 property int defaultItemHeight: 42
property var header_rows:[] property var header_rows:[]
function obtEditDelegate(column,row,display,cellItem){ property var editDelegate
var tableModel = table_view.model property var editPosition
var cellPosition = cellItem.mapToItem(scroll_table, 0, 0) function getEditDelegate(column){
item_loader.column = column
item_loader.row = row
item_loader_layout.cellItem = cellItem
item_loader_layout.x = table_view.contentX + cellPosition.x
item_loader_layout.y = table_view.contentY + cellPosition.y
item_loader_layout.width = header_horizontal.columnWidthProvider(column)
item_loader_layout.height = table_view.rowHeightProvider(row)
item_loader.display = display
var obj =columnSource[column].editDelegate var obj =columnSource[column].editDelegate
if(obj){ if(obj){
return obj return obj
@ -75,7 +67,7 @@ Rectangle {
id:com_edit id:com_edit
FluTextBox{ FluTextBox{
id:text_box id:text_box
text: display text: String(display)
readOnly: true === columnSource[column].readOnly readOnly: true === columnSource[column].readOnly
Component.onCompleted: { Component.onCompleted: {
forceActiveFocus() forceActiveFocus()
@ -173,7 +165,7 @@ Rectangle {
} }
MouseArea{ MouseArea{
id:scroll_table id:layout_mouse_table
hoverEnabled: true hoverEnabled: true
anchors.left: header_vertical.right anchors.left: header_vertical.right
anchors.top: header_horizontal.bottom anchors.top: header_horizontal.bottom
@ -195,14 +187,9 @@ Rectangle {
id:model_columns id:model_columns
} }
boundsBehavior: Flickable.StopAtBounds boundsBehavior: Flickable.StopAtBounds
ScrollBar.horizontal: FluScrollBar{
id:scroll_bar_h
}
ScrollBar.vertical: FluScrollBar{
id:scroll_bar_v
}
syncView: header_horizontal syncView: header_horizontal
syncDirection: Qt.Horizontal syncDirection: Qt.Horizontal
ScrollBar.vertical:scroll_bar_v
rowHeightProvider: function(row) { rowHeightProvider: function(row) {
if(row>=table_view.rows){ if(row>=table_view.rows){
return 0 return 0
@ -215,15 +202,6 @@ Rectangle {
if(!h){ if(!h){
h = d.defaultItemHeight h = d.defaultItemHeight
} }
if(item_loader_layout.cellItem){
if(row === item_loader.row){
item_loader_layout.height = h
}
if(row === item_loader.row-1){
let cellPosition = item_loader_layout.cellItem.mapToItem(scroll_table, 0, 0)
item_loader_layout.y = table_view.contentY + cellPosition.y
}
}
return h return h
} }
model: table_sort_model model: table_sort_model
@ -284,12 +262,13 @@ Rectangle {
if(typeof(display) == "object"){ if(typeof(display) == "object"){
return return
} }
item_loader.sourceComponent = d.obtEditDelegate(column,row,display,item_table) d.editDelegate = d.getEditDelegate(column)
d.editPosition = {"_key":rowObject._key,"column":column}
} }
onClicked: onClicked:
(event)=>{ (event)=>{
d.current = rowObject d.current = rowObject
item_loader.sourceComponent = undefined closeEditor()
event.accepted = true event.accepted = true
} }
} }
@ -312,6 +291,29 @@ Rectangle {
return com_text return com_text
} }
} }
FluLoader{
property var display: itemModel.display
property int column: item_table.position.x
property int row: item_table.position.y
property var tableView: control
signal editTextChaged(string text)
anchors.fill: parent
onEditTextChaged:
(text)=>{
var obj = control.getRow(row)
obj[columnSource[column].dataIndex] = text
control.setRow(row,obj)
}
sourceComponent: {
if(d.editPosition === undefined){
return undefined
}
if(d.editPosition._key === rowObject._key && d.editPosition.column === column){
return d.editDelegate
}
return undefined
}
}
Item{ Item{
anchors.fill: parent anchors.fill: parent
visible: item_table.isRowSelected visible: item_table.isRowSelected
@ -345,38 +347,6 @@ Rectangle {
} }
} }
} }
MouseArea{
property var cellItem
id:item_loader_layout
acceptedButtons: Qt.NoButton
visible: item_loader.sourceComponent
onVisibleChanged: {
if(!visible){
item_loader_layout.cellItem = undefined
}
}
hoverEnabled: true
z:2
onEntered: {
d.rowHoverIndex = -1
}
FluLoader{
id:item_loader
property var display
property int column
property int row
property var tableView: control
signal editTextChaged(string text)
sourceComponent: undefined
anchors.fill: parent
onEditTextChaged:
(text)=>{
var obj = control.getRow(row)
obj[columnSource[column].dataIndex] = text
control.setRow(row,obj)
}
}
}
} }
} }
Component{ Component{
@ -393,7 +363,22 @@ Rectangle {
verticalAlignment: Text.AlignVCenter verticalAlignment: Text.AlignVCenter
} }
} }
FluScrollBar {
id:scroll_bar_h
anchors{
left: layout_mouse_table.left
right: layout_mouse_table.right
bottom: layout_mouse_table.bottom
}
}
FluScrollBar {
id:scroll_bar_v
anchors{
top: layout_mouse_table.top
bottom: layout_mouse_table.bottom
right: layout_mouse_table.right
}
}
TableView { TableView {
id: header_horizontal id: header_horizontal
model: TableModel{ model: TableModel{
@ -401,13 +386,14 @@ Rectangle {
rows: d.header_rows rows: d.header_rows
} }
syncDirection: Qt.Horizontal syncDirection: Qt.Horizontal
anchors.left: scroll_table.left anchors.left: layout_mouse_table.left
anchors.top: parent.top anchors.top: parent.top
visible: control.horizonalHeaderVisible visible: control.horizonalHeaderVisible
implicitWidth: table_view.width implicitWidth: table_view.width
implicitHeight: visible ? Math.max(1, contentHeight) : 0 implicitHeight: visible ? Math.max(1, contentHeight) : 0
boundsBehavior: Flickable.StopAtBounds boundsBehavior: Flickable.StopAtBounds
clip: true clip: true
ScrollBar.horizontal:scroll_bar_h
columnWidthProvider: function(column) { columnWidthProvider: function(column) {
var w = columnSource[column].width var w = columnSource[column].width
if(!w){ if(!w){
@ -416,15 +402,6 @@ Rectangle {
if(!w){ if(!w){
w = d.defaultItemWidth w = d.defaultItemWidth
} }
if(item_loader_layout.cellItem){
if(column === item_loader.column){
item_loader_layout.width = w
}
if(column === item_loader.column-1){
let cellPosition = item_loader_layout.cellItem.mapToItem(scroll_table, 0, 0)
item_loader_layout.x = table_view.contentX + cellPosition.x
}
}
return w return w
} }
delegate: Rectangle { delegate: Rectangle {
@ -557,7 +534,7 @@ Rectangle {
TableView { TableView {
id: header_vertical id: header_vertical
boundsBehavior: Flickable.StopAtBounds boundsBehavior: Flickable.StopAtBounds
anchors.top: scroll_table.top anchors.top: layout_mouse_table.top
anchors.left: parent.left anchors.left: parent.left
visible: control.verticalHeaderVisible visible: control.verticalHeaderVisible
implicitWidth: visible ? Math.max(1, contentWidth) : 0 implicitWidth: visible ? Math.max(1, contentWidth) : 0
@ -592,8 +569,6 @@ Rectangle {
property var rowObject: control.getRow(row) property var rowObject: control.getRow(row)
implicitWidth: Math.max(30, row_text.implicitWidth + (cellPadding * 2)) implicitWidth: Math.max(30, row_text.implicitWidth + (cellPadding * 2))
implicitHeight: row_text.implicitHeight + (cellPadding * 2) implicitHeight: row_text.implicitHeight + (cellPadding * 2)
width: implicitWidth
height: implicitHeight
color: FluTheme.dark ? Qt.rgba(50/255,50/255,50/255,1) : Qt.rgba(247/255,247/255,247/255,1) color: FluTheme.dark ? Qt.rgba(50/255,50/255,50/255,1) : Qt.rgba(247/255,247/255,247/255,1)
Rectangle{ Rectangle{
border.color: control.borderColor border.color: control.borderColor
@ -700,7 +675,8 @@ Rectangle {
} }
} }
function closeEditor(){ function closeEditor(){
item_loader.sourceComponent = null d.editPosition = undefined
d.editDelegate = undefined
} }
function resetPosition(){ function resetPosition(){
scroll_bar_h.position = 0 scroll_bar_h.position = 0

View File

@ -40,17 +40,9 @@ Rectangle {
property int defaultItemWidth: 100 property int defaultItemWidth: 100
property int defaultItemHeight: 42 property int defaultItemHeight: 42
property var header_rows:[] property var header_rows:[]
function obtEditDelegate(column,row,display,cellItem){ property var editDelegate
var tableModel = table_view.model property var editPosition
var cellPosition = cellItem.mapToItem(scroll_table, 0, 0) function getEditDelegate(column){
item_loader.column = column
item_loader.row = row
item_loader_layout.cellItem = cellItem
item_loader_layout.x = table_view.contentX + cellPosition.x
item_loader_layout.y = table_view.contentY + cellPosition.y
item_loader_layout.width = header_horizontal.columnWidthProvider(column)
item_loader_layout.height = table_view.rowHeightProvider(row)
item_loader.display = display
var obj =columnSource[column].editDelegate var obj =columnSource[column].editDelegate
if(obj){ if(obj){
return obj return obj
@ -76,7 +68,7 @@ Rectangle {
id:com_edit id:com_edit
FluTextBox{ FluTextBox{
id:text_box id:text_box
text: display text: String(display)
readOnly: true === columnSource[column].readOnly readOnly: true === columnSource[column].readOnly
Component.onCompleted: { Component.onCompleted: {
forceActiveFocus() forceActiveFocus()
@ -174,7 +166,7 @@ Rectangle {
} }
MouseArea{ MouseArea{
id:scroll_table id:layout_mouse_table
hoverEnabled: true hoverEnabled: true
anchors.left: header_vertical.right anchors.left: header_vertical.right
anchors.top: header_horizontal.bottom anchors.top: header_horizontal.bottom
@ -196,14 +188,9 @@ Rectangle {
id:model_columns id:model_columns
} }
boundsBehavior: Flickable.StopAtBounds boundsBehavior: Flickable.StopAtBounds
ScrollBar.horizontal: FluScrollBar{
id:scroll_bar_h
}
ScrollBar.vertical: FluScrollBar{
id:scroll_bar_v
}
syncView: header_horizontal syncView: header_horizontal
syncDirection: Qt.Horizontal syncDirection: Qt.Horizontal
ScrollBar.vertical:scroll_bar_v
rowHeightProvider: function(row) { rowHeightProvider: function(row) {
if(row>=table_view.rows){ if(row>=table_view.rows){
return 0 return 0
@ -216,15 +203,6 @@ Rectangle {
if(!h){ if(!h){
h = d.defaultItemHeight h = d.defaultItemHeight
} }
if(item_loader_layout.cellItem){
if(row === item_loader.row){
item_loader_layout.height = h
}
if(row === item_loader.row-1){
let cellPosition = item_loader_layout.cellItem.mapToItem(scroll_table, 0, 0)
item_loader_layout.y = table_view.contentY + cellPosition.y
}
}
return h return h
} }
model: table_sort_model model: table_sort_model
@ -285,12 +263,13 @@ Rectangle {
if(typeof(display) == "object"){ if(typeof(display) == "object"){
return return
} }
item_loader.sourceComponent = d.obtEditDelegate(column,row,display,item_table) d.editDelegate = d.getEditDelegate(column)
d.editPosition = {"_key":rowObject._key,"column":column}
} }
onClicked: onClicked:
(event)=>{ (event)=>{
d.current = rowObject d.current = rowObject
item_loader.sourceComponent = undefined closeEditor()
event.accepted = true event.accepted = true
} }
} }
@ -313,6 +292,29 @@ Rectangle {
return com_text return com_text
} }
} }
FluLoader{
property var display: itemModel.display
property int column: item_table.position.x
property int row: item_table.position.y
property var tableView: control
signal editTextChaged(string text)
anchors.fill: parent
onEditTextChaged:
(text)=>{
var obj = control.getRow(row)
obj[columnSource[column].dataIndex] = text
control.setRow(row,obj)
}
sourceComponent: {
if(d.editPosition === undefined){
return undefined
}
if(d.editPosition._key === rowObject._key && d.editPosition.column === column){
return d.editDelegate
}
return undefined
}
}
Item{ Item{
anchors.fill: parent anchors.fill: parent
visible: item_table.isRowSelected visible: item_table.isRowSelected
@ -346,38 +348,6 @@ Rectangle {
} }
} }
} }
MouseArea{
property var cellItem
id:item_loader_layout
acceptedButtons: Qt.NoButton
visible: item_loader.sourceComponent
onVisibleChanged: {
if(!visible){
item_loader_layout.cellItem = undefined
}
}
hoverEnabled: true
z:2
onEntered: {
d.rowHoverIndex = -1
}
FluLoader{
id:item_loader
property var display
property int column
property int row
property var tableView: control
signal editTextChaged(string text)
sourceComponent: undefined
anchors.fill: parent
onEditTextChaged:
(text)=>{
var obj = control.getRow(row)
obj[columnSource[column].dataIndex] = text
control.setRow(row,obj)
}
}
}
} }
} }
Component{ Component{
@ -394,7 +364,22 @@ Rectangle {
verticalAlignment: Text.AlignVCenter verticalAlignment: Text.AlignVCenter
} }
} }
FluScrollBar {
id:scroll_bar_h
anchors{
left: layout_mouse_table.left
right: layout_mouse_table.right
bottom: layout_mouse_table.bottom
}
}
FluScrollBar {
id:scroll_bar_v
anchors{
top: layout_mouse_table.top
bottom: layout_mouse_table.bottom
right: layout_mouse_table.right
}
}
TableView { TableView {
id: header_horizontal id: header_horizontal
model: TableModel{ model: TableModel{
@ -402,13 +387,14 @@ Rectangle {
rows: d.header_rows rows: d.header_rows
} }
syncDirection: Qt.Horizontal syncDirection: Qt.Horizontal
anchors.left: scroll_table.left anchors.left: layout_mouse_table.left
anchors.top: parent.top anchors.top: parent.top
visible: control.horizonalHeaderVisible visible: control.horizonalHeaderVisible
implicitWidth: table_view.width implicitWidth: table_view.width
implicitHeight: visible ? Math.max(1, contentHeight) : 0 implicitHeight: visible ? Math.max(1, contentHeight) : 0
boundsBehavior: Flickable.StopAtBounds boundsBehavior: Flickable.StopAtBounds
clip: true clip: true
ScrollBar.horizontal:scroll_bar_h
columnWidthProvider: function(column) { columnWidthProvider: function(column) {
var w = columnSource[column].width var w = columnSource[column].width
if(!w){ if(!w){
@ -417,15 +403,6 @@ Rectangle {
if(!w){ if(!w){
w = d.defaultItemWidth w = d.defaultItemWidth
} }
if(item_loader_layout.cellItem){
if(column === item_loader.column){
item_loader_layout.width = w
}
if(column === item_loader.column-1){
let cellPosition = item_loader_layout.cellItem.mapToItem(scroll_table, 0, 0)
item_loader_layout.x = table_view.contentX + cellPosition.x
}
}
return w return w
} }
delegate: Rectangle { delegate: Rectangle {
@ -558,7 +535,7 @@ Rectangle {
TableView { TableView {
id: header_vertical id: header_vertical
boundsBehavior: Flickable.StopAtBounds boundsBehavior: Flickable.StopAtBounds
anchors.top: scroll_table.top anchors.top: layout_mouse_table.top
anchors.left: parent.left anchors.left: parent.left
visible: control.verticalHeaderVisible visible: control.verticalHeaderVisible
implicitWidth: visible ? Math.max(1, contentWidth) : 0 implicitWidth: visible ? Math.max(1, contentWidth) : 0
@ -593,8 +570,6 @@ Rectangle {
property var rowObject: control.getRow(row) property var rowObject: control.getRow(row)
implicitWidth: Math.max(30, row_text.implicitWidth + (cellPadding * 2)) implicitWidth: Math.max(30, row_text.implicitWidth + (cellPadding * 2))
implicitHeight: row_text.implicitHeight + (cellPadding * 2) implicitHeight: row_text.implicitHeight + (cellPadding * 2)
width: implicitWidth
height: implicitHeight
color: FluTheme.dark ? Qt.rgba(50/255,50/255,50/255,1) : Qt.rgba(247/255,247/255,247/255,1) color: FluTheme.dark ? Qt.rgba(50/255,50/255,50/255,1) : Qt.rgba(247/255,247/255,247/255,1)
Rectangle{ Rectangle{
border.color: control.borderColor border.color: control.borderColor
@ -701,7 +676,8 @@ Rectangle {
} }
} }
function closeEditor(){ function closeEditor(){
item_loader.sourceComponent = null d.editPosition = undefined
d.editDelegate = undefined
} }
function resetPosition(){ function resetPosition(){
scroll_bar_h.position = 0 scroll_bar_h.position = 0