Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 41 additions & 18 deletions qt6/src/qml/ArrowListView.qml
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,32 @@ FocusScope {
property int itemHeight: DS.Style.arrowListView.itemHeight
property alias view: itemsView

// Fixed per show: rows realized while scrolling can differ in height.
property real _measuredRowHeight: 0
readonly property real _rowHeight: _measuredRowHeight > 0 ? _measuredRowHeight : itemHeight

// Full height of the list, to size a popup before it is mapped.
readonly property real sizedHeight: {
if (itemsView.count === 0)
return 0
const item = itemsView.itemAtIndex(0)
const measured = itemsView.contentHeight > 0 && item ? (item.height || item.implicitHeight) : 0
if (itemsView.contentHeight > 0)
return implicitHeight
const arrowStrips = itemsView.count > maxVisibleItems
? 2 * (DS.Style.arrowListView.stepButtonIconSize.height + contentLayout.spacing) : 0
return Math.min(itemsView.count, maxVisibleItems) * (measured > 0 ? measured : itemHeight) + arrowStrips
return Math.min(itemsView.count, maxVisibleItems) * _rowHeight + arrowStrips
}

implicitWidth: Math.max(DS.Style.arrowListView.width, contentLayout.implicitWidth)
implicitHeight: contentLayout.implicitHeight

onVisibleChanged: {
if (!visible)
return
itemsView.itemMaxWidth = 0
_measuredRowHeight = 0
itemsView.refreshContentItemWidth()
}

ColumnLayout {
id: contentLayout
anchors.fill: parent
Expand All @@ -44,21 +56,14 @@ FocusScope {

ListView {
id: itemsView
property real itemMaxWidth: 0
clip: true
Layout.fillWidth: true
Layout.fillHeight: true
onHeightChanged: if (height > 0 && contentHeight === 0) forceLayout()
implicitHeight: itemsView.count > 0 ? Math.min(contentHeight, maxVisibleItems * contentHeight / itemsView.count) : 0
implicitWidth:{
var maxWidth = DS.Style.arrowListView.width
for (var i = 0; i < itemsView.count; ++i) {
var item = itemsView.itemAtIndex(i)
if (item && item.implicitWidth > maxWidth)
maxWidth = item.implicitWidth
}
return maxWidth
}
interactive: itemsView.count > maxVisibleItems
implicitHeight: itemsView.count > 0 ? Math.min(contentHeight, maxVisibleItems * control._rowHeight) : 0
implicitWidth: itemMaxWidth
Comment thread
mhduiy marked this conversation as resolved.
Resolved
interactive: itemsView.contentHeight > itemsView.height
ScrollIndicator.vertical: ScrollIndicator { }
highlight: HighlightPanel {
visible: false // TODO listview's highlight is confict with Item's highlight.
Expand All @@ -76,16 +81,34 @@ FocusScope {
highlightMoveDuration: -1
highlightMoveVelocity: 400

onCountChanged: refreshContentItemWidth()
Connections {
target: itemsView.contentItem
function onChildrenChanged() { Qt.callLater(itemsView.refreshContentItemWidth) }
}

onCountChanged: {
itemMaxWidth = 0
control._measuredRowHeight = 0
refreshContentItemWidth()
}

onContentHeightChanged: if (control._measuredRowHeight <= 0) refreshContentItemWidth()

onWidthChanged: refreshContentItemWidth()

function refreshContentItemWidth() {
var maxWidth = itemMaxWidth
for (var i = 0; i < itemsView.count; ++i) {
var item = itemsView.itemAtIndex(i)
if (item) {
item.width = itemsView.width
}
if (!item || !item.visible)
continue
item.width = itemsView.width
if (control._measuredRowHeight <= 0 && item.height > 0)
control._measuredRowHeight = item.height
if (item.implicitWidth > maxWidth)
maxWidth = item.implicitWidth
}
itemMaxWidth = maxWidth
}
}

Expand Down
3 changes: 1 addition & 2 deletions qt6/src/qml/ComboBox.qml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ T.ComboBox {
bottomPadding: control.flat ? 0 : padding

delegate: MenuItem {
implicitWidth: Math.max(DS.Style.control.implicitWidth(control), popup.implicitWidth - DS.Style.popup.margin * 2)
useIndicatorPadding: true
text: control.textRole ? (Array.isArray(control.model) ? modelData[control.textRole] : (model[control.textRole] === undefined ? modelData[control.textRole] : model[control.textRole])) : modelData
icon.name: (control.iconNameRole && model[control.iconNameRole] !== undefined) ? model[control.iconNameRole] : null
Expand Down Expand Up @@ -172,7 +171,7 @@ T.ComboBox {
leftMargin: DS.Style.popup.margin
rightMargin: DS.Style.popup.margin
palette: control.palette
implicitWidth: control.flat ? Math.max(contentItem.implicitWidth, control.width) : control.width
implicitWidth: control.flat ? Math.max(contentItem.implicitWidth + leftPadding + rightPadding, control.width) : control.width
// 60 is a temporary viewport so the list can realize one row and be measured.
implicitHeight: (contentItem.sizedHeight > 0 ? contentItem.sizedHeight : 2 * DS.Style.arrowListView.itemHeight)
+ topPadding + bottomPadding
Expand Down
Loading