on bionic help sign in
unity8/tests/plugins/Cursor/tst_Cursor.qml
151 lines 4.5 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"
29 property string cursorHeight: "32"
31 CursorImageInfo {
32 id: imageInfo
33 themeName: root.themeName
34 cursorName: root.cursorName
35 cursorHeight: root.cursorHeight
36 }
38 Item {
39 id: cursor
40 x: (200 - animatedSprite.width) / 2
41 y: (root.height - animatedSprite.height) / 2
43 AnimatedSprite {
44 id: animatedSprite
46 x: -imageInfo.hotspot.x
47 y: -imageInfo.hotspot.y
48 source: "image://cursor/" + root.themeName + "/" + root.cursorName + "/" + root.cursorHeight
50 interpolate: false
52 width: imageInfo.frameWidth
53 height: imageInfo.frameHeight
55 frameCount: imageInfo.frameCount
56 frameDuration: imageInfo.frameDuration
57 frameWidth: imageInfo.frameWidth
58 frameHeight: imageInfo.frameHeight
59 }
60 }
62 Rectangle {
63 id: hotspotCrossH
64 color: "red"
65 width: 200
66 height: 1
67 anchors.top: cursor.top
68 opacity: 0.6
69 }
70 Rectangle {
71 id: hotspotCrossV
72 color: "red"
73 width: 1
74 anchors.left: cursor.left
75 anchors.top: parent.top
76 anchors.bottom: parent.bottom
77 opacity: 0.6
78 }
79 MouseArea {
80 anchors.top: parent.top
81 anchors.bottom: parent.bottom
82 anchors.left: parent.left
83 anchors.right: controls.left
84 onClicked: {
85 if (hotspotCrossH.visible) {
86 hotspotCrossH.visible = false;
87 hotspotCrossV.visible = false;
88 } else {
89 hotspotCrossH.visible = true;
90 hotspotCrossV.visible = true;
91 }
92 }
93 }
95 Rectangle {
96 id: controls
97 color: "lightgrey"
98 anchors.right: parent.right
99 anchors.top: parent.top
100 anchors.bottom: parent.bottom
101 width: root.width - 200
103 Column {
104 anchors.fill: parent
105 anchors.margins: 10
107 TextEntry { id: themeNameEntry; name: "themeName"; value: "default" }
109 Item {width: 10; height: 20}
111 TextEntry { id: cursorNameEntry; name: "cursorName"; value: "left_ptr" }
113 Item {width: 10; height: 40}
115 TextEntry { id: cursorHeightEntry; name: "cursorHeight"; value: "32" }
117 Item {width: 10; height: 40}
119 Rectangle {
120 color: applyMouseArea.pressed ? "green" : "lightslategray"
121 width: parent.width - 20
122 height: 40
123 Text { anchors.centerIn: parent; text: "Apply" }
124 MouseArea {
125 id: applyMouseArea
126 anchors.fill: parent
127 onClicked: {
128 root.themeName = themeNameEntry.value;
129 root.cursorName = cursorNameEntry.value;
130 root.cursorHeight = cursorHeightEntry.value;
131 }
132 }
133 }
135 Item {width: 10; height: 10}
136 Rectangle {
137 color: "black"
138 height: 2
139 anchors.left: parent.left
140 anchors.right: parent.right
141 }
142 Item {width: 10; height: 10}
144 Text { text: "frameWidth: " + imageInfo.frameWidth }
145 Text { text: "frameHeight: " + imageInfo.frameHeight }
146 Text { text: "frameCount: " + imageInfo.frameCount }
147 Text { text: "frameDuration: " + imageInfo.frameDuration }
148 Text { text: "currentFrame: " + animatedSprite.currentFrame }
149 }
150 }