summaryrefslogtreecommitdiff
path: root/noncore/tools/euroconv/calcdisplay.cpp
blob: 06e51585b5d700e19a93a22491041d4a3d13b207 (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
/****************************************************************************
 *
 * File:        calcdisplay.cpp
 *
 * Description:  
 *              
 *               
 * Authors:     Eric Santonacci <Eric.Santonacci@talc.fr>
 *
 * Requirements:    Qt
 *
 * $Id$
 *
 ***************************************************************************/

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

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


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


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

grpbxTop    = new QVGroupBox(vbxlayout, "grpbxTop");
cbbxTop     = new QComboBox(grpbxTop, "cbbxTop");
lcdTop      = new QLCDNumber(10, grpbxTop, "lcdTop");
lcdTop->setMode( QLCDNumber::DEC );
lcdTop->setSmallDecimalPoint(true);
lcdTop->setSegmentStyle(QLCDNumber::Flat);
cbbxTop->insertStrList(aCurrency);

grpbxBottom = new QVGroupBox(vbxlayout, "grpbxBottom");
cbbxBottom  = new QComboBox(grpbxBottom, "cbbxBottom");
lcdBottom   = new QLCDNumber(10, grpbxBottom, "lcdBottom");
lcdBottom->setMode( QLCDNumber::DEC );
lcdBottom->setSmallDecimalPoint(true);
lcdBottom->setSegmentStyle(QLCDNumber::Flat);
cbbxBottom->insertStrList(aCurrency);

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

btnSwap     = new QPushButton("S",this, "swap");
btnSwap->setMaximumSize(20,50);
btnSwap->setMinimumSize(20,50);
// set signal
connect(btnSwap, SIGNAL(clicked()), this, SLOT(swapLCD()));

// set default LCD to top
iCurrentLCD = 0;

//setValue(123.456);

}

/***********************************************************************
 * 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){
    dCurrentValue = lcdTop->value();
    iCurrentLCD = 1;
}else{
    dCurrentValue = lcdBottom->value();
    iCurrentLCD = 0;
}

setValue(dCurrentValue);
}

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

double dCurrentValue;

printf("combo changes...\n");

// 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*FF);
        break;

    case 2: // DM: Deutch Mark
        return(dValue*DM);
        break;
}//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/FF);
        break;

    case 2: // DM: Deutch Mark
        return(dValue/DM);
        break;
}//switch (iIndex)
}// fct x2Euro