/
Button.qml
73 lines (68 loc) · 1.73 KB
/
Button.qml
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
import QtQuick 2.0
Item {
property color color : "red";
property string text : "";
property color textColor : "yellow";
property bool animate : true;
property font font;
height: 50
width: 100
x: 100
y: 10
signal clicked
signal pressed
signal released
signal pressAndHold
signal doubleClicked
Rectangle {
id: button
color: parent.color
height: parent.height
width: parent.width
x: 0
y: 0
radius: 4
Text {
id: text
anchors.fill: parent
font : parent.parent.font
color: parent.parent.textColor
text: parent.parent.text
wrapMode: Text.Wrap
horizontalAlignment : Text.AlignHCenter
verticalAlignment : Text.AlignVCenter
}
}
Rectangle {
id: shadow
color.r: (button.color.r - 0.4 > 0)? button.color.r - 0.4 : 0;
color.g: (button.color.g - 0.4 > 0)? button.color.g - 0.4 : 0;
color.b: (button.color.b - 0.4 > 0)? button.color.b - 0.4 : 0;
height: parent.height
width: parent.width
x: 0
y: 4
radius: button.radius
z: parent.z - 1
}
MouseArea {
anchors.fill: parent
onClicked: parent.clicked();
onPressed: {
if (parent.animate)
button.y += 2
//for (var i = 0; i > parent.children; i++){
// if (parent.children[i] != shadow)
// parent.children.y +=2
//}
parent.pressed();
}
onReleased: {
if (parent.animate)
button.y -= 2
parent.released();
}
onPressAndHold: parent.pressAndHold();
onDoubleClicked: parent.doubleClicked();
}
}