-
Notifications
You must be signed in to change notification settings - Fork 0
/
JalaliDatePicker.qml
324 lines (280 loc) · 12.2 KB
/
JalaliDatePicker.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
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
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
import QtQuick 2.7
import QtQuick.Controls 2.1
import QtQuick.Controls.Material 2.1
import QtQuick.Controls.Universal 2.1
import QtQuick.Layouts 1.1
//import "logic/jalali.js" as Jalali
import "logic/persian-date-0.1.8.js" as PersianDate
Popup {
id: popId
padding: 0
modal: true
clip: true
signal okClicked
property string date: "today"
property string fontFamily: "Samim"
property string iconFont: "Material Icons"
property var selectedPersianDate: new PersianDate.PersianDate()
property string selectedPersianDateString: selectedPersianDate.format("YYYY-MM-DD")
property string selectedPersianTimeString: selectedPersianDate.format("HH:mm")
Component.onCompleted: {
loaderPanelId.sourceComponent = cmpMonthPanelId
}
background: Rectangle {}
ColumnLayout {
anchors.fill: parent
layoutDirection: Qt.RightToLeft
spacing: 10
// Header
Pane {
Layout.fillWidth: true
Layout.preferredHeight: parent.height * 0.25
Material.background: Material.primary
Material.foreground: "white"
Universal.background: Universal.accent
Universal.foreground: "white"
ColumnLayout {
anchors.fill: parent
spacing: 0
Label {
Layout.fillWidth: true
text: selectedPersianDate.format("YYYY")
font.family: fontFamily
font.pixelSize: 14
MouseArea {
hoverEnabled: true
anchors.fill: parent
onClicked: {
yearClicked()
}
}
}
Label {
Layout.fillWidth: true
text: selectedPersianDate.format("dddd، DD MMMM")
font.family: fontFamily
font.pixelSize: 28
font.bold: true
MouseArea {
hoverEnabled: true
anchors.fill: parent
onClicked: {
}
}
}
}
}
Loader {
id: loaderPanelId
Layout.fillWidth: true
Layout.fillHeight: true
}
// Days arrage panel
// Component {
// id: cmpMonthPanelId
// MonthPanel { }
// }
// Action Buttons
Pane {
Layout.fillWidth: true
Row {
//layoutDirection: Qt.RightToLeft
spacing: 5
Button {
text: "OK"
flat: true
Material.foreground: Material.primary
Universal.foreground: Universal.accent
font.bold: true
onClicked: {
okClicked()
popId.close()
}
}
Button {
text: "CANCEL"
flat: true
Material.foreground: Material.primary
Universal.foreground: Universal.accent
font.bold: true
onClicked: popId.close()
}
}
}
}
Component {
id: cmpMonthPanelId
Pane {
id: pnArrageDaysId
property int monthNo: 0
// Prev Month
RoundButton {
id: prevMonthId
anchors.right: parent.right
font.family: iconFont
font.pixelSize: 24
flat: true
text: "\ue315"
onClicked: {
stkMonthPaneId.replaceEnter = transPrevEnterId
stkMonthPaneId.replaceExit = transPrevExitId
stkMonthPaneId.replace(cmpMonthPanelId, {"persianDate": selectedPersianDate.prevMonth(--pnArrageDaysId.monthNo)})
}
}
// Next Month
RoundButton {
id: nextMonthId
anchors.left: parent.left
font.family: iconFont
font.pixelSize: 24
flat: true
text: "\ue314"
onClicked: {
stkMonthPaneId.replaceEnter = transNextEnterId
stkMonthPaneId.replaceExit = transNextExitId
stkMonthPaneId.replace(cmpMonthPanelId, {"persianDate": selectedPersianDate.nextMonth(++pnArrageDaysId.monthNo)})
}
}
// Panel
StackView {
id: stkMonthPaneId
anchors.fill: parent
anchors.topMargin: 14
initialItem: cmpMonthPanelId
replaceEnter: transNextEnterId
replaceExit: transNextExitId
}
Transition {
id: transNextEnterId
XAnimator { from: -stkMonthPaneId.width; to: 0; duration: 300; easing.type: Easing.OutCubic }
}
Transition {
id: transNextExitId
XAnimator { from: 0; to: +stkMonthPaneId.width; duration: 200; easing.type: Easing.OutCubic }
}
Transition {
id: transPrevEnterId
XAnimator { from: stkMonthPaneId.width; to: 0; duration: 300; easing.type: Easing.OutCubic }
}
Transition {
id: transPrevExitId
XAnimator { from: 0; to: -stkMonthPaneId.width; duration: 200; easing.type: Easing.OutCubic }
}
Component {
id: cmpMonthPanelId
ColumnLayout {
id: daysPanelId
layoutDirection: Qt.RightToLeft
spacing: 0
Material.foreground: Qt.rgba(0, 0, 0, 0.87)
Material.accent: Material.primary
Universal.foreground: Qt.rgba(0, 0, 0, 0.87)
Universal.accent: Universal.accent
property var persianDate: selectedPersianDate
onPersianDateChanged: {
//console.log(persianDate.toDate())
selectedPersianDate = persianDate
}
Label {
Layout.fillWidth: true
font.family: fontFamily
font.pixelSize: 14
text: daysPanelId.persianDate.format("MMMM YYYY")
horizontalAlignment: Label.AlignHCenter
verticalAlignment: Label.AlignVCenter
}
Row {
id: layDaysNameId
Layout.fillWidth: true
Layout.preferredHeight: parent.height * (1 / 6)
layoutDirection: Qt.RightToLeft
spacing: 0
opacity: 0.5
Repeater {
model: ListModel {
ListElement { name: "ش" }
ListElement { name: "ی" }
ListElement { name: "د" }
ListElement { name: "س" }
ListElement { name: "چ" }
ListElement { name: "پ" }
ListElement { name: "ج" }
}
delegate: Item {
width: layDaysNameId.width * (1 / 7)
height: parent.height
Label {
anchors.centerIn: parent
font.family: fontFamily
font.pixelSize: 12
text: name
}
}
}
}
Column {
Layout.fillWidth: true
Layout.fillHeight: true
spacing: 5
ButtonGroup {
id: btnGroupId
}
Repeater {
model: 5
delegate: Row {
id: rowWeekId
width: parent.width
height: parent.height * (1 / 5)
spacing: 0
layoutDirection: Qt.RightToLeft
property int rowNo: index
Repeater {
model: 7
delegate: Item {
width: rowWeekId.width * (1 / 7)
height: rowWeekId.height
RoundButton {
id: btnDayId
property int dayNo: (rowWeekId.rowNo * 7) + index - daysPanelId.persianDate.getFirstWeekDayOfMonth() + 2
property var pDate: new PersianDate.PersianDate([daysPanelId.persianDate.year(), daysPanelId.persianDate.month(), dayNo])
anchors.centerIn: parent
width: parent.width < parent.height ? parent.width : parent.height
height: parent.height
flat: true
font.family: fontFamily
text: String(dayNo).toPersianDigit()
visible: dayNo >= 1 && dayNo <= daysPanelId.persianDate.daysInMonth()
padding: 0
checkable: true
ButtonGroup.group: btnGroupId
Material.foreground: hovered || checked ? "white" : Qt.rgba(0, 0, 0, 0.87)
Universal.foreground: hovered || checked ? "white" : Qt.rgba(0, 0, 0, 0.87)
background: Rectangle {
anchors.fill: parent
radius: btnDayId.radius
color: Universal.accent
opacity: btnDayId.checked ? 1.0 : btnDayId.hovered && !btnDayId.down ? 0.5 : btnDayId.down ? 1.0 : 0.0
}
Component.onCompleted: {
//console.log("persianDate: " + persianDate.sod().toDate())
//console.log("pDate: " + pDate.sod().toDate())
//console.log("=======" + (pDate.sod().toDate().getTime() === persianDate.sod().toDate().getTime()))
checked = pDate.sod().toDate().getTime() === selectedPersianDate.sod().toDate().getTime()
}
onCheckedChanged: {
if(!checked) return
monthNo = 0
//selectedPersianDate = pDate
daysPanelId.persianDate = pDate
}
}
}
}
}
}
}
}
}
}
}
}