1 | /* |
2 | * Copyright (C) 2010 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 "angle.h" |
21 | #include "converter.h" |
22 | #include <klocale.h> |
23 | #include <math.h> |
24 | |
25 | using namespace KUnitConversion; |
26 | |
27 | class RadiansConv : public Complex |
28 | { |
29 | double toDefault(double value) const { return (value / (2 * M_PI)) * 360.0; }; |
30 | double fromDefault(double value) const { return (value / 360.0) * (2 * M_PI); }; |
31 | }; |
32 | |
33 | Angle::Angle() : UnitCategory(AngleCategory) |
34 | { |
35 | setName(i18n("Angle" )); |
36 | setSymbolStringFormat(ki18nc("%1 value, %2 unit symbol (angle)" , "%1 %2" )); |
37 | |
38 | setDefaultUnit(UP(Degree, 1, |
39 | i18nc("angle unit symbol" , "°" ), |
40 | i18nc("unit description in lists" , "degrees" ), |
41 | i18nc("unit synonyms for matching user input" , "deg;degree;degrees;°" ), |
42 | ki18nc("amount in units (real)" , "%1 degrees" ), |
43 | ki18ncp("amount in units (integer)" , "%1 degree" , "%1 degrees" ) |
44 | )); |
45 | U(Radian, new RadiansConv(), |
46 | i18nc("angle unit symbol" , "rad" ), |
47 | i18nc("unit description in lists" , "radians" ), |
48 | i18nc("unit synonyms for matching user input" , "rad;radian;radians" ), |
49 | ki18nc("amount in units (real)" , "%1 radians" ), |
50 | ki18ncp("amount in units (integer)" , "%1 radian" , "%1 radians" ) |
51 | ); |
52 | U(Gradian, 360.0 / 400.0, |
53 | i18nc("angle unit symbol" , "grad" ), |
54 | i18nc("unit description in lists" , "gradians" ), |
55 | i18nc("unit synonyms for matching user input" , "grad;gradian;gradians;grade;gon" ), |
56 | ki18nc("amount in units (real)" , "%1 gradians" ), |
57 | ki18ncp("amount in units (integer)" , "%1 gradian" , "%1 gradians" ) |
58 | ); |
59 | U(ArcMinute, 1.0 / 60.0, |
60 | i18nc("angle unit symbol" , "'" ), |
61 | i18nc("unit description in lists" , "arc minutes" ), |
62 | i18nc("unit synonyms for matching user input" , "minute of arc;MOA;arcminute;minute;'" ), |
63 | ki18nc("amount in units (real)" , "%1 arc minutes" ), |
64 | ki18ncp("amount in units (integer)" , "%1 arc minute" , "%1 arc minutes" ) |
65 | ); |
66 | U(ArcSecond, 1.0 / 3600.0, |
67 | i18nc("angle unit symbol" , "\"" ), |
68 | i18nc("unit description in lists" , "arc seconds" ), |
69 | i18nc("unit synonyms for matching user input" , "second of arc;arcsecond;second;\"" ), |
70 | ki18nc("amount in units (real)" , "%1 arc seconds" ), |
71 | ki18ncp("amount in units (integer)" , "%1 arc second" , "%1 arc seconds" ) |
72 | ); |
73 | |
74 | setMostCommonUnits(QList<int>() << Degree << Radian << ArcMinute << ArcSecond); |
75 | } |
76 | |
77 | |