Diffstat (limited to 'noncore/tools/euroconv/calcdisplay.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/tools/euroconv/calcdisplay.cpp | 188 |
1 files changed, 188 insertions, 0 deletions
diff --git a/noncore/tools/euroconv/calcdisplay.cpp b/noncore/tools/euroconv/calcdisplay.cpp new file mode 100644 index 0000000..06e5158 --- a/dev/null +++ b/noncore/tools/euroconv/calcdisplay.cpp | |||
@@ -0,0 +1,188 @@ | |||
1 | /**************************************************************************** | ||
2 | * | ||
3 | * File: calcdisplay.cpp | ||
4 | * | ||
5 | * Description: | ||
6 | * | ||
7 | * | ||
8 | * Authors: Eric Santonacci <Eric.Santonacci@talc.fr> | ||
9 | * | ||
10 | * Requirements: Qt | ||
11 | * | ||
12 | * $Id$ | ||
13 | * | ||
14 | ***************************************************************************/ | ||
15 | |||
16 | #include <stdio.h> | ||
17 | #include <qvbox.h> | ||
18 | |||
19 | #include "currency.h" | ||
20 | #include "calcdisplay.h" | ||
21 | |||
22 | |||
23 | LCDDisplay::LCDDisplay( QWidget *parent, const char *name ) | ||
24 | : QHBox( parent, name ){ | ||
25 | |||
26 | |||
27 | // Create display | ||
28 | QVBox *vbxlayout = new QVBox (this); | ||
29 | |||
30 | grpbxTop = new QVGroupBox(vbxlayout, "grpbxTop"); | ||
31 | cbbxTop = new QComboBox(grpbxTop, "cbbxTop"); | ||
32 | lcdTop = new QLCDNumber(10, grpbxTop, "lcdTop"); | ||
33 | lcdTop->setMode( QLCDNumber::DEC ); | ||
34 | lcdTop->setSmallDecimalPoint(true); | ||
35 | lcdTop->setSegmentStyle(QLCDNumber::Flat); | ||
36 | cbbxTop->insertStrList(aCurrency); | ||
37 | |||
38 | grpbxBottom = new QVGroupBox(vbxlayout, "grpbxBottom"); | ||
39 | cbbxBottom = new QComboBox(grpbxBottom, "cbbxBottom"); | ||
40 | lcdBottom = new QLCDNumber(10, grpbxBottom, "lcdBottom"); | ||
41 | lcdBottom->setMode( QLCDNumber::DEC ); | ||
42 | lcdBottom->setSmallDecimalPoint(true); | ||
43 | lcdBottom->setSegmentStyle(QLCDNumber::Flat); | ||
44 | cbbxBottom->insertStrList(aCurrency); | ||
45 | |||
46 | // set combo box signals | ||
47 | connect(cbbxTop, SIGNAL(activated(int)), this, SLOT(cbbxChange())); | ||
48 | connect(cbbxBottom, SIGNAL(activated(int)), this, SLOT(cbbxChange())); | ||
49 | |||
50 | btnSwap = new QPushButton("S",this, "swap"); | ||
51 | btnSwap->setMaximumSize(20,50); | ||
52 | btnSwap->setMinimumSize(20,50); | ||
53 | // set signal | ||
54 | connect(btnSwap, SIGNAL(clicked()), this, SLOT(swapLCD())); | ||
55 | |||
56 | // set default LCD to top | ||
57 | iCurrentLCD = 0; | ||
58 | |||
59 | //setValue(123.456); | ||
60 | |||
61 | } | ||
62 | |||
63 | /*********************************************************************** | ||
64 | * SLOT: Display value in the correct LCD | ||
65 | **********************************************************************/ | ||
66 | void LCDDisplay::setValue(double dSrcValue){ | ||
67 | |||
68 | double dDstValue=0; | ||
69 | |||
70 | int iSrcIndex; | ||
71 | int iDstIndex; | ||
72 | |||
73 | |||
74 | // get item index of the focused | ||
75 | if(!iCurrentLCD){ | ||
76 | iSrcIndex = cbbxTop->currentItem(); | ||
77 | iDstIndex = cbbxBottom->currentItem(); | ||
78 | }else{ | ||
79 | iSrcIndex = cbbxBottom->currentItem(); | ||
80 | iDstIndex = cbbxTop->currentItem(); | ||
81 | } | ||
82 | |||
83 | if(iSrcIndex == iDstIndex) | ||
84 | dDstValue = dSrcValue; | ||
85 | else{ | ||
86 | if(iSrcIndex){ | ||
87 | // we are NOT in Euro as iDstIndex <> 0 | ||
88 | // Convert to Euro | ||
89 | dDstValue = x2Euro(iSrcIndex, dSrcValue); | ||
90 | dDstValue = Euro2x(iDstIndex, dDstValue); | ||
91 | }else | ||
92 | // We are in Euro | ||
93 | dDstValue = Euro2x(iDstIndex, dSrcValue); | ||
94 | } | ||
95 | |||
96 | |||
97 | if(!iCurrentLCD){ | ||
98 | lcdTop->display(dSrcValue); | ||
99 | lcdBottom->display(dDstValue); | ||
100 | }else{ | ||
101 | lcdBottom->display(dSrcValue); | ||
102 | lcdTop->display(dDstValue); | ||
103 | } | ||
104 | |||
105 | } | ||
106 | |||
107 | /*********************************************************************** | ||
108 | * SLOT: Swap output keypad between LCD displays | ||
109 | **********************************************************************/ | ||
110 | void LCDDisplay::swapLCD(void){ | ||
111 | |||
112 | double dCurrentValue; | ||
113 | |||
114 | // get current value | ||
115 | if(!iCurrentLCD){ | ||
116 | dCurrentValue = lcdTop->value(); | ||
117 | iCurrentLCD = 1; | ||
118 | }else{ | ||
119 | dCurrentValue = lcdBottom->value(); | ||
120 | iCurrentLCD = 0; | ||
121 | } | ||
122 | |||
123 | setValue(dCurrentValue); | ||
124 | } | ||
125 | |||
126 | /*********************************************************************** | ||
127 | * SLOT: Currency change | ||
128 | **********************************************************************/ | ||
129 | void LCDDisplay::cbbxChange(void){ | ||
130 | |||
131 | double dCurrentValue; | ||
132 | |||
133 | printf("combo changes...\n"); | ||
134 | |||
135 | // get current value | ||
136 | if(!iCurrentLCD){ | ||
137 | dCurrentValue = lcdTop->value(); | ||
138 | }else{ | ||
139 | dCurrentValue = lcdBottom->value(); | ||
140 | } | ||
141 | |||
142 | setValue(dCurrentValue); | ||
143 | } | ||
144 | |||
145 | |||
146 | /*********************************************************************** | ||
147 | * Euro2x converts dValue from Euro to the currency which combo box | ||
148 | * index is provided in iIndex. | ||
149 | **********************************************************************/ | ||
150 | double LCDDisplay::Euro2x(int iIndex, double dValue){ | ||
151 | |||
152 | switch (iIndex){ | ||
153 | case 0: // Euro | ||
154 | return(dValue); | ||
155 | break; | ||
156 | |||
157 | case 1: // FF: French Francs | ||
158 | return(dValue*FF); | ||
159 | break; | ||
160 | |||
161 | case 2: // DM: Deutch Mark | ||
162 | return(dValue*DM); | ||
163 | break; | ||
164 | }//switch (iIndex) | ||
165 | }// fct Eur2x | ||
166 | |||
167 | |||
168 | |||
169 | /*********************************************************************** | ||
170 | * x2Euro converts dValue to Euro from the currency which combo box | ||
171 | * index is provided in iIndex. | ||
172 | **********************************************************************/ | ||
173 | double LCDDisplay::x2Euro(int iIndex, double dValue){ | ||
174 | |||
175 | switch (iIndex){ | ||
176 | case 0: // Euro | ||
177 | return(dValue); | ||
178 | break; | ||
179 | |||
180 | case 1: // FF: French Francs | ||
181 | return(dValue/FF); | ||
182 | break; | ||
183 | |||
184 | case 2: // DM: Deutch Mark | ||
185 | return(dValue/DM); | ||
186 | break; | ||
187 | }//switch (iIndex) | ||
188 | }// fct x2Euro | ||