/*************************************************************************** kalzium.cpp - description ------------------- begin : Die Dez 4 17:59:34 CET 2001 copyright : (C) 2001 by Carsten Niehaus email : cniehaus@gmx.de ***************************************************************************/ /*************************************************************************** * * * 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 "kalzium.h" #include "eleminfo.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include //horizontal expansion of a button #define SIZE_X 40 //vertical expansion of a button #define SIZE_Y 40 #define KALZIUM_VERSION 0.11 Kalzium::Kalzium(const char *name) : KMainWindow( 0 ,name ) { const QColor s("LightGreen"); const QColor t("CornflowerBlue"); const QColor p("SandyBrown"); const QColor f("LemonChiffon"); setCaption(i18n("Kalzium - v%1").arg(KALZIUM_VERSION)); // GR Beenden == Quit? KAction *quit = new KAction ("Quit", KStdAccel::quit(), kapp, SLOT (closeAllWindows()), this); KPopupMenu *filemenu = new KPopupMenu; KPopupMenu *help = helpMenu( ); quit->plug(filemenu); menuBar()->insertItem(i18n("File"), filemenu); menuBar()->insertItem( i18n("&Help"), help ); // Loop over all elements int h=0; int v=0; QString elementName, rc_path = "/home/grrussel/kalziumrc"; KSimpleConfig config (rc_path); for (int n=0;n<118;n++) { if (config.hasGroup(QString::number(n+1))) { config.setGroup(QString::number(n+1)); elementName=config.readEntry("Symbol", "Unknown"); } else elementName="Unknown"; position(n+1,h,v); //get position button[n] = new ElementKP(elementName,this,elementName.latin1(),n+1,statusBar()); button[n]->setGeometry(h,v+40,SIZE_X,SIZE_Y); button[n]->setFlat(true); button[n]->setAutoDefault(false); switch (block(n+1 )){ case FBLOCK: button[n] ->setBackgroundColor(f); break; case DBLOCK: button[n] ->setBackgroundColor(t); break; case PBLOCK: button[n] ->setBackgroundColor(p); break; case SBLOCK: button[n] ->setBackgroundColor(s); break; default: break; } button[n]->show(); } } /** Return an int indicating the block in which the element is * param int elements atomic number * return int elements group as set in enumeration */ int Kalzium::block(int e) const{ if ( (e >= 58 && e <= 71) || (e >= 90 && e <= 103) ) return FBLOCK; else if ( (e >= 21 && e <= 30) || ( e >= 39 && e <= 48 ) || (e >= 72 && e <= 80) || ( e == 57) || ( e == 89 ) || (e >= 104 && e <= 112 )) return DBLOCK; else if ( ( e == 2 ) || ( e >= 5 && e <= 10 ) || ( e >= 13 && e <= 18) || ( e >= 31 && e <= 36 ) || ( e >= 49 && e <= 54 ) || ( e >= 81 && e <= 86 ) ) return PBLOCK; else if ( e == 1 || e == 3 || e == 4 || e == 11 || e == 12 || e == 19 || e == 20 || e == 37 || e == 38 || e == 55 || e == 56 || e == 87 || e == 88) return SBLOCK; else return OTHER; } Kalzium::~Kalzium() { for (int n=0; n<118; n++) delete button[n]; }