summaryrefslogtreecommitdiff
path: root/noncore/apps/oxygen/dataTable.cpp
blob: 798230ab0dcb9e3fb48206936ea5e67eb10ef781 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
/***************************************************************************
   application:             : Oxygen

   begin                    : September 2002
   copyright                : ( C ) 2002 by Carsten Niehaus
   email                    : cniehaus@handhelds.org
 **************************************************************************/

/***************************************************************************
 *                                                                         *
 * This program is free software; you can redistribute it and/or modify    *
 * it under the terms of the GNU General Public License as published by    *
 * the Free Software Foundation; either version 2 of the License, or       *
 * ( at your option ) any later version.                                   *
 *                                                                         *
 **************************************************************************/

#include <qpe/config.h>

#include "dataTable.h"
#include <qhbox.h>
#include <qlabel.h>
#include <qlayout.h>
#include <qpe/qpeapplication.h>


OxydataWidget::OxydataWidget(QWidget *parent, const char *name, const QStringList &list ) : QWidget( parent,name ), names( list )
{
    QGridLayout *qgrid = new QGridLayout( this, 2,1 );

    QHBox *hbox = new QHBox( this );
    left = new QLabel( hbox );
    middle = new QLabel( hbox );
    right = new QLabel( hbox );

    right->setAlignment( AlignRight );
    middle->setAlignment( AlignHCenter );

    QFont bf;
    bf.setBold( true );
    bf.setPointSize( bf.pointSize()+2 );
    middle->setFont( bf );

    DataTable = new OxydataTable( 9,2, this );
    setTable();

    qgrid->addWidget( hbox,0,0 );
    qgrid->addWidget( DataTable,1,0 );
}

void OxydataWidget::setElement( int el )
{
	QStringList::ConstIterator it = names.at(el);
    Config configobj( QPEApplication::qpeDir() +"share/oxygen/oxygendata", Config::File );

    configobj.setGroup( QString::number( el+1 ));

    left->setText( configobj.readEntry( "Symbol" ) );
    middle->setText( *it  );
    right->setText( QString::number( el+1 ) );


    DataTable->setText( 0,1,tr( "%1 u" ).arg( configobj.readEntry( "Weight" ) ) );
    DataTable->setText( 1,1,configobj.readEntry( "Block" ) );
    DataTable->setText( 2,1,configobj.readEntry( "Group" ) );
    DataTable->setText( 3,1,configobj.readEntry( "EN" ) );
    DataTable->setText( 4,1,tr( "%1 pm" ).arg( configobj.readEntry( "AR" ) ) ) ;
    DataTable->setText( 5,1,tr( "%1 J" ).arg( configobj.readEntry( "IE" ) ) );
    DataTable->setText( 6,1,tr( "%1 g/cm^3" ).arg( configobj.readEntry( "Density" ) ) );
    DataTable->setText( 7,1,tr( "%1 K" ).arg( configobj.readEntry( "BP" ) ) );
    DataTable->setText( 8,1,tr( "%1 K" ).arg( configobj.readEntry( "MP" ) ) );
}

void OxydataWidget::setTable() const
{
    DataTable->setText( 0,0, tr( "Weight" ) );
    DataTable->setText( 1,0, tr( "Block" )) ;
    DataTable->setText( 2,0, tr( "Group" )) ;
    DataTable->setText( 3,0, tr( "Electronegativity" )) ;
    DataTable->setText( 4,0, tr( "Atomic radius" )) ;
    DataTable->setText( 5,0, tr( "Ionization Energy" )) ;
    DataTable->setText( 6,0, tr( "Density" )) ;
    DataTable->setText( 7,0, tr( "Boiling point" ) );
    DataTable->setText( 8,0, tr( "Melting point" ) );
}

void OxydataWidget::setLayout()
{
#warning this is not working and I have no idea why!
//    DataTable->setColumnWidth ( 0 , this->width()/2 );
//    DataTable->setColumnWidth ( 1 , this->width()/2 );

//X     DataTable->setColumnWidth ( 0 , 110 );
//X     DataTable->setColumnWidth ( 1 , 110 );
}

OxydataTable::OxydataTable(int numRows, int numCols, QWidget *parent,
        const char *name) : QTable(numRows, numCols,parent, name)
{
    setColumnStretchable( 0, true );
    setColumnStretchable( 1, true );

    for (int zeile = 0; zeile < numRows; zeile++)
        for ( int spalte = 0; spalte < numCols; spalte++ )
        {
            OxydataQTI *testus = new OxydataQTI (this, OxydataQTI::Never, "hm" );
            setItem(zeile, spalte, (QTableItem*)testus);
        }


    this->setShowGrid( false );
    this->setHScrollBarMode(QScrollView::AlwaysOff);
    this->horizontalHeader()->hide();
    this->verticalHeader()->hide();
    this->setTopMargin( 0 );
    this->setLeftMargin( 0 );
}

void OxydataTable::paintCell(  QPainter *p, int row, int col, const QRect &cr, bool selected)
{
    if ( cr.width() == 0 || cr.height() == 0 )
        return;
    selected = FALSE;

    QTableItem *itm = item( row, col );
    QColorGroup colgrp = colorGroup();
    if ( itm )
    {
        if ( row%2 )
            colgrp.setColor(  QColorGroup::Base, QColor( 180,200,210 ) );
        else
            colgrp.setColor(  QColorGroup::Base, QColor( 230,235,235 ) );
        p->save();
        itm->paint( p, colgrp, cr, selected );
        p->restore();
    }
}

OxydataQTI::OxydataQTI(QTable * table, EditType et, const QString & text )
    : QTableItem ( table, et, text )
{
}

int OxydataQTI::alignment() const
{
    if ( col()%2 )
    {
        return AlignRight | AlignVCenter;
    }else return AlignLeft | AlignVCenter;
};