MonitorItem.qml 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import QtQuick 2.2
  2. import UM 1.3 as UM
  3. import Cura 1.0 as Cura
  4. Component
  5. {
  6. Item
  7. {
  8. width: maximumWidth
  9. height: maximumHeight
  10. Image
  11. {
  12. id: cameraImage
  13. width: Math.min(sourceSize.width === 0 ? 800 * screenScaleFactor : sourceSize.width, maximumWidth)
  14. height: Math.floor((sourceSize.height === 0 ? 600 * screenScaleFactor : sourceSize.height) * width / sourceSize.width)
  15. anchors.horizontalCenter: parent.horizontalCenter
  16. anchors.verticalCenter: parent.verticalCenter
  17. z: 1
  18. Component.onCompleted:
  19. {
  20. if(OutputDevice.activePrinter != null && OutputDevice.activePrinter.camera != null)
  21. {
  22. OutputDevice.activePrinter.camera.start()
  23. }
  24. }
  25. onVisibleChanged:
  26. {
  27. if(visible)
  28. {
  29. if(OutputDevice.activePrinter != null && OutputDevice.activePrinter.camera != null)
  30. {
  31. OutputDevice.activePrinter.camera.start()
  32. }
  33. } else
  34. {
  35. if(OutputDevice.activePrinter != null && OutputDevice.activePrinter.camera != null)
  36. {
  37. OutputDevice.activePrinter.camera.stop()
  38. }
  39. }
  40. }
  41. source:
  42. {
  43. if(OutputDevice.activePrinter != null && OutputDevice.activePrinter.camera != null && OutputDevice.activePrinter.camera.latestImage)
  44. {
  45. return OutputDevice.activePrinter.camera.latestImage;
  46. }
  47. return "";
  48. }
  49. }
  50. }
  51. }