|
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 * |
|
17 */ |
|
18 |
|
19 |
|
20 |
|
21 #include "VerticalSlider.h" |
|
22 #include "CustomControlPanics.h" |
|
23 #include <ImageEditorUi.mbg> |
|
24 #include "ResolutionUtil.h" |
|
25 #include "ImageEditorUiDefs.h" |
|
26 #include <fbs.h> |
|
27 #include <aknutils.h> |
|
28 #include <AknIconUtils.h> |
|
29 |
|
30 |
|
31 // CONSTANTS |
|
32 const TInt KStandardSliderWidth = 7; |
|
33 const TInt KStandardSliderHeight = 132; |
|
34 const TInt KStandardSliderTabWidth = 7; |
|
35 const TInt KStandardSliderTabHeight = 12; |
|
36 |
|
37 const TInt KDoubleSliderWidth = 13; |
|
38 const TInt KDoubleSliderHeight = 244; |
|
39 const TInt KDoubleSliderTabWidth = 13; |
|
40 const TInt KDoubleSliderTabHeight = 24; |
|
41 |
|
42 const TInt KQVGASliderWidth = 10; |
|
43 const TInt KQVGASliderHeight = 188; |
|
44 const TInt KQVGASliderTabWidth = 10; |
|
45 const TInt KQVGASliderTabHeight = 18; |
|
46 |
|
47 const TInt KHVGASliderWidth = 13; |
|
48 const TInt KHVGASliderHeight = 244; |
|
49 const TInt KHVGASliderTabWidth = 13; |
|
50 const TInt KHVGASliderTabHeight = 24; |
|
51 |
|
52 const TInt KVGASliderWidth = 20; |
|
53 const TInt KVGASliderHeight = 376; |
|
54 const TInt KVGASliderTabWidth = 20; |
|
55 const TInt KVGASliderTabHeight = 36; |
|
56 |
|
57 const TInt KQHDSliderWidth = 13; |
|
58 const TInt KQHDSliderHeight = 244; |
|
59 const TInt KQHDSliderTabWidth = 13; |
|
60 const TInt KQHDSliderTabHeight = 24; |
|
61 |
|
62 //============================================================================= |
|
63 EXPORT_C CVerticalSlider* CVerticalSlider::NewL(const TRect& aRect, const CCoeControl& aControl) |
|
64 { |
|
65 CVerticalSlider* self = CVerticalSlider::NewLC(aRect, aControl); |
|
66 CleanupStack::Pop(self); |
|
67 return self; |
|
68 } |
|
69 |
|
70 //============================================================================= |
|
71 EXPORT_C CVerticalSlider* CVerticalSlider::NewLC(const TRect& aRect, const CCoeControl& aControl) |
|
72 { |
|
73 CVerticalSlider* self = new (ELeave) CVerticalSlider; |
|
74 CleanupStack::PushL(self); |
|
75 self->ConstructL(aRect, aControl); |
|
76 return self; |
|
77 } |
|
78 |
|
79 //============================================================================= |
|
80 EXPORT_C CVerticalSlider::~CVerticalSlider() |
|
81 { |
|
82 delete iSliderBg; |
|
83 delete iSliderBgMask; |
|
84 delete iSliderTab; |
|
85 delete iSliderTabMask; |
|
86 } |
|
87 |
|
88 //============================================================================= |
|
89 void CVerticalSlider::ConstructL(const TRect& /*aRect*/, const CCoeControl& aControl) |
|
90 { |
|
91 SetContainerWindowL(aControl); |
|
92 |
|
93 // Load the bitmaps |
|
94 LoadBitmapL( iSliderBg, iSliderBgMask, EMbmImageeditoruiQgn_graf_ied_vslider, EMbmImageeditoruiQgn_graf_ied_vslider_mask ); |
|
95 LoadBitmapL( iSliderTab, iSliderTabMask, EMbmImageeditoruiQgn_graf_ied_vtab, EMbmImageeditoruiQgn_graf_ied_vtab_mask ); |
|
96 SetBitmapSize(); |
|
97 |
|
98 ActivateL(); |
|
99 } |
|
100 |
|
101 //============================================================================= |
|
102 CVerticalSlider::CVerticalSlider() |
|
103 { |
|
104 // no implementation required |
|
105 } |
|
106 |
|
107 //============================================================================= |
|
108 EXPORT_C TInt CVerticalSlider::CountComponentControls() const |
|
109 { |
|
110 return 0; |
|
111 } |
|
112 |
|
113 //============================================================================= |
|
114 void CVerticalSlider::Draw(const TRect& /*aRect*/) const |
|
115 { |
|
116 if ( iMinimumValue <= iMaximumValue ) |
|
117 { |
|
118 TUint height = iMaximumValue - iMinimumValue; // height of the slider |
|
119 TUint pixelsFromMin = iPosition - iMinimumValue; // tab position from the beginning |
|
120 |
|
121 TReal factor = 0.0; |
|
122 if (iMinimumValue < iMaximumValue ) |
|
123 { |
|
124 factor = (TReal) pixelsFromMin / height; // tab position from the beginning in percentage |
|
125 } |
|
126 TUint sliderTabHeight = iSliderTab->SizeInPixels().iHeight; // slider tab height |
|
127 |
|
128 // slider bitmap is actually a bit longer but this resolves the problem |
|
129 // where the tab is drawn outside of the slider when in maximum position |
|
130 TUint sliderBitmapHeight = iSliderBg->SizeInPixels().iHeight - sliderTabHeight; |
|
131 |
|
132 TUint tabPositionFromMinInPixels = (TUint) (factor * sliderBitmapHeight + 0.5); // calculate tab position |
|
133 |
|
134 // top left coordinate |
|
135 const TPoint tl = Rect().iTl; |
|
136 |
|
137 CWindowGc& gc = SystemGc(); |
|
138 |
|
139 // draw actual slider using mask bitmap |
|
140 TRect bgRect(TPoint(0,0), iSliderBg->SizeInPixels()); |
|
141 gc.BitBltMasked(tl, iSliderBg, bgRect, iSliderBgMask, ETrue); |
|
142 |
|
143 // draw the tab using mask bitmap |
|
144 TRect tabRect(TPoint(0,0),iSliderTab->SizeInPixels()); |
|
145 gc.BitBltMasked(TPoint(tl.iX, tl.iY+tabPositionFromMinInPixels), iSliderTab, tabRect, iSliderTabMask, ETrue); |
|
146 } |
|
147 } |
|
148 |
|
149 //============================================================================= |
|
150 EXPORT_C CCoeControl* CVerticalSlider::ComponentControl(TInt /*aIndex*/) const |
|
151 { |
|
152 return NULL; |
|
153 } |
|
154 |
|
155 //============================================================================= |
|
156 EXPORT_C TSize CVerticalSlider::MinimumSize() |
|
157 { |
|
158 TSize size = iSliderBg->SizeInPixels(); |
|
159 return size; |
|
160 } |
|
161 |
|
162 // setters |
|
163 |
|
164 //============================================================================= |
|
165 EXPORT_C void CVerticalSlider::SetMinimum(TInt aValue) |
|
166 { |
|
167 iMinimumValue = aValue; |
|
168 } |
|
169 |
|
170 //============================================================================= |
|
171 EXPORT_C void CVerticalSlider::SetMaximum(TInt aValue) |
|
172 { |
|
173 iMaximumValue = aValue; |
|
174 } |
|
175 |
|
176 //============================================================================= |
|
177 EXPORT_C void CVerticalSlider::SetStep(TUint aValue) |
|
178 { |
|
179 iStep = aValue; |
|
180 } |
|
181 |
|
182 //============================================================================= |
|
183 EXPORT_C void CVerticalSlider::SetStepAmount(TUint8 aValue) |
|
184 { |
|
185 iNumberOfSteps = aValue; |
|
186 |
|
187 if(aValue == 0) |
|
188 { |
|
189 iStep = 0; |
|
190 } |
|
191 else |
|
192 { |
|
193 iStep = (iMaximumValue-iMinimumValue) / aValue; |
|
194 } |
|
195 } |
|
196 |
|
197 //============================================================================= |
|
198 EXPORT_C void CVerticalSlider::SetPosition(TInt aValue) |
|
199 { |
|
200 __ASSERT_ALWAYS( aValue >= iMinimumValue, Panic(EVerticalSliderPanicIndexUnderflow) ); |
|
201 __ASSERT_ALWAYS( aValue <= iMaximumValue, Panic(EVerticalSliderPanicIndexOverflow) ); |
|
202 |
|
203 iPosition = aValue; |
|
204 } |
|
205 |
|
206 // getters |
|
207 |
|
208 //============================================================================= |
|
209 EXPORT_C TInt CVerticalSlider::Minimum() const |
|
210 { |
|
211 return iMinimumValue; |
|
212 } |
|
213 |
|
214 //============================================================================= |
|
215 EXPORT_C TInt CVerticalSlider::Maximum() const |
|
216 { |
|
217 return iMaximumValue; |
|
218 } |
|
219 |
|
220 //============================================================================= |
|
221 EXPORT_C TInt CVerticalSlider::Step() const |
|
222 { |
|
223 return iStep; |
|
224 } |
|
225 |
|
226 //============================================================================= |
|
227 EXPORT_C TInt CVerticalSlider::Position() const |
|
228 { |
|
229 return iPosition; |
|
230 } |
|
231 |
|
232 //============================================================================= |
|
233 EXPORT_C void CVerticalSlider::Increment() |
|
234 { |
|
235 iPosition += iStep; |
|
236 if(iPosition > iMaximumValue) |
|
237 { |
|
238 iPosition = iMaximumValue; |
|
239 } |
|
240 } |
|
241 |
|
242 //============================================================================= |
|
243 EXPORT_C void CVerticalSlider::Decrement() |
|
244 { |
|
245 iPosition -= iStep; |
|
246 if(iPosition < iMinimumValue) |
|
247 { |
|
248 iPosition = iMinimumValue; |
|
249 } |
|
250 } |
|
251 |
|
252 |
|
253 //============================================================================= |
|
254 void CVerticalSlider::LoadBitmapL( CFbsBitmap*& aBitmap, CFbsBitmap*& aMask, TInt aBitmapId, TInt aMaskId ) const |
|
255 { |
|
256 |
|
257 TFileName iconFile( KImageEditorUiMifFile ); |
|
258 User::LeaveIfError( CompleteWithAppPath(iconFile) ); |
|
259 |
|
260 // Get ids for bitmap and mask |
|
261 AknIconUtils::CreateIconL( |
|
262 aBitmap, |
|
263 aMask, |
|
264 iconFile, |
|
265 aBitmapId, |
|
266 aMaskId |
|
267 ); |
|
268 |
|
269 |
|
270 } |
|
271 |
|
272 //============================================================================= |
|
273 void CVerticalSlider::SetBitmapSize() const |
|
274 { |
|
275 |
|
276 __ASSERT_ALWAYS( iSliderBg && iSliderTab, Panic(EVerticalSliderPanicBitmapsNotLoaded) ); |
|
277 |
|
278 // Get the screen mode from the Resolution Util |
|
279 TInt screenMode = CResolutionUtil::Self()->GetScreenMode(); |
|
280 |
|
281 TSize sliderSize; |
|
282 TSize tabSize; |
|
283 |
|
284 switch( screenMode ) |
|
285 { |
|
286 // small screen sizes |
|
287 case CResolutionUtil::EStandard: |
|
288 case CResolutionUtil::EStandardFullScreen: |
|
289 case CResolutionUtil::EStandardLandscape: |
|
290 case CResolutionUtil::EStandardLandscapeFullScreen: |
|
291 case CResolutionUtil::ESquare: |
|
292 case CResolutionUtil::ESquareFullScreen: |
|
293 case CResolutionUtil::ESquareRotated: |
|
294 case CResolutionUtil::ESquareRotatedFullScreen: |
|
295 { |
|
296 sliderSize = TSize (KStandardSliderWidth, KStandardSliderHeight); |
|
297 tabSize = TSize (KStandardSliderTabWidth, KStandardSliderTabHeight); |
|
298 break; |
|
299 } |
|
300 |
|
301 // QVGA |
|
302 case CResolutionUtil::EQVGA: |
|
303 case CResolutionUtil::EQVGAFullScreen: |
|
304 case CResolutionUtil::EQVGALandscape: |
|
305 case CResolutionUtil::EQVGALandscapeFullScreen: |
|
306 { |
|
307 sliderSize = TSize (KQVGASliderWidth, KQVGASliderHeight); |
|
308 tabSize = TSize (KQVGASliderTabWidth, KQVGASliderTabHeight); |
|
309 break; |
|
310 } |
|
311 |
|
312 case CResolutionUtil::EDouble: |
|
313 case CResolutionUtil::EDoubleFullScreen: |
|
314 case CResolutionUtil::EDoubleLandscape: |
|
315 case CResolutionUtil::EDoubleLandscapeFullScreen: |
|
316 { |
|
317 sliderSize = TSize (KDoubleSliderWidth, KDoubleSliderHeight); |
|
318 tabSize = TSize (KDoubleSliderTabWidth, KDoubleSliderTabHeight); |
|
319 break; |
|
320 } |
|
321 |
|
322 // HVGA |
|
323 case CResolutionUtil::EHVGA: |
|
324 case CResolutionUtil::EHVGAFullScreen: |
|
325 case CResolutionUtil::EHVGALandscape: |
|
326 case CResolutionUtil::EHVGALandscapeFullScreen: |
|
327 { |
|
328 sliderSize = TSize (KHVGASliderWidth, KHVGASliderHeight); |
|
329 tabSize = TSize (KHVGASliderTabWidth, KHVGASliderTabHeight); |
|
330 break; |
|
331 } |
|
332 |
|
333 // VGA |
|
334 case CResolutionUtil::EVGA: |
|
335 case CResolutionUtil::EVGAFullScreen: |
|
336 case CResolutionUtil::EVGALandscape: |
|
337 case CResolutionUtil::EVGALandscapeFullScreen: |
|
338 { |
|
339 sliderSize = TSize (KVGASliderWidth, KVGASliderHeight); |
|
340 tabSize = TSize (KVGASliderTabWidth, KVGASliderTabHeight); |
|
341 break; |
|
342 } |
|
343 |
|
344 // QHD |
|
345 case CResolutionUtil::EQHD: |
|
346 case CResolutionUtil::EQHDFullScreen: |
|
347 case CResolutionUtil::EQHDLandscape: |
|
348 case CResolutionUtil::EQHDLandscapeFullScreen: |
|
349 { |
|
350 sliderSize = TSize (KQHDSliderWidth, KQHDSliderHeight); |
|
351 tabSize = TSize (KQHDSliderTabWidth, KQHDSliderTabHeight); |
|
352 break; |
|
353 } |
|
354 |
|
355 default: |
|
356 { |
|
357 sliderSize = TSize (KStandardSliderWidth, KStandardSliderHeight); |
|
358 tabSize = TSize (KStandardSliderTabWidth, KStandardSliderTabHeight); |
|
359 break; |
|
360 } |
|
361 } |
|
362 |
|
363 // Set size for scalable icons - MUST BE CALLED BEFORE ICON IS USABLE |
|
364 AknIconUtils::SetSize( iSliderBg, sliderSize ); |
|
365 AknIconUtils::SetSize( iSliderTab, tabSize ); |
|
366 |
|
367 } |
|
368 |
|
369 // End of File |