2 Copyright (C) 2010 Artur Duque de Souza <asouza@kde.org>
4 This library is free software; you can redistribute it and/or modify it
5 under the terms of the GNU Library General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or (at your
7 option) any later version.
9 This library is distributed in the hope that it will be useful, but WITHOUT
10 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
12 License for more details.
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to the
16 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
23 import CalendarHelper 4.5
30 property alias day: calendarHelper.day
31 property alias month: calendarHelper.month
32 property alias year: calendarHelper.year
33 property alias daysInMonth: calendarHelper.daysInMonth
39 onDayChanged: calendar.daySelected()
45 anchors.left: parent.left
46 anchors.leftMargin: spacer.width + 5
49 text: KDE.i18n(calendarHelper.monthName)
55 text: calendarHelper.year
66 anchors.top: title.bottom
69 property int dayBoxSize: 54
70 property int headlineHeight: 15
71 property int weekNumberWidth: 20
76 width: calendarGrid.weekNumberWidth
77 height: calendarGrid.headlineHeight
81 model: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"]
83 width: calendarGrid.dayBoxSize
84 height: calendarGrid.headlineHeight
85 text: KDE.i18n(modelData)
89 horizontalAlignment: Text.AlignRight
90 verticalAlignment: Text.AlignBottom
97 width: calendarGrid.weekNumberWidth
98 height: calendarGrid.dayBoxSize
100 text: calendarHelper.weekForPosition(1)
101 horizontalAlignment: Text.AlignRight
102 verticalAlignment: Text.AlignTop
109 currentDay: calendarHelper.day
110 text: calendarHelper.dayForPosition(dayPos);
118 width: calendarGrid.weekNumberWidth
119 height: calendarGrid.dayBoxSize
121 text: calendarHelper.weekForPosition(2)
122 horizontalAlignment: Text.AlignRight
123 verticalAlignment: Text.AlignTop
130 currentDay: calendarHelper.day
131 text: calendarHelper.dayForPosition(dayPos);
139 width: calendarGrid.weekNumberWidth
140 height: calendarGrid.dayBoxSize
142 text: calendarHelper.weekForPosition(3)
143 horizontalAlignment: Text.AlignRight
144 verticalAlignment: Text.AlignTop
151 currentDay: calendarHelper.day
152 text: calendarHelper.dayForPosition(dayPos);
160 width: calendarGrid.weekNumberWidth
161 height: calendarGrid.dayBoxSize
163 text: calendarHelper.weekForPosition(4)
164 horizontalAlignment: Text.AlignRight
165 verticalAlignment: Text.AlignTop
172 currentDay: calendarHelper.day
173 text: calendarHelper.dayForPosition(dayPos);
181 width: calendarGrid.weekNumberWidth
182 height: calendarGrid.dayBoxSize
184 text: calendarHelper.weekForPosition(5)
185 horizontalAlignment: Text.AlignRight
186 verticalAlignment: Text.AlignTop
193 currentDay: calendarHelper.day
194 text: calendarHelper.dayForPosition(dayPos);
202 width: calendarGrid.weekNumberWidth
203 height: calendarGrid.dayBoxSize
205 text: calendarHelper.weekForPosition(6)
206 horizontalAlignment: Text.AlignRight
207 verticalAlignment: Text.AlignTop
214 currentDay: calendarHelper.day
215 text: calendarHelper.dayForPosition(dayPos);
221 anchors.fill: calendarGrid
222 anchors.topMargin: calendarGrid.headlineHeight
223 anchors.leftMargin: calendarGrid.weekNumberWidth
225 property int oldX : 0
226 property int oldY : 0
234 var xDiff = oldX - mouseX;
235 var yDiff = oldY - mouseY;
237 if ( Math.abs( xDiff ) > width * 0.3 || Math.abs( yDiff ) > height * 0.3 ) {
238 // distance is width enough to be a swipe action
240 if ( Math.abs( xDiff ) > Math.abs( yDiff ) ) {
242 calendarHelper.previousMonth();
244 calendarHelper.nextMonth();
247 calendarHelper.previousYear();
249 calendarHelper.nextYear();
256 //onPositionChanged: selectDay(mouse)
258 function selectDay(mouse) {
259 if ((mouse.x < 0) || (mouse.x >= width) || (mouse.y < 0) || (mouse.y >= height))
262 var boxSize = calendarGrid.dayBoxSize + calendarGrid.spacing;
263 var row = Math.floor(mouse.y / boxSize);
264 var column = Math.floor(mouse.x / boxSize);
265 var dayForPosition = calendarHelper.dayForPosition(row * 7 + column + 1);
267 if (dayForPosition != "")
268 calendarHelper.day = dayForPosition;
272 Component.onCompleted: {
273 calendarHelper.registerItems(calendarGrid);