ArtImage.qml 1.5 KB

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