~saviq/unity8/build-arm64

« back to all changes in this revision

Viewing changes to tests/plugins/Cursor/tst_Cursor.qml

  • Committer: Michał Sawicz
  • Date: 2016-07-15 09:51:02 UTC
  • mfrom: (2400.1.142 unity8)
  • Revision ID: michal.sawicz@canonical.com-20160715095102-hf5ac4iqnfn1itpw
Merge trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2016 Canonical, Ltd.
 
3
 *
 
4
 * This program is free software: you can redistribute it and/or modify it under
 
5
 * the terms of the GNU Lesser General Public License version 3, as published by
 
6
 * the Free Software Foundation.
 
7
 *
 
8
 * This program is distributed in the hope that it will be useful, but WITHOUT
 
9
 * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,
 
10
 * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
11
 * Lesser General Public License for more details.
 
12
 *
 
13
 * You should have received a copy of the GNU Lesser General Public License
 
14
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
15
 */
 
16
 
 
17
 
 
18
import QtQuick 2.4
 
19
import Cursor 1.1
 
20
 
 
21
Rectangle {
 
22
    id: root
 
23
    color: "blue"
 
24
    width: 400
 
25
    height: 600
 
26
 
 
27
    property string themeName: "default"
 
28
    property string cursorName: "left_ptr"
 
29
 
 
30
    CursorImageInfo {
 
31
        id: imageInfo
 
32
        themeName: root.themeName
 
33
        cursorName: root.cursorName
 
34
    }
 
35
 
 
36
    Item {
 
37
        id: cursor
 
38
        x: (200 - animatedSprite.width) / 2
 
39
        y: (root.height - animatedSprite.height) / 2
 
40
 
 
41
        AnimatedSprite {
 
42
            id: animatedSprite
 
43
 
 
44
            x: -imageInfo.hotspot.x
 
45
            y: -imageInfo.hotspot.y
 
46
            source: "image://cursor/" + root.themeName + "/" + root.cursorName
 
47
 
 
48
            interpolate: false
 
49
 
 
50
            width: imageInfo.frameWidth
 
51
            height: imageInfo.frameHeight
 
52
 
 
53
            frameCount: imageInfo.frameCount
 
54
            frameDuration: imageInfo.frameDuration
 
55
            frameWidth: imageInfo.frameWidth
 
56
            frameHeight: imageInfo.frameHeight
 
57
        }
 
58
    }
 
59
 
 
60
    Rectangle {
 
61
        id: hotspotCrossH
 
62
        color: "red"
 
63
        width: 200
 
64
        height: 1
 
65
        anchors.top: cursor.top
 
66
        opacity: 0.6
 
67
    }
 
68
    Rectangle {
 
69
        id: hotspotCrossV
 
70
        color: "red"
 
71
        width: 1
 
72
        anchors.left: cursor.left
 
73
        anchors.top: parent.top
 
74
        anchors.bottom: parent.bottom
 
75
        opacity: 0.6
 
76
    }
 
77
    MouseArea {
 
78
        anchors.top: parent.top
 
79
        anchors.bottom: parent.bottom
 
80
        anchors.left: parent.left
 
81
        anchors.right: controls.left
 
82
        onClicked: {
 
83
            if (hotspotCrossH.visible) {
 
84
                hotspotCrossH.visible = false;
 
85
                hotspotCrossV.visible = false;
 
86
            } else {
 
87
                hotspotCrossH.visible = true;
 
88
                hotspotCrossV.visible = true;
 
89
            }
 
90
        }
 
91
    }
 
92
 
 
93
    Rectangle {
 
94
        id: controls
 
95
        color: "lightgrey"
 
96
        anchors.right: parent.right
 
97
        anchors.top: parent.top
 
98
        anchors.bottom: parent.bottom
 
99
        width: root.width - 200
 
100
 
 
101
        Column {
 
102
            anchors.fill: parent
 
103
            anchors.margins: 10
 
104
 
 
105
            TextEntry { id: themeNameEntry; name: "themeName"; value: "default" }
 
106
 
 
107
            Item {width: 10; height: 20}
 
108
 
 
109
            TextEntry { id: cursorNameEntry; name: "cursorName"; value: "left_ptr" }
 
110
 
 
111
            Item {width: 10; height: 40}
 
112
 
 
113
            Rectangle {
 
114
                color: applyMouseArea.pressed ? "green" : "lightslategray"
 
115
                width: parent.width - 20
 
116
                height: 40
 
117
                Text { anchors.centerIn: parent; text: "Apply" }
 
118
                MouseArea {
 
119
                    id: applyMouseArea
 
120
                    anchors.fill: parent
 
121
                    onClicked: {
 
122
                        root.themeName = themeNameEntry.value;
 
123
                        root.cursorName = cursorNameEntry.value;
 
124
                    }
 
125
                }
 
126
            }
 
127
 
 
128
            Item {width: 10; height: 10}
 
129
            Rectangle {
 
130
                color: "black"
 
131
                height: 2
 
132
                anchors.left: parent.left
 
133
                anchors.right: parent.right
 
134
            }
 
135
            Item {width: 10; height: 10}
 
136
 
 
137
            Text { text: "frameWidth: " + imageInfo.frameWidth }
 
138
            Text { text: "frameHeight: " + imageInfo.frameHeight }
 
139
            Text { text: "frameCount: " + imageInfo.frameCount }
 
140
            Text { text: "frameDuration: " + imageInfo.frameDuration }
 
141
            Text { text: "currentFrame: " + animatedSprite.currentFrame }
 
142
        }
 
143
    }
 
144
}