summaryrefslogtreecommitdiff
authorcniehaus <cniehaus>2002-09-15 14:02:04 (UTC)
committer cniehaus <cniehaus>2002-09-15 14:02:04 (UTC)
commitffb701b9a482ca30eda8901506c0c39ad8461e4c (patch) (unidiff)
tree82fa34a6083a48c877f4a7b41c15672832095fbb
parentd01f8da912a2bed9de1943d174ec10dba505bf38 (diff)
downloadopie-ffb701b9a482ca30eda8901506c0c39ad8461e4c.zip
opie-ffb701b9a482ca30eda8901506c0c39ad8461e4c.tar.gz
opie-ffb701b9a482ca30eda8901506c0c39ad8461e4c.tar.bz2
Ok, this is what I have so far. I know it is not really working thus it is
not in the toplevel-Makefile. I am putting as much work in it as possible. Currently I am doing the kmol-port, after that the PSE-stuff.
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/checkbook/TODO4
-rw-r--r--noncore/apps/checkbook/calcdlgui.cpp52
-rw-r--r--noncore/apps/checkbook/calcdlgui.h22
-rw-r--r--noncore/apps/checkbook/kmolcalc.cpp233
-rw-r--r--noncore/apps/checkbook/kmolcalc.h110
-rw-r--r--noncore/apps/checkbook/kmolelements.cpp238
-rw-r--r--noncore/apps/checkbook/kmolelements.h161
-rw-r--r--noncore/apps/checkbook/main.cpp22
-rw-r--r--noncore/apps/checkbook/moc_kmoledit.cpp95
-rw-r--r--noncore/apps/checkbook/opie-oxygen.control9
-rw-r--r--noncore/apps/checkbook/oxygen.cpp52
-rw-r--r--noncore/apps/checkbook/oxygen.h22
-rw-r--r--noncore/apps/checkbook/oxygen.pro18
13 files changed, 1028 insertions, 10 deletions
diff --git a/noncore/apps/checkbook/TODO b/noncore/apps/checkbook/TODO
index adc9665..bc60bf4 100644
--- a/noncore/apps/checkbook/TODO
+++ b/noncore/apps/checkbook/TODO
@@ -1,5 +1 @@
1TODO: TODO:
2 * Date widget
3 * Various bug fixes
4 * Fix "the" crash
5 * Fix graph's legend not showing up \ No newline at end of file
diff --git a/noncore/apps/checkbook/calcdlgui.cpp b/noncore/apps/checkbook/calcdlgui.cpp
new file mode 100644
index 0000000..a86374b
--- a/dev/null
+++ b/noncore/apps/checkbook/calcdlgui.cpp
@@ -0,0 +1,52 @@
1/***************************************************************************
2 * *
3 * This program is free software; you can redistribute it and/or modify *
4 * it under the terms of the GNU General Public License as published by *
5 * the Free Software Foundation; either version 2 of the License, or *
6 * ( at your option ) any later version. *
7 * *
8 * ***********************************************************************/
9#include "oxygen.h"
10
11#include <qmenubar.h>
12#include <qstatusbar.h>
13#include <qpopupmenu.h>
14#include <qlabel.h>
15#include <qapplication.h>
16#include <qpushbutton.h>
17#include <qfile.h>
18#include <qdir.h>
19#include <qvbox.h>
20#include "calcdlg.h"
21
22Oxygen::Oxygen()
23 : QMainWindow()
24{
25 this->setCaption( "Oxygen" );
26 vbox = new QVBox( this );
27 QPushButton *setButton = new QPushButton( "Settings", vbox );
28 connect ( setButton, SIGNAL( clicked() ), this, SLOT( slotSettings() ) );
29 QPushButton *calcButton = new QPushButton( "Calculations", vbox );
30 connect ( calcButton, SIGNAL( clicked() ), this, SLOT( slotCalculations() ) );
31 QPushButton *pseButton = new QPushButton( "PSE", vbox );
32 connect ( pseButton, SIGNAL( clicked() ), this, SLOT( slotPSE() ) );
33
34 setCentralWidget( vbox );
35}
36
37
38void Oxygen::close()
39{
40 QApplication::exit();
41}
42
43//SLOTS
44
45void Oxygen::slotCalculations(){
46 CalcDlgUI *calcDlgUI = new calcDlgUI();
47 calcDlgUI->show();
48};
49
50void Oxygen::slotSettings(){ };
51void Oxygen::slotPSE(){ };
52
diff --git a/noncore/apps/checkbook/calcdlgui.h b/noncore/apps/checkbook/calcdlgui.h
new file mode 100644
index 0000000..1e923ee
--- a/dev/null
+++ b/noncore/apps/checkbook/calcdlgui.h
@@ -0,0 +1,22 @@
1
2#include <qpe/resource.h>
3#include <qmainwindow.h>
4#include <qtoolbar.h>
5#include <qstring.h>
6#include <qpopupmenu.h>
7
8class QVBox;
9
10class Oxygen : public QMainWindow
11{
12 Q_OBJECT
13
14 public:
15 Oxygen();
16 QVBox *vbox;
17 private slots:
18 void slotCalculations();
19 void slotSettings();
20 void slotPSE();
21 void close();
22};
diff --git a/noncore/apps/checkbook/kmolcalc.cpp b/noncore/apps/checkbook/kmolcalc.cpp
new file mode 100644
index 0000000..e5ab736
--- a/dev/null
+++ b/noncore/apps/checkbook/kmolcalc.cpp
@@ -0,0 +1,233 @@
1/*
2 * kmolcalc.cpp
3 *
4 * Copyright (C) 2000 Tomislav Gountchev <tomi@idiom.com>
5 */
6
7/**
8 * KMOLCALC is the calculation engine. It knows about a hashtable of user defined atomic
9 * weights and group definitions ELSTABLE, and the currently processed formula, stored
10 * as a list of elements and their coefficients, ELEMENTS.
11 */
12
13#include "kmolcalc.h"
14#include <qdict.h>
15#include <qdir.h>
16#include <iostream.h>
17
18
19/**
20 * Construct a new calculator object.
21 */
22KMolCalc::KMolCalc() {
23 elements = new ElementList;
24 elstable = NULL;
25 readElstable();
26}
27
28KMolCalc::~KMolCalc() {
29 delete elements;
30}
31
32void KMolCalc::readElstable() {
33 weight = -1; // not calculated yet
34 if (elstable) delete elstable;
35 elstable = new QDict<SubUnit> (197, TRUE);
36 elstable->setAutoDelete(TRUE);
37 QStringList files;// = // KGlobal::dirs()->findAllResources("appdata", "kmolweights");
38// mwfile = locateLocal("data", "kmol")+"/kmolweights";
39 QFile f(mwfile);
40 QString* latest_f = &mwfile;
41 for (uint i=0; i<files.count(); i++) {
42 if (QFileInfo(QFile(files[i])).lastModified() > QFileInfo(QFile(*latest_f)).lastModified()) {
43 latest_f = &files[i];
44 }
45 }
46 QFile lf(*latest_f);
47 if (f.exists()) readMwfile(f);
48 if (!f.exists()) {
49 readMwfile(lf);
50 writeElstable();
51 } else if (QFileInfo(f).lastModified() < QFileInfo(lf).lastModified()) {
52 // announce
53 QMessageBox::information
54 (0, "Warning:", "Found new global Mw file.\nLocal definitions will be updated.", QMessageBox::Ok);
55 readMwfile(lf);
56 writeElstable();
57 }
58
59}
60
61
62/**
63 * Parse a string S and construct the ElementList this->ELEMENTS, representing the
64 * composition of S. Returns 0 if successful, or an error code (currently -1) if
65 * parsing failed.
66 * The elements is S must be valid element or group symbols, as stored in this->ELSTABLE.
67 * See help files for correct formula syntax.
68 */
69QString KMolCalc::readFormula(const QString& s) {
70 weight = -1;
71 if (elements) delete elements;
72 elements = new ElementList;
73 return KMolCalc::readGroup(s, elements);
74}
75
76// read a formula group recursively. Called by readFormula.
77QString KMolCalc::readGroup(const QString& s, ElementList* els) {
78 if (s.isEmpty()) return QString ("Enter a formula."); //ERROR
79 int sl = s.length();
80 int i = 0;
81 QString errors ("OK");
82 bool ok = TRUE;
83 while (i < sl && ((s[i] <= '9' && s[i] >= '0') || s[i] == '.')) i++;
84 double prefix = (i == 0 ? 1 : s.left(i).toDouble(&ok));
85 if (! ok || i == sl || prefix == 0) return QString ("Bad formula."); // ERROR
86 ElementList* elstemp = new ElementList;
87 while (i < sl) {
88 int j = i;
89 if (s[i] == '(') {
90 ElementList* inner = new ElementList;
91 int level = 1; // count levels of nested ( ).
92 while (1) {
93 if (i++ == sl) {
94 delete inner;
95 delete elstemp;
96 return QString ("Bad formula."); //ERROR
97 }
98 if (s[i] == '(') level++;
99 if (s[i] == ')') level--;
100 if (level == 0) break;
101 }
102 errors = KMolCalc::readGroup(s.mid(j+1, i-j-1), inner);
103 j = ++i;
104 while (i < sl && ((s[i] <= '9' && s[i] >= '0') || s[i] == '.')) i++;
105 double suffix = (i == j ? 1 : s.mid(j, i-j).toDouble(&ok));
106 if (! ok || suffix == 0) {
107 delete inner;
108 delete elstemp;
109 return QString ("Bad formula."); // ERROR
110 }
111 inner->addTo(*elstemp, suffix);
112 delete inner;
113 inner = NULL;
114 } else if ((s[i] >= 'A' && s[i] <= 'Z') || (s[i] >= 'a' && s[i] <= 'z')) {
115 while (++i < sl && ((s[i] >= 'a' && s[i] <= 'z') || s[i] == '*' ||
116 s[i] == '\''));
117 QString elname = s.mid(j, i-j);
118 j = i;
119 while (i < sl && ((s[i] <= '9' && s[i] >= '0') || s[i] == '.')) i++;
120 double suffix = (i == j ? 1 : s.mid(j, i-j).toDouble(&ok));
121 if (! ok || suffix == 0) {
122 delete elstemp;
123 return QString ("Bad formula."); // ERROR
124 }
125 SubUnit* group = elstable->find(elname);
126 if (group == 0) {
127 delete elstemp;
128 return QString ("Undefined symbol: ") + elname; //ERROR
129 }
130 group->addTo(*elstemp, suffix);
131 } else if (s[i] == '+') {
132 if (elstemp->isEmpty()) {
133 delete elstemp;
134 return QString ("Bad formula."); //ERROR
135 }
136 elstemp->addTo(*els, prefix);
137 delete elstemp;
138 errors = KMolCalc::readGroup(s.mid(i+1, sl-i-1), els);
139 return errors;
140 } else {
141 delete elstemp;
142 return QString ("Bad formula."); //ERROR
143 }
144 }
145 elstemp->addTo(*els, prefix);
146 delete elstemp;
147 return errors;
148}
149
150/**
151 * Calculate and return the molecular weight of the current chemical formula.
152 */
153double KMolCalc::getWeight() {
154 if (weight == -1) weight = elements->getWeight(elstable);
155 return weight;
156}
157
158/**
159 * Return the elemental composition of the current formula, as a string of tab-separated
160 * element - percentage pairs, separated by newlines.
161 */
162QString KMolCalc::getEA() {
163 if (weight == -1) weight = elements->getWeight(elstable);
164 if (weight == -1) return QString("ERROR: Couldn't get Mw..."); // ERROR
165 return elements->getEA(elstable, weight);
166}
167
168/**
169 * Return the empirical formula of the current compound as a QString.
170 */
171QString KMolCalc::getEmpFormula() {
172 return elements->getEmpFormula();
173}
174
175// Read the element definition file.
176void KMolCalc::readMwfile(QFile& f) {
177 if (! f.open(IO_ReadOnly)) return; //ERROR
178 QTextStream fs (&f);
179 QString line;
180 while (! fs.eof()) {
181 line = fs.readLine();
182 SubUnit* s = SubUnit::makeSubUnit(line);
183 elstable->replace(s->getName(), s);
184 }
185 f.close();
186}
187
188/**
189 * Save the element definitions file.
190 */
191void KMolCalc::writeElstable() {
192 QFile f(mwfile);
193 if (! f.open(IO_WriteOnly)) return; //ERROR
194 QTextStream fs (&f);
195 QString line;
196 QDictIterator<SubUnit> it(*elstable);
197 while (it.current()) {
198 it.current()->writeOut(line);
199 fs << line << endl;
200 ++it;
201 }
202 f.close();
203}
204
205/**
206 * Remove a group or element definition from ELSTABLE.
207 */
208void KMolCalc::undefineGroup (const QString& name) {
209 elstable->remove (name);
210}
211
212/**
213 * Add a new element name - atomic weight record to the ELSTABLE hashtable. Assumes
214 * NAME has valid syntax.
215
216 */
217void KMolCalc::defineElement (const QString& name, double weight) {
218 Element* el = new Element(name, weight);
219 elstable->replace(name, el);
220}
221
222/**
223 * Add a new group definition to the ELSTABLE. Returns 0 if OK, -1 if parsing FORMULA
224 * fails. Assumes the syntax of grpname is correct.
225 */
226QString KMolCalc::defineGroup (const QString& grpname, const QString& formula) {
227 ElementList* els = new ElementList(grpname);
228 QString error = readGroup(formula, els);
229 if (error != "OK") return error;
230 if (els->contains(grpname)) return QString("Can't define a group recursively!\n");
231 elstable->replace(grpname, els);
232 return QString("OK");
233}
diff --git a/noncore/apps/checkbook/kmolcalc.h b/noncore/apps/checkbook/kmolcalc.h
new file mode 100644
index 0000000..c3e02f3
--- a/dev/null
+++ b/noncore/apps/checkbook/kmolcalc.h
@@ -0,0 +1,110 @@
1/*
2 * kmolcalc.h
3 *
4 * Copyright (C) 2000 Tomislav Gountchev <tomi@idiom.com>
5 */
6
7
8#ifndef KMOLCALC_H
9#define KMOLCALC_H
10
11#ifdef HAVE_CONFIG_H
12#include <config.h>
13#endif
14
15
16#include "kmolelements.h"
17#include <qdict.h>
18#include <qlist.h>
19#include <qstring.h>
20#include <qfile.h>
21#include <qfileinfo.h>
22#include <qmessagebox.h>
23#include <qtextstream.h>
24
25
26/**
27 * KMOLCALC is the calculation engine. It knows about a hashtable of user defined atomic
28 * weights and group definitions ELSTABLE, and the currently processed formula, stored
29 * as a list of elements and their coefficients, ELEMENTS.
30 */
31class KMolCalc {
32
33public:
34
35 KMolCalc();
36 ~KMolCalc();
37
38 /**
39 * Parse a string S and construct the ElementList ELEMENTS, representing the composition
40 * of S. Returns "OK" if successful, or an error message if parsing failed.
41 * The elements is S must be valid element or group symbols, as stored in ELSTABLE.
42 * See help files for correct formula syntax.
43 */
44 QString readFormula(const QString& s);
45
46 /**
47 * Calculate and return the molecular weight of the current chemical formula.
48 */
49 double getWeight();
50
51 /**
52 * Return the elemental composition of the current formula, as a string of tab-separated
53 * element - percentage pairs, separated by newlines.
54 */
55 QString getEA();
56
57
58 /**
59 * Return the empirical formula of the current compound as a QString.
60 */
61 QString getEmpFormula();
62
63 /**
64 * Add a new element name - atomic weight record to the ELSTABLE hashtable.
65 * Assumes NAME has valid syntax.
66 */
67 void defineElement(const QString& name, double weight);
68
69 /**
70 * Add a new group definition to the ELSTABLE. Returns "OK" if OK, error message
71 * if parsing FORMULA fails. Assumes the syntax of NAME is correct.
72 */
73 QString defineGroup(const QString& name, const QString& formula);
74
75 /**
76 * Remove a group or element definition from ELSTABLE.
77 */
78 void undefineGroup(const QString& name);
79
80 /**
81 * Save the element definitions file.
82 */
83 void writeElstable();
84
85 /**
86 * Read the element definitions file and construct ELSTABLE.
87 */
88 void readElstable();
89
90 /**
91 * The element dictionary.
92 */
93 QDict<SubUnit>* elstable;
94
95 QString mwfile;
96
97 private:
98 double weight;
99
100 QString readGroup(const QString& s, ElementList* els);
101 void readMwfile(QFile& f);
102 ElementList* elements;
103};
104
105#endif
106
107
108
109
110
diff --git a/noncore/apps/checkbook/kmolelements.cpp b/noncore/apps/checkbook/kmolelements.cpp
new file mode 100644
index 0000000..ce8f9c1
--- a/dev/null
+++ b/noncore/apps/checkbook/kmolelements.cpp
@@ -0,0 +1,238 @@
1/*
2 * kmolelements.cpp
3 *
4 * Copyright (C) 2000 Tomislav Gountchev <tomi@idiom.com>
5 */
6
7// classes that store and manipulate chemical formulas represented as
8// lists of elements
9
10#include <stdio.h>
11#include "kmolelements.h"
12
13/**
14 * A generic chemical entity. Can be an element or a group.
15 */
16SubUnit::SubUnit () {}
17
18SubUnit::~SubUnit () {}
19
20/**
21 * Construct a subunit and return a pointer to it. The syntax of LINE is
22 * the one used in the element definition file.
23 */
24SubUnit* SubUnit::makeSubUnit(QString line) {
25 QString name, grpname, weight, coef;
26 QTextStream str (line, IO_ReadOnly);
27 str >> name;
28 if (name != "-group") { // not a group - must be represented as Element
29 str >> weight >> ws;
30 return new Element(name, weight.toDouble());
31 }
32 else {
33 str >> grpname;
34 ElementList* els = new ElementList(grpname); // group - make an ElementList
35 while (!str.eof()) {
36 str >> name >> ws;
37 str >> coef >> ws;
38 els->addElement(name, coef.toDouble());
39 }
40 return els;
41 }
42}
43
44QString SubUnit::getName() const {
45 return QString("None");
46}
47
48/**
49 * Get the molecular weight of THIS, based on the data from ELSTABLE.
50 */
51double SubUnit::getWeight(QDict<SubUnit>* elstable) const {
52 return -1;
53}
54
55/**
56 * A group of elements.
57 */
58ElementList::ElementList () {
59 elements = new QList<ElementCoef>;
60}
61
62ElementList::~ElementList () {
63 delete elements;
64}
65
66
67/**
68 * A group of elements.
69 */
70ElementList::ElementList (QString name) {
71 this->name = name;
72 elements = new QList<ElementCoef>;
73}
74
75/**
76 * Write THIS to LINE, in a format suitable for the element definition file.
77 */
78void ElementList::writeOut(QString& line) {
79 QString coef;
80 line = "-group " + name;
81 ElementCoef* current = elements->first();
82 while (current != 0) {
83 line += " " + current->name + " " + coef.setNum(current->coef, 'g', 10);
84 // precision set to 10 digits
85 current = elements->next();
86 }
87}
88
89/**
90 * Get the molecular weight of THIS, based on the data from ELSTABLE.
91 */
92double ElementList::getWeight(QDict<SubUnit>* elstable) const {
93 double weight = 0;
94 ElementCoef* current = elements->first();
95 while (current != 0) {
96 SubUnit* e = elstable->find(current->name);
97 if (e != 0) {
98 weight += (current->coef) * (e->getWeight(elstable));
99 } else return -1; //ERROR
100 current = elements->next();
101 }
102 return weight;
103}
104
105/**
106 * Return a string representing the elemental composition of THIS, as
107 * a tab-separated element - percentage pairs, separated by newlines.
108 */
109QString ElementList::getEA(QDict<SubUnit>* elstable, double mw) const {
110 if (mw == 0) mw = getWeight(elstable);
111 QString ea;
112 QString temp;
113 ElementCoef* current = elements->first();
114 while (current != 0) {
115 SubUnit* e = elstable->find(current->name);
116 if (e != 0) {
117 double current_percent = 100 * (current->coef) *
118 (e->getWeight(elstable))
119 / mw;
120 ea += current->name + "\t" +
121 temp.setNum(current_percent) + "\n";
122 } else return QString("ERROR!\n"); //ERROR
123 current = elements->next();
124 }
125 return ea;
126}
127
128/**
129 * Return a string representing THIS as an empirical chemical formula.
130 */
131QString ElementList::getEmpFormula() const {
132 QString ef;
133 QString temp;
134 ElementCoef* current = elements->first();
135 while (current != 0) {
136 ef += current->name + temp.setNum(current->coef);
137 current = elements->next();
138 }
139 return ef;
140}
141
142/**
143 * Multiply THIS (i.e. the coefficient of each element) by coef.
144 */
145void ElementList::multiplyBy(double coef) {
146 ElementCoef* current = elements->first();
147 while (current != 0) {
148 (current->coef) *= coef;
149 current = elements->next();
150 }
151}
152
153/**
154 * Add THIS to ELS. THIS is not modified; ELS is.
155 */
156void ElementList::addTo(ElementList& els, double coef) {
157 ElementCoef* current = elements->first();
158 while (current != 0) {
159 els.addElement(current->name, (current->coef) * coef);
160 current = elements->next();
161 }
162}
163
164/**
165 * Add an element to THIS, with a coefficient COEF. If THIS already contains
166 * an element with the same name, adjust its coefficient only; if not, create
167 * a new ElementCoef pair and add to THIS.
168 */
169void ElementList::addElement(const QString& name, double coef) {
170 ElementCoef* current = elements->first();
171 while (current != 0) {
172 if (current->name == name) {
173 current->coef += coef;
174 return;
175 }
176 current = elements->next();
177 }
178 elements->append(new ElementCoef(name, coef));
179}
180
181/**
182 * True iff THIS contains element named NAME.
183 */
184bool ElementList::contains(const QString& name) {
185 ElementCoef* current = elements->first();
186 while (current != 0) {
187 if (current->name == name)
188 return true;
189 current = elements->next();
190 }
191 return false;
192}
193
194bool ElementList::isEmpty() {
195 return elements->isEmpty();
196}
197
198QString ElementList::getName() const {
199 return name;
200}
201
202/**
203 * A chemical element.
204 */
205Element::Element(const QString& n, double w)
206 : weight(w), name(n) { }
207
208
209Element::~Element() {
210}
211
212
213/**
214 * Write THIS to LINE, in a format suitable for the element definition file.
215 */
216void Element::writeOut(QString& line) {
217 line.setNum(weight);
218 line = name + " " + line;
219}
220
221double Element::getWeight(QDict<SubUnit>* elstable) const {
222 return weight;
223}
224
225void Element::addTo(ElementList& els, double coef) {
226 els.addElement(name, coef);
227}
228
229QString Element::getName() const {
230 return name;
231}
232
233/**
234 * An element - coefficient pair. Used to represent elements within an
235 * element list.
236 */
237ElementCoef::ElementCoef(const QString& n, double c) : name(n), coef(c) {}
238
diff --git a/noncore/apps/checkbook/kmolelements.h b/noncore/apps/checkbook/kmolelements.h
new file mode 100644
index 0000000..06d1469
--- a/dev/null
+++ b/noncore/apps/checkbook/kmolelements.h
@@ -0,0 +1,161 @@
1/*
2 * kmolelements.h
3 *
4 * Copyright (C) 2000 Tomislav Gountchev <tomi@idiom.com>
5 */
6
7// classes that store and manipulate chemical formulas represented as
8// lists of elements
9
10#ifndef KMOLELEMENTS_H
11#define KMOLELEMENTS_H
12
13
14#ifdef HAVE_CONFIG_H
15#include <config.h>
16#endif
17
18
19#include <qlist.h>
20#include <qdict.h>
21#include <qstring.h>
22#include <qtextstream.h>
23
24class ElementCoef;
25class ElementList;
26
27/**
28 * A generic chemical entity. Can be an element or a group.
29 */
30class SubUnit {
31 public:
32
33 SubUnit();
34
35 virtual ~SubUnit();
36
37 /**
38 * Construct a subunit and return a pointer to it. The syntax of LINE is
39 * the one used in the element definition file.
40 */
41 static SubUnit* makeSubUnit(QString line);
42
43 /**
44 * Get the molecular weight of THIS, based on the data from ELSTABLE.
45 */
46 virtual double getWeight(QDict<SubUnit>* elstable) const;
47
48 /**
49 * Add THIS to ELS.
50 */
51 virtual void addTo(ElementList& els, double coef) = 0;
52
53 virtual QString getName() const;
54
55 /**
56 * Write THIS to LINE, in the format used in the definition file.
57 */
58 virtual void writeOut(QString& line) = 0;
59};
60
61
62/**
63 * A group of elements.
64 */
65class ElementList : public SubUnit {
66 public:
67 ElementList ();
68 ElementList (QString name);
69 virtual ~ElementList();
70 double getWeight(QDict<SubUnit>* elstable) const;
71
72 /**
73 * Return a string representing the elemental composition of THIS, as
74 * a tab-separated element - percentage pairs, separated by newlines.
75 */
76 QString getEA(QDict<SubUnit>* elstable, double mw = 0) const;
77
78 /**
79 * Return a string representing THIS as an empirical chemical formula.
80 */
81 QString getEmpFormula() const;
82
83 /**
84 * Multiply THIS (i.e. the coefficient of each element) by coef.
85 */
86 void multiplyBy(double coef);
87
88 /**
89 * Add THIS to ELS. THIS is not modified; ELS is.
90 */
91 void addTo(ElementList& els, double coef);
92
93 /**
94 * Add an element to THIS, with a coefficient COEF.
95 */
96 void addElement(const QString& name, double coef);
97
98 /**
99 * True iff THIS contains element named NAME.
100 */
101 bool contains(const QString& name);
102
103
104 bool isEmpty();
105
106 /**
107 * The name of THIS, as a chemical group.
108 */
109 QString getName() const;
110
111 /**
112 * Write THIS to LINE, in a format suitable for the element definition file.
113 */
114 void writeOut(QString& line);
115
116 private:
117 QString name;
118 QList<ElementCoef>* elements;
119};
120
121/**
122 * A chemical element.
123 */
124class Element : public SubUnit {
125 public:
126 Element(const QString& name, double weight);
127 virtual ~Element();
128 double getWeight(QDict<SubUnit>* elstable) const;
129
130 /**
131 * Add THIS to ELS, with a coefficient COEF.
132 */
133 void addTo(ElementList& els, double coef);
134
135 QString getName() const;
136
137 void writeOut(QString& line);
138
139 private:
140 double weight;
141 QString name;
142};
143
144
145/**
146 * An element - coefficient pair. Used to represent elements within an
147 * element list.
148 */
149class ElementCoef {
150 friend class ElementList;
151 public:
152 ElementCoef(const QString& name, double coef = 1.0);
153 private:
154 QString name;
155 double coef;
156};
157
158
159#endif
160
161
diff --git a/noncore/apps/checkbook/main.cpp b/noncore/apps/checkbook/main.cpp
index 68f00e6..328b61f 100644
--- a/noncore/apps/checkbook/main.cpp
+++ b/noncore/apps/checkbook/main.cpp
@@ -1,3 +1,13 @@
1/***************************************************************************
2 * *
3 * This program is free software; you can redistribute it and/or modify *
4 * it under the terms of the GNU General Public License as published by *
5 * the Free Software Foundation; either version 2 of the License, or *
6 * ( at your option ) any later version. *
7 * *
8 * ***********************************************************************/
9
10
1#include <qpe/qpeapplication.h> 11#include <qpe/qpeapplication.h>
2#include "qcheckbook.h" 12#include "oxygen.h"
3 13
@@ -5,7 +15,7 @@ int main(int argc, char **argv)
5{ 15{
6 QPEApplication app(argc, argv); 16 QPEApplication app(argc, argv);
7 QCheckBook *qcb = new QCheckBook(); 17 Oxygen *oxi = new Oxygen();
8 app.setMainWidget(qcb); 18 app.setMainWidget(oxi);
9 qcb->showMaximized(); 19 oxi->showMaximized();
10 return app.exec(); 20 return app.exec();
11} 21}
diff --git a/noncore/apps/checkbook/moc_kmoledit.cpp b/noncore/apps/checkbook/moc_kmoledit.cpp
new file mode 100644
index 0000000..a94e93b
--- a/dev/null
+++ b/noncore/apps/checkbook/moc_kmoledit.cpp
@@ -0,0 +1,95 @@
1/****************************************************************************
2** KMolEdit meta object code from reading C++ file 'kmoledit.h'
3**
4** Created: Sun Sep 15 15:21:49 2002
5** by: The Qt MOC ($Id$)
6**
7** WARNING! All changes made in this file will be lost!
8*****************************************************************************/
9
10#if !defined(Q_MOC_OUTPUT_REVISION)
11#define Q_MOC_OUTPUT_REVISION 9
12#elif Q_MOC_OUTPUT_REVISION != 9
13#error "Moc format conflict - please regenerate all moc files"
14#endif
15
16#include "kmoledit.h"
17#include <qmetaobject.h>
18#include <qapplication.h>
19
20
21
22const char *KMolEdit::className() const
23{
24 return "KMolEdit";
25}
26
27QMetaObject *KMolEdit::metaObj = 0;
28
29void KMolEdit::initMetaObject()
30{
31 if ( metaObj )
32 return;
33 if ( qstrcmp(QDialog::className(), "QDialog") != 0 )
34 badSuperclassWarning("KMolEdit","QDialog");
35 (void) staticMetaObject();
36}
37
38#ifndef QT_NO_TRANSLATION
39
40QString KMolEdit::tr(const char* s)
41{
42 return qApp->translate( "KMolEdit", s, 0 );
43}
44
45QString KMolEdit::tr(const char* s, const char * c)
46{
47 return qApp->translate( "KMolEdit", s, c );
48}
49
50#endif // QT_NO_TRANSLATION
51
52QMetaObject* KMolEdit::staticMetaObject()
53{
54 if ( metaObj )
55 return metaObj;
56 (void) QDialog::staticMetaObject();
57#ifndef QT_NO_PROPERTIES
58#endif // QT_NO_PROPERTIES
59 typedef bool (KMolEdit::*m1_t0)();
60 typedef bool (QObject::*om1_t0)();
61 typedef void (KMolEdit::*m1_t1)();
62 typedef void (QObject::*om1_t1)();
63 typedef void (KMolEdit::*m1_t2)();
64 typedef void (QObject::*om1_t2)();
65 m1_t0 v1_0 = &KMolEdit::edit;
66 om1_t0 ov1_0 = (om1_t0)v1_0;
67 m1_t1 v1_1 = &KMolEdit::save;
68 om1_t1 ov1_1 = (om1_t1)v1_1;
69 m1_t2 v1_2 = &KMolEdit::undo;
70 om1_t2 ov1_2 = (om1_t2)v1_2;
71 QMetaData *slot_tbl = QMetaObject::new_metadata(3);
72 QMetaData::Access *slot_tbl_access = QMetaObject::new_metaaccess(3);
73 slot_tbl[0].name = "edit()";
74 slot_tbl[0].ptr = (QMember)ov1_0;
75 slot_tbl_access[0] = QMetaData::Private;
76 slot_tbl[1].name = "save()";
77 slot_tbl[1].ptr = (QMember)ov1_1;
78 slot_tbl_access[1] = QMetaData::Private;
79 slot_tbl[2].name = "undo()";
80 slot_tbl[2].ptr = (QMember)ov1_2;
81 slot_tbl_access[2] = QMetaData::Private;
82 metaObj = QMetaObject::new_metaobject(
83 "KMolEdit", "QDialog",
84 slot_tbl, 3,
85 0, 0,
86#ifndef QT_NO_PROPERTIES
87 0, 0,
88 0, 0,
89#endif // QT_NO_PROPERTIES
90 0, 0 );
91 metaObj->set_slot_access( slot_tbl_access );
92#ifndef QT_NO_PROPERTIES
93#endif // QT_NO_PROPERTIES
94 return metaObj;
95}
diff --git a/noncore/apps/checkbook/opie-oxygen.control b/noncore/apps/checkbook/opie-oxygen.control
new file mode 100644
index 0000000..4f84158
--- a/dev/null
+++ b/noncore/apps/checkbook/opie-oxygen.control
@@ -0,0 +1,9 @@
1Files: bin/oxygen apps/Applications/oxygencheckbook.desktop pics/oxygen/oxygen.png
2Priority: optional
3Section: applications
4Maintainer: Carsten Niehaus <cniehaus@handhelds.org>
5Architecture: arm
6Version: $QPE_VERSION-$SUB_VERSION
7Depends: opie-base ($QPE_VERSION)
8Description: Periodic System of the Elements
9 The chemistry application for the Opie-environment
diff --git a/noncore/apps/checkbook/oxygen.cpp b/noncore/apps/checkbook/oxygen.cpp
new file mode 100644
index 0000000..a86374b
--- a/dev/null
+++ b/noncore/apps/checkbook/oxygen.cpp
@@ -0,0 +1,52 @@
1/***************************************************************************
2 * *
3 * This program is free software; you can redistribute it and/or modify *
4 * it under the terms of the GNU General Public License as published by *
5 * the Free Software Foundation; either version 2 of the License, or *
6 * ( at your option ) any later version. *
7 * *
8 * ***********************************************************************/
9#include "oxygen.h"
10
11#include <qmenubar.h>
12#include <qstatusbar.h>
13#include <qpopupmenu.h>
14#include <qlabel.h>
15#include <qapplication.h>
16#include <qpushbutton.h>
17#include <qfile.h>
18#include <qdir.h>
19#include <qvbox.h>
20#include "calcdlg.h"
21
22Oxygen::Oxygen()
23 : QMainWindow()
24{
25 this->setCaption( "Oxygen" );
26 vbox = new QVBox( this );
27 QPushButton *setButton = new QPushButton( "Settings", vbox );
28 connect ( setButton, SIGNAL( clicked() ), this, SLOT( slotSettings() ) );
29 QPushButton *calcButton = new QPushButton( "Calculations", vbox );
30 connect ( calcButton, SIGNAL( clicked() ), this, SLOT( slotCalculations() ) );
31 QPushButton *pseButton = new QPushButton( "PSE", vbox );
32 connect ( pseButton, SIGNAL( clicked() ), this, SLOT( slotPSE() ) );
33
34 setCentralWidget( vbox );
35}
36
37
38void Oxygen::close()
39{
40 QApplication::exit();
41}
42
43//SLOTS
44
45void Oxygen::slotCalculations(){
46 CalcDlgUI *calcDlgUI = new calcDlgUI();
47 calcDlgUI->show();
48};
49
50void Oxygen::slotSettings(){ };
51void Oxygen::slotPSE(){ };
52
diff --git a/noncore/apps/checkbook/oxygen.h b/noncore/apps/checkbook/oxygen.h
new file mode 100644
index 0000000..1e923ee
--- a/dev/null
+++ b/noncore/apps/checkbook/oxygen.h
@@ -0,0 +1,22 @@
1
2#include <qpe/resource.h>
3#include <qmainwindow.h>
4#include <qtoolbar.h>
5#include <qstring.h>
6#include <qpopupmenu.h>
7
8class QVBox;
9
10class Oxygen : public QMainWindow
11{
12 Q_OBJECT
13
14 public:
15 Oxygen();
16 QVBox *vbox;
17 private slots:
18 void slotCalculations();
19 void slotSettings();
20 void slotPSE();
21 void close();
22};
diff --git a/noncore/apps/checkbook/oxygen.pro b/noncore/apps/checkbook/oxygen.pro
new file mode 100644
index 0000000..f8e0197
--- a/dev/null
+++ b/noncore/apps/checkbook/oxygen.pro
@@ -0,0 +1,18 @@
1 TEMPLATE= app
2 CONFIG = qt warn_on release
3 HEADERS = oxygen.h \
4 kmolcalc.h \
5 kmolelements.h
6
7 SOURCES = main.cpp \
8 oxygen.cpp \
9 kmolcalc.cpp \
10 kmolelements.cpp
11INCLUDEPATH += $(OPIEDIR)/include
12DEPENDPATH += $(OPIEDIR)/include
13 LIBS += -lqpe
14 INTERFACES= calcdlg.ui
15 TARGET = oxygen
16 DESTDIR = $(OPIEDIR)/bin
17
18TRANSLATIONS = ../../../i18n/de/oxygen.ts