Toolbar.qml 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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. model: Cura.ExtrudersModel { id: extrudersModel }
  65. ExtruderButton { extruder: model }
  66. }
  67. }
  68. UM.PointingRectangle
  69. {
  70. id: panelBorder;
  71. anchors.left: parent.right;
  72. anchors.leftMargin: UM.Theme.getSize("default_margin").width;
  73. anchors.top: base.top;
  74. anchors.topMargin: base.activeY
  75. z: buttons.z -1
  76. target: Qt.point(parent.right, base.activeY + UM.Theme.getSize("button").height/2)
  77. arrowSize: UM.Theme.getSize("default_arrow").width
  78. width:
  79. {
  80. if (panel.item && panel.width > 0){
  81. return Math.max(panel.width + 2 * UM.Theme.getSize("default_margin").width)
  82. }
  83. else {
  84. return 0
  85. }
  86. }
  87. height: panel.item ? panel.height + 2 * UM.Theme.getSize("default_margin").height : 0;
  88. opacity: panel.item && panel.width > 0 ? 1 : 0
  89. Behavior on opacity { NumberAnimation { duration: 100 } }
  90. color: UM.Theme.getColor("lining");
  91. UM.PointingRectangle
  92. {
  93. id: panelBackground;
  94. color: UM.Theme.getColor("tool_panel_background");
  95. anchors.fill: parent
  96. anchors.margins: UM.Theme.getSize("default_lining").width
  97. target: Qt.point(-UM.Theme.getSize("default_margin").width, UM.Theme.getSize("button").height/2)
  98. arrowSize: parent.arrowSize
  99. MouseArea //Catch all mouse events (so scene doesnt handle them)
  100. {
  101. anchors.fill: parent
  102. }
  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. }