summaryrefslogtreecommitdiff
authoreric <eric>2003-02-25 13:37:30 (UTC)
committer eric <eric>2003-02-25 13:37:30 (UTC)
commitaf4a36adc86052db4ab6855830cb7c5cc9e2d008 (patch) (unidiff)
tree6c1e4c51ce9663b8256f56aa0c98ab1eaab72d07
parente21765875b06f8e76bdd6cfce120a68beaf48e41 (diff)
downloadopie-af4a36adc86052db4ab6855830cb7c5cc9e2d008.zip
opie-af4a36adc86052db4ab6855830cb7c5cc9e2d008.tar.gz
opie-af4a36adc86052db4ab6855830cb7c5cc9e2d008.tar.bz2
- add more currency support
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/tools/euroconv/calcdisplay.cpp40
-rw-r--r--noncore/tools/euroconv/currency.h10
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
24LCDDisplay::LCDDisplay( QWidget *parent, const char *name ) 24LCDDisplay::LCDDisplay( QWidget *parent, const char *name )
25 : QHBox( parent, name ){ 25 : QHBox( parent, name ){
26 26
27 27
28 28
29this->setMargin(5); 29this->setMargin(5);
30this->setSpacing(5); 30this->setSpacing(5);
31 31
32// Create display 32// Create display
33QVBox *vbxlayout = new QVBox (this); 33QVBox *vbxlayout = new QVBox (this);
34 34
35/*************** Top LCD ***********************/ 35/*************** Top LCD ***********************/
36grpbxTop = new QHGroupBox(vbxlayout, "grpbxTop"); 36grpbxTop = new QHGroupBox(vbxlayout, "grpbxTop");
37grpbxStyle = grpbxTop->frameStyle(); 37grpbxStyle = grpbxTop->frameStyle();
38grpbxTop->setMaximumHeight(48); 38grpbxTop->setMaximumHeight(48);
39 39
40cbbxTop = new QComboBox(grpbxTop, "cbbxTop"); 40cbbxTop = new QComboBox(grpbxTop, "cbbxTop");
41cbbxTop->setMaximumWidth(50); 41cbbxTop->setMaximumWidth(50);
42cbbxTop->insertStrList(aCurrency); 42cbbxTop->insertStrList(aCurrency);
43 43
44lcdTop = new QLCDNumber(10, grpbxTop, "lcdTop"); 44lcdTop = new QLCDNumber(10, grpbxTop, "lcdTop");
45lcdTop->setMode( QLCDNumber::DEC ); 45lcdTop->setMode( QLCDNumber::DEC );
46lcdTop->setSmallDecimalPoint(true); 46lcdTop->setSmallDecimalPoint(true);
47lcdTop->setSegmentStyle(QLCDNumber::Flat); 47lcdTop->setSegmentStyle(QLCDNumber::Flat);
48 48
49/************** Bottom LCD ************************/ 49/************** Bottom LCD ************************/
50grpbxBottom = new QHGroupBox(vbxlayout, "grpbxBottom"); 50grpbxBottom = new QHGroupBox(vbxlayout, "grpbxBottom");
51grpbxBottom->setMaximumHeight(46); 51grpbxBottom->setMaximumHeight(46);
52grpbxBottom->setFrameStyle(0); 52grpbxBottom->setFrameStyle(0);
53grpbxBottom->setFrameShadow(QFrame::MShadow); 53grpbxBottom->setFrameShadow(QFrame::MShadow);
54 54
55cbbxBottom = new QComboBox(grpbxBottom, "cbbxBottom"); 55cbbxBottom = new QComboBox(grpbxBottom, "cbbxBottom");
56cbbxBottom->setMaximumWidth(50); 56cbbxBottom->setMaximumWidth(50);
57cbbxBottom->insertStrList(aCurrency); 57cbbxBottom->insertStrList(aCurrency);
58 58
59lcdBottom = new QLCDNumber(10, grpbxBottom, "lcdBottom"); 59lcdBottom = new QLCDNumber(10, grpbxBottom, "lcdBottom");
60lcdBottom->setMode( QLCDNumber::DEC ); 60lcdBottom->setMode( QLCDNumber::DEC );
61lcdBottom->setSmallDecimalPoint(true); 61lcdBottom->setSmallDecimalPoint(true);
62lcdBottom->setSegmentStyle(QLCDNumber::Flat); 62lcdBottom->setSegmentStyle(QLCDNumber::Flat);
63 63
64// set combo box signals 64// set combo box signals
65connect(cbbxTop, SIGNAL(activated(int)), this, SLOT(cbbxChange())); 65connect(cbbxTop, SIGNAL(activated(int)), this, SLOT(cbbxChange()));
66connect(cbbxBottom, SIGNAL(activated(int)), this, SLOT(cbbxChange())); 66connect(cbbxBottom, SIGNAL(activated(int)), this, SLOT(cbbxChange()));
67 67
68btnSwap = new QPushButton(this, "swap"); 68btnSwap = new QPushButton(this, "swap");
69QPixmap imgSwap((const char**) swap_xpm); 69QPixmap imgSwap((const char**) swap_xpm);
70btnSwap->setPixmap(imgSwap); 70btnSwap->setPixmap(imgSwap);
71btnSwap->setFixedSize(20,40); 71btnSwap->setFixedSize(20,40);
72// set signal 72// set signal
73connect(btnSwap, SIGNAL(clicked()), this, SLOT(swapLCD())); 73connect(btnSwap, SIGNAL(clicked()), this, SLOT(swapLCD()));
74 74
75// set default LCD to top 75// set default LCD to top
76iCurrentLCD = 0; 76iCurrentLCD = 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 **********************************************************************/
83void LCDDisplay::setValue(double dSrcValue){ 83void LCDDisplay::setValue(double dSrcValue){
84 84
85double dDstValue=0; 85double dDstValue=0;
86 86
87int iSrcIndex; 87int iSrcIndex;
88int iDstIndex; 88int iDstIndex;
89 89
90 90
91// get item index of the focused 91// get item index of the focused
92if(!iCurrentLCD){ 92if(!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
100if(iSrcIndex == iDstIndex) 100if(iSrcIndex == iDstIndex)
101 dDstValue = dSrcValue; 101 dDstValue = dSrcValue;
102else{ 102else{
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
114if(!iCurrentLCD){ 114if(!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 **********************************************************************/
127void LCDDisplay::swapLCD(void){ 127void LCDDisplay::swapLCD(void){
128 128
129double dCurrentValue; 129double dCurrentValue;
130 130
131// get current value 131// get current value
132if(!iCurrentLCD){ 132if(!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
146setValue(dCurrentValue); 146setValue(dCurrentValue);
147} 147}
148 148
149/*********************************************************************** 149/***********************************************************************
150 * SLOT: Currency change 150 * SLOT: Currency change
151 **********************************************************************/ 151 **********************************************************************/
152void LCDDisplay::cbbxChange(void){ 152void LCDDisplay::cbbxChange(void){
153 153
154double dCurrentValue; 154double dCurrentValue;
155 155
156// get current value 156// get current value
157if(!iCurrentLCD){ 157if(!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
163setValue(dCurrentValue); 163setValue(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 **********************************************************************/
171double LCDDisplay::Euro2x(int iIndex, double dValue){ 171double LCDDisplay::Euro2x(int iIndex, double dValue){
172 172
173switch (iIndex){ 173switch (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 **********************************************************************/
197double LCDDisplay::x2Euro(int iIndex, double dValue){ 213double LCDDisplay::x2Euro(int iIndex, double dValue){
198 214
199switch (iIndex){ 215switch (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
214return 0; 246return 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
20static const char* aCurrency[] = { "Euro", "FF", "DM", 0 }; 24static const char* aCurrency[] = { "Euro", "FRF", "DEM", "BEF", "ITL", "LUF", "IEP", 0 };