OutputDevicesActionButton.qml 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. // Copyright (c) 2021 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. anchors
  22. {
  23. top: parent.top
  24. left: parent.left
  25. right: deviceSelectionMenu.visible ? deviceSelectionMenu.left : parent.right
  26. }
  27. tooltip: UM.OutputDeviceManager.activeDeviceDescription
  28. text: UM.OutputDeviceManager.activeDeviceShortDescription
  29. onClicked:
  30. {
  31. forceActiveFocus()
  32. widget.requestWriteToDevice()
  33. }
  34. }
  35. Cura.PrimaryButton
  36. {
  37. id: deviceSelectionMenu
  38. height: parent.height
  39. anchors
  40. {
  41. top: parent.top
  42. right: parent.right
  43. }
  44. leftPadding: UM.Theme.getSize("narrow_margin").width //Need more space than usual here for wide text.
  45. rightPadding: UM.Theme.getSize("narrow_margin").width
  46. iconSource: popup.opened ? UM.Theme.getIcon("ChevronSingleUp") : UM.Theme.getIcon("ChevronSingleDown")
  47. color: popup.opened ? hoverColor : UM.Theme.getColor("action_panel_secondary")
  48. visible: (devicesModel.deviceCount > 1)
  49. onClicked: popup.opened ? popup.close() : popup.open()
  50. Popup
  51. {
  52. id: popup
  53. padding: 0
  54. spacing: 0
  55. y: -height
  56. x: parent.width - width
  57. closePolicy: Popup.CloseOnEscape | Popup.CloseOnPressOutsideParent
  58. contentItem: ColumnLayout
  59. {
  60. spacing: 0
  61. Repeater
  62. {
  63. model: devicesModel
  64. delegate: Cura.PrimaryButton
  65. {
  66. text: model.description
  67. visible: model.id != UM.OutputDeviceManager.activeDevice // Don't show the active device in the list
  68. Layout.fillWidth: true
  69. // The total width of the popup should be defined by the largest button. By stating that each
  70. // button should be minimally the size of it's content (aka; implicitWidth) we can ensure that.
  71. Layout.minimumWidth: implicitWidth
  72. Layout.preferredHeight: widget.height
  73. onClicked:
  74. {
  75. UM.OutputDeviceManager.setActiveDevice(model.id)
  76. popup.close()
  77. }
  78. }
  79. }
  80. }
  81. }
  82. }
  83. UM.OutputDevicesModel { id: devicesModel }
  84. }