ObjectItemButton.qml 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. // Copyright (c) 2018 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 UM 1.1 as UM
  6. import Cura 1.0 as Cura
  7. Button
  8. {
  9. id: objectItemButton
  10. width: parent.width
  11. height: UM.Theme.getSize("action_button").height
  12. leftPadding: UM.Theme.getSize("thin_margin").width
  13. rightPadding: UM.Theme.getSize("thin_margin").width
  14. checkable: true
  15. hoverEnabled: true
  16. contentItem: Item
  17. {
  18. width: objectItemButton.width - objectItemButton.leftPadding
  19. height: UM.Theme.getSize("action_button").height
  20. Label
  21. {
  22. id: buttonText
  23. anchors
  24. {
  25. left: parent.left
  26. right: parent.right
  27. verticalCenter: parent.verticalCenter
  28. }
  29. text: objectItemButton.text
  30. font: UM.Theme.getFont("default")
  31. color: UM.Theme.getColor("text_scene")
  32. visible: text != ""
  33. renderType: Text.NativeRendering
  34. verticalAlignment: Text.AlignVCenter
  35. elide: Text.ElideRight
  36. }
  37. }
  38. background: Rectangle
  39. {
  40. id: backgroundRect
  41. color: objectItemButton.hovered ? UM.Theme.getColor("action_button_hovered") : "transparent"
  42. radius: UM.Theme.getSize("action_button_radius").width
  43. border.width: UM.Theme.getSize("default_lining").width
  44. border.color: objectItemButton.checked ? UM.Theme.getColor("primary") : "transparent"
  45. }
  46. TextMetrics
  47. {
  48. id: buttonTextMetrics
  49. text: buttonText.text
  50. font: buttonText.font
  51. elide: buttonText.elide
  52. elideWidth: buttonText.width
  53. }
  54. Cura.ToolTip
  55. {
  56. id: tooltip
  57. tooltipText: objectItemButton.text
  58. visible: objectItemButton.hovered && buttonTextMetrics.elidedText != buttonText.text
  59. }
  60. onClicked: Cura.SceneController.changeSelection(index)
  61. }