forked from JackV2020/thermostatPlusBasic
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathYaLabel.qml
More file actions
246 lines (217 loc) · 9.02 KB
/
Copy pathYaLabel.qml
File metadata and controls
246 lines (217 loc) · 9.02 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
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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
////// yaLabel :: Yet Anoter Label by JackV
////// Based on : 'newTextLabel.qml' MODIFIED BUTTON BY OEPI-LOEPI for TOON
////// So many thanks to OEPIE-LOEPI for 'newTextLabel.qml'
/*
JackV changes :
added
string buttonText2 : ""
bool buttonText2Stack : false // default is buttonText and buttonText2 next to each other
bool buttonText2Active : false // default is buttonText active
bool buttonText2Swap : false // default is that buttonText and buttonText2 do not swap place
fixed in code : buttonText2 size = 0.75 * buttonText size
Reason :
Support a toggle button with 2 text values
Example in the app life in LifeScreen.qml
real lineHeightSize : 1.0
Reason : line spacing for text containing "\n" characters
state selected + string buttonSelectedColor
Reason :
To highlight all selected options on a screen like on my daikin Controls.
There I have up to 4 airco's with different modes, fan speeds etc.
( default: false and when true "yellow" )
use with a variable to detect if button is selected like :
buttonSelectedColor : "red"
selected : ( ad == "3") ? true : false
bool pixelsizeoverride + int pixelsizeoverridesize
Reason :
pixelSize was fixed, now supports different sizes of text on the buttons
( defaults: false and when true 20 )
int buttonBorderWidth + string buttonBorderColor
Reason :
To give each button a configurable border
( defaults: 1 and "black" )
bool hoveringEnabled
Reason :
hovering on Toon 1 leaves button hovered after touching and setting selected false.
now when you use 'hoveringEnabled : isNxt' hovering will only work on Toon 2
I use this in toonSmallHeating, daikin and other apps
int buttonBorderRadius
Reason :
make it configurable so you can make nice rounded corners
removed
fixed margins from anchors in buttonRect
Reason : lef, right, top and bottom were fixed 5, now variable
*/
import QtQuick 2.1
import BasicUIControls 1.0
Item {
id: yaLabel
width : 430
height : defaultHeight
property int defaultHeight : 36
property string buttonText
property real lineHeightSize : 1.0
property alias labelFontFamily : labelTitle.font.family
property alias labelFontSize : labelTitle.font.pixelSize
property string buttonActiveColor : "grey"
property string buttonHoverColor : "blue"
property string buttonSelectedColor : "yellow"
property string buttonDisabledColor : "lightgrey"
property string textColor : "black"
property string textDisabledColor : "grey"
property bool selected : false
property bool pixelsizeoverride : false
property int pixelsizeoverridesize : isNxt ? 20 : 16
property bool hoveringEnabled : true
property string buttonBorderColor : "black"
property int buttonBorderWidth : 1
property int buttonBorderRadius : 5
property string buttonText2 : ""
property bool buttonText2Stack : false
property bool buttonText2Active : false
property bool buttonText2Swap : false
onButtonText2ActiveChanged: {
selected = buttonText2Active
}
// pixelSize: ( (!buttonText2Active || buttonText2Swap) ? 1 : 0.75) * ( yaLabel.pixelsizeoverride ? yaLabel.pixelsizeoverridesize : isNxt ? 20 : 16 )
signal clicked()
function doClick(){
if (buttonText2 != "") { buttonText2Active =! buttonText2Active}
clicked();
}
Rectangle {
id: buttonRect
border {
width: buttonBorderWidth
color: buttonBorderColor
}
anchors {
fill: parent
}
color: buttonActiveColor
radius: buttonBorderRadius
Text {
id: labelTitle
visible: (buttonText2 == "")
anchors {
verticalCenter: parent.verticalCenter
horizontalCenter: parent.horizontalCenter
}
font {
family: qfont.semiBold.name
//pixelSize: qfont.titleText
pixelSize: yaLabel.pixelsizeoverride ? yaLabel.pixelsizeoverridesize : isNxt ? 20 : 16
}
text: buttonText
lineHeight : yaLabel.lineHeightSize
color: yaLabel.enabled? textColor: textDisabledColor
}
Text {
id: labelTitleHorizontal
visible: (!buttonText2Stack && (buttonText2 != ""))
anchors {
right : parent.horizontalCenter
verticalCenter : parent.verticalCenter
}
font {
family: qfont.semiBold.name
//pixelSize: qfont.titleText
pixelSize: ( (!buttonText2Active || buttonText2Swap) ? 1 : 0.75) * ( yaLabel.pixelsizeoverride ? yaLabel.pixelsizeoverridesize : isNxt ? 20 : 16 )
}
text: (buttonText2Active && buttonText2Swap) ? buttonText2 : buttonText
lineHeight : yaLabel.lineHeightSize
color: yaLabel.enabled? textColor: textDisabledColor
}
Text {
id: labelTitleVertical
visible: (buttonText2Stack && (buttonText2 != ""))
anchors {
horizontalCenter: parent.horizontalCenter
bottom: parent.verticalCenter
}
font {
family: qfont.semiBold.name
//pixelSize: qfont.titleText
pixelSize: ( (!buttonText2Active || buttonText2Swap) ? 1 : 0.75) * ( yaLabel.pixelsizeoverride ? yaLabel.pixelsizeoverridesize : isNxt ? 20 : 16 )
}
text: (buttonText2Active && buttonText2Swap) ? buttonText2 : buttonText
lineHeight : yaLabel.lineHeightSize
color: yaLabel.enabled? textColor: textDisabledColor
}
Text {
id: labelTitle2Vertical
visible: (buttonText2Stack && (buttonText2 != ""))
anchors {
top : parent.verticalCenter
horizontalCenter: parent.horizontalCenter
}
font {
family: labelFontFamily
//pixelSize: qfont.titleText
pixelSize: ( (buttonText2Active && ! buttonText2Swap) ? 1 : 0.75) * ( yaLabel.pixelsizeoverride ? yaLabel.pixelsizeoverridesize : isNxt ? 20 : 16 )
}
text: (buttonText2Active && buttonText2Swap) ? buttonText : buttonText2
lineHeight : yaLabel.lineHeightSize
color: yaLabel.enabled? textColor: textDisabledColor
}
Text {
id: labelTitle2Horizontal
visible: (!buttonText2Stack && (buttonText2 != ""))
anchors {
left : parent.horizontalCenter
verticalCenter : parent.verticalCenter
}
font {
family: labelFontFamily
//pixelSize: qfont.titleText
pixelSize: ( (buttonText2Active && ! buttonText2Swap) ? 1 : 0.75) * ( yaLabel.pixelsizeoverride ? yaLabel.pixelsizeoverridesize : isNxt ? 20 : 16 )
}
text: (buttonText2Active && buttonText2Swap) ? buttonText : buttonText2
lineHeight : yaLabel.lineHeightSize
color: yaLabel.enabled? textColor: textDisabledColor
}
state: yaLabel.enabled ? "active" : "disabled"
Component.onCompleted: state = state
states: [
State {
name: "hover"
when: buttonArea.containsMouse || yaLabel.focus
PropertyChanges {
target : buttonRect
color : buttonHoverColor
}
},
State {
name: "active"
when: yaLabel.enabled && !yaLabel.selected
PropertyChanges {
target : buttonRect
color : buttonActiveColor
}
},
State {
name: "selected"
when: yaLabel.enabled && yaLabel.selected
PropertyChanges {
target : buttonRect
color : buttonSelectedColor
}
},
State {
name: "disabled"
when: !yaLabel.enabled
PropertyChanges {
target : buttonRect
color : buttonDisabledColor
}
}
]
}
MouseArea {
id : buttonArea
anchors.fill : parent
hoverEnabled : hoveringEnabled
onClicked : doClick()
cursorShape : Qt.PointingHandCursor
}
}