author | cniehaus <cniehaus> | 2002-09-18 13:54:36 (UTC) |
---|---|---|
committer | cniehaus <cniehaus> | 2002-09-18 13:54:36 (UTC) |
commit | 6008e7d286293a87fca4ff43729bdfa66d700989 (patch) (unidiff) | |
tree | bd0b5067e9914f0aca79540511dceea662a11d62 | |
parent | 15ecc4aa71878039ad40ce270fae06282d8e98c2 (diff) | |
download | opie-6008e7d286293a87fca4ff43729bdfa66d700989.zip opie-6008e7d286293a87fca4ff43729bdfa66d700989.tar.gz opie-6008e7d286293a87fca4ff43729bdfa66d700989.tar.bz2 |
This is far better: I use 2 more classes, everything is far more OO
-rw-r--r-- | noncore/apps/oxygen/dataTable.cpp | 77 | ||||
-rw-r--r-- | noncore/apps/oxygen/dataTable.h | 31 | ||||
-rw-r--r-- | noncore/apps/oxygen/datawidgetui.cpp | 76 | ||||
-rw-r--r-- | noncore/apps/oxygen/datawidgetui.h | 5 |
4 files changed, 116 insertions, 73 deletions
diff --git a/noncore/apps/oxygen/dataTable.cpp b/noncore/apps/oxygen/dataTable.cpp index bb786ea..642a8be 100644 --- a/noncore/apps/oxygen/dataTable.cpp +++ b/noncore/apps/oxygen/dataTable.cpp | |||
@@ -7,11 +7,88 @@ | |||
7 | * * | 7 | * * |
8 | **************************************************************************/ | 8 | **************************************************************************/ |
9 | 9 | ||
10 | #include <qpe/config.h> | ||
11 | |||
10 | #include "dataTable.h" | 12 | #include "dataTable.h" |
13 | #include <qwidget.h> | ||
14 | #include <qhbox.h> | ||
15 | #include <qvbox.h> | ||
16 | #include <qlabel.h> | ||
17 | #include <qfont.h> | ||
18 | #include <qlayout.h> | ||
19 | |||
20 | OxydataWidget::OxydataWidget(QWidget *parent) : QWidget(parent) | ||
21 | { | ||
22 | QGridLayout *qgrid = new QGridLayout( this, 2,1 ); | ||
23 | QHBox *hbox = new QHBox( this ); | ||
24 | left = new QLabel( hbox ); | ||
25 | middle = new QLabel( hbox ); | ||
26 | right = new QLabel( hbox ); | ||
27 | |||
28 | DataTable = new OxydataTable( 9,2, this ); | ||
29 | |||
30 | QFont bf; | ||
31 | bf.setBold( true ); | ||
32 | bf.setPointSize( bf.pointSize()+2 ); | ||
33 | middle->setFont( bf ); | ||
34 | |||
35 | setTable(); | ||
36 | |||
37 | qgrid->addWidget( hbox,0,0 ); | ||
38 | qgrid->addWidget( DataTable,1,0 ); | ||
39 | } | ||
40 | |||
41 | void OxydataWidget::setElement( int el ) | ||
42 | { | ||
43 | Config test( "/home/opie/Settings/oxygendata", Config::File ); | ||
44 | test.setGroup( QString::number( el+1 )); | ||
45 | |||
46 | left->setText( test.readEntry( "Symbol" ) ); | ||
47 | middle->setText( test.readEntry( "Name" ) ); | ||
48 | right->setText( QString::number( el+1 ) ); | ||
49 | |||
50 | QString weight = test.readEntry( "Weight" ); | ||
51 | DataTable->setText( 0,1,weight ); | ||
52 | QString block = test.readEntry( "Block" ); | ||
53 | DataTable->setText( 1,1,block ); | ||
54 | QString grp = test.readEntry( "Group" ); | ||
55 | DataTable->setText( 2,1,grp ); | ||
56 | QString en = test.readEntry( "EN" ); | ||
57 | DataTable->setText( 3,1,en ); | ||
58 | QString ar = test.readEntry( "AR" ); | ||
59 | DataTable->setText( 4,1,ar ) ; | ||
60 | QString ion = test.readEntry( "IE" ); | ||
61 | DataTable->setText( 5,1,ion ); | ||
62 | QString dens = test.readEntry( "Density" ); | ||
63 | DataTable->setText( 6,1,dens ); | ||
64 | QString bp = test.readEntry( "BP" ); | ||
65 | DataTable->setText( 7,1,bp ); | ||
66 | QString mp = test.readEntry( "MP" ); | ||
67 | DataTable->setText( 8,1,mp ); | ||
68 | } | ||
69 | |||
70 | void OxydataWidget::setTable() | ||
71 | { | ||
72 | DataTable->setText( 0,0, tr( "Weight:" ) ); | ||
73 | DataTable->setText( 1,0, tr( "Block" )) ; | ||
74 | DataTable->setText( 2,0, tr( "Group" )) ; | ||
75 | DataTable->setText( 3,0, tr( "Electronegativity" )) ; | ||
76 | DataTable->setText( 4,0, tr( "Atomic radius" )) ; | ||
77 | DataTable->setText( 5,0, tr( "Ionizationenergie" )) ; | ||
78 | DataTable->setText( 6,0, tr( "Density" )) ; | ||
79 | DataTable->setText( 7,0, tr( "Boilingpoint" ) ); | ||
80 | DataTable->setText( 8,0, tr( "Meltingpoint" ) ); | ||
81 | } | ||
11 | 82 | ||
12 | OxydataTable::OxydataTable(int numRows, int numCols, QWidget *parent, | 83 | OxydataTable::OxydataTable(int numRows, int numCols, QWidget *parent, |
13 | const char *name) : QTable(numRows, numRows, parent, name) | 84 | const char *name) : QTable(numRows, numRows, parent, name) |
14 | { | 85 | { |
86 | this->setShowGrid( false ); | ||
87 | this->setHScrollBarMode(QScrollView::AlwaysOff); | ||
88 | this->horizontalHeader()->hide(); | ||
89 | this->verticalHeader()->hide(); | ||
90 | this->setTopMargin( 0 ); | ||
91 | this->setLeftMargin( 0 ); | ||
15 | } | 92 | } |
16 | 93 | ||
17 | void OxydataTable::paintCell( QPainter *p, int row, int col, const QRect &cr, bool selected) | 94 | void OxydataTable::paintCell( QPainter *p, int row, int col, const QRect &cr, bool selected) |
diff --git a/noncore/apps/oxygen/dataTable.h b/noncore/apps/oxygen/dataTable.h index 908d241..624e8bd 100644 --- a/noncore/apps/oxygen/dataTable.h +++ b/noncore/apps/oxygen/dataTable.h | |||
@@ -11,8 +11,37 @@ | |||
11 | #ifndef _DATATABLE_H | 11 | #ifndef _DATATABLE_H |
12 | #define _DATATABLE_H | 12 | #define _DATATABLE_H |
13 | 13 | ||
14 | #include <qwidget.h> | ||
14 | #include <qtable.h> | 15 | #include <qtable.h> |
15 | 16 | ||
17 | class QLabel; | ||
18 | class OxydataTable; | ||
19 | |||
20 | class OxydataWidget : public QWidget | ||
21 | { | ||
22 | Q_OBJECT | ||
23 | |||
24 | public: | ||
25 | OxydataWidget(QWidget *parent=0); | ||
26 | |||
27 | QLabel *left, *middle, *right; | ||
28 | |||
29 | private: | ||
30 | OxydataTable *DataTable; | ||
31 | void setTable(); | ||
32 | |||
33 | public slots: | ||
34 | void setElement( int ); | ||
35 | }; | ||
36 | |||
37 | /* | ||
38 | * A OxydataTable is derived from QTable. I recoded the paintCell to have | ||
39 | * different colors in the backgound. Furthermore this widget never has a | ||
40 | * grid, thus I removed that code in paintCell. | ||
41 | * | ||
42 | * Author: Carsten Niehaus <cniehaus@handhelds.org> | ||
43 | */ | ||
44 | |||
16 | class OxydataTable : public QTable | 45 | class OxydataTable : public QTable |
17 | { | 46 | { |
18 | Q_OBJECT | 47 | Q_OBJECT |
@@ -26,7 +55,7 @@ class OxydataTable : public QTable | |||
26 | * This method is reimplemented form QTable. It implements the colourisation | 55 | * This method is reimplemented form QTable. It implements the colourisation |
27 | * of every second row. | 56 | * of every second row. |
28 | */ | 57 | */ |
29 | virtual void paintCell( QPainter *p, int row, int col, const QRect &cr, bool selected ); | 58 | virtual void paintCell( QPainter *p, int row, int col, const QRect &cr, bool selected ); |
30 | }; | 59 | }; |
31 | 60 | ||
32 | #endif | 61 | #endif |
diff --git a/noncore/apps/oxygen/datawidgetui.cpp b/noncore/apps/oxygen/datawidgetui.cpp index 7256777..fa3f40d 100644 --- a/noncore/apps/oxygen/datawidgetui.cpp +++ b/noncore/apps/oxygen/datawidgetui.cpp | |||
@@ -7,9 +7,9 @@ | |||
7 | * * | 7 | * * |
8 | **************************************************************************/ | 8 | **************************************************************************/ |
9 | #include "oxygen.h" | 9 | #include "oxygen.h" |
10 | #include "datawidgetui.h" | ||
10 | 11 | ||
11 | #include <qpe/config.h> | 12 | #include <qpe/config.h> |
12 | #include "datawidgetui.h" | ||
13 | #include <qstring.h> | 13 | #include <qstring.h> |
14 | #include <qcombobox.h> | 14 | #include <qcombobox.h> |
15 | #include <qlayout.h> | 15 | #include <qlayout.h> |
@@ -21,26 +21,15 @@ dataWidgetUI::dataWidgetUI() : QDialog() | |||
21 | { | 21 | { |
22 | this->setCaption("Chemical Data"); | 22 | this->setCaption("Chemical Data"); |
23 | 23 | ||
24 | QVBoxLayout *vbox = new QVBoxLayout( this ); | 24 | QGridLayout *qgrid = new QGridLayout( this, 2,1 ); |
25 | 25 | ||
26 | dataCombo = new QComboBox( this ); | 26 | dataCombo = new QComboBox( this ); |
27 | DataTable = new OxydataTable( 8,2, this ); | 27 | OxydataWidget *oxyDW = new OxydataWidget(this); |
28 | DataTable->setShowGrid( false ); | 28 | oxyDW->setElement( 1 ); |
29 | DataTable->setHScrollBarMode(QScrollView::AlwaysOff); | 29 | qgrid->addWidget( dataCombo, 0,0); |
30 | 30 | qgrid->addWidget( oxyDW , 1,0 ); | |
31 | QHBox *hbox = new QHBox( this ); | ||
32 | left = new QLabel( hbox ); | ||
33 | middle = new QLabel( hbox ); | ||
34 | right = new QLabel( hbox ); | ||
35 | |||
36 | vbox->addWidget( dataCombo ); | ||
37 | vbox->addWidget( hbox ); | ||
38 | vbox->addWidget( DataTable ); | ||
39 | 31 | ||
40 | DataTable->show(); | 32 | connect ( dataCombo, SIGNAL( activated(int) ), oxyDW, SLOT( setElement(int) ) ); |
41 | dataCombo->show(); | ||
42 | |||
43 | connect ( dataCombo, SIGNAL( activated(int) ), this, SLOT( slotShowData(int) ) ); | ||
44 | Config test( "/home/opie/Settings/oxygendata", Config::File ); | 33 | Config test( "/home/opie/Settings/oxygendata", Config::File ); |
45 | 34 | ||
46 | //read in all names of the 118 elements | 35 | //read in all names of the 118 elements |
@@ -50,59 +39,10 @@ dataWidgetUI::dataWidgetUI() : QDialog() | |||
50 | QString foo = test.readEntry( "Name" ); | 39 | QString foo = test.readEntry( "Name" ); |
51 | dataCombo->insertItem( foo ); | 40 | dataCombo->insertItem( foo ); |
52 | } | 41 | } |
53 | |||
54 | createTableLayout(); | ||
55 | slotShowData( 1 ); //this way we do always get data here | ||
56 | |||
57 | } | 42 | } |
58 | 43 | ||
59 | void dataWidgetUI::createTableLayout(){ | ||
60 | DataTable->horizontalHeader()->hide(); | ||
61 | DataTable->verticalHeader()->hide(); | ||
62 | DataTable->setTopMargin( 0 ); | ||
63 | DataTable->setLeftMargin( 0 ); | ||
64 | |||
65 | DataTable->setText( 0,0,"Weight:" ); | ||
66 | DataTable->setText( 1,0,"Block" ); | ||
67 | DataTable->setText( 2,0,"Group" ); | ||
68 | DataTable->setText( 3,0,"Electronegativity" ); | ||
69 | DataTable->setText( 4,0,"Atomic radius" ); | ||
70 | DataTable->setText( 5,0,"Ionizationenergie" ); | ||
71 | DataTable->setText( 6,0,"Density" ); | ||
72 | DataTable->setText( 7,0, tr( "Boilingpoint" ) ); | ||
73 | DataTable->setText( 8,0, tr( "Meltingpoint" ) ); | ||
74 | } | ||
75 | 44 | ||
76 | 45 | ||
77 | void dataWidgetUI::slotShowData(int number){ | 46 | void dataWidgetUI::slotShowData(int number){ |
78 | Config test( "/home/opie/Settings/oxygendata", Config::File ); | 47 | oxyDW->setElement( 6 ); |
79 | test.setGroup( QString::number( number+1 )); | ||
80 | |||
81 | left->setText( test.readEntry( "Symbol" ) ); | ||
82 | middle->setText( test.readEntry( "Name" ) ); | ||
83 | right->setText( QString::number( number+1 ) ); | ||
84 | |||
85 | QFont bf; | ||
86 | bf.setBold( true ); | ||
87 | bf.setPointSize( bf.pointSize()+2 ); | ||
88 | middle->setFont( bf ); | ||
89 | |||
90 | QString weight = test.readEntry( "Weight" ); | ||
91 | DataTable->setText( 0,1,weight ); | ||
92 | QString block = test.readEntry( "Block" ); | ||
93 | DataTable->setText( 1,1,block ); | ||
94 | QString grp = test.readEntry( "Group" ); | ||
95 | DataTable->setText( 2,1,grp ); | ||
96 | QString en = test.readEntry( "EN" ); | ||
97 | DataTable->setText( 3,1,en ); | ||
98 | QString ar = test.readEntry( "AR" ); | ||
99 | DataTable->setText( 4,1,ar ) ; | ||
100 | QString ion = test.readEntry( "IE" ); | ||
101 | DataTable->setText( 5,1,ion ); | ||
102 | QString dens = test.readEntry( "Density" ); | ||
103 | DataTable->setText( 6,1,dens ); | ||
104 | QString bp = test.readEntry( "BP" ); | ||
105 | DataTable->setText( 7,1,bp ); | ||
106 | QString mp = test.readEntry( "MP" ); | ||
107 | DataTable->setText( 7,1,mp ); | ||
108 | } | 48 | } |
diff --git a/noncore/apps/oxygen/datawidgetui.h b/noncore/apps/oxygen/datawidgetui.h index 64599a7..20622db 100644 --- a/noncore/apps/oxygen/datawidgetui.h +++ b/noncore/apps/oxygen/datawidgetui.h | |||
@@ -10,9 +10,7 @@ | |||
10 | #include "dataTable.h" | 10 | #include "dataTable.h" |
11 | #include <qdialog.h> | 11 | #include <qdialog.h> |
12 | 12 | ||
13 | class QTable; | ||
14 | class QComboBox; | 13 | class QComboBox; |
15 | class QLabel; | ||
16 | 14 | ||
17 | class dataWidgetUI : public QDialog | 15 | class dataWidgetUI : public QDialog |
18 | { | 16 | { |
@@ -20,12 +18,11 @@ class dataWidgetUI : public QDialog | |||
20 | 18 | ||
21 | public: | 19 | public: |
22 | dataWidgetUI(); | 20 | dataWidgetUI(); |
21 | OxydataWidget *oxyDW; | ||
23 | 22 | ||
24 | private: | 23 | private: |
25 | void createTableLayout(); | ||
26 | OxydataTable *DataTable; | 24 | OxydataTable *DataTable; |
27 | QComboBox *dataCombo; | 25 | QComboBox *dataCombo; |
28 | QLabel *left, *middle, *right; | ||
29 | 26 | ||
30 | private slots: | 27 | private slots: |
31 | void slotShowData(int); | 28 | void slotShowData(int); |