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 "fuel_efficiency.h"
21#include "converter.h"
22#include <klocale.h>
23
24using namespace KUnitConversion;
25
26class kmpl : public Complex
27{
28 double toDefault(double value) const { return 100.0 / value; };
29 double fromDefault(double value) const { return 100.0 / value; };
30};
31
32class mpg : public Complex
33{
34 double toDefault(double value) const { return 235.2 / value; };
35 double fromDefault(double value) const { return 235.2 / value; };
36};
37
38class mpgi : public Complex
39{
40 double toDefault(double value) const { return 282.5 / value; };
41 double fromDefault(double value) const { return 282.5 / value; };
42};
43
44FuelEfficiency::FuelEfficiency() : UnitCategory(FuelEfficiencyCategory)
45{
46 setName(i18n("Fuel Efficiency"));
47 setSymbolStringFormat(ki18nc("%1 value, %2 unit symbol (fuel efficiency)", "%1 %2"));
48
49 setDefaultUnit(UP(LitersPer100Kilometers, 1,
50 i18nc("fuelefficiency unit symbol", "l/100 km"),
51 i18nc("unit description in lists", "liters per 100 kilometers"),
52 i18nc("unit synonyms for matching user input", "liters per 100 kilometers;liters per 100 kilometers;l/100 km;L/100 km"),
53 ki18nc("amount in units (real)", "%1 liters per 100 kilometers"),
54 ki18ncp("amount in units (integer)", "%1 liters per 100 kilometers", "%1 liters per 100 kilometers")
55 ));
56 U(MilePerUsGallon, new mpg(),
57 i18nc("fuelefficiency unit symbol", "mpg"),
58 i18nc("unit description in lists", "miles per US gallon"),
59 i18nc("unit synonyms for matching user input", "mile per US gallon;miles per US gallon;mpg"),
60 ki18nc("amount in units (real)", "%1 miles per US gallon"),
61 ki18ncp("amount in units (integer)", "%1 mile per US gallon", "%1 miles per US gallon")
62 );
63 U(MilePerImperialGallon, new mpgi(),
64 i18nc("fuelefficiency unit symbol", "mpg (imperial)"),
65 i18nc("unit description in lists", "miles per imperial gallon"),
66 i18nc("unit synonyms for matching user input", "mile per imperial gallon;miles per imperial gallon;mpg (imperial)"),
67 ki18nc("amount in units (real)", "%1 miles per imperial gallon"),
68 ki18ncp("amount in units (integer)", "%1 mile per imperial gallon", "%1 miles per imperial gallon")
69 );
70 U(KilometrePerLitre, new kmpl(),
71 i18nc("fuelefficiency unit symbol", "kmpl"),
72 i18nc("unit description in lists", "kilometers per liter"),
73 i18nc("unit synonyms for matching user input", "kilometer per liter;kilometers per liter;kmpl;km/l"),
74 ki18nc("amount in units (real)", "%1 kilometers per liter"),
75 ki18ncp("amount in units (integer)", "%1 kilometer per liter", "%1 kilometers per liter")
76 );
77
78 setMostCommonUnits(QList<int>() <<
79 LitersPer100Kilometers << MilePerUsGallon << MilePerImperialGallon);
80}
81