1/*
2 * Copyright (C) 2009 Petri Damstén <damu@iki.fi>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Library General Public License as
6 * published by the Free Software Foundation; either version 2, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details
13 *
14 * You should have received a copy of the GNU Library General Public
15 * License along with this program; if not, write to the
16 * Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 */
19
20#include "energy.h"
21#include "converter.h"
22#include <klocale.h>
23
24using namespace KUnitConversion;
25
26class PhotonWavelengthConv : public Complex
27{
28 double toDefault(double value) const { return (2.99792458e+08 * 6.62606896e-34) / (value * 1e-09); };
29 double fromDefault(double value) const { return ((2.99792458e+08 * 6.62606896e-34) / value) / 1e-09; };
30};
31
32Energy::Energy() : UnitCategory(EnergyCategory)
33{
34 setName(i18n("Energy"));
35 setSymbolStringFormat(ki18nc("%1 value, %2 unit symbol (energy)", "%1 %2"));
36
37 U(Yottajoule, 1e+24,
38 i18nc("energy unit symbol", "YJ"),
39 i18nc("unit description in lists", "yottajoules"),
40 i18nc("unit synonyms for matching user input", "yottajoule;yottajoules;YJ"),
41 ki18nc("amount in units (real)", "%1 yottajoules"),
42 ki18ncp("amount in units (integer)", "%1 yottajoule", "%1 yottajoules")
43 );
44 U(Zettajoule, 1e+21,
45 i18nc("energy unit symbol", "ZJ"),
46 i18nc("unit description in lists", "zettajoules"),
47 i18nc("unit synonyms for matching user input", "zettajoule;zettajoules;ZJ"),
48 ki18nc("amount in units (real)", "%1 zettajoules"),
49 ki18ncp("amount in units (integer)", "%1 zettajoule", "%1 zettajoules")
50 );
51 U(Exajoule, 1e+18,
52 i18nc("energy unit symbol", "EJ"),
53 i18nc("unit description in lists", "exajoules"),
54 i18nc("unit synonyms for matching user input", "exajoule;exajoules;EJ"),
55 ki18nc("amount in units (real)", "%1 exajoules"),
56 ki18ncp("amount in units (integer)", "%1 exajoule", "%1 exajoules")
57 );
58 U(Petajoule, 1e+15,
59 i18nc("energy unit symbol", "PJ"),
60 i18nc("unit description in lists", "petajoules"),
61 i18nc("unit synonyms for matching user input", "petajoule;petajoules;PJ"),
62 ki18nc("amount in units (real)", "%1 petajoules"),
63 ki18ncp("amount in units (integer)", "%1 petajoule", "%1 petajoules")
64 );
65 U(Terajoule, 1e+12,
66 i18nc("energy unit symbol", "TJ"),
67 i18nc("unit description in lists", "terajoules"),
68 i18nc("unit synonyms for matching user input", "terajoule;terajoules;TJ"),
69 ki18nc("amount in units (real)", "%1 terajoules"),
70 ki18ncp("amount in units (integer)", "%1 terajoule", "%1 terajoules")
71 );
72 U(Gigajoule, 1e+09,
73 i18nc("energy unit symbol", "GJ"),
74 i18nc("unit description in lists", "gigajoules"),
75 i18nc("unit synonyms for matching user input", "gigajoule;gigajoules;GJ"),
76 ki18nc("amount in units (real)", "%1 gigajoules"),
77 ki18ncp("amount in units (integer)", "%1 gigajoule", "%1 gigajoules")
78 );
79 U(Megajoule, 1e+06,
80 i18nc("energy unit symbol", "MJ"),
81 i18nc("unit description in lists", "megajoules"),
82 i18nc("unit synonyms for matching user input", "megajoule;megajoules;MJ"),
83 ki18nc("amount in units (real)", "%1 megajoules"),
84 ki18ncp("amount in units (integer)", "%1 megajoule", "%1 megajoules")
85 );
86 U(Kilojoule, 1000,
87 i18nc("energy unit symbol", "kJ"),
88 i18nc("unit description in lists", "kilojoules"),
89 i18nc("unit synonyms for matching user input", "kilojoule;kilojoules;kJ"),
90 ki18nc("amount in units (real)", "%1 kilojoules"),
91 ki18ncp("amount in units (integer)", "%1 kilojoule", "%1 kilojoules")
92 );
93 U(Hectojoule, 100,
94 i18nc("energy unit symbol", "hJ"),
95 i18nc("unit description in lists", "hectojoules"),
96 i18nc("unit synonyms for matching user input", "hectojoule;hectojoules;hJ"),
97 ki18nc("amount in units (real)", "%1 hectojoules"),
98 ki18ncp("amount in units (integer)", "%1 hectojoule", "%1 hectojoules")
99 );
100 U(Decajoule, 10,
101 i18nc("energy unit symbol", "daJ"),
102 i18nc("unit description in lists", "decajoules"),
103 i18nc("unit synonyms for matching user input", "decajoule;decajoules;daJ"),
104 ki18nc("amount in units (real)", "%1 decajoules"),
105 ki18ncp("amount in units (integer)", "%1 decajoule", "%1 decajoules")
106 );
107 setDefaultUnit(UP(Joule, 1,
108 i18nc("energy unit symbol", "J"),
109 i18nc("unit description in lists", "joules"),
110 i18nc("unit synonyms for matching user input", "joule;joules;J"),
111 ki18nc("amount in units (real)", "%1 joules"),
112 ki18ncp("amount in units (integer)", "%1 joule", "%1 joules")
113 ));
114 U(Decijoule, 0.1,
115 i18nc("energy unit symbol", "dJ"),
116 i18nc("unit description in lists", "decijoules"),
117 i18nc("unit synonyms for matching user input", "decijoule;decijoules;dJ"),
118 ki18nc("amount in units (real)", "%1 decijoules"),
119 ki18ncp("amount in units (integer)", "%1 decijoule", "%1 decijoules")
120 );
121 U(Centijoule, 0.01,
122 i18nc("energy unit symbol", "cJ"),
123 i18nc("unit description in lists", "centijoules"),
124 i18nc("unit synonyms for matching user input", "centijoule;centijoules;cJ"),
125 ki18nc("amount in units (real)", "%1 centijoules"),
126 ki18ncp("amount in units (integer)", "%1 centijoule", "%1 centijoules")
127 );
128 U(Millijoule, 0.001,
129 i18nc("energy unit symbol", "mJ"),
130 i18nc("unit description in lists", "millijoules"),
131 i18nc("unit synonyms for matching user input", "millijoule;millijoules;mJ"),
132 ki18nc("amount in units (real)", "%1 millijoules"),
133 ki18ncp("amount in units (integer)", "%1 millijoule", "%1 millijoules")
134 );
135 U(Microjoule, 1e-06,
136 i18nc("energy unit symbol", "µJ"),
137 i18nc("unit description in lists", "microjoules"),
138 i18nc("unit synonyms for matching user input", "microjoule;microjoules;µJ;uJ"),
139 ki18nc("amount in units (real)", "%1 microjoules"),
140 ki18ncp("amount in units (integer)", "%1 microjoule", "%1 microjoules")
141 );
142 U(Nanojoule, 1e-09,
143 i18nc("energy unit symbol", "nJ"),
144 i18nc("unit description in lists", "nanojoules"),
145 i18nc("unit synonyms for matching user input", "nanojoule;nanojoules;nJ"),
146 ki18nc("amount in units (real)", "%1 nanojoules"),
147 ki18ncp("amount in units (integer)", "%1 nanojoule", "%1 nanojoules")
148 );
149 U(Picojoule, 1e-12,
150 i18nc("energy unit symbol", "pJ"),
151 i18nc("unit description in lists", "picojoules"),
152 i18nc("unit synonyms for matching user input", "picojoule;picojoules;pJ"),
153 ki18nc("amount in units (real)", "%1 picojoules"),
154 ki18ncp("amount in units (integer)", "%1 picojoule", "%1 picojoules")
155 );
156 U(Femtojoule, 1e-15,
157 i18nc("energy unit symbol", "fJ"),
158 i18nc("unit description in lists", "femtojoules"),
159 i18nc("unit synonyms for matching user input", "femtojoule;femtojoules;fJ"),
160 ki18nc("amount in units (real)", "%1 femtojoules"),
161 ki18ncp("amount in units (integer)", "%1 femtojoule", "%1 femtojoules")
162 );
163 U(Attojoule, 1e-18,
164 i18nc("energy unit symbol", "aJ"),
165 i18nc("unit description in lists", "attojoules"),
166 i18nc("unit synonyms for matching user input", "attojoule;attojoules;aJ"),
167 ki18nc("amount in units (real)", "%1 attojoules"),
168 ki18ncp("amount in units (integer)", "%1 attojoule", "%1 attojoules")
169 );
170 U(Zeptojoule, 1e-21,
171 i18nc("energy unit symbol", "zJ"),
172 i18nc("unit description in lists", "zeptojoules"),
173 i18nc("unit synonyms for matching user input", "zeptojoule;zeptojoules;zJ"),
174 ki18nc("amount in units (real)", "%1 zeptojoules"),
175 ki18ncp("amount in units (integer)", "%1 zeptojoule", "%1 zeptojoules")
176 );
177 U(Yoctojoule, 1e-24,
178 i18nc("energy unit symbol", "yJ"),
179 i18nc("unit description in lists", "yoctojoules"),
180 i18nc("unit synonyms for matching user input", "yoctojoule;yoctojoules;yJ"),
181 ki18nc("amount in units (real)", "%1 yoctojoules"),
182 ki18ncp("amount in units (integer)", "%1 yoctojoule", "%1 yoctojoules")
183 );
184 U(GuidelineDailyAmount, 8.3736e+06,
185 i18nc("energy unit symbol", "GDA"),
186 i18nc("unit description in lists", "guideline daily amount"),
187 i18nc("unit synonyms for matching user input",
188 "guideline daily amount;guideline daily amount;GDA"),
189 ki18nc("amount in units (real)", "%1 guideline daily amount"),
190 ki18ncp("amount in units (integer)", "%1 guideline daily amount", "%1 guideline daily amount")
191 );
192 U(Electronvolt, 1.60218e-19,
193 i18nc("energy unit symbol", "eV"),
194 i18nc("unit description in lists", "electronvolts"),
195 i18nc("unit synonyms for matching user input", "electronvolt;electronvolts;eV"),
196 ki18nc("amount in units (real)", "%1 electronvolts"),
197 ki18ncp("amount in units (integer)", "%1 electronvolt", "%1 electronvolts")
198 );
199 U(JoulePerMole, 1.66054238581e-24,
200 i18nc("energy unit symbol", "J/mol"),
201 i18nc("unit description in lists", "joule per mole"),
202 i18nc("unit synonyms for matching user input", "joule per mole;joulepermole;joulemol;jmol;j/mol"),
203 ki18nc("amount in units (real)", "%1 joules per mole"),
204 ki18ncp("amount in units (integer)", "%1 joule per mole", "%1 joules per mole")
205 );
206 U(KiloJoulePerMole, 1.66054238581e-21,
207 i18nc("energy unit symbol", "kJ/mol"),
208 i18nc("unit description in lists", "kilojoule per mole"),
209 i18nc("unit synonyms for matching user input", "kilojoule per mole;kilojoulepermole;kilojoule per mole;kilojoulemol;kjmol;kj/mol"),
210 ki18nc("amount in units (real)", "%1 kilojoules per mole"),
211 ki18ncp("amount in units (integer)", "%1 kilojoule per mole", "%1 kilojoules per mole")
212 );
213 U(Rydberg, 2.17987e-18,
214 i18nc("energy unit symbol", "Ry"),
215 i18nc("unit description in lists", "rydbergs"),
216 i18nc("unit synonyms for matching user input", "rydberg;rydbergs;Ry"),
217 ki18nc("amount in units (real)", "%1 rydbergs"),
218 ki18ncp("amount in units (integer)", "%1 rydberg", "%1 rydbergs")
219 );
220 U(Kilocalorie, 4186.8,
221 i18nc("energy unit symbol", "kcal"),
222 i18nc("unit description in lists", "kilocalories"),
223 i18nc("unit synonyms for matching user input", "kilocalorie;kilocalories;kcal"),
224 ki18nc("amount in units (real)", "%1 kilocalories"),
225 ki18ncp("amount in units (integer)", "%1 kilocalorie", "%1 kilocalories")
226 );
227 U(PhotonWavelength, new PhotonWavelengthConv(),
228 i18nc("energy unit symbol", "nm"),
229 i18nc("unit description in lists", "photon wavelength in nanometers"),
230 i18nc("unit synonyms for matching user input", "nm;photon wavelength"),
231 ki18nc("amount in units (real)", "%1 nanometers"),
232 ki18ncp("amount in units (integer)", "%1 nanometer", "%1 nanometers")
233 );
234
235 setMostCommonUnits(QList<int>() <<
236 Joule << Kilojoule << Kilocalorie << GuidelineDailyAmount);
237}
238