PrinterVideoStream.qml 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. import QtQuick 2.2
  2. import QtQuick.Controls 1.4
  3. import QtQuick.Controls.Styles 1.4
  4. import UM 1.3 as UM
  5. Item
  6. {
  7. Rectangle
  8. {
  9. anchors.fill:parent
  10. color: UM.Theme.getColor("viewport_overlay")
  11. opacity: 0.5
  12. }
  13. MouseArea
  14. {
  15. anchors.fill: parent
  16. onClicked: OutputDevice.setActivePrinter(null)
  17. z: 0
  18. }
  19. Button
  20. {
  21. id: backButton
  22. anchors.bottom: cameraImage.top
  23. anchors.bottomMargin: UM.Theme.getSize("default_margin").width
  24. anchors.right: cameraImage.right
  25. // TODO: Harcoded sizes
  26. width: 20 * screenScaleFactor
  27. height: 20 * screenScaleFactor
  28. onClicked: OutputDevice.setActivePrinter(null)
  29. style: ButtonStyle
  30. {
  31. label: Item
  32. {
  33. UM.RecolorImage
  34. {
  35. anchors.verticalCenter: parent.verticalCenter
  36. anchors.horizontalCenter: parent.horizontalCenter
  37. width: control.width
  38. height: control.height
  39. sourceSize.width: width
  40. sourceSize.height: width
  41. source: UM.Theme.getIcon("cross1")
  42. }
  43. }
  44. background: Item {}
  45. }
  46. }
  47. Image
  48. {
  49. id: cameraImage
  50. width: Math.min(sourceSize.width === 0 ? 800 * screenScaleFactor : sourceSize.width, maximumWidth)
  51. height: Math.round((sourceSize.height === 0 ? 600 * screenScaleFactor : sourceSize.height) * width / sourceSize.width)
  52. anchors.horizontalCenter: parent.horizontalCenter
  53. anchors.verticalCenter: parent.verticalCenter
  54. z: 1
  55. onVisibleChanged:
  56. {
  57. if(visible)
  58. {
  59. if(OutputDevice.activePrinter != null && OutputDevice.activePrinter.camera != null)
  60. {
  61. OutputDevice.activePrinter.camera.start()
  62. }
  63. } else
  64. {
  65. if(OutputDevice.activePrinter != null && OutputDevice.activePrinter.camera != null)
  66. {
  67. OutputDevice.activePrinter.camera.stop()
  68. }
  69. }
  70. }
  71. source:
  72. {
  73. if(OutputDevice.activePrinter != null && OutputDevice.activePrinter.camera != null && OutputDevice.activePrinter.camera.latestImage)
  74. {
  75. return OutputDevice.activePrinter.camera.latestImage;
  76. }
  77. return "";
  78. }
  79. }
  80. MouseArea
  81. {
  82. anchors.fill: cameraImage
  83. onClicked: { /* no-op */ }
  84. z: 1
  85. }
  86. }