MonitorItem.qml 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import QtQuick 2.2
  2. import UM 1.3 as UM
  3. import Cura 1.0 as Cura
  4. Component
  5. {
  6. Image
  7. {
  8. id: cameraImage
  9. property bool proportionalHeight:
  10. {
  11. if(sourceSize.height == 0 || maximumHeight == 0)
  12. {
  13. return true;
  14. }
  15. return (sourceSize.width / sourceSize.height) > (maximumWidth / maximumHeight);
  16. }
  17. property real _width: Math.min(maximumWidth, sourceSize.width)
  18. property real _height: Math.min(maximumHeight, sourceSize.height)
  19. width: proportionalHeight ? _width : sourceSize.width * _height / sourceSize.height
  20. height: !proportionalHeight ? _height : sourceSize.height * _width / sourceSize.width
  21. anchors.horizontalCenter: parent.horizontalCenter
  22. onVisibleChanged:
  23. {
  24. if(visible)
  25. {
  26. OutputDevice.startCamera()
  27. } else
  28. {
  29. OutputDevice.stopCamera()
  30. }
  31. }
  32. source:
  33. {
  34. if(OutputDevice.cameraImage)
  35. {
  36. return OutputDevice.cameraImage;
  37. }
  38. return "";
  39. }
  40. }
  41. }