25 #include <hbmainwindow.h> |
25 #include <hbmainwindow.h> |
26 #include <hbframeitem.h> |
26 #include <hbframeitem.h> |
27 #include <hbframedrawer.h> |
27 #include <hbframedrawer.h> |
28 #include <hbfontspec.h> |
28 #include <hbfontspec.h> |
29 #include <hbcolorscheme.h> |
29 #include <hbcolorscheme.h> |
|
30 #include <hbtapgesture.h> |
|
31 #include <hbpangesture.h> |
30 #include <agendautil.h> |
32 #include <agendautil.h> |
31 #include <agendaentry.h> |
33 #include <agendaentry.h> |
32 |
34 |
33 //user includes |
35 //user includes |
34 #include "calenagendautils.h" |
36 #include "calenagendautils.h" |
57 mTwoSecTimer = new QTimer(this); |
61 mTwoSecTimer = new QTimer(this); |
58 mScrollDirection = invalid; |
62 mScrollDirection = invalid; |
59 mIsNoEntriesAdded = true; |
63 mIsNoEntriesAdded = true; |
60 mIsGestureHandled = false; |
64 mIsGestureHandled = false; |
61 mNoEntriesLabel = 0; |
65 mNoEntriesLabel = 0; |
|
66 mHtDiff = 0.0; |
|
67 mScrollDuration = 0; |
62 setAcceptDrops(true); |
68 setAcceptDrops(true); |
63 setScrollDirections(Qt::Vertical); |
69 setScrollDirections(Qt::Vertical); |
64 setVerticalScrollBarPolicy(HbScrollArea::ScrollBarAlwaysOff); |
70 setVerticalScrollBarPolicy(HbScrollArea::ScrollBarAlwaysOff); |
65 |
71 |
66 // Connect the scrollig finished signal |
72 // Connect the scrollig finished signal |
152 QString summary = mInstanceArray[i].summary(); |
158 QString summary = mInstanceArray[i].summary(); |
153 if(!summary.length()) { |
159 if(!summary.length()) { |
154 // No summary display "No subject" |
160 // No summary display "No subject" |
155 summary.append(hbTrId("txt_calendar_dblist_unnamed")); |
161 summary.append(hbTrId("txt_calendar_dblist_unnamed")); |
156 } |
162 } |
157 QDateTime startTime = mInstanceArray[i].startTime(); |
163 // Chcek the entry type, based on the type display time field in |
158 HbExtendedLocale systemLocale =HbExtendedLocale::system(); |
164 // preview pane. |
159 QString start = systemLocale.format(startTime.time(), |
165 QString start; |
160 r_qtn_time_usual_with_zero); |
166 if(mInstanceArray[i].type() != AgendaEntry::TypeTodo ) { |
161 start.append(EMPTYSTRING); |
167 QDateTime startTime = mInstanceArray[i].startTime(); |
|
168 HbExtendedLocale systemLocale =HbExtendedLocale::system(); |
|
169 start = systemLocale.format(startTime.time(), |
|
170 r_qtn_time_usual_with_zero); |
|
171 start.append(EMPTYSTRING); |
|
172 } |
162 // Append summary to start time |
173 // Append summary to start time |
163 QString text = start.append(summary); |
174 QString text = start.append(summary); |
164 label->setPlainText(text); |
175 label->setPlainText(text); |
165 layout->setStretchFactor(label,0); |
176 layout->setStretchFactor(label,0); |
166 } |
177 } |
236 */ |
247 */ |
237 void CalenPreviewPane::startAutoScroll() |
248 void CalenPreviewPane::startAutoScroll() |
238 { |
249 { |
239 if (mIsNoEntriesAdded) { |
250 if (mIsNoEntriesAdded) { |
240 scrollContentsTo(QPointF(0.0,0.0)); |
251 scrollContentsTo(QPointF(0.0,0.0)); |
241 |
|
242 // Call pan gesture with zero delta just to stop the scfrolling |
|
243 HbScrollArea::panGesture(QPointF(0.0,0.0)); |
|
244 return; |
252 return; |
245 } |
253 } |
246 |
254 |
247 // Start the 2 seconds timer |
255 // Start the 2 seconds timer |
248 mTwoSecTimer->setSingleShot(true); |
256 mTwoSecTimer->setSingleShot(true); |
257 void CalenPreviewPane::onTwoSecondsTimeout() |
265 void CalenPreviewPane::onTwoSecondsTimeout() |
258 { |
266 { |
259 mTwoSecTimer->stop(); |
267 mTwoSecTimer->stop(); |
260 disconnect(mTwoSecTimer, SIGNAL(timeout()), |
268 disconnect(mTwoSecTimer, SIGNAL(timeout()), |
261 this, SLOT(onTwoSecondsTimeout())); |
269 this, SLOT(onTwoSecondsTimeout())); |
262 // Start the scrolling in the proper direction |
270 |
|
271 // Calculate the timer and the height difference of pane and its content |
|
272 if (!mScrollDuration) { |
|
273 qreal contentHeight = contentWidget()->size().height(); |
|
274 qreal paneHeight = size().height(); |
|
275 mHtDiff = contentHeight - paneHeight; |
|
276 if (mHtDiff > 0) { // content is more than widget height, we need to scroll |
|
277 mScrollDuration = mHtDiff / SCROLLING_SPEED; |
|
278 } |
|
279 } |
|
280 |
|
281 // Start the scrolling in the proper direction |
263 if (mScrollDirection == up) { |
282 if (mScrollDirection == up) { |
264 // Start scrolling upwards |
283 // Start scrolling upwards |
265 mScrollDirection = down; |
284 mScrollDirection = down; |
266 mNumOfScrolls++; |
285 mNumOfScrolls++; |
267 upGesture(SCROLLING_SPEED); |
286 QPointF targetPos(0.0, -mHtDiff); |
|
287 scrollContentsTo(-targetPos, mScrollDuration * 1000); |
268 } else if (mScrollDirection == down) { |
288 } else if (mScrollDirection == down) { |
269 mScrollDirection = up; |
289 mScrollDirection = up; |
270 mNumOfScrolls++; |
290 mNumOfScrolls++; |
271 // Start scrolling downwards |
291 // Start scrolling downwards |
272 downGesture(SCROLLING_SPEED); |
292 QPointF targetPos(0.0, 0.0); |
|
293 scrollContentsTo(targetPos, mScrollDuration * 1000); |
273 } |
294 } |
274 } |
295 } |
275 |
296 |
276 /*! |
297 /*! |
277 Slot to handle scrolling finished |
298 Slot to handle scrolling finished |
288 connect(mTwoSecTimer, SIGNAL(timeout()), this, SLOT(onTwoSecondsTimeout())); |
309 connect(mTwoSecTimer, SIGNAL(timeout()), this, SLOT(onTwoSecondsTimeout())); |
289 mTwoSecTimer->start(TWO_SECONDS_TIMER); |
310 mTwoSecTimer->start(TWO_SECONDS_TIMER); |
290 } |
311 } |
291 |
312 |
292 /*! |
313 /*! |
293 Function to listen mouse press events |
314 Function to listen for all gestures |
294 */ |
315 */ |
295 void CalenPreviewPane::mousePressEvent(QGraphicsSceneMouseEvent* event) |
316 void CalenPreviewPane::gestureEvent(QGestureEvent *event) |
296 { |
317 { |
297 mIsGestureHandled = false; |
318 if(HbPanGesture *gesture = qobject_cast<HbPanGesture *>(event->gesture(Qt::PanGesture))) { |
298 mPressedPos = event->pos(); |
319 if (gesture->state() == Qt::GestureStarted) { |
299 event->accept(); |
320 // TODO: This work aroung till framework provides an api |
300 } |
321 // to know the direciton of the pan, until then we need |
301 |
322 // calculate the direction explicitly |
302 /*! |
323 // Get to know the direction of the gesture |
303 Function to listen mouse release events |
324 QPointF delta = gesture->delta(); |
304 */ |
325 if (abs(delta.y()) > MAX_PAN_DIRECTION_THRESHOLD) { |
305 void CalenPreviewPane::mouseReleaseEvent(QGraphicsSceneMouseEvent* event) |
326 // Now see if y coord diff has crossed threshold |
306 { |
327 if (delta.x() > MAX_PAN_DIRECTION_THRESHOLD) { |
307 qreal posDiff = mPressedPos.x()-event->pos().x(); |
328 mIsGestureHandled = true; |
308 if (abs(posDiff) < 50 && !mIsGestureHandled) { |
329 // right gesture |
309 // Preview pane tapped |
330 mView->handlePreviewPaneGesture(true); |
310 mServices.IssueCommandL(ECalenDayView); |
331 event->accept(Qt::PanGesture); |
311 } |
332 } else if (delta.x() < -MAX_PAN_DIRECTION_THRESHOLD){ |
312 event->accept(); |
333 mIsGestureHandled = true; |
313 } |
334 // left gesture |
314 |
335 mView->handlePreviewPaneGesture(false); |
315 /*! |
336 event->accept(Qt::PanGesture); |
316 Function to listen mouse move events |
337 } else { |
317 */ |
338 event->accept(Qt::PanGesture); |
318 void CalenPreviewPane::mouseMoveEvent(QGraphicsSceneMouseEvent* event) |
339 return; |
319 { |
340 } |
320 qreal posDiff = mPressedPos.x()-event->pos().x(); |
341 } else if (abs(delta.y()) < MAX_PAN_DIRECTION_THRESHOLD) { |
321 if (posDiff < -50) { |
342 if (delta.x() > MIN_PAN_DIRECTION_THRESHOLD) { |
322 mIsGestureHandled = true; |
343 mIsGestureHandled = true; |
323 // right gesture |
344 // right gesture |
324 mView->handlePreviewPaneGesture(true); |
345 mView->handlePreviewPaneGesture(true); |
325 } else if (posDiff > 50) { |
346 event->accept(Qt::PanGesture); |
326 mIsGestureHandled = true; |
347 } else if (delta.x() < -MIN_PAN_DIRECTION_THRESHOLD){ |
327 // left gesture |
348 mIsGestureHandled = true; |
328 mView->handlePreviewPaneGesture(false); |
349 // left gesture |
329 } |
350 mView->handlePreviewPaneGesture(false); |
330 event->accept(); |
351 event->accept(Qt::PanGesture); |
|
352 }else { |
|
353 event->accept(Qt::PanGesture); |
|
354 return; |
|
355 } |
|
356 } |
|
357 } |
|
358 } else if(HbTapGesture *gesture = qobject_cast<HbTapGesture *>(event->gesture(Qt::TapGesture))) { |
|
359 if (gesture->state() == Qt::GestureFinished) { |
|
360 if (gesture->tapStyleHint() == HbTapGesture::Tap) { |
|
361 // Preview pane tapped |
|
362 mServices.IssueCommandL(ECalenAgendaView); |
|
363 event->accept(Qt::TapGesture); |
|
364 } |
|
365 } |
|
366 } |
331 } |
367 } |
332 |
368 |
333 /*! |
369 /*! |
334 Set monthview pointer |
370 Set monthview pointer |
335 */ |
371 */ |