summaryrefslogtreecommitdiff
path: root/noncore/apps/oxygen/calcdlgui.cpp
blob: 2bb8337d88327cd799bdb8080a51e11bafcd8cdf (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
/***************************************************************************
   application:             : Oxygen

   begin                    : September 2002
   copyright                : ( C ) 2002 by Carsten Niehaus
   email                    : cniehaus@handhelds.org
 **************************************************************************/

/***************************************************************************
 *                                                                         *
 * 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 "calcdlgui.h"
#include "kmolcalc.h"
#include <qlineedit.h>
#include <qmultilineedit.h>
#include <qpushbutton.h>

calcDlgUI::calcDlgUI() : CalcDlg()
{
    kmolcalc = new KMolCalc;
    connect( calculate, SIGNAL( clicked() ), this, SLOT( calc() ) );
    connect( clear_fields, SIGNAL( clicked() ), this, SLOT( clear() ) );
    result->setReadOnly( true );
}

void calcDlgUI::calc()
{
    QString compound( formula->text() );
    if ( compound.isEmpty() ) {
        clear();
        return;
    }
    QString errors( kmolcalc->readFormula( compound ) );
    QString mw, ea;
    double weight = kmolcalc->getWeight();
    if ( errors == "OK" ) {
        mw.setNum( weight );
        ea = kmolcalc->getEmpFormula() + " :\n" + kmolcalc->getEA();
    } else {
        mw = "???";
        ea = tr( "ERROR: \n" ).arg( errors )+ "\n";
    }
    result->setText( mw );
    anal_display->setText( ea );
}

/**
 * * Clear all text entry / result fields.
 * */
void calcDlgUI::clear()
{
    formula->clear();
    result->clear();
    anal_display->clear();
}