• Skip to content
  • Skip to link menu
KDE 4.6 API Reference
  • KDE API Reference
  • kdelibs
  • KDE Home
  • Contact Us
 

KUnitConversion

temperature.cpp

Go to the documentation of this file.
00001 /*
00002  *   Copyright (C) 2007-2009 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 "temperature.h"
00021 #include "converter.h"
00022 #include <klocale.h>
00023 
00024 using namespace KUnitConversion;
00025 
00026 class CelsiusConv : public Complex
00027 {
00028     double toDefault(double value) const { return value + 273.15; };
00029     double fromDefault(double value) const { return value - 273.15; };
00030 };
00031 
00032 class FahrenheitConv : public Complex
00033 {
00034     double toDefault(double value) const { return (value + 459.67) * 5.0 / 9.0; };
00035     double fromDefault(double value) const { return (value * 9.0 / 5.0) - 459.67; };
00036 };
00037 
00038 class DelisleConv : public Complex
00039 {
00040     double toDefault(double value) const { return 373.15 - (value * 2.0 / 3.0); };
00041     double fromDefault(double value) const { return (373.15 - value) * 3.0 / 2.0; };
00042 };
00043 
00044 class NewtonConv : public Complex
00045 {
00046     double toDefault(double value) const { return (value * 100.0 / 33.0) + 273.15; };
00047     double fromDefault(double value) const { return (value - 273.15) * 33.0 / 100.0; };
00048 };
00049 
00050 class ReaumurConv : public Complex
00051 {
00052     double toDefault(double value) const { return (value * 5.0 / 4.0) + 273.15; };
00053     double fromDefault(double value) const { return (value - 273.15) * 4.0 / 5.0; };
00054 };
00055 
00056 class RomerConv : public Complex
00057 {
00058     double toDefault(double value) const { return (value - 7.5) * 40.0 / 21.0 + 273.15; };
00059     double fromDefault(double value) const { return (value - 273.15) * 21.0 / 40.0 + 7.5; };
00060 };
00061 
00062 
00063 Temperature::Temperature() : UnitCategory(TemperatureCategory)
00064 {
00065     setName(i18n("Temperature"));
00066     setSymbolStringFormat(ki18nc("%1 value, %2 unit symbol (temperature)", "%1 %2"));
00067 
00068     setDefaultUnit(UP(Kelvin, 1,
00069       i18nc("temperature unit symbol", "K"),
00070       i18nc("unit description in lists", "kelvins"),
00071       i18nc("unit synonyms for matching user input", "kelvin;kelvins;K"),
00072       ki18nc("amount in units (real)", "%1 kelvins"),
00073       ki18ncp("amount in units (integer)", "%1 kelvin", "%1 kelvins")
00074     ));
00075     U(Celsius, new CelsiusConv(),
00076       i18nc("temperature unit symbol", "°C"),
00077       i18nc("unit description in lists", "Celsius"),
00078       i18nc("unit synonyms for matching user input", "Celsius;°C;C"),
00079       ki18nc("amount in units (real)", "%1 degrees Celsius"),
00080       ki18ncp("amount in units (integer)", "%1 degree Celsius", "%1 degrees Celsius")
00081     );
00082     U(Fahrenheit, new FahrenheitConv(),
00083       i18nc("temperature unit symbol", "°F"),
00084       i18nc("unit description in lists", "Fahrenheit"),
00085       i18nc("unit synonyms for matching user input", "Fahrenheit;°F;F"),
00086       ki18nc("amount in units (real)", "%1 degrees Fahrenheit"),
00087       ki18ncp("amount in units (integer)", "%1 degree Fahrenheit", "%1 degrees Fahrenheit")
00088     );
00089     U(Rankine, 0.555556,
00090       i18nc("temperature unit symbol", "R"),
00091       i18nc("unit description in lists", "Rankine"),
00092       i18nc("unit synonyms for matching user input", "Rankine;°R;R;Ra"),
00093       ki18nc("amount in units (real)", "%1 Rankine"),
00094       ki18ncp("amount in units (integer)", "%1 Rankine", "%1 Rankine")
00095     );
00096     U(Delisle, new DelisleConv(),
00097       i18nc("temperature unit symbol", "°De"),
00098       i18nc("unit description in lists", "Delisle"),
00099       i18nc("unit synonyms for matching user input", "Delisle;°De;De"),
00100       ki18nc("amount in units (real)", "%1 degrees Delisle"),
00101       ki18ncp("amount in units (integer)", "%1 degree Delisle", "%1 degrees Delisle")
00102     );
00103     U(TemperatureNewton, new NewtonConv(),
00104       i18nc("temperature unit symbol", "°N"),
00105       i18nc("unit description in lists", "Newton"),
00106       i18nc("unit synonyms for matching user input", "Newton;°N;N"),
00107       ki18nc("amount in units (real)", "%1 degrees Newton"),
00108       ki18ncp("amount in units (integer)", "%1 degree Newton", "%1 degrees Newton")
00109     );
00110     U(Reaumur, new ReaumurConv(),
00111       i18nc("temperature unit symbol", "°Ré"),
00112       i18nc("unit description in lists", "Réaumur"),
00113       i18nc("unit synonyms for matching user input", "Réaumur;°Ré;Ré;Reaumur;°Re;Re"),
00114       ki18nc("amount in units (real)", "%1 degrees Réaumur"),
00115       ki18ncp("amount in units (integer)", "%1 degree Réaumur", "%1 degrees Réaumur")
00116     );
00117     U(Romer, new RomerConv(),
00118       i18nc("temperature unit symbol", "°Rø"),
00119       i18nc("unit description in lists", "Rømer"),
00120       i18nc("unit synonyms for matching user input", "Rømer;°Rø;Rø;Romer;°Ro;Ro"),
00121       ki18nc("amount in units (real)", "%1 degrees Rømer"),
00122       ki18ncp("amount in units (integer)", "%1 degree Rømer", "%1 degrees Rømer")
00123     );
00124 
00125     setMostCommonUnits(QList<int>() << Kelvin << Celsius << Fahrenheit);
00126 }

KUnitConversion

Skip menu "KUnitConversion"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.7.3
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal