ArtImage.qml 2.2 KB

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