Toolbar.qml 4.6 KB

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