Toolbar.qml 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. // Copyright (c) 2015 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. Column
  16. {
  17. id: buttons;
  18. anchors.bottom: parent.bottom;
  19. anchors.left: parent.left;
  20. spacing: UM.Theme.getSize("button_lining").width
  21. Repeater
  22. {
  23. id: repeat
  24. model: UM.ToolModel { }
  25. width: childrenRect.width
  26. height: childrenRect.height
  27. Button
  28. {
  29. text: model.name
  30. iconSource: (UM.Theme.getIcon(model.icon) != "") ? UM.Theme.getIcon(model.icon) : "file:///" + model.location + "/" + model.icon
  31. checkable: true
  32. checked: model.active
  33. enabled: model.enabled && UM.Selection.hasSelection && UM.Controller.toolsEnabled
  34. style: UM.Theme.styles.tool_button
  35. onCheckedChanged: {
  36. if (checked) {
  37. base.activeY = y
  38. }
  39. }
  40. //Workaround since using ToolButton"s onClicked would break the binding of the checked property, instead
  41. //just catch the click so we do not trigger that behaviour.
  42. MouseArea
  43. {
  44. anchors.fill: parent;
  45. onClicked:
  46. {
  47. forceActiveFocus() //First grab focus, so all the text fields are updated
  48. if(parent.checked)
  49. {
  50. UM.Controller.setActiveTool(null)
  51. }
  52. else
  53. {
  54. UM.Controller.setActiveTool(model.id);
  55. }
  56. }
  57. }
  58. }
  59. }
  60. Item { height: UM.Theme.getSize("default_margin").height; width: UM.Theme.getSize("default_lining").width; visible: extruders.count > 0 }
  61. Repeater
  62. {
  63. id: extruders
  64. width: childrenRect.width
  65. height: childrenRect.height
  66. property var _model: Cura.ExtrudersModel { id: extrudersModel }
  67. model: _model.items.length > 1 ? _model : 0
  68. ExtruderButton { extruder: model }
  69. }
  70. }
  71. UM.PointingRectangle
  72. {
  73. id: panelBorder;
  74. anchors.left: parent.right;
  75. anchors.leftMargin: UM.Theme.getSize("default_margin").width;
  76. anchors.top: base.top;
  77. anchors.topMargin: base.activeY
  78. z: buttons.z -1
  79. target: Qt.point(parent.right, base.activeY + Math.round(UM.Theme.getSize("button").height/2))
  80. arrowSize: UM.Theme.getSize("default_arrow").width
  81. width:
  82. {
  83. if (panel.item && panel.width > 0){
  84. return Math.max(panel.width + 2 * UM.Theme.getSize("default_margin").width)
  85. }
  86. else {
  87. return 0
  88. }
  89. }
  90. height: panel.item ? panel.height + 2 * UM.Theme.getSize("default_margin").height : 0;
  91. opacity: panel.item && panel.width > 0 ? 1 : 0
  92. Behavior on opacity { NumberAnimation { duration: 100 } }
  93. color: UM.Theme.getColor("tool_panel_background")
  94. borderColor: UM.Theme.getColor("lining")
  95. borderWidth: UM.Theme.getSize("default_lining").width
  96. MouseArea //Catch all mouse events (so scene doesnt handle them)
  97. {
  98. anchors.fill: parent
  99. }
  100. Loader
  101. {
  102. id: panel
  103. x: UM.Theme.getSize("default_margin").width;
  104. y: UM.Theme.getSize("default_margin").height;
  105. source: UM.ActiveTool.valid ? UM.ActiveTool.activeToolPanel : "";
  106. enabled: UM.Controller.toolsEnabled;
  107. }
  108. }
  109. // This rectangle displays the information about the current angle etc. when
  110. // dragging a tool handle.
  111. Rectangle
  112. {
  113. x: -base.x + base.mouseX + UM.Theme.getSize("default_margin").width
  114. y: -base.y + base.mouseY + UM.Theme.getSize("default_margin").height
  115. width: toolHint.width + UM.Theme.getSize("default_margin").width
  116. height: toolHint.height;
  117. color: UM.Theme.getColor("tooltip")
  118. Label
  119. {
  120. id: toolHint
  121. text: UM.ActiveTool.properties.getValue("ToolHint") != undefined ? UM.ActiveTool.properties.getValue("ToolHint") : ""
  122. color: UM.Theme.getColor("tooltip_text")
  123. font: UM.Theme.getFont("default")
  124. anchors.horizontalCenter: parent.horizontalCenter
  125. }
  126. visible: toolHint.text != "";
  127. }
  128. }