1 /* |
|
2 * Copyright (c) 2007 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: Encapsulates the data for a particular Capture Setup Menu item.* |
|
15 */ |
|
16 |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include "CamCaptureSetupMenuListItem.h" |
|
21 #include "CamUtility.h" |
|
22 #include <eikenv.h> |
|
23 #include <eikappui.h> // For CCoeAppUiBase |
|
24 #include <eikapp.h> // For CEikApplication |
|
25 #include <barsread.h> |
|
26 #include <AknIconUtils.h> |
|
27 |
|
28 const TInt KIconTextGranularity = 2; |
|
29 |
|
30 // ============================= LOCAL FUNCTIONS =============================== |
|
31 |
|
32 // ----------------------------------------------------------------------------- |
|
33 // NewL |
|
34 // Two-phased constructor. |
|
35 // Returns: CCamCaptureSetupMenuListItem*: Pointer to the created list item. |
|
36 // ----------------------------------------------------------------------------- |
|
37 // |
|
38 CCamCaptureSetupMenuListItem* CCamCaptureSetupMenuListItem::NewL( |
|
39 TResourceReader& aReader ) // Used to read/construct data for this list item. |
|
40 { |
|
41 CCamCaptureSetupMenuListItem* self = |
|
42 new (ELeave ) CCamCaptureSetupMenuListItem(); |
|
43 CleanupStack::PushL( self ); |
|
44 self->ConstructFromResourceL( aReader ); |
|
45 CleanupStack::Pop( self ); |
|
46 return self; |
|
47 } |
|
48 |
|
49 // ----------------------------------------------------------------------------- |
|
50 // CCamCaptureSetupMenuListItem::~CCamCaptureSetupMenuListItem |
|
51 // ----------------------------------------------------------------------------- |
|
52 // |
|
53 CCamCaptureSetupMenuListItem::~CCamCaptureSetupMenuListItem() |
|
54 { |
|
55 PRINT( _L("Camera => ~CCamCaptureSetupMenuListItem") ); |
|
56 |
|
57 delete iIconTexts; |
|
58 iIconTexts = NULL; |
|
59 |
|
60 // Destroy bitmap array. |
|
61 iBitmaps.ResetAndDestroy(); |
|
62 iBitmaps.Close(); |
|
63 iMasks.ResetAndDestroy(); |
|
64 iMasks.Close(); |
|
65 PRINT( _L("Camera <= ~CCamCaptureSetupMenuListItem") ); |
|
66 } |
|
67 |
|
68 // ----------------------------------------------------------------------------- |
|
69 // CCamCaptureSetupMenuListItem::Bitmap |
|
70 // Returns the bitmap that represents the current settings model |
|
71 // value for this list item. |
|
72 // Returns: CFbsBitmap*: Pointer to the bitmap. |
|
73 // ----------------------------------------------------------------------------- |
|
74 // |
|
75 CFbsBitmap* CCamCaptureSetupMenuListItem::Bitmap() const |
|
76 { |
|
77 return iBitmaps[iCurrentSettingItemValueId]; |
|
78 } |
|
79 |
|
80 // ----------------------------------------------------------------------------- |
|
81 // CCamCaptureSetupMenuListItem::Mask |
|
82 // Returns the bitmap that represents the current settings model |
|
83 // value for this list item. |
|
84 // Returns: CFbsBitmap*: Pointer to the bitmap. |
|
85 // ----------------------------------------------------------------------------- |
|
86 // |
|
87 CFbsBitmap* CCamCaptureSetupMenuListItem::Mask() const |
|
88 { |
|
89 return iMasks[iCurrentSettingItemValueId]; |
|
90 } |
|
91 |
|
92 // ----------------------------------------------------------------------------- |
|
93 // CCamCaptureSetupMenuListItem::IconText |
|
94 // Returns text used in place of an icon for this list item. |
|
95 // Returns: Ref to the icon text. |
|
96 // ----------------------------------------------------------------------------- |
|
97 // |
|
98 const TDesC& CCamCaptureSetupMenuListItem::IconText( TInt aSettingVal ) const |
|
99 { |
|
100 if ( iSettingsModelItemId == ECamSettingItemDynamicPhotoBrightness || |
|
101 iSettingsModelItemId == ECamSettingItemDynamicVideoBrightness || |
|
102 iSettingsModelItemId == ECamSettingItemDynamicPhotoContrast || |
|
103 iSettingsModelItemId == ECamSettingItemDynamicVideoContrast ) |
|
104 { |
|
105 // get the array index if this item is brightness or contrast |
|
106 GetBrightnessContrastArrayIndex( aSettingVal ); |
|
107 } |
|
108 |
|
109 return (*iIconTexts)[aSettingVal]; |
|
110 } |
|
111 |
|
112 // ----------------------------------------------------------------------------- |
|
113 // CCamCaptureSetupMenuListItem::Text |
|
114 // Returns text that describes the setting represented by this list item. |
|
115 // Returns: Ref to the item text. |
|
116 // ----------------------------------------------------------------------------- |
|
117 // |
|
118 const TDesC& CCamCaptureSetupMenuListItem::Text() const |
|
119 { |
|
120 return iText; |
|
121 } |
|
122 |
|
123 // ----------------------------------------------------------------------------- |
|
124 // CCamCaptureSetupMenuListItem::CurrentValue |
|
125 // Returns the cached settings model value that the current bitmap represents. |
|
126 // Returns: TInt: The current value. |
|
127 // ----------------------------------------------------------------------------- |
|
128 // |
|
129 TInt CCamCaptureSetupMenuListItem::CurrentValue() const |
|
130 { |
|
131 return iCurrentSettingItemValueId; |
|
132 } |
|
133 |
|
134 // ----------------------------------------------------------------------------- |
|
135 // CCamCaptureSetupMenuListItem::SettingsModelItemId |
|
136 // Returns the id of the settings model item that this list item represents. |
|
137 // Returns: TInt: The settings model item id. |
|
138 // ----------------------------------------------------------------------------- |
|
139 // |
|
140 TInt CCamCaptureSetupMenuListItem::SettingsModelItemId() const |
|
141 { |
|
142 return iSettingsModelItemId; |
|
143 } |
|
144 |
|
145 // ----------------------------------------------------------------------------- |
|
146 // CCamCaptureSetupMenuListItem::SetValueTo |
|
147 // Changes the cached settings model value and the bitmap that represents it. |
|
148 // ----------------------------------------------------------------------------- |
|
149 // |
|
150 void CCamCaptureSetupMenuListItem::SetValueTo( |
|
151 TInt aNewValueId ) // the new cached settings model value. |
|
152 { |
|
153 if ( iSettingsModelItemId == ECamSettingItemDynamicPhotoBrightness || |
|
154 iSettingsModelItemId == ECamSettingItemDynamicVideoBrightness || |
|
155 iSettingsModelItemId == ECamSettingItemDynamicPhotoContrast || |
|
156 iSettingsModelItemId == ECamSettingItemDynamicVideoContrast ) |
|
157 { |
|
158 // get the array index if this item is brightness or contrast |
|
159 GetBrightnessContrastArrayIndex( aNewValueId ); |
|
160 } |
|
161 |
|
162 iCurrentSettingItemValueId = aNewValueId; |
|
163 } |
|
164 |
|
165 // ----------------------------------------------------------------------------- |
|
166 // CCamCaptureSetupMenuListItem::CCamCaptureSetupMenuListItem |
|
167 // C++ default constructor. |
|
168 // ----------------------------------------------------------------------------- |
|
169 // |
|
170 CCamCaptureSetupMenuListItem::CCamCaptureSetupMenuListItem() |
|
171 { |
|
172 } |
|
173 |
|
174 // ----------------------------------------------------------------------------- |
|
175 // CCamCaptureSetupMenuListItem::ConstructFromResourceL |
|
176 // 2nd phase constructor. |
|
177 // ----------------------------------------------------------------------------- |
|
178 // |
|
179 void |
|
180 CCamCaptureSetupMenuListItem::ConstructFromResourceL( |
|
181 TResourceReader& aReader ) // reader that is used to construct the data |
|
182 { |
|
183 PRINT( _L("Camera => CCamCaptureSetupMenuListItem::ConstructFromResourceL") ); |
|
184 delete iIconTexts; |
|
185 iIconTexts = NULL; |
|
186 iIconTexts = new (ELeave) CArrayFixFlat<TIconText>( KIconTextGranularity ); |
|
187 |
|
188 // Get the full path for the mbm file |
|
189 TFileName resFileName; |
|
190 CamUtility::ResourceFileName( resFileName ); |
|
191 |
|
192 // Create a resource reader for reading only this list items data. |
|
193 TInt resourceID = aReader.ReadInt32(); |
|
194 TResourceReader localReader; |
|
195 CEikonEnv::Static()->CreateResourceReaderLC( localReader, resourceID ); |
|
196 |
|
197 // Read the data for this list item from resource. |
|
198 // ...get setting model item id for associated with this list item. |
|
199 iSettingsModelItemId = localReader.ReadInt16(); |
|
200 // ...get the text description of this list item. |
|
201 iText = localReader.ReadTPtrC(); |
|
202 // ...get the count of all possible values (bitmaps) |
|
203 // ...that this list item can have, and repeatedly get the values. |
|
204 TInt valuesCount = localReader.ReadInt16(); |
|
205 TInt i; |
|
206 for ( i = 0; i < valuesCount; ++i ) |
|
207 { |
|
208 // ...read the current value's settings model id. |
|
209 TInt settingsModelId = localReader.ReadInt16(); |
|
210 // ...read associated bitmap id for current value. |
|
211 TInt bitmapId = localReader.ReadInt16(); |
|
212 CFbsBitmap* newBitmap = NULL; |
|
213 CFbsBitmap* mask = NULL; |
|
214 if ( bitmapId != -1 ) |
|
215 { |
|
216 AknIconUtils::CreateIconLC( newBitmap, mask, resFileName, bitmapId, bitmapId ); |
|
217 // ...add the bitmap to the array of bitmaps for this list item. |
|
218 iBitmaps.InsertL( newBitmap, settingsModelId ); |
|
219 iMasks.InsertL( mask, settingsModelId ); |
|
220 // newBitmap, mask. Don't know the order of pushing so pop anonymously. |
|
221 CleanupStack::Pop( 2 ); |
|
222 } |
|
223 else |
|
224 { |
|
225 // Add NULL bitmaps: |
|
226 iBitmaps.InsertL( newBitmap, settingsModelId ); |
|
227 iMasks.InsertL( mask, settingsModelId ); |
|
228 } |
|
229 |
|
230 iIconTexts->InsertL( settingsModelId, localReader.ReadTPtrC() ); |
|
231 } |
|
232 |
|
233 // Pop local resource reader. |
|
234 CleanupStack::PopAndDestroy(); |
|
235 PRINT( _L("Camera <= CCamCaptureSetupMenuListItem::ConstructFromResourceL") ) |
|
236 } |
|
237 |
|
238 |
|
239 // ----------------------------------------------------------------------------- |
|
240 // CCamCaptureSetupMenuListItem::GetBrightnessContrastArrayIndex |
|
241 // Returns the array position for brightness and contrast, as these controls |
|
242 // can have negative values, so this maps to an index in the text/bitmaps arrays |
|
243 // ----------------------------------------------------------------------------- |
|
244 // |
|
245 void CCamCaptureSetupMenuListItem::GetBrightnessContrastArrayIndex( TInt& aValue ) const |
|
246 { |
|
247 // if brightness or contrast settings - only display either |
|
248 // the plus or negative icon. There isn't going to be an icon |
|
249 // for each setting value as the values can range from -10 to +10 |
|
250 if ( iSettingsModelItemId == ECamSettingItemDynamicPhotoBrightness || |
|
251 iSettingsModelItemId == ECamSettingItemDynamicVideoBrightness ) |
|
252 { |
|
253 if ( aValue > 0 ) |
|
254 { |
|
255 aValue = ECamBrightnessPlus; |
|
256 } |
|
257 else if ( aValue < 0 ) |
|
258 { |
|
259 aValue = ECamBrightnessNeg; |
|
260 } |
|
261 else |
|
262 { |
|
263 aValue = ECamBrightnessNorm; |
|
264 } |
|
265 } |
|
266 else if ( iSettingsModelItemId == ECamSettingItemDynamicPhotoContrast || |
|
267 iSettingsModelItemId == ECamSettingItemDynamicVideoContrast ) |
|
268 { |
|
269 if ( aValue > 0 ) |
|
270 { |
|
271 aValue = ECamContrastPlus; |
|
272 } |
|
273 else if ( aValue < 0 ) |
|
274 { |
|
275 aValue = ECamContrastNeg; |
|
276 } |
|
277 else |
|
278 { |
|
279 aValue = ECamBrightnessNorm; |
|
280 } |
|
281 } |
|
282 else // lint |
|
283 { |
|
284 } |
|
285 } |
|
286 |
|
287 |
|
288 // End of File |
|