45
|
1 |
/*
|
57
|
2 |
* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
* All rights reserved.
|
|
4 |
* This component and the accompanying materials are made available
|
|
5 |
* under the terms of "Eclipse Public License v1.0"
|
|
6 |
* which accompanies this distribution, and is available
|
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
*
|
|
9 |
* Initial Contributors:
|
|
10 |
* Nokia Corporation - initial contribution.
|
|
11 |
*
|
|
12 |
* Contributors:
|
|
13 |
*
|
|
14 |
* Description: Day view container - parent widget for events (CalenDayItem)
|
|
15 |
* and hours area widgets (CalenDayEventsPane)
|
|
16 |
* Responsible for positioning and resizing events widgets.
|
|
17 |
*/
|
45
|
18 |
|
|
19 |
//System includes
|
|
20 |
#include <QTime>
|
|
21 |
#include <QGraphicsLinearLayout>
|
|
22 |
#include <QGesture>
|
|
23 |
|
|
24 |
#ifdef _DEBUG
|
|
25 |
#include <QPainter>
|
|
26 |
#endif
|
|
27 |
|
57
|
28 |
#include <HbAbstractItemView>
|
|
29 |
#include <HbTextItem>
|
|
30 |
#include <HbModelIterator>
|
|
31 |
#include <HbInstance>
|
45
|
32 |
|
|
33 |
//User includes
|
|
34 |
#include "calendaycontainer.h"
|
|
35 |
#include "calendayutils.h"
|
|
36 |
#include "calendayeventspane.h"
|
|
37 |
#include "calendayitem.h"
|
|
38 |
#include "calendaymodel.h"
|
|
39 |
#include "calendayinfo.h"
|
|
40 |
#include "calendayview.h"
|
57
|
41 |
#include "calenagendautils.h"
|
|
42 |
#include "calendaycommonheaders.h"
|
|
43 |
|
|
44 |
/*!
|
|
45 |
\class CalenDayContainer
|
|
46 |
|
|
47 |
\brief CalenDayContainer Item container class associated with model.
|
|
48 |
*/
|
45
|
49 |
|
55
|
50 |
/*!
|
|
51 |
\brief Constructor
|
|
52 |
|
|
53 |
Sets container initial geometry, creates hours area widgets.
|
57
|
54 |
\param parent Parent object
|
55
|
55 |
*/
|
83
|
56 |
CalenDayContainer::CalenDayContainer(QGraphicsObject *parent) :
|
45
|
57 |
HbAbstractItemContainer(parent), mGeometryUpdated(false), mInfo(0)
|
|
58 |
{
|
83
|
59 |
mEventsPaneElements.clear();
|
45
|
60 |
getTimedEventLayoutValues(mLayoutValues);
|
57
|
61 |
|
45
|
62 |
QGraphicsLinearLayout* timeLinesLayout = new QGraphicsLinearLayout(
|
|
63 |
Qt::Vertical, this);
|
57
|
64 |
for (int i = 0; i < KCalenHoursInDay; i++) {
|
45
|
65 |
CalenDayEventsPane* element = new CalenDayEventsPane(this);
|
57
|
66 |
// Draw top line at midnight
|
45
|
67 |
if (i == 0) {
|
55
|
68 |
element->setDrawTopLine(true);
|
45
|
69 |
}
|
|
70 |
timeLinesLayout->addItem(element);
|
83
|
71 |
mEventsPaneElements.append(element);
|
45
|
72 |
}
|
|
73 |
timeLinesLayout->setContentsMargins(0.0, 0.0, 0.0, 0.0);
|
|
74 |
timeLinesLayout->setSpacing(0.0);
|
|
75 |
|
|
76 |
setLayout(timeLinesLayout);
|
|
77 |
}
|
|
78 |
|
55
|
79 |
/*!
|
|
80 |
\brief Destructor
|
|
81 |
*/
|
45
|
82 |
CalenDayContainer::~CalenDayContainer()
|
|
83 |
{
|
57
|
84 |
// Remove absorbers if exist
|
|
85 |
if (mAbsorbers.count()) {
|
|
86 |
qDeleteAll(mAbsorbers);
|
|
87 |
mAbsorbers.clear();
|
|
88 |
}
|
45
|
89 |
}
|
|
90 |
|
55
|
91 |
/*
|
57
|
92 |
\reimp
|
55
|
93 |
*/
|
57
|
94 |
void CalenDayContainer::itemAdded(
|
|
95 |
int index,
|
|
96 |
HbAbstractViewItem *item,
|
|
97 |
bool animate)
|
45
|
98 |
{
|
|
99 |
Q_UNUSED( index )
|
|
100 |
Q_UNUSED( item )
|
|
101 |
Q_UNUSED( animate )
|
|
102 |
}
|
|
103 |
|
55
|
104 |
|
|
105 |
/*
|
57
|
106 |
\brief Resets the state of container.
|
|
107 |
|
|
108 |
Removes absorbers, gets layout values and maintains current position.
|
55
|
109 |
*/
|
45
|
110 |
void CalenDayContainer::reset()
|
|
111 |
{
|
57
|
112 |
// Remove absorbers if exist
|
|
113 |
if (mAbsorbers.count()) {
|
|
114 |
qDeleteAll(mAbsorbers);
|
|
115 |
mAbsorbers.clear();
|
|
116 |
}
|
|
117 |
|
|
118 |
// Shrink event area when all-day events available after reset
|
|
119 |
getTimedEventLayoutValues(mLayoutValues);
|
|
120 |
|
|
121 |
// Position need to be maintained while changing model
|
45
|
122 |
QPointF position(pos());
|
|
123 |
HbAbstractItemContainer::reset();
|
57
|
124 |
setPos(position);
|
45
|
125 |
}
|
|
126 |
|
55
|
127 |
/*
|
57
|
128 |
\reimp
|
55
|
129 |
*/
|
57
|
130 |
void CalenDayContainer::itemRemoved(HbAbstractViewItem *item, bool animate)
|
45
|
131 |
{
|
|
132 |
Q_UNUSED( item )
|
|
133 |
Q_UNUSED( animate )
|
|
134 |
}
|
|
135 |
|
55
|
136 |
/*
|
57
|
137 |
\reimp
|
55
|
138 |
*/
|
57
|
139 |
void CalenDayContainer::viewResized(const QSizeF &size)
|
45
|
140 |
{
|
|
141 |
resize(size);
|
|
142 |
if (!mGeometryUpdated) {
|
|
143 |
mGeometryUpdated = true;
|
|
144 |
updateGeometry();
|
|
145 |
}
|
|
146 |
}
|
|
147 |
|
55
|
148 |
/*
|
57
|
149 |
\reimp
|
55
|
150 |
*/
|
45
|
151 |
HbAbstractViewItem * CalenDayContainer::createDefaultPrototype() const
|
|
152 |
{
|
55
|
153 |
CalenDayItem *calendarViewItem = new CalenDayItem(this);
|
45
|
154 |
return calendarViewItem;
|
|
155 |
}
|
|
156 |
|
55
|
157 |
/*
|
57
|
158 |
\reimp
|
55
|
159 |
*/
|
57
|
160 |
void CalenDayContainer::setItemModelIndex(
|
|
161 |
HbAbstractViewItem *item,
|
|
162 |
const QModelIndex &index)
|
45
|
163 |
{
|
57
|
164 |
QVariant variant = index.data(CalenDayEntry);
|
|
165 |
AgendaEntry entry = variant.value<AgendaEntry> ();
|
|
166 |
|
|
167 |
// Check for All Day Events and Timed entries
|
|
168 |
if (CalenAgendaUtils::isAlldayEvent(entry)) {
|
|
169 |
updateAllDayEventGeometry(item, index);
|
45
|
170 |
item->setParentItem(this);
|
|
171 |
}
|
57
|
172 |
else
|
|
173 |
if (entry.isTimedEntry()) {
|
|
174 |
updateTimedEventGeometry(item, index);
|
|
175 |
item->setParentItem(this);
|
|
176 |
}
|
|
177 |
else {
|
|
178 |
item->setVisible(false);
|
|
179 |
}
|
|
180 |
|
|
181 |
// Create touch event absorbers after last item
|
45
|
182 |
if (index.row() == index.model()->rowCount() - 1) {
|
57
|
183 |
createTouchEventAbsorbers();
|
45
|
184 |
}
|
|
185 |
|
|
186 |
HbAbstractItemContainer::setItemModelIndex(item, index);
|
|
187 |
}
|
|
188 |
|
55
|
189 |
|
|
190 |
/*!
|
57
|
191 |
\brief Set size and position of singe timed event widget (bubble)
|
|
192 |
\a item bubble widget
|
|
193 |
\a index pointing item data in model
|
55
|
194 |
*/
|
57
|
195 |
void CalenDayContainer::updateTimedEventGeometry(
|
|
196 |
HbAbstractViewItem *item,
|
|
197 |
const QModelIndex &index)
|
45
|
198 |
{
|
57
|
199 |
// Safety check
|
|
200 |
if (!mInfo) {
|
45
|
201 |
return;
|
|
202 |
}
|
57
|
203 |
|
|
204 |
QVariant variant = index.data(CalenDayEntry);
|
|
205 |
AgendaEntry entry = variant.value<AgendaEntry> ();
|
|
206 |
|
|
207 |
// 1. Get 'virtual' event position from DayInfo
|
45
|
208 |
SCalenApptInfo apptInfo;
|
|
209 |
apptInfo.iIndex = index;
|
57
|
210 |
|
45
|
211 |
QDateTime start;
|
|
212 |
QDateTime end;
|
|
213 |
QDateTime currentDate;
|
57
|
214 |
currentDate
|
|
215 |
= static_cast<const CalenDayModel*> (index.model())->modelDate();
|
|
216 |
CalenDayUtils::instance()->getEventValidStartEndTime(start, end, entry,
|
|
217 |
currentDate);
|
45
|
218 |
apptInfo.iStartTime = start;
|
|
219 |
apptInfo.iEndTime = end;
|
57
|
220 |
|
45
|
221 |
TCalenInstanceId id = TCalenInstanceId::nullInstanceId();
|
|
222 |
id.mEntryLocalUid = index.row(); //index.row() - temporary ID
|
57
|
223 |
id.mInstanceTime = apptInfo.iStartTime;
|
45
|
224 |
apptInfo.iId = id;
|
|
225 |
apptInfo.iAllDay = 0;
|
|
226 |
apptInfo.iColor = 0xffff;
|
57
|
227 |
|
45
|
228 |
int startSlot, endSlot, columnIdx, columns;
|
57
|
229 |
mInfo->GetLocation(apptInfo, startSlot, endSlot, columnIdx, columns);
|
45
|
230 |
|
57
|
231 |
// 2. Set timed event's geometry
|
|
232 |
qreal eventStartX(mLayoutValues.eventAreaX);
|
45
|
233 |
qreal eventStartY(0.0);
|
|
234 |
qreal eventWidth(mLayoutValues.eventAreaWidth);
|
|
235 |
qreal eventHeight(0.0);
|
57
|
236 |
|
|
237 |
// Event's startY/height
|
45
|
238 |
eventStartY = startSlot * mLayoutValues.slotHeight;
|
|
239 |
eventHeight = (endSlot - startSlot) * mLayoutValues.slotHeight;
|
|
240 |
|
57
|
241 |
// Event's startX/width
|
45
|
242 |
eventWidth /= columns;
|
63
|
243 |
|
|
244 |
// In case when eventWidth will be smaller then KCalenMinEventWidth [un]
|
57
|
245 |
// spacings between events should be smaller.
|
|
246 |
// Check whether it's possible to shrink them so the bubbles width
|
63
|
247 |
// can stay at KCalenMinEventWidth [un] (time stripe + frame margins).
|
|
248 |
qreal minWidth = KCalenMinEventWidth * mLayoutValues.unitInPixels;
|
57
|
249 |
if (eventWidth - mLayoutValues.eventMargin < minWidth) {
|
|
250 |
|
|
251 |
// Calculate new margin value
|
64
|
252 |
// from totalMarginSpace we need to subtract mLayoutValues.eventMargin
|
|
253 |
// because first margin is always KCalenSpaceBeetwenEvents
|
57
|
254 |
qreal totalMarginSpace = mLayoutValues.eventAreaWidth - minWidth
|
|
255 |
* columns - mLayoutValues.eventMargin;
|
45
|
256 |
qreal newMarginValue = totalMarginSpace / (columns - 1);
|
57
|
257 |
|
|
258 |
// Check if we managed to pack all the events into space we have
|
|
259 |
if (newMarginValue > 0) {
|
45
|
260 |
eventWidth = minWidth;
|
|
261 |
}
|
57
|
262 |
else {
|
|
263 |
// There's not enough space
|
64
|
264 |
// New minWidth is KCalenMinTimeStripWidth [un] (time stripe only)
|
|
265 |
minWidth = KCalenMinTimeStripWidth * mLayoutValues.unitInPixels;
|
57
|
266 |
totalMarginSpace = mLayoutValues.eventAreaWidth - minWidth * columns
|
|
267 |
- mLayoutValues.eventMargin;
|
45
|
268 |
newMarginValue = totalMarginSpace / (columns - 1);
|
|
269 |
eventWidth = minWidth;
|
|
270 |
}
|
|
271 |
|
63
|
272 |
// First column margin should be always KCalenSpaceBeetwenEvents
|
|
273 |
// (mLayoutValues.eventMargin)
|
45
|
274 |
eventStartX += columnIdx * (eventWidth + newMarginValue) + mLayoutValues.eventMargin;
|
|
275 |
}
|
57
|
276 |
else {
|
|
277 |
// Add margins between the event
|
45
|
278 |
eventStartX += columnIdx * eventWidth + mLayoutValues.eventMargin;
|
|
279 |
eventWidth -= mLayoutValues.eventMargin;
|
|
280 |
}
|
57
|
281 |
|
70
|
282 |
// Verify if height of event is greater than minimum (UI spec)
|
|
283 |
qreal minHeight = CalenDayUtils::instance()->minEventHeight();
|
|
284 |
eventHeight = (eventHeight < minHeight ? minHeight : eventHeight);
|
57
|
285 |
QRectF eventGeometry(eventStartX, eventStartY, eventWidth, eventHeight);
|
63
|
286 |
|
|
287 |
// Workaround to prevent size hint caching inside effectiveSizeHint
|
|
288 |
item->setMinimumSize(0, 0);
|
|
289 |
item->setMaximumSize(eventWidth, eventHeight);
|
55
|
290 |
item->setGeometry(eventGeometry);
|
|
291 |
}
|
45
|
292 |
|
|
293 |
|
55
|
294 |
/*!
|
57
|
295 |
\brief Set size and position of singe all-day event widget (bubble)
|
|
296 |
\a item bubble widget
|
|
297 |
\a index pointing item data in model
|
55
|
298 |
*/
|
57
|
299 |
void CalenDayContainer::updateAllDayEventGeometry(
|
|
300 |
HbAbstractViewItem *item,
|
|
301 |
const QModelIndex &index)
|
45
|
302 |
{
|
57
|
303 |
// Safety check
|
|
304 |
if (!mInfo) {
|
|
305 |
return;
|
|
306 |
}
|
|
307 |
|
|
308 |
QVariant variant = index.data(CalenDayEntry);
|
|
309 |
AgendaEntry entry = variant.value<AgendaEntry> ();
|
|
310 |
|
|
311 |
// 1. Get 'virtual' event position from DayInfo
|
|
312 |
SCalenApptInfo apptInfo;
|
|
313 |
apptInfo.iIndex = index;
|
|
314 |
|
|
315 |
QDateTime start;
|
45
|
316 |
QDateTime end;
|
|
317 |
QDateTime currentDate;
|
57
|
318 |
currentDate
|
|
319 |
= static_cast<const CalenDayModel*> (index.model())->modelDate();
|
|
320 |
CalenDayUtils::instance()->getEventValidStartEndTime(start, end, entry,
|
|
321 |
currentDate);
|
45
|
322 |
apptInfo.iStartTime = start;
|
|
323 |
apptInfo.iEndTime = end;
|
57
|
324 |
|
|
325 |
TCalenInstanceId id = TCalenInstanceId::nullInstanceId();
|
|
326 |
id.mEntryLocalUid = index.row(); //index.row() - temporary ID
|
|
327 |
id.mInstanceTime = apptInfo.iStartTime;
|
|
328 |
apptInfo.iId = id;
|
|
329 |
apptInfo.iAllDay = true;
|
|
330 |
apptInfo.iColor = 0xffff;
|
|
331 |
|
|
332 |
int startSlot, endSlot, columnIdx, columns;
|
|
333 |
mInfo->GetLocation(apptInfo, startSlot, endSlot, columnIdx, columns);
|
45
|
334 |
|
57
|
335 |
// 2. Set timed event's geometry
|
|
336 |
qreal eventStartX(0.0);
|
|
337 |
qreal eventStartY(0.0);
|
|
338 |
qreal eventWidth(mLayoutValues.eventAreaX);
|
|
339 |
qreal eventHeight = (endSlot - startSlot) * mLayoutValues.slotHeight;
|
|
340 |
|
|
341 |
// Event's startX/width
|
|
342 |
if (columns > 1) {
|
|
343 |
eventWidth /= columns;
|
|
344 |
eventStartX += columnIdx * eventWidth + mLayoutValues.eventMargin;
|
|
345 |
// Add margins between the event
|
|
346 |
eventWidth -= mLayoutValues.eventMargin;
|
|
347 |
}
|
|
348 |
else {
|
|
349 |
eventStartX += mLayoutValues.eventMargin;
|
|
350 |
eventWidth -= mLayoutValues.eventMargin;
|
|
351 |
}
|
|
352 |
|
|
353 |
QRectF eventGeometry(eventStartX, eventStartY, eventWidth, eventHeight);
|
63
|
354 |
|
|
355 |
// Workaround to prevent size hint caching inside effectiveSizeHint
|
|
356 |
item->setMinimumSize(0, 0);
|
|
357 |
item->setMaximumSize(eventWidth, eventHeight);
|
57
|
358 |
item->setGeometry(eventGeometry);
|
45
|
359 |
}
|
|
360 |
|
|
361 |
|
55
|
362 |
/*!
|
57
|
363 |
\brief Gets event layout values
|
|
364 |
\a layoutValues structure to be filled with layout data
|
55
|
365 |
*/
|
45
|
366 |
void CalenDayContainer::getTimedEventLayoutValues(LayoutValues& layoutValues)
|
|
367 |
{
|
64
|
368 |
// Get the width of entire content area
|
45
|
369 |
qreal contentWidth = CalenDayUtils::instance()->contentWidth();
|
57
|
370 |
|
45
|
371 |
HbStyle style;
|
|
372 |
HbDeviceProfile deviceProfile;
|
|
373 |
layoutValues.unitInPixels = deviceProfile.unitValue();
|
57
|
374 |
|
64
|
375 |
// Empty right column's width
|
|
376 |
qreal emptyRightColumnWidth = KCalenEmptyRightColumnWidth
|
|
377 |
* layoutValues.unitInPixels;
|
|
378 |
|
|
379 |
// Margins between the overlapping events -> eventMargin[out]
|
|
380 |
layoutValues.eventMargin = KCalenSpaceBeetwenEvents
|
|
381 |
* layoutValues.unitInPixels;
|
|
382 |
|
|
383 |
// Start position (x) for drawing events -> eventAreaX[out]
|
57
|
384 |
if (mInfo && mInfo->AlldayCount()) {
|
64
|
385 |
layoutValues.eventAreaX = KCalenAllDayEventArea * (contentWidth
|
|
386 |
- emptyRightColumnWidth);
|
57
|
387 |
}
|
|
388 |
else {
|
|
389 |
layoutValues.eventAreaX = 0;
|
|
390 |
}
|
|
391 |
|
64
|
392 |
// Event area width (excluding All Day Events area)-> eventAreaWidth[out]
|
57
|
393 |
layoutValues.eventAreaWidth = contentWidth - emptyRightColumnWidth
|
|
394 |
- layoutValues.eventAreaX;
|
|
395 |
|
64
|
396 |
// Half-hour slot's height -> slotHeight[out]
|
57
|
397 |
layoutValues.slotHeight = CalenDayUtils::instance()->hourElementHeight()
|
|
398 |
/ KCalenSlotsInHour;
|
|
399 |
|
64
|
400 |
// Check if touch absorbers should be created over some overlapping regions
|
57
|
401 |
layoutValues.maxColumns = layoutValues.eventAreaWidth
|
63
|
402 |
/ ((KCalenMinTouchableEventWidth + KCalenSpaceBeetwenEvents)
|
|
403 |
* layoutValues.unitInPixels);
|
45
|
404 |
}
|
|
405 |
|
55
|
406 |
|
|
407 |
/*!
|
57
|
408 |
\brief Sets day's info structure to the container.
|
|
409 |
\a dayInfo day's info data
|
|
410 |
|
|
411 |
\sa CalenDayInfo, CalenDayContainer::dayInfo
|
55
|
412 |
*/
|
57
|
413 |
void CalenDayContainer::setDayInfo(CalenDayInfo* dayInfo)
|
45
|
414 |
{
|
|
415 |
mInfo = dayInfo;
|
|
416 |
}
|
|
417 |
|
57
|
418 |
/*!
|
|
419 |
\brief It return pointer to info structure of container.
|
|
420 |
|
|
421 |
\sa CalenDayInfo, CalenDayContainer::setDayInfo
|
|
422 |
*/
|
|
423 |
CalenDayInfo* CalenDayContainer::dayInfo()
|
|
424 |
{
|
|
425 |
return mInfo;
|
|
426 |
}
|
|
427 |
|
|
428 |
/*!
|
|
429 |
\brief Sets date to the container.
|
|
430 |
Changes according to model which is connected to given view.
|
|
431 |
|
|
432 |
\a date Date of container
|
|
433 |
*/
|
55
|
434 |
void CalenDayContainer::setDate(const QDate &date)
|
|
435 |
{
|
|
436 |
mDate = date;
|
|
437 |
}
|
|
438 |
|
57
|
439 |
/*!
|
|
440 |
\brief Returns date of the container.
|
|
441 |
|
|
442 |
\sa date Date of container
|
|
443 |
*/
|
55
|
444 |
const QDate &CalenDayContainer::date() const
|
|
445 |
{
|
|
446 |
return mDate;
|
|
447 |
}
|
|
448 |
|
|
449 |
/*!
|
83
|
450 |
\brief Calculates date and time for scene position given by parameter.
|
|
451 |
If date and time for given position cannot be calculated, invalid dateTime is returned.
|
|
452 |
The accuracy of returned time is 30 minutes.
|
|
453 |
|
|
454 |
\sa pos Position in scene.
|
|
455 |
*/
|
|
456 |
QDateTime CalenDayContainer::dateTimeAtPos(const QPointF &pos)
|
|
457 |
{
|
|
458 |
QPointF pointPos = mapFromScene(pos);
|
|
459 |
QDateTime dateTime;
|
|
460 |
int hour = -1;
|
|
461 |
int minutes = 0;
|
|
462 |
for (int i = 0; i < mEventsPaneElements.count(); i++) {
|
|
463 |
QRectF paneGeometry = mEventsPaneElements.at(i)->geometry();
|
|
464 |
if (paneGeometry.contains(pointPos)) {
|
|
465 |
hour = i;
|
|
466 |
QRectF firstHalf(paneGeometry.left(), paneGeometry.top(),
|
|
467 |
paneGeometry.width(), paneGeometry.height() / 2);
|
|
468 |
if (firstHalf.contains(pointPos)) {
|
|
469 |
minutes = 0;
|
|
470 |
}
|
|
471 |
else {
|
|
472 |
minutes = 30;
|
|
473 |
}
|
|
474 |
break;
|
|
475 |
}
|
|
476 |
}
|
|
477 |
|
|
478 |
if (hour >= 0) {
|
|
479 |
dateTime.setDate(mDate);
|
|
480 |
dateTime.setTime(QTime(hour, minutes));
|
|
481 |
}
|
|
482 |
|
|
483 |
return dateTime;
|
|
484 |
}
|
|
485 |
|
|
486 |
/*!
|
57
|
487 |
\brief Slot handles layout switch.
|
|
488 |
\a orientation current device orientation
|
55
|
489 |
*/
|
45
|
490 |
void CalenDayContainer::orientationChanged(Qt::Orientation orientation)
|
|
491 |
{
|
57
|
492 |
getTimedEventLayoutValues(mLayoutValues);
|
|
493 |
|
45
|
494 |
Q_UNUSED( orientation )
|
|
495 |
QList<HbAbstractViewItem *> items = this->items();
|
|
496 |
int count(items.count());
|
|
497 |
for (int i = 0; i < count; i++) {
|
|
498 |
QModelIndex modelIndex = items[i]->modelIndex();
|
|
499 |
if (modelIndex.isValid()) {
|
|
500 |
QVariant variant = modelIndex.data(CalenDayEntry);
|
|
501 |
AgendaEntry entry = variant.value<AgendaEntry> ();
|
57
|
502 |
if (entry.isTimedEntry() && !CalenAgendaUtils::isAlldayEvent(entry)) {
|
45
|
503 |
updateTimedEventGeometry(items[i], modelIndex);
|
|
504 |
}
|
57
|
505 |
else
|
|
506 |
if (CalenAgendaUtils::isAlldayEvent(entry)) {
|
|
507 |
updateAllDayEventGeometry(items[i], modelIndex);
|
|
508 |
}
|
45
|
509 |
}
|
|
510 |
}
|
57
|
511 |
|
45
|
512 |
createTouchEventAbsorbers();
|
|
513 |
}
|
|
514 |
|
55
|
515 |
|
|
516 |
/*!
|
57
|
517 |
\brief Creates absorbers which prevent touching to small items
|
|
518 |
According to UI spec items smaller than 8.2 un are untouchable
|
55
|
519 |
*/
|
45
|
520 |
void CalenDayContainer::createTouchEventAbsorbers()
|
|
521 |
{
|
57
|
522 |
// remove absorbers if exist
|
|
523 |
if (mAbsorbers.count()) {
|
|
524 |
qDeleteAll(mAbsorbers);
|
|
525 |
mAbsorbers.clear();
|
|
526 |
}
|
|
527 |
|
|
528 |
// Create absorber for all-day events
|
|
529 |
Qt::Orientation orientation = CalenDayUtils::instance()->orientation();
|
|
530 |
int allDayCount = mInfo->AlldayCount();
|
|
531 |
|
|
532 |
if ((orientation == Qt::Vertical
|
|
533 |
&& allDayCount > KCalenTouchableAllDayEventsCountPortrait)
|
|
534 |
|| (orientation == Qt::Horizontal
|
|
535 |
&& allDayCount > KCalenTouchableAllDayEventsCountLandscape)) {
|
|
536 |
TouchEventAbsorber* absorber = crateAbsorberBetweenSlots(0, 0, true);
|
|
537 |
mAbsorbers.append(absorber);
|
|
538 |
}
|
|
539 |
|
|
540 |
// Create absorbers for timed events
|
|
541 |
const QList<CalenTimeRegion>& regionList = mInfo->RegionList();
|
|
542 |
for (int i = 0; i < regionList.count(); i++) {
|
|
543 |
if (regionList[i].iColumns.count() > mLayoutValues.maxColumns) {
|
|
544 |
TouchEventAbsorber* absorber = crateAbsorberBetweenSlots(
|
|
545 |
regionList[i].iStartSlot, regionList[i].iEndSlot, false);
|
|
546 |
|
|
547 |
mAbsorbers.append(absorber);
|
|
548 |
}
|
|
549 |
}
|
45
|
550 |
}
|
|
551 |
|
55
|
552 |
|
|
553 |
/*!
|
57
|
554 |
\brief Creates single absorber in given location
|
|
555 |
\a startSlot absorber area starts from there
|
|
556 |
\a endSlot absobrber area ends here
|
|
557 |
\a forAllDayEvents if true absorber in all-day events area is created
|
55
|
558 |
*/
|
57
|
559 |
TouchEventAbsorber *CalenDayContainer::crateAbsorberBetweenSlots(
|
|
560 |
int startSlot,
|
|
561 |
int endSlot,
|
|
562 |
bool forAllDayEvents)
|
45
|
563 |
{
|
|
564 |
TouchEventAbsorber *absorber = new TouchEventAbsorber(this);
|
|
565 |
absorber->setZValue(1000);
|
|
566 |
absorber->setVisible(true);
|
57
|
567 |
if (!forAllDayEvents) {
|
|
568 |
absorber->setGeometry(mLayoutValues.eventAreaX, // x
|
|
569 |
startSlot * mLayoutValues.slotHeight, // y
|
|
570 |
mLayoutValues.eventAreaWidth, // w
|
|
571 |
(endSlot - startSlot) * mLayoutValues.slotHeight); // h
|
|
572 |
}
|
|
573 |
else {
|
|
574 |
absorber->setGeometry(0, 0, mLayoutValues.eventAreaX,
|
|
575 |
KCalenHoursInDay * KCalenSlotsInHour * mLayoutValues.slotHeight);
|
|
576 |
}
|
|
577 |
|
45
|
578 |
return absorber;
|
|
579 |
}
|
|
580 |
|
83
|
581 |
/*!
|
|
582 |
\brief This slot is called when backround type of item changes. It maintains mFloatingItemsList.
|
|
583 |
Thanks that scroll events are propagated only to items that might be interested in getting such
|
|
584 |
information.
|
|
585 |
|
|
586 |
\a item Pointer to the item that reported backround type change.
|
|
587 |
*/
|
|
588 |
void CalenDayContainer::updateFloatingItemsList(const CalenDayItem *item)
|
|
589 |
{
|
|
590 |
if(!item){
|
|
591 |
return;
|
|
592 |
}
|
|
593 |
|
|
594 |
bool isItemOnList = mFloatingItemsList.contains(item);
|
|
595 |
|
|
596 |
switch(item->backgroundType()){
|
|
597 |
|
|
598 |
case CalenDayItem::EFloatingBackground:
|
|
599 |
|
|
600 |
if(!isItemOnList){
|
|
601 |
connect(itemView(), SIGNAL(scrollPositionChanged(const QPointF&)), item, SLOT(scrollBackground(const QPointF&)));
|
|
602 |
mFloatingItemsList.append(item);
|
|
603 |
}
|
|
604 |
break;
|
|
605 |
|
|
606 |
case CalenDayItem::EStaticBackground:
|
|
607 |
|
|
608 |
if(isItemOnList){
|
|
609 |
disconnect(itemView(), SIGNAL(scrollPositionChanged(const QPointF&)), item, SLOT(scrollBackground(const QPointF&)));
|
|
610 |
mFloatingItemsList.removeOne(item);
|
|
611 |
}
|
|
612 |
break;
|
|
613 |
}
|
|
614 |
}
|
|
615 |
|
45
|
616 |
|
55
|
617 |
/*!
|
57
|
618 |
\brief Handles tap event on overlapping area
|
|
619 |
Currently it leads to Agenda View - as described in UI spec
|
|
620 |
\a event qt gesture event
|
55
|
621 |
*/
|
45
|
622 |
void TouchEventAbsorber::gestureEvent(QGestureEvent *event)
|
|
623 |
{
|
|
624 |
QTapGesture *tapGesture = qobject_cast<QTapGesture*> (event->gesture(
|
|
625 |
Qt::TapGesture));
|
|
626 |
|
57
|
627 |
if (tapGesture && tapGesture->state() == Qt::GestureFinished) {
|
45
|
628 |
CalenDayView* dayView = static_cast<CalenDayView*>
|
|
629 |
(CalenDayUtils::instance()->mainWindow()->currentView());
|
|
630 |
|
|
631 |
dayView->changeView(ECalenAgendaView);
|
57
|
632 |
}
|
45
|
633 |
}
|
|
634 |
|
55
|
635 |
/*!
|
57
|
636 |
\brief Constructor
|
55
|
637 |
*/
|
57
|
638 |
TouchEventAbsorber::TouchEventAbsorber(QGraphicsItem *parent) :
|
|
639 |
HbWidget(parent)
|
45
|
640 |
{
|
|
641 |
#ifdef _DEBUG
|
|
642 |
setFlag(QGraphicsItem::ItemHasNoContents, false);
|
|
643 |
#endif
|
57
|
644 |
grabGesture(Qt::TapGesture);
|
45
|
645 |
}
|
|
646 |
|
55
|
647 |
|
|
648 |
/*!
|
|
649 |
\brief Destructor
|
|
650 |
|
|
651 |
Sets container initial geometry, creates hours area widgets.
|
|
652 |
*/
|
45
|
653 |
TouchEventAbsorber::~TouchEventAbsorber()
|
|
654 |
{
|
55
|
655 |
|
45
|
656 |
}
|
|
657 |
|
55
|
658 |
|
|
659 |
/*!
|
57
|
660 |
\brief Used for debugging purposes to see absorbers areas
|
|
661 |
Not active in release builds!
|
55
|
662 |
|
|
663 |
*/
|
45
|
664 |
#ifdef _DEBUG
|
57
|
665 |
void TouchEventAbsorber::paint(
|
|
666 |
QPainter *painter,
|
|
667 |
const QStyleOptionGraphicsItem *option,
|
|
668 |
QWidget *widget)
|
45
|
669 |
{
|
57
|
670 |
Q_UNUSED(option)
|
|
671 |
Q_UNUSED(widget)
|
|
672 |
|
|
673 |
painter->save();
|
|
674 |
QPen pen;
|
|
675 |
pen.setWidth(2);
|
|
676 |
pen.setColor(Qt::red);
|
|
677 |
painter->setPen(pen);
|
|
678 |
painter->drawRect(boundingRect());
|
|
679 |
painter->restore();
|
45
|
680 |
}
|
|
681 |
#endif
|
|
682 |
// End of File
|