27 #include <alf/alftextvisual.h> |
25 #include <alf/alftextvisual.h> |
28 #include <alf/alfanchorlayout.h> |
26 #include <alf/alfanchorlayout.h> |
29 #include <alf/alfgradientbrush.h> |
27 #include <alf/alfgradientbrush.h> |
30 #include <alf/alfframebrush.h> |
28 #include <alf/alfframebrush.h> |
31 #include <alf/alfimagebrush.h> |
29 #include <alf/alfimagebrush.h> |
|
30 #include <alf/alfshadowborderbrush.h> |
32 #include <alf/alfbrusharray.h> |
31 #include <alf/alfbrusharray.h> |
33 #include <alf/alftextstyle.h> |
32 #include <alf/alftextstyle.h> |
34 //</cmail> |
|
35 #include <AknsConstants.h> |
33 #include <AknsConstants.h> |
36 #include <AknUtils.h> |
34 #include <AknUtils.h> |
37 #include <touchlogicalfeedback.h> |
35 #include <touchlogicalfeedback.h> |
38 |
36 |
39 #include "fscontrolbuttonvisualiser.h" |
37 #include "fscontrolbuttonvisualiser.h" |
42 #include "fstextstylemanager.h" |
40 #include "fstextstylemanager.h" |
43 #include "fslayoutmanager.h" |
41 #include "fslayoutmanager.h" |
44 #include "fscontrolbar.h" |
42 #include "fscontrolbar.h" |
45 |
43 |
46 const TInt KFsDefaultFontStyle = EAlfTextStyleNormal; |
44 const TInt KFsDefaultFontStyle = EAlfTextStyleNormal; |
|
45 const TInt KDefaultShadowBorderWidth( 8 ); |
|
46 const TReal KShadowBorderOpacity( 0.08 ); |
|
47 const TInt KButtonBorderSize( 8 ); |
47 |
48 |
48 |
49 |
49 // ======== MEMBER FUNCTIONS ======== |
50 // ======== MEMBER FUNCTIONS ======== |
50 |
51 |
51 // --------------------------------------------------------------------------- |
52 // --------------------------------------------------------------------------- |
166 // Add background color brush. This cannot be done in ConstructL as the |
168 // Add background color brush. This cannot be done in ConstructL as the |
167 // button model isn't set before. |
169 // button model isn't set before. |
168 if ( !iBgColorBrush ) |
170 if ( !iBgColorBrush ) |
169 { |
171 { |
170 iBgColorBrush = CAlfGradientBrush::NewL( iParent->Env() ); |
172 iBgColorBrush = CAlfGradientBrush::NewL( iParent->Env() ); |
|
173 if( iShowShadow ) |
|
174 { |
|
175 iBgColorBrush->SetOpacity( KShadowBorderOpacity ); |
|
176 iBgColorBrush->SetColor(KRgbBlack); |
|
177 } |
|
178 else |
|
179 { |
|
180 iBgColorBrush->SetOpacity( 0 ); |
|
181 } |
|
182 |
|
183 iBgColorBrush->SetLayer( EAlfBrushLayerBackground ); |
|
184 iButtonLayout->Brushes()->AppendL( iBgColorBrush, |
|
185 EAlfDoesNotHaveOwnership ); |
|
186 } |
|
187 |
|
188 iUseDefaultBackground = ETrue; |
|
189 |
|
190 // Add a shadow border brush to outline the buttons with a shadowed border. |
|
191 if ( iShowShadow && !iShadowBorderBrush ) |
|
192 { |
|
193 iShadowBorderBrush = CAlfShadowBorderBrush::NewL( |
|
194 iParent->Env(), TAlfMetric( KDefaultShadowBorderWidth ) ); |
|
195 iShadowBorderBrush->SetOpacity( KShadowBorderOpacity ); |
|
196 iShadowBorderBrush->SetLayer( EAlfBrushLayerBackground ); |
|
197 iButtonLayout->Brushes()->AppendL( iShadowBorderBrush, |
|
198 EAlfDoesNotHaveOwnership ); |
|
199 } |
|
200 |
|
201 UpdateVisualThemeL(); |
|
202 |
|
203 // create needed visuals |
|
204 CreateButtonVisualsL(); |
|
205 |
|
206 UpdateBarLayout(); |
|
207 } |
|
208 |
|
209 // --------------------------------------------------------------------------- |
|
210 // CFsControlButtonVisualiser::UpdateVisualThemeL |
|
211 // --------------------------------------------------------------------------- |
|
212 // |
|
213 void CFsControlButtonVisualiser::UpdateVisualThemeL() |
|
214 { |
|
215 if( iUseDefaultBackground ) |
|
216 { |
|
217 ClearBackgroundImage(); |
|
218 iDefaultBgBrush = CAlfFrameBrush::NewL( iParent->Env(), KAknsIIDQsnFrButtonTb ); |
|
219 iBgBrush = iDefaultBgBrush; |
|
220 iButtonLayout->Brushes()->AppendL( iBgBrush, EAlfDoesNotHaveOwnership ); |
|
221 UpdateBarLayout(); |
|
222 } |
|
223 else if ( iBgColorBrush ) |
|
224 { |
171 SetBackgroundColor( iButtonModel->TextColor( |
225 SetBackgroundColor( iButtonModel->TextColor( |
172 CFsControlButtonModel::EButtonBackground ) ); |
226 CFsControlButtonModel::EButtonBackground ) ); |
173 iButtonLayout->Brushes()->AppendL( |
227 } |
174 iBgColorBrush, EAlfDoesNotHaveOwnership ); |
228 } |
175 } |
|
176 |
|
177 // create needed visuals |
|
178 CreateButtonVisualsL(); |
|
179 |
|
180 UpdateBarLayout(); |
|
181 } |
|
182 |
|
183 |
229 |
184 // --------------------------------------------------------------------------- |
230 // --------------------------------------------------------------------------- |
185 // From class CFsControlButtonVisualiserBase. |
231 // From class CFsControlButtonVisualiserBase. |
186 // Refreshes button's content. |
232 // Refreshes button's content. |
187 // --------------------------------------------------------------------------- |
233 // --------------------------------------------------------------------------- |
336 // Release the old background image. |
382 // Release the old background image. |
337 ClearBackgroundImage(); |
383 ClearBackgroundImage(); |
338 |
384 |
339 // As the ownership of the new brush is gained the pointer can't be lost. |
385 // As the ownership of the new brush is gained the pointer can't be lost. |
340 CleanupStack::PushL( aImage ); |
386 CleanupStack::PushL( aImage ); |
341 iButtonLayout->Brushes()->AppendL( aImage, EAlfDoesNotHaveOwnership ); |
387 iButtonLayout->Brushes()->InsertL( 0, aImage, EAlfDoesNotHaveOwnership ); |
342 CleanupStack::Pop( aImage ); |
388 CleanupStack::Pop( aImage ); |
343 |
389 |
|
390 iUseDefaultBackground = EFalse; |
344 iBgBrush = aImage; |
391 iBgBrush = aImage; |
345 } |
392 } |
346 |
393 |
347 |
394 |
348 // --------------------------------------------------------------------------- |
395 // --------------------------------------------------------------------------- |
629 // New size for the button background. |
680 // New size for the button background. |
630 iButtonLayout->SetSize( iButtonModel->Size() ); |
681 iButtonLayout->SetSize( iButtonModel->Size() ); |
631 // Same size for the content |
682 // Same size for the content |
632 iButtonContentLayout->SetSize( iButtonModel->Size() ); |
683 iButtonContentLayout->SetSize( iButtonModel->Size() ); |
633 |
684 |
|
685 if( iDefaultBgBrush ) |
|
686 { |
|
687 TSize size = iButtonModel->Size(); |
|
688 TRect fullRect = TRect( size ); |
|
689 TRect innerRect = fullRect; |
|
690 innerRect.Shrink( KButtonBorderSize,KButtonBorderSize ); |
|
691 TRAP_IGNORE( |
|
692 iDefaultBgBrush->SetFrameRectsL( innerRect, fullRect ); ); |
|
693 } |
|
694 |
634 if ( iLabelFirstLine ) |
695 if ( iLabelFirstLine ) |
635 { |
696 { |
636 iLabelFirstLine->SetWrapping( textWrapping ); |
697 iLabelFirstLine->SetWrapping( textWrapping ); |
637 iLabelFirstLine->SetClipping( textClipping ); |
698 iLabelFirstLine->SetClipping( textClipping ); |
638 } |
699 } |
826 TInt styleId( KFsDefaultFontStyle ); |
887 TInt styleId( KFsDefaultFontStyle ); |
827 |
888 |
828 if ( iTextStyleManager ) |
889 if ( iTextStyleManager ) |
829 { |
890 { |
830 ResolveCharFormat( charFormat, iLabelFirstLine ); |
891 ResolveCharFormat( charFormat, iLabelFirstLine ); |
|
892 charFormat.iFontPresentation.iUnderline = EUnderlineOff; |
|
893 TRAPD( leaveErr, |
|
894 styleId = iTextStyleManager->GetStyleIDL( charFormat ) ); |
|
895 // Use modified style if possible, otherwise use the default |
|
896 // style. |
|
897 if ( KErrNone == leaveErr ) |
|
898 { |
|
899 iLabelFirstLine->SetTextStyle( styleId ); |
|
900 } |
|
901 } |
|
902 iLabelFirstLine->SetColor( iButtonModel->TextColor( |
|
903 CFsControlButtonModel::EButtonNormal ) ); |
|
904 } |
|
905 |
|
906 if ( iLabelSecondLine ) |
|
907 { |
|
908 TCharFormat charFormat; |
|
909 TInt styleId( KFsDefaultFontStyle ); |
|
910 |
|
911 if ( iTextStyleManager ) |
|
912 { |
|
913 ResolveCharFormat( charFormat, iLabelSecondLine ); |
|
914 charFormat.iFontPresentation.iUnderline = EUnderlineOff; |
|
915 TRAPD( leaveErr, |
|
916 styleId = iTextStyleManager->GetStyleIDL( charFormat ) ); |
|
917 // Use modified style if possible, otherwise use the default |
|
918 // style. |
|
919 if ( KErrNone == leaveErr ) |
|
920 { |
|
921 iLabelSecondLine->SetTextStyle( styleId ); |
|
922 } |
|
923 } |
|
924 iLabelSecondLine->SetColor( iButtonModel->TextColor( |
|
925 CFsControlButtonModel::EButtonNormal ) ); |
|
926 } |
|
927 |
|
928 if ( iIconA ) |
|
929 { |
|
930 iIconA->SetColorMode( CAlfImageVisual::EColorModulate ); |
|
931 } |
|
932 |
|
933 if ( iIconB ) |
|
934 { |
|
935 iIconB->SetColorMode( CAlfImageVisual::EColorModulate ); |
|
936 } |
|
937 } |
|
938 |
|
939 |
|
940 // --------------------------------------------------------------------------- |
|
941 // Changes color of text when button's state is dimmed. |
|
942 // --------------------------------------------------------------------------- |
|
943 // |
|
944 EXPORT_C void CFsControlButtonVisualiser::PrepareDrawDimmed() |
|
945 { |
|
946 FUNC_LOG; |
|
947 TCharFormat charFormat; |
|
948 |
|
949 if ( iLabelFirstLine ) |
|
950 { |
|
951 TCharFormat charFormat; |
|
952 TInt styleId( KFsDefaultFontStyle ); |
|
953 |
|
954 if ( iTextStyleManager ) |
|
955 { |
|
956 ResolveCharFormat( charFormat, iLabelFirstLine ); |
831 charFormat.iFontPresentation.iUnderline = EUnderlineOn; |
957 charFormat.iFontPresentation.iUnderline = EUnderlineOn; |
832 TRAPD( leaveErr, |
958 TRAPD( leaveErr, |
833 styleId = iTextStyleManager->GetStyleIDL( charFormat ) ); |
959 styleId = iTextStyleManager->GetStyleIDL( charFormat ) ); |
834 // Use modified style if possible, otherwise use the default |
960 // Use modified style if possible, otherwise use the default |
835 // style. |
961 // style. |
859 { |
985 { |
860 iLabelSecondLine->SetTextStyle( styleId ); |
986 iLabelSecondLine->SetTextStyle( styleId ); |
861 } |
987 } |
862 } |
988 } |
863 iLabelSecondLine->SetColor( iButtonModel->TextColor( |
989 iLabelSecondLine->SetColor( iButtonModel->TextColor( |
864 CFsControlButtonModel::EButtonNormal ) ); |
|
865 } |
|
866 |
|
867 if ( iIconA ) |
|
868 { |
|
869 iIconA->SetColorMode( CAlfImageVisual::EColorModulate ); |
|
870 } |
|
871 |
|
872 if ( iIconB ) |
|
873 { |
|
874 iIconB->SetColorMode( CAlfImageVisual::EColorModulate ); |
|
875 } |
|
876 } |
|
877 |
|
878 |
|
879 // --------------------------------------------------------------------------- |
|
880 // Changes color of text when button's state is dimmed. |
|
881 // --------------------------------------------------------------------------- |
|
882 // |
|
883 EXPORT_C void CFsControlButtonVisualiser::PrepareDrawDimmed() |
|
884 { |
|
885 FUNC_LOG; |
|
886 TCharFormat charFormat; |
|
887 |
|
888 if ( iLabelFirstLine ) |
|
889 { |
|
890 TCharFormat charFormat; |
|
891 TInt styleId( KFsDefaultFontStyle ); |
|
892 |
|
893 if ( iTextStyleManager ) |
|
894 { |
|
895 ResolveCharFormat( charFormat, iLabelFirstLine ); |
|
896 charFormat.iFontPresentation.iUnderline = EUnderlineOn; |
|
897 TRAPD( leaveErr, |
|
898 styleId = iTextStyleManager->GetStyleIDL( charFormat ) ); |
|
899 // Use modified style if possible, otherwise use the default |
|
900 // style. |
|
901 if ( KErrNone == leaveErr ) |
|
902 { |
|
903 iLabelFirstLine->SetTextStyle( styleId ); |
|
904 } |
|
905 } |
|
906 iLabelFirstLine->SetColor( iButtonModel->TextColor( |
|
907 CFsControlButtonModel::EButtonDimmed ) ); |
|
908 } |
|
909 |
|
910 if ( iLabelSecondLine ) |
|
911 { |
|
912 TCharFormat charFormat; |
|
913 TInt styleId( KFsDefaultFontStyle ); |
|
914 |
|
915 if ( iTextStyleManager ) |
|
916 { |
|
917 ResolveCharFormat( charFormat, iLabelSecondLine ); |
|
918 charFormat.iFontPresentation.iUnderline = EUnderlineOn; |
|
919 TRAPD( leaveErr, |
|
920 styleId = iTextStyleManager->GetStyleIDL( charFormat ) ); |
|
921 // Use modified style if possible, otherwise use the default |
|
922 // style. |
|
923 if ( KErrNone == leaveErr ) |
|
924 { |
|
925 iLabelSecondLine->SetTextStyle( styleId ); |
|
926 } |
|
927 } |
|
928 iLabelSecondLine->SetColor( iButtonModel->TextColor( |
|
929 CFsControlButtonModel::EButtonDimmed ) ); |
990 CFsControlButtonModel::EButtonDimmed ) ); |
930 } |
991 } |
931 |
992 |
932 if ( iIconA ) |
993 if ( iIconA ) |
933 { |
994 { |
952 if ( iButtonModel->ContainsElement( ECBElemIconA ) ) |
1013 if ( iButtonModel->ContainsElement( ECBElemIconA ) ) |
953 { |
1014 { |
954 iIconAContainer = |
1015 iIconAContainer = |
955 CAlfLayout::AddNewL( *iParent, iButtonContentLayout ); |
1016 CAlfLayout::AddNewL( *iParent, iButtonContentLayout ); |
956 iIconA = CAlfImageVisual::AddNewL( *iParent, iIconAContainer ); |
1017 iIconA = CAlfImageVisual::AddNewL( *iParent, iIconAContainer ); |
957 // <cmail> Platform layout change |
1018 iIconA->SetScaleMode( CAlfImageVisual::EScaleFitInside ); |
958 //iIconA->SetScaleMode( CAlfImageVisual::EScaleNormal ); |
|
959 iIconA->SetScaleMode( CAlfImageVisual::EScaleFit ); |
|
960 // </cmail> Platform layout change |
|
961 iIconAContainer->SetClipping( ETrue ); |
1019 iIconAContainer->SetClipping( ETrue ); |
962 } |
1020 } |
963 |
1021 |
964 // create visual for first line of text |
1022 // create visual for first line of text |
965 if ( iButtonModel->ContainsElement( ECBElemLabelFirstLine ) ) |
1023 if ( iButtonModel->ContainsElement( ECBElemLabelFirstLine ) ) |
1019 TSize size( iLabelFirstLine->TextExtents() ); |
1078 TSize size( iLabelFirstLine->TextExtents() ); |
1020 TAlfRealRect padding( iLabelFirstLine->PaddingInPixels() ); |
1079 TAlfRealRect padding( iLabelFirstLine->PaddingInPixels() ); |
1021 TRect textRect( 0, 0, |
1080 TRect textRect( 0, 0, |
1022 padding.iTl.iX + padding.iBr.iX + size.iWidth, |
1081 padding.iTl.iX + padding.iBr.iX + size.iWidth, |
1023 padding.iTl.iY + padding.iBr.iY + size.iHeight ); |
1082 padding.iTl.iY + padding.iBr.iY + size.iHeight ); |
1024 |
1083 |
1025 if ( iButtonModel->ContainsElement( ECBElemLabelSndLine ) ) |
1084 if ( iButtonModel->ContainsElement( ECBElemLabelSndLine ) ) |
1026 { |
1085 { |
1027 // to get correct value from ExpandRectWithContent method |
1086 // to get correct value from ExpandRectWithContent method |
1028 iLabelSecondLine->SetClipping( EFalse ); |
1087 iLabelSecondLine->SetClipping( EFalse ); |
1029 |
1088 |
1169 text1 = text.iTextRect; |
1228 text1 = text.iTextRect; |
1170 CFsLayoutManager::LayoutMetricsRect( parentRect, |
1229 CFsLayoutManager::LayoutMetricsRect( parentRect, |
1171 CFsLayoutManager::EFsLmMainSpFsCtrlbarDdmenuPaneG1, |
1230 CFsLayoutManager::EFsLmMainSpFsCtrlbarDdmenuPaneG1, |
1172 iconB, 1 ); |
1231 iconB, 1 ); |
1173 break; |
1232 break; |
1174 |
|
1175 //<CMAIL> As a device user, I want Message List items to follow platform layouts to be consistent with other apps |
|
1176 |
|
1177 /* |
|
1178 REMOVED, Not needed anymore. |
|
1179 |
|
1180 case ECBTypeTwoLinesLabelOnly: |
|
1181 text1 = TRect(0,0,60,20); |
|
1182 text2 = TRect(0,0,60,20); |
|
1183 break; |
|
1184 case ECBTypeTwoLinesLabelIconA: |
|
1185 iconA = TRect(0,0,16,16); |
|
1186 text1 = TRect(0,0,60,20); |
|
1187 text2 = TRect(0,0,60,20); |
|
1188 break; |
|
1189 case ECBTypeTwoLinesLabelIconB: |
|
1190 text1 = TRect(0,0,60,20); |
|
1191 text2 = TRect(0,0,60,20); |
|
1192 iconB = TRect(0,0,16,16); |
|
1193 break; |
|
1194 case ECBTypeTwoLinesLabelTwoIcons: |
|
1195 iconA = TRect(0,0,16,16); |
|
1196 text1 = TRect(0,0,60,20); |
|
1197 text2 = TRect(0,0,60,20); |
|
1198 iconB = TRect(0,0,16,16); |
|
1199 break; |
|
1200 */ |
|
1201 //<CMAIL> |
|
1202 |
|
1203 default: |
1233 default: |
1204 break; |
1234 break; |
1205 } |
1235 } |
1206 |
1236 |
1207 // <cmail> Platform layout changes |
1237 // Buttons have different sizes so adapt the used rectangle dynamically |
|
1238 TSize buttonSize = iButtonModel->Size(); |
|
1239 buttonSize -= TPoint( KButtonBorderSize, KButtonBorderSize ); // shrink frame border size |
|
1240 |
|
1241 // If there is no text in the button, center the icon to the button |
|
1242 if( !iLabelFirstLine || iLabelFirstLine->Text().Length() == 0 ) |
|
1243 { |
|
1244 TSize oldIconSize = iconA.Size(); |
|
1245 iconA.SetRect( TPoint( |
|
1246 iconA.iTl .iX + ( buttonSize.iWidth - oldIconSize.iWidth ) / 2, |
|
1247 iconA.iTl .iY + ( buttonSize.iHeight - oldIconSize.iHeight ) / 2 ), |
|
1248 oldIconSize ); |
|
1249 } |
|
1250 iconA.SetHeight( buttonSize.iHeight ); |
|
1251 text1.SetHeight( buttonSize.iHeight ); |
|
1252 |
1208 if ( iButtonModel->ContainsElement( ECBElemIconA ) ) |
1253 if ( iButtonModel->ContainsElement( ECBElemIconA ) ) |
1209 { |
1254 { |
1210 const TSize& size( iconA.Size() ); |
1255 const TSize& size( iconA.Size() ); |
1211 iIconAContainer->SetSize( size ); |
1256 iIconAContainer->SetSize( size ); |
1212 iIconAContainer->SetPos( iconA.iTl ); |
1257 iIconAContainer->SetPos( iconA.iTl ); |