This commit is contained in:
zhuzichu 2024-01-30 11:45:08 +08:00
parent 9bc5794db8
commit a705577cba
2 changed files with 30 additions and 38 deletions

View File

@ -244,6 +244,7 @@ Rectangle {
model: table_model model: table_model
clip: true clip: true
delegate: MouseArea{ delegate: MouseArea{
property var rowObject : table_model.getRow(row)
hoverEnabled: true hoverEnabled: true
implicitHeight: 40 implicitHeight: 40
implicitWidth: { implicitWidth: {
@ -263,7 +264,6 @@ Rectangle {
id:item_table id:item_table
anchors.fill: parent anchors.fill: parent
property point position: Qt.point(column,row) property point position: Qt.point(column,row)
property var rowObject : table_model.getRow(row)
property bool isRowSelected: d.currentIndex === rowObject.__index property bool isRowSelected: d.currentIndex === rowObject.__index
color:{ color:{
if(d.rowHoverIndex === row || item_table.isRowSelected){ if(d.rowHoverIndex === row || item_table.isRowSelected){
@ -301,7 +301,7 @@ Rectangle {
} }
onClicked: onClicked:
(event)=>{ (event)=>{
d.currentIndex = table_model.getRow(row).__index d.currentIndex = rowObject.__index
item_loader.sourceComponent = undefined item_loader.sourceComponent = undefined
event.accepted = true event.accepted = true
} }
@ -398,7 +398,7 @@ Rectangle {
readonly property real cellPadding: 8 readonly property real cellPadding: 8
property bool canceled: false property bool canceled: false
property int columnIndex: column property int columnIndex: column
readonly property var obj : columnSource[column] readonly property var columnObject : columnSource[column]
implicitWidth: { implicitWidth: {
return (item_column_loader.item && item_column_loader.item.implicitWidth) + (cellPadding * 2) return (item_column_loader.item && item_column_loader.item.implicitWidth) + (cellPadding * 2)
} }
@ -480,7 +480,7 @@ Rectangle {
anchors.right: parent.right anchors.right: parent.right
acceptedButtons: Qt.LeftButton acceptedButtons: Qt.LeftButton
hoverEnabled: true hoverEnabled: true
visible: !(obj.width === obj.minimumWidth && obj.width === obj.maximumWidth && obj.width) visible: !(columnObject.width === columnObject.minimumWidth && columnObject.width === columnObject.maximumWidth && columnObject.width)
cursorShape: Qt.SplitHCursor cursorShape: Qt.SplitHCursor
onPressed : onPressed :
(mouse)=>{ (mouse)=>{
@ -502,9 +502,9 @@ Rectangle {
return return
} }
var delta = Qt.point(mouse.x - clickPos.x, mouse.y - clickPos.y) var delta = Qt.point(mouse.x - clickPos.x, mouse.y - clickPos.y)
var minimumWidth = obj.minimumWidth var minimumWidth = columnObject.minimumWidth
var maximumWidth = obj.maximumWidth var maximumWidth = columnObject.maximumWidth
var w = obj.width var w = columnObject.width
if(!w){ if(!w){
w = d.defaultItemWidth w = d.defaultItemWidth
} }
@ -514,7 +514,7 @@ Rectangle {
if(!maximumWidth){ if(!maximumWidth){
maximumWidth = 65535 maximumWidth = 65535
} }
obj.width = Math.min(Math.max(minimumWidth, w + delta.x),maximumWidth) columnObject.width = Math.min(Math.max(minimumWidth, w + delta.x),maximumWidth)
table_view.forceLayout() table_view.forceLayout()
} }
} }
@ -554,6 +554,7 @@ Rectangle {
id:item_control id:item_control
readonly property real cellPadding: 8 readonly property real cellPadding: 8
property bool canceled: false property bool canceled: false
property var rowObject: table_model.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 width: implicitWidth
@ -613,16 +614,12 @@ Rectangle {
} }
MouseArea{ MouseArea{
property point clickPos: "0,0" property point clickPos: "0,0"
property bool isResize: {
var obj = table_model.getRow(row)
return !(obj.height === obj.minimumHeight && obj.height === obj.maximumHeight && obj.height)
}
height: 6 height: 6
width: parent.width width: parent.width
anchors.bottom: parent.bottom anchors.bottom: parent.bottom
acceptedButtons: Qt.LeftButton acceptedButtons: Qt.LeftButton
cursorShape: Qt.SplitVCursor cursorShape: Qt.SplitVCursor
visible: isResize visible: !(rowObject.height === rowObject.minimumHeight && rowObject.height === rowObject.maximumHeight && rowObject.height)
onPressed : onPressed :
(mouse)=>{ (mouse)=>{
header_vertical.interactive = false header_vertical.interactive = false
@ -642,11 +639,10 @@ Rectangle {
if(!pressed){ if(!pressed){
return return
} }
var obj = table_model.getRow(row)
var delta = Qt.point(mouse.x - clickPos.x, mouse.y - clickPos.y) var delta = Qt.point(mouse.x - clickPos.x, mouse.y - clickPos.y)
var minimumHeight = obj.minimumHeight var minimumHeight = rowObject.minimumHeight
var maximumHeight = obj.maximumHeight var maximumHeight = rowObject.maximumHeight
var h = obj.height var h = rowObject.height
if(!h){ if(!h){
h = d.defaultItemHeight h = d.defaultItemHeight
} }
@ -656,8 +652,8 @@ Rectangle {
if(!maximumHeight){ if(!maximumHeight){
maximumHeight = 65535 maximumHeight = 65535
} }
obj.height = Math.min(Math.max(minimumHeight, h + delta.y),maximumHeight) rowObject.height = Math.min(Math.max(minimumHeight, h + delta.y),maximumHeight)
table_model.setRow(row,obj) table_model.setRow(row,rowObject)
table_view.forceLayout() table_view.forceLayout()
} }
} }

View File

@ -245,6 +245,7 @@ Rectangle {
model: table_model model: table_model
clip: true clip: true
delegate: MouseArea{ delegate: MouseArea{
property var rowObject : table_model.getRow(row)
hoverEnabled: true hoverEnabled: true
implicitHeight: 40 implicitHeight: 40
implicitWidth: { implicitWidth: {
@ -264,7 +265,6 @@ Rectangle {
id:item_table id:item_table
anchors.fill: parent anchors.fill: parent
property point position: Qt.point(column,row) property point position: Qt.point(column,row)
property var rowObject : table_model.getRow(row)
property bool isRowSelected: d.currentIndex === rowObject.__index property bool isRowSelected: d.currentIndex === rowObject.__index
color:{ color:{
if(d.rowHoverIndex === row || item_table.isRowSelected){ if(d.rowHoverIndex === row || item_table.isRowSelected){
@ -302,7 +302,7 @@ Rectangle {
} }
onClicked: onClicked:
(event)=>{ (event)=>{
d.currentIndex = table_model.getRow(row).__index d.currentIndex = rowObject.__index
item_loader.sourceComponent = undefined item_loader.sourceComponent = undefined
event.accepted = true event.accepted = true
} }
@ -399,7 +399,7 @@ Rectangle {
readonly property real cellPadding: 8 readonly property real cellPadding: 8
property bool canceled: false property bool canceled: false
property int columnIndex: column property int columnIndex: column
readonly property var obj : columnSource[column] readonly property var columnObject : columnSource[column]
implicitWidth: { implicitWidth: {
return (item_column_loader.item && item_column_loader.item.implicitWidth) + (cellPadding * 2) return (item_column_loader.item && item_column_loader.item.implicitWidth) + (cellPadding * 2)
} }
@ -481,7 +481,7 @@ Rectangle {
anchors.right: parent.right anchors.right: parent.right
acceptedButtons: Qt.LeftButton acceptedButtons: Qt.LeftButton
hoverEnabled: true hoverEnabled: true
visible: !(obj.width === obj.minimumWidth && obj.width === obj.maximumWidth && obj.width) visible: !(columnObject.width === columnObject.minimumWidth && columnObject.width === columnObject.maximumWidth && columnObject.width)
cursorShape: Qt.SplitHCursor cursorShape: Qt.SplitHCursor
onPressed : onPressed :
(mouse)=>{ (mouse)=>{
@ -503,9 +503,9 @@ Rectangle {
return return
} }
var delta = Qt.point(mouse.x - clickPos.x, mouse.y - clickPos.y) var delta = Qt.point(mouse.x - clickPos.x, mouse.y - clickPos.y)
var minimumWidth = obj.minimumWidth var minimumWidth = columnObject.minimumWidth
var maximumWidth = obj.maximumWidth var maximumWidth = columnObject.maximumWidth
var w = obj.width var w = columnObject.width
if(!w){ if(!w){
w = d.defaultItemWidth w = d.defaultItemWidth
} }
@ -515,7 +515,7 @@ Rectangle {
if(!maximumWidth){ if(!maximumWidth){
maximumWidth = 65535 maximumWidth = 65535
} }
obj.width = Math.min(Math.max(minimumWidth, w + delta.x),maximumWidth) columnObject.width = Math.min(Math.max(minimumWidth, w + delta.x),maximumWidth)
table_view.forceLayout() table_view.forceLayout()
} }
} }
@ -555,6 +555,7 @@ Rectangle {
id:item_control id:item_control
readonly property real cellPadding: 8 readonly property real cellPadding: 8
property bool canceled: false property bool canceled: false
property var rowObject: table_model.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 width: implicitWidth
@ -614,16 +615,12 @@ Rectangle {
} }
MouseArea{ MouseArea{
property point clickPos: "0,0" property point clickPos: "0,0"
property bool isResize: {
var obj = table_model.getRow(row)
return !(obj.height === obj.minimumHeight && obj.height === obj.maximumHeight && obj.height)
}
height: 6 height: 6
width: parent.width width: parent.width
anchors.bottom: parent.bottom anchors.bottom: parent.bottom
acceptedButtons: Qt.LeftButton acceptedButtons: Qt.LeftButton
cursorShape: Qt.SplitVCursor cursorShape: Qt.SplitVCursor
visible: isResize visible: !(rowObject.height === rowObject.minimumHeight && rowObject.height === rowObject.maximumHeight && rowObject.height)
onPressed : onPressed :
(mouse)=>{ (mouse)=>{
header_vertical.interactive = false header_vertical.interactive = false
@ -643,11 +640,10 @@ Rectangle {
if(!pressed){ if(!pressed){
return return
} }
var obj = table_model.getRow(row)
var delta = Qt.point(mouse.x - clickPos.x, mouse.y - clickPos.y) var delta = Qt.point(mouse.x - clickPos.x, mouse.y - clickPos.y)
var minimumHeight = obj.minimumHeight var minimumHeight = rowObject.minimumHeight
var maximumHeight = obj.maximumHeight var maximumHeight = rowObject.maximumHeight
var h = obj.height var h = rowObject.height
if(!h){ if(!h){
h = d.defaultItemHeight h = d.defaultItemHeight
} }
@ -657,8 +653,8 @@ Rectangle {
if(!maximumHeight){ if(!maximumHeight){
maximumHeight = 65535 maximumHeight = 65535
} }
obj.height = Math.min(Math.max(minimumHeight, h + delta.y),maximumHeight) rowObject.height = Math.min(Math.max(minimumHeight, h + delta.y),maximumHeight)
table_model.setRow(row,obj) table_model.setRow(row,rowObject)
table_view.forceLayout() table_view.forceLayout()
} }
} }