mirror of
https://git.mirrors.martin98.com/https://github.com/Ultimaker/Cura
synced 2025-08-14 15:15:56 +08:00
Add default text in the ComboBox
The Cura.ComboBox component can now display a default text when there are no items in its model and another text when there is no item selected. CURA-7865
This commit is contained in:
parent
2774ec7bdf
commit
fc718892d9
@ -15,6 +15,18 @@ ComboBox
|
|||||||
{
|
{
|
||||||
id: control
|
id: control
|
||||||
|
|
||||||
|
UM.I18nCatalog
|
||||||
|
{
|
||||||
|
id: catalog
|
||||||
|
name: "cura"
|
||||||
|
}
|
||||||
|
|
||||||
|
property var defaultTextOnEmptyModel: catalog.i18nc("@label", "No items to select from") // Text displayed in the combobox when the model is empty
|
||||||
|
property var defaultTextOnEmptyIndex: "" // Text displayed in the combobox when the model has items but no item is selected
|
||||||
|
enabled: model.count > 0
|
||||||
|
|
||||||
|
onVisibleChanged: { popup.close() }
|
||||||
|
|
||||||
states: [
|
states: [
|
||||||
State
|
State
|
||||||
{
|
{
|
||||||
@ -67,11 +79,22 @@ ComboBox
|
|||||||
anchors.verticalCenter: parent.verticalCenter
|
anchors.verticalCenter: parent.verticalCenter
|
||||||
anchors.right: downArrow.left
|
anchors.right: downArrow.left
|
||||||
|
|
||||||
text: control.currentText
|
text:
|
||||||
|
{
|
||||||
|
if (control.model.count == 0)
|
||||||
|
{
|
||||||
|
return control.defaultTextOnEmptyModel != "" ? control.defaultTextOnEmptyModel : control.defaultTextOnEmptyIndex
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return control.currentIndex == -1 ? control.defaultTextOnEmptyIndex : control.currentText
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
textFormat: Text.PlainText
|
textFormat: Text.PlainText
|
||||||
renderType: Text.NativeRendering
|
renderType: Text.NativeRendering
|
||||||
font: UM.Theme.getFont("default")
|
font: UM.Theme.getFont("default")
|
||||||
color: UM.Theme.getColor("setting_control_text")
|
color: control.currentIndex == -1 ? UM.Theme.getColor("setting_control_disabled_text") : UM.Theme.getColor("setting_control_text")
|
||||||
elide: Text.ElideRight
|
elide: Text.ElideRight
|
||||||
verticalAlignment: Text.AlignVCenter
|
verticalAlignment: Text.AlignVCenter
|
||||||
}
|
}
|
||||||
@ -81,6 +104,7 @@ ComboBox
|
|||||||
y: control.height - UM.Theme.getSize("default_lining").height
|
y: control.height - UM.Theme.getSize("default_lining").height
|
||||||
width: control.width
|
width: control.width
|
||||||
implicitHeight: contentItem.implicitHeight + 2 * UM.Theme.getSize("default_lining").width
|
implicitHeight: contentItem.implicitHeight + 2 * UM.Theme.getSize("default_lining").width
|
||||||
|
bottomMargin: UM.Theme.getSize("default_margin").height
|
||||||
padding: UM.Theme.getSize("default_lining").width
|
padding: UM.Theme.getSize("default_lining").width
|
||||||
|
|
||||||
contentItem: ListView
|
contentItem: ListView
|
||||||
@ -133,7 +157,7 @@ ComboBox
|
|||||||
text: delegateItem.text
|
text: delegateItem.text
|
||||||
textFormat: Text.PlainText
|
textFormat: Text.PlainText
|
||||||
renderType: Text.NativeRendering
|
renderType: Text.NativeRendering
|
||||||
color: control.contentItem.color
|
color: UM.Theme.getColor("setting_control_text")
|
||||||
font: UM.Theme.getFont("default")
|
font: UM.Theme.getFont("default")
|
||||||
elide: Text.ElideRight
|
elide: Text.ElideRight
|
||||||
verticalAlignment: Text.AlignVCenter
|
verticalAlignment: Text.AlignVCenter
|
||||||
|
Loading…
x
Reference in New Issue
Block a user