main.qml 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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. property var images: []
  14. }
  15. Item{
  16. id: source
  17. width: parent.width
  18. height: parent.height
  19. // Simple Animation
  20. Rectangle{
  21. id: rect
  22. width: 20
  23. height: 20
  24. x: 10
  25. y: 10
  26. color: "black"
  27. radius: width
  28. visible: true
  29. }
  30. SequentialAnimation{
  31. id: moveAnimation
  32. running: true
  33. loops: Animation.Infinite
  34. PropertyAnimation{target: rect; property: "x"; from: 10; to: source.width - rect.width - 10; duration: 1500; easing.type: Easing.OutCirc}
  35. PropertyAnimation{target: rect; property: "y"; from: 10; to: source.height - rect.height - 10; duration: 1000/*; easing.type: Easing.OutCirc*/}
  36. PropertyAnimation{target: rect; property: "x"; from: source.width - rect.width - 10; to: 10; duration: 1000/*; easing.type: Easing.OutCirc*/}
  37. PropertyAnimation{target: rect; property: "y"; from: source.height - rect.height - 10; to: 0; duration: 1000/*; easing.type: Easing.OutCirc*/}
  38. }
  39. Image {
  40. id: img
  41. anchors.fill: parent
  42. mipmap: true
  43. asynchronous: true
  44. visible: false
  45. }
  46. MouseArea{
  47. anchors.fill: parent
  48. onClicked: {
  49. timeToScreenShoot.stop()
  50. moveAnimation.stop()
  51. rect.visible = false
  52. img.visible = true
  53. timeToAnimate.start()
  54. }
  55. }
  56. // Rectangle{
  57. // id: rect
  58. // width: parent.width
  59. // height: parent.height
  60. // color: "#49cc19"
  61. // Rectangle{
  62. // id: btn
  63. // anchors.centerIn: parent
  64. // width: parent.width / 2
  65. // height: parent.height / 2
  66. // radius: width / 3
  67. // Text {
  68. // id: btnText
  69. // text: qsTr("Yo!")
  70. // font.pointSize: 40
  71. // color: "black"
  72. // anchors.centerIn: parent
  73. // }
  74. // MouseArea{
  75. // id: mouseArea
  76. // anchors.fill: parent
  77. // onPressed: {
  78. // btn.scale = 0.9
  79. // btnShadow.scale = 0.9
  80. // btnText.text = "Clicked"
  81. // }
  82. // onReleased: {
  83. // btn.scale = 1
  84. // btnShadow.scale = 1
  85. // btnText.text = "Yo!"
  86. // }
  87. // }
  88. // }
  89. // DropShadow{
  90. // id: btnShadow
  91. // anchors.fill: btn
  92. // horizontalOffset: 3
  93. // verticalOffset: 13
  94. // radius: 8.0
  95. // samples: 17
  96. // color: "#80000000"
  97. // source: btn
  98. // }
  99. // }
  100. }
  101. ShaderEffectSource{
  102. id: sourceShader
  103. visible: false // Do not render it (will only be rendered when called grapToImage()
  104. sourceItem: source
  105. width: source.width
  106. height: source.height
  107. live: false // Will only be updated, when explicitly called for
  108. function save() {
  109. scheduleUpdate() // explicitly update. grabToImage() will force rendering afterwards.
  110. sourceShader.grabToImage(function(result) {
  111. d.images.push(result)
  112. })
  113. }
  114. }
  115. Timer{
  116. id: timeToScreenShoot
  117. interval: 25
  118. repeat: true
  119. running: true
  120. onTriggered: {
  121. // sourceShader.save()
  122. source.grabToImage(function(result) {
  123. d.images.push(result)
  124. })
  125. }
  126. }
  127. Timer{
  128. id: timeToAnimate
  129. property int current: 0
  130. interval: 25
  131. repeat: true
  132. running: false
  133. onTriggered: {
  134. if(current > d.images.length) current = 0
  135. img.source = d.images[current++].url
  136. }
  137. }
  138. }