1
/***************************************************************************
2
copyright : (C) 2009 by Kashyap R Puranik
3
email : kashthealien@gmail.com
4
***************************************************************************/
5
/***************************************************************************
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. *
12
***************************************************************************/
13
#ifndef concentrationCalculator_HEADER
14
#define concentrationCalculator_HEADER
18
#include <Plasma/PopupApplet>
20
#include <kunitconversion/converter.h>
21
#include <kunitconversion/value.h>
23
#include "ui_concentrationCalculatorConfig.h"
34
enum ERROR_TYPE_CONC {
46
INSUFFICIENT_DATA_EQT,
47
INSUFFICIENT_DATA_MOLE,
48
INSUFFICIENT_DATA_MOLES,
49
INSUFFICIENT_DATA_SOLVENT
52
using namespace KUnitConversion;
54
// Define our plasma Applet
55
class concentrationCalculator : public Plasma::PopupApplet
59
// Basic Create/Destroy
60
concentrationCalculator(QObject *parent, const QVariantList &args);
61
~concentrationCalculator();
64
virtual QGraphicsWidget *graphicsWidget();
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
75
// Functions ( slots ) that occur on changing a value
76
// Sub routines which act as quantity change event handlers
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
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
101
* outputs error messages on the screen
102
* @param type is the type of error that occurred (refer ERROR_TYPE_CONC)
104
void error(int type);
106
/// Performs the initialisation for the class
110
* Sets the mode of calculation eg, volume, amount of substance etc
111
* @param mode is the mode of calculation.
113
void setMode(int mode);
115
void configChanged();
118
void createConfigurationInterface(KConfigDialog *parent);
121
void configAccepted();
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;
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;
145
Plasma::PushButton *m_reset;
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
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
168
// This is the command that links your applet to the .desktop file
169
K_EXPORT_PLASMA_APPLET(concentrationCalculator, concentrationCalculator)
170
#endif //concentrationCalculator_HEADER