|
1 /* |
|
2 * Copyright (c) 2004-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: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <AknQueryDialog.h> |
|
20 #include <StringLoader.h> |
|
21 #include <imageprintengine.rsg> |
|
22 |
|
23 #include "cfloatcapability.h" |
|
24 |
|
25 const TInt KMaxTRealCharNum( 30 ); |
|
26 const TInt KDecimals( 2 ); |
|
27 |
|
28 // Destructor |
|
29 CFloatCapability::~CFloatCapability() |
|
30 { |
|
31 } |
|
32 |
|
33 // Creates text string for the settings list box |
|
34 HBufC* CFloatCapability::ListBoxTextL() |
|
35 { |
|
36 const TInt KGranularity( 4 ); |
|
37 TRealFormat format( KMaxTRealCharNum, KDecimals ); |
|
38 TBuf<KMaxTRealCharNum> numStr; |
|
39 |
|
40 numStr.Zero(); |
|
41 numStr.AppendNum( iRealValue, format ); |
|
42 |
|
43 CDesCArrayFlat* strings = new ( ELeave ) CDesCArrayFlat( KGranularity ); |
|
44 CleanupStack::PushL( strings ); |
|
45 strings->AppendL( iTitle ); |
|
46 strings->AppendL( numStr ); |
|
47 |
|
48 HBufC* buf = StringLoader::LoadL( R_QTN_LBOX_FORMAT, *strings ); |
|
49 CleanupStack::PopAndDestroy(); // strings |
|
50 |
|
51 return buf; |
|
52 } |
|
53 |
|
54 // Displays pop-up list for changing the active TInt value |
|
55 TBool CFloatCapability::LaunchPopupListL() |
|
56 { |
|
57 TReal aMin = 0; |
|
58 TReal aMax = TReal( iMaxNumerator )/TReal( iDenominator ); |
|
59 |
|
60 CAknFloatingPointQueryDialog* dlg = |
|
61 CAknFloatingPointQueryDialog::NewL( iRealValue ); |
|
62 CleanupStack::PushL( dlg ); |
|
63 dlg->SetPromptL( iTitle ); |
|
64 dlg->PrepareLC( R_GENERIC_FLOAT_QUERY_DLG ); |
|
65 CleanupStack::Pop( dlg ); |
|
66 dlg->SetMinimumAndMaximum( aMin, aMax ); |
|
67 TBool valueChanged = dlg->RunLD(); |
|
68 |
|
69 if ( valueChanged ) |
|
70 { |
|
71 iValue = TInt( TReal ( iRealValue / TReal ( iDenominator ) ) ); |
|
72 } |
|
73 |
|
74 return valueChanged; |
|
75 } |
|
76 |
|
77 // Clones itself |
|
78 CBaseCapability* CFloatCapability::CloneL() |
|
79 { |
|
80 CFloatCapability* clone = new ( ELeave ) CFloatCapability; |
|
81 |
|
82 clone->iDenominator = iDenominator; |
|
83 clone->iIndexOnList = iIndexOnList; |
|
84 clone->iMaxNumerator = iMaxNumerator; |
|
85 clone->iValue = iValue; |
|
86 clone->iTitle = iTitle; |
|
87 clone->iUid = iUid; |
|
88 clone->iRealValue = iRealValue; |
|
89 |
|
90 return clone; |
|
91 } |
|
92 |
|
93 // Sets the new values and checks the boundaries |
|
94 TInt CFloatCapability::SetValues( |
|
95 TInt aDenom, |
|
96 TInt aNumerator, |
|
97 TInt aMaxNumerator ) |
|
98 { |
|
99 TInt err( KErrNone ); |
|
100 |
|
101 if ( aNumerator > aMaxNumerator ) |
|
102 { |
|
103 err = KErrArgument; |
|
104 } |
|
105 else |
|
106 { |
|
107 iDenominator = aDenom; |
|
108 iValue = aNumerator; |
|
109 iMaxNumerator = aMaxNumerator; |
|
110 if( iDenominator != 0 ) |
|
111 { |
|
112 iRealValue = TReal( iValue )/TReal( iDenominator ); |
|
113 } |
|
114 } |
|
115 |
|
116 return err; |
|
117 } |
|
118 |
|
119 // Numerator |
|
120 TInt CFloatCapability::Numerator() const |
|
121 { |
|
122 return iValue; |
|
123 } |
|
124 |
|
125 // Denominator |
|
126 TInt CFloatCapability::Denominator() const |
|
127 { |
|
128 return iDenominator; |
|
129 } |
|
130 |
|
131 // End of File |