ArtImage.qml 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. x: globalSettings.artFrameWidth
  18. y: globalSettings.artFrameWidth
  19. height: root.height - 2*globalSettings.artFrameWidth
  20. width: root.width - 2*globalSettings.artFrameWidth
  21. asynchronous: true
  22. fillMode: Image.PreserveAspectFit
  23. source: nativeUtils.imageCollection.data(modelIndex)
  24. mirror: globalSettings.randomlyMirrorArt && (Math.random() < globalSettings.randomlyMirrorArtFreq)
  25. smooth: true
  26. mipmap: false
  27. sourceSize.height: height
  28. sourceSize.width: width
  29. Behavior on opacity {
  30. enabled: image.asynchronous
  31. SequentialAnimation {
  32. ScriptAction { script: root.effect !== undefined ? root.effect.scheduleUpdate() : undefined }
  33. NumberAnimation { duration: 1000 }
  34. }
  35. }
  36. onStatusChanged: {
  37. if (status === Image.Ready) {
  38. opacity = globalSettings.artOpacity
  39. }
  40. }
  41. }
  42. Component.onCompleted: {
  43. modelIndex = nativeUtils.imageCollection.requestIndex()
  44. if (globalSettings.effect !== "" && Effects.validate(globalSettings.effect)) {
  45. var component = Qt.createComponent("VisualEffect.qml");
  46. component.status !== Component.Ready && console.log('Component failed with:' + component.errorString())
  47. root.effect = component.createObject(root, { target: image, effect: globalSettings.effect })
  48. }
  49. }
  50. Component.onDestruction: nativeUtils.imageCollection.retireIndex(modelIndex)
  51. }