ArtImage.qml 1.9 KB

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