main.qml 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. import QtQuick 2.11
  2. import QtQuick.Window 2.11
  3. import QtGraphicalEffects 1.0
  4. Window {
  5. id: window
  6. visible: true
  7. width: 640
  8. height: 480
  9. title: qsTr("Hello World")
  10. QtObject{
  11. id: d
  12. property int screenCount: 0
  13. }
  14. Item{
  15. id: source
  16. width: parent.width
  17. height: parent.height
  18. // Simple Animation
  19. Rectangle{
  20. id: rect
  21. width: 20
  22. height: 20
  23. x: 10
  24. y: 10
  25. color: "black"
  26. radius: width
  27. }
  28. SequentialAnimation{
  29. id: moveAnimation
  30. running: true
  31. loops: Animation.Infinite
  32. PropertyAnimation{target: rect; property: "x"; from: 10; to: source.width - rect.width - 10; duration: 1500; easing.type: Easing.OutCirc}
  33. PropertyAnimation{target: rect; property: "y"; from: 10; to: source.height - rect.height - 10; duration: 1000/*; easing.type: Easing.OutCirc*/}
  34. PropertyAnimation{target: rect; property: "x"; from: source.width - rect.width - 10; to: 10; duration: 1000/*; easing.type: Easing.OutCirc*/}
  35. PropertyAnimation{target: rect; property: "y"; from: source.height - rect.height - 10; to: 0; duration: 1000/*; easing.type: Easing.OutCirc*/}
  36. }
  37. // Rectangle{
  38. // id: rect
  39. // width: parent.width
  40. // height: parent.height
  41. // color: "#49cc19"
  42. // Rectangle{
  43. // id: btn
  44. // anchors.centerIn: parent
  45. // width: parent.width / 2
  46. // height: parent.height / 2
  47. // radius: width / 3
  48. // Text {
  49. // id: btnText
  50. // text: qsTr("Yo!")
  51. // font.pointSize: 40
  52. // color: "black"
  53. // anchors.centerIn: parent
  54. // }
  55. // MouseArea{
  56. // id: mouseArea
  57. // anchors.fill: parent
  58. // onPressed: {
  59. // btn.scale = 0.9
  60. // btnShadow.scale = 0.9
  61. // btnText.text = "Clicked"
  62. // }
  63. // onReleased: {
  64. // btn.scale = 1
  65. // btnShadow.scale = 1
  66. // btnText.text = "Yo!"
  67. // }
  68. // }
  69. // }
  70. // DropShadow{
  71. // id: btnShadow
  72. // anchors.fill: btn
  73. // horizontalOffset: 3
  74. // verticalOffset: 13
  75. // radius: 8.0
  76. // samples: 17
  77. // color: "#80000000"
  78. // source: btn
  79. // }
  80. // }
  81. }
  82. ShaderEffectSource{
  83. id: sourceShader
  84. visible: false // Do not render it (will only be rendered when called grapToImage()
  85. sourceItem: source
  86. width: source.width
  87. height: source.height
  88. live: false // Will only be updated, when explicitly called for
  89. function save() {
  90. scheduleUpdate() // explicitly update. grabToImage() will force rendering afterwards.
  91. sourceShader.grabToImage(function(result) {
  92. result.saveToFile("C://Documents/%1.png".arg(d.screenCount++));
  93. })
  94. }
  95. }
  96. Timer{
  97. id: timeToScreenShoot
  98. interval: 25
  99. repeat: true
  100. running: true
  101. onTriggered: {
  102. sourceShader.save()
  103. }
  104. }
  105. }