summaryrefslogtreecommitdiff
authorgroucho <groucho>2003-02-15 11:45:26 (UTC)
committer groucho <groucho>2003-02-15 11:45:26 (UTC)
commitb50692ba650418aa06cbd2662b4ff698c7d3f961 (patch) (unidiff)
tree433cba343b22bfa15e246c302553d976975b08dd
parente8f0c623ff6a8822b84b9cc4ee3c1fb3b3016738 (diff)
downloadopie-b50692ba650418aa06cbd2662b4ff698c7d3f961.zip
opie-b50692ba650418aa06cbd2662b4ff698c7d3f961.tar.gz
opie-b50692ba650418aa06cbd2662b4ff698c7d3f961.tar.bz2
Forgot to add the sources :-}
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--noncore/tools/euroconv/calcdisplay.cpp188
-rw-r--r--noncore/tools/euroconv/calcdisplay.h57
-rw-r--r--noncore/tools/euroconv/calckeypad.cpp191
-rw-r--r--noncore/tools/euroconv/calckeypad.h78
-rw-r--r--noncore/tools/euroconv/config.in4
-rw-r--r--noncore/tools/euroconv/currency.h20
-rw-r--r--noncore/tools/euroconv/euroconv.pro12
-rw-r--r--noncore/tools/euroconv/main.cpp39
-rw-r--r--noncore/tools/euroconv/opie-euroconv.control9
9 files changed, 598 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
diff --git a/noncore/tools/euroconv/calcdisplay.h b/noncore/tools/euroconv/calcdisplay.h
new file mode 100644
index 0000000..17ce8f4
--- a/dev/null
+++ b/noncore/tools/euroconv/calcdisplay.h
@@ -0,0 +1,57 @@
1/****************************************************************************
2 *
3 * File: calcdisplay.h
4 *
5 * Description: Header file for the class LCDDisplay
6 *
7 *
8 * Authors: Eric Santonacci <Eric.Santonacci@talc.fr>
9 *
10 * Requirements: Qt
11 *
12 * $Id$
13 *
14 *
15 ***************************************************************************/
16#ifndef CALCDISPLAY_H
17#define CALCDISPLAY_H
18
19#include <qhbox.h>
20#include <qlcdnumber.h>
21#include <qvgroupbox.h>
22#include <qpushbutton.h>
23#include <qcombobox.h>
24
25class LCDDisplay : public QHBox{
26
27Q_OBJECT
28public:
29 LCDDisplay( QWidget *parent=0, const char *name=0 );
30
31public slots:
32 void setValue(double);
33 void swapLCD(void);
34 void cbbxChange(void);
35
36//signals:
37// void valueChanged( int );
38private:
39 QVGroupBox *grpbxTop;
40 QComboBox *cbbxTop;
41 QLCDNumber *lcdTop;
42
43 QVGroupBox *grpbxBottom;
44 QComboBox *cbbxBottom;
45 QLCDNumber *lcdBottom;
46
47 QPushButton *btnSwap;
48
49 int iCurrentLCD; // 0=top, 1=bottom
50
51 double Euro2x(int iIndex, double dValue);
52 double x2Euro(int iIndex, double dValue);
53
54
55};
56
57#endif // CALCDISPLAY_H
diff --git a/noncore/tools/euroconv/calckeypad.cpp b/noncore/tools/euroconv/calckeypad.cpp
new file mode 100644
index 0000000..4156570
--- a/dev/null
+++ b/noncore/tools/euroconv/calckeypad.cpp
@@ -0,0 +1,191 @@
1/****************************************************************************
2 *
3 * File: calckeypad.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 <qmessagebox.h>
17
18#include "calckeypad.h"
19
20
21KeyPad::KeyPad(LCDDisplay *lcd, QWidget *parent, const char *name )
22 : QGrid(5, parent, name){
23
24
25// save lcd at init
26display = lcd;
27// Init variable
28dCurrent = 0;
29iLenCurrent = 1;
30bIsDec = false;
31dDecCurrent = 0;
32iPreviousOperator = 0;
33dPreviousValue = 0;
34
35// First line
36btnClear = new QPushButton("CE/C", this, "Clear");
37btn7 = new QPushButton("7", this, "7");
38btn8 = new QPushButton("8", this, "8");
39btn9 = new QPushButton("9", this, "9");
40btnPlus = new QPushButton("+", this, "+");
41// 2nd line
42btnPercent = new QPushButton("%", this, "percent");
43btn4 = new QPushButton("4", this, "4");
44btn5 = new QPushButton("5", this, "5");
45btn6 = new QPushButton("6", this, "6");
46btnMinus = new QPushButton("-", this, "-");
47// 3rd line
48btnF1 = new QPushButton("",this, "F1");
49btn1 = new QPushButton("1", this, "1");
50btn2 = new QPushButton("2", this, "2");
51btn3 = new QPushButton("3", this, "3");
52btnMultiply = new QPushButton("X", this, "X");
53// 4th line
54btnAbout = new QPushButton("?", this, "About");
55btn0 = new QPushButton("0", this, "0");
56btnDot = new QPushButton(".", this, "dot");
57btnEqual = new QPushButton("=", this, "equal");
58btnDivide = new QPushButton("/", this, "divide");
59
60// Digit key
61grpbtnDigits = new QButtonGroup(0, "digits");
62grpbtnDigits->insert(btn0, 0);
63grpbtnDigits->insert(btn1, 1);
64grpbtnDigits->insert(btn2, 2);
65grpbtnDigits->insert(btn3, 3);
66grpbtnDigits->insert(btn4, 4);
67grpbtnDigits->insert(btn5, 5);
68grpbtnDigits->insert(btn6, 6);
69grpbtnDigits->insert(btn7, 7);
70grpbtnDigits->insert(btn8, 8);
71grpbtnDigits->insert(btn9, 9);
72
73// Operator key
74grpbtnOperators = new QButtonGroup(0, "operator");
75grpbtnOperators->insert(btnPlus, 1);
76grpbtnOperators->insert(btnMinus,2);
77grpbtnOperators->insert(btnMultiply,3);
78grpbtnOperators->insert(btnDivide,4);
79grpbtnOperators->insert(btnEqual,5);
80
81
82// SIGNALS AND SLOTS
83connect(grpbtnDigits, SIGNAL(clicked(int) ), this, SLOT(enterDigits(int)));
84connect(grpbtnOperators, SIGNAL(clicked(int)), this, SLOT(operatorPressed(int)));
85connect(btnClear, SIGNAL(clicked()), this, SLOT(clearLCD()));
86connect(btnAbout, SIGNAL(clicked()), this, SLOT(aboutDialog()));
87connect(btnDot, SIGNAL(clicked()), this, SLOT(gotoDec()));
88}
89
90
91/***********************************************************************
92 * SLOT: enterDigits calculates the value to display and display it.
93 **********************************************************************/
94void KeyPad::enterDigits(int i){
95
96if(!dCurrent)
97 dCurrent = i;
98else if(!bIsDec){
99 if(iLenCurrent > 9)
100 return;
101 dCurrent *= 10;
102 dCurrent += i;
103 iLenCurrent++;
104}else{
105 dCurrent += i*dDecCurrent;
106 dDecCurrent /= 10;
107}
108
109display->setValue(dCurrent);
110}
111
112/***********************************************************************
113 * SLOT: Operator has been pressed
114 **********************************************************************/
115void KeyPad::operatorPressed(int i){
116
117if(iPreviousOperator){
118 switch(iPreviousOperator){
119 case 1: // Plus +
120 dCurrent += dPreviousValue;
121 break;
122
123 case 2: // Minus -
124 dCurrent = dPreviousValue - dCurrent;
125 break;
126
127 case 3: // Multiply *
128 dCurrent *= dPreviousValue;
129 break;
130
131 case 4: // Divide /
132 dCurrent = dPreviousValue / dCurrent;
133 break;
134
135 }
136 display->setValue(dCurrent);
137}
138if(i == 5){
139 // key '=' pressed
140 dPreviousValue = 0;
141 iPreviousOperator = 0;
142 // We don't want to add digits
143 iLenCurrent = 100;
144}else{
145 dPreviousValue = dCurrent;
146 iPreviousOperator = i;
147 // reset LCD for next digit
148 dCurrent = 0;
149 iLenCurrent = 1;
150 bIsDec = false;
151 dDecCurrent = 0;
152}
153
154}
155/***********************************************************************
156 * SLOT: clearLCD CE/C has been pressed
157 **********************************************************************/
158void KeyPad::clearLCD(void){
159
160dCurrent = 0;
161iLenCurrent = 1;
162bIsDec = false;
163dDecCurrent = 0;
164iPreviousOperator = 0;
165dPreviousValue = 0;
166display->setValue(0);
167}
168
169/***********************************************************************
170 * SLOT: gotoDec Dot has been pressed
171 **********************************************************************/
172void KeyPad::gotoDec(void){
173
174bIsDec = true;
175dDecCurrent = 0.1;
176}
177
178
179
180/***********************************************************************
181 * SLOT: Display About Dialog...
182 **********************************************************************/
183void KeyPad::aboutDialog(void){
184
185QMessageBox::about( this, "About Euroconv",
186 "Euroconv is an Euro converter\n\n"
187 "Copyright 2003 TALC Informatique.\n"
188 "Under GPL license\n\n"
189 "Written by Eric Santonacci for Opie\n"
190 "http://opie.handhelds.org\n" );
191}
diff --git a/noncore/tools/euroconv/calckeypad.h b/noncore/tools/euroconv/calckeypad.h
new file mode 100644
index 0000000..42e7eb3
--- a/dev/null
+++ b/noncore/tools/euroconv/calckeypad.h
@@ -0,0 +1,78 @@
1/****************************************************************************
2 *
3 * File: calckeypad.h
4 *
5 * Description: Header file for the class KeyPad
6 *
7 *
8 * Authors: Eric Santonacci <Eric.Santonacci@talc.fr>
9 *
10 * Requirements: Qt
11 *
12 * $Id$
13 *
14 *
15 ***************************************************************************/
16#ifndef CALCKEYPAD_H
17#define CALCKEYPAD_H
18
19#include <qpushbutton.h>
20#include <qgrid.h>
21#include <qbuttongroup.h>
22
23#include "calcdisplay.h"
24
25class KeyPad : public QGrid {
26
27Q_OBJECT
28public:
29 KeyPad(LCDDisplay *LCD, QWidget *parent=0, const char *name=0 );
30
31public slots:
32 void enterDigits(int);
33 void operatorPressed(int);
34 void clearLCD(void);
35 void aboutDialog(void);
36 void gotoDec(void);
37
38private:
39 LCDDisplay *display;
40 double dCurrent;
41 int iLenCurrent;
42 bool bIsDec;
43 double dDecCurrent;
44 int iPreviousOperator;
45 double dPreviousValue;
46
47 QPushButton *btn0;
48 QPushButton *btn1;
49 QPushButton *btn2;
50 QPushButton *btn3;
51 QPushButton *btn4;
52 QPushButton *btn5;
53 QPushButton *btn6;
54 QPushButton *btn7;
55 QPushButton *btn8;
56 QPushButton *btn9;
57 QButtonGroup *grpbtnDigits;
58
59 QPushButton *btnDot;
60
61 QPushButton *btnClear;
62
63 QPushButton *btnPlus;
64 QPushButton *btnMinus;
65 QPushButton *btnMultiply;
66 QPushButton *btnDivide;
67 QPushButton *btnEqual;
68 QPushButton *btnPercent;
69 QPushButton *btnF1;
70 QPushButton *btnAbout;
71
72 QButtonGroup *grpbtnOperators;
73
74
75
76};
77
78#endif // CALCKEYPAD_H
diff --git a/noncore/tools/euroconv/config.in b/noncore/tools/euroconv/config.in
new file mode 100644
index 0000000..f4f1d78
--- a/dev/null
+++ b/noncore/tools/euroconv/config.in
@@ -0,0 +1,4 @@
1 config EUROCONV
2 boolean "euroconv"
3 default "y"
4 depends ( LIBQPE || LIBQPE-X11 ) && LIBOPIE
diff --git a/noncore/tools/euroconv/currency.h b/noncore/tools/euroconv/currency.h
new file mode 100644
index 0000000..90f5b57
--- a/dev/null
+++ b/noncore/tools/euroconv/currency.h
@@ -0,0 +1,20 @@
1/****************************************************************************
2 *
3 * File: currency.h
4 *
5 * Description: define constant for currency compare Euro
6 *
7 *
8 * Authors: Eric Santonacci <Eric.Santonacci@talc.fr>
9 *
10 *
11 * $Id$
12 *
13 ***************************************************************************/
14
15// 1 Euro equal....
16#define EURO 1 // Euro
17#define FF 6.55957 // French Francs
18#define DM 1.96 // Deutch Mark
19
20static const char* aCurrency[] = { "Euro", "French Frs", "DM", 0 };
diff --git a/noncore/tools/euroconv/euroconv.pro b/noncore/tools/euroconv/euroconv.pro
new file mode 100644
index 0000000..dd2f7af
--- a/dev/null
+++ b/noncore/tools/euroconv/euroconv.pro
@@ -0,0 +1,12 @@
1 TEMPLATE= app
2 CONFIG = qt warn_on release
3 HEADERS = calcdisplay.h \
4 calckeypad.h
5 SOURCES = calcdisplay.cpp \
6 calckeypad.cpp \
7 main.cpp
8INCLUDEPATH += $(OPIEDIR)/include
9DEPENDPATH += $(OPIEDIR)/include
10LIBS += -lqpe -lopie
11 DESTDIR = ${OPIEDIR}/bin
12 INTERFACES=
diff --git a/noncore/tools/euroconv/main.cpp b/noncore/tools/euroconv/main.cpp
new file mode 100644
index 0000000..2d97f4e
--- a/dev/null
+++ b/noncore/tools/euroconv/main.cpp
@@ -0,0 +1,39 @@
1/****************************************************************************
2 *
3 * File: main.cpp
4 *
5 * Description: main file for OPIE Euroconv aapp
6 *
7 *
8 * Authors: Eric Santonacci <Eric.Santonacci@talc.fr>
9 *
10 * Requirements: Qt
11 *
12 * $Id$
13 *
14 ***************************************************************************/
15
16#include <qpe/qpeapplication.h>
17#include <qvbox.h>
18//#include <qapplication.h>
19
20#include "calcdisplay.h"
21#include "calckeypad.h"
22
23
24
25int main( int argc, char **argv ) {
26
27 QPEApplication app( argc, argv );
28
29 QVBox *layout = new QVBox(0, "fond");
30
31 LCDDisplay lcd (layout, "lcd");
32 KeyPad num(&lcd, layout, "keypad");
33 app.setMainWidget(layout);
34 layout->setCaption("Euroconv");
35 layout->showMaximized ();
36 layout->show();
37 return app.exec();
38}
39
diff --git a/noncore/tools/euroconv/opie-euroconv.control b/noncore/tools/euroconv/opie-euroconv.control
new file mode 100644
index 0000000..643637e
--- a/dev/null
+++ b/noncore/tools/euroconv/opie-euroconv.control
@@ -0,0 +1,9 @@
1Files: bin/euroconv pics/euroconv/* apps/Applications/euroconv.desktop
2Priority: optional
3Section: opie/applications
4Maintainer: Eric Santonacci <Eric.Santonacci@talc.fr>
5Architecture: arm
6Version: $QPE_VERSION-$SUB_VERSION
7Depends: opie-base
8Description: Euroconv
9 Converts currencies between different european formats