KUnitConversion
angle.cpp
Go to the documentation of this file.
00001 /* 00002 * Copyright (C) 2010 Petri Damstén <damu@iki.fi> 00003 * 00004 * This program is free software; you can redistribute it and/or modify 00005 * it under the terms of the GNU Library General Public License as 00006 * published by the Free Software Foundation; either version 2, or 00007 * (at your option) any later version. 00008 * 00009 * This program is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 * GNU General Public License for more details 00013 * 00014 * You should have received a copy of the GNU Library General Public 00015 * License along with this program; if not, write to the 00016 * Free Software Foundation, Inc., 00017 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00018 */ 00019 00020 #include "angle.h" 00021 #include "converter.h" 00022 #include <klocale.h> 00023 #include <math.h> 00024 00025 using namespace KUnitConversion; 00026 00027 class RadiansConv : public Complex 00028 { 00029 double toDefault(double value) const { return (value / (2 * M_PI)) * 360.0; }; 00030 double fromDefault(double value) const { return (value / 360.0) * (2 * M_PI); }; 00031 }; 00032 00033 Angle::Angle() : UnitCategory(AngleCategory) 00034 { 00035 setName(i18n("Angle")); 00036 setSymbolStringFormat(ki18nc("%1 value, %2 unit symbol (angle)", "%1 %2")); 00037 00038 setDefaultUnit(UP(Degree, 1, 00039 i18nc("angle unit symbol", "°"), 00040 i18nc("unit description in lists", "degrees"), 00041 i18nc("unit synonyms for matching user input", "deg;degree;degrees;°"), 00042 ki18nc("amount in units (real)", "%1 degrees"), 00043 ki18ncp("amount in units (integer)", "%1 degree", "%1 degrees") 00044 )); 00045 U(Radian, new RadiansConv(), 00046 i18nc("angle unit symbol", "rad"), 00047 i18nc("unit description in lists", "radians"), 00048 i18nc("unit synonyms for matching user input", "rad;radian;radians"), 00049 ki18nc("amount in units (real)", "%1 radians"), 00050 ki18ncp("amount in units (integer)", "%1 radian", "%1 radians") 00051 ); 00052 U(Gradian, 360.0 / 400.0, 00053 i18nc("angle unit symbol", "grad"), 00054 i18nc("unit description in lists", "gradians"), 00055 i18nc("unit synonyms for matching user input", "grad;gradian;gradians;grade;gon"), 00056 ki18nc("amount in units (real)", "%1 gradians"), 00057 ki18ncp("amount in units (integer)", "%1 gradian", "%1 gradians") 00058 ); 00059 U(ArcMinute, 1.0 / 60.0, 00060 i18nc("angle unit symbol", "'"), 00061 i18nc("unit description in lists", "arc minutes"), 00062 i18nc("unit synonyms for matching user input", "minute of arc;MOA;arcminute;minute;'"), 00063 ki18nc("amount in units (real)", "%1 arc minutes"), 00064 ki18ncp("amount in units (integer)", "%1 arc minute", "%1 arc minutes") 00065 ); 00066 U(ArcSecond, 1.0 / 3600.0, 00067 i18nc("angle unit symbol", "\""), 00068 i18nc("unit description in lists", "arc seconds"), 00069 i18nc("unit synonyms for matching user input", "second of arc;arcsecond;second;\""), 00070 ki18nc("amount in units (real)", "%1 arc seconds"), 00071 ki18ncp("amount in units (integer)", "%1 arc second", "%1 arc seconds") 00072 ); 00073 00074 setMostCommonUnits(QList<int>() << Degree << Radian << ArcMinute << ArcSecond); 00075 } 00076
KDE 4.6 API Reference