ArtImage.qml 2.7 KB

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