Cell.qml 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /*
  2. * Copyright (c) 2011 Nokia Corporation.
  3. */
  4. import QtQuick 1.0
  5. Image {
  6. id: cell
  7. property int cellIdx
  8. property url bgImageSource
  9. property alias number: cellLabel.text
  10. property bool free: false
  11. property bool highlighted: false
  12. source: highlighted ? "gfx/lightGridItem.png" : bgImageSource
  13. //width: //portrait ? (main.blockDim * (main.width / main.dim - 2)) / 3 : (main.blockDim * (main.height / main.dim - 2)) / 3 //portrait ? main.width / 9 - 2 : main.height / 9 - 2
  14. height: width
  15. function startCollisionAnimation() {
  16. collisionNote.startAnimation();
  17. }
  18. Connections {
  19. target: main
  20. onFreeCellsReseted: {
  21. if (free && cellLabel.text) {
  22. resetNumber(cellIdx);
  23. cellLabel.text = "";
  24. }
  25. }
  26. onBoardChanged: {
  27. var val = getNumber(cellIdx);
  28. cellLabel.text = val ? val : "";
  29. free = !val;
  30. // The following needs to be done, because sometimes QML can't
  31. // handle the changing automatically.
  32. cellLabel.color = free ? "white" : "black"
  33. }
  34. }
  35. Text {
  36. id: cellLabel
  37. font {
  38. pixelSize: 30
  39. family: "series 60 zdigi"
  40. }
  41. color: free ? "white" : "black"
  42. anchors.centerIn: parent
  43. }
  44. Rectangle {
  45. id: collisionNote
  46. property string colorOfLabel
  47. function startAnimation() {
  48. collisionNoteAnimation.start();
  49. }
  50. scale: 0
  51. color: "red"
  52. opacity: 0.45
  53. anchors {
  54. fill: parent
  55. }
  56. SequentialAnimation {
  57. id: collisionNoteAnimation
  58. property int speed: 800
  59. ScriptAction {
  60. script: {
  61. collisionNote.colorOfLabel = cellLabel.color;
  62. cellLabel.color = "red";
  63. }
  64. }
  65. NumberAnimation {
  66. target: collisionNote
  67. property: "scale"
  68. to: 1
  69. duration: collisionNoteAnimation.speed
  70. }
  71. ScriptAction {
  72. script: collisionNote.scale = 0;
  73. }
  74. NumberAnimation {
  75. target: collisionNote
  76. property: "scale"
  77. to: 1
  78. duration: collisionNoteAnimation.speed
  79. }
  80. ScriptAction {
  81. script: collisionNote.scale = 0;
  82. }
  83. NumberAnimation {
  84. target: collisionNote
  85. property: "scale"
  86. to: 1
  87. duration: collisionNoteAnimation.speed
  88. }
  89. ScriptAction {
  90. script: {
  91. cellLabel.color = collisionNote.colorOfLabel;
  92. collisionNote.scale = 0;
  93. }
  94. }
  95. }
  96. }
  97. }