1 | /* |
2 | * Copyright (C) 2007-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 "temperature.h" |
21 | #include "converter.h" |
22 | #include <klocale.h> |
23 | |
24 | using namespace KUnitConversion; |
25 | |
26 | class CelsiusConv : public Complex |
27 | { |
28 | double toDefault(double value) const { return value + 273.15; }; |
29 | double fromDefault(double value) const { return value - 273.15; }; |
30 | }; |
31 | |
32 | class FahrenheitConv : public Complex |
33 | { |
34 | double toDefault(double value) const { return (value + 459.67) * 5.0 / 9.0; }; |
35 | double fromDefault(double value) const { return (value * 9.0 / 5.0) - 459.67; }; |
36 | }; |
37 | |
38 | class DelisleConv : public Complex |
39 | { |
40 | double toDefault(double value) const { return 373.15 - (value * 2.0 / 3.0); }; |
41 | double fromDefault(double value) const { return (373.15 - value) * 3.0 / 2.0; }; |
42 | }; |
43 | |
44 | class NewtonConv : public Complex |
45 | { |
46 | double toDefault(double value) const { return (value * 100.0 / 33.0) + 273.15; }; |
47 | double fromDefault(double value) const { return (value - 273.15) * 33.0 / 100.0; }; |
48 | }; |
49 | |
50 | class ReaumurConv : public Complex |
51 | { |
52 | double toDefault(double value) const { return (value * 5.0 / 4.0) + 273.15; }; |
53 | double fromDefault(double value) const { return (value - 273.15) * 4.0 / 5.0; }; |
54 | }; |
55 | |
56 | class RomerConv : public Complex |
57 | { |
58 | double toDefault(double value) const { return (value - 7.5) * 40.0 / 21.0 + 273.15; }; |
59 | double fromDefault(double value) const { return (value - 273.15) * 21.0 / 40.0 + 7.5; }; |
60 | }; |
61 | |
62 | |
63 | Temperature::Temperature() : UnitCategory(TemperatureCategory) |
64 | { |
65 | setName(i18n("Temperature" )); |
66 | setSymbolStringFormat(ki18nc("%1 value, %2 unit symbol (temperature)" , "%1 %2" )); |
67 | |
68 | setDefaultUnit(UP(Kelvin, 1, |
69 | i18nc("temperature unit symbol" , "K" ), |
70 | i18nc("unit description in lists" , "kelvins" ), |
71 | i18nc("unit synonyms for matching user input" , "kelvin;kelvins;K" ), |
72 | ki18nc("amount in units (real)" , "%1 kelvins" ), |
73 | ki18ncp("amount in units (integer)" , "%1 kelvin" , "%1 kelvins" ) |
74 | )); |
75 | U(Celsius, new CelsiusConv(), |
76 | i18nc("temperature unit symbol" , "°C" ), |
77 | i18nc("unit description in lists" , "Celsius" ), |
78 | i18nc("unit synonyms for matching user input" , "Celsius;°C;C" ), |
79 | ki18nc("amount in units (real)" , "%1 degrees Celsius" ), |
80 | ki18ncp("amount in units (integer)" , "%1 degree Celsius" , "%1 degrees Celsius" ) |
81 | ); |
82 | U(Fahrenheit, new FahrenheitConv(), |
83 | i18nc("temperature unit symbol" , "°F" ), |
84 | i18nc("unit description in lists" , "Fahrenheit" ), |
85 | i18nc("unit synonyms for matching user input" , "Fahrenheit;°F;F" ), |
86 | ki18nc("amount in units (real)" , "%1 degrees Fahrenheit" ), |
87 | ki18ncp("amount in units (integer)" , "%1 degree Fahrenheit" , "%1 degrees Fahrenheit" ) |
88 | ); |
89 | U(Rankine, 0.555556, |
90 | i18nc("temperature unit symbol" , "R" ), |
91 | i18nc("unit description in lists" , "Rankine" ), |
92 | i18nc("unit synonyms for matching user input" , "Rankine;°R;R;Ra" ), |
93 | ki18nc("amount in units (real)" , "%1 Rankine" ), |
94 | ki18ncp("amount in units (integer)" , "%1 Rankine" , "%1 Rankine" ) |
95 | ); |
96 | U(Delisle, new DelisleConv(), |
97 | i18nc("temperature unit symbol" , "°De" ), |
98 | i18nc("unit description in lists" , "Delisle" ), |
99 | i18nc("unit synonyms for matching user input" , "Delisle;°De;De" ), |
100 | ki18nc("amount in units (real)" , "%1 degrees Delisle" ), |
101 | ki18ncp("amount in units (integer)" , "%1 degree Delisle" , "%1 degrees Delisle" ) |
102 | ); |
103 | U(TemperatureNewton, new NewtonConv(), |
104 | i18nc("temperature unit symbol" , "°N" ), |
105 | i18nc("unit description in lists" , "Newton" ), |
106 | i18nc("unit synonyms for matching user input" , "Newton;°N;N" ), |
107 | ki18nc("amount in units (real)" , "%1 degrees Newton" ), |
108 | ki18ncp("amount in units (integer)" , "%1 degree Newton" , "%1 degrees Newton" ) |
109 | ); |
110 | U(Reaumur, new ReaumurConv(), |
111 | i18nc("temperature unit symbol" , "°Ré" ), |
112 | i18nc("unit description in lists" , "Réaumur" ), |
113 | i18nc("unit synonyms for matching user input" , "Réaumur;°Ré;Ré;Reaumur;°Re;Re" ), |
114 | ki18nc("amount in units (real)" , "%1 degrees Réaumur" ), |
115 | ki18ncp("amount in units (integer)" , "%1 degree Réaumur" , "%1 degrees Réaumur" ) |
116 | ); |
117 | U(Romer, new RomerConv(), |
118 | i18nc("temperature unit symbol" , "°Rø" ), |
119 | i18nc("unit description in lists" , "Rømer" ), |
120 | i18nc("unit synonyms for matching user input" , "Rømer;°Rø;Rø;Romer;°Ro;Ro" ), |
121 | ki18nc("amount in units (real)" , "%1 degrees Rømer" ), |
122 | ki18ncp("amount in units (integer)" , "%1 degree Rømer" , "%1 degrees Rømer" ) |
123 | ); |
124 | |
125 | setMostCommonUnits(QList<int>() << Kelvin << Celsius << Fahrenheit); |
126 | } |
127 | |