ArtImage.qml 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. color: globalSettings.randomTapestryColour ? Qt.rgba(Math.random(255), Math.random(255), Math.random(255), 1.0) : "black"
  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. SequentialAnimation {
  25. ScriptAction { script: root.effect !== undefined ? root.effect.scheduleUpdate() : undefined }
  26. NumberAnimation { duration: 1000 }
  27. }
  28. }
  29. onStatusChanged: {
  30. if (status === Image.Ready) {
  31. opacity = globalSettings.artOpacity
  32. }
  33. }
  34. }
  35. Component.onCompleted: {
  36. modelIndex = Math.floor(Math.random()*imageModel.count)
  37. if (globalSettings.effect !== "" && Effects.validate(globalSettings.effect)) {
  38. var component = Qt.createComponent("VisualEffect.qml");
  39. component.status !== Component.Ready && console.log('Component failed with:' + effectDelegate.errorString())
  40. root.effect = component.createObject(root, { target: image, effect: globalSettings.effect })
  41. }
  42. }
  43. }