ArtImage.qml 2.3 KB

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