Improve Delegate Width Sizing

Create a cpp helper class to calculate the correct delegate width given it's parent width.

This is designed to be more robust and hopefully easier to understand than the current mass of javascript calcs.

BUG: 470167
This commit is contained in:
James Graham
2023-05-30 18:14:25 +00:00
parent f1be509d13
commit fa37f28c94
10 changed files with 492 additions and 23 deletions

View File

@@ -14,11 +14,7 @@ QQC2.Control {
readonly property bool sectionVisible: model.showSection
// extraWidth defines how the delegate can grow after the listView gets very wide
readonly property int extraWidth: parent ? (parent.width >= Kirigami.Units.gridUnit * 46 ? Math.min((parent.width - Kirigami.Units.gridUnit * 46), Kirigami.Units.gridUnit * 20) : 0) : 0
readonly property int delegateMaxWidth: parent ? (Config.compactLayout ? parent.width: Math.min(parent.width, Kirigami.Units.gridUnit * 40 + extraWidth)) : 0
width: delegateMaxWidth
width: stateDelegateSizeHelper.currentWidth
state: Config.compactLayout ? "alignLeft" : "alignCenter"
// Align left when in compact mode and center when using bubbles
@@ -170,4 +166,15 @@ QQC2.Control {
excessAvatars: excessReadMarkers
}
}
DelegateSizeHelper {
id: stateDelegateSizeHelper
startBreakpoint: Kirigami.Units.gridUnit * 46
endBreakpoint: Kirigami.Units.gridUnit * 66
startPercentWidth: 100
endPercentWidth: Config.compactLayout ? 100 : 85
maxWidth: Config.compactLayout ? -1 : Kirigami.Units.gridUnit * 60
parentWidth: stateDelegate.parent ? stateDelegate.parent.width : 0
}
}