27 const int MAXZVALUE = 100; |
27 const int MAXZVALUE = 100; |
28 const int MINZVALUE = 0; |
28 const int MINZVALUE = 0; |
29 const int NOOFSTEPSZI = 24; |
29 const int NOOFSTEPSZI = 24; |
30 const int NOOFSTEPSZO = 18; |
30 const int NOOFSTEPSZO = 18; |
31 const float MAXDTZOOMIN = 3.5; |
31 const float MAXDTZOOMIN = 3.5; |
|
32 const int NO_OF_STEPS_FOR_SPRINGBACK_AT_MAX = 12; |
|
33 const int NO_OF_STEPS_FOR_SPRINGBACK_AT_MIN = 5; |
32 |
34 |
33 GlxZoomWidget::GlxZoomWidget(QGraphicsItem *parent):HbScrollArea(parent), |
35 GlxZoomWidget::GlxZoomWidget(QGraphicsItem *parent):HbScrollArea(parent), |
34 mModel(NULL), mMinZValue(MINZVALUE), |
36 mModel(NULL), mMinZValue(MINZVALUE), |
35 mMaxZValue(MAXZVALUE), mTimerId(0), |
37 mMaxZValue(MAXZVALUE), mTimerId(0), |
36 mImageDecodeRequestSend(false), |
38 mImageDecodeRequestSend(false), |
60 setVerticalScrollBarPolicy(HbScrollArea::ScrollBarAlwaysOff); |
62 setVerticalScrollBarPolicy(HbScrollArea::ScrollBarAlwaysOff); |
61 setHorizontalScrollBarPolicy(HbScrollArea::ScrollBarAlwaysOff); |
63 setHorizontalScrollBarPolicy(HbScrollArea::ScrollBarAlwaysOff); |
62 //AA: signal and slot to perform double tap animation |
64 //AA: signal and slot to perform double tap animation |
63 //after every step redraw, signal is emitted to perform the next step |
65 //after every step redraw, signal is emitted to perform the next step |
64 connect( this, SIGNAL( stepZoom() ), this, SLOT( animateDoubleTap() ), Qt::QueuedConnection ); |
66 connect( this, SIGNAL( stepZoom() ), this, SLOT( animateDoubleTap() ), Qt::QueuedConnection ); |
|
67 mDoubleTap = false; |
65 } |
68 } |
66 |
69 |
67 GlxZoomWidget::~GlxZoomWidget() |
70 GlxZoomWidget::~GlxZoomWidget() |
68 { |
71 { |
69 |
72 |
236 } |
240 } |
237 } |
241 } |
238 |
242 |
239 if (pinchG->state() == Qt::GestureFinished) { |
243 if (pinchG->state() == Qt::GestureFinished) { |
240 //For giving a spring effect when user has zoomed more than normal. |
244 //For giving a spring effect when user has zoomed more than normal. |
241 if(mStepCurrentSize.width() > mMaxScaleDecSize.width()) { |
245 mPinchGestureOngoing = false; |
242 //scale the image to limited size |
246 //scale the image to limited size |
243 qreal value = mMaxScaleDecSize.width()/mCurrentSize.width(); |
247 if(mCurrentSize.width() > mMaxScaleDecSize.width() ) |
244 QPointF center(mWindowSize.width()/2, mWindowSize.height()/2); |
248 { |
245 QPointF sceneGestureCenter = source->sceneTransform().map(center); |
249 QPointF center(mWindowSize.width()/2, mWindowSize.height()/2); |
246 zoomImage(value, sceneGestureCenter); |
250 m_AnimRefPoint = source->sceneTransform().map(center); |
247 } |
251 springEffectAtMax(); |
248 mPinchGestureOngoing = false; |
252 return true; |
249 //finalize the transforms to the geometry else panning will not work |
253 } |
250 finalizeWidgetTransform(); |
|
251 |
254 |
252 //push the Zoom widget to background when zoomed image size nears FS image |
255 if(mCurrentSize.width() < mMinDecScaleSize.width()) |
253 if(mStepCurrentSize.width() <= mMinDecScaleSize.width()*1.3) { |
256 { |
254 mBlackBackgroundItem->hide(); |
257 QPointF center(mWindowSize.width()/2, mWindowSize.height()/2); |
255 //push the widget back to background |
258 m_AnimRefPoint = source->sceneTransform().map(center); |
256 setZValue(mMinZValue); |
259 springEffectAtMin(); |
257 mZoomOngoing = false; |
260 return true; |
258 emit zoomWidgetMovedBackground(mFocusIndex); |
|
259 //do not reset the transform here as it will then zoom-in the widget to decoded image size |
261 //do not reset the transform here as it will then zoom-in the widget to decoded image size |
260 } |
262 } |
|
263 //finalize the transforms to the geometry else panning will not work |
|
264 finalizeWidgetTransform(); |
261 } |
265 } |
262 //gesture accepted |
266 //gesture accepted |
263 return true; |
267 return true; |
264 } |
268 } |
265 //gesture rejected |
269 //gesture rejected |
266 if(!mPinchGestureOngoing) { |
270 if(!mPinchGestureOngoing) { |
267 return false; |
271 return false; |
268 } |
272 } |
269 return true; |
273 return true; |
270 |
274 |
|
275 } |
|
276 void GlxZoomWidget::springEffectAtMax() |
|
277 { |
|
278 //set the no. of steps for double tap animation |
|
279 mdoubletapSteps = NO_OF_STEPS_FOR_SPRINGBACK_AT_MAX; |
|
280 //initiale variable for double tap animation |
|
281 mIncSF = 1; |
|
282 |
|
283 //For giving a spring effect when user has zoomed out more than normal. |
|
284 //Zoom out to mMaxScaleDecSize from the currentsize |
|
285 m_FinalAnimatedScaleFactor = mMaxScaleDecSize.width()/mCurrentSize.width(); |
|
286 //calculate the step increment SF for each step |
|
287 msfInc = (1 - m_FinalAnimatedScaleFactor)/(mdoubletapSteps); |
|
288 //preserve the size when zoom out was initiated, requried for calculates applicable/req scale factor |
|
289 minitSize = mCurrentSize; |
|
290 animateDoubleTap(); |
|
291 } |
|
292 |
|
293 void GlxZoomWidget::springEffectAtMin() |
|
294 { |
|
295 |
|
296 m_FinalAnimatedScaleFactor = mMinDecScaleSize.width()/mCurrentSize.width(); |
|
297 //set the no. of steps for double tap animation |
|
298 mdoubletapSteps = NO_OF_STEPS_FOR_SPRINGBACK_AT_MIN; |
|
299 //initiale variable for double tap animation |
|
300 mIncSF = 1; |
|
301 //SF has to always greater than 1 for upscaling, hence range for zoomout is [1,m_FinalAnimatedScaleFactor] |
|
302 msfInc = (m_FinalAnimatedScaleFactor-1)/mdoubletapSteps; |
|
303 //preserve the size when zoom out was initiated, requried for calculates applicable/req scale factor |
|
304 minitSize = mCurrentSize; |
|
305 animateDoubleTap(); |
|
306 |
271 } |
307 } |
272 |
308 |
273 void GlxZoomWidget::zoomImage(qreal zoomFactor, QPointF center) |
309 void GlxZoomWidget::zoomImage(qreal zoomFactor, QPointF center) |
274 { |
310 { |
275 // Pinch event filtering for very small zoom factors |
311 // Pinch event filtering for very small zoom factors |
607 |
644 |
608 } |
645 } |
609 void GlxZoomWidget::animationTimeLineFinished() |
646 void GlxZoomWidget::animationTimeLineFinished() |
610 { |
647 { |
611 finalizeWidgetTransform(); |
648 finalizeWidgetTransform(); |
612 //push the Zoom widget to background when zoomed image size nears FS image |
649 //push the Zoom widget to background when zoomed image size nears FS image |
613 if(mStepCurrentSize.width() <= mMinDecScaleSize.width()*1.3) { |
650 if(mDoubleTap && (mStepCurrentSize.width() <= mMinDecScaleSize.width()*1.3)) { |
614 mBlackBackgroundItem->hide(); |
651 mBlackBackgroundItem->hide(); |
615 //push the widget back to background |
652 //push the widget back to background |
616 setZValue(mMinZValue); |
653 setZValue(mMinZValue); |
617 mZoomOngoing = false; |
654 mZoomOngoing = false; |
618 emit zoomWidgetMovedBackground(mFocusIndex); |
655 emit zoomWidgetMovedBackground(mFocusIndex); |
619 //do not reset the transform here as it will then zoom-in the widget to decoded image size |
656 //do not reset the transform here as it will then zoom-in the widget to decoded image size |
620 } |
657 mDoubleTap = false; |
|
658 } |
|
659 if(mCurrentSize.width() == mMinDecScaleSize.width()) { |
|
660 mBlackBackgroundItem->hide(); |
|
661 //push the widget back to background |
|
662 setZValue(mMinZValue); |
|
663 mZoomOngoing = false; |
|
664 emit zoomWidgetMovedBackground(mFocusIndex); |
|
665 |
|
666 } |
621 } |
667 } |
622 |
668 |
623 |
669 |
624 void GlxZoomWidget::timerEvent(QTimerEvent *event) |
670 void GlxZoomWidget::timerEvent(QTimerEvent *event) |
625 { |
671 { |