Toolbar.qml 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. // Copyright (c) 2018 Ultimaker B.V.
  2. // Cura is released under the terms of the LGPLv3 or higher.
  3. import QtQuick 2.2
  4. import QtQuick.Controls 2.3
  5. import UM 1.2 as UM
  6. import Cura 1.0 as Cura
  7. Item
  8. {
  9. id: base
  10. width: buttons.width
  11. height: buttons.height
  12. property int activeY
  13. Item
  14. {
  15. id: buttons
  16. width: parent.visible ? toolButtons.width : 0
  17. height: childrenRect.height
  18. Behavior on width { NumberAnimation { duration: 100 } }
  19. // Used to create a rounded rectangle behind the toolButtons
  20. Rectangle
  21. {
  22. anchors
  23. {
  24. fill: toolButtons
  25. leftMargin: -radius - border.width
  26. rightMargin: -border.width
  27. topMargin: -border.width
  28. bottomMargin: -border.width
  29. }
  30. radius: UM.Theme.getSize("default_radius").width
  31. color: UM.Theme.getColor("lining")
  32. }
  33. Column
  34. {
  35. id: toolButtons
  36. anchors.top: parent.top
  37. anchors.right: parent.right
  38. spacing: UM.Theme.getSize("default_lining").height
  39. Repeater
  40. {
  41. id: repeat
  42. model: UM.ToolModel { id: toolsModel }
  43. width: childrenRect.width
  44. height: childrenRect.height
  45. delegate: ToolbarButton
  46. {
  47. text: model.name + (model.shortcut ? (" (" + model.shortcut + ")") : "")
  48. checkable: true
  49. checked: model.active
  50. enabled: model.enabled && UM.Selection.hasSelection && UM.Controller.toolsEnabled
  51. isTopElement: toolsModel.getItem(0).id == model.id
  52. isBottomElement: toolsModel.getItem(toolsModel.count - 1).id == model.id
  53. toolItem: UM.RecolorImage
  54. {
  55. source: UM.Theme.getIcon(model.icon) != "" ? UM.Theme.getIcon(model.icon) : "file:///" + model.location + "/" + model.icon
  56. color: UM.Theme.getColor("icon")
  57. sourceSize: UM.Theme.getSize("button_icon")
  58. }
  59. onCheckedChanged:
  60. {
  61. if (checked)
  62. {
  63. base.activeY = y;
  64. }
  65. }
  66. //Workaround since using ToolButton's onClicked would break the binding of the checked property, instead
  67. //just catch the click so we do not trigger that behaviour.
  68. MouseArea
  69. {
  70. anchors.fill: parent;
  71. onClicked:
  72. {
  73. forceActiveFocus() //First grab focus, so all the text fields are updated
  74. if(parent.checked)
  75. {
  76. UM.Controller.setActiveTool(null);
  77. }
  78. else
  79. {
  80. UM.Controller.setActiveTool(model.id);
  81. }
  82. }
  83. }
  84. }
  85. }
  86. }
  87. // Used to create a rounded rectangle behind the extruderButtons
  88. Rectangle
  89. {
  90. anchors
  91. {
  92. fill: extruderButtons
  93. leftMargin: -radius - border.width
  94. rightMargin: -border.width
  95. topMargin: -border.width
  96. bottomMargin: -border.width
  97. }
  98. radius: UM.Theme.getSize("default_radius").width
  99. color: UM.Theme.getColor("lining")
  100. visible: extrudersModel.items.length > 1
  101. }
  102. Column
  103. {
  104. id: extruderButtons
  105. anchors.topMargin: UM.Theme.getSize("default_margin").height
  106. anchors.top: toolButtons.bottom
  107. anchors.right: parent.right
  108. spacing: UM.Theme.getSize("default_lining").height
  109. Repeater
  110. {
  111. id: extruders
  112. width: childrenRect.width
  113. height: childrenRect.height
  114. model: extrudersModel.items.length > 1 ? extrudersModel : 0
  115. delegate: ExtruderButton
  116. {
  117. extruder: model
  118. isTopElement: extrudersModel.getItem(0).id == model.id
  119. isBottomElement: extrudersModel.getItem(extrudersModel.rowCount() - 1).id == model.id
  120. }
  121. }
  122. }
  123. }
  124. property var extrudersModel: CuraApplication.getExtrudersModel()
  125. UM.PointingRectangle
  126. {
  127. id: panelBorder
  128. anchors.left: parent.right
  129. anchors.leftMargin: UM.Theme.getSize("default_margin").width
  130. anchors.top: base.top
  131. anchors.topMargin: base.activeY
  132. z: buttons.z - 1
  133. target: Qt.point(parent.right, base.activeY + Math.round(UM.Theme.getSize("button").height/2))
  134. arrowSize: UM.Theme.getSize("default_arrow").width
  135. width:
  136. {
  137. if (panel.item && panel.width > 0)
  138. {
  139. return Math.max(panel.width + 2 * UM.Theme.getSize("default_margin").width)
  140. }
  141. else
  142. {
  143. return 0;
  144. }
  145. }
  146. height: panel.item ? panel.height + 2 * UM.Theme.getSize("default_margin").height : 0
  147. opacity: panel.item && panel.width > 0 ? 1 : 0
  148. Behavior on opacity { NumberAnimation { duration: 100 } }
  149. color: UM.Theme.getColor("tool_panel_background")
  150. borderColor: UM.Theme.getColor("lining")
  151. borderWidth: UM.Theme.getSize("default_lining").width
  152. MouseArea //Catch all mouse events (so scene doesnt handle them)
  153. {
  154. anchors.fill: parent
  155. acceptedButtons: Qt.NoButton
  156. onWheel: wheel.accepted = true
  157. }
  158. Loader
  159. {
  160. id: panel
  161. x: UM.Theme.getSize("default_margin").width
  162. y: UM.Theme.getSize("default_margin").height
  163. source: UM.ActiveTool.valid ? UM.ActiveTool.activeToolPanel : ""
  164. enabled: UM.Controller.toolsEnabled
  165. }
  166. }
  167. // This rectangle displays the information about the current angle etc. when
  168. // dragging a tool handle.
  169. Rectangle
  170. {
  171. x: -base.x + base.mouseX + UM.Theme.getSize("default_margin").width
  172. y: -base.y + base.mouseY + UM.Theme.getSize("default_margin").height
  173. width: toolHint.width + UM.Theme.getSize("default_margin").width
  174. height: toolHint.height;
  175. color: UM.Theme.getColor("tooltip")
  176. Label
  177. {
  178. id: toolHint
  179. text: UM.ActiveTool.properties.getValue("ToolHint") != undefined ? UM.ActiveTool.properties.getValue("ToolHint") : ""
  180. color: UM.Theme.getColor("tooltip_text")
  181. font: UM.Theme.getFont("default")
  182. anchors.horizontalCenter: parent.horizontalCenter
  183. }
  184. visible: toolHint.text != ""
  185. }
  186. }