photosgallery/viewframework/views/zoomview/src/glxzoomcontrol.cpp
changeset 1 9ba538e329bd
parent 0 4e91876724a2
child 2 7d9067c6fcb1
equal deleted inserted replaced
0:4e91876724a2 1:9ba538e329bd
   193 
   193 
   194     iImageVisual = CAlfImageVisual::AddNewL(*this,iViewPort);
   194     iImageVisual = CAlfImageVisual::AddNewL(*this,iViewPort);
   195     iImageVisual->SetScaleMode(CAlfImageVisual::EScaleFitInside);
   195     iImageVisual->SetScaleMode(CAlfImageVisual::EScaleFitInside);
   196 
   196 
   197     iEventHandler = CGlxZoomPanEventHandler::NewL(*this);
   197     iEventHandler = CGlxZoomPanEventHandler::NewL(*this);
   198     
       
   199     }
   198     }
   200 
   199 
   201 // -----------------------------------------------------------------------------
   200 // -----------------------------------------------------------------------------
   202 // CGlxZoomControl::NewL
   201 // CGlxZoomControl::NewL
   203 // Two-phased constructor.
   202 // Two-phased constructor.
   273     if ( !iZoomActive )
   272     if ( !iZoomActive )
   274         {
   273         {
   275         //This Varaiable updates that we are in zoom state now.
   274         //This Varaiable updates that we are in zoom state now.
   276         iZoomActive = ETrue;
   275         iZoomActive = ETrue;
   277         //To Retrive the image details
   276         //To Retrive the image details
   278         TMPXAttribute thumbNailAttribute(0,0);        
   277         TMPXAttribute thumbNailAttribute(0,0);
       
   278 
   279         TGlxIdSpaceId idspace = iMediaList.IdSpaceId( aFocusIndex );
   279         TGlxIdSpaceId idspace = iMediaList.IdSpaceId( aFocusIndex );
   280         //Get the texture Created in fullscreen View.
   280         //Get the texture Created in fullscreen View.
   281         iImageTexture = &(iTextureMgr->CreateNewTextureForMediaL(
   281         iImageTexture = &(iTextureMgr->CreateNewTextureForMediaL(
   282               ScreenSize(),aItem, idspace, this ));
   282                 ScreenSize(),aItem, idspace, this ));
   283         iImageVisual->SetImage(*iImageTexture);         
   283         iImageVisual->SetImage(*iImageTexture);
   284         
   284         
   285         if(iGlxTvOut->IsConnected())
   285         if(iGlxTvOut->IsConnected())
   286             {
   286             {
   287             StartZoomAnimation();
   287             StartZoomAnimation();
   288             }
   288             }
   290             {
   290             {
   291             ShowZoom(ETrue);
   291             ShowZoom(ETrue);
   292             iZoomSliderWidget.AddEventHandler(*this);
   292             iZoomSliderWidget.AddEventHandler(*this);
   293             iZoomSliderWidget.SetHandleKeyEvent(EFalse);
   293             iZoomSliderWidget.SetHandleKeyEvent(EFalse);
   294             iZoomSliderModel = (IMulSliderModel*) iZoomSliderWidget.model();
   294             iZoomSliderModel = (IMulSliderModel*) iZoomSliderWidget.model();
   295         // Get size, return value tells us if it was available
   295             // Get size, return value tells us if it was available
   296         //We need this Value to calculate the size of the visual/Layout corresponding to the Zoom factor
   296             //We need this Value to calculate the size of the visual/Layout corresponding to the Zoom factor
   297         TSize imageSize;
   297             TSize imageSize;
   298         aItem.GetDimensions( imageSize );
   298             aItem.GetDimensions( imageSize );
   299         TSize maxVirtualImageSize = imageSize;
   299             TSize maxVirtualImageSize = imageSize;
   300 
   300     
   301         if (KGlxDecodingThreshold < (imageSize.iWidth * imageSize.iHeight))
   301             if (KGlxDecodingThreshold < (imageSize.iWidth * imageSize.iHeight))
   302             {
   302                 {
   303             TReal areaRatio = TReal(imageSize.iWidth*imageSize.iHeight)/KGlxDecodingThreshold ;
   303                 TReal areaRatio = TReal(imageSize.iWidth*imageSize.iHeight)/KGlxDecodingThreshold ;
       
   304                 
       
   305                 TReal sideRatio;
       
   306                 Math::Sqrt(sideRatio, areaRatio);
       
   307                 
       
   308                 maxVirtualImageSize.iHeight = imageSize.iHeight /  sideRatio ;
       
   309                 maxVirtualImageSize.iWidth  = imageSize.iWidth  /  sideRatio ;
       
   310                 }
   304             
   311             
   305             TReal sideRatio;
   312             // Now since our maximum size possible is 3 MP. all our zoom percentages will be relative to it. 
   306             Math::Sqrt(sideRatio, areaRatio);
   313             // So our initial zoom ratio will be different and cnsequently our minimum slider value too will change. 
   307 
   314             // Maximum is an
       
   315             TInt initialZoomRatio = GetInitialZoomLevel(maxVirtualImageSize);
       
   316             iZoomSliderModel->SetMinRange(initialZoomRatio);
       
   317     
       
   318             iEventHandler->SetZoomActivated(ETrue);
       
   319             iEventHandler->ActivateZoom(initialZoomRatio,
       
   320                     maxVirtualImageSize,
       
   321                     aStartMode,
       
   322                     iZoomSliderModel->MinRange(), 
       
   323                     iZoomSliderModel->MaxRange(),
       
   324                     maxVirtualImageSize,
       
   325                     aZoomFocus);
   308             
   326             
   309             maxVirtualImageSize.iHeight = imageSize.iHeight /  sideRatio ;
   327             TRAP_IGNORE(iImageTexture = 
   310             maxVirtualImageSize.iWidth  = imageSize.iWidth  /  sideRatio ;
   328             &(iTextureMgr->CreateZoomedTextureL(aItem,thumbNailAttribute,idspace,this)));
   311 
   329            
   312             }
   330             //This is for handling the alaram interrupt events,that causes the phone to freeze.
   313         
   331             CEikButtonGroupContainer* cba = CEikButtonGroupContainer::Current();
   314         TInt initialZoomRatio = GetIntialZoomLevel(maxVirtualImageSize);
   332             if (NULL != cba)
   315         iZoomSliderModel->SetMinRange(initialZoomRatio);
       
   316 
       
   317         iEventHandler->SetZoomActivated(ETrue);
       
   318         iEventHandler->ActivateZoom(initialZoomRatio,
       
   319                 maxVirtualImageSize,
       
   320                 aStartMode,
       
   321                 iZoomSliderModel->MinRange(), 
       
   322                 iZoomSliderModel->MaxRange(),
       
   323                 maxVirtualImageSize,
       
   324                 aZoomFocus);
       
   325         
       
   326         TRAP_IGNORE(iImageTexture = 
       
   327         &(iTextureMgr->CreateZoomedTextureL(aItem,thumbNailAttribute,idspace,this)));
       
   328        
       
   329         //This is for handling the alaram interrupt events,that causes the phone to freeze.
       
   330         CEikButtonGroupContainer* cba = CEikButtonGroupContainer::Current();
       
   331         if (NULL != cba)
       
   332             {
       
   333             if (cba->IsVisible())
       
   334                 {
   333                 {
   335                 cba->ActivateL();
   334                 if (cba->IsVisible())
       
   335                     {
       
   336                     cba->ActivateL();
       
   337                     }
   336                 }
   338                 }
   337             }
   339             }
   338         }
   340         }
   339     }
   341     }
   340 }
       
   341 // ---------------------------------------------------------------------------
   342 // ---------------------------------------------------------------------------
   342 // StartZoomAnimation
   343 // StartZoomAnimation
   343 // ---------------------------------------------------------------------------
   344 // ---------------------------------------------------------------------------
   344 // 
   345 // 
   345 void CGlxZoomControl::StartZoomAnimation()
   346 void CGlxZoomControl::StartZoomAnimation()
   431 // ----------------------------------------------------------------------------------
   432 // ----------------------------------------------------------------------------------
   432 //
   433 //
   433 EXPORT_C void CGlxZoomControl::HandleZoomForegroundEvent(TBool aForeground)
   434 EXPORT_C void CGlxZoomControl::HandleZoomForegroundEvent(TBool aForeground)
   434     {
   435     {
   435     TRACER("CGlxZoomControl::HandleZoomForegroundEventL()");
   436     TRACER("CGlxZoomControl::HandleZoomForegroundEventL()");
       
   437 
       
   438     //Refeed the textures if we are coming back to foreground from background
       
   439     //To Retrive the image details
       
   440     TMPXAttribute thumbNailAttribute(0,0);
       
   441     TInt focusIndex = iMediaList.FocusIndex();
       
   442     TGlxIdSpaceId idspace = iMediaList.IdSpaceId( focusIndex );
       
   443     //Get the texture Created in fullscreen View.
       
   444     TGlxMedia item = iMediaList.Item( focusIndex );
       
   445     
   436     if (!aForeground)
   446     if (!aForeground)
   437         {
   447         {
   438         iEventHandler->CancelZoomPanTimer();
   448         iEventHandler->CancelZoomPanTimer();
       
   449         iEventHandler->CancelUITimer();
       
   450         iEventHandler->CancelAnimationTimer();
       
   451         }
       
   452     else
       
   453         {
       
   454         // if we already have the decoded zoomed image bitmap use the texture corresponding to that.
       
   455         // Else make do with the fullscreen texture till that happens.  
       
   456         TRAP_IGNORE(iImageTexture = 
       
   457             iTextureMgr->CreateZoomedTextureL());
       
   458         
       
   459         if (NULL == iImageTexture)
       
   460             {
       
   461             iImageTexture = &(iTextureMgr->CreateNewTextureForMediaL(
       
   462                     ScreenSize(),item, idspace, this ));
       
   463             }
       
   464 
       
   465         iImageVisual->SetImage(*iImageTexture);
   439         }
   466         }
   440     } 
   467     } 
   441 
   468 
   442 // -----------------------------------------------------------------------------
   469 // -----------------------------------------------------------------------------
   443 // CleanUpVisual:reset the values of the variables.
   470 // CleanUpVisual:reset the values of the variables.
   502     TRACER("CGlxZoomControl::TextureContentChangedL ");
   529     TRACER("CGlxZoomControl::TextureContentChangedL ");
   503     //if both the textures are null that means we do not have memory to 
   530     //if both the textures are null that means we do not have memory to 
   504     //decode and show anything. So try and check if the fullscreen texture 
   531     //decode and show anything. So try and check if the fullscreen texture 
   505     //is created by now if not then go to fullscreen view.
   532     //is created by now if not then go to fullscreen view.
   506 
   533 
   507     if(aNewTexture == NULL)
   534     if(NULL == aNewTexture )
   508         {
   535         {
   509         if(iImageTexture == NULL)
   536         if(NULL == iImageTexture)
   510             {
   537             {
   511             TSize TextureSize = ScreenSize();
   538             TSize TextureSize = ScreenSize();
   512             TInt focus = iMediaList.FocusIndex();
   539             TInt focus = iMediaList.FocusIndex();
   513             TGlxMedia item = iMediaList.Item( focus );
   540             TGlxMedia item = iMediaList.Item( focus );
   514             TGlxIdSpaceId idspace = iMediaList.IdSpaceId( focus );
   541             TGlxIdSpaceId idspace = iMediaList.IdSpaceId( focus );
   816             break;
   843             break;
   817         }
   844         }
   818     iEventHandler->SetPreviousEventCode(code);
   845     iEventHandler->SetPreviousEventCode(code);
   819     }
   846     }
   820 
   847 
   821 TInt CGlxZoomControl::GetIntialZoomLevel(TSize& aSize )
   848 // -----------------------------------------------------------------------------
   822     {
   849 // GetInitialZoomLevel
   823     TRACER("CGlxZoomControl::IntialZoomLevel");
   850 // -----------------------------------------------------------------------------
       
   851 //
       
   852 TInt CGlxZoomControl::GetInitialZoomLevel(TSize& aSize )
       
   853     {
       
   854     TRACER("CGlxZoomControl::InitialZoomLevel");
   824 
   855 
   825     TRect rect = AlfUtil::ScreenSize();
   856     TRect rect = AlfUtil::ScreenSize();
   826     TUint8 initialZoomLevel;
   857     TUint8 initialZoomLevel;
   827 
   858 
   828     if( rect.Width()>= aSize.iWidth && rect.Height() >= aSize.iHeight)
   859     if( rect.Width()>= aSize.iWidth && rect.Height() >= aSize.iHeight)