imageeditorengine/ImageEditorUtils/src/ResolutionUtil.cpp
changeset 1 edfc90759b9f
equal deleted inserted replaced
0:57d4cdd99204 1:edfc90759b9f
       
     1 /*
       
     2 * Copyright (c) 2010 Ixonos Plc.
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of the "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 * Ixonos Plc
       
    14 *
       
    15 * Description:  
       
    16 * Resolution utility class for Image Editor.
       
    17 *
       
    18 */
       
    19 
       
    20 
       
    21 #include <eikappui.h>
       
    22 #include <AknUtils.h> 
       
    23 
       
    24 #include "ResolutionUtil.h"
       
    25 #include "imageeditordebugutils.h"
       
    26 //#include "ImageEditorUids.hrh"
       
    27 
       
    28 // CONSTANTS
       
    29 const TInt KStandardScreenWidth = 176;
       
    30 const TInt KStandardScreenHeight = 208;
       
    31 
       
    32 const TInt KSquareScreenWidth = 208;
       
    33 const TInt KSquareScreenHeight = 208;
       
    34 
       
    35 const TInt KQVGAScreenWidth = 240;
       
    36 const TInt KQVGAScreenHeight = 320;
       
    37 
       
    38 const TInt KDoubleScreenWidth = 352;
       
    39 const TInt KDoubleScreenHeight = 416;
       
    40 
       
    41 const TInt KHVGAScreenWidth = 320;
       
    42 const TInt KHVGAScreenHeight = 480;
       
    43 
       
    44 const TInt KVGAScreenWidth = 480;
       
    45 const TInt KVGAScreenHeight = 640;
       
    46 
       
    47 const TInt KQHDScreenWidth = 360;
       
    48 const TInt KQHDScreenHeight = 640;
       
    49 
       
    50 #define UID_RESOLUTION_UTIL  0x101FFA91
       
    51 
       
    52 // CCoeStatic-derived class is accessible only inside the 
       
    53 // thread, so the UID does not need to be globally unique.
       
    54 const TUid KUidResolutionUtil = {UID_RESOLUTION_UTIL};
       
    55 
       
    56 _LIT( KComponentName, "CResolutionUtil" );
       
    57 
       
    58 
       
    59 //=============================================================================
       
    60 CResolutionUtil::CResolutionUtil( const TUid& aUid )
       
    61 : CCoeStatic( aUid ),
       
    62   iScreenRect(0,0,0,0),
       
    63   iClientRect(0,0,0,0),
       
    64   iLandscape(EFalse),
       
    65   iFullScreen(EFalse)
       
    66     {
       
    67 
       
    68     }
       
    69 
       
    70 //=============================================================================
       
    71 EXPORT_C CResolutionUtil::~CResolutionUtil()
       
    72 {
       
    73     LOG(KImageEditorLogFile, "CResolutionUtil::~CResolutionUtil()");
       
    74 }
       
    75 
       
    76 //=============================================================================
       
    77 EXPORT_C CResolutionUtil* CResolutionUtil::Self()
       
    78 {
       
    79     CResolutionUtil* self = static_cast<CResolutionUtil *>( CCoeEnv::Static (KUidResolutionUtil) );
       
    80     __ASSERT_ALWAYS( self, User::Panic(KComponentName,KErrNotFound) );
       
    81     return self;
       
    82 }
       
    83 
       
    84 //=============================================================================
       
    85 EXPORT_C CResolutionUtil* CResolutionUtil::InitializeL()
       
    86 {
       
    87     LOG(KImageEditorLogFile, "CResolutionUtil::InitializeL()");
       
    88 
       
    89     // First check if this already exists
       
    90     CResolutionUtil* self = static_cast<CResolutionUtil *>( CCoeEnv::Static (KUidResolutionUtil) );
       
    91     
       
    92     // If not, create new instance
       
    93     if ( !self )
       
    94     {
       
    95         self = new (ELeave) CResolutionUtil( KUidResolutionUtil );
       
    96         LOG(KImageEditorLogFile, "CResolutionUtil::InitializeL(): created new instance");
       
    97     }
       
    98 
       
    99     return self;
       
   100 }
       
   101     
       
   102 //=============================================================================
       
   103 EXPORT_C TInt CResolutionUtil::ScreenMode() const
       
   104     {
       
   105 
       
   106     TInt screenMode = EUnknown;
       
   107     TSize screenSize = iScreenRect.Size();
       
   108 
       
   109     if (!iLandscape)
       
   110         {
       
   111         switch (screenSize.iWidth)
       
   112             {
       
   113             // Standard
       
   114             case KStandardScreenWidth:
       
   115                 {
       
   116                 if (screenSize.iHeight == KStandardScreenHeight)
       
   117                     {
       
   118                     if (!iFullScreen)
       
   119                         {
       
   120                         screenMode = EStandard;
       
   121                         }                     
       
   122                     else
       
   123                         {
       
   124                         screenMode = EStandardFullScreen;
       
   125                         }
       
   126                     }
       
   127                 break;
       
   128                 }
       
   129             // Square
       
   130             case KSquareScreenWidth:
       
   131                 {
       
   132                 if (screenSize.iHeight == KSquareScreenHeight)
       
   133                     {
       
   134                     if (!iFullScreen)
       
   135                         {
       
   136                         screenMode = ESquare;
       
   137                         }                     
       
   138                     else
       
   139                         {
       
   140                         screenMode = ESquareFullScreen;
       
   141                         }
       
   142                     }
       
   143                 break;
       
   144                 }
       
   145             // QVGA
       
   146             case KQVGAScreenWidth:
       
   147                 {
       
   148                 if (screenSize.iHeight == KQVGAScreenHeight)
       
   149                     {
       
   150                     if (!iFullScreen)
       
   151                         {
       
   152                         screenMode = EQVGA;
       
   153                         }
       
   154                     else
       
   155                         {
       
   156                         screenMode = EQVGAFullScreen;
       
   157                         }
       
   158                     }
       
   159                 break;
       
   160                 }
       
   161             // Double
       
   162             case KDoubleScreenWidth:
       
   163                 {
       
   164                 if (screenSize.iHeight == KDoubleScreenHeight)
       
   165                     {
       
   166                     if (!iFullScreen)
       
   167                         {
       
   168                         screenMode = EDouble;
       
   169                         }
       
   170                     else
       
   171                         {
       
   172                         screenMode = EDoubleFullScreen;
       
   173                         }
       
   174                     }
       
   175                 break;
       
   176                 }
       
   177             // Unknown
       
   178             default:
       
   179                 {
       
   180                 screenMode = EUnknown;
       
   181                 break;
       
   182                 }
       
   183             }
       
   184         }
       
   185     else
       
   186         {
       
   187         // Landscape iHeight == normal iWidth
       
   188         switch (screenSize.iHeight)
       
   189             {
       
   190             // Standard, landscape
       
   191             case KStandardScreenWidth:
       
   192                 {
       
   193                 if (screenSize.iWidth == KStandardScreenHeight)
       
   194                     {
       
   195                     if (!iFullScreen)
       
   196                         {
       
   197                         screenMode = EStandardLandscape;
       
   198                         }                     
       
   199                     else
       
   200                         {
       
   201                         screenMode = EStandardLandscapeFullScreen;
       
   202                         }
       
   203                     }
       
   204                 break;
       
   205                 }
       
   206             // Square, rotated
       
   207             case KSquareScreenWidth:
       
   208                 {
       
   209                 if (screenSize.iWidth == KSquareScreenHeight)
       
   210                     {
       
   211                     if (!iFullScreen)
       
   212                         {
       
   213                         screenMode = ESquareRotated;
       
   214                         }                     
       
   215                     else
       
   216                         {
       
   217                         screenMode = ESquareRotatedFullScreen;
       
   218                         }
       
   219                     }
       
   220                 break;
       
   221                 }
       
   222             // QVGA, landscape
       
   223             case KQVGAScreenWidth:
       
   224                 {
       
   225                 if (screenSize.iWidth == KQVGAScreenHeight)
       
   226                     {
       
   227                     if (!iFullScreen)
       
   228                         {
       
   229                         screenMode = EQVGALandscape;
       
   230                         }
       
   231                     else
       
   232                         {
       
   233                         screenMode = EQVGALandscapeFullScreen;
       
   234                         }
       
   235                     }
       
   236                 break;
       
   237                 }
       
   238             // Double, landscape
       
   239             case KDoubleScreenWidth:
       
   240                 {
       
   241                 if (screenSize.iWidth == KDoubleScreenHeight)
       
   242                     {
       
   243                     if (!iFullScreen)
       
   244                         {
       
   245                         screenMode = EDoubleLandscape;
       
   246                         }
       
   247                     else
       
   248                         {
       
   249                         screenMode = EDoubleLandscapeFullScreen;
       
   250                         }
       
   251                     }
       
   252                 break;
       
   253                 }
       
   254             // Unknown
       
   255             default:
       
   256                 {
       
   257                 screenMode = EUnknown;
       
   258                 break;
       
   259                 }
       
   260             }
       
   261 
       
   262         }
       
   263 
       
   264     return screenMode;
       
   265     }
       
   266 
       
   267 //=============================================================================
       
   268 EXPORT_C TInt CResolutionUtil::GetScreenMode() const
       
   269     {
       
   270     TInt screenMode = EUnknown;
       
   271     TSize screenSize = iScreenRect.Size();
       
   272     
       
   273     // Standard (Portrait)
       
   274     if ( screenSize.iWidth == KStandardScreenWidth &&
       
   275          screenSize.iHeight == KStandardScreenHeight )
       
   276         {
       
   277         if (!iFullScreen)
       
   278             {
       
   279             screenMode = EStandard;
       
   280             }
       
   281         else
       
   282             {
       
   283             screenMode = EStandardFullScreen;
       
   284             }
       
   285         }
       
   286     // Square (Portrait)
       
   287     else if ( screenSize.iWidth == KSquareScreenWidth &&
       
   288               screenSize.iHeight == KSquareScreenHeight )
       
   289         {
       
   290         if (!iFullScreen)
       
   291             {
       
   292             screenMode = ESquare;
       
   293             }
       
   294         else
       
   295             {
       
   296             screenMode = ESquareFullScreen;
       
   297             }
       
   298         }
       
   299     // QVGA (Portrait)
       
   300     else if ( screenSize.iWidth == KQVGAScreenWidth &&
       
   301               screenSize.iHeight == KQVGAScreenHeight )
       
   302         {
       
   303         if (!iFullScreen)
       
   304             {
       
   305             screenMode = EQVGA;
       
   306             }
       
   307         else
       
   308             {
       
   309             screenMode = EQVGAFullScreen;
       
   310             }
       
   311         }
       
   312     // Double (Portrait)
       
   313     else if ( screenSize.iWidth == KDoubleScreenWidth &&
       
   314           screenSize.iHeight == KDoubleScreenHeight )
       
   315         {
       
   316         if (!iFullScreen)
       
   317             {
       
   318             screenMode = EDouble;
       
   319             }
       
   320         else
       
   321             {
       
   322             screenMode = EDoubleFullScreen;
       
   323             }
       
   324         }
       
   325     // HVGA (Portrait) 
       
   326     else if ( screenSize.iWidth == KHVGAScreenWidth &&
       
   327               screenSize.iHeight == KHVGAScreenHeight )
       
   328         {
       
   329         if (!iFullScreen)
       
   330             {
       
   331             screenMode = EHVGA;
       
   332             }
       
   333         else
       
   334             {
       
   335             screenMode = EHVGAFullScreen;
       
   336             }
       
   337         }
       
   338     // VGA (Portrait)
       
   339     else if ( screenSize.iWidth == KVGAScreenWidth &&
       
   340               screenSize.iHeight == KVGAScreenHeight )
       
   341         {
       
   342         if (!iFullScreen)
       
   343             {
       
   344             screenMode = EVGA;
       
   345             }
       
   346         else
       
   347             {
       
   348             screenMode = EVGAFullScreen;
       
   349             }
       
   350         }
       
   351     // QHD (Portrait)
       
   352     else if ( screenSize.iWidth == KQHDScreenWidth &&
       
   353               screenSize.iHeight == KQHDScreenHeight )
       
   354         {
       
   355         if (!iFullScreen)
       
   356             {
       
   357             screenMode = EQHD;
       
   358             }
       
   359         else
       
   360             {
       
   361             screenMode = EQHDFullScreen;
       
   362             }
       
   363         }    
       
   364     // Standard (Landscape)
       
   365     else if ( screenSize.iWidth == KStandardScreenHeight &&
       
   366          screenSize.iHeight == KStandardScreenWidth )
       
   367         {
       
   368         if (!iFullScreen)
       
   369             {
       
   370             screenMode = EStandardLandscape;
       
   371             }
       
   372         else
       
   373             {
       
   374             screenMode = EStandardLandscapeFullScreen;
       
   375             }
       
   376         }
       
   377     // Square (Landscape)
       
   378     else if ( screenSize.iWidth == KSquareScreenHeight &&
       
   379               screenSize.iHeight == KSquareScreenWidth )
       
   380         {
       
   381         if (!iFullScreen)
       
   382             {
       
   383             screenMode = ESquareRotated;
       
   384             }
       
   385         else
       
   386             {
       
   387             screenMode = ESquareRotatedFullScreen;
       
   388             }
       
   389         }
       
   390     // QVGA (Landscape)
       
   391     else if ( screenSize.iWidth == KQVGAScreenHeight &&
       
   392               screenSize.iHeight == KQVGAScreenWidth )
       
   393         {
       
   394         if (!iFullScreen)
       
   395             {
       
   396             screenMode = EQVGALandscape;
       
   397             }
       
   398         else
       
   399             {
       
   400             screenMode = EQVGALandscapeFullScreen;
       
   401             }
       
   402         }
       
   403     // Double (Landscape)
       
   404     else if ( screenSize.iWidth == KDoubleScreenHeight &&
       
   405           screenSize.iHeight == KDoubleScreenWidth )
       
   406         {
       
   407         if (!iFullScreen)
       
   408             {
       
   409             screenMode = EDoubleLandscape;
       
   410             }
       
   411         else
       
   412             {
       
   413             screenMode = EDoubleLandscapeFullScreen;
       
   414             }
       
   415         }
       
   416     // HVGA (Landscape)
       
   417     else if ( screenSize.iWidth == KHVGAScreenHeight &&
       
   418               screenSize.iHeight == KHVGAScreenWidth )
       
   419         {
       
   420         if (!iFullScreen)
       
   421             {
       
   422             screenMode = EHVGALandscape;
       
   423             }
       
   424         else
       
   425             {
       
   426             screenMode = EHVGALandscapeFullScreen;
       
   427             }
       
   428         }
       
   429     // VGA (Landscape)
       
   430     else if ( screenSize.iWidth == KVGAScreenHeight &&
       
   431               screenSize.iHeight == KVGAScreenWidth )
       
   432         {
       
   433         if (!iFullScreen)
       
   434             {
       
   435             screenMode = EVGALandscape;
       
   436             }
       
   437         else
       
   438             {
       
   439             screenMode = EVGALandscapeFullScreen;
       
   440             }
       
   441         }
       
   442     // QHD (Landscape)
       
   443     else if ( screenSize.iWidth == KQHDScreenHeight &&
       
   444               screenSize.iHeight == KQHDScreenWidth )
       
   445         {
       
   446         if (!iFullScreen)
       
   447             {
       
   448             screenMode = EQHDLandscape;
       
   449             }
       
   450         else
       
   451             {
       
   452             screenMode = EQHDLandscapeFullScreen;
       
   453             }
       
   454         }    
       
   455     // Unknown    
       
   456     else 
       
   457         {
       
   458         screenMode = EUnknown;
       
   459         }
       
   460          
       
   461     return screenMode;                         
       
   462     }
       
   463     
       
   464 //=============================================================================
       
   465 EXPORT_C void CResolutionUtil::GetClientRect(TRect& aRect) const
       
   466     {
       
   467     aRect = iClientRect; 
       
   468     }
       
   469 
       
   470 //=============================================================================
       
   471 EXPORT_C void CResolutionUtil::SetClientRect(const TRect& aRect)
       
   472     {
       
   473     iClientRect = aRect; 
       
   474     }
       
   475 
       
   476 //=============================================================================
       
   477 EXPORT_C void CResolutionUtil::GetScreenRect(TRect& aRect) const
       
   478     {
       
   479     aRect = iScreenRect; 
       
   480     }
       
   481 
       
   482 //=============================================================================
       
   483 EXPORT_C void CResolutionUtil::SetScreenRect(const TRect& aRect) 
       
   484     {
       
   485     iScreenRect = aRect; 
       
   486     }
       
   487 
       
   488 //=============================================================================
       
   489 EXPORT_C void CResolutionUtil::SetFullScreen(TBool aFullScreen)
       
   490     {
       
   491     iFullScreen = aFullScreen; 
       
   492     }
       
   493 
       
   494 //=============================================================================
       
   495 EXPORT_C TBool CResolutionUtil::GetFullScreen() const
       
   496     {
       
   497     return iFullScreen; 
       
   498     }
       
   499 
       
   500 //=============================================================================
       
   501 EXPORT_C void CResolutionUtil::SetLandscape(TBool aLandscape)
       
   502     {
       
   503     iLandscape = aLandscape; 
       
   504     }
       
   505 
       
   506 //=============================================================================
       
   507 EXPORT_C TBool CResolutionUtil::GetLandscape() const
       
   508     {
       
   509     return iLandscape; 
       
   510     }
       
   511 
       
   512 //=============================================================================
       
   513 EXPORT_C void CResolutionUtil::UpdateScreenMode()
       
   514     {
       
   515     LOG(KImageEditorLogFile, "CResolutionUtil::UpdateScreenMode()");
       
   516 
       
   517     AknLayoutUtils::LayoutMetricsRect(AknLayoutUtils::EScreen, iScreenRect);
       
   518     //iScreenRect.SetRect(0,0,352,416);
       
   519 
       
   520     if (iFullScreen)
       
   521         {
       
   522         iClientRect = iScreenRect;
       
   523         }
       
   524     else 
       
   525         {
       
   526         AknLayoutUtils::LayoutMetricsRect(AknLayoutUtils::EMainPane, iClientRect);
       
   527         }
       
   528 
       
   529     LOGFMT2(KImageEditorLogFile, "CResolutionUtil: Screen dimensions: W:%d, H:%d", iScreenRect.Width(), iScreenRect.Height());
       
   530     LOGFMT4(KImageEditorLogFile, "  ClientRect: iTl.iX:%d, iTl.iY:%d, iBr.iX:%d, iBr.iY:%d", iClientRect.iTl.iX, iClientRect.iTl.iY, iClientRect.iBr.iX, iClientRect.iBr.iY);
       
   531     LOGFMT2(KImageEditorLogFile, "  Full screen: %d, Landscape mode: %d", iFullScreen, iLandscape);
       
   532     }
       
   533 
       
   534 // End of File