kalzium
eqchemview.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
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
00061 ui.answer_label->setText(answer);
00062
00063
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 -> <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 -> <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