Changeset View
Changeset View
Standalone View
Standalone View
src/common/KReportUnit.h
1 | /* This file is part of the KDE project | 1 | /* This file is part of the KDE project | ||
---|---|---|---|---|---|
2 | Copyright (C) 1998, 1999 Reginald Stadlbauer <reggie@kde.org> | 2 | Copyright (C) 1998, 1999 Reginald Stadlbauer <reggie@kde.org> | ||
3 | Copyright (C) 1998, 1999 Torben Weis <weis@kde.org> | 3 | Copyright (C) 1998, 1999 Torben Weis <weis@kde.org> | ||
4 | Copyright (C) 2004, Nicolas GOUTTE <goutte@kde.org> | 4 | Copyright (C) 2004, Nicolas GOUTTE <goutte@kde.org> | ||
5 | Copyright (C) 2010 Thomas Zander <zander@kde.org> | 5 | Copyright (C) 2010 Thomas Zander <zander@kde.org> | ||
6 | Copyright 2012 Friedrich W. H. Kossebau <kossebau@kde.org> | 6 | Copyright (C) 2012 Friedrich W. H. Kossebau <kossebau@kde.org> | ||
7 | Copyright (C) 2017 Jarosław Staniek <staniek@kde.org> | ||||
7 | 8 | | |||
8 | This library is free software; you can redistribute it and/or | 9 | This library is free software; you can redistribute it and/or | ||
9 | modify it under the terms of the GNU Library General Public | 10 | modify it under the terms of the GNU Library General Public | ||
10 | License as published by the Free Software Foundation; either | 11 | License as published by the Free Software Foundation; either | ||
11 | version 2 of the License, or (at your option) any later version. | 12 | version 2 of the License, or (at your option) any later version. | ||
12 | 13 | | |||
13 | This library is distributed in the hope that it will be useful, | 14 | This library is distributed in the hope that it will be useful, | ||
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
▲ Show 20 Lines • Show All 169 Lines • ▼ Show 20 Line(s) | 71 | public: | |||
184 | */ | 185 | */ | ||
185 | static inline qreal toCicero(qreal ptValue) | 186 | static inline qreal toCicero(qreal ptValue) | ||
186 | { | 187 | { | ||
187 | // "cc" values are rounded to 0.00001 inches | 188 | // "cc" values are rounded to 0.00001 inches | ||
188 | return floor(POINT_TO_CC(ptValue) * 100000.0) / 100000.0; | 189 | return floor(POINT_TO_CC(ptValue) * 100000.0) / 100000.0; | ||
189 | } | 190 | } | ||
190 | 191 | | |||
191 | /** | 192 | /** | ||
192 | * convert the given value directly from one unit to another | 193 | * convert the given value directly from one unit to another with high accuracy | ||
193 | */ | 194 | */ | ||
194 | static qreal convertFromUnitToUnit(qreal value, const KReportUnit &fromUnit, const KReportUnit &toUnit, qreal factor = 1.0); | 195 | static qreal convertFromUnitToUnit(qreal value, const KReportUnit &fromUnit, | ||
196 | const KReportUnit &toUnit); | ||||
195 | 197 | | |||
198 | /** | ||||
199 | * convert the given value directly from one unit to another with high accuracy | ||||
200 | */ | ||||
201 | static QPointF convertFromUnitToUnit(const QPointF &value, | ||||
202 | const KReportUnit &fromUnit, | ||||
203 | const KReportUnit &toUnit); | ||||
204 | | ||||
205 | /** | ||||
206 | * convert the given value directly from one unit to another with high accuracy | ||||
207 | */ | ||||
208 | static QSizeF convertFromUnitToUnit(const QSizeF &value, const KReportUnit &fromUnit, | ||||
209 | const KReportUnit &toUnit); | ||||
196 | 210 | | |||
197 | /** | 211 | /** | ||
198 | * This method is the one to use to display a value in a dialog | 212 | * This method is the one to use to display a value in a dialog | ||
199 | * \return the value @p ptValue converted to unit and rounded, ready to be displayed | 213 | * \return the value @p ptValue converted to unit and rounded, ready to be displayed | ||
200 | */ | 214 | */ | ||
201 | qreal toUserValue(qreal ptValue) const; | 215 | qreal toUserValue(qreal ptValue) const; | ||
202 | 216 | | |||
203 | /** | 217 | /** | ||
204 | * Convert the value @p ptValue to a given unit @p unit | 218 | * Convert the value @p ptValue to a given unit @p unit | ||
205 | * Unlike KReportUnit::ptToUnit the return value remains unrounded, so that it can be used in complex calculation | 219 | * Unlike KReportUnit::ptToUnit the return value remains unrounded, so that it can be used in complex calculation | ||
206 | * \return the converted value | 220 | * \return the converted value | ||
207 | */ | 221 | */ | ||
208 | static qreal ptToUnit(qreal ptValue, const KReportUnit &unit); | 222 | static qreal ptToUnit(qreal ptValue, const KReportUnit &unit); | ||
209 | 223 | | |||
210 | /// This method is the one to use to display a value in a dialog | 224 | /// This method is the one to use to display a value in a dialog | ||
211 | /// @return the value @p ptValue converted the unit and rounded, ready to be displayed | 225 | /// @return the value @p ptValue converted the unit and rounded, ready to be displayed | ||
212 | QString toUserStringValue(qreal ptValue) const; | 226 | QString toUserStringValue(qreal ptValue) const; | ||
213 | 227 | | |||
214 | /// This method is the one to use to read a value from a dialog | 228 | //! @return the value converted to points with high accuracy | ||
215 | /// @return the value converted to points for internal use | 229 | qreal convertToPoint(qreal value) const; | ||
216 | qreal fromUserValue(qreal value) const; | 230 | | ||
231 | //! @return the value converted from points to the actual unit with high accuracy | ||||
232 | qreal convertFromPoint(qreal ptValue) const; | ||||
217 | 233 | | |||
218 | /// This method is the one to use to read a value from a dialog | 234 | //! @return the value converted from points to the actual unit with high accuracy | ||
235 | QPointF convertFromPoint(const QPointF &ptValue) const; | ||||
236 | | ||||
237 | //! @return the value converted from points to the actual unit with high accuracy | ||||
238 | QSizeF convertFromPoint(const QSizeF &ptValue) const; | ||||
239 | | ||||
240 | //! Equal to convertToPoint(), use convertToPoint() instead for clarity | ||||
241 | inline qreal fromUserValue(qreal value) const { return convertToPoint(value); } | ||||
242 | | ||||
243 | /// @return the value converted to points with high accuracy | ||||
244 | QPointF convertToPoint(const QPointF &value) const; | ||||
245 | | ||||
246 | /// @return the value converted to points with high accuracy | ||||
247 | QSizeF convertToPoint(const QSizeF &value) const; | ||||
248 | | ||||
249 | /// @return the value converted to points with high accuracy | ||||
219 | /// @param value value entered by the user | 250 | /// @param value value entered by the user | ||
220 | /// @param ok if set, the pointed bool is set to true if the value could be | 251 | /// @param ok if set, the pointed bool is set to true if the value could be | ||
221 | /// converted to a qreal, and to false otherwise. | 252 | /// converted to a qreal, and to false otherwise. | ||
222 | /// @return the value converted to points for internal use | 253 | /// @return the value converted to points for internal use | ||
223 | qreal fromUserValue(const QString &value, bool *ok = 0) const; | 254 | qreal convertToPoint(const QString &value, bool *ok = 0) const; | ||
255 | | ||||
256 | //! Equal to convertToPoint(), use convertToPoint() instead for clarity | ||||
257 | inline qreal fromUserValue(const QString &value, bool *ok = 0) const { | ||||
258 | return convertToPoint(value, ok); | ||||
259 | } | ||||
224 | 260 | | |||
225 | /// Get the description string of the given unit | 261 | /// Get the description string of the given unit | ||
226 | static QString unitDescription(KReportUnit::Type type); | 262 | static QString unitDescription(KReportUnit::Type type); | ||
227 | 263 | | |||
228 | /// Get the symbol string of the unit | 264 | /// Get the symbol string of the unit | ||
229 | QString symbol() const; | 265 | QString symbol() const; | ||
230 | 266 | | |||
231 | /// Returns the list of unit types for the UI, controlled with the given @p listOptions. | 267 | /// Returns the list of unit types for the UI, controlled with the given @p listOptions. | ||
232 | static QStringList listOfUnitNameForUi(ListOptions listOptions = ListAll); | 268 | static QStringList listOfUnitNameForUi(ListOptions listOptions = ListAll); | ||
233 | 269 | | |||
234 | /// Get the index of this unit in the list of unit types for the UI, | 270 | /// Get the index of this unit in the list of unit types for the UI, | ||
235 | /// if it is controlled with the given @p listOptions. | 271 | /// if it is controlled with the given @p listOptions. | ||
236 | int indexInListForUi(ListOptions listOptions = ListAll) const; | 272 | int indexInListForUi(ListOptions listOptions = ListAll) const; | ||
237 | 273 | | |||
238 | /// Parses common %KReport and ODF values, like "10cm", "5mm" to pt. | 274 | /// Parses common %KReport and ODF values, like "10cm", "5mm" to pt. | ||
239 | /// If no unit is specified, pt is assumed. | 275 | /// If no unit is specified, pt is assumed. | ||
276 | /// @a defaultVal is in Points | ||||
240 | static qreal parseValue(const QString &value, qreal defaultVal = 0.0); | 277 | static qreal parseValue(const QString &value, qreal defaultVal = 0.0); | ||
241 | 278 | | |||
242 | /// parse an angle to its value in degrees | 279 | /// parse an angle to its value in degrees | ||
280 | /// @a defaultVal is in degrees | ||||
243 | static qreal parseAngle(const QString &value, qreal defaultVal = 0.0); | 281 | static qreal parseAngle(const QString &value, qreal defaultVal = 0.0); | ||
244 | 282 | | |||
245 | /** | 283 | /** | ||
246 | * Equal to symbol(): returns the symbol string of the unit. | 284 | * Equal to symbol(): returns the symbol string of the unit. | ||
247 | */ | 285 | */ | ||
248 | inline QString toString() const | 286 | inline QString toString() const | ||
249 | { | 287 | { | ||
250 | return symbol(); | 288 | return symbol(); | ||
Show All 15 Lines |