Changeset View
Changeset View
Standalone View
Standalone View
src/formatstrings.cpp
Show First 20 Lines • Show All 170 Lines • ▼ Show 20 Line(s) | 169 | if (val < 0.3 && !qFuzzyIsNull(val)) { | |||
---|---|---|---|---|---|
171 | auto roundedReciprocal = round(reciprocal); | 171 | auto roundedReciprocal = round(reciprocal); | ||
172 | if (abs(reciprocal - roundedReciprocal) < 1e-3) { | 172 | if (abs(reciprocal - roundedReciprocal) < 1e-3) { | ||
173 | return i18nc("Time period given in seconds as rational number, denominator is given", "1/%1 s", roundedReciprocal); | 173 | return i18nc("Time period given in seconds as rational number, denominator is given", "1/%1 s", roundedReciprocal); | ||
174 | } | 174 | } | ||
175 | } | 175 | } | ||
176 | return i18nc("Time period given in seconds", "%1 s", QLocale().toString(value.toDouble(), 'g', 3)); | 176 | return i18nc("Time period given in seconds", "%1 s", QLocale().toString(value.toDouble(), 'g', 3)); | ||
177 | } | 177 | } | ||
178 | 178 | | |||
179 | QString FormatStrings::formatPhotoExposureBias(const QVariant& value) | ||||
180 | { | ||||
181 | QLocale locale; | ||||
182 | auto val = value.toDouble(); | ||||
183 | /* | ||||
bruns: You obviously multiply here ... | |||||
astippich: dividing by one third is multiplying by three :) | |||||
184 | * Exposure values are mostly in steps of one half or third. | ||||
185 | * Try to construct a rational number from it. | ||||
186 | * Output as double when it is not possible. | ||||
187 | */ | ||||
188 | auto sixthParts = val * 6; | ||||
189 | int roundedSixthParts = static_cast<int>(round(sixthParts)); | ||||
bruns: this is probably not working for e.g. "-1 1/3" | |||||
190 | int fractional = roundedSixthParts % 6; | ||||
191 | if (fractional == 0 || abs(sixthParts - roundedSixthParts) > 1e-3) { | ||||
192 | return i18nc("Exposure bias/compensation in exposure value (EV)", "%1 EV", locale.toString(val, 'g', 3)); | ||||
193 | } | ||||
bruns: no need for else here, you return. dito below | |||||
194 | int integral = roundedSixthParts / 6; | ||||
195 | int nominator = fractional; | ||||
196 | int denominator = 6; | ||||
197 | if (nominator % 2 == 0) { | ||||
198 | nominator = nominator / 2; | ||||
199 | denominator = denominator / 2; | ||||
200 | } else if (nominator % 3 == 0) { | ||||
201 | nominator = nominator / 3; | ||||
202 | denominator = denominator / 3; | ||||
203 | } | ||||
204 | if (integral != 0) { | ||||
205 | return i18nc("Exposure compensation given as integral with fraction, in exposure value (EV)", | ||||
206 | "%1 %2/%3 EV", locale.toString(integral), locale.toString(abs(nominator)), locale.toString(denominator)); | ||||
207 | } | ||||
208 | return i18nc("Exposure compensation given as rational, in exposure value (EV)", | ||||
209 | "%1/%2 EV", locale.toString(nominator), locale.toString(denominator)); | ||||
210 | } | ||||
211 | | ||||
179 | QString FormatStrings::formatAspectRatio(const QVariant& value) | 212 | QString FormatStrings::formatAspectRatio(const QVariant& value) | ||
180 | { | 213 | { | ||
181 | return i18nc("Aspect ratio, normalized to one", "%1:1", QLocale().toString(round(value.toDouble() * 100) / 100)); | 214 | return i18nc("Aspect ratio, normalized to one", "%1:1", QLocale().toString(round(value.toDouble() * 100) / 100)); | ||
182 | } | 215 | } | ||
183 | 216 | | |||
184 | QString FormatStrings::formatAsFNumber(const QVariant& value) | 217 | QString FormatStrings::formatAsFNumber(const QVariant& value) | ||
185 | { | 218 | { | ||
186 | return i18nc("F number for photographs", "f/%1", QLocale().toString(value.toDouble(), 'g', 2)); | 219 | return i18nc("F number for photographs", "f/%1", QLocale().toString(value.toDouble(), 'g', 2)); | ||
187 | } | 220 | } |
You obviously multiply here ...