Toolbar.qml 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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);
  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. {
  35. if(checked)
  36. {
  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: 1; visible: extruders.count > 0 }
  61. Repeater
  62. {
  63. id: extruders
  64. property var _model: Cura.ExtrudersModel { id: extrudersModel }
  65. model: _model.items.length > 1 ? _model : 0
  66. ExtruderButton { extruder: model }
  67. }
  68. }
  69. UM.PointingRectangle
  70. {
  71. id: panelBorder;
  72. anchors.left: parent.right;
  73. anchors.leftMargin: UM.Theme.getSize("default_margin").width;
  74. anchors.top: base.top;
  75. anchors.topMargin: base.activeY
  76. z: buttons.z -1
  77. target: Qt.point(parent.right, base.activeY + UM.Theme.getSize("button").height/2)
  78. arrowSize: UM.Theme.getSize("default_arrow").width
  79. width:
  80. {
  81. if (panel.item && panel.width > 0){
  82. return Math.max(panel.width + 2 * UM.Theme.getSize("default_margin").width)
  83. }
  84. else {
  85. return 0
  86. }
  87. }
  88. height: panel.item ? panel.height + 2 * UM.Theme.getSize("default_margin").height : 0;
  89. opacity: panel.item && panel.width > 0 ? 1 : 0
  90. Behavior on opacity { NumberAnimation { duration: 100 } }
  91. color: UM.Theme.getColor("tool_panel_background")
  92. borderColor: UM.Theme.getColor("lining")
  93. borderWidth: UM.Theme.getSize("default_lining").width
  94. MouseArea //Catch all mouse events (so scene doesnt handle them)
  95. {
  96. anchors.fill: parent
  97. }
  98. Loader
  99. {
  100. id: panel
  101. x: UM.Theme.getSize("default_margin").width;
  102. y: UM.Theme.getSize("default_margin").height;
  103. source: UM.ActiveTool.valid ? UM.ActiveTool.activeToolPanel : "";
  104. enabled: UM.Controller.toolsEnabled;
  105. }
  106. }
  107. // This rectangle displays the information about the current angle etc. when
  108. // dragging a tool handle.
  109. Rectangle
  110. {
  111. x: -base.x + base.mouseX + UM.Theme.getSize("default_margin").width
  112. y: -base.y + base.mouseY + UM.Theme.getSize("default_margin").height
  113. width: toolHint.width + UM.Theme.getSize("default_margin").width
  114. height: toolHint.height;
  115. color: UM.Theme.getColor("tooltip")
  116. Label
  117. {
  118. id: toolHint
  119. text: UM.ActiveTool.properties.getValue("ToolHint") != undefined ? UM.ActiveTool.properties.getValue("ToolHint") : ""
  120. color: UM.Theme.getColor("tooltip_text")
  121. font: UM.Theme.getFont("default")
  122. anchors.horizontalCenter: parent.horizontalCenter
  123. }
  124. visible: toolHint.text != "";
  125. }
  126. }