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: Implements a user scene setup list item.* |
|
15 */ |
|
16 |
|
17 |
|
18 // INCLUDE FILES |
|
19 #include "CamUserSceneSetupListItem.h" |
|
20 #include "CamSettings.hrh" |
|
21 #include "CamSettingsInternal.hrh" |
|
22 #include "CamPanic.h" |
|
23 #include <barsread.h> |
|
24 #include <e32std.h> |
|
25 #include <eikenv.h> |
|
26 #include "CamUtility.h" |
|
27 |
|
28 // CONSTANTS |
|
29 const TInt KValuesArrayGranularity = 6; |
|
30 |
|
31 |
|
32 // ================= MEMBER FUNCTIONS ======================= |
|
33 // --------------------------------------------------------- |
|
34 // CCamUserSceneSetupListItem::NewLC |
|
35 // Symbian two-phased constructor. |
|
36 // --------------------------------------------------------- |
|
37 // |
|
38 CCamUserSceneSetupListItem* CCamUserSceneSetupListItem::NewLC |
|
39 ( TInt aResId ) |
|
40 { |
|
41 CCamUserSceneSetupListItem* self = |
|
42 new ( ELeave ) CCamUserSceneSetupListItem; |
|
43 CleanupStack::PushL( self ); |
|
44 self->ConstructL( aResId ); |
|
45 return self; |
|
46 } |
|
47 |
|
48 // --------------------------------------------------------- |
|
49 // CCamUserSceneSetupListItem::NewL |
|
50 // Symbian two-phased constructor. |
|
51 // --------------------------------------------------------- |
|
52 // |
|
53 CCamUserSceneSetupListItem* CCamUserSceneSetupListItem::NewL |
|
54 ( TInt aResId ) |
|
55 { |
|
56 CCamUserSceneSetupListItem* self = |
|
57 CCamUserSceneSetupListItem::NewLC( aResId ); |
|
58 CleanupStack::Pop( self ); |
|
59 return self; |
|
60 } |
|
61 |
|
62 // --------------------------------------------------------- |
|
63 // CCamUserSceneSetupListItem::~CCamUserSceneSetupListItem |
|
64 // Destructor. |
|
65 // --------------------------------------------------------- |
|
66 // |
|
67 CCamUserSceneSetupListItem::~CCamUserSceneSetupListItem() |
|
68 { |
|
69 PRINT( _L("Camera => ~CCamUserSceneSetupListItem" )) |
|
70 iValues.ResetAndDestroy(); |
|
71 iValues.Close(); |
|
72 PRINT( _L("Camera <= ~CCamUserSceneSetupListItem" )) |
|
73 } |
|
74 |
|
75 // --------------------------------------------------------- |
|
76 // CCamUserSceneSetupListItem::ListBoxText |
|
77 // Returns the formatted text of this item to be used in the list box |
|
78 // --------------------------------------------------------- |
|
79 // |
|
80 TPtrC16 CCamUserSceneSetupListItem::ListBoxText() |
|
81 { |
|
82 // Create the title part of the text. |
|
83 _LIT( KSettingItemSingleSpace, " " ); |
|
84 _LIT( KListBoxTextSeparator, "\t" ); |
|
85 |
|
86 TPtr listBoxTextPtr = iListBoxText.Des(); |
|
87 listBoxTextPtr.Copy( KSettingItemSingleSpace ); |
|
88 listBoxTextPtr.Append( KListBoxTextSeparator ); |
|
89 listBoxTextPtr.Append( SettingName() ); |
|
90 listBoxTextPtr.Append( KListBoxTextSeparator ); |
|
91 listBoxTextPtr.Append( KListBoxTextSeparator ); |
|
92 |
|
93 // Append the second part of the text to the title part. |
|
94 // ...If there is value text for this item then append it. |
|
95 if ( iValues.Count() > 0 ) |
|
96 { |
|
97 TPtrC settingPtr = SettingText(); |
|
98 listBoxTextPtr.Append( settingPtr ); |
|
99 } |
|
100 |
|
101 return iListBoxText; |
|
102 } |
|
103 |
|
104 // --------------------------------------------------------- |
|
105 // CCamUserSceneSetupListItem::SettingsModelTypeId |
|
106 // Returns the settings model item id that is associated with this |
|
107 // list item. |
|
108 // --------------------------------------------------------- |
|
109 // |
|
110 TInt CCamUserSceneSetupListItem::SettingsModelTypeId() |
|
111 { |
|
112 return iSettingsModelItemId; |
|
113 } |
|
114 |
|
115 // --------------------------------------------------------- |
|
116 // CCamUserSceneSetupListItem::SetCurrentValue |
|
117 // Sets the current value of this list item |
|
118 // --------------------------------------------------------- |
|
119 // |
|
120 void CCamUserSceneSetupListItem::SetCurrentValue( TInt aNewValue ) |
|
121 { |
|
122 PRINT1( _L("Camera => CCamUserSceneSetupListItem::SetCurrentValue = %d" ), aNewValue ) |
|
123 PRINT1( _L("iSettingsModelItemId = %d" ), iSettingsModelItemId ) |
|
124 // Find the value-text pair that match the new current value, |
|
125 // and store the index. |
|
126 // Currently the brightness and contrast items only show 3 icons |
|
127 // 1 for normal setting i.e. 0 |
|
128 // 1 for any positive setting i.e. above 0 and |
|
129 // 1 for any negative setting i.e. below 0 |
|
130 // The code below matches positive/negative values to the correct icon |
|
131 if ( iSettingsModelItemId == ECamSettingItemUserSceneBrightness ) |
|
132 { |
|
133 if ( aNewValue < ECamBrightnessNorm ) |
|
134 { |
|
135 iCurrentPairIndex = ECamBrightnessNeg; |
|
136 return; |
|
137 } |
|
138 if ( aNewValue > ECamBrightnessNorm ) |
|
139 { |
|
140 iCurrentPairIndex = ECamBrightnessPlus; |
|
141 return; |
|
142 } |
|
143 } |
|
144 else if ( iSettingsModelItemId == ECamSettingItemUserSceneContrast ) |
|
145 { |
|
146 if ( aNewValue < ECamContrastNorm ) |
|
147 { |
|
148 PRINT( _L("iCurrentPairIndex = ECamContrastNeg" ) ) |
|
149 iCurrentPairIndex = ECamContrastNeg; |
|
150 return; |
|
151 } |
|
152 if ( aNewValue > ECamContrastNorm ) |
|
153 { |
|
154 iCurrentPairIndex = ECamContrastPlus; |
|
155 PRINT( _L("iCurrentPairIndex = ECamContrastPlus" ) ) |
|
156 return; |
|
157 } |
|
158 } |
|
159 else |
|
160 { |
|
161 // lint |
|
162 } |
|
163 |
|
164 |
|
165 TInt i = 0; |
|
166 TBool foundPair = EFalse; |
|
167 do |
|
168 { |
|
169 __ASSERT_DEBUG( i <= iValues.Count(), |
|
170 CamPanic( ECamPanicUSSPairNotFound ) ); |
|
171 if ( aNewValue == iValues[i]->iSettingsModelId ) |
|
172 { |
|
173 foundPair = ETrue; |
|
174 iCurrentPairIndex = i; |
|
175 } |
|
176 else |
|
177 { |
|
178 ++i; |
|
179 } |
|
180 } |
|
181 while ( !foundPair ); |
|
182 |
|
183 PRINT1( _L("iCurrentPairIndex = %d" ), iCurrentPairIndex ) |
|
184 } |
|
185 |
|
186 // --------------------------------------------------------- |
|
187 // CCamUserSceneSetupListItem::CCamUserSceneSetupListItem |
|
188 // Constructor |
|
189 // --------------------------------------------------------- |
|
190 // |
|
191 CCamUserSceneSetupListItem::CCamUserSceneSetupListItem() |
|
192 :iValues( KValuesArrayGranularity ) |
|
193 { |
|
194 } |
|
195 |
|
196 // --------------------------------------------------------- |
|
197 // CCamUserSceneSetupListItem::ConstructFromResourceL |
|
198 // 2nd phase Constructor |
|
199 // --------------------------------------------------------- |
|
200 // |
|
201 void CCamUserSceneSetupListItem::ConstructL |
|
202 ( TInt aResId ) |
|
203 { |
|
204 // Create a resource reader for reading only this list items data. |
|
205 TResourceReader localReader; |
|
206 CEikonEnv::Static()->CreateResourceReaderLC |
|
207 ( localReader, aResId ); |
|
208 |
|
209 // Read the data for this list item from resource. |
|
210 // ...get setting model item id associated with this list item. |
|
211 iSettingsModelItemId = localReader.ReadInt16(); |
|
212 // ...get the text name of this list item. |
|
213 iName = localReader.ReadTPtrC(); |
|
214 // ...get the count of all possible values |
|
215 // ...that this list item can have, and repeatedly get these values |
|
216 // ...and their associated textual description. |
|
217 TInt valuesCount = localReader.ReadInt16(); |
|
218 TInt i; |
|
219 for ( i = 0; i < valuesCount; ++i ) |
|
220 { |
|
221 // ...create the pair object. |
|
222 CValueTextPair* pair = new ( ELeave ) CValueTextPair; |
|
223 // ...set the data. |
|
224 pair->iSettingsModelId = localReader.ReadInt16(); |
|
225 pair->iText = localReader.ReadTPtrC(); |
|
226 |
|
227 // ...add the pair to the pair list. |
|
228 CleanupStack::PushL( pair ); |
|
229 iValues.AppendL( pair ); |
|
230 CleanupStack::Pop( pair ); |
|
231 } |
|
232 |
|
233 // Pop local resource reader. |
|
234 CleanupStack::PopAndDestroy(); |
|
235 } |
|
236 |
|
237 // --------------------------------------------------------- |
|
238 // CCamUserSceneSetupListItem::SettingName |
|
239 // Returns the name of the setting type represented by this |
|
240 // list item. |
|
241 // --------------------------------------------------------- |
|
242 // |
|
243 TPtrC CCamUserSceneSetupListItem::SettingName() const |
|
244 { |
|
245 return iName; |
|
246 } |
|
247 |
|
248 // --------------------------------------------------------- |
|
249 // CCamUserSceneSetupListItem::SettingText |
|
250 // Returns the text for the current setting value of this item |
|
251 // --------------------------------------------------------- |
|
252 // |
|
253 TPtrC CCamUserSceneSetupListItem::SettingText() |
|
254 { |
|
255 iValueText = iValues[iCurrentPairIndex]->iText; |
|
256 return iValueText; |
|
257 } |
|
258 |
|
259 |
|
260 |
|
261 |
|
262 |
|
263 // End of File |
|