~lukas-kde/miral/shellchrome-windowinfo

« back to all changes in this revision

Viewing changes to miral-qt/demos/qml-demo-client/MovingRect.qml

  • Committer: Larry Price
  • Date: 2016-09-13 16:19:29 UTC
  • mto: (330.4.1 miral)
  • mto: This revision was merged to the branch mainline in revision 352.
  • Revision ID: larry.price@canonical.com-20160913161929-vs9ka1capmljq1es
Removing miral-qt from release branch, updating copyright file, and adding GPL3 license to root dir

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
import QtQuick 2.0
2
 
 
3
 
Rectangle {
4
 
    id: movingRect
5
 
    width: 80
6
 
    height: 80
7
 
    color: "red"
8
 
 
9
 
    property real maxX: parent.width - width
10
 
    property real targetX: maxX
11
 
 
12
 
    function flipTargetX() {
13
 
        if (targetX == 0) {
14
 
            targetX = maxX
15
 
        } else {
16
 
            targetX = 0
17
 
        }
18
 
    }
19
 
 
20
 
    Timer {
21
 
        property real step: 4
22
 
        repeat: true
23
 
        running: true
24
 
        interval: 1000 / 60
25
 
        onTriggered: {
26
 
            if (x < targetX) {
27
 
                if (x + step > targetX) {
28
 
                    x = targetX;
29
 
                } else {
30
 
                    x += step;
31
 
                }
32
 
            } else {
33
 
                if (x - step < targetX) {
34
 
                    x = targetX;
35
 
                } else {
36
 
                    x -= step;
37
 
                }
38
 
            }
39
 
        }
40
 
    }
41
 
 
42
 
    onXChanged: {
43
 
        if (x == targetX) {
44
 
            flipTargetX();
45
 
        }
46
 
    }
47
 
    onWidthChanged: {
48
 
        if (targetX > 0) {
49
 
            targetX = maxX;
50
 
        }
51
 
    }
52
 
 
53
 
    MouseArea {
54
 
        anchors.fill: parent
55
 
        onPressed: {
56
 
            parent.flipTargetX();
57
 
        }
58
 
    }
59
 
}