ArtImage.qml 1.9 KB

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