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

psewidget.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002    application:             : Oxygen
00003 
00004    begin                    : September 2002
00005    copyright                : ( C ) 2002, 2003 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 #include <qlayout.h>
00020 #include <qpe/qpeapplication.h>
00021 #include "dataTable.h"
00022 #include "psewidget.h"
00023 
00024 
00025 PSEWidget::PSEWidget(const QStringList &list) : QWidget()
00026 {
00027     this->setCaption( tr( "Periodic System" ) );
00028         
00029         lastElement=1;
00030         names = list;
00031 
00032     QVBoxLayout *vlay = new QVBoxLayout( this );
00033     
00034     QGridLayout *grid = new QGridLayout( 18,10 );
00035     int h=0, v=0;
00036     
00037     Config configobj( QPEApplication::qpeDir() +"share/oxygen/oxygendata", Config::File );
00038     for( int n = 0 ; n < 109 ; n++ )
00039     {
00040         configobj.setGroup( QString::number( n+1 ));
00041         
00042         position( n+1,h,v );
00043         PSEframe.append( new OxyFrame( this , QString::number(n), configobj.readEntry( "Symbol" ) ) );
00044         grid->addWidget( PSEframe.current() , v/40+1 , h/40 );
00045         PSEframe.current()->setMinimumHeight( 11 );
00046         PSEframe.current()->setPalette(  QPalette(  PSEColor( configobj.readEntry( "Block" )  ) ) );
00047         connect( PSEframe.current(), SIGNAL( num(QString) ), this, SLOT( slotShowElement(QString) ));
00048         connect( PSEframe.current(), SIGNAL( num(QString) ), this, SLOT( inverseColor(QString) ));
00049     }
00050     
00051     oxyDW = new OxydataWidget(this, "PSEWidget_oxyDW", names);
00052     oxyDW->setElement( 0 );
00053     oxyDW->setLayout();
00054 
00055     vlay->addLayout( grid );
00056     vlay->addWidget( oxyDW );
00057 }
00058 
00059 QColor PSEWidget::PSEColor( QString block ) const
00060 {
00061     QColor c;
00062     if ( block == "s" ) c.setRgb( 213 , 233 , 231 );
00063     else if ( block == "d" ) c.setRgb( 200,230,160 );
00064     else if ( block == "p" ) c.setRgb( 238,146,138 );
00065     else if ( block == "f" ) c.setRgb( 190 , 190 , 190 );
00066     return  c;
00067 };
00068 
00069 void PSEWidget::inverseColor( QString number)
00070 {
00071     Config configobj( QPEApplication::qpeDir() +"share/oxygen/oxygendata", Config::File );
00072     configobj.setGroup(  number );
00073         QString block = configobj.readEntry( "Block" );
00074     QColor c, d;
00075         c = PSEColor( block );
00076         d = c.dark();
00077         
00078         PSEframe.at( number.toUInt() )->setPalette(  QPalette( d ) );
00079 
00080         configobj.setGroup( QString::number( lastElement+1 ) );
00081         block = configobj.readEntry( "Block" );
00082         c = PSEColor( block );
00083         PSEframe.at( lastElement )->setPalette(  QPalette( c ) );
00084 
00085         lastElement=number.toInt();
00086 }
00087 
00088 void PSEWidget::slotShowElement(QString number)
00089 { 
00090     oxyDW->setElement( number.toInt() );
00091 };
00092 
00093 void PSEWidget::position(int n, int& h, int& v)
00094 {
00095         //Hydrogen
00096         if (n == 1)
00097         {
00098                 h=0; v=0;
00099         }
00100 
00101 
00102         //Helium
00103         if (n == 2)
00104         {
00105                 h=680; v=0;
00106         }
00107 
00108 
00109         //Lithium
00110         if (n == 3)
00111         {
00112                 h=0; v=40;
00113         }
00114 
00115 
00116         //Beryllium
00117         if (n == 4)
00118         {
00119                 h=40; v=40;
00120         }
00121 
00122 
00123         //Boron-->Neon or Aluminum --> Argon
00124         if ((n >= 5 && n <= 10) || (n >= 13 && n <= 18))
00125                 for (int i = 1; i <= (6-(10-n)); i++)
00126                 {
00127                         h=((i*40)+440);
00128                         v = 40;
00129                         if (n >= 13)
00130                         {
00131                                 v=80;
00132                                 h=(h-320);
00133                         }
00134                 }
00135 
00136 
00137         //Sodium
00138         if (n == 11)
00139         {
00140                 h=0; v=80;
00141         }
00142 
00143 
00144         //Magnesium
00145         if (n == 12)
00146         {
00147                 h=40; v=80;
00148         }
00149 
00150 
00151         //Potassium --> Uuo without La and Ac
00152         if ((n >= 19 && n <= 57) || (n >= 72 && n <= 89) || n >= 104)
00153                 for (int i = 1; i <= 18; i++)
00154                 {
00155                         int f = n;
00156                         if (n > 18)
00157                                 f = n-18;
00158                         if (n > 36)
00159                                 f = n-36;
00160                         if (n > 54)
00161                                 f = n-54;
00162                         if (n > 71)
00163                                 f = n-68;
00164                         if (n > 86)
00165                                 f = n-86;
00166                         if (n > 103)
00167                                 f = n-100;
00168 
00169                         h=((f*40)-40);
00170 
00171                         v = 120;
00172                         if (n >= 37)
00173                                 v=160;
00174                         if (n >= 55)
00175                                 v=200;
00176                         if (n >= 87)
00177                                 v=240;
00178                 }
00179 
00180 
00181         //Lanthanum --> Lutetium and Actinum --> Lawrencium
00182         if ((n >= 58 && n <= 71) || (n >= 90 && n <= 103))
00183                 for (int i = 1; i <= 14; i++)
00184                 {
00185                         int f = n;
00186                         if (n > 57)
00187                                 f = n-55;
00188                         if (n > 88)
00189                                 f = n-87;
00190                         h=(f*40);
00191                         v = 290;
00192                         if (n >= 90)
00193                                 v=330;
00194                 }
00195         v += 10;
00196 }

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