45
|
1 |
/*
|
70
|
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 control of calendar
|
|
15 |
*
|
|
16 |
*/
|
45
|
17 |
|
|
18 |
//System includes
|
|
19 |
#include <QGesture>
|
|
20 |
#include <QGraphicsLinearLayout>
|
63
|
21 |
#include <HbAbstractViewItem>
|
|
22 |
#include <HbInstance>
|
|
23 |
#include <HbAction>
|
45
|
24 |
|
|
25 |
//User includes
|
|
26 |
#include "calendayitemview.h"
|
|
27 |
#include "calendayutils.h"
|
|
28 |
#include "calendaycontainer.h"
|
75
|
29 |
#include "calendayitemview.h"
|
45
|
30 |
#include "calendayinfo.h"
|
|
31 |
#include "calendaymodel.h"
|
|
32 |
#include "calenservices.h"
|
|
33 |
#include "calencontext.h"
|
57
|
34 |
#include "calenagendautils.h"
|
45
|
35 |
#include "CalenUid.h"
|
|
36 |
|
70
|
37 |
/*!
|
|
38 |
\brief Constructor
|
|
39 |
*/
|
|
40 |
CalenDayItemView::CalenDayItemView(
|
|
41 |
MCalenServices &services,
|
|
42 |
HbModelIterator *iterator,
|
|
43 |
QGraphicsItem *parent) :
|
|
44 |
HbAbstractItemView(mContainer = new CalenDayContainer(), iterator, parent),
|
|
45 |
mServices(services)
|
|
46 |
{
|
|
47 |
mInfo = new CalenDayInfo(CalenDayInfo::EFour);
|
|
48 |
mContainer->setDayInfo(mInfo);
|
45
|
49 |
|
|
50 |
//setup Selection Model
|
|
51 |
QItemSelectionModel* selModel = new QItemSelectionModel(this->model());
|
70
|
52 |
if (selModel) {
|
|
53 |
setSelectionMode(HbAbstractItemView::SingleSelection);
|
|
54 |
setSelectionModel(selModel);
|
45
|
55 |
}
|
70
|
56 |
|
45
|
57 |
setScrollDirections(Qt::Vertical);
|
|
58 |
setScrollingStyle(HbScrollArea::PanWithFollowOn);
|
|
59 |
setVerticalScrollBarPolicy(HbScrollArea::ScrollBarAlwaysOff);
|
70
|
60 |
|
45
|
61 |
//TODO: KG: Animate item pressed?! HbAbstractItemView::TouchDown
|
70
|
62 |
setEnabledAnimations(HbAbstractItemView::None);
|
|
63 |
|
45
|
64 |
// Get the width of content and fix its size
|
|
65 |
qreal contentWidth = CalenDayUtils::instance()->contentWidth();
|
|
66 |
setMinimumWidth(contentWidth);
|
|
67 |
setMaximumWidth(contentWidth);
|
70
|
68 |
|
45
|
69 |
setupSlots();
|
|
70 |
setupContextMenu();
|
|
71 |
}
|
|
72 |
|
57
|
73 |
/*!
|
70
|
74 |
\brief Destructor
|
|
75 |
*/
|
45
|
76 |
CalenDayItemView::~CalenDayItemView()
|
|
77 |
{
|
|
78 |
delete mInfo;
|
|
79 |
}
|
|
80 |
|
57
|
81 |
/*!
|
70
|
82 |
\brief Scrolls to given index
|
|
83 |
*/
|
|
84 |
void CalenDayItemView::scrollTo(
|
|
85 |
const QModelIndex &index,
|
|
86 |
HbAbstractItemView::ScrollHint hint)
|
45
|
87 |
{
|
|
88 |
HbAbstractItemView::scrollTo(index, hint);
|
|
89 |
}
|
|
90 |
|
57
|
91 |
/*!
|
75
|
92 |
\brief Gets context menu of ItemView
|
|
93 |
|
|
94 |
\return Context menu
|
|
95 |
*/
|
|
96 |
HbMenu *CalenDayItemView::contextMenu() const
|
|
97 |
{
|
|
98 |
return mContextMenu;
|
|
99 |
}
|
|
100 |
|
|
101 |
/*!
|
|
102 |
\brief Sets context menu of ItemView
|
|
103 |
|
|
104 |
\param contextMenu Context menu
|
|
105 |
*/
|
|
106 |
void CalenDayItemView::setContextMenu(HbMenu *contextMenu)
|
|
107 |
{
|
|
108 |
mContextMenu = contextMenu;
|
|
109 |
}
|
|
110 |
|
|
111 |
/*!
|
70
|
112 |
\brief Currently empty implementation.
|
|
113 |
*/
|
45
|
114 |
void CalenDayItemView::reset()
|
|
115 |
{
|
57
|
116 |
|
45
|
117 |
}
|
|
118 |
|
57
|
119 |
/*!
|
70
|
120 |
\brief Handles signal that is emitted when reset() is called, before the model's
|
|
121 |
internal state (e.g. persistent model indexes) has been invalidated.
|
|
122 |
*/
|
45
|
123 |
void CalenDayItemView::modelAboutToBeReset()
|
|
124 |
{
|
70
|
125 |
|
45
|
126 |
}
|
|
127 |
|
57
|
128 |
/*!
|
70
|
129 |
\brief Handles signal that is emitted when reset() is called, before the model's
|
|
130 |
internal state (e.g. persistent model indexes) has been invalidated.
|
|
131 |
*/
|
45
|
132 |
void CalenDayItemView::modelReset()
|
|
133 |
{
|
70
|
134 |
if (!mInfo) {
|
45
|
135 |
return;
|
|
136 |
}
|
|
137 |
//reset day info
|
|
138 |
mInfo->Reset();
|
55
|
139 |
|
45
|
140 |
CalenDayModel* model(0);
|
70
|
141 |
model = static_cast<CalenDayModel*> (this->model());
|
|
142 |
if (!model) {
|
45
|
143 |
return;
|
|
144 |
}
|
70
|
145 |
|
55
|
146 |
mContainer->setDate(model->modelDate().date());
|
70
|
147 |
int rowCount = model->rowCount();
|
|
148 |
SCalenApptInfo apptInfo;
|
|
149 |
for (int row = 0; row < rowCount; row++) {
|
|
150 |
QModelIndex idx = model->index(row, 0);
|
|
151 |
QVariant variant = idx.data(CalenDayEntry);
|
|
152 |
AgendaEntry entry = variant.value<AgendaEntry> ();
|
45
|
153 |
apptInfo.iIndex = idx;
|
70
|
154 |
|
45
|
155 |
QDateTime start;
|
|
156 |
QDateTime end;
|
70
|
157 |
QDateTime currDate(model->modelDate());
|
|
158 |
CalenDayUtils::instance()->getEventValidStartEndTime(start, end, entry,
|
|
159 |
currDate);
|
45
|
160 |
|
|
161 |
apptInfo.iStartTime = start;
|
|
162 |
apptInfo.iEndTime = end;
|
70
|
163 |
|
45
|
164 |
TCalenInstanceId id = TCalenInstanceId::nullInstanceId();//index.row() - temporary ID
|
|
165 |
id.mEntryLocalUid = row;
|
70
|
166 |
id.mInstanceTime = apptInfo.iStartTime;
|
45
|
167 |
apptInfo.iId = id;
|
|
168 |
apptInfo.iColor = 0xffff;
|
70
|
169 |
|
|
170 |
if (entry.isTimedEntry() && !CalenAgendaUtils::isAlldayEvent(entry)) {
|
45
|
171 |
apptInfo.iAllDay = false;
|
70
|
172 |
mInfo->InsertTimedEvent(apptInfo);
|
|
173 |
}
|
|
174 |
else
|
|
175 |
if (CalenAgendaUtils::isAlldayEvent(entry)) //all-day event
|
|
176 |
{
|
|
177 |
apptInfo.iAllDay = true;
|
|
178 |
mInfo->InsertAlldayEvent(apptInfo);
|
|
179 |
}
|
45
|
180 |
}
|
70
|
181 |
|
45
|
182 |
HbAbstractItemView::reset();
|
|
183 |
}
|
|
184 |
|
57
|
185 |
/*!
|
70
|
186 |
\brief Scrolls view vertically to the given position.
|
|
187 |
|
|
188 |
\param newPosition position to scroll to.
|
|
189 |
*/
|
|
190 |
void CalenDayItemView::scrollVertically(const QPointF &newPosition)
|
45
|
191 |
{
|
|
192 |
QPointF currentPos = contentWidget()->pos();
|
|
193 |
if (abs(newPosition.y()) != abs(currentPos.y())) {
|
|
194 |
currentPos.setY(newPosition.y());
|
|
195 |
scrollContentsTo(currentPos, 0);
|
|
196 |
}
|
|
197 |
}
|
|
198 |
|
57
|
199 |
/*!
|
70
|
200 |
\brief This function is called when a touch press event is received
|
|
201 |
within Abstract view item that is representing index.
|
|
202 |
Currently it does nothing.
|
|
203 |
*/
|
|
204 |
void CalenDayItemView::itemPressed(const QModelIndex &index)
|
45
|
205 |
{
|
70
|
206 |
Q_UNUSED( index )
|
45
|
207 |
}
|
|
208 |
|
57
|
209 |
/*!
|
70
|
210 |
\brief This function is called when a touch release event is received
|
|
211 |
within Abstract view item that is representing index.
|
|
212 |
Currently it does nothing.
|
|
213 |
*/
|
|
214 |
void CalenDayItemView::itemReleased(const QModelIndex &index)
|
45
|
215 |
{
|
70
|
216 |
Q_UNUSED( index )
|
45
|
217 |
}
|
|
218 |
|
57
|
219 |
/*!
|
70
|
220 |
\brief This function is called when the item specified by index is activated by the user.
|
|
221 |
|
|
222 |
\param position Not used.
|
|
223 |
*/
|
|
224 |
void CalenDayItemView::itemActivated(const QModelIndex &index)
|
45
|
225 |
{
|
70
|
226 |
QItemSelectionModel* selModel(selectionModel());
|
|
227 |
if (index.isValid() && selModel) {
|
|
228 |
selModel->select(index, QItemSelectionModel::Current
|
|
229 |
| QItemSelectionModel::Select);
|
45
|
230 |
openSelectedItem();
|
|
231 |
}
|
|
232 |
}
|
|
233 |
|
57
|
234 |
/*!
|
70
|
235 |
\brief This function is called when long press event is received within Abstract view item viewItem.
|
57
|
236 |
|
70
|
237 |
\param item Pointer to pressed item.
|
|
238 |
\param coord Position where item was pressed.
|
|
239 |
*/
|
45
|
240 |
void CalenDayItemView::itemLongPressed(HbAbstractViewItem* item, QPointF coords)
|
|
241 |
{
|
|
242 |
QModelIndex index = item->modelIndex();
|
70
|
243 |
QItemSelectionModel* selModel(selectionModel());
|
|
244 |
if (index.isValid() && selModel && mContextMenu) {
|
|
245 |
selModel->select(index, QItemSelectionModel::Current
|
|
246 |
| QItemSelectionModel::Select);
|
|
247 |
mContextMenu->setPreferredPos(coords, HbPopup::BottomRightCorner);
|
45
|
248 |
mContextMenu->open();
|
|
249 |
}
|
|
250 |
}
|
|
251 |
|
57
|
252 |
/*!
|
70
|
253 |
\brief Slot which is called whenever the orientation of the device changes.
|
57
|
254 |
|
70
|
255 |
\param orientation New orientation.
|
|
256 |
*/
|
|
257 |
void CalenDayItemView::orientationChanged(Qt::Orientation orientation)
|
45
|
258 |
{
|
|
259 |
// Update the width of screen
|
|
260 |
qreal contentWidth = CalenDayUtils::instance()->contentWidth();
|
|
261 |
setMinimumWidth(contentWidth);
|
|
262 |
setMaximumWidth(contentWidth);
|
70
|
263 |
if (mContainer) {
|
|
264 |
mContainer->orientationChanged(orientation);
|
45
|
265 |
}
|
|
266 |
}
|
|
267 |
|
57
|
268 |
/*!
|
70
|
269 |
\brief Opens currently selected model item.
|
|
270 |
*/
|
45
|
271 |
void CalenDayItemView::openSelectedItem()
|
|
272 |
{
|
70
|
273 |
issueCommandOnSelectedItem(ECalenEventView);
|
45
|
274 |
}
|
|
275 |
|
57
|
276 |
/*!
|
70
|
277 |
\brief Edits currently selected model item.
|
|
278 |
*/
|
45
|
279 |
void CalenDayItemView::editSelectedItem()
|
|
280 |
{
|
70
|
281 |
issueCommandOnSelectedItem(ECalenEditCurrentEntry);
|
45
|
282 |
}
|
|
283 |
|
57
|
284 |
/*!
|
70
|
285 |
\brief Deletes currently selected model item.
|
|
286 |
*/
|
45
|
287 |
void CalenDayItemView::deleteSelectedItem()
|
|
288 |
{
|
70
|
289 |
issueCommandOnSelectedItem(ECalenDeleteCurrentEntry);
|
45
|
290 |
}
|
|
291 |
|
57
|
292 |
/*!
|
70
|
293 |
\brief Connects item view's slots.
|
|
294 |
*/
|
45
|
295 |
void CalenDayItemView::setupSlots()
|
|
296 |
{
|
|
297 |
// Connect to main window's orientationChanged signal to handle orientation
|
|
298 |
// switching
|
70
|
299 |
QObject::connect(CalenDayUtils::instance()->mainWindow(),
|
45
|
300 |
SIGNAL(orientationChanged(Qt::Orientation)), this,
|
|
301 |
SLOT(orientationChanged(Qt::Orientation)));
|
|
302 |
|
|
303 |
// Connect with model signals
|
|
304 |
if (this->model()) {
|
|
305 |
QObject::connect(this->model(), SIGNAL(modelAboutToBeReset()), this,
|
|
306 |
SLOT(modelAboutToBeReset()));
|
|
307 |
QObject::connect(this->model(), SIGNAL(modelReset()), this,
|
|
308 |
SLOT(modelReset()));
|
|
309 |
}
|
|
310 |
if (mContainer) {
|
|
311 |
// Connect with base class to enable handling item press by model index
|
|
312 |
QObject::connect(mContainer, SIGNAL(itemCreated(HbAbstractViewItem *)),
|
|
313 |
this, SLOT(itemCreated(HbAbstractViewItem*)));
|
|
314 |
}
|
70
|
315 |
QObject::connect(this, SIGNAL(pressed(const QModelIndex&)), this,
|
|
316 |
SLOT(itemPressed(const QModelIndex&)));
|
|
317 |
QObject::connect(this, SIGNAL(released(const QModelIndex&)), this,
|
|
318 |
SLOT(itemReleased(const QModelIndex&)));
|
|
319 |
QObject::connect(this, SIGNAL(activated(const QModelIndex&)), this,
|
|
320 |
SLOT(itemActivated(const QModelIndex&)));
|
45
|
321 |
QObject::connect(this, SIGNAL(longPressed(HbAbstractViewItem*, QPointF)),
|
|
322 |
this, SLOT(itemLongPressed(HbAbstractViewItem*, QPointF)));
|
|
323 |
}
|
|
324 |
|
57
|
325 |
/*!
|
70
|
326 |
\brief Creates context menu.
|
|
327 |
*/
|
45
|
328 |
void CalenDayItemView::setupContextMenu()
|
|
329 |
{
|
|
330 |
mContextMenu = new HbMenu();
|
70
|
331 |
HbAction *openAction = mContextMenu->addAction(hbTrId(
|
|
332 |
"txt_common_menu_open"));
|
45
|
333 |
if (openAction) {
|
|
334 |
connect(openAction, SIGNAL(triggered()), this, SLOT(openSelectedItem()));
|
|
335 |
}
|
70
|
336 |
HbAction *editAction = mContextMenu->addAction(hbTrId(
|
|
337 |
"txt_common_menu_edit"));
|
45
|
338 |
if (editAction) {
|
|
339 |
connect(editAction, SIGNAL(triggered()), this, SLOT(editSelectedItem()));
|
|
340 |
}
|
70
|
341 |
HbAction *deleteAction = mContextMenu->addAction(hbTrId(
|
|
342 |
"txt_common_menu_delete"));
|
45
|
343 |
if (deleteAction) {
|
|
344 |
connect(deleteAction, SIGNAL(triggered()), this,
|
|
345 |
SLOT(deleteSelectedItem()));
|
|
346 |
}
|
|
347 |
}
|
|
348 |
|
57
|
349 |
/*!
|
70
|
350 |
\brief Sets context to currently selected model item and issues calendar command.
|
|
351 |
|
|
352 |
\param command A command to be issued.
|
|
353 |
*/
|
|
354 |
bool CalenDayItemView::issueCommandOnSelectedItem(int command)
|
45
|
355 |
{
|
|
356 |
bool retVal(false);
|
|
357 |
QItemSelectionModel* selModel(selectionModel());
|
70
|
358 |
if (!selModel) {
|
45
|
359 |
return retVal;
|
|
360 |
}
|
70
|
361 |
QModelIndex index(selModel->currentIndex());
|
|
362 |
if (index.isValid()) {
|
45
|
363 |
retVal = true;
|
70
|
364 |
QVariant variant = index.data(CalenDayEntry);
|
|
365 |
AgendaEntry entry = variant.value<AgendaEntry> ();
|
45
|
366 |
QDateTime start;
|
|
367 |
QDateTime end;
|
|
368 |
CalenDayModel* model(0);
|
70
|
369 |
model = static_cast<CalenDayModel*> (this->model());
|
|
370 |
QDateTime currDate(model->modelDate());
|
|
371 |
CalenDayUtils::instance()->getEventValidStartEndTime(start, end, entry,
|
|
372 |
currDate);
|
45
|
373 |
TRAPD(error,
|
70
|
374 |
mServices.Context().setFocusDateAndTimeAndInstance(start,
|
|
375 |
TCalenInstanceId::create(entry));
|
|
376 |
mServices.IssueCommandL( command );
|
|
377 |
);
|
|
378 |
if (error) {
|
45
|
379 |
retVal = false;
|
|
380 |
}
|
|
381 |
clearSelectionInModel();
|
|
382 |
}
|
|
383 |
return retVal;
|
|
384 |
}
|
|
385 |
|
57
|
386 |
/*!
|
70
|
387 |
\brief Clears current selection in Selection Model.
|
|
388 |
*/
|
45
|
389 |
void CalenDayItemView::clearSelectionInModel()
|
|
390 |
{
|
|
391 |
QItemSelectionModel* selModel(selectionModel());
|
|
392 |
if (selModel) {
|
|
393 |
selModel->clear();
|
|
394 |
}
|
|
395 |
}
|
|
396 |
|
|
397 |
// End of File
|