-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathTemperaturePresetWidget.qml
216 lines (175 loc) · 6.89 KB
/
TemperaturePresetWidget.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
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
import QtQuick
import QtQuick.Layouts
import QtQuick.Controls
import "qrc:/js/UtilsPresets.js" as UtilsPresets
import ThemeEngine
SwipeDelegate {
id: temperaturePresetWidget
implicitWidth: 256
implicitHeight: 80
clip: true
padding: Theme.componentMargin
////////////////////////////////////////////////////////////////////////////
Loader {
id: popupDeleteLoader
active: false
asynchronous: false
sourceComponent: PopupPresetDelete {
id: popupDelete
onConfirmed: presetsManager.removePreset(modelData.name)
onClosed: swipe.close()
}
}
////////////////////////////////////////////////////////////////////////////
background: Rectangle {
color: temperaturePresetWidget.pressed ? Qt.darker(Theme.colorLowContrast, 1.05) : Theme.colorLowContrast
Rectangle {
anchors.right: parent.right
anchors.rightMargin: -12
anchors.verticalCenter: parent.verticalCenter
width: parent.height*0.33
height: parent.height*1.33
rotation: 10
antialiasing: true
color: parent.color
}
Rectangle {
anchors.left: parent.left
anchors.right: parent.right
anchors.bottom: parent.bottom
height: 1
color: Theme.colorSeparator
}
}
////////////////////////////////////////////////////////////////////////////
contentItem: Item {
RowLayout {
anchors.left: parent.left
anchors.right: parent.right
anchors.verticalCenter: parent.verticalCenter
spacing: Theme.componentMargin
////////
Item {
Layout.preferredWidth: 48
Layout.preferredHeight: 48
Layout.alignment: Qt.AlignVCenter
IconSvg {
anchors.centerIn: parent
width: 36
height: 36
smooth: true
color: Theme.colorSubText
source: UtilsPresets.getPresetIcon(modelData.type)
}
}
////////
Column {
Layout.fillWidth: true
Layout.alignment: Qt.AlignVCenter
spacing: Theme.componentMargin / 3
Text {
anchors.left: parent.left
anchors.right: parent.right
text: modelData.name
textFormat: Text.PlainText
//font.capitalization: Text.Capitalize
font.pixelSize: Theme.fontSizeContentVeryBig
color: Theme.colorText
elide: Text.ElideRight
}
////
Row { // preset count & min/max
anchors.left: parent.left
anchors.right: parent.right
spacing: Theme.componentMargin
Text {
visible: (modelData.rangeCount === 0)
text: qsTr("No temperature range defined")
font.pixelSize: Theme.fontSizeContent
color: Theme.colorSubText
}
Text { // count
visible: modelData.rangeCount
text: qsTr("%1 range(s)").arg(modelData.rangeCount)
font.pixelSize: Theme.fontSizeContent
color: Theme.colorSubText
}
Text { // min/max
function unitCelsiusToFahrenheitOrNot(temp_unit) {
if (temp_unit === 0) return "°C"
return "°F"
}
function tempCelsiusToFahrenheitOrNot(temp_c, temp_unit) {
if (temp_unit === 0) return temp_c.toFixed(0)
return (temp_c * 1.8 + 32).toFixed(1);
}
visible: modelData.rangeCount
text: {
if (modelData.tempMaxEnabled) {
return qsTr("(%1°%0 to %2°%0)")
.arg(settingsManager.tempUnit)
.arg(tempCelsiusToFahrenheitOrNot(modelData.rangeMin, settingsManager.appUnits))
.arg(tempCelsiusToFahrenheitOrNot(modelData.rangeMax, settingsManager.appUnits))
} else {
return qsTr("(%1°%0 and up)")
.arg(settingsManager.tempUnit)
.arg(tempCelsiusToFahrenheitOrNot(modelData.rangeMin, settingsManager.appUnits))
}
}
font.pixelSize: Theme.fontSizeContent
color: Theme.colorSubText
}
}
////
}
////////
}
}
////////////////////////////////////////////////////////////////////////////
swipe.enabled: !modelData.readOnly
swipe.right: Row {
anchors.right: parent.right
height: parent.height
Item {
id: deleteLabel
width: parent.height*1.33
height: parent.height
Rectangle {
anchors.fill: parent
color: temperaturePresetWidget.background.color
}
Rectangle {
anchors.centerIn: parent
anchors.horizontalCenterOffset: 10
width: parent.height*1.33
height: parent.height*2
rotation: 10
antialiasing: true
color: deleteLabel.SwipeDelegate.pressed ? Qt.darker(Theme.colorMaterialOrange, 1.1) : Theme.colorMaterialOrange
border.width: 2
border.color: Qt.darker(color, 1.1)
}
Column {
anchors.centerIn: parent
anchors.horizontalCenterOffset: 8
IconSvg {
anchors.horizontalCenter: parent.horizontalCenter
source: "qrc:/assets/icons_material/baseline-delete-24px.svg"
color: "white"
}
Text {
anchors.horizontalCenter: parent.horizontalCenter
text: qsTr("Supprimer")
font.bold: true
color: "white"
}
}
SwipeDelegate.onClicked: {
utilsApp.vibrate(33)
popupDeleteLoader.active = true
popupDeleteLoader.item.open()
}
}
}
////////////////////////////////////////////////////////////////////////////
}