43
|
1 |
/*
|
|
2 |
* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
* All rights reserved.
|
|
4 |
* This component and the accompanying materials are made available
|
|
5 |
* under the terms of "Eclipse Public License v1.0"
|
|
6 |
* which accompanies this distribution, and is available
|
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
*
|
|
9 |
* Initial Contributors:
|
|
10 |
* Nokia Corporation - initial contribution.
|
|
11 |
*
|
|
12 |
* Contributors:
|
|
13 |
*
|
|
14 |
* Description: glxzoomwidget.cpp
|
|
15 |
* description of the class GlxGlxZoomWidget which controls the Zoom behavior of coverflow.
|
|
16 |
*
|
|
17 |
*/
|
|
18 |
#include <QPinchGesture>
|
|
19 |
#include <hbiconitem.h>
|
|
20 |
#include <QTimeLine>
|
|
21 |
#include <QGesture>
|
50
|
22 |
#include <hbinstance.h>
|
43
|
23 |
#include "glximagedecoderwrapper.h"
|
|
24 |
#include "glxmodelparm.h"
|
|
25 |
#include "glxzoomwidget.h"
|
|
26 |
|
52
|
27 |
GlxZoomWidget::GlxZoomWidget(QGraphicsItem *parent):HbScrollArea(parent),
|
|
28 |
mModel(NULL), mMinZValue(MINZVALUE),
|
|
29 |
mMaxZValue(MAXZVALUE), mTimerId(0),
|
|
30 |
mImageDecodeRequestSend(false),
|
|
31 |
mPinchGestureOngoing(false), mDecodedImageAvailable(false),
|
|
32 |
mZoomOngoing(false)
|
43
|
33 |
{
|
|
34 |
grabGesture(Qt::PinchGesture);
|
44
|
35 |
grabGesture(Qt::TapGesture);
|
43
|
36 |
setAcceptTouchEvents(true) ;
|
|
37 |
setFrictionEnabled(false);
|
|
38 |
setZValue(mMinZValue);
|
|
39 |
//create the child items and background
|
|
40 |
mZoomWidget = new QGraphicsWidget(this);
|
|
41 |
mZoomItem = new QGraphicsPixmapItem(mZoomWidget);
|
|
42 |
mZoomItem->setTransformationMode(Qt::SmoothTransformation);
|
|
43 |
//the black background
|
|
44 |
//replace when a proper substitute for setting backgrounds is known
|
|
45 |
mBlackBackgroundItem = new HbIconItem(this);
|
|
46 |
mBlackBackgroundItem->setBrush(QBrush(Qt::black));
|
|
47 |
mBlackBackgroundItem->hide();
|
|
48 |
//does not work so is commented
|
|
49 |
//setBackgroundItem(mBlackBackgroundItem);
|
|
50 |
|
|
51 |
//initializing the image decoder
|
|
52 |
mImageDecoder = new GlxImageDecoderWrapper;
|
|
53 |
|
|
54 |
//inititalizing the timer for animation
|
44
|
55 |
m_AnimTimeLine = new QTimeLine(500, this);
|
43
|
56 |
m_AnimTimeLine->setFrameRange(0, 100);
|
|
57 |
connect(m_AnimTimeLine, SIGNAL(frameChanged(int)), this, SLOT(animationFrameChanged(int)));
|
|
58 |
connect(m_AnimTimeLine, SIGNAL(finished()), this, SLOT(animationTimeLineFinished()));
|
|
59 |
}
|
|
60 |
|
|
61 |
GlxZoomWidget::~GlxZoomWidget()
|
|
62 |
{
|
|
63 |
//disconnect all existing signals
|
|
64 |
disconnect(this,SIGNAL( pinchGestureReceived(int) ), this, SLOT( sendDecodeRequest(int) ) );
|
|
65 |
//no Null checks required
|
|
66 |
delete mZoomItem;
|
|
67 |
// delete mZoomWidget; //as this is a content widegt it will automatically be deleted
|
|
68 |
delete mBlackBackgroundItem;
|
|
69 |
//reset the decoder to cancel pending tasks
|
|
70 |
if(mImageDecoder) {
|
|
71 |
mImageDecoder->resetDecoder();
|
|
72 |
delete mImageDecoder;
|
|
73 |
}
|
|
74 |
}
|
|
75 |
|
|
76 |
void GlxZoomWidget::setModel (QAbstractItemModel *model)
|
|
77 |
{
|
|
78 |
if(model)
|
|
79 |
{
|
|
80 |
mModel = model;
|
|
81 |
retreiveFocusedImage(); //Update mZoomItem with focused Image
|
|
82 |
connect( mModel, SIGNAL( dataChanged(QModelIndex,QModelIndex) ), this, SLOT( dataChanged(QModelIndex,QModelIndex) ) );
|
45
|
83 |
connect( mModel, SIGNAL( destroyed() ), this, SLOT( modelDestroyed() ) );
|
43
|
84 |
}
|
|
85 |
}
|
|
86 |
|
|
87 |
void GlxZoomWidget::setWindowSize(QSize windowSize)
|
|
88 |
{
|
|
89 |
mWindowSize = windowSize;
|
|
90 |
mBlackBackgroundItem->setGeometry(QRectF(QPointF(0,0), mWindowSize));
|
|
91 |
//try to reset the max and min zoomed size here
|
50
|
92 |
//In case the zoom widget is in background reset it
|
|
93 |
if(!mZoomOngoing && mModel) {
|
|
94 |
retreiveFocusedImage();
|
|
95 |
}
|
|
96 |
setZoomParams();
|
|
97 |
}
|
|
98 |
|
|
99 |
void GlxZoomWidget::forceZoomToBackground()
|
|
100 |
{
|
|
101 |
mBlackBackgroundItem->hide();
|
|
102 |
//push the widget back to background
|
|
103 |
setZValue(mMinZValue);
|
|
104 |
mZoomOngoing = false;
|
|
105 |
emit zoomWidgetMovedBackground(mFocusIndex);
|
|
106 |
//this actually resets the ZoomWidget and decoder
|
|
107 |
if(mImageDecoder) {
|
|
108 |
mImageDecoder->resetDecoder();
|
|
109 |
}
|
|
110 |
retreiveFocusedImage();
|
|
111 |
|
43
|
112 |
}
|
|
113 |
|
|
114 |
void GlxZoomWidget::indexChanged(int index)
|
|
115 |
{
|
|
116 |
if(mFocusIndex != index) {
|
|
117 |
mImageDecoder->resetDecoder();//reset the decoder first to cancel pending tasks
|
|
118 |
mImageDecodeRequestSend = false;
|
|
119 |
mDecodedImageAvailable = false;
|
|
120 |
retreiveFocusedImage(); //Update mZoomItem with focused Image
|
|
121 |
}
|
|
122 |
}
|
|
123 |
|
|
124 |
void GlxZoomWidget::cleanUp()
|
|
125 |
{
|
44
|
126 |
if(mModel) {
|
|
127 |
disconnect( mModel, SIGNAL( dataChanged(QModelIndex,QModelIndex) ), this, SLOT( dataChanged(QModelIndex,QModelIndex) ) );
|
45
|
128 |
disconnect( mModel, SIGNAL( destroyed() ), this, SLOT( modelDestroyed() ) );
|
44
|
129 |
mModel = NULL;
|
|
130 |
}
|
43
|
131 |
if(mImageDecoder) {
|
|
132 |
mImageDecoder->resetDecoder();
|
|
133 |
}
|
|
134 |
mZoomItem->setPixmap(QPixmap());
|
|
135 |
}
|
|
136 |
|
|
137 |
void GlxZoomWidget::activate()
|
|
138 |
{
|
|
139 |
}
|
|
140 |
|
|
141 |
void GlxZoomWidget::setMinMaxZValue(int minZvalue, int maxZvalue)
|
|
142 |
{
|
|
143 |
mMinZValue = minZvalue;
|
|
144 |
mMaxZValue = maxZvalue;
|
|
145 |
}
|
|
146 |
|
|
147 |
void GlxZoomWidget::connectDecodeRequestToPinchEvent()
|
|
148 |
{
|
|
149 |
connect(this,SIGNAL( pinchGestureReceived(int) ), this, SLOT( sendDecodeRequest(int) ), Qt::QueuedConnection );
|
|
150 |
}
|
|
151 |
|
|
152 |
bool GlxZoomWidget::sceneEvent(QEvent *event)
|
|
153 |
{
|
|
154 |
bool consume(false);
|
|
155 |
if (event->type() == QEvent::Gesture) {
|
|
156 |
consume = executeGestureEvent(this, static_cast<QGestureEvent*>(event));
|
|
157 |
}
|
|
158 |
if(!consume)
|
|
159 |
{
|
|
160 |
consume = HbScrollArea::sceneEvent(event);
|
|
161 |
}
|
|
162 |
return consume;
|
|
163 |
}
|
|
164 |
|
|
165 |
bool GlxZoomWidget::sceneEventFilter(QGraphicsItem *watched,QEvent *event)
|
|
166 |
{
|
|
167 |
qDebug("GlxCoverFlow::eventFilter " );
|
|
168 |
bool consume = false;
|
|
169 |
if (event->type() == QEvent::Gesture) {
|
|
170 |
consume = executeGestureEvent(watched, static_cast<QGestureEvent*>(event));
|
|
171 |
}
|
|
172 |
|
|
173 |
if(!consume) {
|
|
174 |
consume = HbScrollArea::sceneEventFilter(watched,event);
|
|
175 |
}
|
|
176 |
return consume;
|
|
177 |
|
|
178 |
}
|
|
179 |
|
|
180 |
bool GlxZoomWidget::executeGestureEvent(QGraphicsItem *source,QGestureEvent *event)
|
|
181 |
{
|
44
|
182 |
if(QTapGesture *gesture = static_cast<QTapGesture *>(event->gesture(Qt::TapGesture))) {
|
|
183 |
if (gesture->state() == Qt::GestureFinished) {
|
|
184 |
if(!mTimerId) {
|
|
185 |
mTimerId = startTimer(500);
|
|
186 |
}
|
|
187 |
else {
|
|
188 |
killTimer(mTimerId);
|
|
189 |
mTimerId = 0;
|
50
|
190 |
animateZoomOut(hbInstance->allMainWindows().first()->mapToScene(gesture->position().toPoint()));
|
44
|
191 |
}
|
|
192 |
}
|
|
193 |
event->accept(gesture);
|
|
194 |
return true;
|
|
195 |
}
|
43
|
196 |
if (QGesture *pinch = event->gesture(Qt::PinchGesture)) {
|
52
|
197 |
if (isFocussedItemCorrupt()){
|
|
198 |
return true;
|
|
199 |
}
|
43
|
200 |
QPinchGesture* pinchG = static_cast<QPinchGesture *>(pinch);
|
|
201 |
QPinchGesture::ChangeFlags changeFlags = pinchG->changeFlags();
|
|
202 |
if (changeFlags & QPinchGesture::ScaleFactorChanged) {
|
|
203 |
mPinchGestureOngoing = true;
|
50
|
204 |
mZoomOngoing = true;
|
43
|
205 |
//bring the zoom widget to foreground
|
|
206 |
setZValue(mMaxZValue);
|
|
207 |
//show the black background
|
|
208 |
mBlackBackgroundItem->setParentItem(parentItem());
|
|
209 |
mBlackBackgroundItem->setZValue(mMaxZValue - 1);
|
|
210 |
mBlackBackgroundItem->show();
|
|
211 |
|
|
212 |
//retreive the gesture values
|
|
213 |
qreal value = pinchG->scaleFactor() / pinchG->lastScaleFactor();
|
|
214 |
QPointF center = pinchG->property("centerPoint").toPointF();
|
|
215 |
//set the gesture center to the scene coordinates
|
50
|
216 |
QPointF sceneGestureCenter = hbInstance->allMainWindows().first()->mapToScene(center.toPoint());
|
43
|
217 |
zoomImage(value, sceneGestureCenter);
|
|
218 |
|
|
219 |
}
|
|
220 |
if (pinchG->state() == Qt::GestureStarted) {
|
|
221 |
emit pinchGestureReceived(mFocusIndex);
|
|
222 |
}
|
|
223 |
|
|
224 |
if (pinchG->state() == Qt::GestureFinished) {
|
|
225 |
if(mStepCurrentSize != mCurrentSize) {
|
|
226 |
//For giving a spring effect when user has zoomed more than normal.
|
|
227 |
if(mStepCurrentSize.width() > mMaxScaleDecSize.width()) {
|
|
228 |
//scale the image to limited size
|
|
229 |
qreal value = mMaxScaleDecSize.width()/mCurrentSize.width();
|
|
230 |
QPointF center(mWindowSize.width()/2, mWindowSize.height()/2);
|
|
231 |
QPointF sceneGestureCenter = source->sceneTransform().map(center);
|
|
232 |
zoomImage(value, sceneGestureCenter);
|
|
233 |
}
|
|
234 |
mPinchGestureOngoing = false;
|
|
235 |
//finalize the transforms to the geometry else panning will not work
|
|
236 |
finalizeWidgetTransform();
|
|
237 |
}
|
|
238 |
//push the Zoom widget to background when zoomed image size nears FS image
|
|
239 |
if(mStepCurrentSize.width() <= mMinDecScaleSize.width()*1.3) {
|
|
240 |
mBlackBackgroundItem->hide();
|
|
241 |
//push the widget back to background
|
|
242 |
setZValue(mMinZValue);
|
50
|
243 |
mZoomOngoing = false;
|
43
|
244 |
emit zoomWidgetMovedBackground(mFocusIndex);
|
|
245 |
//do not reset the transform here as it will then zoom-in the widget to decoded image size
|
|
246 |
}
|
|
247 |
}
|
|
248 |
//gesture accepted
|
|
249 |
return true;
|
|
250 |
}
|
|
251 |
//gesture rejected
|
|
252 |
if(!mPinchGestureOngoing) {
|
|
253 |
return false;
|
|
254 |
}
|
|
255 |
return true;
|
|
256 |
|
|
257 |
}
|
|
258 |
|
|
259 |
void GlxZoomWidget::zoomImage(qreal zoomFactor, QPointF center)
|
|
260 |
{
|
50
|
261 |
// Pinch event filtering for very small zoom factors
|
|
262 |
if (qAbs(1.0 - zoomFactor) < 0.007) {
|
|
263 |
return;
|
|
264 |
}
|
43
|
265 |
adjustGestureCenter(center, zoomFactor);
|
|
266 |
QSizeF requiredSize(mCurrentSize.width()*zoomFactor, mCurrentSize.height()*zoomFactor);
|
|
267 |
limitRequiredSize(requiredSize);
|
|
268 |
if(requiredSize != mCurrentSize) {
|
|
269 |
QTransform zoomTransform = mZoomWidget->transform();
|
|
270 |
QPointF transformedCenter = mZoomWidget->sceneTransform().inverted().map(center);
|
|
271 |
zoomTransform.translate(transformedCenter.x(),transformedCenter.y());
|
|
272 |
zoomTransform.scale(requiredSize.width()/mCurrentSize.width(), requiredSize.height()/mCurrentSize.height());
|
|
273 |
zoomTransform.translate(-transformedCenter.x(),-transformedCenter.y());
|
|
274 |
mZoomWidget->setTransform(zoomTransform);
|
|
275 |
mCurrentSize = requiredSize;
|
|
276 |
}
|
|
277 |
|
|
278 |
}
|
|
279 |
|
|
280 |
|
|
281 |
void GlxZoomWidget::limitRequiredSize(QSizeF &requiredSize)
|
|
282 |
{
|
|
283 |
if(requiredSize.width() > mMaxScaleSize.width() ) {
|
|
284 |
requiredSize = mMaxScaleSize ;
|
|
285 |
}
|
|
286 |
else if(requiredSize.width() < mMinDecScaleSize.width() ) {
|
|
287 |
requiredSize = mMinDecScaleSize ;
|
|
288 |
}
|
|
289 |
|
|
290 |
|
|
291 |
}
|
|
292 |
|
|
293 |
//makes sure that the gesture is on the screen center if the image is smaller than the screen
|
|
294 |
void GlxZoomWidget::adjustGestureCenter(QPointF & gestureCenter, qreal& zoomFactor)
|
|
295 |
{
|
|
296 |
if(zoomFactor > 1 &&zoomFactor > 1.2 ) {
|
|
297 |
zoomFactor = 1.2;
|
|
298 |
}
|
|
299 |
|
|
300 |
if(zoomFactor < 1 &&zoomFactor < 0.8 ) {
|
|
301 |
zoomFactor = 0.8;
|
|
302 |
}
|
|
303 |
QSizeF requiredSize(mCurrentSize.width()*zoomFactor, mCurrentSize.height()*zoomFactor);
|
|
304 |
//keep smaller image centered
|
|
305 |
if(mCurrentSize.width() <= mWindowSize.width() )
|
|
306 |
{
|
|
307 |
gestureCenter.setX(mWindowSize.width()/2);
|
|
308 |
|
|
309 |
}
|
|
310 |
if(mCurrentSize.height() <= mWindowSize.height())
|
|
311 |
{
|
|
312 |
gestureCenter.setY(mWindowSize.height()/2);
|
|
313 |
|
|
314 |
}
|
|
315 |
//maintains the boundary of the edges for zoom out conditions
|
50
|
316 |
if(zoomFactor < 1) {
|
43
|
317 |
QPointF itemOriginPos = mZoomWidget->sceneTransform().map(QPointF(0,0));
|
|
318 |
bool hasWidthExceededWindow = mCurrentSize.width() > mWindowSize.width();
|
|
319 |
bool hasHeightExceededWindow = mCurrentSize.height() > mWindowSize.height();
|
50
|
320 |
if(hasWidthExceededWindow) {
|
|
321 |
bool hasItemCrossedBoundary = false;
|
|
322 |
if(itemOriginPos.x() >= -5) {
|
|
323 |
//image has crossed left boundry leaving blank space
|
43
|
324 |
//stick the gesture to the left corner
|
|
325 |
gestureCenter.setX(itemOriginPos.x());
|
50
|
326 |
hasItemCrossedBoundary = true;
|
|
327 |
}
|
|
328 |
|
|
329 |
//Check if the right boundry can be adjusted
|
|
330 |
if(itemOriginPos.x()+ mCurrentSize.width() <= mWindowSize.width()+5) {
|
|
331 |
//Image is before the right boundry leaving blank space
|
|
332 |
gestureCenter.setX(itemOriginPos.x()+ mCurrentSize.width() );
|
|
333 |
hasItemCrossedBoundary = true;
|
|
334 |
}
|
|
335 |
if((mCurrentSize.width() - mWindowSize.width() <= 20) && !hasItemCrossedBoundary) {
|
|
336 |
gestureCenter.setX(mWindowSize.width()/2 + (qAbs(itemOriginPos.x()) - 10));
|
43
|
337 |
}
|
|
338 |
}
|
50
|
339 |
|
|
340 |
if(hasHeightExceededWindow) {
|
|
341 |
bool hasItemCrossedBoundary = false;
|
|
342 |
//check if the upper boundry could be adjusted
|
|
343 |
if(itemOriginPos.y() >= -5) {
|
|
344 |
//image has crossed the upper boundry leaving blank space
|
|
345 |
//stick the image to the upper boundry
|
|
346 |
gestureCenter.setY(itemOriginPos.y());
|
|
347 |
hasItemCrossedBoundary = true;
|
|
348 |
}
|
|
349 |
//check if the lower boundry could be adjusted
|
|
350 |
if(itemOriginPos.y()+ mCurrentSize.height() <= mWindowSize.height()+5) {
|
43
|
351 |
//Image is before the right boundry leaving blank space
|
|
352 |
//stick the image to the right corner
|
|
353 |
gestureCenter.setY(itemOriginPos.y()+ mCurrentSize.height());
|
50
|
354 |
hasItemCrossedBoundary = true;
|
43
|
355 |
}
|
50
|
356 |
if((mCurrentSize.height() - mWindowSize.height() <= 20) && !hasItemCrossedBoundary) {
|
|
357 |
gestureCenter.setY(mWindowSize.height()/2 + (qAbs(itemOriginPos.y()) - 10));
|
|
358 |
}
|
43
|
359 |
}
|
|
360 |
}
|
|
361 |
//control the zoom Factor to boundaries
|
|
362 |
if(mCurrentSize.width() > mWindowSize.width() && requiredSize.width() <= mWindowSize.width())
|
|
363 |
{
|
|
364 |
zoomFactor = mWindowSize.width()/mCurrentSize.width();
|
|
365 |
|
|
366 |
}
|
|
367 |
else if(mCurrentSize.height() > mWindowSize.height() && requiredSize.height() <= mWindowSize.height())
|
|
368 |
{
|
|
369 |
zoomFactor = mWindowSize.height()/mCurrentSize.height();
|
|
370 |
|
|
371 |
}
|
|
372 |
|
|
373 |
//reduce the ZF so as to show a decelerated effect at max/min levels
|
|
374 |
|
|
375 |
if(mCurrentSize.width() > mMaxScaleDecSize.width() && zoomFactor > 1 ) {
|
|
376 |
zoomFactor = 1.0 + ((zoomFactor-1.0)/6) ;
|
|
377 |
}
|
|
378 |
if(mCurrentSize.width() < mMinDecScaleSize.width() && zoomFactor < 1 ) {
|
|
379 |
zoomFactor = 1.0 - ((1.0-zoomFactor)/6) ;
|
|
380 |
}
|
|
381 |
|
|
382 |
|
|
383 |
}
|
|
384 |
|
|
385 |
//get the latest focused image and set it to mZoomItem
|
|
386 |
void GlxZoomWidget::retreiveFocusedImage()
|
|
387 |
{
|
|
388 |
|
|
389 |
QPixmap targetPixmap(getFocusedImage());
|
|
390 |
//initialize all the variables wrt the focussed pixmap
|
|
391 |
mZoomWidget->resetTransform();
|
|
392 |
mItemSize = targetPixmap.size();
|
|
393 |
mMaxScaleSize = mItemSize;
|
|
394 |
mMaxScaleSize.scale(mWindowSize*13, Qt::KeepAspectRatio);
|
|
395 |
mMaxScaleDecSize = mItemSize;
|
|
396 |
mMaxScaleDecSize.scale(mWindowSize*7, Qt::KeepAspectRatio);
|
|
397 |
mMinScaleSize = mItemSize* 0.7;
|
|
398 |
mMinDecScaleSize = mItemSize;
|
|
399 |
QPointF originPos = sceneTransform().map(QPointF(0,0));
|
|
400 |
mZoomWidget->setGeometry(QRectF(QPointF(mWindowSize.width()/2 - mItemSize.width()/2,mWindowSize.height()/2 - mItemSize.height()/2),mItemSize )); //chk this
|
|
401 |
mZoomWidget->setPreferredSize(mItemSize);
|
|
402 |
mZoomItem->setPixmap(targetPixmap);
|
|
403 |
mCurrentSize = mItemSize;
|
|
404 |
mStepCurrentSize = mItemSize;
|
|
405 |
setContentWidget(mZoomWidget);
|
|
406 |
show();
|
|
407 |
}
|
|
408 |
|
|
409 |
|
|
410 |
void GlxZoomWidget::dataChanged(QModelIndex startIndex, QModelIndex endIndex)
|
|
411 |
{
|
|
412 |
if(mFocusIndex >= startIndex.row() && mFocusIndex <= endIndex.row()) {
|
|
413 |
//get the latest image from the model
|
|
414 |
//will replace a decoded image if callback is received after decoded image is received so a fix is required
|
|
415 |
//retreiveFocusedImage();
|
|
416 |
if(!mDecodedImageAvailable) {
|
|
417 |
QPixmap targetPixmap(getFocusedImage());
|
44
|
418 |
mItemSize = targetPixmap.size();
|
|
419 |
mMaxScaleSize = mItemSize;
|
|
420 |
mMaxScaleSize.scale(mWindowSize*13, Qt::KeepAspectRatio);
|
|
421 |
mMaxScaleDecSize = mItemSize;
|
|
422 |
mMaxScaleDecSize.scale(mWindowSize*7, Qt::KeepAspectRatio);
|
|
423 |
mMinScaleSize = mItemSize* 0.7;
|
|
424 |
mMinDecScaleSize = mItemSize;
|
43
|
425 |
mZoomItem->setPixmap(targetPixmap);
|
|
426 |
finalizeWidgetTransform();
|
|
427 |
}
|
|
428 |
}
|
|
429 |
}
|
|
430 |
|
45
|
431 |
void GlxZoomWidget::modelDestroyed()
|
|
432 |
{
|
|
433 |
mModel = NULL ;
|
|
434 |
}
|
|
435 |
|
|
436 |
void GlxZoomWidget::indexChanged()
|
|
437 |
{
|
|
438 |
retreiveFocusedImage();
|
|
439 |
}
|
|
440 |
|
43
|
441 |
void GlxZoomWidget::decodedImageAvailable()
|
|
442 |
{
|
|
443 |
//new bitmap with better resolution is available
|
|
444 |
//so set it to the item
|
|
445 |
QPixmap decodedPixmap = mImageDecoder->getPixmap();
|
|
446 |
disconnect(mImageDecoder, SIGNAL(pixmapDecoded()), this, SLOT(decodedImageAvailable()));
|
|
447 |
if(decodedPixmap.isNull()){
|
|
448 |
return;
|
|
449 |
}
|
|
450 |
mDecodedImageAvailable = true;
|
|
451 |
mZoomItem->setPixmap(decodedPixmap);
|
|
452 |
mItemSize = decodedPixmap.size();
|
|
453 |
//this is important if not done then old transforms will be applied on the new image
|
|
454 |
finalizeWidgetTransform();
|
|
455 |
}
|
|
456 |
|
|
457 |
void GlxZoomWidget::sendDecodeRequest(int index)
|
|
458 |
{
|
|
459 |
if(!mImageDecodeRequestSend) {
|
|
460 |
QString imagePath = (mModel->data(mModel->index(index,0),GlxUriRole)).value<QString>();
|
|
461 |
mImageDecoder->decodeImage(imagePath);
|
|
462 |
connect(mImageDecoder, SIGNAL(pixmapDecoded()), this, SLOT(decodedImageAvailable()));
|
|
463 |
mImageDecodeRequestSend = true;
|
|
464 |
}
|
|
465 |
}
|
|
466 |
|
|
467 |
|
|
468 |
void GlxZoomWidget::finalizeWidgetTransform()
|
|
469 |
{
|
|
470 |
QPointF widgetPos = mZoomWidget->sceneTransform().map(QPointF(0,0)); //Map the origin wrt scene
|
|
471 |
mZoomWidget->resetTransform();
|
|
472 |
mZoomWidget->scale(mCurrentSize.width()/mItemSize.width(), mCurrentSize.height()/mItemSize.height());
|
|
473 |
mZoomWidget->setGeometry(QRectF(widgetPos , mCurrentSize));
|
|
474 |
// this updates HbScrollArea on the sizeHint of ZoomWidget
|
|
475 |
mZoomWidget->setPreferredSize(mCurrentSize);
|
|
476 |
mStepCurrentSize = mCurrentSize;
|
|
477 |
}
|
|
478 |
|
|
479 |
QPixmap GlxZoomWidget::getFocusedImage()
|
|
480 |
{
|
|
481 |
mFocusIndex = mModel->data(mModel->index(0,0),GlxFocusIndexRole).value<int>();
|
|
482 |
QVariant iconVariant = mModel->data(mModel->index(mFocusIndex,0),GlxFsImageRole);
|
|
483 |
QVariant sizeVariant = mModel->data(mModel->index(mFocusIndex,0),GlxDimensionsRole);
|
|
484 |
QPixmap targetPixmap;
|
|
485 |
//retreive pixmap from the HbIcon received from model
|
|
486 |
//should change the model to return and save pixmaps and convert to HbIcons Instead
|
|
487 |
if ( iconVariant.isValid() && iconVariant.canConvert<HbIcon> () ) {
|
|
488 |
QIcon itemIcon = iconVariant.value<HbIcon>().qicon();
|
|
489 |
QSize itemSize = itemIcon.actualSize(mWindowSize);
|
|
490 |
QSize scaleSize;
|
|
491 |
if(sizeVariant.isValid() && sizeVariant.canConvert<QSize> ()) {
|
|
492 |
scaleSize = sizeVariant.toSize();
|
|
493 |
if(!(scaleSize.width() < mWindowSize.width() && scaleSize.height() < mWindowSize.height())) {
|
|
494 |
scaleSize = mWindowSize;
|
|
495 |
}
|
|
496 |
}
|
|
497 |
targetPixmap = itemIcon.pixmap(itemSize).scaled(scaleSize, Qt::KeepAspectRatio);
|
|
498 |
mItemSize = targetPixmap.size();
|
|
499 |
}
|
|
500 |
return targetPixmap;
|
|
501 |
|
|
502 |
}
|
|
503 |
|
50
|
504 |
void GlxZoomWidget::setZoomParams()
|
|
505 |
{
|
|
506 |
if (mModel) {
|
|
507 |
QVariant sizeVariant = mModel->data(mModel->index(mFocusIndex,0),GlxDimensionsRole);
|
|
508 |
QSize fsSize;
|
|
509 |
if(sizeVariant.isValid() && sizeVariant.canConvert<QSize> ()) {
|
|
510 |
fsSize = sizeVariant.toSize();
|
|
511 |
if(!(fsSize.width() < mWindowSize.width() && fsSize.height() < mWindowSize.height())) {
|
|
512 |
fsSize.scale( mWindowSize, Qt::KeepAspectRatio);
|
|
513 |
}
|
|
514 |
mMaxScaleSize = fsSize;
|
|
515 |
mMaxScaleSize.scale(mWindowSize*13, Qt::KeepAspectRatio);
|
|
516 |
mMaxScaleDecSize = fsSize;
|
|
517 |
mMaxScaleDecSize.scale(mWindowSize*7, Qt::KeepAspectRatio);
|
|
518 |
mMinScaleSize = fsSize* 0.7;
|
|
519 |
mMinDecScaleSize = fsSize;
|
|
520 |
}
|
|
521 |
}
|
43
|
522 |
|
|
523 |
|
50
|
524 |
}
|
|
525 |
|
43
|
526 |
|
|
527 |
|
|
528 |
void GlxZoomWidget::animateZoomIn(QPointF animRefPoint)
|
|
529 |
{
|
52
|
530 |
if (isFocussedItemCorrupt()){
|
|
531 |
return;
|
|
532 |
}
|
|
533 |
emit pinchGestureReceived(mFocusIndex);
|
|
534 |
//bring the zoom widget to foreground
|
|
535 |
mZoomOngoing = true;
|
|
536 |
setZValue(mMaxZValue);
|
|
537 |
//show the black background
|
|
538 |
mBlackBackgroundItem->setParentItem(parentItem());
|
|
539 |
mBlackBackgroundItem->setZValue(mMaxZValue - 1);
|
|
540 |
mBlackBackgroundItem->show();
|
|
541 |
m_AnimRefPoint = animRefPoint;
|
43
|
542 |
QSizeF requiredSize = mItemSize;
|
|
543 |
requiredSize.scale(mWindowSize*3.5, Qt::KeepAspectRatio);
|
44
|
544 |
m_FinalAnimatedScaleFactor = requiredSize.width()/mMinDecScaleSize.width();
|
43
|
545 |
m_AnimTimeLine->setDirection(QTimeLine::Forward);
|
|
546 |
m_AnimTimeLine->start();
|
|
547 |
// zoomImage(5, m_AnimRefPoint);
|
|
548 |
|
|
549 |
}
|
|
550 |
void GlxZoomWidget::animateZoomOut(QPointF animRefPoint)
|
|
551 |
{
|
|
552 |
m_AnimRefPoint = animRefPoint;
|
44
|
553 |
m_FinalAnimatedScaleFactor = mMinDecScaleSize.width()/mCurrentSize.width();
|
43
|
554 |
//m_AnimTimeLine->setDirection(QTimeLine::Backward);
|
|
555 |
m_AnimTimeLine->start();
|
|
556 |
}
|
|
557 |
void GlxZoomWidget::animationFrameChanged(int frameNumber)
|
|
558 |
{
|
|
559 |
qreal scaleFactor = 1;
|
|
560 |
if(m_FinalAnimatedScaleFactor > 1) {
|
44
|
561 |
scaleFactor = (1.0 + (((m_FinalAnimatedScaleFactor - 1)/100)*frameNumber))/(mCurrentSize.width()/mMinDecScaleSize.width());
|
43
|
562 |
}
|
|
563 |
if(m_FinalAnimatedScaleFactor < 1) {
|
44
|
564 |
scaleFactor = (m_FinalAnimatedScaleFactor+ (((1 - m_FinalAnimatedScaleFactor)/100)*frameNumber))/(mCurrentSize.width()/mMinDecScaleSize.width());
|
43
|
565 |
}
|
|
566 |
|
|
567 |
zoomImage(scaleFactor, m_AnimRefPoint);
|
|
568 |
|
|
569 |
}
|
|
570 |
void GlxZoomWidget::animationTimeLineFinished()
|
|
571 |
{
|
|
572 |
finalizeWidgetTransform();
|
|
573 |
//push the Zoom widget to background when zoomed image size nears FS image
|
|
574 |
if(mStepCurrentSize.width() <= mMinDecScaleSize.width()*1.3) {
|
|
575 |
mBlackBackgroundItem->hide();
|
|
576 |
//push the widget back to background
|
|
577 |
setZValue(mMinZValue);
|
50
|
578 |
mZoomOngoing = false;
|
43
|
579 |
emit zoomWidgetMovedBackground(mFocusIndex);
|
|
580 |
//do not reset the transform here as it will then zoom-in the widget to decoded image size
|
|
581 |
}
|
|
582 |
}
|
|
583 |
|
44
|
584 |
|
|
585 |
void GlxZoomWidget::timerEvent(QTimerEvent *event)
|
|
586 |
{
|
|
587 |
if(mTimerId == event->timerId())
|
|
588 |
{
|
|
589 |
killTimer(mTimerId);
|
|
590 |
mTimerId = 0;
|
|
591 |
}
|
|
592 |
}
|
52
|
593 |
|
|
594 |
bool GlxZoomWidget::isFocussedItemCorrupt()
|
|
595 |
{
|
|
596 |
QVariant variant = mModel->data( mModel->index( mFocusIndex, 0 ), GlxImageCorruptRole );
|
|
597 |
if ( variant.isValid() && variant.canConvert< bool> () ) {
|
|
598 |
return variant.value< bool > () ;
|
|
599 |
}
|
|
600 |
return false ;
|
|
601 |
}
|
|
602 |
|