calendarui/views/src/calenpreviewpane.cpp
changeset 51 0b38fc5b94c6
parent 45 b6db4fd4947b
child 55 2c54b51f39c4
equal deleted inserted replaced
46:ecd7b9840282 51:0b38fc5b94c6
    39 #include "calenservices.h"
    39 #include "calenservices.h"
    40 #include "calenservices.h"
    40 #include "calenservices.h"
    41 #include "calencommon.h"
    41 #include "calencommon.h"
    42 #include "calenpreviewpane.h"
    42 #include "calenpreviewpane.h"
    43 #include "calenmonthview.h"
    43 #include "calenmonthview.h"
       
    44 #include "OstTraceDefinitions.h"
       
    45 #ifdef OST_TRACE_COMPILER_IN_USE
       
    46 #include "calenpreviewpaneTraces.h"
       
    47 #endif
       
    48 
    44 
    49 
    45 // Macros
    50 // Macros
    46 #define TWO_SECONDS_TIMER 2000 // millseconds
    51 #define TWO_SECONDS_TIMER 2000 // millseconds
    47 #define SCROLLING_SPEED 10
    52 #define SCROLLING_SPEED 10
    48 #define MAX_PAN_DIRECTION_THRESHOLD 50
    53 #define MAX_PAN_DIRECTION_THRESHOLD 50
    55  */
    60  */
    56 CalenPreviewPane::CalenPreviewPane(MCalenServices& services, 
    61 CalenPreviewPane::CalenPreviewPane(MCalenServices& services, 
    57 							QGraphicsItem* parent)
    62 							QGraphicsItem* parent)
    58 	: HbScrollArea(parent),mServices(services)
    63 	: HbScrollArea(parent),mServices(services)
    59 {
    64 {
       
    65     OstTraceFunctionEntry0( CALENPREVIEWPANE_CALENPREVIEWPANE_ENTRY );
       
    66     
    60 	// Create the timer
    67 	// Create the timer
    61 	mTwoSecTimer = new QTimer(this);
    68 	mTwoSecTimer = new QTimer(this);
    62 	mScrollDirection = invalid;
    69 	mScrollDirection = invalid;
    63 	mIsNoEntriesAdded = true;
    70 	mIsNoEntriesAdded = true;
    64 	mIsGestureHandled = false;
    71 	mIsGestureHandled = false;
    70 	setVerticalScrollBarPolicy(HbScrollArea::ScrollBarAlwaysOff);
    77 	setVerticalScrollBarPolicy(HbScrollArea::ScrollBarAlwaysOff);
    71 	
    78 	
    72 	// Connect the scrollig finished signal
    79 	// Connect the scrollig finished signal
    73 	connect(this, SIGNAL(scrollingEnded()), this,
    80 	connect(this, SIGNAL(scrollingEnded()), this,
    74 				SLOT(scrollingFinished()));
    81 				SLOT(scrollingFinished()));
       
    82 	
       
    83 	OstTraceFunctionExit0( CALENPREVIEWPANE_CALENPREVIEWPANE_EXIT );
    75 }
    84 }
    76 
    85 
    77 /*!
    86 /*!
    78  Destructor
    87  Destructor
    79  */
    88  */
    80 CalenPreviewPane::~CalenPreviewPane()
    89 CalenPreviewPane::~CalenPreviewPane()
    81 {
    90 {
       
    91     OstTraceFunctionEntry0( DUP1_CALENPREVIEWPANE_CALENPREVIEWPANE_ENTRY );
       
    92     
       
    93     OstTraceFunctionExit0( DUP1_CALENPREVIEWPANE_CALENPREVIEWPANE_EXIT );
    82 }
    94 }
    83 
    95 
    84 /*!
    96 /*!
    85  Stores the "No Entries for today" label
    97  Stores the "No Entries for today" label
    86  */
    98  */
    87 void CalenPreviewPane::setNoEntriesLabel(HbLabel* label)
    99 void CalenPreviewPane::setNoEntriesLabel(HbLabel* label)
    88 {
   100 {
       
   101     OstTraceFunctionEntry0( CALENPREVIEWPANE_SETNOENTRIESLABEL_ENTRY );
       
   102     
    89 	mNoEntriesLabel = label;
   103 	mNoEntriesLabel = label;
       
   104 	
       
   105 	OstTraceFunctionExit0( CALENPREVIEWPANE_SETNOENTRIESLABEL_EXIT );
    90 }
   106 }
    91 
   107 
    92 /*!
   108 /*!
    93  Populates the preview with proper data
   109  Populates the preview with proper data
    94  */
   110  */
    95 void CalenPreviewPane::populateLabel(QDateTime date)
   111 void CalenPreviewPane::populateLabel(QDateTime date)
    96 {
   112 {
       
   113     OstTraceFunctionEntry0( CALENPREVIEWPANE_POPULATELABEL_ENTRY );
       
   114     
    97 	mScrollDirection = up;
   115 	mScrollDirection = up;
    98 	
   116 	
    99 	// Scroll contents to zero position before we display to the user
   117 	// Scroll contents to zero position before we display to the user
   100 	// if it was scrolling already or timer was running
   118 	// if it was scrolling already or timer was running
   101 	mNumOfScrolls = 0;
   119 	mNumOfScrolls = 0;
   114 	int instanceCount = mInstanceArray.count();
   132 	int instanceCount = mInstanceArray.count();
   115 	HbFontSpec font(HbFontSpec::Secondary);
   133 	HbFontSpec font(HbFontSpec::Secondary);
   116 	if (mIsNoEntriesAdded) {
   134 	if (mIsNoEntriesAdded) {
   117 		if (!instanceCount) {
   135 		if (!instanceCount) {
   118 		    mNoEntriesLabel->setVisible(true);
   136 		    mNoEntriesLabel->setVisible(true);
       
   137 		    OstTraceFunctionExit0( CALENPREVIEWPANE_POPULATELABEL_EXIT );
   119 		    return;
   138 		    return;
   120 		} else {
   139 		} else {
   121 			// Remove the no entries label
   140 			// Remove the no entries label
   122 			mNoEntriesLabel->setVisible(false);
   141 			mNoEntriesLabel->setVisible(false);
   123 		}
   142 		}
   158 			QString summary = mInstanceArray[i].summary();
   177 			QString summary = mInstanceArray[i].summary();
   159 			if(!summary.length()) {
   178 			if(!summary.length()) {
   160 				// No summary display "No subject"
   179 				// No summary display "No subject"
   161 				summary.append(hbTrId("txt_calendar_dblist_unnamed"));
   180 				summary.append(hbTrId("txt_calendar_dblist_unnamed"));
   162 			}
   181 			}
   163 			// Chcek the entry type, based on the type display time field in
   182 			// Check the entry type, based on the type display time field in
   164 			// preview pane.
   183 			// preview pane.
   165 			QString start;
   184 			QString start;
   166 			if(mInstanceArray[i].type() != AgendaEntry::TypeTodo ) {
   185 			if(mInstanceArray[i].type() != AgendaEntry::TypeTodo && 
       
   186 					mInstanceArray[i].type() != AgendaEntry::TypeAnniversary) {
   167 				QDateTime startTime = mInstanceArray[i].startTime();
   187 				QDateTime startTime = mInstanceArray[i].startTime();
   168 				HbExtendedLocale systemLocale =HbExtendedLocale::system();
   188 				HbExtendedLocale systemLocale =HbExtendedLocale::system();
   169 				start = systemLocale.format(startTime.time(), 
   189 				start = systemLocale.format(startTime.time(), 
   170 				                                    r_qtn_time_usual_with_zero);
   190 				                                    r_qtn_time_usual_with_zero);
   171 				start.append(EMPTYSTRING);	
   191 				start.append(EMPTYSTRING);	
   209 		// Add the no entries text to the preview pane
   229 		// Add the no entries text to the preview pane
   210 		mNoEntriesLabel->setVisible(true);
   230 		mNoEntriesLabel->setVisible(true);
   211 		mIsNoEntriesAdded = true;
   231 		mIsNoEntriesAdded = true;
   212 	}
   232 	}
   213 	layout->activate();
   233 	layout->activate();
       
   234 	
       
   235 	OstTraceFunctionExit0( DUP1_CALENPREVIEWPANE_POPULATELABEL_EXIT );
   214 }
   236 }
   215 
   237 
   216 /*!
   238 /*!
   217  Fetches the instance for a given day
   239  Fetches the instance for a given day
   218  */
   240  */
   219 void CalenPreviewPane::GetInstanceListL()
   241 void CalenPreviewPane::GetInstanceListL()
   220 {
   242 {
       
   243     OstTraceFunctionEntry0( CALENPREVIEWPANE_GETINSTANCELISTL_ENTRY );
       
   244     
   221 	mInstanceArray.clear();
   245 	mInstanceArray.clear();
   222 
   246 
   223 	// Find Meetings, Remainders, Anniversaries and Day Notes
   247 	// Find Meetings, Remainders, Anniversaries and Day Notes
   224 	QDateTime dayStart( CalenDateUtils::beginningOfDay( mDate ) );
   248 	QDateTime dayStart( CalenDateUtils::beginningOfDay( mDate ) );
   225 
   249 
   230 											AgendaUtil::IncludeEvents |
   254 											AgendaUtil::IncludeEvents |
   231 											AgendaUtil::IncludeIncompletedTodos | 
   255 											AgendaUtil::IncludeIncompletedTodos | 
   232 										AgendaUtil::IncludeReminders);
   256 										AgendaUtil::IncludeReminders);
   233 	mInstanceArray = mServices.agendaInterface()->
   257 	mInstanceArray = mServices.agendaInterface()->
   234 									createEntryIdListForDay(dayStart, filter);
   258 									createEntryIdListForDay(dayStart, filter);
       
   259 	
       
   260 	OstTraceFunctionExit0( CALENPREVIEWPANE_GETINSTANCELISTL_EXIT );
   235 }
   261 }
   236 
   262 
   237 /*!
   263 /*!
   238  Returns the date which this preview pane is representing
   264  Returns the date which this preview pane is representing
   239  */
   265  */
   240 QDateTime CalenPreviewPane::Date()
   266 QDateTime CalenPreviewPane::Date()
   241 {
   267 {
       
   268     OstTraceFunctionEntry0( CALENPREVIEWPANE_DATE_ENTRY );
       
   269     
       
   270 	OstTraceFunctionExit0( CALENPREVIEWPANE_DATE_EXIT );
   242 	return mDate;
   271 	return mDate;
   243 }
   272 }
   244 
   273 
   245 /*!
   274 /*!
   246  Starts the auto scroll on the preview pane
   275  Starts the auto scroll on the preview pane
   247  */
   276  */
   248 void CalenPreviewPane::startAutoScroll()
   277 void CalenPreviewPane::startAutoScroll()
   249 {
   278 {
       
   279     OstTraceFunctionEntry0( CALENPREVIEWPANE_STARTAUTOSCROLL_ENTRY );
       
   280     
   250 	if (mIsNoEntriesAdded) {
   281 	if (mIsNoEntriesAdded) {
   251 		scrollContentsTo(QPointF(0.0,0.0));
   282 		scrollContentsTo(QPointF(0.0,0.0));
       
   283 		OstTraceFunctionExit0( CALENPREVIEWPANE_STARTAUTOSCROLL_EXIT );
   252 		return;
   284 		return;
   253 	}
   285 	}
   254 
   286 
   255 	// Start the 2 seconds timer
   287 	// Start the 2 seconds timer
   256 	mTwoSecTimer->setSingleShot(true);
   288 	mTwoSecTimer->setSingleShot(true);
   257 	connect(mTwoSecTimer, SIGNAL(timeout()), this, SLOT(onTwoSecondsTimeout()));
   289 	connect(mTwoSecTimer, SIGNAL(timeout()), this, SLOT(onTwoSecondsTimeout()));
   258 	mTwoSecTimer->start(TWO_SECONDS_TIMER);
   290 	mTwoSecTimer->start(TWO_SECONDS_TIMER);
       
   291 	
       
   292 	OstTraceFunctionExit0( DUP1_CALENPREVIEWPANE_STARTAUTOSCROLL_EXIT );
   259 }
   293 }
   260 
   294 
   261 /*!
   295 /*!
   262  Slot to handle two seconds timer time out
   296  Slot to handle two seconds timer time out
   263  Starts the scrolling animation in required direction
   297  Starts the scrolling animation in required direction
   264  */
   298  */
   265 void CalenPreviewPane::onTwoSecondsTimeout()
   299 void CalenPreviewPane::onTwoSecondsTimeout()
   266 {
   300 {
       
   301     OstTraceFunctionEntry0( CALENPREVIEWPANE_ONTWOSECONDSTIMEOUT_ENTRY );
       
   302     
   267 	mTwoSecTimer->stop();
   303 	mTwoSecTimer->stop();
   268 	disconnect(mTwoSecTimer, SIGNAL(timeout()), 
   304 	disconnect(mTwoSecTimer, SIGNAL(timeout()), 
   269 										   this, SLOT(onTwoSecondsTimeout()));
   305 										   this, SLOT(onTwoSecondsTimeout()));
   270 	
   306 	
   271 	// Calculate the timer and the height difference of pane and its content
   307 	// Calculate the timer and the height difference of pane and its content
   290 		mNumOfScrolls++;
   326 		mNumOfScrolls++;
   291 		// Start scrolling downwards
   327 		// Start scrolling downwards
   292 		QPointF targetPos(0.0, 0.0);
   328 		QPointF targetPos(0.0, 0.0);
   293         scrollContentsTo(targetPos, mScrollDuration * 1000);
   329         scrollContentsTo(targetPos, mScrollDuration * 1000);
   294 	}
   330 	}
       
   331 	
       
   332 	OstTraceFunctionExit0( CALENPREVIEWPANE_ONTWOSECONDSTIMEOUT_EXIT );
   295 }
   333 }
   296 
   334 
   297 /*!
   335 /*!
   298  Slot to handle scrolling finished
   336  Slot to handle scrolling finished
   299  Restarts the two seconds timer
   337  Restarts the two seconds timer
   300  */
   338  */
   301 void CalenPreviewPane::scrollingFinished()
   339 void CalenPreviewPane::scrollingFinished()
   302 {
   340 {
       
   341     OstTraceFunctionEntry0( CALENPREVIEWPANE_SCROLLINGFINISHED_ENTRY );
       
   342     
   303 	// If we are here because of calling scrollContentsTo()
   343 	// If we are here because of calling scrollContentsTo()
   304 	if (!mNumOfScrolls) {
   344 	if (!mNumOfScrolls) {
       
   345 		OstTraceFunctionExit0( CALENPREVIEWPANE_SCROLLINGFINISHED_EXIT );
   305 		return;
   346 		return;
   306 	}
   347 	}
   307 	// Now start the two seconds timer again
   348 	// Now start the two seconds timer again
   308 	mTwoSecTimer->setSingleShot(true);
   349 	mTwoSecTimer->setSingleShot(true);
   309 	connect(mTwoSecTimer, SIGNAL(timeout()), this, SLOT(onTwoSecondsTimeout()));
   350 	connect(mTwoSecTimer, SIGNAL(timeout()), this, SLOT(onTwoSecondsTimeout()));
   310 	mTwoSecTimer->start(TWO_SECONDS_TIMER);
   351 	mTwoSecTimer->start(TWO_SECONDS_TIMER);
       
   352 	
       
   353 	OstTraceFunctionExit0( DUP1_CALENPREVIEWPANE_SCROLLINGFINISHED_EXIT );
   311 }
   354 }
   312 
   355 
   313 /*!
   356 /*!
   314     Function to listen for all gestures
   357     Function to listen for all gestures
   315  */
   358  */
   316 void CalenPreviewPane::gestureEvent(QGestureEvent *event)
   359 void CalenPreviewPane::gestureEvent(QGestureEvent *event)
   317 {
   360 {
       
   361     OstTraceFunctionEntry0( CALENPREVIEWPANE_GESTUREEVENT_ENTRY );
       
   362     
   318     if(HbPanGesture *gesture = qobject_cast<HbPanGesture *>(event->gesture(Qt::PanGesture))) {
   363     if(HbPanGesture *gesture = qobject_cast<HbPanGesture *>(event->gesture(Qt::PanGesture))) {
   319         if (gesture->state() == Qt::GestureStarted) {
   364         if (gesture->state() == Qt::GestureStarted) {
   320             // TODO: This work aroung till framework provides an api
   365             // TODO: This work aroung till framework provides an api
   321             // to know the direciton of the pan, until then we need
   366             // to know the direciton of the pan, until then we need
   322             // calculate the direction explicitly
   367             // calculate the direction explicitly
   334                     // left gesture
   379                     // left gesture
   335                     mView->handlePreviewPaneGesture(false);
   380                     mView->handlePreviewPaneGesture(false);
   336                     event->accept(Qt::PanGesture);
   381                     event->accept(Qt::PanGesture);
   337                 } else {
   382                 } else {
   338                     event->accept(Qt::PanGesture);
   383                     event->accept(Qt::PanGesture);
       
   384                     OstTraceFunctionExit0( CALENPREVIEWPANE_GESTUREEVENT_EXIT );
   339                     return;
   385                     return;
   340                 }
   386                 }
   341             } else if (abs(delta.y()) < MAX_PAN_DIRECTION_THRESHOLD) {
   387             } else if (abs(delta.y()) < MAX_PAN_DIRECTION_THRESHOLD) {
   342                if (delta.x() > MIN_PAN_DIRECTION_THRESHOLD) {
   388                if (delta.x() > MIN_PAN_DIRECTION_THRESHOLD) {
   343                    mIsGestureHandled = true;
   389                    mIsGestureHandled = true;
   349                    // left gesture
   395                    // left gesture
   350                    mView->handlePreviewPaneGesture(false);
   396                    mView->handlePreviewPaneGesture(false);
   351                    event->accept(Qt::PanGesture);
   397                    event->accept(Qt::PanGesture);
   352                }else {
   398                }else {
   353                    event->accept(Qt::PanGesture);
   399                    event->accept(Qt::PanGesture);
       
   400                    OstTraceFunctionExit0( DUP1_CALENPREVIEWPANE_GESTUREEVENT_EXIT );
   354                    return;
   401                    return;
   355                }
   402                }
   356             }
   403             }
   357         }
   404         }
   358     } else if(HbTapGesture *gesture = qobject_cast<HbTapGesture *>(event->gesture(Qt::TapGesture))) {
   405     } else if(HbTapGesture *gesture = qobject_cast<HbTapGesture *>(event->gesture(Qt::TapGesture))) {
   362                 mServices.IssueCommandL(ECalenAgendaView);
   409                 mServices.IssueCommandL(ECalenAgendaView);
   363                 event->accept(Qt::TapGesture);
   410                 event->accept(Qt::TapGesture);
   364             }
   411             }
   365         }
   412         }
   366     }
   413     }
       
   414     
       
   415     OstTraceFunctionExit0( DUP2_CALENPREVIEWPANE_GESTUREEVENT_EXIT );
   367 }
   416 }
   368 
   417 
   369 /*!
   418 /*!
   370  Set monthview pointer
   419  Set monthview pointer
   371  */
   420  */
   372 void CalenPreviewPane::setView(CalenMonthView* view)
   421 void CalenPreviewPane::setView(CalenMonthView* view)
   373 {
   422 {
       
   423     OstTraceFunctionEntry0( CALENPREVIEWPANE_SETVIEW_ENTRY );
       
   424     
   374 	mView = view;
   425 	mView = view;
       
   426 	
       
   427 	OstTraceFunctionExit0( CALENPREVIEWPANE_SETVIEW_EXIT );
   375 }
   428 }
   376 
   429 
   377 /*!
   430 /*!
   378  Stops the auto scrolling
   431  Stops the auto scrolling
   379  */
   432  */
   380 void CalenPreviewPane::stopScrolling()
   433 void CalenPreviewPane::stopScrolling()
   381 {
   434 {
       
   435     OstTraceFunctionEntry0( CALENPREVIEWPANE_STOPSCROLLING_ENTRY );
       
   436     
   382 	if (isScrolling() || mTwoSecTimer->isActive()) {
   437 	if (isScrolling() || mTwoSecTimer->isActive()) {
   383 		scrollContentsTo(QPointF(0.0,0.0));
   438 		scrollContentsTo(QPointF(0.0,0.0));
   384 		
   439 		
   385 		// Call pan gesture with zero delta just to stop the scfrolling 
   440 		// Call pan gesture with zero delta just to stop the scfrolling 
   386 		HbScrollArea::panGesture(QPointF(0.0,0.0));
   441 		HbScrollArea::panGesture(QPointF(0.0,0.0));
   387 		mTwoSecTimer->stop();
   442 		mTwoSecTimer->stop();
   388 	}
   443 	}
       
   444 	
       
   445 	OstTraceFunctionExit0( CALENPREVIEWPANE_STOPSCROLLING_EXIT );
   389 }
   446 }
   390 
   447 
   391 // End of file  --Don't remove this.
   448 // End of file  --Don't remove this.