summaryrefslogtreecommitdiff
path: root/noncore/tools/euroconv/calcdisplay.cpp
blob: 8f3de225e2007d9e49f8e5edf5e37c4ec791dbc1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
/****************************************************************************
 *
 * File:        calcdisplay.cpp
 *
 * Description:
 *
 *
 * Authors:     Eric Santonacci <Eric.Santonacci@talc.fr>
 *
 * Requirements:    Qt
 *
 * $Id$
 *
 ***************************************************************************/

#include <stdio.h>
#include <qvbox.h>
#include <qpixmap.h>

#include "currency.h"
#include "calcdisplay.h"

/* XPM */
static char *swap_xpm[] = {
/* width height num_colors chars_per_pixel */
"    13    18        2            1",
/* colors */
". c None",
"# c #000000",
/* pixels */
"..#######....",
"..#####......",
"..######.....",
"..#...###....",
"........##...",
".........##..",
"..........##.",
"...........##",
"...........##",
"...........##",
"...........##",
"..........##.",
".........##..",
"........##...",
"..#...###....",
"..######.....",
"..#####......",
"..#######....",
};


LCDDisplay::LCDDisplay( QWidget *parent, const char *name )
        : QHBox( parent, name ){



this->setMargin(5);
this->setSpacing(5);

// Create display
QVBox *vbxlayout    = new QVBox (this);

/***************    Top LCD   ***********************/
grpbxTop    = new QHGroupBox(vbxlayout, "grpbxTop");
grpbxStyle  = grpbxTop->frameStyle();
grpbxTop->setMaximumHeight(48);

cbbxTop     = new QComboBox(grpbxTop, "cbbxTop");
cbbxTop->setMaximumWidth(50);
cbbxTop->insertStrList(aCurrency);

lcdTop      = new QLCDNumber(10, grpbxTop, "lcdTop");
lcdTop->setMode( QLCDNumber::DEC );
lcdTop->setSmallDecimalPoint(false);
lcdTop->setSegmentStyle(QLCDNumber::Flat);

/**************   Bottom LCD  ************************/
grpbxBottom = new QHGroupBox(vbxlayout, "grpbxBottom");
grpbxBottom->setMaximumHeight(46);
grpbxBottom->setFrameStyle(0);
grpbxBottom->setFrameShadow(QFrame::MShadow);

cbbxBottom  = new QComboBox(grpbxBottom, "cbbxBottom");
cbbxBottom->setMaximumWidth(50);
cbbxBottom->insertStrList(aCurrency);

lcdBottom   = new QLCDNumber(10, grpbxBottom, "lcdBottom");
lcdBottom->setMode( QLCDNumber::DEC );
lcdBottom->setSmallDecimalPoint(false);
lcdBottom->setSegmentStyle(QLCDNumber::Flat);

// set combo box signals
connect(cbbxTop, SIGNAL(activated(int)), this, SLOT(cbbxChange()));
connect(cbbxBottom, SIGNAL(activated(int)), this, SLOT(cbbxChange()));

btnSwap     = new QPushButton(this, "swap");
QPixmap imgSwap((const char**) swap_xpm);
btnSwap->setPixmap(imgSwap);
btnSwap->setFixedSize(20,40);
// set signal
connect(btnSwap, SIGNAL(clicked()), this, SLOT(swapLCD()));

// set default LCD to top
iCurrentLCD = 0;

}

/***********************************************************************
 * SLOT: Display value in the correct LCD
 **********************************************************************/
void LCDDisplay::setValue(double dSrcValue){

double  dDstValue=0;

int     iSrcIndex;
int     iDstIndex;


// get item index of the focused
if(!iCurrentLCD){
    iSrcIndex = cbbxTop->currentItem();
    iDstIndex = cbbxBottom->currentItem();
}else{
    iSrcIndex = cbbxBottom->currentItem();
    iDstIndex = cbbxTop->currentItem();
}

if(iSrcIndex == iDstIndex)
    dDstValue = dSrcValue;
else{
    if(iSrcIndex){
        // we are NOT in Euro as iDstIndex <> 0
        // Convert to Euro
        dDstValue = x2Euro(iSrcIndex, dSrcValue);
        dDstValue = Euro2x(iDstIndex, dDstValue);
    }else
        // We are in Euro
        dDstValue = Euro2x(iDstIndex, dSrcValue);
}


if(!iCurrentLCD){
    lcdTop->display(dSrcValue);
    lcdBottom->display(dDstValue);
}else{
    lcdBottom->display(dSrcValue);
    lcdTop->display(dDstValue);
}

}

/***********************************************************************
 * SLOT: Swap output keypad between LCD displays
 **********************************************************************/
void LCDDisplay::swapLCD(void){

double dCurrentValue;

// get current value
if(!iCurrentLCD){
    // iCurrentLCD = 0, lcdTop has current focus and is going to loose
    // it
    dCurrentValue = lcdTop->value();
    iCurrentLCD = 1;
    grpbxTop->setFrameStyle(0);
    grpbxBottom->setFrameStyle(grpbxStyle);
}else{
    dCurrentValue = lcdBottom->value();
    iCurrentLCD = 0;
    grpbxTop->setFrameStyle(grpbxStyle);
    grpbxBottom->setFrameStyle(0);
}

setValue(dCurrentValue);
}

/***********************************************************************
 * SLOT: Currency change
 **********************************************************************/
void LCDDisplay::cbbxChange(void){

double dCurrentValue;

// get current value
if(!iCurrentLCD){
    dCurrentValue = lcdTop->value();
}else{
    dCurrentValue = lcdBottom->value();
}

setValue(dCurrentValue);
}


/***********************************************************************
 * Euro2x converts dValue from Euro to the currency which combo box
 * index is provided in iIndex.
 **********************************************************************/
double LCDDisplay::Euro2x(int iIndex, double dValue){

switch (iIndex){
    case 0: // Euro
        return(dValue);
        break;

    case 1: // FF: French Francs
        return(dValue*FRF);
        break;

    case 2: // DM: Deutch Mark
        return(dValue*DEM);
        break;

    case 3: // BEL Belgium Francs
        return(dValue*BEF);
        break;

    case 4: // ITL Itialian Lire
        return(dValue*ITL);
        break;

    case 5: // LUF Luxemburg
        return(dValue*LUF);
        break;

    case 6: // IEP Irish Pound
        return(dValue*IEP);
        break;

    default:
        return 0;
}//switch (iIndex)
}// fct Eur2x



/***********************************************************************
 * x2Euro converts dValue to Euro from the currency which combo box
 * index is provided in iIndex.
 **********************************************************************/
double LCDDisplay::x2Euro(int iIndex, double dValue){

switch (iIndex){
    case 0: // Euro
        return(dValue);
        break;

    case 1: // FF: French Francs
        return(dValue/FRF);
        break;

    case 2: // DM: Deutch Mark
        return(dValue/DEM);
        break;

    case 3: // BEL Belgium Francs
        return(dValue/BEF);
        break;

    case 4: // ITL Itialian Lire
        return(dValue/ITL);
        break;

    case 5: // LUF Luxemburg
        return(dValue/LUF);
        break;

    case 6: // IEP Irish Pound
        return(dValue/IEP);
        break;
}//switch (iIndex)

// we shouldn't come here
return 0;

}// fct x2Euro