• Skip to content
  • Skip to link menu
KDE 4.0 API Reference
  • KDE API Reference
  • kdeedu
  • Sitemap
  • Contact Us
 

kalzium

eqchemview.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2004, 2005, 2006 by Thomas Nagy <tnagy2^8@yahoo.fr>
00003  *   Copyright (C) 2006 by Carsten Niehaus <cniehaus@kde.org>
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU General Public License as published by  *
00007  *   the Free Software Foundation; either version 2 of the License, or     *
00008  *   (at your option) any later version.                                   *
00009  *                                                                         *
00010  *   This program is distributed in the hope that it will be useful,       *
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00013  *   GNU General Public License for more details.                          *
00014  *                                                                         *
00015  *   You should have received a copy of the GNU General Public License     *
00016  *   along with this program; if not, write to the                         *
00017  *   Free Software Foundation, Inc.,                                       *
00018  *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.             *
00019  ***************************************************************************/
00020 
00021 #include "eqchemview.h"
00022 
00023 #include <QClipboard>
00024 #include <QLabel>
00025 #include <KTextBrowser>
00026 
00027 #include <kdebug.h>
00028 
00029 #include "ui_equationview.h"
00030 
00031 #include <stdlib.h>
00032 
00033 #include <config-kalzium.h>
00034 
00035 #ifdef HAVE_FACILE
00036 extern "C" {
00037     char* solve_equation(const char *);
00038 }
00039 #else
00040 char* solve_equation(const char *) {
00041     return NULL; 
00042 }
00043 #endif
00044 
00045 void EQChemDialog::compute()
00046 {
00047     QString equation( ui.lineEdit->text() );
00048     equation.replace("+", "+");
00049     equation.replace("->", " -> ");
00050     equation.append(" ");
00051     equation.prepend(" ");
00052     
00053     char * result = solve_equation( equation.toLatin1() );
00054 
00055     QString answer = QString(result);
00056 
00057     kDebug() << "Answer: " << answer;
00058 
00059 
00060 //    ui.question_label->setText(equation);
00061     ui.answer_label->setText(answer);
00062 
00063     // mem leak ?
00064     free(result);
00065 }
00066 
00067 EQChemDialog::EQChemDialog( QWidget *parent )
00068   : KDialog( parent )
00069 {
00070     setCaption( i18n( "Solve Chemical Equations Viewer" ) );
00071     setButtons( Help | User1 | Close );
00072     setDefaultButton( None );
00073 
00074     m_helpWindow = NULL;
00075 
00076     ui.setupUi( mainWidget() );
00077     setButtonGuiItem( User1, KGuiItem( i18n( "Copy" ), "edit-copy", i18n( "Copy answer to clipboard" ) ) );
00078     
00079     connect( ui.calculateButton , SIGNAL( clicked() ), 
00080             this, SLOT( compute() ) );
00081     connect( this , SIGNAL( user1Clicked() ), 
00082             this, SLOT( slotUser1() ) );
00083     connect( this , SIGNAL( helpClicked() ),
00084             this, SLOT( slotHelp() ) );
00085 }
00086 
00087 void EQChemDialog::copyAnswer()
00088 {
00089     kDebug() << "EQChemDialog::copyAnswer()";
00090     QClipboard *clipboard = QApplication::clipboard(); clipboard->setText( ui.answer_label->text(), QClipboard::Clipboard);
00091 }
00092 
00093 void EQChemDialog::slotUser1()
00094 {
00095    copyAnswer(); 
00096 }
00097 
00098 void EQChemDialog::slotHelp()
00099 {
00100     if( m_helpWindow == NULL )
00101     {
00102         m_helpWindow = new KDialog( this );
00103         m_helpWindow->setMinimumSize( 500, 300 );
00104         m_helpWindow->showButton( KDialog::Cancel, false );
00105         KTextBrowser *helpText = new KTextBrowser;
00106         helpText->setHtml( i18nc(
00107         "Help text for the chemical equation solver",
00108         "The equation solver allows you to balance a chemical equation.<br> "
00109         "<br>"
00110         "<b>Using Variables</b><br>"
00111         "To express variable quantities of an element, put a single character in front "
00112         "of the element's symbol, as shown in this example:<br>"
00113         "<i>aH + bO -> 5H2O</i> (Result: <b>10</b> H + <b>5</b> O -&gt; <b>5</b> H<sub>2</sub>O)<br>"
00114         "Solving this expression will give you the needed amount of Hydrogen and Oxygen.<br>"
00115         "<br>"
00116         "<b>Defining electric charges</b><br>"
00117         "Use box brackets to specify the electric charge of an element, as shown in this example:<br>"
00118         "<i>4H[+] + 2O -> cH2O[2+]</i> (Result: <b>4</b> H<b><sup>+</sup></b> + <b>2</b> O -&gt; <b>2</b> H<b><sub>2</sub></b>O<b><sup>2+</sub></b>)"
00119         ) );
00120         helpText->setOpenExternalLinks( true );
00121         m_helpWindow->setMainWidget( helpText );
00122         m_helpWindow->setCaption( i18nc( "Window title for the chemical solver's help", "Chemical Solver Help" ) );
00123         m_helpWindow->show();
00124     }
00125     else
00126     {
00127         if( !m_helpWindow->isVisible() )
00128         {
00129             m_helpWindow->show();
00130         }
00131         m_helpWindow->activateWindow();
00132     }
00133 }
00134 
00135 
00136 #include "eqchemview.moc"
00137 

kalzium

Skip menu "kalzium"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

kdeedu

Skip menu "kdeedu"
  • kalzium
  • kanagram
  • kig
  • klettres
  • kstars
  • libkdeedu
  •   keduvocdocument
  •   docs
  •   src
  • parley
Generated for kdeedu by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal