meetingrequest/mrgui/mrfieldbuilderplugin/src/cesmrvieweralarmfield.cpp
changeset 0 8466d47a6819
child 16 4ce476e64c59
equal deleted inserted replaced
-1:000000000000 0:8466d47a6819
       
     1 /*
       
     2 * Copyright (c) 2007-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:  ESMR UI Container class
       
    15 *
       
    16 */
       
    17 
       
    18 #include "cesmrvieweralarmfield.h"
       
    19 #include "cesmreditor.h"
       
    20 #include "cmrlabel.h"
       
    21 #include "cmrimage.h"
       
    22 #include "nmrlayoutmanager.h"
       
    23 
       
    24 #include <caluser.h>
       
    25 #include <calalarm.h>
       
    26 #include <calentry.h>
       
    27 #include <StringLoader.h>
       
    28 #include <AknLayout2ScalableDef.h>
       
    29 #include <esmrgui.rsg>
       
    30 
       
    31 // DEBUG
       
    32 #include "emailtrace.h"
       
    33 
       
    34 // Unnamed namespace for local definitions
       
    35 namespace{ //codescanner::namespace
       
    36 
       
    37 const TInt KHourInMinutes(60);
       
    38 const TInt KDayInMinutes(1440);
       
    39 
       
    40 }//namespace
       
    41 
       
    42 // ======== MEMBER FUNCTIONS ========
       
    43 
       
    44 // ---------------------------------------------------------------------------
       
    45 // CESMRViewerAlarmField::NewL()
       
    46 // ---------------------------------------------------------------------------
       
    47 //
       
    48 CESMRViewerAlarmField* CESMRViewerAlarmField::NewL()
       
    49     {
       
    50     FUNC_LOG;
       
    51     CESMRViewerAlarmField* self = new (ELeave) CESMRViewerAlarmField();
       
    52     CleanupStack::PushL( self );
       
    53     self->ConstructL();
       
    54     CleanupStack::Pop( self );
       
    55     return self;
       
    56     }
       
    57 
       
    58 // ---------------------------------------------------------------------------
       
    59 // CESMRViewerAlarmField::~CESMRViewerAlarmField()
       
    60 // ---------------------------------------------------------------------------
       
    61 //
       
    62 CESMRViewerAlarmField::~CESMRViewerAlarmField()
       
    63     {
       
    64     FUNC_LOG;
       
    65     delete iIcon;
       
    66     delete iLabel;
       
    67     }
       
    68 
       
    69 // ---------------------------------------------------------------------------
       
    70 // CESMRViewerAlarmField::CESMRViewerAlarmField()
       
    71 // ---------------------------------------------------------------------------
       
    72 //
       
    73 CESMRViewerAlarmField::CESMRViewerAlarmField()
       
    74     {
       
    75     FUNC_LOG;
       
    76     SetFieldId ( EESMRFieldAlarm );
       
    77     }
       
    78 
       
    79 // ---------------------------------------------------------------------------
       
    80 // CESMRViewerAlarmField::ConstructL()
       
    81 // ---------------------------------------------------------------------------
       
    82 //
       
    83 void CESMRViewerAlarmField::ConstructL()
       
    84     {
       
    85     FUNC_LOG;
       
    86     iLabel = CMRLabel::NewL();
       
    87     iLabel->SetParent( this );
       
    88     iIcon = CMRImage::NewL( KAknsIIDQgnMeetReqIndiAlarm );
       
    89     iIcon->SetParent( this );
       
    90     
       
    91     SetFocusType( EESMRHighlightFocus );
       
    92     }
       
    93 
       
    94 // ---------------------------------------------------------------------------
       
    95 // CESMRViewerAlarmField::InternalizeL()
       
    96 // ---------------------------------------------------------------------------
       
    97 //
       
    98 void CESMRViewerAlarmField::InternalizeL( MESMRCalEntry& aEntry )
       
    99     {
       
   100     FUNC_LOG;
       
   101     if ( aEntry.IsAllDayEventL() )
       
   102         {
       
   103         iObserver->RemoveControl( FieldId() );
       
   104         }
       
   105     else
       
   106         {
       
   107         CCalAlarm* alarm = aEntry.Entry().AlarmL();
       
   108         TInt minutes(0);
       
   109         HBufC* stringholder;
       
   110         if( alarm )
       
   111             {
       
   112             minutes = alarm->TimeOffset().Int();
       
   113             delete alarm;
       
   114             alarm = NULL;
       
   115             }
       
   116         else
       
   117             {
       
   118             stringholder = StringLoader::LoadLC( 
       
   119                     R_QTN_MEET_REQ_ALARM_OFF , iEikonEnv );
       
   120             iLabel->SetTextL( *stringholder );
       
   121             CleanupStack::PopAndDestroy( stringholder );
       
   122             return;
       
   123             }
       
   124 
       
   125         // time units can be minutes, hours or days
       
   126         TInt timeUnits(0);
       
   127 
       
   128         // Alarm is one hour before
       
   129         if( minutes == KHourInMinutes )
       
   130             {
       
   131             timeUnits = minutes / KHourInMinutes;
       
   132             stringholder = StringLoader::LoadLC( 
       
   133                     R_QTN_MEET_REQ_ALARM_HOUR , timeUnits, iEikonEnv );
       
   134             }
       
   135         // Alarm time is more than one hour and less than one day before
       
   136         else if( minutes > KHourInMinutes && minutes < KDayInMinutes )
       
   137             {
       
   138             timeUnits = minutes / KHourInMinutes;
       
   139             stringholder = StringLoader::LoadLC( 
       
   140                     R_QTN_MEET_REQ_ALARM_HOURS , timeUnits, iEikonEnv );
       
   141             }
       
   142         // Alarm is several days before // 
       
   143         else if( minutes >= KDayInMinutes )
       
   144             {
       
   145             timeUnits = minutes / KDayInMinutes;
       
   146             stringholder = StringLoader::LoadLC( 
       
   147                     R_QTN_MEET_REQ_ALARM_DAYS , timeUnits, iEikonEnv );
       
   148             }
       
   149         // Alarm is minutes before // 
       
   150         else
       
   151             {
       
   152             stringholder = StringLoader::LoadLC( 
       
   153                     R_QTN_MEET_REQ_ALARM_MINUTES , minutes, iEikonEnv );
       
   154             }
       
   155 
       
   156         iLabel->SetTextL( *stringholder );
       
   157         CleanupStack::PopAndDestroy( stringholder );
       
   158         }
       
   159     }
       
   160 
       
   161 // ---------------------------------------------------------------------------
       
   162 // CESMRViewerAlarmField::InitializeL()
       
   163 // ---------------------------------------------------------------------------
       
   164 //
       
   165 void CESMRViewerAlarmField::InitializeL()
       
   166     {
       
   167     FUNC_LOG;
       
   168     TAknLayoutText text = NMRLayoutManager::GetLayoutText( 
       
   169             Rect(), 
       
   170             NMRLayoutManager::EMRTextLayoutTextEditor );
       
   171     
       
   172     iLabel->SetFont( text.Font() );
       
   173     // This is called so that theme changes will apply when changing theme "on the fly"
       
   174     if ( IsFocused() )
       
   175         {
       
   176         iLabel->FocusChanged( EDrawNow );
       
   177         }
       
   178 
       
   179     AknLayoutUtils::OverrideControlColorL ( *iLabel, EColorLabelText,
       
   180                                              KRgbBlack );
       
   181     }
       
   182 
       
   183 // ---------------------------------------------------------------------------
       
   184 // CESMRViewerAlarmField::SizeChanged()
       
   185 // ---------------------------------------------------------------------------
       
   186 //
       
   187 void CESMRViewerAlarmField::SizeChanged()
       
   188     {
       
   189     FUNC_LOG;
       
   190     TRect rect = Rect();
       
   191     TAknLayoutRect rowLayoutRect =
       
   192         NMRLayoutManager::GetFieldRowLayoutRect( rect, 1 );
       
   193     rect = rowLayoutRect.Rect();
       
   194     
       
   195     TAknWindowComponentLayout iconLayout =
       
   196         NMRLayoutManager::GetWindowComponentLayout( 
       
   197                 NMRLayoutManager::EMRLayoutTextEditorIcon );
       
   198     AknLayoutUtils::LayoutImage( iIcon, rect, iconLayout );
       
   199     
       
   200     TAknLayoutRect bgLayoutRect =
       
   201         NMRLayoutManager::GetLayoutRect( 
       
   202                 rect, NMRLayoutManager::EMRLayoutTextEditorBg );
       
   203     TRect bgRect( bgLayoutRect.Rect() );
       
   204     // Move focus rect so that it's relative to field's position.
       
   205     bgRect.Move( -Position() );
       
   206     SetFocusRect( bgRect );
       
   207     
       
   208     TAknLayoutText labelLayout = 
       
   209         NMRLayoutManager::GetLayoutText( 
       
   210                 rect, NMRLayoutManager::EMRTextLayoutTextEditor );
       
   211     iLabel->SetRect( labelLayout.TextRect() );
       
   212     }
       
   213 
       
   214 // ---------------------------------------------------------------------------
       
   215 // CESMRViewerAlarmField::CountComponentControls()
       
   216 // ---------------------------------------------------------------------------
       
   217 //
       
   218 TInt CESMRViewerAlarmField::CountComponentControls() const
       
   219     {
       
   220     FUNC_LOG;
       
   221     TInt count( 0 );
       
   222     if ( iIcon )
       
   223         {
       
   224         ++count;
       
   225         }
       
   226 
       
   227     if ( iLabel )
       
   228         {
       
   229         ++count;
       
   230         }
       
   231     return count;
       
   232     }
       
   233 
       
   234 // ---------------------------------------------------------------------------
       
   235 // CESMRViewerAlarmField::ComponentControl()
       
   236 // ---------------------------------------------------------------------------
       
   237 //
       
   238 CCoeControl* CESMRViewerAlarmField::ComponentControl( TInt aIndex ) const
       
   239     {
       
   240     FUNC_LOG;
       
   241     switch ( aIndex )
       
   242         {
       
   243         case 0:
       
   244             return iIcon;
       
   245         case 1:
       
   246             return iLabel;
       
   247         default:
       
   248             return NULL;
       
   249         }
       
   250     }
       
   251 
       
   252 // ---------------------------------------------------------------------------
       
   253 // CESMRViewerAlarmField::SetOutlineFocusL()
       
   254 // ---------------------------------------------------------------------------
       
   255 //
       
   256 void CESMRViewerAlarmField::SetOutlineFocusL( TBool aFocus )
       
   257     {
       
   258     FUNC_LOG;
       
   259     CESMRField::SetOutlineFocusL ( aFocus );
       
   260     
       
   261     iLabel->SetFocus( aFocus );    
       
   262 
       
   263     if ( !aFocus )
       
   264         {
       
   265         AknLayoutUtils::OverrideControlColorL ( *iLabel, EColorLabelText,
       
   266                                                  KRgbBlack );
       
   267         }
       
   268     }
       
   269 
       
   270 // EOF