-
Notifications
You must be signed in to change notification settings - Fork 1
/
NlalertThreeStateButton.qml
136 lines (125 loc) · 3.18 KB
/
NlalertThreeStateButton.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
import QtQuick 2.1
import BasicUIControls 1.0
/**
ThreStateButton implements button with 3 defined states: "up", "down" and "disabled". Clickable area with
size of the button is created and filled with background color (backgroundUp property).
Button hold only the image (no text). Original image can be rotated using 'imgRotation' property.
For image placed on the button shadow is created (moving original image [+2; +2] with opacity 20%.
Disabled button has no shadow for the icon and color effect is applied on the original image.
States "up" and "down" are handled via mouse click. Icon and button background is different for the statess.
State disabled has to be raised by user calling ThreeStateButton.disable(). Enabling of the button is done
by ThreeStateButton.enable(). This is not a new state - if button is enabled state "up" is used.
*/
Item {
id: threeStateButton
width: 50
height: 50
property url image
property color backgroundUp
property color backgroundDown
property int imgRotation: 0
property color buttonDownColor
property int iconBottomMargin
property alias color: buttonWrap.color
property alias bottomClickMargin: buttonWrap.bottomClickMargin
property alias topClickMargin: buttonWrap.topClickMargin
property alias leftClickMargin: buttonWrap.leftClickMargin
property alias rightClickMargin: buttonWrap.rightClickMargin
property string kpiPostfix: image.toString().split("/").pop().split(".").shift() + imgRotation
property bool enabled: true
onEnabledChanged: {
if(enabled)
threeStateButton.state = "up"
else
threeStateButton.state = "disabled"
}
signal clicked;
onIconBottomMarginChanged: {
icon.anchors.bottomMargin = iconBottomMargin
iconDisabled.anchors.bottomMargin = iconBottomMargin
}
StyledRectangle {
id: buttonWrap
width: threeStateButton.width
height: threeStateButton.height
color: backgroundUp
onPressed: threeStateButton.state = "down"
onReleased: threeStateButton.state = "up"
onClicked: threeStateButton.clicked()
}
Image {
id: icon
rotation: imgRotation
anchors.horizontalCenter: parent.horizontalCenter
source: image
anchors.bottom: parent.bottom
anchors.bottomMargin: 0
}
Image {
id: iconDisabled
rotation: imgRotation
anchors.left: icon.left
anchors.top: icon.top
source: image
opacity: 0.8
visible: false
}
states: [
State {
name: "up"
PropertyChanges {
target: icon
visible: true
}
PropertyChanges {
target: iconDisabled
visible: false
}
PropertyChanges {
target: buttonWrap
mouseEnabled: true
}
},
State {
name: "down"
PropertyChanges {
target: icon
visible: true
}
PropertyChanges {
target: effectDown
enabled: true
}
PropertyChanges {
target: buttonWrap
color: backgroundDown
}
},
State {
name: "disabled"
PropertyChanges {
target: icon
visible: false
}
PropertyChanges {
target: iconDisabled
visible: true
}
PropertyChanges {
target: buttonWrap
mouseEnabled: false
}
},
State {
name: "hidden"
PropertyChanges {
target: icon
visible: false
}
PropertyChanges {
target: buttonWrap
mouseEnabled: false
}
}
]
}