OutputDevicesActionButton.qml 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. Cura.ActionButton
  12. {
  13. id: saveToButton
  14. height: parent.height
  15. anchors
  16. {
  17. top: parent.top
  18. left: parent.left
  19. right: deviceSelectionMenu.visible ? deviceSelectionMenu.left : parent.right
  20. }
  21. tooltip: UM.OutputDeviceManager.activeDeviceDescription
  22. text: UM.OutputDeviceManager.activeDeviceShortDescription
  23. onClicked:
  24. {
  25. forceActiveFocus();
  26. UM.OutputDeviceManager.requestWriteToDevice(UM.OutputDeviceManager.activeDevice, PrintInformation.jobName,
  27. { "filter_by_machine": true, "preferred_mimetypes": Cura.MachineManager.activeMachine.preferred_output_file_formats });
  28. }
  29. }
  30. Cura.ActionButton
  31. {
  32. id: deviceSelectionMenu
  33. height: parent.height
  34. anchors
  35. {
  36. top: parent.top
  37. right: parent.right
  38. }
  39. tooltip: catalog.i18nc("@info:tooltip", "Select the active output device")
  40. iconSource: popup.opened ? UM.Theme.getIcon("arrow_top") : UM.Theme.getIcon("arrow_bottom")
  41. visible: (devicesModel.deviceCount > 1)
  42. onClicked: popup.opened ? popup.close() : popup.open()
  43. Popup
  44. {
  45. id: popup
  46. y: -height
  47. x: parent.width - width
  48. closePolicy: Popup.CloseOnEscape | Popup.CloseOnPressOutsideParent
  49. contentItem: Column
  50. {
  51. Repeater
  52. {
  53. model: devicesModel
  54. delegate: Cura.ActionButton
  55. {
  56. text: model.description
  57. color: "transparent"
  58. hoverColor: "red"
  59. onClicked:
  60. {
  61. UM.OutputDeviceManager.setActiveDevice(model.id)
  62. popup.close()
  63. }
  64. }
  65. }
  66. }
  67. background: Rectangle
  68. {
  69. opacity: visible ? 1 : 0
  70. Behavior on opacity { NumberAnimation { duration: 100 } }
  71. color: UM.Theme.getColor("primary")
  72. border.color: UM.Theme.getColor("lining")
  73. border.width: UM.Theme.getSize("default_lining").width
  74. }
  75. }
  76. }
  77. UM.OutputDevicesModel { id: devicesModel }
  78. }