|
1 /* |
|
2 * Copyright (c) 2008-2008 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: ALF control class for Analog Dialer example application, which |
|
15 * implements rotating dial pad. |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 |
|
21 #ifndef ANALOGDIALER_CONTROL_H |
|
22 #define ANALOGDIALER_CONTROL_H |
|
23 |
|
24 #include <alf/alfcontrol.h> // derivation from this class |
|
25 #include <alf/alftexturemanager.h> // derivation from this class |
|
26 |
|
27 // Forward reference |
|
28 class CAlfGridLayout; |
|
29 class CAlfDeckLayout; |
|
30 |
|
31 // Feedback launcher |
|
32 class CAlfExAnalogDialerFeedback; |
|
33 |
|
34 // Id of this CAlfExAnalogDialerControl |
|
35 const TInt KAlfExAnalogDialerControlId = 1; |
|
36 |
|
37 // Length of number display buffer |
|
38 const TInt KNumberDisplayBufferLength = 64; |
|
39 |
|
40 /** |
|
41 * Control class for Analog Dialer |
|
42 * |
|
43 * @since S60 5.0 |
|
44 */ |
|
45 class CAlfExAnalogDialerControl : public CAlfControl |
|
46 |
|
47 |
|
48 { |
|
49 public: |
|
50 |
|
51 |
|
52 /* Constructors and destructor. */ |
|
53 |
|
54 /** |
|
55 * First phase constructor of CAlfExAnalogDialerControl. |
|
56 * |
|
57 * @param aEnv ALF environment |
|
58 * @since S60 5.0 |
|
59 */ |
|
60 static CAlfExAnalogDialerControl* NewL(CAlfEnv& aEnv); |
|
61 |
|
62 /** |
|
63 * First phase constructor of CAlfExAnalogDialerControl. |
|
64 * |
|
65 * @param aEnv ALF environment |
|
66 * @since S60 5.0 |
|
67 */ |
|
68 static CAlfExAnalogDialerControl* NewLC(CAlfEnv& aEnv); |
|
69 |
|
70 /** |
|
71 * Destructor of CAlfExAnalogDialerAppUi |
|
72 * |
|
73 * @since S60 5.0 |
|
74 */ |
|
75 virtual ~CAlfExAnalogDialerControl(); |
|
76 |
|
77 /** |
|
78 * Prepares for layout switch |
|
79 */ |
|
80 void PrepareForLayoutSwitchL(); |
|
81 |
|
82 |
|
83 /** |
|
84 * Makes layout switch. The layout switch with same directionality as previous one |
|
85 * but with different resolution is supported, too. |
|
86 * |
|
87 * @param aRect new layout for the screen area |
|
88 */ |
|
89 void SwitchLayoutL(); |
|
90 |
|
91 private: |
|
92 |
|
93 |
|
94 /* Constructors */ |
|
95 |
|
96 /** |
|
97 * Constructor of CAlfExAnalogDialerAppUi. |
|
98 * Private as this object must be constructed via NewL() or NewLC() |
|
99 * |
|
100 * @since S60 5.0 |
|
101 */ |
|
102 CAlfExAnalogDialerControl(); |
|
103 |
|
104 /** |
|
105 * Second phase constructor of CAlfExAnalogDialerAppUi. |
|
106 * |
|
107 * @since S60 5.0 |
|
108 */ |
|
109 void ConstructL(CAlfEnv& aEnv); |
|
110 |
|
111 |
|
112 /* Methods. */ |
|
113 |
|
114 /** |
|
115 * Creates portrait layout for application |
|
116 * |
|
117 */ |
|
118 void SetupPortraitModeL(); |
|
119 |
|
120 /** |
|
121 * Creates landspace layout for application |
|
122 * |
|
123 */ |
|
124 void SetupLandscapeModeL(); |
|
125 |
|
126 // from base class CAlfControl |
|
127 /** |
|
128 * From CAlfControl. |
|
129 * Called when an input event is being offered to the control. |
|
130 * |
|
131 * @param aEvent Event to be handled. |
|
132 * |
|
133 * @return ETrue, if the event was handled. |
|
134 * EFalse, otherwise |
|
135 */ |
|
136 TBool OfferEventL(const TAlfEvent& aEvent); |
|
137 |
|
138 // own methods |
|
139 |
|
140 /** |
|
141 * Creates root layout for application |
|
142 */ |
|
143 void AddGridLayoutL(); |
|
144 |
|
145 /** |
|
146 * Create display pane to display dialed number(s) |
|
147 */ |
|
148 void AddDisplayPaneL(); |
|
149 |
|
150 /** |
|
151 * Create dialer pane for the application |
|
152 */ |
|
153 void AddDialerL(); |
|
154 |
|
155 // |
|
156 enum TLayoutMode |
|
157 { |
|
158 ELayoutAnalogDialerPortrait=0, |
|
159 ELayoutAnalogDialerLandscape, |
|
160 }; |
|
161 |
|
162 /** |
|
163 * Resolves current layout data. Layout rectangular is retrieved from Alf environment |
|
164 * |
|
165 * @param aShorterSide smaller extent of application rectangular |
|
166 * @param aLongerSide bigger extent of application rectangular |
|
167 * |
|
168 * @return TLayoutMode |
|
169 * @since S60 5.0 |
|
170 */ |
|
171 TLayoutMode ResolveLayout( TInt& aShorterSide, |
|
172 TInt& aLongerSide) const; |
|
173 |
|
174 /** |
|
175 * Adds dialed number into number display |
|
176 * @param aNumber number start from 0. Function adds internal +1 to the number |
|
177 */ |
|
178 void AddNumberToDisplayPaneL(TInt aNumber); |
|
179 |
|
180 /** |
|
181 * Handles pointer down event |
|
182 * @param aEvent event from ALF framework |
|
183 * |
|
184 * @since S60 5.0 |
|
185 */ |
|
186 TBool HandlePointerDownEventL(const TAlfEvent& aEvent); |
|
187 |
|
188 /** |
|
189 * Handles dragging events |
|
190 * @param aEvent event from ALF framework |
|
191 * |
|
192 * @since S60 5.0 |
|
193 */ |
|
194 TBool HandleDraggingEventL(const TAlfEvent& aEvent); |
|
195 |
|
196 /** |
|
197 * Handles long tap event |
|
198 * @param aEvent event from ALF framework |
|
199 * |
|
200 * @since S60 5.0 |
|
201 */ |
|
202 TBool HandlePointerLongTapEventL(const TAlfEvent& aEvent); |
|
203 |
|
204 /** |
|
205 * Handles pointer up event |
|
206 * @param aEvent event from ALF framework |
|
207 * |
|
208 * @since S60 5.0 |
|
209 */ |
|
210 TBool HandlePointerUpEventL(const TAlfEvent& aEvent); |
|
211 |
|
212 /** |
|
213 * Toggles value of iDraggingData.iIsClockWiseOverZeroReached, if zero angle of X-axis |
|
214 * crossed has been crossed. |
|
215 * @param aAngle of pointer event |
|
216 */ |
|
217 void ResolveXAxisCrossing(TInt aAngle); |
|
218 |
|
219 /** |
|
220 * Calculate angle of triangle, when adjacent and opposite sides are known |
|
221 * @param aAdjacent length of adjacent side (x-coordinate) |
|
222 * @param aOpposite length of opposite side (y-coordinate) |
|
223 * @return angle of position in degrees |
|
224 */ |
|
225 static TInt Angle(TReal32 aAdjacent, TReal32 aOpposite); |
|
226 |
|
227 /** |
|
228 * Calculate hypotenuse of triangle, when adjacent and opposite sides are known |
|
229 * @param aPosition position of pointer event |
|
230 * @return hypotenuse i.e. distance of pointer event from centre of the plate |
|
231 */ |
|
232 static TInt Hypotenuse(const TPoint& aPosition); |
|
233 |
|
234 /** |
|
235 * Sets weights of grid for a new grid layout, or grid layout after orientation or resolution |
|
236 * change. ResolveLayout() can be used to get basic input parameters |
|
237 * |
|
238 * aLayout layout of application rectangular |
|
239 * aSquareSide length of side of dialer pane, which must be square in form. |
|
240 * Value of this must be same as shorter side of application rectangular. |
|
241 * aLongerSide length of longer side of application rectangular |
|
242 * aPlateTop offset of Y-coordinate of the plate |
|
243 */ |
|
244 static void SetWeightsOfGridL( CAlfGridLayout& aGridLayout, |
|
245 TLayoutMode aLayout, |
|
246 TInt aSquareSide, |
|
247 TInt aLongerSide, |
|
248 TInt& aPlateTop); |
|
249 |
|
250 /** |
|
251 * Converts position of TAlfEvent to plate centric position, in which centre of the |
|
252 * plate represents position (0, 0). |
|
253 * X coordinates to the left of the centre position are negative. |
|
254 * Y coordinates above the centre position are negative. |
|
255 * |
|
256 * @param aEvent pointer event from Alf |
|
257 * @param aPlateTopOffset difference between Y coordinate of top left corner of plate pane and |
|
258 * top left corner of screen. Value is in pixels. |
|
259 * @param aSquareSide length of a side of plate pane square |
|
260 * @param aPlateCentricPoint returned position |
|
261 */ |
|
262 static void ConvertEventToPlateCentricPosition( |
|
263 const TAlfEvent& aEvent, |
|
264 TInt aPlateTopOffset, |
|
265 TInt aSquareSide, |
|
266 TPoint& aPlateCentricPoint); |
|
267 |
|
268 /** |
|
269 * Checks whether pointer event occurs between outer and inner radius |
|
270 * |
|
271 * @param aPlateCentric position of event returned by ConvertEventToPlateCentricPosition |
|
272 * @param aOuterRadius radius of outer arc. In pixels |
|
273 * @param aInnerRadius radius of inner arc. In pixels. |
|
274 * @return ETrue if radius of event is <= aOuterRadius or >= aInnerRadius |
|
275 * EFalse otherwise |
|
276 */ |
|
277 static TBool IsPointerEventOnArcPath( TPoint& aPlateCentricPoint, |
|
278 TInt aOuterRadius, |
|
279 TInt aInnerRadius); |
|
280 |
|
281 /** |
|
282 * Checks whether pointer event follows path which is between Clear area and edges of plate |
|
283 * @param aEvent pointer event from Alf |
|
284 * @return TBool |
|
285 */ |
|
286 TBool IsPointerEventFollowingNumbersArcPath(const TAlfEvent& aEvent) const; |
|
287 |
|
288 /** |
|
289 * Checks whether pointer event occurs on Clear area |
|
290 * @param aEvent pointer event from Alf |
|
291 * @return TBool |
|
292 */ |
|
293 TBool IsPointerEventOnClearKey(const TAlfEvent& aEvent) const; |
|
294 |
|
295 /** |
|
296 * Perfoms actions needed when dragging (rotating plate) has finished. |
|
297 * Actions are e.g. putting selected number into display, and rotating plate into idle position |
|
298 */ |
|
299 void FinishDragging(); |
|
300 |
|
301 /** |
|
302 * After rotating plate ends, resets data involved in calculations of turn angle of plate image. |
|
303 */ |
|
304 void ResetDraggingData(); |
|
305 |
|
306 /** |
|
307 * After clear key event ends, resets data involved in Clear key event. |
|
308 * The event started from pointer down event on Clear key area |
|
309 */ |
|
310 void ResetClearKeyData(); |
|
311 |
|
312 /** |
|
313 * Rotates plate back to idle position |
|
314 */ |
|
315 static void RotatePlateToIdlePosition(CAlfImageVisual& aImage); |
|
316 |
|
317 /** |
|
318 * Rotates image to a given angle. As the angle may jump from 0->359, |
|
319 * calculation of rotation angle becomes more complicated than subtracting initial angle from |
|
320 * current angle. |
|
321 * |
|
322 * @param aImage imagevisual to rotate |
|
323 * @param aInitialAngle initial angle of image visual |
|
324 * @param aTargetAngle current angle of image visual |
|
325 * @param aIsClockWiseOverZeroReached whether angle has jumped from 0->359 |
|
326 */ |
|
327 static void RotatePlate(CAlfImageVisual& aImage, |
|
328 TInt aInitialAngle, |
|
329 TInt aTargetAngle, |
|
330 TBool aIsClockWiseOverZeroReached); |
|
331 |
|
332 /** |
|
333 * Returns dialed number when initial angle and current angle is given. |
|
334 * @param aInitialAngle angle value between 0-360 |
|
335 * @param aCurrentAngle angle value between 0-360 |
|
336 * @return KErrNotFound, if plate has not rotated enough to select any value |
|
337 * otherwise 0-9 |
|
338 */ |
|
339 TInt DialedNumber( TInt aInitialAngle, |
|
340 TInt aCurrentAngle) const; |
|
341 |
|
342 /** |
|
343 * Puts dialed number into number display. |
|
344 * @param aInitialAngle angle value between 0-360 |
|
345 * @param aCurrentAngle angle value between 0-360 |
|
346 */ |
|
347 void DialedNumberToDisplay( TInt aInitialAngle, |
|
348 TInt aCurrentAngle ); |
|
349 |
|
350 /** |
|
351 * Clears number display; either wholly or last number. |
|
352 * @param aClearWholeDisplay clears number display wholly |
|
353 */ |
|
354 void ClearNumberDisplay(TBool aClearWholeDisplay); |
|
355 |
|
356 /** |
|
357 * Debugs dragging data + given angle into RDebug |
|
358 */ |
|
359 void DebugDraggingData(TInt aDegrees); |
|
360 |
|
361 private: |
|
362 |
|
363 // Image Ids for CAlfTextureManager |
|
364 enum TAnalogDialerImageIds |
|
365 { |
|
366 EImageIdAnalogDialerBgPt = 1, |
|
367 EImageIdAnalogDialerPlatePt, |
|
368 EImageIdAnalogDialerStopperPt, |
|
369 EImageIdAnalogDialerLast |
|
370 }; |
|
371 |
|
372 // Tag enumeration definition. It is used in the .cpp file to index tags in tables |
|
373 // defined .cpp file: |
|
374 // KTagArrayTheRest, which is tags for visuals, which are layout independent |
|
375 // Indexing of both arrays start from 0. |
|
376 enum TTagAnalogDialerVisual |
|
377 { |
|
378 ETagAnalogDialerRootLayout = 0, |
|
379 ETagAnalogDialerDisplayDeck, |
|
380 ETagAnalogDialerDisplayVisual, |
|
381 ETagAnalogDialerPlateDeck, |
|
382 ETagAnalogDialerNumbersVisual, |
|
383 ETagAnalogDialerPlateVisual, |
|
384 ETagAnalogDialerStopperVisual |
|
385 }; |
|
386 |
|
387 |
|
388 // indices for KRowsAndColumnsOfGrid and KWeightsGrid arrays defined in .cpp file |
|
389 enum TRowsAndColumnsOfGrid |
|
390 { |
|
391 EColumn = 0, |
|
392 ERow |
|
393 }; |
|
394 |
|
395 // indices for grid elements |
|
396 enum TIndicesGrid |
|
397 { |
|
398 EFirstGridElement = 0, |
|
399 ESecondGridElement |
|
400 }; |
|
401 |
|
402 /** |
|
403 * Data needed in calculating rotating angle of plate is grouped together. |
|
404 */ |
|
405 struct TDraggingData |
|
406 { |
|
407 /** Initial pointer angle. It is used to calculate selected number. |
|
408 * It is especially important, if stopper was not reached. |
|
409 */ |
|
410 TInt iInitialAngle; |
|
411 |
|
412 /** Previous pointer angle. This is just used to optimise plate redrawing. |
|
413 * Plate is not redrawn after every dragging event |
|
414 */ |
|
415 TInt iPreviousAngle; |
|
416 |
|
417 /** |
|
418 * When plate is rotated clockwise, angle of pointer position changes from 0 to 359. |
|
419 * When this happens, this flag is set. When change from 359 to 0 happens, |
|
420 * this flag is reset. |
|
421 */ |
|
422 TBool iIsClockWiseOverZeroReached; |
|
423 |
|
424 /** ETrue, if user has turned all the way to the stopper */ |
|
425 TBool iStopperReached; |
|
426 }; |
|
427 |
|
428 /** Miscellaneous flags to memorise state of the control */ |
|
429 enum TAnalogDialerControlFlags |
|
430 { |
|
431 /** Observer for long tap pointer event has been registered */ |
|
432 EAnalogDialerControlFlagLongTapRegistered = 0x1, |
|
433 |
|
434 /** Long tap has been pressed */ |
|
435 EAnalogDialerControlFlagLongTapPressed = 0x2, |
|
436 |
|
437 /** Set, if dragging is ongoing */ |
|
438 EAnalogDialerControlDragging = 0x4, |
|
439 |
|
440 /** Set, if clear key area pressed */ |
|
441 EAnalogDialerControlClearKeyEvent = 0x8, |
|
442 }; |
|
443 |
|
444 /** Flags of this control */ |
|
445 TInt iFlags; |
|
446 |
|
447 /** |
|
448 * Rotating plate image |
|
449 * Not own. |
|
450 */ |
|
451 CAlfGridLayout* iRootLayout; |
|
452 |
|
453 /** |
|
454 * Number display |
|
455 * Not own. |
|
456 */ |
|
457 CAlfTextVisual* iDisplayPane; |
|
458 |
|
459 /** Number current visible in the number display */ |
|
460 TBuf<KNumberDisplayBufferLength> iDisplayNumber; |
|
461 |
|
462 /** |
|
463 * ELayoutAnalogDialerPt: application is running in portrait mode |
|
464 * ELayoutAnalogDialerLd: application is running in landscape mode |
|
465 */ |
|
466 TLayoutMode iLayoutMode; |
|
467 |
|
468 /** |
|
469 * Feedback launcher |
|
470 * Own. |
|
471 */ |
|
472 CAlfExAnalogDialerFeedback* iFeedback; |
|
473 |
|
474 /** |
|
475 * Rotating plate image |
|
476 * Not own. |
|
477 */ |
|
478 CAlfImageVisual* iPlate; |
|
479 |
|
480 /** |
|
481 * Stopper image |
|
482 * Not own. |
|
483 */ |
|
484 CAlfImageVisual* iStopper; |
|
485 |
|
486 /** ETrue, if dragging is ongoing */ |
|
487 TBool iDragging; |
|
488 |
|
489 /** Length of the shorter edge of the plate */ |
|
490 TInt iSquareSide; |
|
491 |
|
492 /** Length of the longer edge of the application */ |
|
493 TInt iLongerSide; |
|
494 |
|
495 /** Y -coordinate of the plate */ |
|
496 TInt iPlateTopOffset; |
|
497 |
|
498 /** Data needed in calculating rotating angle of plate is grouped together.*/ |
|
499 TDraggingData iDraggingData; |
|
500 }; |
|
501 |
|
502 |
|
503 #endif // ANALOGDIALER_CONTROL_H |