summaryrefslogtreecommitdiffstats
path: root/kalzium/src/eqchemview.cpp
blob: aa73c40b739d210b68596f822ff18406f4fbe672 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/***************************************************************************
 *   Copyright (C) 2004, 2005 by Thomas Nagy                               *
 *   tnagy2^8@yahoo.fr                                                     *
 *                                                                         *
 *   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.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.             *
 ***************************************************************************/

#include <tqlayout.h>
#include <tqlabel.h>
#include <tqstring.h>

#include <kdebug.h>
#include <klocale.h>
#include <klineedit.h>
#include <kpushbutton.h>
#include <kiconloader.h>
#include <kglobal.h>
#include <kapplication.h>

#include "config.h"
#include "eqresult.h"
#include "eqchemview.h"

#include <stdlib.h>

#ifdef HAVE_FACILE
extern "C" {
    char* solve_equation(const char *);
}
#endif

#ifndef HAVE_FACILE
char* solve_equation(const char *) { return NULL; }
#endif

eqchemView::eqchemView(TQWidget *parent) : TQWidget(parent)
{
    settingsChanged();

    TQGridLayout *l = new TQGridLayout(this, 2, 2, 11, 6, "eqchemView::eqchemView tqlayout");

    m_eqResult = new EqResult(this);
    m_eqedit = new KLineEdit(this);
    m_eqclear = new KPushButton(this);

    l->addMultiCellWidget(m_eqResult, 0, 0, 0, 1);
    l->addWidget(m_eqedit, 1, 1);
    l->addWidget(m_eqclear, 1, 0);

    m_eqclear->setIconSet( KGlobal::instance()->iconLoader()->loadIconSet("locationbar_erase", 
		KIcon::NoGroup, 22 /*KIcon::SizeSmallMedium*/) );

    connect(m_eqclear, TQT_SIGNAL(clicked()), m_eqedit, TQT_SLOT(clear()) );
}

eqchemView::~eqchemView()
{

}

void eqchemView::settingsChanged()
{
    // i18n : internationalization
    emit signalChangetqStatusbar( i18n("Settings changed") );
}


void eqchemView::clear()
{
    kdWarning()<<"eqchemView::clear"<<endl;

    // clear the result window
    m_eqResult->clear();
}

void eqchemView::compute()
{
    TQString equation( m_eqedit->text() );
    equation.tqreplace("+", "+");
    equation.tqreplace("->", " -> ");
    equation.append(" ");
    equation.prepend(" ");
    
    char * result = solve_equation( equation.latin1() );
    TQString disp = TQString(result);

    // mem leak ?
    free(result);

    // add the equation in the result window
    m_eqResult->add( equation, disp );
}

EQChemDialog::EQChemDialog( TQWidget *parent )
	: KDialogBase(parent, "EQChemDialog", true, i18n( "Solve Chemical Equations" ),
			KDialogBase::Apply|KDialogBase::Close|KDialogBase::Help, KDialogBase::Apply, true )
{
}

void EQChemDialog::slotHelp()
{
	emit helpClicked();
	if ( kapp )
		kapp->invokeHelp ( "eq_solver", "kalzium" );
}

#include "eqchemview.moc"