Toolbar.qml 4.9 KB

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