Warning, /games/kreversi/src/qml/Chip.qml is written in an unsupported language. File is not indexed.

0001 /*
0002     SPDX-FileCopyrightText: 2013 Denis Kuplyakov <dener.kup@gmail.com>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 import QtQuick 2.3
0008 import "globals.js" as Globals
0009 
0010 /**
0011   * Chip
0012   *
0013   * Represents chip on cell.
0014   * Set state to:
0015   *     "Black" to show black chip
0016   *     "White" to show white chip
0017   *     "" (empty string) to hide chip
0018   */
0019 
0020 Item {
0021     id: chipContainer
0022 
0023     /**
0024      * Total frames in animation
0025      */
0026     property int framesCount: 12
0027     /**
0028       * Current chip's frame
0029       */
0030     property int currentFrame: 1
0031     /**
0032       * Chips image's ID prefix at SVG theme file to use.
0033       * Should already contain '_' at end of it.
0034       */
0035     property string imagePrefix: "chip_bw_"
0036     /**
0037       * Duration of chip's turning animation
0038       */
0039     property int animationTime: 25 * 12
0040     /**
0041      * How long to wait before start of animation
0042      */
0043     property int preAnimationTime: 0
0044 
0045     CanvasItem {
0046         id: chipImage
0047         anchors.fill: parent
0048         visible: false
0049         spriteKey: imagePrefix + currentFrame
0050     }
0051     
0052     MouseArea {
0053         id: mouseArea
0054         anchors.fill: parent
0055         onClicked: chipContainer.clicked()
0056     }
0057     
0058     Timer {
0059         id: blinkingTimer
0060         interval: 500
0061         running: false
0062         repeat: true
0063         onTriggered: chipImage.visible = !chipImage.visible
0064     }
0065     
0066     states: [
0067     State {
0068         name: "Black"
0069         
0070         PropertyChanges {
0071             target: chipImage
0072             visible: true
0073         }
0074         
0075         PropertyChanges {
0076             target: chipContainer
0077             currentFrame: 1
0078         }
0079         
0080         PropertyChanges {
0081             target: blinkingTimer
0082             running: false
0083         }
0084     },
0085     
0086     State {
0087         name: "Black_blinking"
0088         
0089         PropertyChanges {
0090             target: chipImage
0091             visible: true
0092         }
0093         
0094         PropertyChanges {
0095             target: chipContainer
0096             currentFrame: 1
0097         }
0098         
0099         PropertyChanges {
0100             target: blinkingTimer
0101             running: true
0102         }
0103     },
0104     
0105     State {
0106         name: "White"
0107         
0108         PropertyChanges {
0109             target: chipImage
0110             visible: true
0111         }
0112         
0113         PropertyChanges {
0114             target: chipContainer
0115             currentFrame: framesCount
0116         }
0117         
0118         PropertyChanges {
0119             target: blinkingTimer
0120             running: false
0121         }
0122     },
0123     
0124     State {
0125         name: "White_blinking"
0126         
0127         PropertyChanges {
0128             target: chipImage
0129             visible: true
0130         }
0131         
0132         PropertyChanges {
0133             target: chipContainer
0134             currentFrame: framesCount
0135         }
0136         
0137         PropertyChanges {
0138             target: blinkingTimer
0139             running: true
0140         }
0141     }
0142     ]
0143     
0144     Behavior on currentFrame {
0145         SequentialAnimation {
0146             PauseAnimation {
0147                 duration: preAnimationTime
0148             }
0149             
0150             NumberAnimation {
0151                 duration: animationTime
0152                 easing.type: Easing.InOutQuad
0153             }
0154 
0155         }
0156     }
0157     
0158     transitions: [
0159     Transition {
0160         from: ""
0161         to: "*"
0162         reversible: false
0163         
0164         NumberAnimation {
0165             property: "currentFrame"
0166             duration: 0
0167         }
0168     }
0169     ]
0170 }