calendarui/views/src/calenpreviewpane.cpp
changeset 68 a5a1242fd2e8
parent 58 ef813d54df51
child 77 b0711afde476
equal deleted inserted replaced
58:ef813d54df51 68:a5a1242fd2e8
    19 // System includes
    19 // System includes
    20 #include <QtGui>
    20 #include <QtGui>
    21 #include <qfont.h>
    21 #include <qfont.h>
    22 #include <qicon.h>
    22 #include <qicon.h>
    23 #include <qpainter.h>
    23 #include <qpainter.h>
       
    24 #include <qevent.h>
    24 #include <hblabel.h>
    25 #include <hblabel.h>
    25 #include <hbmainwindow.h>
    26 #include <hbmainwindow.h>
    26 #include <hbframeitem.h>
    27 #include <hbframeitem.h>
    27 #include <hbframedrawer.h>
    28 #include <hbframedrawer.h>
    28 #include <hbfontspec.h>
    29 #include <hbfontspec.h>
    72 	mIsNoEntriesAdded = true;
    73 	mIsNoEntriesAdded = true;
    73 	mIsGestureHandled = false;
    74 	mIsGestureHandled = false;
    74 	mNoEntriesLabel = 0;
    75 	mNoEntriesLabel = 0;
    75 	mHtDiff = 0.0;
    76 	mHtDiff = 0.0;
    76 	mScrollDuration = 0;
    77 	mScrollDuration = 0;
       
    78 	mPreviewTextColor = HbColorScheme::color("qtc_cal_day_preview_text");
       
    79 	
    77 	setAcceptDrops(true);
    80 	setAcceptDrops(true);
    78 	setScrollDirections(Qt::Vertical);
    81 	setScrollDirections(Qt::Vertical);
    79 	setVerticalScrollBarPolicy(HbScrollArea::ScrollBarAlwaysOff);
    82 	setVerticalScrollBarPolicy(HbScrollArea::ScrollBarAlwaysOff);
    80 	
    83 	
    81 	// Connect the scrollig finished signal
    84 	// Connect the scrollig finished signal
   105 {
   108 {
   106     OstTraceFunctionEntry0( CALENPREVIEWPANE_SETNOENTRIESLABEL_ENTRY );
   109     OstTraceFunctionEntry0( CALENPREVIEWPANE_SETNOENTRIESLABEL_ENTRY );
   107     
   110     
   108 	mNoEntriesLabel = label;
   111 	mNoEntriesLabel = label;
   109 	
   112 	
       
   113 	if (mPreviewTextColor.isValid()) {
       
   114 		mNoEntriesLabel->setTextColor(mPreviewTextColor);
       
   115 	}
   110 	OstTraceFunctionExit0( CALENPREVIEWPANE_SETNOENTRIESLABEL_EXIT );
   116 	OstTraceFunctionExit0( CALENPREVIEWPANE_SETNOENTRIESLABEL_EXIT );
   111 }
   117 }
   112 
   118 
   113 /*!
   119 /*!
   114  Populates the preview with proper data
   120  Populates the preview with proper data
   120 	mScrollDirection = up;
   126 	mScrollDirection = up;
   121 	
   127 	
   122 	// Scroll contents to zero position before we display to the user
   128 	// Scroll contents to zero position before we display to the user
   123 	// if it was scrolling already or timer was running
   129 	// if it was scrolling already or timer was running
   124 	mNumOfScrolls = 0;
   130 	mNumOfScrolls = 0;
       
   131 	mScrollDuration = 0;
   125 	stopScrolling();
   132 	stopScrolling();
   126 	
   133 	
   127 	mDate = date;
   134 	mDate = date;
   128 	
   135 	
   129 	// Get Instances for the day
   136 	// Get Instances for the day
   136 															(content->layout());
   143 															(content->layout());
   137 	int instanceCount = mInstanceArray.count();
   144 	int instanceCount = mInstanceArray.count();
   138 	HbFontSpec font(HbFontSpec::Secondary);
   145 	HbFontSpec font(HbFontSpec::Secondary);
   139 	if (mIsNoEntriesAdded) {
   146 	if (mIsNoEntriesAdded) {
   140 		if (!instanceCount) {
   147 		if (!instanceCount) {
       
   148 			if (mPreviewTextColor.isValid()) {
       
   149 				mNoEntriesLabel->setTextColor(mPreviewTextColor);
       
   150 			}
   141 		    mNoEntriesLabel->setVisible(true);
   151 		    mNoEntriesLabel->setVisible(true);
   142 		    OstTraceFunctionExit0( CALENPREVIEWPANE_POPULATELABEL_EXIT );
   152 		    OstTraceFunctionExit0( CALENPREVIEWPANE_POPULATELABEL_EXIT );
   143 		    return;
   153 		    return;
   144 		} else {
   154 		} else {
   145 			// Remove the no entries label
   155 			// Remove the no entries label
   160 				label = new HbLabel(this);
   170 				label = new HbLabel(this);
   161 				
   171 				
   162 				// Set the required font
   172 				// Set the required font
   163 				label->setFontSpec(font);
   173 				label->setFontSpec(font);
   164 				
   174 				
   165 				// Set the text color from the theme
       
   166 				QColor previewPaneColor = HbColorScheme::color(
       
   167 												"qtc_cal_day_preview_text");
       
   168 				if (previewPaneColor.isValid()) {
       
   169 				    label->setTextColor(previewPaneColor);
       
   170 				}
       
   171 				
       
   172 				// Set the elide mode to right
   175 				// Set the elide mode to right
   173 				label->setElideMode(Qt::ElideRight);
   176 				label->setElideMode(Qt::ElideRight);
   174 				// Add the label to the list
   177 				// Add the label to the list
   175 				mLabelList.append(label);
   178 				mLabelList.append(label);
   176 				layout->addItem(label);
   179 				layout->addItem(label);
   177 			} else {
   180 			} else {
   178 				// Reuse the same label
   181 				// Reuse the same label
   179 				label = mLabelList.at(i);
   182 				label = mLabelList.at(i);
   180 				count--;
   183 				count--;
       
   184 			}
       
   185 			
       
   186 			if (mPreviewTextColor.isValid()) {
       
   187 				label->setTextColor(mPreviewTextColor);
   181 			}
   188 			}
   182 			QString summary = mInstanceArray[i].summary();
   189 			QString summary = mInstanceArray[i].summary();
   183 			if(!summary.length()) {
   190 			if(!summary.length()) {
   184 				// No summary display "Unnamed"
   191 				// No summary display "Unnamed"
   185 				summary.append(hbTrId("txt_calendar_preview_unnamed"));
   192 				summary.append(hbTrId("txt_calendar_preview_unnamed"));
   232 			}
   239 			}
   233 		}
   240 		}
   234 		// Clear the list
   241 		// Clear the list
   235 		mLabelList.clear();
   242 		mLabelList.clear();
   236 		
   243 		
       
   244 		if (mPreviewTextColor.isValid()) {
       
   245 			mNoEntriesLabel->setTextColor(mPreviewTextColor);
       
   246 		}
   237 		// Add the no entries text to the preview pane
   247 		// Add the no entries text to the preview pane
   238 		mNoEntriesLabel->setVisible(true);
   248 		mNoEntriesLabel->setVisible(true);
   239 		mIsNoEntriesAdded = true;
   249 		mIsNoEntriesAdded = true;
   240 	}
   250 	}
   241 	layout->activate();
   251 	layout->activate();
   289 	if (mIsNoEntriesAdded) {
   299 	if (mIsNoEntriesAdded) {
   290 		scrollContentsTo(QPointF(0.0,0.0));
   300 		scrollContentsTo(QPointF(0.0,0.0));
   291 		OstTraceFunctionExit0( CALENPREVIEWPANE_STARTAUTOSCROLL_EXIT );
   301 		OstTraceFunctionExit0( CALENPREVIEWPANE_STARTAUTOSCROLL_EXIT );
   292 		return;
   302 		return;
   293 	}
   303 	}
   294 
   304 	
       
   305 	// Stop the timer
       
   306 	mTwoSecTimer->stop();
       
   307 	
       
   308 	// Set the proper scroll direction
       
   309 	mScrollDirection = up;
       
   310 	
   295 	// Start the 2 seconds timer
   311 	// Start the 2 seconds timer
   296 	mTwoSecTimer->setSingleShot(true);
   312 	mTwoSecTimer->setSingleShot(true);
   297 	connect(mTwoSecTimer, SIGNAL(timeout()), this, SLOT(onTwoSecondsTimeout()));
   313 	connect(mTwoSecTimer, SIGNAL(timeout()), this, SLOT(onTwoSecondsTimeout()));
   298 	mTwoSecTimer->start(TWO_SECONDS_TIMER);
   314 	mTwoSecTimer->start(TWO_SECONDS_TIMER);
   299 	
   315 	
   321             mScrollDuration = mHtDiff / SCROLLING_SPEED;
   337             mScrollDuration = mHtDiff / SCROLLING_SPEED;
   322         }
   338         }
   323 	}
   339 	}
   324 	
   340 	
   325     // Start the scrolling in the proper direction
   341     // Start the scrolling in the proper direction
   326 	if (mScrollDirection == up) {
   342 	if (mScrollDirection == up && mScrollDuration) {
   327 		// Start scrolling upwards
   343 		// Start scrolling upwards
   328 		mScrollDirection = down;
   344 		mScrollDirection = down;
   329 		mNumOfScrolls++;
   345 		mNumOfScrolls++;
   330 		QPointF targetPos(0.0, -mHtDiff);
   346 		QPointF targetPos(0.0, -mHtDiff);
   331         scrollContentsTo(-targetPos, mScrollDuration * 1000);
   347         scrollContentsTo(-targetPos, mScrollDuration * 1000);
   332 	} else if (mScrollDirection == down) {
   348 	} else if (mScrollDirection == down && mScrollDuration) {
   333 		mScrollDirection = up;
   349 		mScrollDirection = up;
   334 		mNumOfScrolls++;
   350 		mNumOfScrolls++;
   335 		// Start scrolling downwards
   351 		// Start scrolling downwards
   336 		QPointF targetPos(0.0, 0.0);
   352 		QPointF targetPos(0.0, 0.0);
   337         scrollContentsTo(targetPos, mScrollDuration * 1000);
   353         scrollContentsTo(targetPos, mScrollDuration * 1000);
   428         }
   444         }
   429     } else if(QTapGesture *tapGesture = qobject_cast<QTapGesture *>(event->gesture(Qt::TapGesture))) {
   445     } else if(QTapGesture *tapGesture = qobject_cast<QTapGesture *>(event->gesture(Qt::TapGesture))) {
   430         if (tapGesture && tapGesture->state() == Qt::GestureFinished) {
   446         if (tapGesture && tapGesture->state() == Qt::GestureFinished) {
   431             	HbInstantFeedback::play(HbFeedback::Basic);
   447             	HbInstantFeedback::play(HbFeedback::Basic);
   432                 // Preview pane tapped
   448                 // Preview pane tapped
       
   449             	// Stop the scrolling first
       
   450             	stopScrolling();
       
   451             	// Issue command to launch agenda view
   433                 mServices.IssueCommandL(ECalenAgendaView);
   452                 mServices.IssueCommandL(ECalenAgendaView);
       
   453                 mView->disconnectAboutToQuitEvent();
   434                 event->accept(Qt::TapGesture);
   454                 event->accept(Qt::TapGesture);
   435         }
   455         }
   436     }
   456     }
   437     
   457     
   438     OstTraceFunctionExit0( DUP2_CALENPREVIEWPANE_GESTUREEVENT_EXIT );
   458     OstTraceFunctionExit0( DUP3_CALENPREVIEWPANE_GESTUREEVENT_EXIT );
   439 }
   459 }
   440 
   460 
   441 /*!
   461 /*!
   442  Set monthview pointer
   462  Set monthview pointer
   443  */
   463  */
   455  */
   475  */
   456 void CalenPreviewPane::stopScrolling()
   476 void CalenPreviewPane::stopScrolling()
   457 {
   477 {
   458     OstTraceFunctionEntry0( CALENPREVIEWPANE_STOPSCROLLING_ENTRY );
   478     OstTraceFunctionEntry0( CALENPREVIEWPANE_STOPSCROLLING_ENTRY );
   459     
   479     
   460 	if (isScrolling() || mTwoSecTimer->isActive()) {
   480     mTwoSecTimer->stop();
       
   481 	if (isScrolling()) {
       
   482         mNumOfScrolls = 0; // required so that timer will not get started again in 
       
   483         // scrollingFinished() slot
       
   484         // Stop the scrolling by sending the foucs out event
       
   485         QFocusEvent* focusEvent = new QFocusEvent(QFocusEvent::FocusOut, Qt::MouseFocusReason);
       
   486         focusOutEvent(focusEvent); 
       
   487         
       
   488         // Set the contents position to zero
   461 		scrollContentsTo(QPointF(0.0,0.0));
   489 		scrollContentsTo(QPointF(0.0,0.0));
   462 		
       
   463 		// Call pan gesture with zero delta just to stop the scfrolling 
       
   464 		HbScrollArea::panGesture(QPointF(0.0,0.0));
       
   465 		mTwoSecTimer->stop();
       
   466 	}
   490 	}
   467 	
   491 	
   468 	OstTraceFunctionExit0( CALENPREVIEWPANE_STOPSCROLLING_EXIT );
   492 	OstTraceFunctionExit0( CALENPREVIEWPANE_STOPSCROLLING_EXIT );
   469 }
   493 }
   470 
   494 
   497 void CalenPreviewPane::effectFinished()
   521 void CalenPreviewPane::effectFinished()
   498 {
   522 {
   499     mIsGestureHandled = false;
   523     mIsGestureHandled = false;
   500 }
   524 }
   501 
   525 
       
   526 /*!
       
   527  Slot to handle the change in theme
       
   528  */
       
   529 void CalenPreviewPane::handleThemeChange()
       
   530 {
       
   531     OstTraceFunctionEntry0( CALENPREVIEWPANE_HANDLETHEMECHANGE_ENTRY );
       
   532     
       
   533     mPreviewTextColor = HbColorScheme::color("qtc_cal_day_preview_text");
       
   534     
       
   535     OstTraceFunctionExit0( CALENPREVIEWPANE_HANDLETHEMECHANGE_EXIT );
       
   536 }
       
   537 
   502 // End of file  --Don't remove this.
   538 // End of file  --Don't remove this.