Debian Codegraph @

tests/resources/lomirishape/LomiriShapeTest.qml

raw ◀ ▶
Source reconstructed at patch state 0 of 1 — not the installed (fully patched) source.
1 Debian patch touch this file
1 /*
2 * Copyright 2015 Canonical Ltd.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation; version 3.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU 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 import QtQuick 2.0
18 import Lomiri.Components 1.3
19
20 Item {
21 id: root
22 width: 1000
23 height: 600
24 focus: true
25
26 // Enum to string tables.
27 property variant aspectTable: [
28 "Flat", "Inset", "DropShadow"
29 ]
30 property variant backgroundModeTable: [
31 "SolidColor", "VerticalGradient"
32 ]
33 property variant sourceHAlignmentTable: [
34 "AlignLeft", "AlignHCenter", "AlignRight"
35 ]
36 property variant sourceVAlignmentTable: [
37 "AlignTop", "AlignVCenter", "AlignBottom"
38 ]
39 property variant sourceFillModeTable: [
40 "Stretch", "PreserveAspectFit", "PreserveAspectCrop", "Pad"
41 ]
42 property variant wrapModeTable: [
43 "Transparent", "Repeat"
44 ]
45 property variant imageFillModeTable: [
46 "Stretch", "PreserveAspectFit", "PreserveAspectCrop", "Tile", "TileVertically",
47 "TileHorizontally", "Pad"
48 ]
49
50 // Zoom properties.
51 property variant translation: Qt.point(0.0, 0.0)
52 property real scaleBase: 1.1
53 property real scaleExponent: 0.0
54 property real minScaleExponent: 0.0
55 property real maxScaleExponent: 48.317715856 // Logarithm of 100 to base 1.1 (scaleBase).
56 property real scaleFactor: 1.0
57 property real scale: 1.0
58
59 // Overlay text properties. French keymapping... :)
60 property string textOverlayString:
61 "Zoom (scroll): x " + root.scaleFactor.toFixed(1) + "\n\n" +
62 "Background colors (a/z): " + shape.backgroundColor + ", " + shape.secondaryBackgroundColor + "\n" +
63 "Background mode (e): " + root.backgroundModeTable[shape.backgroundMode] + "\n\n" +
64 "Radius (r): " + "\"" + shape.radius + "\"\n" +
65 "Aspect (t): " + root.aspectTable[shape.aspect] + "\n" +
66 "relativeRadius (y): " + shape.relativeRadius.toFixed(2) + "\n\n" +
67 "Source (o): " + shape.source + "\n" +
68 "Source opacity (p): " + shape.sourceOpacity.toFixed(2) + "\n" +
69 "Source fill (q): " + root.sourceFillModeTable[shape.sourceFillMode] + "\n" +
70 "Source hwrap (s): " + root.wrapModeTable[shape.sourceHorizontalWrapMode] + "\n" +
71 "Source vwrap (d): " + root.wrapModeTable[shape.sourceVerticalWrapMode] + "\n" +
72 "Source halign (f): " + root.sourceHAlignmentTable[shape.sourceHorizontalAlignment] + "\n" +
73 "Source valign (g): " + root.sourceVAlignmentTable[shape.sourceVerticalAlignment] + "\n" +
74 "Source translation (h/j): " + shape.sourceTranslation.x.toFixed(2) + ", " + shape.sourceTranslation.y.toFixed(2) + "\n" +
75 "Source scale (k/l): " + shape.sourceScale.x.toFixed(2) + ", " + shape.sourceScale.y.toFixed(2) + "\n\n" +
76 "Image (deprecated) (m): " + shape.image + "\n" +
77 "Image fill (w): " + root.imageFillModeTable[img1.fillMode] + "\n" +
78 "Image halign (x): " + img1.horizontalAlignment + "\n" +
79 "Image valign (c): " + img1.verticalAlignment + "\n\n" +
80 "Border (deprecated) (b): " + "\"" + shape.borderSource + "\"\n\n" +
81 "Colors (deprecated) (n/,): " + shape.color + ", " + shape.gradientColor
82
83 // Main scene.
84 Item {
85 id: scene
86 anchors.fill: parent
87
88 Image {
89 id: background
90 anchors.fill: parent
91 source: "background.jpg"
92 fillMode: Image.Tile
93 }
94
95 // Put the LomiriShape source image in the middle of a texture atlas. We use img1.
96 Image { id: img1; visible: false; source: "img1.png"; }
97 Image { id: img2; visible: false; source: "img2.png"; }
98 Image { id: img3; visible: false; source: "img3.png"; }
99 Image { id: img4; visible: false; source: "img4.png"; }
100
101 LomiriShape {
102 id: shape
103 anchors.fill: parent
104 anchors.leftMargin: 400
105 anchors.rightMargin: 100
106 anchors.topMargin: 100
107 anchors.bottomMargin: 100
108 }
109 }
110
111 // Zoom support.
112 ShaderEffectSource {
113 id: shaderEffectSource
114 anchors.fill: scene
115 sourceItem: scene
116 hideSource: true
117 visible: false
118 smooth: false
119 }
120 ShaderEffect {
121 anchors.fill: scene
122 property variant tex: shaderEffectSource
123 property variant translation: root.translation
124 property real scaleFactor: root.scale
125 vertexShader: "
126 uniform mat4 qt_Matrix;
127 uniform float scaleFactor;
128 uniform vec2 translation;
129 attribute vec4 qt_Vertex;
130 attribute vec2 qt_MultiTexCoord0;
131 varying vec2 texCoord;
132 void main() {
133 texCoord = vec2(scaleFactor) * qt_MultiTexCoord0 + translation;
134 gl_Position = qt_Matrix * qt_Vertex;
135 }"
136 fragmentShader: "
137 uniform sampler2D tex;
138 uniform float qt_Opacity;
139 varying vec2 texCoord;
140 void main() {
141 gl_FragColor = texture2D(tex, texCoord) * qt_Opacity;
142 }"
143 }
144
145 // Text overlay.
146 Text {
147 id: textOverlay
148 width:200
149 anchors.top: parent.top
150 anchors.topMargin: 10
151 anchors.left: parent.left
152 anchors.leftMargin: 10
153 font.family: "Ubuntu Mono"
154 font.pixelSize: 14
155 font.weight: Font.Bold
156 color: "black"
157 text: textOverlayString
158 }
159
160 // Mouse handling.
161 MouseArea {
162 id: mouseArea
163 anchors.fill: parent
164 acceptedButtons: Qt.LeftButton
165 hoverEnabled: true
166
167 property real lastX: 0.0
168 property real lastY: 0.0
169
170 onPressed: {
171 if (pressedButtons & Qt.LeftButton) {
172 lastX = mouseX;
173 lastY = mouseY;
174 }
175 }
176 onPositionChanged: {
177 if (pressedButtons & Qt.LeftButton) {
178 var tx = root.translation.x;
179 var ty = root.translation.y;
180 var sx = root.scale / root.width;
181 var sy = root.scale / root.height;
182 var x = mouseX - lastX;
183 var y = mouseY - lastY;
184 root.translation = Qt.point(Math.max(0.0, Math.min(1.0 - root.scale, tx - sx * x)),
185 Math.max(0.0, Math.min(1.0 - root.scale, ty - sy * y)));
186 lastX = mouseX;
187 lastY = mouseY;
188 }
189 }
190 onWheel: {
191 root.scaleExponent = Math.max(minScaleExponent, Math.min(maxScaleExponent,
192 root.scaleExponent + (wheel.angleDelta.y < 0.0 ? -1.0 : 1.0)));
193 root.scaleFactor = Math.pow(root.scaleBase, root.scaleExponent);
194 var oldScale = root.scale;
195 root.scale = 1.0 / root.scaleFactor;
196 var s = oldScale - root.scale;
197 var tx = root.translation.x;
198 var ty = root.translation.y;
199 var x = mouseX / root.width;
200 var y = mouseY / root.height;
201 root.translation = Qt.point(Math.max(0.0, Math.min(1.0 - root.scale, tx + s * x)),
202 Math.max(0.0, Math.min(1.0 - root.scale, ty + s * y)));
203 }
204 }
205
206 // Keyboard handling.
207 Keys.onPressed: {
208 var shift = Qt.ShiftModifier;
209
210 // Background.
211 if (event.key == Qt.Key_A) {
212 shape.backgroundColor = Qt.rgba(
213 Math.random(), Math.random(), Math.random(), Math.random());
214 } else if (event.key == Qt.Key_Z) {
215 shape.secondaryBackgroundColor = Qt.rgba(
216 Math.random(), Math.random(), Math.random(), Math.random());
217 } else if (event.key == Qt.Key_E) {
218 shape.backgroundMode = (shape.backgroundMode + 1) % 3;
219
220 // Styling.
221 } else if (event.key == Qt.Key_R) {
222 shape.radius = (shape.radius == "large") ? "small" :
223 ((shape.radius == "small") ? "medium" : "large");
224 } else if (event.key == Qt.Key_T) {
225 shape.aspect = (shape.aspect + 1) % 3;
226 } else if (event.key == Qt.Key_Y) {
227 shape.relativeRadius = Math.max(0.0, Math.min(
228 1.0, shape.relativeRadius + ((event.modifiers & shift) ? 0.01 : -0.01)));
229
230 // Source.
231 } else if (event.key == Qt.Key_O) {
232 if (shape.source == null) {
233 shape.source = img1;
234 } else {
235 shape.source = null;
236 }
237 } else if (event.key == Qt.Key_P) {
238 shape.sourceOpacity = Math.max(0.0, Math.min(
239 1.0, shape.sourceOpacity + ((event.modifiers & shift) ? 0.01 : -0.01)));
240 } else if (event.key == Qt.Key_Q) {
241 shape.sourceFillMode = (shape.sourceFillMode + 1) % 4;
242 } else if (event.key == Qt.Key_S) {
243 shape.sourceHorizontalWrapMode = (shape.sourceHorizontalWrapMode + 1) % 3;
244 } else if (event.key == Qt.Key_D) {
245 shape.sourceVerticalWrapMode = (shape.sourceVerticalWrapMode + 1) % 3;
246 } else if (event.key == Qt.Key_F) {
247 shape.sourceHorizontalAlignment = (shape.sourceHorizontalAlignment + 1) % 3;
248 } else if (event.key == Qt.Key_G) {
249 shape.sourceVerticalAlignment = (shape.sourceVerticalAlignment + 1) % 3;
250 } else if (event.key == Qt.Key_H) {
251 shape.sourceTranslation = Qt.vector2d(
252 shape.sourceTranslation.x + ((event.modifiers & shift) ? 0.01 : -0.01),
253 shape.sourceTranslation.y);
254 } else if (event.key == Qt.Key_J) {
255 shape.sourceTranslation = Qt.vector2d(
256 shape.sourceTranslation.x,
257 shape.sourceTranslation.y + ((event.modifiers & shift) ? 0.01 : -0.01));
258 } else if (event.key == Qt.Key_K) {
259 shape.sourceScale = Qt.vector2d(
260 shape.sourceScale.x + ((event.modifiers & shift) ? 0.02 : -0.02),
261 shape.sourceScale.y);
262 } else if (event.key == Qt.Key_L) {
263 shape.sourceScale = Qt.vector2d(
264 shape.sourceScale.x,
265 shape.sourceScale.y + ((event.modifiers & shift) ? 0.02 : -0.02));
266
267 // Deprecated image.
268 } else if (event.key == Qt.Key_M) {
269 if (shape.image == null) {
270 shape.image = img1;
271 } else {
272 shape.image = null;
273 }
274 } else if (event.key == Qt.Key_W) {
275 img1.fillMode = (img1.fillMode + 1) % 7;
276 } else if (event.key == Qt.Key_X) {
277 if (img1.horizontalAlignment == Image.AlignLeft) {
278 img1.horizontalAlignment = Image.AlignHCenter;
279 } else if (img1.horizontalAlignment == Image.AlignHCenter) {
280 img1.horizontalAlignment = Image.AlignRight;
281 } else {
282 img1.horizontalAlignment = Image.AlignLeft;
283 }
284 } else if (event.key == Qt.Key_C) {
285 if (img1.verticalAlignment == Image.AlignTop) {
286 img1.verticalAlignment = Image.AlignVCenter;
287 } else if (img1.verticalAlignment == Image.AlignVCenter) {
288 img1.verticalAlignment = Image.AlignBottom;
289 } else {
290 img1.verticalAlignment = Image.AlignTop;
291 }
292
293 // Deprecated styling.
294 } else if (event.key == Qt.Key_B) {
295 if (shape.borderSource == "radius_idle.sci") {
296 shape.borderSource = "radius_pressed.sci";
297 } else if (shape.borderSource == "radius_pressed.sci") {
298 shape.borderSource = "";
299 } else {
300 shape.borderSource = "radius_idle.sci";
301 }
302 } else if (event.key == Qt.Key_N) {
303 shape.color = Qt.rgba(
304 Math.random(), Math.random(), Math.random(), Math.random());
305 } else if (event.key == Qt.Key_Comma) {
306 shape.gradientColor = Qt.rgba(
307 Math.random(), Math.random(), Math.random(), Math.random());
308 }
309 }
310 }