blob: 65c2577b7fd86de8b25c6d4e45a97bfd2ed448f6 (
plain)
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
|
//
// [maya] components/SpButton.qml
//
// Implements custom action button with label
//
// (c) 2016 Sanjeev Premi (spremi@ymail.com)
//
// SPDX-License-Identifier: MIT
// (https://spdx.org/licenses/MIT.html)
//
import QtQuick 2.0
Item {
id : sp_button
property bool enabled : true
property alias icon : sp_button_icon.source
property alias label : sp_button_label.text
property alias font : sp_button_label.font
property color iconColor : "#aaaaaa"
property color labelColor : "#424242"
property color hoverIconColor : "#cccccc"
property color hoverLabelColor : "#808080"
property color pressIconColor : "#dcdcdc"
property color pressLabelColor : "#a0a0a0"
property color disableColor : "#888888"
signal pressed()
signal released()
signal clicked()
Row {
x : 4
y : 4
spacing : 8
Rectangle {
id : sp_button_bg
width : 40
height : 40
radius : 20
color : iconColor
Image {
id : sp_button_icon
width : 40
height : 40
source : "./blank.svg"
fillMode : Image.Pad
horizontalAlignment : Image.AlignHCenter
verticalAlignment : Image.AlignVCenter
}
}
Text {
id : sp_button_label
height : 40
text : ""
color : labelColor
font.pixelSize : 24
font.weight : Font.DemiBold
fontSizeMode : Text.VerticalFit
horizontalAlignment : Text.AlignRight
verticalAlignment : Text.AlignVCenter
}
}
//
// States and associated visual attributes
//
states: [
State {
name : "disabled"
when : (sp_button.enabled === false)
PropertyChanges {
target : sp_button_bg
color : disableColor
}
PropertyChanges {
target : sp_button_label
color : disableColor
}
},
State {
name : "hover"
PropertyChanges {
target : sp_button_label
color : hoverLabelColor
}
PropertyChanges {
target : sp_button_bg
color : hoverIconColor
}
},
State {
name : "pressed"
PropertyChanges {
target : sp_button_label
color : hoverLabelColor
}
PropertyChanges {
target : sp_button_bg
color : pressIconColor
}
}
]
//
// Behavior on state transitions
//
transitions: [
Transition {
from : ""
to : "hover"
ColorAnimation {
duration: 250
}
},
Transition {
from : ""
to : "pressed"
ColorAnimation {
duration: 25
}
},
Transition {
from : "disabled"
to : "enabled"
ColorAnimation {
duration: 50
}
},
Transition {
from : "enabled"
to : "disabled"
ColorAnimation {
duration: 50
}
}
]
//
// Area to react to mouse actions
//
MouseArea {
anchors.fill : sp_button
hoverEnabled : true
cursorShape : Qt.PointingHandCursor
acceptedButtons : Qt.LeftButton
onEntered : {
sp_button.state = "hover"
}
onExited : {
sp_button.state = ""
}
onPressed : {
sp_button.state = "pressed"
}
onClicked : {
sp_button.clicked()
}
onReleased : {
if (containsMouse) {
sp_button.state = "hover"
} else {
sp_button.state = ""
}
}
}
}
|