DelegateItem.qml 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. import QtQuick 2.0
  2. Item {
  3. id: root
  4. property string name
  5. property bool isSelected: listView.currentIndex === index
  6. width: parent ? parent.width : imageItem.width
  7. height: imageItem.height
  8. z: isSelected ? 1000 : -index
  9. rotation: isSelected ? 0 : -15
  10. scale: isSelected ? 1.5 : 0.8
  11. Behavior on rotation {
  12. NumberAnimation { duration: 500; easing.type: Easing.OutBack }
  13. }
  14. Behavior on scale {
  15. NumberAnimation { duration: 1000; easing.type: Easing.OutElastic }
  16. }
  17. MouseArea {
  18. anchors.fill: parent
  19. onClicked: {
  20. if (isSelected) {
  21. detailsView.image = model.image
  22. detailsView.name = model.name
  23. detailsView.year = model.year
  24. detailsView.director = model.director
  25. detailsView.cast = model.cast
  26. detailsView.rating = model.rating
  27. detailsView.overview = model.overview
  28. detailsView.show();
  29. } else {
  30. listView.currentIndex = index;
  31. if (settings.showShootingStarParticles) shootingStarBurst.burst(50);
  32. }
  33. }
  34. }
  35. Image {
  36. id: imageItem
  37. anchors.horizontalCenter: parent.horizontalCenter
  38. source: "images/" + model.image
  39. visible: !settings.showLighting
  40. }
  41. ShaderEffectSource {
  42. id: s1
  43. sourceItem: imageItem
  44. hideSource: settings.showLighting
  45. visible: settings.showLighting
  46. }
  47. ShaderEffect {
  48. anchors.fill: imageItem
  49. property variant src: s1
  50. property variant srcNmap: coverNmapSource
  51. property real widthPortition: mainView.width/imageItem.width
  52. property real heightPortition: mainView.height/imageItem.height
  53. property real widthNorm: widthPortition * 0.5 - 0.5
  54. property real heightNorm: root.y/imageItem.height - listView.contentY / imageItem.height
  55. property real lightPosX: listView.globalLightPosX * widthPortition - widthNorm
  56. property real lightPosY: listView.globalLightPosY * heightPortition - heightNorm
  57. visible: settings.showLighting
  58. fragmentShader: "
  59. uniform sampler2D src;
  60. uniform sampler2D srcNmap;
  61. uniform lowp float qt_Opacity;
  62. varying highp vec2 qt_TexCoord0;
  63. uniform highp float lightPosX;
  64. uniform highp float lightPosY;
  65. void main() {
  66. highp vec4 pix = texture2D(src, qt_TexCoord0.st);
  67. highp vec4 pix2 = texture2D(srcNmap, qt_TexCoord0.st);
  68. highp vec3 normal = normalize(pix2.rgb * 2.0 - 1.0);
  69. highp vec3 light_pos = normalize(vec3(qt_TexCoord0.x - lightPosX, qt_TexCoord0.y - lightPosY, 0.6 ));
  70. highp float diffuse = max(dot(normal, light_pos), 0.4);
  71. // boost a bit
  72. diffuse *= 1.8;
  73. highp vec3 color = diffuse * pix.rgb;
  74. gl_FragColor = vec4(color, pix.a) * qt_Opacity;
  75. }
  76. "
  77. }
  78. }