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