calendarui/views/src/calenpreviewpane.cpp
changeset 32 ea672fcb0ea0
parent 23 fd30d51f876b
child 49 5de72ea7a065
equal deleted inserted replaced
26:a949c2543c15 32:ea672fcb0ea0
    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"
    40 #include "calenpreviewpane.h"
    42 #include "calenpreviewpane.h"
    41 #include "calenmonthview.h"
    43 #include "calenmonthview.h"
    42 
    44 
    43 // Macros
    45 // Macros
    44 #define TWO_SECONDS_TIMER 2000 // millseconds
    46 #define TWO_SECONDS_TIMER 2000 // millseconds
    45 #define SCROLLING_SPEED 50
    47 #define SCROLLING_SPEED 10
    46 
    48 
    47 static const QString EMPTYSTRING(" ");
    49 static const QString EMPTYSTRING(" ");
    48 
    50 
    49 /*!
    51 /*!
    50  Constructor
    52  Constructor
    57 	mTwoSecTimer = new QTimer(this);
    59 	mTwoSecTimer = new QTimer(this);
    58 	mScrollDirection = invalid;
    60 	mScrollDirection = invalid;
    59 	mIsNoEntriesAdded = true;
    61 	mIsNoEntriesAdded = true;
    60 	mIsGestureHandled = false;
    62 	mIsGestureHandled = false;
    61 	mNoEntriesLabel = 0;
    63 	mNoEntriesLabel = 0;
       
    64 	mHtDiff = 0.0;
       
    65 	mScrollDuration = 0;
    62 	setAcceptDrops(true);
    66 	setAcceptDrops(true);
    63 	setScrollDirections(Qt::Vertical);
    67 	setScrollDirections(Qt::Vertical);
    64 	setVerticalScrollBarPolicy(HbScrollArea::ScrollBarAlwaysOff);
    68 	setVerticalScrollBarPolicy(HbScrollArea::ScrollBarAlwaysOff);
    65 	
    69 	
    66 	// Connect the scrollig finished signal
    70 	// Connect the scrollig finished signal
    99 	
   103 	
   100 	// Get Instances for the day
   104 	// Get Instances for the day
   101 	GetInstanceListL();
   105 	GetInstanceListL();
   102 	
   106 	
   103 	// Get the content of the scroll area
   107 	// Get the content of the scroll area
   104 	QGraphicsWidget* content = this->contentWidget();
   108 	QGraphicsWidget* content = contentWidget();
   105 	// Adjust the layout
   109 	// Adjust the layout
   106 	QGraphicsLinearLayout* layout = static_cast<QGraphicsLinearLayout *>
   110 	QGraphicsLinearLayout* layout = static_cast<QGraphicsLinearLayout *>
   107 															(content->layout());
   111 															(content->layout());
   108 	int instanceCount = mInstanceArray.count();
   112 	int instanceCount = mInstanceArray.count();
   109 	HbFontSpec font(HbFontSpec::Secondary);
   113 	HbFontSpec font(HbFontSpec::Secondary);
   152 			QString summary = mInstanceArray[i].summary();
   156 			QString summary = mInstanceArray[i].summary();
   153 			if(!summary.length()) {
   157 			if(!summary.length()) {
   154 				// No summary display "No subject"
   158 				// No summary display "No subject"
   155 				summary.append(hbTrId("txt_calendar_dblist_unnamed"));
   159 				summary.append(hbTrId("txt_calendar_dblist_unnamed"));
   156 			}
   160 			}
   157 			QDateTime startTime = mInstanceArray[i].startTime();
   161 			// Chcek the entry type, based on the type display time field in
   158 			HbExtendedLocale systemLocale =HbExtendedLocale::system();
   162 			// preview pane.
   159 			QString start = systemLocale.format(startTime.time(), 
   163 			QString start;
   160 			                                    r_qtn_time_usual_with_zero);
   164 			if(mInstanceArray[i].type() != AgendaEntry::TypeTodo ) {
   161 			start.append(EMPTYSTRING);
   165 				QDateTime startTime = mInstanceArray[i].startTime();
       
   166 				HbExtendedLocale systemLocale =HbExtendedLocale::system();
       
   167 				start = systemLocale.format(startTime.time(), 
       
   168 				                                    r_qtn_time_usual_with_zero);
       
   169 				start.append(EMPTYSTRING);	
       
   170 			}
   162 			// Append summary to start time
   171 			// Append summary to start time
   163 			QString text = start.append(summary);
   172 			QString text = start.append(summary);
   164 			label->setPlainText(text);
   173 			label->setPlainText(text);
   165 			layout->setStretchFactor(label,0);
   174 			layout->setStretchFactor(label,0);
   166 		}
   175 		}
   257 void CalenPreviewPane::onTwoSecondsTimeout()
   266 void CalenPreviewPane::onTwoSecondsTimeout()
   258 {
   267 {
   259 	mTwoSecTimer->stop();
   268 	mTwoSecTimer->stop();
   260 	disconnect(mTwoSecTimer, SIGNAL(timeout()), 
   269 	disconnect(mTwoSecTimer, SIGNAL(timeout()), 
   261 										   this, SLOT(onTwoSecondsTimeout()));
   270 										   this, SLOT(onTwoSecondsTimeout()));
   262 	// Start the scrolling in the proper direction
   271 	
       
   272 	// Calculate the timer and the height difference of pane and its content
       
   273 	if (!mScrollDuration) {
       
   274         qreal contentHeight = contentWidget()->size().height();
       
   275         qreal paneHeight = size().height();
       
   276         mHtDiff = contentHeight - paneHeight;
       
   277         if (mHtDiff > 0) { // content is more than widget height, we need to scroll
       
   278             mScrollDuration = mHtDiff / SCROLLING_SPEED;
       
   279         }
       
   280 	}
       
   281 	
       
   282     // Start the scrolling in the proper direction
   263 	if (mScrollDirection == up) {
   283 	if (mScrollDirection == up) {
   264 		// Start scrolling upwards
   284 		// Start scrolling upwards
   265 		mScrollDirection = down;
   285 		mScrollDirection = down;
   266 		mNumOfScrolls++;
   286 		mNumOfScrolls++;
   267 		upGesture(SCROLLING_SPEED);
   287 		QPointF targetPos(0.0, -mHtDiff);
       
   288         scrollContentsTo(-targetPos, mScrollDuration * 1000);
   268 	} else if (mScrollDirection == down) {
   289 	} else if (mScrollDirection == down) {
   269 		mScrollDirection = up;
   290 		mScrollDirection = up;
   270 		mNumOfScrolls++;
   291 		mNumOfScrolls++;
   271 		// Start scrolling downwards
   292 		// Start scrolling downwards
   272 		downGesture(SCROLLING_SPEED);
   293 		QPointF targetPos(0.0, 0.0);
       
   294         scrollContentsTo(targetPos, mScrollDuration * 1000);
   273 	}
   295 	}
   274 }
   296 }
   275 
   297 
   276 /*!
   298 /*!
   277  Slot to handle scrolling finished
   299  Slot to handle scrolling finished
   288 	connect(mTwoSecTimer, SIGNAL(timeout()), this, SLOT(onTwoSecondsTimeout()));
   310 	connect(mTwoSecTimer, SIGNAL(timeout()), this, SLOT(onTwoSecondsTimeout()));
   289 	mTwoSecTimer->start(TWO_SECONDS_TIMER);
   311 	mTwoSecTimer->start(TWO_SECONDS_TIMER);
   290 }
   312 }
   291 
   313 
   292 /*!
   314 /*!
   293  Function to listen mouse press events
   315     Function to listen for all gestures
   294  */
   316  */
   295 void CalenPreviewPane::mousePressEvent(QGraphicsSceneMouseEvent* event)
   317 void CalenPreviewPane::gestureEvent(QGestureEvent *event)
   296 {
   318 {
   297 	mIsGestureHandled = false;
   319     if(HbPanGesture *gesture = qobject_cast<HbPanGesture *>(event->gesture(Qt::PanGesture))) {
   298 	mPressedPos = event->pos();
   320         if (gesture->state() == Qt::GestureStarted) {
   299 	event->accept();
   321             // Get to know the direction of the gesture
   300 }
   322         	QPointF delta = gesture->sceneDelta();
   301 
   323             if (delta.x() > 20) {
   302 /*!
   324                 mIsGestureHandled = true;
   303  Function to listen mouse release events
   325                 // right gesture
   304  */
   326                 mView->handlePreviewPaneGesture(true);
   305 void CalenPreviewPane::mouseReleaseEvent(QGraphicsSceneMouseEvent* event)
   327                 event->accept(Qt::PanGesture);
   306 {
   328             } else if (delta.x() < -20){
   307 	qreal posDiff = mPressedPos.x()-event->pos().x();
   329                 mIsGestureHandled = true;
   308 	if (abs(posDiff) < 50 && !mIsGestureHandled) {
   330                 // left gesture
   309 		// Preview pane tapped
   331                 mView->handlePreviewPaneGesture(false);
   310 		mServices.IssueCommandL(ECalenDayView);
   332                 event->accept(Qt::PanGesture);
   311 	}
   333             }
   312 	event->accept();
   334         }
   313 }
   335     } else if(HbTapGesture *gesture = qobject_cast<HbTapGesture *>(event->gesture(Qt::TapGesture))) {
   314 
   336         if (gesture->state() == Qt::GestureFinished) {
   315 /*!
   337             if (gesture->tapStyleHint() == HbTapGesture::Tap) {
   316  Function to listen mouse move events
   338                 // Preview pane tapped
   317  */
   339                 mServices.IssueCommandL(ECalenDayView);
   318 void CalenPreviewPane::mouseMoveEvent(QGraphicsSceneMouseEvent* event)
   340                 event->accept(Qt::TapGesture);
   319 {
   341             }
   320 	qreal posDiff = mPressedPos.x()-event->pos().x();
   342         }
   321 	if (posDiff < -50) {
   343     }
   322 		mIsGestureHandled = true;
       
   323 		// right gesture
       
   324 		mView->handlePreviewPaneGesture(true);
       
   325 	} else if (posDiff > 50) {
       
   326 		mIsGestureHandled = true;
       
   327 		// left gesture
       
   328 		mView->handlePreviewPaneGesture(false);
       
   329 	}
       
   330 	event->accept();
       
   331 }
   344 }
   332 
   345 
   333 /*!
   346 /*!
   334  Set monthview pointer
   347  Set monthview pointer
   335  */
   348  */