Skip to content
Open
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
57 changes: 38 additions & 19 deletions qt6/src/qml/ArrowListView.qml
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,28 @@ FocusScope {
property int itemHeight: DS.Style.arrowListView.itemHeight
property alias view: itemsView

// Full height of the list, to size a popup before it is mapped.
// Height of a visible realized row, or the style height before one exists:
// row 0 can be a row hidden by a visible role, and its height is 0.
readonly property real _rowHeight: {
if (itemsView.contentHeight > 0) {
for (var i = 0; i < itemsView.count; ++i) {
const item = itemsView.itemAtIndex(i)
if (item && item.visible && item.height > 0)
return item.height
}
}
return 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)
Expand All @@ -44,21 +57,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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

implicitWidth重构与原来的逻辑是一样的吧,只是多了个visible的判断么?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

算是,重复逻辑都抽出到refreshContentItemWidth中,

另外就是主要是修复了一个循环依赖,popup, menuitem 相互取宽度,导致最终算出来的宽度是错误的。
删除 implicitWidth: Math.max(DS.Style.control.implicitWidth(control), popup.implicitWidth - DS.Style.popup.margin * 2)

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 +82,29 @@ FocusScope {
highlightMoveDuration: -1
highlightMoveVelocity: 400

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

onCountChanged: {
itemMaxWidth = 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 (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