Changeset View
Changeset View
Standalone View
Standalone View
libs/odf/KoUnit.cpp
Show First 20 Lines • Show All 129 Lines • ▼ Show 20 Line(s) | 129 | if (typesInUi[i] == m_type) { | |||
---|---|---|---|---|---|
130 | result = i - skipped; | 130 | result = i - skipped; | ||
131 | break; | 131 | break; | ||
132 | } | 132 | } | ||
133 | } | 133 | } | ||
134 | 134 | | |||
135 | return result; | 135 | return result; | ||
136 | } | 136 | } | ||
137 | 137 | | |||
138 | qreal KoUnit::toUserValue(qreal ptValue) const | 138 | | ||
139 | | ||||
140 | qreal KoUnit::toUserValueRounded(const qreal value) const | ||||
139 | { | 141 | { | ||
142 | qreal userValue = toUserValuePrecise(value); | ||||
143 | qreal rounding = 1.0; | ||||
144 | | ||||
140 | switch (m_type) { | 145 | switch (m_type) { | ||
146 | case Pixel: | ||||
147 | return userValue; // no rounding for Pixel value | ||||
141 | case Millimeter: | 148 | case Millimeter: | ||
142 | return toMillimeter(ptValue); | 149 | rounding = MM_ROUNDING; | ||
150 | break; | ||||
143 | case Centimeter: | 151 | case Centimeter: | ||
144 | return toCentimeter(ptValue); | 152 | rounding = CM_ROUNDING; | ||
153 | break; | ||||
145 | case Decimeter: | 154 | case Decimeter: | ||
146 | return toDecimeter(ptValue); | 155 | rounding = DM_ROUNDING; | ||
156 | break; | ||||
147 | case Inch: | 157 | case Inch: | ||
148 | return toInch(ptValue); | 158 | rounding = IN_ROUNDING; | ||
159 | break; | ||||
149 | case Pica: | 160 | case Pica: | ||
150 | return toPica(ptValue); | 161 | rounding = PI_ROUNDING; | ||
162 | break; | ||||
151 | case Cicero: | 163 | case Cicero: | ||
152 | return toCicero(ptValue); | 164 | rounding = CC_ROUNDING; | ||
153 | case Pixel: | 165 | break; | ||
154 | return ptValue * m_pixelConversion; | | |||
155 | case Point: | 166 | case Point: | ||
156 | default: | 167 | default: | ||
157 | return toPoint(ptValue); | 168 | rounding = PT_ROUNDING; | ||
158 | } | 169 | } | ||
170 | | ||||
171 | | ||||
172 | return floor(userValue * rounding) / rounding; | ||||
rempt: I prefer spaces around arithmetic operators | |||||
159 | } | 173 | } | ||
160 | 174 | | |||
161 | qreal KoUnit::ptToUnit(const qreal ptValue, const KoUnit &unit) | 175 | qreal KoUnit::toUserValuePrecise(const qreal ptValue) const | ||
162 | { | 176 | { | ||
163 | switch (unit.m_type) { | 177 | switch (m_type) { | ||
164 | case Millimeter: | 178 | case Millimeter: | ||
165 | return POINT_TO_MM(ptValue); | 179 | return POINT_TO_MM(ptValue); | ||
166 | case Centimeter: | 180 | case Centimeter: | ||
167 | return POINT_TO_CM(ptValue); | 181 | return POINT_TO_CM(ptValue); | ||
168 | case Decimeter: | 182 | case Decimeter: | ||
169 | return POINT_TO_DM(ptValue); | 183 | return POINT_TO_DM(ptValue); | ||
170 | case Inch: | 184 | case Inch: | ||
171 | return POINT_TO_INCH(ptValue); | 185 | return POINT_TO_INCH(ptValue); | ||
172 | case Pica: | 186 | case Pica: | ||
173 | return POINT_TO_PI(ptValue); | 187 | return POINT_TO_PI(ptValue); | ||
174 | case Cicero: | 188 | case Cicero: | ||
175 | return POINT_TO_CC(ptValue); | 189 | return POINT_TO_CC(ptValue); | ||
176 | case Pixel: | 190 | case Pixel: | ||
177 | return ptValue * unit.m_pixelConversion; | 191 | return ptValue * m_pixelConversion; | ||
178 | case Point: | 192 | case Point: | ||
179 | default: | 193 | default: | ||
180 | return ptValue; | 194 | return ptValue; | ||
181 | } | 195 | } | ||
182 | } | 196 | } | ||
183 | 197 | | |||
198 | | ||||
199 | | ||||
200 | qreal KoUnit::toUserValue(qreal ptValue, bool rounding) const | ||||
201 | { | ||||
202 | if (rounding) { | ||||
Okay, space between if and ( and always use curly braces. The style guide is here: https://community.kde.org/Policies/Kdelibs_Coding_Style rempt: Okay, space between if and ( and always use curly braces. The style guide is here: https… | |||||
203 | return toUserValueRounded(ptValue); | ||||
204 | } | ||||
205 | else { | ||||
206 | return toUserValuePrecise(ptValue); | ||||
207 | } | ||||
208 | } | ||||
209 | | ||||
184 | QString KoUnit::toUserStringValue(qreal ptValue) const | 210 | QString KoUnit::toUserStringValue(qreal ptValue) const | ||
185 | { | 211 | { | ||
186 | return QLocale().toString(toUserValue(ptValue)); | 212 | return QLocale().toString(toUserValue(ptValue)); | ||
187 | } | 213 | } | ||
188 | 214 | | |||
189 | qreal KoUnit::fromUserValue(qreal value) const | 215 | qreal KoUnit::fromUserValue(qreal value) const | ||
190 | { | 216 | { | ||
191 | switch (m_type) { | 217 | switch (m_type) { | ||
▲ Show 20 Lines • Show All 206 Lines • Show Last 20 Lines |
I prefer spaces around arithmetic operators