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. width: childrenRect.width
  112. height: childrenRect.height
  113. model: extrudersModel.items.length > 1 ? extrudersModel : 0
  114. delegate: ExtruderButton
  115. {
  116. extruder: model
  117. isTopElement: extrudersModel.getItem(0).id == model.id
  118. isBottomElement: extrudersModel.getItem(extrudersModel.rowCount() - 1).id == model.id
  119. }
  120. }
  121. }
  122. }
  123. property var extrudersModel: CuraApplication.getExtrudersModel()
  124. UM.PointingRectangle
  125. {
  126. id: panelBorder
  127. anchors.left: parent.right
  128. anchors.leftMargin: UM.Theme.getSize("default_margin").width
  129. anchors.top: base.top
  130. anchors.topMargin: base.activeY
  131. z: buttons.z - 1
  132. target: Qt.point(parent.right, base.activeY + Math.round(UM.Theme.getSize("button").height/2))
  133. arrowSize: UM.Theme.getSize("default_arrow").width
  134. width:
  135. {
  136. if (panel.item && panel.width > 0)
  137. {
  138. return Math.max(panel.width + 2 * UM.Theme.getSize("default_margin").width)
  139. }
  140. else
  141. {
  142. return 0;
  143. }
  144. }
  145. height: panel.item ? panel.height + 2 * UM.Theme.getSize("default_margin").height : 0
  146. opacity: panel.item && panel.width > 0 ? 1 : 0
  147. Behavior on opacity { NumberAnimation { duration: 100 } }
  148. color: UM.Theme.getColor("tool_panel_background")
  149. borderColor: UM.Theme.getColor("lining")
  150. borderWidth: UM.Theme.getSize("default_lining").width
  151. MouseArea //Catch all mouse events (so scene doesnt handle them)
  152. {
  153. anchors.fill: parent
  154. acceptedButtons: Qt.AllButtons
  155. onWheel: wheel.accepted = true
  156. }
  157. Loader
  158. {
  159. id: panel
  160. x: UM.Theme.getSize("default_margin").width
  161. y: UM.Theme.getSize("default_margin").height
  162. source: UM.ActiveTool.valid ? UM.ActiveTool.activeToolPanel : ""
  163. enabled: UM.Controller.toolsEnabled
  164. }
  165. }
  166. // This rectangle displays the information about the current angle etc. when
  167. // dragging a tool handle.
  168. Rectangle
  169. {
  170. id: toolInfo
  171. x: visible ? -base.x + base.mouseX + UM.Theme.getSize("default_margin").width: 0
  172. y: visible ? -base.y + base.mouseY + UM.Theme.getSize("default_margin").height: 0
  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. }