EffectsPage.qml 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516
  1. import Felgo 4.0
  2. import QtQuick 2.0
  3. import QtQuick.Controls 2.0
  4. import Qt5Compat.GraphicalEffects
  5. import QtMultimedia 5.5
  6. import "../common"
  7. import "../controls"
  8. import "../qmlvideofx/qml"
  9. AppPage {
  10. id: page
  11. // for windows platform check
  12. property bool isWindows: system.isPlatform(4)
  13. || system.isPlatform(9)
  14. || system.isPlatform(10) // windows, winPhone or winRT
  15. rightBarItem: TextButtonBarItem {
  16. text: "Hide effects"
  17. visible: fxControls.visible
  18. onClicked: {
  19. if(fxControls.visible) {
  20. if (appsVideo.started) {
  21. appsVideo.pause()
  22. appsVideo.pausedByUser = true
  23. }
  24. fxControls.hide()
  25. }
  26. }
  27. }
  28. Item {
  29. id: flickArea
  30. anchors.fill: parent
  31. // flickable
  32. AppFlickable {
  33. id: pageFlickable
  34. // show/hide embedded video during scrolling to opimize scroll performance
  35. property real yBeginning: 0
  36. property real yDelta: pageFlickable.contentY - pageFlickable.yBeginning
  37. property real videoContentY: 0
  38. anchors.fill: parent
  39. contentHeight: content.height + dp(Theme.navigationBar.defaultBarItemPadding) * 2
  40. onHeightChanged: {
  41. videoContentY = appsVideo.parent.mapToItem(pageFlickable.contentItem, 0 , 0).y
  42. }
  43. onContentHeightChanged: {
  44. videoContentY = appsVideo.parent.mapToItem(pageFlickable.contentItem, 0 , 0).y
  45. }
  46. Component.onCompleted: {
  47. pageFlickable.yBeginning = pageFlickable.contentY
  48. }
  49. // add background to flickable to also have background within shader effect
  50. Rectangle {
  51. anchors.fill: parent
  52. color: page.backgroundColor
  53. }
  54. // remove focus from controls if clicked outside
  55. MouseArea {
  56. anchors.fill: parent
  57. onClicked: {
  58. pageFlickable.forceActiveFocus()
  59. }
  60. }
  61. // content
  62. Column {
  63. id: content
  64. width: parent.width
  65. Section {
  66. title: "Custom Shaders Effects"
  67. spacing: dp(15)
  68. // shaders currently not supported in Qt 6.3.1
  69. visible: false
  70. AppButton {
  71. text: fxControls.visible ? "Hide Shader Example" : "Open Shader Example"
  72. anchors.horizontalCenter: parent.horizontalCenter
  73. flat: false
  74. onClicked: {
  75. if (!fxControls.visible) {
  76. appsVideo.play()
  77. fxControls.show()
  78. }
  79. else {
  80. if (appsVideo.started) {
  81. appsVideo.pause()
  82. appsVideo.pausedByUser = true
  83. }
  84. fxControls.hide()
  85. }
  86. }
  87. }
  88. // embedded apps video
  89. Rectangle {
  90. color: "black"
  91. width: parent.width
  92. height: width / 1280 * 720
  93. Column {
  94. anchors.centerIn: parent
  95. width: parent.width
  96. spacing: dp(10)
  97. AppImage {
  98. source: "../../assets/playicon.png"
  99. width: dp(75)
  100. height: width / sourceSize.width * sourceSize.height
  101. anchors.horizontalCenter: parent.horizontalCenter
  102. }
  103. AppText {
  104. width: parent.width * 0.75
  105. text: "Tap to play video for live video shader effects"
  106. horizontalAlignment: AppText.AlignHCenter
  107. anchors.horizontalCenter: parent.horizontalCenter
  108. wrapMode: AppText.WordWrap
  109. font.pixelSize: sp(16)
  110. color: "white"
  111. }
  112. }
  113. Video {
  114. id: appsVideo
  115. property bool started: false
  116. property bool pausedByUser: false
  117. anchors.fill: parent
  118. visible: (pageFlickable.yDelta + pageFlickable.height >= pageFlickable.videoContentY) && (pageFlickable.yDelta <= pageFlickable.videoContentY + height)
  119. source: "https://raw.githubusercontent.com/FelgoSDK/Demos-Examples/master/preview-assets/appdemos/component-showcase/data/multimedia/Felgo_mobile." + (isWindows ? "wmv" : "mp4")
  120. //autoLoad: true
  121. onPlaying: {
  122. pausedByUser = false
  123. started = true
  124. }
  125. onStopped: {
  126. pausedByUser = false
  127. started = false
  128. }
  129. // hide and stop pause if not within visible view to improve performance
  130. onVisibleChanged: {
  131. if (!visible && started) {
  132. pause()
  133. } else if (visible && started && !pausedByUser) {
  134. play()
  135. }
  136. }
  137. // play / pause video on click
  138. MouseArea {
  139. anchors.fill: parent
  140. onClicked: {
  141. if (!appsVideo.started) {
  142. appsVideo.play()
  143. fxControls.show()
  144. } else {
  145. if (appsVideo.pausedByUser) {
  146. appsVideo.play()
  147. } else {
  148. appsVideo.pause()
  149. appsVideo.pausedByUser = true
  150. }
  151. }
  152. }
  153. }
  154. }
  155. }
  156. } // custom shaders effect ssection
  157. Section {
  158. title: "Graphical effects"
  159. AppImage {
  160. id: displacementImage
  161. anchors.horizontalCenter: parent.horizontalCenter
  162. height: dp(150)
  163. width: height / sourceSize.height * sourceSize.width
  164. source: "../../assets/devices.png"
  165. layer.enabled: true
  166. layer.effect: Displace {
  167. id: displaceEffect
  168. displacement: 0.2
  169. displacementSource: Rectangle {
  170. width: displacementImage.width
  171. height: displacementImage.height
  172. color: Qt.rgba(0.5,0.5,0,1)
  173. AppImage {
  174. id: displaceLogo
  175. anchors.fill: parent
  176. fillMode: AppImage.PreserveAspectFit
  177. source: "../../assets/felgo-logo.png"
  178. }
  179. PropertyAnimation {
  180. target: displaceEffect
  181. property: "displacement"
  182. duration: 1500
  183. easing.type: Easing.OutBounce
  184. to: 0.3
  185. running: true
  186. onStopped: {
  187. to *= -1
  188. start()
  189. }
  190. }
  191. }
  192. } // Displace effect
  193. } // Displacement Image
  194. } // graphical effects section
  195. // Blend effect currently not implemented in Qt 6
  196. // Section {
  197. // title: "Blend Effect"
  198. // spacing: dp(Theme.navigationBar.defaultBarItemPadding)
  199. // Row {
  200. // spacing: parent.spacing
  201. // anchors.horizontalCenter: parent.horizontalCenter
  202. // height: blendComboBox.height
  203. // AppText {
  204. // text: "Blend Mode: "
  205. // anchors.verticalCenter: parent.verticalCenter
  206. // }
  207. // CustomComboBox {
  208. // id: blendComboBox
  209. // implicitWidth: dp(110) + 30
  210. // model: ["Normal", "Addition", "Subtract", "Multiply", "Divide", "Exclusion", "DarkerColor", "LighterColor"]
  211. // anchors.verticalCenter: parent.verticalCenter
  212. // }
  213. // }
  214. // AppImage {
  215. // id: blendImage
  216. // height: dp(150)
  217. // width: height / sourceSize.height * sourceSize.width
  218. // source: "../../assets/devices.png"
  219. // anchors.horizontalCenter: parent.horizontalCenter
  220. // layer.enabled: true
  221. // layer.effect: Blend {
  222. // mode: blendComboBox.currentText
  223. // foregroundSource: AppImage {
  224. // width: blendImage.width
  225. // height: blendImage.height
  226. // fillMode: AppImage.PreserveAspectFit
  227. // source: "../../assets/felgo-logo.png"
  228. // }
  229. // } // Blend Effect
  230. // } // Blend Image
  231. // } // Blend effect section
  232. Section {
  233. title: "Color Adjustment"
  234. spacing: dp(Theme.navigationBar.defaultBarItemPadding)
  235. Row {
  236. anchors.horizontalCenter: parent.horizontalCenter
  237. spacing: parent.spacing
  238. AppText {
  239. text: "Apply:"
  240. anchors.verticalCenter: parent.verticalCenter
  241. }
  242. CustomComboBox {
  243. id: colorComboBox
  244. implicitWidth: dp(160) + 30
  245. anchors.verticalCenter: parent.verticalCenter
  246. model: ["BrightnessContrast", "ColorOverlay", "Colorize", "HueSaturation"]
  247. onCurrentIndexChanged: {
  248. // apply new effect
  249. switch (currentIndex) {
  250. case 0:
  251. colorEffectImage.layer.effect = brightnessContrastEffect
  252. break
  253. case 1:
  254. colorEffectImage.layer.effect = colorOverlayEffect
  255. break
  256. case 2:
  257. colorEffectImage.layer.effect = colorizeEffect
  258. break
  259. case 3:
  260. colorEffectImage.layer.effect = hueSaturationEffect
  261. break
  262. }
  263. }
  264. }
  265. }
  266. AppImage {
  267. id: colorEffectImage
  268. anchors.horizontalCenter: parent.horizontalCenter
  269. height: dp(150)
  270. width: height / sourceSize.height * sourceSize.width
  271. source: "../../assets/devices.png"
  272. layer.enabled: true
  273. layer.effect: brightnessContrastEffect
  274. Component {
  275. id: brightnessContrastEffect
  276. BrightnessContrast {
  277. brightness: -0.5
  278. contrast: 0.5
  279. }
  280. }
  281. Component {
  282. id: colorOverlayEffect
  283. ColorOverlay {
  284. color: Qt.rgba(0,0,1,0.25)
  285. }
  286. }
  287. Component {
  288. id: colorizeEffect
  289. Colorize {
  290. hue: 0.7
  291. saturation: 0.5
  292. }
  293. }
  294. Component {
  295. id: hueSaturationEffect
  296. HueSaturation {
  297. hue: 0.3
  298. saturation: 0.5
  299. }
  300. }
  301. }
  302. } // Color adjustment section
  303. Section {
  304. title: "Improved Style"
  305. spacing: dp(Theme.navigationBar.defaultBarItemPadding)
  306. Row {
  307. spacing: parent.spacing
  308. anchors.horizontalCenter: parent.horizontalCenter
  309. AppText {
  310. text: "Add: "
  311. anchors.verticalCenter: parent.verticalCenter
  312. }
  313. CustomComboBox {
  314. id: styleComboBox
  315. implicitWidth: dp(120) + 30
  316. anchors.verticalCenter: parent.verticalCenter
  317. // Qt 6 - RadialBlur currently not supported
  318. model: ["DropShadow", "FastBlur", /*"RadialBlur", */"Glow"]
  319. onCurrentIndexChanged: {
  320. // apply new effect
  321. switch (currentIndex) {
  322. case 0:
  323. styleEffectImage.layer.effect = dropShadowEffect
  324. break
  325. case 1:
  326. styleEffectImage.layer.effect = fastBlurEffect
  327. break
  328. case 2:
  329. // styleEffectImage.layer.effect = radialBlurEffect
  330. // break
  331. // case 3:
  332. styleEffectImage.layer.effect = glowEffect
  333. break
  334. }
  335. }
  336. }
  337. }
  338. AppImage {
  339. id: styleEffectImage
  340. height: dp(150)
  341. width: height / sourceSize.height * sourceSize.width
  342. anchors.horizontalCenter: parent.horizontalCenter
  343. source: "../../assets/felgo-logo.png"
  344. layer.enabled: true
  345. layer.effect: dropShadowEffect
  346. Component {
  347. id: dropShadowEffect
  348. DropShadow {
  349. horizontalOffset: 6
  350. verticalOffset: 6
  351. radius: 12.0
  352. //samples: 17
  353. color: "#80000000"
  354. }
  355. }
  356. Component {
  357. id: fastBlurEffect
  358. FastBlur {
  359. radius: dp(8)
  360. }
  361. }
  362. // Component {
  363. // id: radialBlurEffect
  364. // RadialBlur {
  365. // samples: 24
  366. // angle: 30
  367. // }
  368. // }
  369. Component {
  370. id: glowEffect
  371. Glow {
  372. radius: 16
  373. //samples: 17
  374. color: Qt.rgba(1,1,0,0.5)
  375. }
  376. }
  377. }
  378. } // Style Effect section
  379. } // column
  380. } // flickable
  381. // scroll indicator
  382. AppScrollIndicator {
  383. flickable: pageFlickable
  384. z: 1
  385. }
  386. }
  387. // logo will be visible behind page when using page effect ;-)
  388. Column {
  389. anchors.centerIn: flickArea
  390. spacing: dp(10)
  391. opacity: 0.5
  392. AppImage {
  393. width: dp(50)
  394. source: "../../assets/felgo-logo.png"
  395. fillMode: AppImage.PreserveAspectFit
  396. anchors.horizontalCenter: parent.horizontalCenter
  397. }
  398. AppText {
  399. width: dp(150)
  400. text: "Congratulations, you found this hidden message!"
  401. font.pixelSize: dp(12)
  402. wrapMode: Text.WordWrap
  403. anchors.horizontalCenter: parent.horizontalCenter
  404. }
  405. AppText {
  406. width: dp(150)
  407. text: "Shaders are awesome. ;-)"
  408. font.pixelSize: dp(12)
  409. anchors.horizontalCenter: parent.horizontalCenter
  410. }
  411. }
  412. // apply shader fx effect
  413. VideoFXEffect {
  414. id: fxEffect
  415. anchors.fill: flickArea
  416. divider.anchors.topMargin: fxControls.parameterPanelHeight
  417. sourceForShaderEffect.sourceItem: flickArea
  418. gripSize: fxControls.gripSize
  419. }
  420. // shader fx controls
  421. VideoFXControls {
  422. id: fxControls
  423. targetEffect: fxEffect
  424. visible: false
  425. onEffectLoaded: function(name) {
  426. if(name === "No effect") {
  427. fxControls.visible = false
  428. }
  429. }
  430. function show() {
  431. fxControls.visible = true
  432. fxEffect.divider.value = 0.5
  433. fxControls.loadEffect("Blur", "EffectGaussianBlur.qml")
  434. }
  435. function hide() {
  436. fxControls.visible = false
  437. fxControls.loadEffect("No effect", "EffectPassThrough.qml")
  438. }
  439. }
  440. }