~ubuntu-branches/ubuntu/precise/kalzium/precise

« back to all changes in this revision

Viewing changes to plasmoid/applet/concentrationPlasmoid/concentrationCalculator.h

  • Committer: Bazaar Package Importer
  • Author(s): Philip Muškovac
  • Date: 2011-07-03 12:28:58 UTC
  • Revision ID: james.westby@ubuntu.com-20110703122858-q1yyxncs89e4w0hs
Tags: upstream-4.6.90+repack
Import upstream version 4.6.90+repack

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
    copyright            : (C) 2009 by Kashyap R Puranik
 
3
    email                : kashthealien@gmail.com
 
4
 ***************************************************************************/
 
5
/***************************************************************************
 
6
 *                                                                         *
 
7
 *   This program is free software; you can redistribute it and/or modify  *
 
8
 *   it under the terms of the GNU General Public License as published by  *
 
9
 *   the Free Software Foundation; either version 2 of the License, or     *
 
10
 *   (at your option) any later version.                                   *
 
11
 *                                                                         *
 
12
 ***************************************************************************/
 
13
#ifndef concentrationCalculator_HEADER
 
14
#define concentrationCalculator_HEADER
 
15
 
 
16
#include <KIcon>
 
17
 
 
18
#include <Plasma/PopupApplet>
 
19
#include <Plasma/Svg>
 
20
#include <kunitconversion/converter.h>
 
21
#include <kunitconversion/value.h>
 
22
 
 
23
#include "ui_concentrationCalculatorConfig.h"
 
24
namespace Plasma{
 
25
        class ComboBox;
 
26
        class SpinBox;
 
27
        class TextEdit;
 
28
        class Label;
 
29
        class Slider;
 
30
        class RadioButton;
 
31
        class PushButton;
 
32
}
 
33
 
 
34
enum ERROR_TYPE_CONC {
 
35
    RESET_CONC_MESG = 0,
 
36
    PERCENTAGE_ZERO,
 
37
    DENSITY_ZERO,
 
38
    MASS_ZERO,
 
39
    VOLUME_ZERO,
 
40
    MOLES_ZERO,
 
41
    MOLAR_MASS_ZERO,
 
42
    EQT_MASS_ZERO,
 
43
    MOLAR_SOLVENT_ZERO,
 
44
    EQTS_ZERO,
 
45
    CONC_ZERO,
 
46
    INSUFFICIENT_DATA_EQT,
 
47
    INSUFFICIENT_DATA_MOLE,
 
48
    INSUFFICIENT_DATA_MOLES,
 
49
    INSUFFICIENT_DATA_SOLVENT
 
50
};
 
51
 
 
52
using namespace KUnitConversion;
 
53
 
 
54
// Define our plasma Applet
 
55
class concentrationCalculator : public Plasma::PopupApplet
 
