RecommendedResolutionSelector.qml 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. // Copyright (c) 2022 Ultimaker B.V.
  2. // Cura is released under the terms of the LGPLv3 or higher.
  3. import QtQuick 2.10
  4. import UM 1.6 as UM
  5. import Cura 1.7 as Cura
  6. Item
  7. {
  8. id: recommendedResolutionSelector
  9. height: childrenRect.height
  10. property real labelColumnWidth: Math.round(width / 3)
  11. property string _previousResolution: "" //Internal variable to detect changes.
  12. Component.onCompleted: _previousResolution = Cura.MachineManager.activeQualityType;
  13. visible: visibilityPreset.count > 0 //Only show if there are quality types to select from.
  14. Cura.IconWithText
  15. {
  16. id: resolutionTitle
  17. anchors.top: parent.top
  18. anchors.left: parent.left
  19. source: UM.Theme.getIcon("PrintQuality")
  20. text: catalog.i18nc("@label", "Resolution")
  21. width: labelColumnWidth
  22. height: parent.height
  23. spacing: UM.Theme.getSize("thick_margin").width
  24. iconSize: UM.Theme.getSize("medium_button_icon").width
  25. }
  26. Cura.ComboBox
  27. {
  28. id: visibilityPreset
  29. implicitHeight: UM.Theme.getSize("combobox").height
  30. implicitWidth: UM.Theme.getSize("combobox").width
  31. anchors
  32. {
  33. top: parent.top
  34. right: parent.right
  35. }
  36. textRole: "display_text"
  37. textFormat: Text.StyledText
  38. model: Cura.ActiveIntentQualitiesModel{}
  39. currentIndex:
  40. {
  41. var current_quality_type = Cura.MachineManager.activeQualityType
  42. var index = 0
  43. for (var i = 0; i < model.count; i++)
  44. {
  45. if (model.getItem(i).quality_type == current_quality_type)
  46. {
  47. index = i
  48. break
  49. }
  50. }
  51. return index
  52. }
  53. onActivated:
  54. {
  55. var selected_item = model.getItem(currentIndex)
  56. Cura.IntentManager.selectIntent(selected_item.intent_category, selected_item.quality_type)
  57. if (Cura.IntentManager.currentIntentCategory == selected_item.intent_category)
  58. {
  59. recommendedResolutionSelector._previousResolution = selected_item.quality_type;
  60. }
  61. }
  62. Connections
  63. {
  64. target: Cura.IntentManager
  65. function onIntentCategoryChanged()
  66. {
  67. if(recommendedResolutionSelector._previousResolution !== Cura.MachineManager.activeQualityType)
  68. {
  69. visibilityPreset.pulse();
  70. }
  71. recommendedResolutionSelector._previousResolution = Cura.MachineManager.activeQualityType;
  72. }
  73. }
  74. }
  75. }