ToolbarButton.qml 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. // Copyright (c) 2018 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.2 as UM
  6. import Cura 1.0 as Cura
  7. Button
  8. {
  9. id: base
  10. property alias toolItem: contentItemLoader.sourceComponent
  11. // These two properties indicate whether the toolbar button is at the top of the toolbar column or at the bottom.
  12. // If it is somewhere in the middle, then both has to be false. If there is only one element in the column, then
  13. // both properties have to be set to true. This is used to create a rounded corner.
  14. property bool isTopElement: false
  15. property bool isBottomElement: false
  16. hoverEnabled: true
  17. background: Rectangle
  18. {
  19. implicitWidth: UM.Theme.getSize("button").width
  20. implicitHeight: UM.Theme.getSize("button").height
  21. color:
  22. {
  23. if (base.checked && base.hovered)
  24. {
  25. return UM.Theme.getColor("toolbar_button_active_hover")
  26. }
  27. else if (base.checked)
  28. {
  29. return UM.Theme.getColor("toolbar_button_active")
  30. }
  31. else if(base.hovered)
  32. {
  33. return UM.Theme.getColor("toolbar_button_hover")
  34. }
  35. return UM.Theme.getColor("toolbar_background")
  36. }
  37. radius: UM.Theme.getSize("default_radius").width
  38. Rectangle
  39. {
  40. id: topSquare
  41. anchors
  42. {
  43. left: parent.left
  44. right: parent.right
  45. top: parent.top
  46. }
  47. height: parent.radius
  48. color: parent.color
  49. visible: !base.isTopElement
  50. }
  51. Rectangle
  52. {
  53. id: bottomSquare
  54. anchors
  55. {
  56. left: parent.left
  57. right: parent.right
  58. bottom: parent.bottom
  59. }
  60. height: parent.radius
  61. color: parent.color
  62. visible: !base.isBottomElement
  63. }
  64. Rectangle
  65. {
  66. id: leftSquare
  67. anchors
  68. {
  69. left: parent.left
  70. top: parent.top
  71. bottom: parent.bottom
  72. }
  73. width: parent.radius
  74. color: parent.color
  75. }
  76. }
  77. contentItem: Item
  78. {
  79. opacity: parent.enabled ? 1.0 : 0.2
  80. Loader
  81. {
  82. id: contentItemLoader
  83. anchors.centerIn: parent
  84. width: UM.Theme.getSize("button_icon").width
  85. height: UM.Theme.getSize("button_icon").height
  86. }
  87. }
  88. Cura.ToolTip
  89. {
  90. id: tooltip
  91. tooltipText: base.text
  92. visible: base.hovered
  93. }
  94. }