56
{
 
57
    Q_OBJECT
 
58
    public:
 
59
        // Basic Create/Destroy
 
60
        concentrationCalculator(QObject *parent, const QVariantList &args);
 
61
        ~concentrationCalculator();
 
62
 
 
63
        virtual void init();
 
64
        virtual QGraphicsWidget *graphicsWidget();
 
65
 
 
66
        public slots:
 
67
                // Sub-routines involved in calculations of the unit
 
68
            void calculateAmountSolute();       // Calculates the amount of solute
 
69
            void calculateAmountSolvent();      // Calculates the amount of solvent
 
70
            void calculateMolarMass();          // Calculates the molar mass
 
71
            void calculateEqtMass();            // Calculates the equivalent mass
 
72
            void calculateMolarMassSolvent();   // Calculates the calculate molar mass of the solvent
 
73
            void calculateConcentration();      // calculates the concentration
 
74
 
 
75
            // Functions ( slots ) that occur on changing a value
 
76
            // Sub routines which act as quantity change event handlers
 
77
 
 
78
            void amountSoluteChanged();         // occurs when the amount of solute is changed
 
79
            void amountSoluteTypeChanged();             // occurs when the mode of amount of solute is changed
 
80
            void amountSolventChanged();        // occurs when the amount of solvent is changed
 
81
            void amountSolventTypeChanged();    // occurs when the mode of amount of solvent is changed
 
82
            void molarMassChanged(int);         // occurs when the molar mass of solute is changed
 
83
            void eqtMassChanged(int);           // occurs when the equivalent mass of solute is changed
 
84
            void molarMassSolventChanged(int);  // occurs when the molar mass of solvent is changed
 
85
            void densitySoluteChanged();        // occurs when the number of moles is changed
 
86
            void densitySolventChanged();       // occurs when the density of solvent is changed
 
87
            void concentrationChanged(int);     // occurs when the concentration is changed
 
88
            void calculate();                   // occurs when any quantity is changed
 
89
 
 
90
            double volumeSolvent();             // returns volume of solvent in liters
 
91
            double massSolvent();               // returns mass of solvent in grams
 
92
            double molesSolvent();              // returns number of moles of solvent
 
93
            double densitySolvent();            // returns density of solvent in grams per liter
 
94
            double volumeSolute();              // returns volume of solute in liters
 
95
            double massSolute();                // returns mass of solute in grams
 
96
            double molesSolute();               // returns the number of moles of solute
 
97
            double eqtsSolute();                // returns the number of equivalents of solute
 
98
            double densitySolute();             // returns density of solute in grams per liter
 
99
 
 
100
                /*
 
101
                 * outputs error messages on the screen
 
102
                 * @param type is the type of error that occurred (refer ERROR_TYPE_CONC)
 
103
                 */
 
104
            void error(int type);
 
105
 
 
106
            /// Performs the initialisation for the class
 
107
            void reset();
 
108
 
 
109
            /*
 
110
             * Sets the mode of calculation eg, volume, amount of substance etc
 
111
             * @param mode is the mode of calculation.
 
112
             */
 
113
            void setMode(int mode);
 
114
            
 
115
            void configChanged();
 
116
 
 
117
    protected:
 
118
        void createConfigurationInterface(KConfigDialog *parent);
 
119
    
 
120
    protected slots:
 
121
        void configAccepted();
 
122
 
 
123
    private:
 
124
    Converter *m_converter;
 
125
        QGraphicsWidget  *m_widget;
 
126
        Plasma::ComboBox *m_amountSoluteType;
 
127
        Plasma::ComboBox *m_amountSoluteUnit;
 
128
        Plasma::ComboBox *m_amountSolventType;
 
129
        Plasma::ComboBox *m_amountSolventUnit;
 
130
        Plasma::ComboBox *m_densitySoluteUnit;
 
131
        Plasma::ComboBox *m_densitySolventUnit;
 
132
        Plasma::ComboBox *m_concentrationUnit;
 
133
        Plasma::ComboBox *m_calculationMode;
 
134
 
 
135
        Plasma::SpinBox *m_amountSolute;
 
136
        Plasma::SpinBox *m_molarMass;
 
137
        Plasma::SpinBox *m_eqtMass;
 
138
        Plasma::SpinBox *m_densitySolute;
 
139
        Plasma::SpinBox *m_amountSolvent;
 
140
        Plasma::SpinBox *m_molarMassSolvent;
 
141
        Plasma::SpinBox *m_densitySolvent;
 
142
        Plasma::SpinBox *m_concentration;
 
143
        Plasma::Label   *m_error;
 
144
 
 
145
        Plasma::PushButton *m_reset;
 
146
 
 
147
        Value m_AmtSolute;                          // amount of solute
 
148
            Value m_AmtSolvent;                         // amount of solvent
 
149
            double m_MolesSolute;                       // amount of solute in moles
 
150
            double m_MolesSolvent;                      // amount of solvent in moles
 
151
            double m_MolarMass;                         // molar mass of solute
 
152
            double m_EqtMass;                           // equivalent mass of solute
 
153
            double m_MolarMassSolvent;                  // molar mass of solvent
 
154
            Value m_DensitySolute;                      // density of solute
 
155
            Value m_DensitySolvent;                     // density of the solvent
 
156
            double m_Concentration;                     // concentration of the solution
 
157
            int m_mode;                                                                 // mode of calculation
 
158
 
 
159
            /// Designer Config file
 
160
        Ui::concentrationCalculatorConfig ui;
 
161
        bool m_configUpdated;
 
162
        // Indicates solute is always given in terms of mass
 
163
        bool m_soluteMass;                                      // For configuration
 
164
        // Indicates solvent is always given in terms of volume
 
165
        bool m_solventVolume;                           // For configuration
 
166
};
 
167
 
 
168
// This is the command that links your applet to the .desktop file
 
169
K_EXPORT_PLASMA_APPLET(concentrationCalculator, concentrationCalculator)
 
170
#endif //concentrationCalculator_HEADER