SimpleCheckBox.qml 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. // Copyright (c) 2020 Ultimaker B.V.
  2. // Cura is released under the terms of the LGPLv3 or higher.
  3. import QtQuick 2.10
  4. import QtQuick.Controls 2.3
  5. import QtQuick.Layouts 1.3
  6. import UM 1.3 as UM
  7. import Cura 1.1 as Cura
  8. //
  9. // CheckBox widget for the on/off or true/false settings in the Machine Settings Dialog.
  10. //
  11. UM.TooltipArea
  12. {
  13. id: simpleCheckBox
  14. UM.I18nCatalog { id: catalog; name: "cura"; }
  15. property int controlHeight: UM.Theme.getSize("setting_control").height
  16. height: childrenRect.height
  17. width: childrenRect.width
  18. text: tooltip
  19. property alias containerStackId: propertyProvider.containerStackId
  20. property alias settingKey: propertyProvider.key
  21. property alias settingStoreIndex: propertyProvider.storeIndex
  22. property alias labelText: fieldLabel.text
  23. property alias labelFont: fieldLabel.font
  24. property alias labelWidth: fieldLabel.width
  25. property string tooltip: propertyProvider.properties.description ? propertyProvider.properties.description : ""
  26. // callback functions
  27. property var forceUpdateOnChangeFunction: dummy_func
  28. // a dummy function for default property values
  29. function dummy_func() {}
  30. UM.SettingPropertyProvider
  31. {
  32. id: propertyProvider
  33. watchedProperties: [ "value", "description" ]
  34. }
  35. Label
  36. {
  37. id: fieldLabel
  38. anchors.left: parent.left
  39. anchors.verticalCenter: checkBox.verticalCenter
  40. visible: text != ""
  41. font: UM.Theme.getFont("medium")
  42. color: UM.Theme.getColor("text")
  43. renderType: Text.NativeRendering
  44. }
  45. Cura.CheckBox
  46. {
  47. id: checkBox
  48. anchors.left: fieldLabel.right
  49. anchors.leftMargin: UM.Theme.getSize("default_margin").width
  50. checked: String(propertyProvider.properties.value).toLowerCase() != 'false'
  51. height: simpleCheckBox.controlHeight
  52. text: ""
  53. onClicked:
  54. {
  55. propertyProvider.setPropertyValue("value", checked)
  56. forceUpdateOnChangeFunction()
  57. }
  58. }
  59. }