Changeset View
Changeset View
Standalone View
Standalone View
src/formatstrings.cpp
Show All 13 Lines | |||||
14 | * You should have received a copy of the GNU Lesser General Public | 14 | * You should have received a copy of the GNU Lesser General Public | ||
15 | * License along with this library; if not, write to the Free Software | 15 | * License along with this library; if not, write to the Free Software | ||
16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
17 | * | 17 | * | ||
18 | */ | 18 | */ | ||
19 | 19 | | |||
20 | #include "formatstrings_p.h" | 20 | #include "formatstrings_p.h" | ||
21 | 21 | | |||
22 | #include <math.h> | ||||
22 | #include <QDateTime> | 23 | #include <QDateTime> | ||
23 | #include <KLocalizedString> | 24 | #include <KLocalizedString> | ||
24 | 25 | | |||
25 | using namespace KFileMetaData; | 26 | using namespace KFileMetaData; | ||
26 | 27 | | |||
28 | int significantDigits(int value) | ||||
29 | { | ||||
30 | if (value == 0) { | ||||
31 | return 0; | ||||
32 | } | ||||
33 | int before_decimal_point = static_cast<int>(log10(value > 0 ? value : -value)) % 3; | ||||
34 | return 2 - before_decimal_point; | ||||
35 | } | ||||
36 | | ||||
27 | QString FormatStrings::toStringFunction(const QVariant& value) | 37 | QString FormatStrings::toStringFunction(const QVariant& value) | ||
28 | { | 38 | { | ||
29 | return value.toString(); | 39 | return value.toString(); | ||
30 | } | 40 | } | ||
31 | 41 | | |||
32 | QString FormatStrings::joinStringListFunction(const QVariant& value) | 42 | QString FormatStrings::joinStringListFunction(const QVariant& value) | ||
33 | { | 43 | { | ||
34 | return value.toStringList().join(i18nc("Separation between multiple entries in a list", ", ")); | 44 | return value.toStringList().join(i18nc("Separation between multiple entries in a list", ", ")); | ||
Show All 18 Lines | |||||
53 | { | 63 | { | ||
54 | KFormat form; | 64 | KFormat form; | ||
55 | return form.formatDuration(value.toInt() * 1000); | 65 | return form.formatDuration(value.toInt() * 1000); | ||
56 | } | 66 | } | ||
57 | 67 | | |||
58 | QString FormatStrings::formatBitRate(const QVariant& value) | 68 | QString FormatStrings::formatBitRate(const QVariant& value) | ||
59 | { | 69 | { | ||
60 | KFormat form; | 70 | KFormat form; | ||
61 | return i18nc("@label bitrate (per second)", "%1/s", form.formatByteSize(value.toInt(), 0, KFormat::MetricBinaryDialect)); | 71 | return i18nc("@label bitrate (per second)", "%1/s", form.formatValue(value.toInt(), | ||
72 | KFormat::Unit::Bit, significantDigits(value.toInt()), KFormat::UnitPrefix::AutoAdjust, KFormat::MetricBinaryDialect)); | ||||
62 | } | 73 | } | ||
63 | 74 | | |||
64 | QString FormatStrings::formatSampleRate(const QVariant& value) | 75 | QString FormatStrings::formatSampleRate(const QVariant& value) | ||
65 | { | 76 | { | ||
66 | return i18nc("@label samplerate in kilohertz", "%1 kHz", QLocale().toString(value.toDouble() / 1000)); | 77 | KFormat form; | ||
78 | return form.formatValue(value.toInt(), KFormat::Unit::Hertz, significantDigits(value.toInt()), KFormat::UnitPrefix::AutoAdjust, KFormat::MetricBinaryDialect); | ||||
67 | } | 79 | } | ||
68 | 80 | | |||
69 | QString FormatStrings::formatOrientationValue(const QVariant& value) | 81 | QString FormatStrings::formatOrientationValue(const QVariant& value) | ||
70 | { | 82 | { | ||
71 | QString string; | 83 | QString string; | ||
72 | switch (value.toInt()) { | 84 | switch (value.toInt()) { | ||
73 | case 1: string = i18nc("Description of image orientation", "Unchanged"); break; | 85 | case 1: string = i18nc("Description of image orientation", "Unchanged"); break; | ||
74 | case 2: string = i18nc("Description of image orientation", "Horizontally flipped"); break; | 86 | case 2: string = i18nc("Description of image orientation", "Horizontally flipped"); break; | ||
Show All 12 Lines |