123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 |
- // Copyright (c) 2019 Ultimaker B.V.
- // Cura is released under the terms of the LGPLv3 or higher.
- import QtQuick 2.10
- import QtQuick.Controls 2.3
- import QtQuick.Layouts 1.3
- import UM 1.3 as UM
- import Cura 1.1 as Cura
- //
- // ComboBox with dropdown options in the Machine Settings dialog.
- //
- UM.TooltipArea
- {
- id: comboBoxWithOptions
- UM.I18nCatalog { id: catalog; name: "cura"; }
- height: childrenRect.height
- width: childrenRect.width
- text: tooltipText
- property alias containerStackId: propertyProvider.containerStackId
- property alias settingKey: propertyProvider.key
- property alias settingStoreIndex: propertyProvider.storeIndex
- property alias labelText: fieldLabel.text
- property alias labelWidth: fieldLabel.width
- property string tooltipText: propertyProvider.properties.description
- // callback functions
- property var afterOnActivateFunction: dummy_func
- property var forceUpdateOnChangeFunction: dummy_func
- // a dummy function for default property values
- function dummy_func() {}
- UM.SettingPropertyProvider
- {
- id: propertyProvider
- watchedProperties: [ "value", "options", "description" ]
- }
- Row
- {
- spacing: UM.Theme.getSize("default_margin").width
- Label
- {
- id: fieldLabel
- anchors.verticalCenter: comboBox.verticalCenter
- visible: text != ""
- elide: Text.ElideRight
- //width: Math.max(0, settingsTabs.labelColumnWidth)
- }
- ListModel
- {
- id: optionsModel
- Component.onCompleted:
- {
- // Options come in as a string-representation of an OrderedDict
- var options = propertyProvider.properties.options.match(/^OrderedDict\(\[\((.*)\)\]\)$/)
- if (options)
- {
- options = options[1].split("), (")
- for (var i = 0; i < options.length; i++)
- {
- var option = options[i].substring(1, options[i].length - 1).split("', '")
- optionsModel.append({text: option[1], value: option[0]})
- }
- }
- }
- }
- ComboBox
- {
- id: comboBox
- model: optionsModel
- textRole: "text"
- currentIndex:
- {
- var currentValue = propertyProvider.properties.value
- var index = 0
- for (var i = 0; i < model.count; i++)
- {
- if (model.get(i).value == currentValue)
- {
- index = i
- break
- }
- }
- return index
- }
- onActivated:
- {
- if(propertyProvider.properties.value != model.get(index).value)
- {
- propertyProvider.setPropertyValue("value", model.get(index).value)
- forceUpdateOnChangeFunction()
- afterOnActivateFunction()
- }
- }
- }
- }
- }
|