OutputDevicesActionButton.qml 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. // Copyright (c) 2018 Ultimaker B.V.
  2. // Cura is released under the terms of the LGPLv3 or higher.
  3. import QtQuick 2.7
  4. import QtQuick.Controls 2.1
  5. import QtQuick.Layouts 1.3
  6. import UM 1.1 as UM
  7. import Cura 1.0 as Cura
  8. Item
  9. {
  10. id: widget
  11. function requestWriteToDevice()
  12. {
  13. UM.OutputDeviceManager.requestWriteToDevice(UM.OutputDeviceManager.activeDevice, PrintInformation.jobName,
  14. { "filter_by_machine": true, "preferred_mimetypes": Cura.MachineManager.activeMachine.preferred_output_file_formats });
  15. }
  16. Cura.PrimaryButton
  17. {
  18. id: saveToButton
  19. height: parent.height
  20. fixedWidthMode: true
  21. cornerSide: deviceSelectionMenu.visible ? Cura.RoundedRectangle.Direction.Left : Cura.RoundedRectangle.Direction.All
  22. anchors
  23. {
  24. top: parent.top
  25. left: parent.left
  26. right: deviceSelectionMenu.visible ? deviceSelectionMenu.left : parent.right
  27. }
  28. tooltip: UM.OutputDeviceManager.activeDeviceDescription
  29. text: UM.OutputDeviceManager.activeDeviceShortDescription
  30. onClicked:
  31. {
  32. forceActiveFocus()
  33. widget.requestWriteToDevice()
  34. }
  35. }
  36. Cura.ActionButton
  37. {
  38. id: deviceSelectionMenu
  39. height: parent.height
  40. shadowEnabled: true
  41. shadowColor: UM.Theme.getColor("primary_shadow")
  42. cornerSide: Cura.RoundedRectangle.Direction.Right
  43. anchors
  44. {
  45. top: parent.top
  46. right: parent.right
  47. }
  48. leftPadding: UM.Theme.getSize("narrow_margin").width //Need more space than usual here for wide text.
  49. rightPadding: UM.Theme.getSize("narrow_margin").width
  50. iconSource: popup.opened ? UM.Theme.getIcon("arrow_top") : UM.Theme.getIcon("arrow_bottom")
  51. color: UM.Theme.getColor("action_panel_secondary")
  52. visible: (devicesModel.deviceCount > 1)
  53. onClicked: popup.opened ? popup.close() : popup.open()
  54. Popup
  55. {
  56. id: popup
  57. padding: 0
  58. y: -height
  59. x: parent.width - width
  60. closePolicy: Popup.CloseOnEscape | Popup.CloseOnPressOutsideParent
  61. contentItem: ColumnLayout
  62. {
  63. Repeater
  64. {
  65. model: devicesModel
  66. delegate: Cura.ActionButton
  67. {
  68. text: model.description
  69. visible: model.id != UM.OutputDeviceManager.activeDevice // Don't show the active device in the list
  70. color: "transparent"
  71. cornerRadius: 0
  72. hoverColor: UM.Theme.getColor("primary")
  73. Layout.fillWidth: true
  74. // The total width of the popup should be defined by the largest button. By stating that each
  75. // button should be minimally the size of it's content (aka; implicitWidth) we can ensure that.
  76. Layout.minimumWidth: implicitWidth
  77. Layout.preferredHeight: widget.height
  78. onClicked:
  79. {
  80. UM.OutputDeviceManager.setActiveDevice(model.id)
  81. popup.close()
  82. }
  83. }
  84. }
  85. }
  86. background: Rectangle
  87. {
  88. opacity: visible ? 1 : 0
  89. Behavior on opacity { NumberAnimation { duration: 100 } }
  90. color: UM.Theme.getColor("action_panel_secondary")
  91. }
  92. }
  93. }
  94. UM.OutputDevicesModel { id: devicesModel }
  95. }