summaryrefslogtreecommitdiff
path: root/noncore/tools/euroconv/calcdisplay.cpp
Unidiff
Diffstat (limited to 'noncore/tools/euroconv/calcdisplay.cpp') (more/less context) (show whitespace changes)
-rw-r--r--noncore/tools/euroconv/calcdisplay.cpp188
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
23LCDDisplay::LCDDisplay( QWidget *parent, const char *name )
24 : QHBox( parent, name ){
25
26
27// Create display
28QVBox *vbxlayout = new QVBox (this);
29
30grpbxTop = new QVGroupBox(vbxlayout, "grpbxTop");
31cbbxTop = new QComboBox(grpbxTop, "cbbxTop");
32lcdTop = new QLCDNumber(10, grpbxTop, "lcdTop");
33lcdTop->setMode( QLCDNumber::DEC );
34lcdTop->setSmallDecimalPoint(true);
35lcdTop->setSegmentStyle(QLCDNumber::Flat);
36cbbxTop->insertStrList(aCurrency);
37
38grpbxBottom = new QVGroupBox(vbxlayout, "grpbxBottom");
39cbbxBottom = new QComboBox(grpbxBottom, "cbbxBottom");
40lcdBottom = new QLCDNumber(10, grpbxBottom, "lcdBottom");
41lcdBottom->setMode( QLCDNumber::DEC );
42lcdBottom->setSmallDecimalPoint(true);
43lcdBottom->setSegmentStyle(QLCDNumber::Flat);
44cbbxBottom->insertStrList(aCurrency);
45
46// set combo box signals
47connect(cbbxTop, SIGNAL(activated(int)), this, SLOT(cbbxChange()));
48connect(cbbxBottom, SIGNAL(activated(int)), this, SLOT(cbbxChange()));
49
50btnSwap = new QPushButton("S",this, "swap");
51btnSwap->setMaximumSize(20,50);
52btnSwap->setMinimumSize(20,50);
53// set signal
54connect(btnSwap, SIGNAL(clicked()), this, SLOT(swapLCD()));
55
56// set default LCD to top
57iCurrentLCD = 0;
58
59//setValue(123.456);
60
61}
62
63/***********************************************************************
64 * SLOT: Display value in the correct LCD
65 **********************************************************************/
66void LCDDisplay::setValue(double dSrcValue){
67
68double dDstValue=0;
69
70int iSrcIndex;
71int iDstIndex;
72
73
74// get item index of the focused
75if(!iCurrentLCD){
76 iSrcIndex = cbbxTop->currentItem();
77 iDstIndex = cbbxBottom->currentItem();
78}else{
79 iSrcIndex = cbbxBottom->currentItem();
80 iDstIndex = cbbxTop->currentItem();
81}
82
83if(iSrcIndex == iDstIndex)
84 dDstValue = dSrcValue;
85else{
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
97if(!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 **********************************************************************/
110void LCDDisplay::swapLCD(void){
111
112double dCurrentValue;
113
114// get current value
115if(!iCurrentLCD){
116 dCurrentValue = lcdTop->value();
117 iCurrentLCD = 1;
118}else{
119 dCurrentValue = lcdBottom->value();
120 iCurrentLCD = 0;
121}
122
123setValue(dCurrentValue);
124}
125
126/***********************************************************************
127 * SLOT: Currency change
128 **********************************************************************/
129void LCDDisplay::cbbxChange(void){
130
131double dCurrentValue;
132
133printf("combo changes...\n");
134
135// get current value
136if(!iCurrentLCD){
137 dCurrentValue = lcdTop->value();
138}else{
139 dCurrentValue = lcdBottom->value();
140}
141
142setValue(dCurrentValue);
143}
144
145
146/***********************************************************************
147 * Euro2x converts dValue from Euro to the currency which combo box
148 * index is provided in iIndex.
149 **********************************************************************/
150double LCDDisplay::Euro2x(int iIndex, double dValue){
151
152switch (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 **********************************************************************/
173double LCDDisplay::x2Euro(int iIndex, double dValue){
174
175switch (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