ToolbarButton.qml 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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: UM.Theme.getColor("toolbar_background")
  22. radius: UM.Theme.getSize("default_radius").width
  23. Rectangle
  24. {
  25. id: topSquare
  26. anchors
  27. {
  28. left: parent.left
  29. right: parent.right
  30. top: parent.top
  31. }
  32. height: parent.radius
  33. color: parent.color
  34. visible: !base.isTopElement
  35. }
  36. Rectangle
  37. {
  38. id: bottomSquare
  39. anchors
  40. {
  41. left: parent.left
  42. right: parent.right
  43. bottom: parent.bottom
  44. }
  45. height: parent.radius
  46. color: parent.color
  47. visible: !base.isBottomElement
  48. }
  49. Rectangle
  50. {
  51. id: leftSquare
  52. anchors
  53. {
  54. left: parent.left
  55. top: parent.top
  56. bottom: parent.bottom
  57. }
  58. width: parent.radius
  59. color: parent.color
  60. }
  61. }
  62. contentItem: Rectangle
  63. {
  64. opacity: parent.enabled ? 1.0 : 0.2
  65. implicitWidth: Math.round(UM.Theme.getSize("button").width * 0.75)
  66. implicitHeight: Math.round(UM.Theme.getSize("button").height * 0.75)
  67. radius: Math.round(width * 0.5)
  68. color:
  69. {
  70. if (base.checked && base.hovered)
  71. {
  72. return UM.Theme.getColor("toolbar_button_active_hover")
  73. }
  74. else if (base.checked)
  75. {
  76. return UM.Theme.getColor("toolbar_button_active")
  77. }
  78. else if(base.hovered)
  79. {
  80. return UM.Theme.getColor("toolbar_button_hover")
  81. }
  82. return UM.Theme.getColor("toolbar_background")
  83. }
  84. Loader
  85. {
  86. id: contentItemLoader
  87. anchors.centerIn: parent
  88. width: Math.round(UM.Theme.getSize("button").width / 2)
  89. height: Math.round(UM.Theme.getSize("button").height / 2)
  90. }
  91. }
  92. Cura.ToolTip
  93. {
  94. id: tooltip
  95. tooltipText: base.text
  96. visible: base.hovered
  97. }
  98. }