author | eric <eric> | 2003-02-25 13:37:30 (UTC) |
---|---|---|
committer | eric <eric> | 2003-02-25 13:37:30 (UTC) |
commit | af4a36adc86052db4ab6855830cb7c5cc9e2d008 (patch) (unidiff) | |
tree | 6c1e4c51ce9663b8256f56aa0c98ab1eaab72d07 | |
parent | e21765875b06f8e76bdd6cfce120a68beaf48e41 (diff) | |
download | opie-af4a36adc86052db4ab6855830cb7c5cc9e2d008.zip opie-af4a36adc86052db4ab6855830cb7c5cc9e2d008.tar.gz opie-af4a36adc86052db4ab6855830cb7c5cc9e2d008.tar.bz2 |
- add more currency support
-rw-r--r-- | noncore/tools/euroconv/calcdisplay.cpp | 40 | ||||
-rw-r--r-- | noncore/tools/euroconv/currency.h | 10 |
2 files changed, 43 insertions, 7 deletions
diff --git a/noncore/tools/euroconv/calcdisplay.cpp b/noncore/tools/euroconv/calcdisplay.cpp index 1659858..898de81 100644 --- a/noncore/tools/euroconv/calcdisplay.cpp +++ b/noncore/tools/euroconv/calcdisplay.cpp | |||
@@ -1,216 +1,248 @@ | |||
1 | /**************************************************************************** | 1 | /**************************************************************************** |
2 | * | 2 | * |
3 | * File: calcdisplay.cpp | 3 | * File: calcdisplay.cpp |
4 | * | 4 | * |
5 | * Description: | 5 | * Description: |
6 | * | 6 | * |
7 | * | 7 | * |
8 | * Authors: Eric Santonacci <Eric.Santonacci@talc.fr> | 8 | * Authors: Eric Santonacci <Eric.Santonacci@talc.fr> |
9 | * | 9 | * |
10 | * Requirements: Qt | 10 | * Requirements: Qt |
11 | * | 11 | * |
12 | * $Id$ | 12 | * $Id$ |
13 | * | 13 | * |
14 | ***************************************************************************/ | 14 | ***************************************************************************/ |
15 | 15 | ||
16 | #include <stdio.h> | 16 | #include <stdio.h> |
17 | #include <qvbox.h> | 17 | #include <qvbox.h> |
18 | #include <qpixmap.h> | 18 | #include <qpixmap.h> |
19 | 19 | ||
20 | #include "currency.h" | 20 | #include "currency.h" |
21 | #include "calcdisplay.h" | 21 | #include "calcdisplay.h" |
22 | 22 | ||
23 | 23 | ||
24 | LCDDisplay::LCDDisplay( QWidget *parent, const char *name ) | 24 | LCDDisplay::LCDDisplay( QWidget *parent, const char *name ) |
25 | : QHBox( parent, name ){ | 25 | : QHBox( parent, name ){ |
26 | 26 | ||
27 | 27 | ||
28 | 28 | ||
29 | this->setMargin(5); | 29 | this->setMargin(5); |
30 | this->setSpacing(5); | 30 | this->setSpacing(5); |
31 | 31 | ||
32 | // Create display | 32 | // Create display |
33 | QVBox *vbxlayout = new QVBox (this); | 33 | QVBox *vbxlayout = new QVBox (this); |
34 | 34 | ||
35 | /*************** Top LCD ***********************/ | 35 | /*************** Top LCD ***********************/ |
36 | grpbxTop = new QHGroupBox(vbxlayout, "grpbxTop"); | 36 | grpbxTop = new QHGroupBox(vbxlayout, "grpbxTop"); |
37 | grpbxStyle = grpbxTop->frameStyle(); | 37 | grpbxStyle = grpbxTop->frameStyle(); |
38 | grpbxTop->setMaximumHeight(48); | 38 | grpbxTop->setMaximumHeight(48); |
39 | 39 | ||
40 | cbbxTop = new QComboBox(grpbxTop, "cbbxTop"); | 40 | cbbxTop = new QComboBox(grpbxTop, "cbbxTop"); |
41 | cbbxTop->setMaximumWidth(50); | 41 | cbbxTop->setMaximumWidth(50); |
42 | cbbxTop->insertStrList(aCurrency); | 42 | cbbxTop->insertStrList(aCurrency); |
43 | 43 | ||
44 | lcdTop = new QLCDNumber(10, grpbxTop, "lcdTop"); | 44 | lcdTop = new QLCDNumber(10, grpbxTop, "lcdTop"); |
45 | lcdTop->setMode( QLCDNumber::DEC ); | 45 | lcdTop->setMode( QLCDNumber::DEC ); |
46 | lcdTop->setSmallDecimalPoint(true); | 46 | lcdTop->setSmallDecimalPoint(true); |
47 | lcdTop->setSegmentStyle(QLCDNumber::Flat); | 47 | lcdTop->setSegmentStyle(QLCDNumber::Flat); |
48 | 48 | ||
49 | /************** Bottom LCD ************************/ | 49 | /************** Bottom LCD ************************/ |
50 | grpbxBottom = new QHGroupBox(vbxlayout, "grpbxBottom"); | 50 | grpbxBottom = new QHGroupBox(vbxlayout, "grpbxBottom"); |
51 | grpbxBottom->setMaximumHeight(46); | 51 | grpbxBottom->setMaximumHeight(46); |
52 | grpbxBottom->setFrameStyle(0); | 52 | grpbxBottom->setFrameStyle(0); |
53 | grpbxBottom->setFrameShadow(QFrame::MShadow); | 53 | grpbxBottom->setFrameShadow(QFrame::MShadow); |
54 | 54 | ||
55 | cbbxBottom = new QComboBox(grpbxBottom, "cbbxBottom"); | 55 | cbbxBottom = new QComboBox(grpbxBottom, "cbbxBottom"); |
56 | cbbxBottom->setMaximumWidth(50); | 56 | cbbxBottom->setMaximumWidth(50); |
57 | cbbxBottom->insertStrList(aCurrency); | 57 | cbbxBottom->insertStrList(aCurrency); |
58 | 58 | ||
59 | lcdBottom = new QLCDNumber(10, grpbxBottom, "lcdBottom"); | 59 | lcdBottom = new QLCDNumber(10, grpbxBottom, "lcdBottom"); |
60 | lcdBottom->setMode( QLCDNumber::DEC ); | 60 | lcdBottom->setMode( QLCDNumber::DEC ); |
61 | lcdBottom->setSmallDecimalPoint(true); | 61 | lcdBottom->setSmallDecimalPoint(true); |
62 | lcdBottom->setSegmentStyle(QLCDNumber::Flat); | 62 | lcdBottom->setSegmentStyle(QLCDNumber::Flat); |
63 | 63 | ||
64 | // set combo box signals | 64 | // set combo box signals |
65 | connect(cbbxTop, SIGNAL(activated(int)), this, SLOT(cbbxChange())); | 65 | connect(cbbxTop, SIGNAL(activated(int)), this, SLOT(cbbxChange())); |
66 | connect(cbbxBottom, SIGNAL(activated(int)), this, SLOT(cbbxChange())); | 66 | connect(cbbxBottom, SIGNAL(activated(int)), this, SLOT(cbbxChange())); |
67 | 67 | ||
68 | btnSwap = new QPushButton(this, "swap"); | 68 | btnSwap = new QPushButton(this, "swap"); |
69 | QPixmap imgSwap((const char**) swap_xpm); | 69 | QPixmap imgSwap((const char**) swap_xpm); |
70 | btnSwap->setPixmap(imgSwap); | 70 | btnSwap->setPixmap(imgSwap); |
71 | btnSwap->setFixedSize(20,40); | 71 | btnSwap->setFixedSize(20,40); |
72 | // set signal | 72 | // set signal |
73 | connect(btnSwap, SIGNAL(clicked()), this, SLOT(swapLCD())); | 73 | connect(btnSwap, SIGNAL(clicked()), this, SLOT(swapLCD())); |
74 | 74 | ||
75 | // set default LCD to top | 75 | // set default LCD to top |
76 | iCurrentLCD = 0; | 76 | iCurrentLCD = 0; |
77 | 77 | ||
78 | } | 78 | } |
79 | 79 | ||
80 | /*********************************************************************** | 80 | /*********************************************************************** |
81 | * SLOT: Display value in the correct LCD | 81 | * SLOT: Display value in the correct LCD |
82 | **********************************************************************/ | 82 | **********************************************************************/ |
83 | void LCDDisplay::setValue(double dSrcValue){ | 83 | void LCDDisplay::setValue(double dSrcValue){ |
84 | 84 | ||
85 | double dDstValue=0; | 85 | double dDstValue=0; |
86 | 86 | ||
87 | int iSrcIndex; | 87 | int iSrcIndex; |
88 | int iDstIndex; | 88 | int iDstIndex; |
89 | 89 | ||
90 | 90 | ||
91 | // get item index of the focused | 91 | // get item index of the focused |
92 | if(!iCurrentLCD){ | 92 | if(!iCurrentLCD){ |
93 | iSrcIndex = cbbxTop->currentItem(); | 93 | iSrcIndex = cbbxTop->currentItem(); |
94 | iDstIndex = cbbxBottom->currentItem(); | 94 | iDstIndex = cbbxBottom->currentItem(); |
95 | }else{ | 95 | }else{ |
96 | iSrcIndex = cbbxBottom->currentItem(); | 96 | iSrcIndex = cbbxBottom->currentItem(); |
97 | iDstIndex = cbbxTop->currentItem(); | 97 | iDstIndex = cbbxTop->currentItem(); |
98 | } | 98 | } |
99 | 99 | ||
100 | if(iSrcIndex == iDstIndex) | 100 | if(iSrcIndex == iDstIndex) |
101 | dDstValue = dSrcValue; | 101 | dDstValue = dSrcValue; |
102 | else{ | 102 | else{ |
103 | if(iSrcIndex){ | 103 | if(iSrcIndex){ |
104 | // we are NOT in Euro as iDstIndex <> 0 | 104 | // we are NOT in Euro as iDstIndex <> 0 |
105 | // Convert to Euro | 105 | // Convert to Euro |
106 | dDstValue = x2Euro(iSrcIndex, dSrcValue); | 106 | dDstValue = x2Euro(iSrcIndex, dSrcValue); |
107 | dDstValue = Euro2x(iDstIndex, dDstValue); | 107 | dDstValue = Euro2x(iDstIndex, dDstValue); |
108 | }else | 108 | }else |
109 | // We are in Euro | 109 | // We are in Euro |
110 | dDstValue = Euro2x(iDstIndex, dSrcValue); | 110 | dDstValue = Euro2x(iDstIndex, dSrcValue); |
111 | } | 111 | } |
112 | 112 | ||
113 | 113 | ||
114 | if(!iCurrentLCD){ | 114 | if(!iCurrentLCD){ |
115 | lcdTop->display(dSrcValue); | 115 | lcdTop->display(dSrcValue); |
116 | lcdBottom->display(dDstValue); | 116 | lcdBottom->display(dDstValue); |
117 | }else{ | 117 | }else{ |
118 | lcdBottom->display(dSrcValue); | 118 | lcdBottom->display(dSrcValue); |
119 | lcdTop->display(dDstValue); | 119 | lcdTop->display(dDstValue); |
120 | } | 120 | } |
121 | 121 | ||
122 | } | 122 | } |
123 | 123 | ||
124 | /*********************************************************************** | 124 | /*********************************************************************** |
125 | * SLOT: Swap output keypad between LCD displays | 125 | * SLOT: Swap output keypad between LCD displays |
126 | **********************************************************************/ | 126 | **********************************************************************/ |
127 | void LCDDisplay::swapLCD(void){ | 127 | void LCDDisplay::swapLCD(void){ |
128 | 128 | ||
129 | double dCurrentValue; | 129 | double dCurrentValue; |
130 | 130 | ||
131 | // get current value | 131 | // get current value |
132 | if(!iCurrentLCD){ | 132 | if(!iCurrentLCD){ |
133 | // iCurrentLCD = 0, lcdTop has current focus and is going to loose | 133 | // iCurrentLCD = 0, lcdTop has current focus and is going to loose |
134 | // it | 134 | // it |
135 | dCurrentValue = lcdTop->value(); | 135 | dCurrentValue = lcdTop->value(); |
136 | iCurrentLCD = 1; | 136 | iCurrentLCD = 1; |
137 | grpbxTop->setFrameStyle(0); | 137 | grpbxTop->setFrameStyle(0); |
138 | grpbxBottom->setFrameStyle(grpbxStyle); | 138 | grpbxBottom->setFrameStyle(grpbxStyle); |
139 | }else{ | 139 | }else{ |
140 | dCurrentValue = lcdBottom->value(); | 140 | dCurrentValue = lcdBottom->value(); |
141 | iCurrentLCD = 0; | 141 | iCurrentLCD = 0; |
142 | grpbxTop->setFrameStyle(grpbxStyle); | 142 | grpbxTop->setFrameStyle(grpbxStyle); |
143 | grpbxBottom->setFrameStyle(0); | 143 | grpbxBottom->setFrameStyle(0); |
144 | } | 144 | } |
145 | 145 | ||
146 | setValue(dCurrentValue); | 146 | setValue(dCurrentValue); |
147 | } | 147 | } |
148 | 148 | ||
149 | /*********************************************************************** | 149 | /*********************************************************************** |
150 | * SLOT: Currency change | 150 | * SLOT: Currency change |
151 | **********************************************************************/ | 151 | **********************************************************************/ |
152 | void LCDDisplay::cbbxChange(void){ | 152 | void LCDDisplay::cbbxChange(void){ |
153 | 153 | ||
154 | double dCurrentValue; | 154 | double dCurrentValue; |
155 | 155 | ||
156 | // get current value | 156 | // get current value |
157 | if(!iCurrentLCD){ | 157 | if(!iCurrentLCD){ |
158 | dCurrentValue = lcdTop->value(); | 158 | dCurrentValue = lcdTop->value(); |
159 | }else{ | 159 | }else{ |
160 | dCurrentValue = lcdBottom->value(); | 160 | dCurrentValue = lcdBottom->value(); |
161 | } | 161 | } |
162 | 162 | ||
163 | setValue(dCurrentValue); | 163 | setValue(dCurrentValue); |
164 | } | 164 | } |
165 | 165 | ||
166 | 166 | ||
167 | /*********************************************************************** | 167 | /*********************************************************************** |
168 | * Euro2x converts dValue from Euro to the currency which combo box | 168 | * Euro2x converts dValue from Euro to the currency which combo box |
169 | * index is provided in iIndex. | 169 | * index is provided in iIndex. |
170 | **********************************************************************/ | 170 | **********************************************************************/ |
171 | double LCDDisplay::Euro2x(int iIndex, double dValue){ | 171 | double LCDDisplay::Euro2x(int iIndex, double dValue){ |
172 | 172 | ||
173 | switch (iIndex){ | 173 | switch (iIndex){ |
174 | case 0: // Euro | 174 | case 0: // Euro |
175 | return(dValue); | 175 | return(dValue); |
176 | break; | 176 | break; |
177 | 177 | ||
178 | case 1: // FF: French Francs | 178 | case 1: // FF: French Francs |
179 | return(dValue*FF); | 179 | return(dValue*FRF); |
180 | break; | 180 | break; |
181 | 181 | ||
182 | case 2: // DM: Deutch Mark | 182 | case 2: // DM: Deutch Mark |
183 | return(dValue*DM); | 183 | return(dValue*DEM); |
184 | break; | ||
185 | |||
186 | case 3: // BEL Belgium Francs | ||
187 | return(dValue*BEF); | ||
188 | break; | ||
189 | |||
190 | case 4: // ITL Itialian Lire | ||
191 | return(dValue*ITL); | ||
192 | break; | ||
193 | |||
194 | case 5: // LUF Luxemburg | ||
195 | return(dValue*LUF); | ||
196 | break; | ||
197 | |||
198 | case 6: // IEP Irish Pound | ||
199 | return(dValue*IEP); | ||
184 | break; | 200 | break; |
185 | 201 | ||
186 | default: | 202 | default: |
187 | return 0; | 203 | return 0; |
188 | }//switch (iIndex) | 204 | }//switch (iIndex) |
189 | }// fct Eur2x | 205 | }// fct Eur2x |
190 | 206 | ||
191 | 207 | ||
192 | 208 | ||
193 | /*********************************************************************** | 209 | /*********************************************************************** |
194 | * x2Euro converts dValue to Euro from the currency which combo box | 210 | * x2Euro converts dValue to Euro from the currency which combo box |
195 | * index is provided in iIndex. | 211 | * index is provided in iIndex. |
196 | **********************************************************************/ | 212 | **********************************************************************/ |
197 | double LCDDisplay::x2Euro(int iIndex, double dValue){ | 213 | double LCDDisplay::x2Euro(int iIndex, double dValue){ |
198 | 214 | ||
199 | switch (iIndex){ | 215 | switch (iIndex){ |
200 | case 0: // Euro | 216 | case 0: // Euro |
201 | return(dValue); | 217 | return(dValue); |
202 | break; | 218 | break; |
203 | 219 | ||
204 | case 1: // FF: French Francs | 220 | case 1: // FF: French Francs |
205 | return(dValue/FF); | 221 | return(dValue/FRF); |
206 | break; | 222 | break; |
207 | 223 | ||
208 | case 2: // DM: Deutch Mark | 224 | case 2: // DM: Deutch Mark |
209 | return(dValue/DM); | 225 | return(dValue/DEM); |
226 | break; | ||
227 | |||
228 | case 3: // BEL Belgium Francs | ||
229 | return(dValue/BEF); | ||
230 | break; | ||
231 | |||
232 | case 4: // ITL Itialian Lire | ||
233 | return(dValue/ITL); | ||
234 | break; | ||
235 | |||
236 | case 5: // LUF Luxemburg | ||
237 | return(dValue/LUF); | ||
238 | break; | ||
239 | |||
240 | case 6: // IEP Irish Pound | ||
241 | return(dValue/IEP); | ||
210 | break; | 242 | break; |
211 | }//switch (iIndex) | 243 | }//switch (iIndex) |
212 | 244 | ||
213 | // we shouldn't come here | 245 | // we shouldn't come here |
214 | return 0; | 246 | return 0; |
215 | 247 | ||
216 | }// fct x2Euro | 248 | }// fct x2Euro |
diff --git a/noncore/tools/euroconv/currency.h b/noncore/tools/euroconv/currency.h index d9ee75c..6ca4d09 100644 --- a/noncore/tools/euroconv/currency.h +++ b/noncore/tools/euroconv/currency.h | |||
@@ -1,20 +1,24 @@ | |||
1 | /**************************************************************************** | 1 | /**************************************************************************** |
2 | * | 2 | * |
3 | * File: currency.h | 3 | * File: currency.h |
4 | * | 4 | * |
5 | * Description: define constant for currency compare Euro | 5 | * Description: define constant for currency compare Euro |
6 | * | 6 | * |
7 | * | 7 | * |
8 | * Authors: Eric Santonacci <Eric.Santonacci@talc.fr> | 8 | * Authors: Eric Santonacci <Eric.Santonacci@talc.fr> |
9 | * | 9 | * |
10 | * | 10 | * |
11 | * $Id$ | 11 | * $Id$ |
12 | * | 12 | * |
13 | ***************************************************************************/ | 13 | ***************************************************************************/ |
14 | 14 | ||
15 | // 1 Euro equal.... | 15 | // 1 Euro equal.... |
16 | #define EURO 1 // Euro | 16 | #define EURO 1 // Euro |
17 | #define FF 6.55957 // French Francs | 17 | #define FRF 6.55957 // French Francs |
18 | #define DM 1.9594 // Deutch Mark | 18 | #define DEM 1.9594 // Deutch Mark |
19 | #define BEF 40.3399 // Belgium Francs | ||
20 | #define ITL 1936.27 // Italian Lire | ||
21 | #define LUF 40.3399 // Luxemburg | ||
22 | #define IEP 0.787564 // Irish Pound | ||
19 | 23 | ||
20 | static const char* aCurrency[] = { "Euro", "FF", "DM", 0 }; | 24 | static const char* aCurrency[] = { "Euro", "FRF", "DEM", "BEF", "ITL", "LUF", "IEP", 0 }; |