Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

dataTable.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002    application:             : Oxygen
00003 
00004    begin                    : September 2002
00005    copyright                : ( C ) 2002 by Carsten Niehaus
00006    email                    : cniehaus@handhelds.org
00007  **************************************************************************/
00008 
00009 /***************************************************************************
00010  *                                                                         *
00011  * This program is free software; you can redistribute it and/or modify    *
00012  * it under the terms of the GNU General Public License as published by    *
00013  * the Free Software Foundation; either version 2 of the License, or       *
00014  * ( at your option ) any later version.                                   *
00015  *                                                                         *
00016  **************************************************************************/
00017 
00018 #include <qpe/config.h>
00019 
00020 #include "dataTable.h"
00021 #include <qhbox.h>
00022 #include <qlabel.h>
00023 #include <qlayout.h>
00024 #include <qpe/qpeapplication.h>
00025 
00026 
00027 OxydataWidget::OxydataWidget(QWidget *parent, const char *name, const QStringList &list ) : QWidget( parent,name ), names( list )
00028 {
00029     QGridLayout *qgrid = new QGridLayout( this, 2,1 );
00030 
00031     QHBox *hbox = new QHBox( this );
00032     left = new QLabel( hbox );
00033     middle = new QLabel( hbox );
00034     right = new QLabel( hbox );
00035 
00036     right->setAlignment( AlignRight );
00037     middle->setAlignment( AlignHCenter );
00038 
00039     QFont bf;
00040     bf.setBold( true );
00041     bf.setPointSize( bf.pointSize()+2 );
00042     middle->setFont( bf );
00043 
00044     DataTable = new OxydataTable( 9,2, this );
00045     setTable();
00046 
00047     qgrid->addWidget( hbox,0,0 );
00048     qgrid->addWidget( DataTable,1,0 );
00049 }
00050 
00051 void OxydataWidget::setElement( int el )
00052 {
00053         QStringList::ConstIterator it = names.at(el);
00054     Config configobj( QPEApplication::qpeDir() +"share/oxygen/oxygendata", Config::File );
00055 
00056     configobj.setGroup( QString::number( el+1 ));
00057 
00058     left->setText( configobj.readEntry( "Symbol" ) );
00059     middle->setText( *it  );
00060     right->setText( QString::number( el+1 ) );
00061 
00062 
00063     DataTable->setText( 0,1,tr( "%1 u" ).arg( configobj.readEntry( "Weight" ) ) );
00064     DataTable->setText( 1,1,configobj.readEntry( "Block" ) );
00065     DataTable->setText( 2,1,configobj.readEntry( "Group" ) );
00066     DataTable->setText( 3,1,configobj.readEntry( "EN" ) );
00067     DataTable->setText( 4,1,tr( "%1 pm" ).arg( configobj.readEntry( "AR" ) ) ) ;
00068     DataTable->setText( 5,1,tr( "%1 J" ).arg( configobj.readEntry( "IE" ) ) );
00069     DataTable->setText( 6,1,tr( "%1 g/cm^3" ).arg( configobj.readEntry( "Density" ) ) );
00070     DataTable->setText( 7,1,tr( "%1 K" ).arg( configobj.readEntry( "BP" ) ) );
00071     DataTable->setText( 8,1,tr( "%1 K" ).arg( configobj.readEntry( "MP" ) ) );
00072 }
00073 
00074 void OxydataWidget::setTable() const
00075 {
00076     DataTable->setText( 0,0, tr( "Weight" ) );
00077     DataTable->setText( 1,0, tr( "Block" )) ;
00078     DataTable->setText( 2,0, tr( "Group" )) ;
00079     DataTable->setText( 3,0, tr( "Electronegativity" )) ;
00080     DataTable->setText( 4,0, tr( "Atomic radius" )) ;
00081     DataTable->setText( 5,0, tr( "Ionization Energy" )) ;
00082     DataTable->setText( 6,0, tr( "Density" )) ;
00083     DataTable->setText( 7,0, tr( "Boiling point" ) );
00084     DataTable->setText( 8,0, tr( "Melting point" ) );
00085 }
00086 
00087 void OxydataWidget::setLayout()
00088 {
00089 #warning this is not working and I have no idea why!
00090 //    DataTable->setColumnWidth ( 0 , this->width()/2 );
00091 //    DataTable->setColumnWidth ( 1 , this->width()/2 );
00092 
00093 //X     DataTable->setColumnWidth ( 0 , 110 );
00094 //X     DataTable->setColumnWidth ( 1 , 110 );
00095 }
00096 
00097 OxydataTable::OxydataTable(int numRows, int numCols, QWidget *parent,
00098         const char *name) : QTable(numRows, numCols,parent, name)
00099 {
00100     setColumnStretchable( 0, true );
00101     setColumnStretchable( 1, true );
00102 
00103     for (int zeile = 0; zeile < numRows; zeile++)
00104         for ( int spalte = 0; spalte < numCols; spalte++ )
00105         {
00106             OxydataQTI *testus = new OxydataQTI (this, OxydataQTI::Never, "hm" );
00107             setItem(zeile, spalte, (QTableItem*)testus);
00108         }
00109 
00110 
00111     this->setShowGrid( false );
00112     this->setHScrollBarMode(QScrollView::AlwaysOff);
00113     this->horizontalHeader()->hide();
00114     this->verticalHeader()->hide();
00115     this->setTopMargin( 0 );
00116     this->setLeftMargin( 0 );
00117 }
00118 
00119 void OxydataTable::paintCell(  QPainter *p, int row, int col, const QRect &cr, bool selected)
00120 {
00121     if ( cr.width() == 0 || cr.height() == 0 )
00122         return;
00123     selected = FALSE;
00124 
00125     QTableItem *itm = item( row, col );
00126     QColorGroup colgrp = colorGroup();
00127     if ( itm )
00128     {
00129         if ( row%2 )
00130             colgrp.setColor(  QColorGroup::Base, QColor( 180,200,210 ) );
00131         else
00132             colgrp.setColor(  QColorGroup::Base, QColor( 230,235,235 ) );
00133         p->save();
00134         itm->paint( p, colgrp, cr, selected );
00135         p->restore();
00136     }
00137 }
00138 
00139 OxydataQTI::OxydataQTI(QTable * table, EditType et, const QString & text )
00140     : QTableItem ( table, et, text )
00141 {
00142 }
00143 
00144 int OxydataQTI::alignment() const
00145 {
00146     if ( col()%2 )
00147     {
00148         return AlignRight | AlignVCenter;
00149     }else return AlignLeft | AlignVCenter;
00150 };
00151 

Generated on Sat Nov 5 16:17:07 2005 for OPIE by  doxygen 1.4.2