Toolbar.qml 6.4 KB

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