ArtImage.qml 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. opacity: globalSettings.fadeInImages ? 0 : 1.0
  15. anchors.fill: parent
  16. asynchronous: true
  17. fillMode: Image.PreserveAspectFit
  18. source: imageModel.data(modelIndex)
  19. mirror: globalSettings.randomlyMirrorArt && (Math.random() < 0.5)
  20. smooth: globalSettings.smoothArt
  21. mipmap: !globalSettings.smoothArt
  22. sourceSize.height: globalVars.imageWidthOverride > 0 ? Math.ceil(globalVars.imageWidthOverride/imageModel.data(modelIndex, PictureModel.RatioRole)) : height
  23. sourceSize.width: globalVars.imageWidthOverride > 0 ? globalVars.imageWidthOverride : width
  24. Behavior on opacity {
  25. enabled: image.asynchronous
  26. SequentialAnimation {
  27. ScriptAction { script: root.effect !== undefined ? root.effect.scheduleUpdate() : undefined }
  28. NumberAnimation { duration: 1000 }
  29. }
  30. }
  31. onStatusChanged: {
  32. if (status === Image.Ready) {
  33. opacity = globalSettings.artOpacity
  34. }
  35. }
  36. }
  37. Component.onCompleted: {
  38. modelIndex = Math.floor(Math.random()*imageModel.count)
  39. if (globalSettings.effect !== "" && Effects.validate(globalSettings.effect)) {
  40. var component = Qt.createComponent("VisualEffect.qml");
  41. component.status !== Component.Ready && console.log('Component failed with:' + component.errorString())
  42. root.effect = component.createObject(root, { target: image, effect: globalSettings.effect })
  43. }
  44. }
  45. }