-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathTile.qml
More file actions
80 lines (73 loc) · 1.67 KB
/
Tile.qml
File metadata and controls
80 lines (73 loc) · 1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import QtQuick 2.2
Rectangle {
id: tile
property int tileWidth: 70
property string value: ""
// retourn une chaine vide si 0, sinon la valeur
function valueToText(value) {
if (parseInt(value, 10) === 0) {
return "";
}
return value;
}
// retourne la couleur en fonction de la valeur
function valueToColor(value) {
var v = parseInt(value, 10);
var color;
switch(v) {
case 2:
color = "#eee4da";
break;
case 4:
color = "#eae0c8";
break;
case 8:
color = "#f59563";
break;
case 16:
color = "#3399ff";
break;
case 32:
color = "#ffa333";
break;
case 64:
color = "#cef030";
break;
case 128:
color = "#e8d8ce";
break;
case 256:
color = "#990303";
break;
case 512:
color = "#6ba5de";
break;
case 1024:
color = "#dcad60";
break;
case 2048:
color = "#b60022";
break;
default:
color = "#cbbeb1";
}
return color;
}
function fontSize(value) {
var v = parseInt(value, 10);
if (v < 1024) {
return tileWidth / 2.5;
}
return tileWidth / 3;
}
width: tileWidth
height: tileWidth
color: valueToColor(value)
radius: tileWidth / 14
Text {
text: valueToText(value)
font.pointSize: fontSize(value)
anchors.centerIn: parent
color: "black"
}
}