on 310bdf2 help sign in
unity8/tests/plugins/Cursor/tst_Cursor.qml
144 lines 4.2 kB history raw
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 */
18import QtQuick 2.4
19import Cursor 1.1
21Rectangle {
22 id: root
23 color: "blue"
24 width: 400
25 height: 600
27 property string themeName: "default"
28 property string cursorName: "left_ptr"
30 CursorImageInfo {
31 id: imageInfo
32 themeName: root.themeName
33 cursorName: root.cursorName
34 }
36 Item {
37 id: cursor
38 x: (200 - animatedSprite.width) / 2
39 y: (root.height - animatedSprite.height) / 2
41 AnimatedSprite {
42 id: animatedSprite
44 x: -imageInfo.hotspot.x
45 y: -imageInfo.hotspot.y
46 source: "image://cursor/" + root.themeName + "/" + root.cursorName
48 interpolate: false
50 width: imageInfo.frameWidth
51 height: imageInfo.frameHeight
53 frameCount: imageInfo.frameCount
54 frameDuration: imageInfo.frameDuration
55 frameWidth: imageInfo.frameWidth
56 frameHeight: imageInfo.frameHeight
57 }
58 }
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 }
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
101 Column {
102 anchors.fill: parent
103 anchors.margins: 10
105 TextEntry { id: themeNameEntry; name: "themeName"; value: "default" }
107 Item {width: 10; height: 20}
109 TextEntry { id: cursorNameEntry; name: "cursorName"; value: "left_ptr" }
111 Item {width: 10; height: 40}
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 }
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}
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 }