Changeset View
Standalone View
src/formatstrings.cpp
Show First 20 Lines • Show All 152 Lines • ▼ Show 20 Line(s) | 151 | { | |||
---|---|---|---|---|---|
153 | return form.formatValue(value.toDouble(), KFormat::Unit::Meter, 1, KFormat::UnitPrefix::AutoAdjust, KFormat::MetricBinaryDialect); | 153 | return form.formatValue(value.toDouble(), KFormat::Unit::Meter, 1, KFormat::UnitPrefix::AutoAdjust, KFormat::MetricBinaryDialect); | ||
154 | } | 154 | } | ||
155 | 155 | | |||
156 | QString FormatStrings::formatAsFrameRate(const QVariant& value) | 156 | QString FormatStrings::formatAsFrameRate(const QVariant& value) | ||
157 | { | 157 | { | ||
158 | return i18nc("Symbol of frames per second, with space", "%1 fps", QLocale().toString(round(value.toDouble() * 100) / 100)); | 158 | return i18nc("Symbol of frames per second, with space", "%1 fps", QLocale().toString(round(value.toDouble() * 100) / 100)); | ||
159 | } | 159 | } | ||
160 | 160 | | |||
161 | QString FormatStrings::formatPhotoTime(const QVariant& value) | ||||
bruns: Rational, without 'e' | |||||
162 | { | ||||
163 | auto val = value.toDouble(); | ||||
164 | if (val < 0.3 && !qFuzzyIsNull(val)) { | ||||
165 | auto reciprocal = 1.0/val; | ||||
166 | auto roundedReciprocal = round(reciprocal); | ||||
167 | if (abs(reciprocal - roundedReciprocal) < 1e-3) { | ||||
bruns: This will give a wrong result (1/2) for 0.4 seconds. | |||||
I changed the threshold to be lower than that as a workaround. astippich: I changed the threshold to be lower than that as a workaround.
My impression was that only 1… | |||||
For a chart of typical exposure times, see https://www.borrowlenses.com/blog/shutter-speed-chart/ I can confirm for my Canon SLR there is at one more value which would give a deviating result, 0.3 seconds (!= 1/3s). 0.25 seconds is shown as 1/4s. bruns: For a chart of typical exposure times, see https://www.borrowlenses.com/blog/shutter-speed… | |||||
Thanks for the information. From what I've read, for the exposure time the right threshold is 0.3, and the value is always a rational of 1/x. astippich: Thanks for the information. From what I've read, for the exposure time the right threshold is 0. | |||||
Computation now also falls back to decimal representation if it cannot be represented with a 1/x rational astippich: Computation now also falls back to decimal representation if it cannot be represented with a… | |||||
168 | return i18nc("Time period given in seconds as rational number, denominator is given", "1/%1 s", roundedReciprocal); | ||||
169 | } | ||||
170 | } | ||||
171 | return i18nc("Time period given in seconds", "%1 s", QLocale().toString(value.toDouble(), 'g', 3)); | ||||
172 | } | ||||
173 | | ||||
161 | QString FormatStrings::formatAspectRatio(const QVariant& value) | 174 | QString FormatStrings::formatAspectRatio(const QVariant& value) | ||
162 | { | 175 | { | ||
163 | return i18nc("Aspect ratio, normalized to one", "%1:1", QLocale().toString(round(value.toDouble() * 100) / 100)); | 176 | return i18nc("Aspect ratio, normalized to one", "%1:1", QLocale().toString(round(value.toDouble() * 100) / 100)); | ||
164 | } | 177 | } | ||
165 | 178 | | |||
166 | QString FormatStrings::formatAsFNumber(const QVariant& value) | 179 | QString FormatStrings::formatAsFNumber(const QVariant& value) | ||
167 | { | 180 | { | ||
168 | return i18nc("F number for photographs", "f/%1", QLocale().toString(value.toDouble(), 'g', 2)); | 181 | return i18nc("F number for photographs", "f/%1", QLocale().toString(value.toDouble(), 'g', 2)); | ||
169 | } | 182 | } |
Rational, without 'e'