KUnitConversion

angle.cpp
1/*
2 * SPDX-FileCopyrightText: 2010 Petri Damstén <damu@iki.fi>
3 * SPDX-FileCopyrightText: 2014 John Layt <jlayt@kde.org>
4 *
5 * SPDX-License-Identifier: LGPL-2.0-or-later
6 */
7
8#include "angle_p.h"
9#include "unit_p.h"
10
11#include <KLocalizedString>
12
13#include <math.h>
14
15namespace KUnitConversion
16{
17class RadiansUnitPrivate : public UnitPrivate
18{
19public:
20 RadiansUnitPrivate(CategoryId categoryId,
21 UnitId id,
22 qreal multiplier,
23 const QString &symbol,
24 const QString &description,
25 const QString &matchString,
26 const KLocalizedString &symbolString,
27 const KLocalizedString &realString,
28 const KLocalizedString &integerString)
29 : UnitPrivate(categoryId, id, multiplier, symbol, description, matchString, symbolString, realString, integerString)
30 {
31 }
32
33 qreal toDefault(qreal value) const override
34 {
35 return (value / (2 * M_PI)) * 360.0;
36 }
37 qreal fromDefault(qreal value) const override
38 {
39 return (value / 360.0) * (2 * M_PI);
40 }
41};
42
43UnitCategory Angle::makeCategory()
44{
45 auto c = UnitCategoryPrivate::makeCategory(AngleCategory, i18n("Angle"), i18n("Angle"));
46 auto d = UnitCategoryPrivate::get(c);
47 KLocalizedString symbolString = ki18nc("%1 value, %2 unit symbol (angle)", "%1 %2");
48
49 d->addDefaultUnit(UnitPrivate::makeUnit(AngleCategory,
50 Degree,
51 1,
52 i18nc("angle unit symbol", "°"),
53 i18nc("unit description in lists", "degrees"),
54 i18nc("unit synonyms for matching user input", "deg;degree;degrees;°"),
55 symbolString,
56 ki18nc("amount in units (real)", "%1 degrees"),
57 ki18ncp("amount in units (integer)", "%1 degree", "%1 degrees")));
58
59 d->addCommonUnit(UnitPrivate::makeUnit(new RadiansUnitPrivate(AngleCategory,
60 Radian,
61 1.0,
62 i18nc("angle unit symbol", "rad"),
63 i18nc("unit description in lists", "radians"),
64 i18nc("unit synonyms for matching user input", "rad;radian;radians"),
65 symbolString,
66 ki18nc("amount in units (real)", "%1 radians"),
67 ki18ncp("amount in units (integer)", "%1 radian", "%1 radians"))));
68
69 d->addUnit(UnitPrivate::makeUnit(AngleCategory,
70 Gradian,
71 360.0 / 400.0,
72 i18nc("angle unit symbol", "grad"),
73 i18nc("unit description in lists", "gradians"),
74 i18nc("unit synonyms for matching user input", "grad;gradian;gradians;grade;gon"),
75 symbolString,
76 ki18nc("amount in units (real)", "%1 gradians"),
77 ki18ncp("amount in units (integer)", "%1 gradian", "%1 gradians")));
78
79 d->addCommonUnit(UnitPrivate::makeUnit(AngleCategory,
80 ArcMinute,
81 1.0 / 60.0,
82 i18nc("angle unit symbol", "'"),
83 i18nc("unit description in lists", "arc minutes"),
84 i18nc("unit synonyms for matching user input", "minute of arc;MOA;arcminute;minute;'"),
85 symbolString,
86 ki18nc("amount in units (real)", "%1 arc minutes"),
87 ki18ncp("amount in units (integer)", "%1 arc minute", "%1 arc minutes")));
88
89 d->addCommonUnit(UnitPrivate::makeUnit(AngleCategory,
90 ArcSecond,
91 1.0 / 3600.0,
92 i18nc("angle unit symbol", "\""),
93 i18nc("unit description in lists", "arc seconds"),
94 i18nc("unit synonyms for matching user input", "second of arc;arcsecond;second;\""),
95 symbolString,
96 ki18nc("amount in units (real)", "%1 arc seconds"),
97 ki18ncp("amount in units (integer)", "%1 arc second", "%1 arc seconds")));
98
99 return c;
100}
101
102} // KUnitConversion namespace
QString i18nc(const char *context, const char *text, const TYPE &arg...)
KLocalizedString KI18N_EXPORT ki18ncp(const char *context, const char *singular, const char *plural)
KLocalizedString KI18N_EXPORT ki18nc(const char *context, const char *text)
QString i18n(const char *text, const TYPE &arg...)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 17:06:12 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.