ArtImage.qml 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. import QtQuick 2.5
  2. import PictureModel 1.0
  3. import ".."
  4. Rectangle {
  5. id: root
  6. property var effect
  7. property int modelIndex
  8. property alias asynchronous: image.asynchronous
  9. property alias source: image.source
  10. color: globalSettings.randomBackdropColor ? Qt.rgba(Math.random(255), Math.random(255), Math.random(255), 1.0) : "black"
  11. height: width*nativeUtils.imageCollection.data(modelIndex, PictureModel.SizeRole).height/nativeUtils.imageCollection.data(modelIndex, PictureModel.SizeRole).width
  12. width: globalVars.imageWidthOverride
  13. Image {
  14. id: image
  15. cache: false
  16. opacity: globalSettings.fadeInImages ? 0 : 1.0
  17. height: root.height
  18. width: root.width
  19. asynchronous: true
  20. fillMode: Image.PreserveAspectFit
  21. source: nativeUtils.imageCollection.data(modelIndex)
  22. mirror: globalSettings.randomlyMirrorArt && (Math.random() < globalSettings.randomlyMirrorArtFreq)
  23. smooth: true
  24. mipmap: false
  25. sourceSize.height: height
  26. sourceSize.width: width
  27. Behavior on opacity {
  28. enabled: image.asynchronous
  29. SequentialAnimation {
  30. ScriptAction { script: root.effect !== undefined ? root.effect.scheduleUpdate() : undefined }
  31. NumberAnimation { duration: 1000 }
  32. }
  33. }
  34. onStatusChanged: {
  35. if (status === Image.Ready) {
  36. opacity = globalSettings.artOpacity
  37. }
  38. }
  39. }
  40. Component.onCompleted: {
  41. modelIndex = nativeUtils.imageCollection.requestIndex()
  42. if (globalSettings.effect !== "" && Effects.validate(globalSettings.effect)) {
  43. var component = Qt.createComponent("VisualEffect.qml");
  44. component.status !== Component.Ready && console.log('Component failed with:' + component.errorString())
  45. root.effect = component.createObject(root, { target: image, effect: globalSettings.effect })
  46. }
  47. }
  48. Component.onDestruction: nativeUtils.imageCollection.retireIndex(modelIndex)
  49. }