bc4d49b7851aa3049e6cc9615f5175f3eedf94bd
[lichviet] / qml / DatePicker / component / DateReel.qml
1 import QtQuick 1.1
2
3 import "../../LichViet/main.js" as Script
4
5 Item {
6     id: container
7
8     // Year item dimensions
9     property int yearWidth: (width-2*spacing)*0.4
10     property int yearHeight: height
11     // Month item dimensions
12     property int monthWidth: (width-2*spacing)*0.3
13     property int monthHeight: height
14     // Day item dimensions
15     property int dayWidth: (width-2*spacing)*0.3
16     property int dayHeight: height
17     // Font properties
18     property string fontName: 'Helvetica'
19     property int fontSize: 22
20     property color fontColor: "#666666"
21     // Spacing between items
22     property int spacing: 8
23
24
25     width: 240
26     height:  90
27
28     Component.onCompleted: {
29     }
30
31     Component {
32         id: dayDelegate
33         Button {
34             width: container.dayWidth
35             height: container.dayHeight
36             text: number
37             fontColor: container.fontColor
38             fontName: container.fontName
39             fontSize: container.fontSize
40              opacity: (index+1 < days.start || index+1 > days.end) ? 0.5 : 1.0
41         }
42     }
43
44     Component {
45         id: monthDelegate
46         Button {
47             width: container.monthWidth
48             height: container.monthHeight
49             text: number
50             fontColor: container.fontColor
51             fontName: container.fontName
52             fontSize: container.fontSize
53
54         }
55     }
56
57     Component {
58         id: yearDelegate
59         Button {
60             width: container.yearWidth
61             height: container.yearHeight
62             text: number
63             fontColor: container.fontColor
64             fontName: container.fontName
65             fontSize: container.fontSize
66         }
67     }
68
69
70     Row {
71         id: reels
72         spacing: container.spacing
73
74         Reel {
75             id: day
76             width: container.dayWidth
77             height: container.dayHeight
78             model: days
79             delegate:  dayDelegate
80             autoClose: false
81
82             function mouseoff(){
83                 if (day.index+1 < days.start) day.index = days.start-1;
84                 else if (day.index+1 > days.end ) day.index = days.end-1;
85
86
87                 datePicker.mDay = day.index + 1;
88                 datePicker.mMonth = month.index + 1;
89                 datePicker.mYear = year.index + 1900;
90             }
91         }
92
93         Reel {
94             id: month
95             width: container.monthWidth
96             height: container.monthHeight
97             model: months
98             delegate: monthDelegate
99             autoClose: false
100
101             function mouseoff(){
102                 days.reset()
103                 datePicker.mDay = day.index + 1;
104                 datePicker.mMonth = month.index + 1;
105                 datePicker.mYear = year.index + 1900;
106             }
107         }
108
109         Reel {
110             id: year
111             width: container.yearWidth
112             height: container.yearHeight
113             model: years
114             delegate: yearDelegate
115             autoClose: false
116
117             function mouseoff(){
118                  days.reset()
119                 datePicker.mDay = day.index + 1;
120                 datePicker.mMonth = month.index + 1;
121                 datePicker.mYear = year.index + 1900;
122             }
123         }
124
125     }
126
127
128     ListModel {
129         id: days
130
131         property int start: 1
132         property int end: 31
133
134         Component.onCompleted: {
135             appends()
136             day.index = Script.curDay - 1
137             end = Script.calDaysX(month.index+1,year.index+1900);
138         }
139
140         function reset(){
141             var howmanydays =  Script.calDaysX(month.index+1,year.index+1900);
142             end = howmanydays;
143
144             if (day.index+1 < days.start) day.index = days.start-1;
145             else if (day.index+1 > days.end ) day.index = days.end-1;
146         }
147
148         function appends(){
149             for(var j=1;j<=31;j++){
150                 if (j<=9)
151                    append({number:"0"+j})
152                 else
153                    append({number:j})
154             }
155         }
156
157         function change(){
158            day.index = Script.curDay-1;
159         }
160     }
161
162     ListModel{
163         id: months
164         Component.onCompleted: {
165             for(var j=1;j<=12;j++){
166                 if (j<=9)
167                    append({number:"0"+j})
168                 else
169                    append({number:j})
170             }
171             month.index = Script.curMonth - 1
172         }
173
174         function change(){
175              month.index = Script.curMonth - 1;
176         }
177     }
178
179     ListModel{
180         id: years
181         Component.onCompleted: {
182             for(var i=1900;i<2099;i++){
183                 append({number:i})
184             }
185             year.index = Script.curYear - 1900
186         }
187
188         function change(){
189               year.index = Script.curYear - 1900
190         }
191     }
192
193     function day_reset(){
194          datePicker.mDay = Script.curDay
195         days.change()
196     }
197
198     function month_reset(){
199                  datePicker.mMonth = Script.curMonth
200         months.change()
201     }
202
203     function year_reset(){
204         datePicker.mYear = Script.curYear
205         years.change()
206     }
207
208
209 }