Make ComboBoxes work a bit more

This commit is contained in:
Yuri Becker
2025-03-19 13:28:31 +01:00
parent 325e396774
commit 13416edd25

View File

@@ -16,60 +16,75 @@ T.ComboBox {
height: 47 height: 47
radius: Dimensions.radius radius: Dimensions.radius
} }
contentItem: T.TextField {
autoScroll: control.editable
color: Colors.foreground
enabled: control.editable
font: Typography.body
inputMethodHints: control.inputMethodHints
readOnly: control.down
selectByMouse: control.selectTextByMouse
text: control.editable ? control.editText : control.displayText
validator: control.validator
}
delegate: MenuItem {
id: menuItem
required property int index
required property var model
delegate: T.ItemDelegate {
width: control.width
height: implicitContentHeight + topPadding + bottomPadding
padding: Dimensions.s
leftPadding: control.leftPadding
contentItem: Label {
text: control.textRole ? model[control.textRole] : modelData
color: Colors.foreground
elide: Text.ElideRight
verticalAlignment: Text.AlignVCenter
}
highlighted: control.highlightedIndex === index highlighted: control.highlightedIndex === index
hoverEnabled: control.hoverEnabled
text: model[control.textRole]
width: control.width
background: Rectangle {
color: menuItem.down || menuItem.highlighted ? Colors.primary : "transparent"
height: menuItem.height
width: menuItem.width
}
} }
indicator: Label { indicator: Label {
x: control.width - width
height: control.height height: control.height
width: contentWidth + Dimensions.s * 2
text: "▼"
verticalAlignment: Text.AlignVCenter
horizontalAlignment: Text.AlignHCenter horizontalAlignment: Text.AlignHCenter
padding: Dimensions.s padding: Dimensions.s
text: "▼"
verticalAlignment: Text.AlignVCenter
width: contentWidth + Dimensions.s * 2
x: control.width - width
background: Rectangle { background: Rectangle {
anchors.fill: parent anchors.fill: parent
border.color: Colors.interactive
bottomRightRadius: Dimensions.radius
color: Colors.primary color: Colors.primary
topRightRadius: Dimensions.radius topRightRadius: Dimensions.radius
bottomRightRadius: Dimensions.radius
border.color: Colors.interactive
} }
} }
popup: T.Popup { popup: T.Popup {
y: control.height
z: 2
width: control.width width: control.width
height: Math.min(contentItem.implicitHeight + 2, control.Window.height - topMargin - bottomMargin)
topMargin: 6
bottomMargin: 6
padding: 1
background: Rectangle {
border.color: Colors.interactive
color: Colors.mantle
radius: Dimensions.radius
}
contentItem: ListView { contentItem: ListView {
clip: true clip: true
currentIndex: control.highlightedIndex
implicitHeight: contentHeight implicitHeight: contentHeight
model: control.popup.visible ? control.delegateModel : null model: control.popup.visible ? control.delegateModel : null
currentIndex: control.highlightedIndex
T.ScrollBar.vertical: ScrollBar { }
highlight: Rectangle { highlight: Rectangle {
color: Colors.primary color: Colors.primary
opacity: Colors.highlightOpacity opacity: Colors.highlightOpacity
} }
ScrollIndicator.vertical: ScrollIndicator {}
}
background: Rectangle {
color: Colors.mantle
border.color: Colors.interactive
radius: Dimensions.radius
} }
} }
} }