Tile.qml 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. import Qt 4.7
  2. Flipable {
  3. id: flipable
  4. property int angle: 0
  5. property double ratio: 1
  6. width: 55*ratio; height: 55*ratio
  7. transform: Rotation { origin.x: 28*ratio; origin.y: 28*ratio; axis.x: 0; axis.y: 1; axis.z: 0; angle: flipable.angle }
  8. opacity: 0.8
  9. front: Image {
  10. anchors.centerIn: parent
  11. source: "tiles/white" + ((((index%2) + Math.floor(index/8)%2)%2 + 1) + (Math.floor(index/8)==7 ? 2 : 0 ) + (Math.floor(index/8)==0 ? 4 : 0 ) + (Math.floor(index%8)==0 ? 8 : 0 ) + (Math.floor(index%8)==7 ? 16 : 0 )) + ".png";
  12. width: 90*ratio; height: 90*ratio
  13. Image {
  14. anchors.centerIn: parent
  15. source: "icons/delete.png"; opacity: modelData.hasFlag
  16. width:16
  17. height:16
  18. Behavior on opacity { NumberAnimation {} }
  19. }
  20. Explosion {
  21. property bool repeatable: true;
  22. id: mark
  23. anchors.top: parent.top
  24. anchors.topMargin: 26*ratio
  25. anchors.left: parent.left
  26. anchors.leftMargin: 26*ratio
  27. }
  28. }
  29. back: Image {
  30. source: "tiles/"+(modelData.type.color)+((((index%2) + Math.floor(index/8)%2)%2 + 1) + (Math.floor(index/8)==7 ? 2 : 0 ) + (Math.floor(index/8)==0 ? 4 : 0 ) + (Math.floor(index%8)==0 ? 8 : 0 ) + (Math.floor(index%8)==7 ? 16 : 0 ))+".png"; width: 90*ratio; height: 90*ratio
  31. anchors.centerIn: parent
  32. Text {
  33. anchors.centerIn: parent
  34. text: modelData.hint; color: "white"; font.bold: true
  35. style: Text.Outline
  36. font.pixelSize: 12 * ratio
  37. opacity: /*!modelData.hasMine &&*/ modelData.hint > 0
  38. }
  39. Explosion {
  40. id: expl
  41. anchors.top: parent.top
  42. anchors.topMargin: 26*ratio
  43. anchors.left: parent.left
  44. anchors.leftMargin: 26*ratio
  45. }
  46. }
  47. states: State {
  48. name: "back"; when: modelData.flipped
  49. PropertyChanges { target: flipable; angle: 180 }
  50. }
  51. property real pauseDur: 250
  52. transitions: Transition {
  53. SequentialAnimation {
  54. ScriptAction {
  55. script: {
  56. var ret = Math.abs(flipable.x - field.clickx)
  57. + Math.abs(flipable.y - field.clicky);
  58. if (modelData.hasMine && modelData.flipped)
  59. pauseDur = ret * 3
  60. else
  61. pauseDur = ret
  62. }
  63. }
  64. PauseAnimation {
  65. duration: pauseDur
  66. }
  67. RotationAnimation { easing.type: Easing.InOutQuad }
  68. ScriptAction { script: if (modelData.hasEvidence && modelData.flipped) { expl.explode = true } }
  69. }
  70. }
  71. MouseArea {
  72. anchors.fill: parent
  73. acceptedButtons: Qt.LeftButton | Qt.RightButton
  74. onClicked: {
  75. var row = Math.floor(index / 8);
  76. var col = index - (Math.floor(index / 8) * 8);
  77. if (mouse.button == undefined || mouse.button == Qt.RightButton) {
  78. flag(row, col);
  79. mark.callExplode();
  80. } else {
  81. flip(row, col);
  82. if (modelData.flipped) {
  83. if (modelData.hasEvidence) {
  84. loadEvidence(row, col);
  85. expl.explode = true;
  86. }
  87. }
  88. }
  89. }
  90. onPressAndHold: {
  91. var row = Math.floor(index / 8);
  92. var col = index - (Math.floor(index / 8) * 8);
  93. flag(row, col);
  94. mark.callExplode();
  95. }
  96. }
  97. }