MenuItem.qml 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. // Copyright (c) 2021 Ultimaker B.V.
  2. // Cura is released under the terms of the LGPLv3 or higher.
  3. import QtQuick 2.7
  4. import QtQuick.Controls 2.3
  5. import UM 1.1 as UM
  6. //
  7. // MenuItem with Cura styling.
  8. //
  9. MenuItem
  10. {
  11. id: menuItem
  12. implicitHeight: UM.Theme.getSize("setting_control").height + UM.Theme.getSize("narrow_margin").height
  13. opacity: enabled ? 1.0 : 0.5
  14. arrow: UM.RecolorImage
  15. {
  16. visible: menuItem.subMenu
  17. height: UM.Theme.getSize("default_arrow").height
  18. width: height
  19. anchors.verticalCenter: parent.verticalCenter
  20. anchors.right: parent.right
  21. anchors.rightMargin: UM.Theme.getSize("default_margin").width
  22. source: UM.Theme.getIcon("ChevronSingleRight")
  23. color: UM.Theme.getColor("setting_control_text")
  24. }
  25. indicator: UM.RecolorImage
  26. {
  27. id: check
  28. visible: menuItem.checkable && menuItem.checked
  29. height: UM.Theme.getSize("default_arrow").height
  30. width: height
  31. anchors.verticalCenter: parent.verticalCenter
  32. anchors.left: parent.left
  33. anchors.leftMargin: UM.Theme.getSize("default_margin").width
  34. source: UM.Theme.getIcon("Check")
  35. color: UM.Theme.getColor("setting_control_text")
  36. }
  37. contentItem: Text {
  38. leftPadding: menuItem.checkable ? menuItem.indicator.width + UM.Theme.getSize("default_margin").width : UM.Theme.getSize("thin_margin").width
  39. rightPadding: menuItem.subMenu ? menuItem.arrow.width + UM.Theme.getSize("default_margin").width : UM.Theme.getSize("thin_margin").width
  40. text: menuItem.text
  41. textFormat: Text.PlainText
  42. renderType: Text.NativeRendering
  43. color: UM.Theme.getColor("setting_control_text")
  44. font: UM.Theme.getFont("default")
  45. elide: Text.ElideRight
  46. verticalAlignment: Text.AlignVCenter
  47. }
  48. background: Rectangle {
  49. x: UM.Theme.getSize("default_lining").width
  50. y: UM.Theme.getSize("default_lining").width
  51. width: menuItem.width - 2 * UM.Theme.getSize("default_lining").width
  52. height: menuItem.height - 2 * UM.Theme.getSize("default_lining").height
  53. color: menuItem.highlighted ? UM.Theme.getColor("setting_control_highlight") : "transparent"
  54. border.color: menuItem.highlighted ? UM.Theme.getColor("setting_control_border_highlight") : "transparent"
  55. }
  56. }