ArtImage.qml 2.2 KB

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