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 | Copyright (C) 2017 Jarosław Staniek <staniek@kde.org> | ||
8 | 8 | | |||
9 | This library is free software; you can redistribute it and/or | 9 | This library is free software; you can redistribute it and/or | ||
10 | modify it under the terms of the GNU Library General Public | 10 | modify it under the terms of the GNU Library General Public | ||
11 | License as published by the Free Software Foundation; either | 11 | License as published by the Free Software Foundation; either | ||
12 | 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. | ||
13 | 13 | | |||
14 | 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, | ||
▲ Show 20 Lines • Show All 197 Lines • ▼ Show 20 Line(s) | 70 | public: | |||
212 | */ | 212 | */ | ||
213 | static inline qreal toCicero(qreal ptValue) | 213 | static inline qreal toCicero(qreal ptValue) | ||
214 | { | 214 | { | ||
215 | // "cc" values are rounded to 0.00001 inches | 215 | // "cc" values are rounded to 0.00001 inches | ||
216 | return floor(POINT_TO_CC(ptValue) * 100000.0) / 100000.0; | 216 | return floor(POINT_TO_CC(ptValue) * 100000.0) / 100000.0; | ||
217 | } | 217 | } | ||
218 | 218 | | |||
219 | /** | 219 | /** | ||
220 | * convert the given value directly from one unit to another | 220 | * convert the given value directly from one unit to another with high accuracy | ||
221 | */ | 221 | */ | ||
222 | static qreal convertFromUnitToUnit(qreal value, const KReportUnit &fromUnit, const KReportUnit &toUnit, qreal factor = 1.0); | 222 | static qreal convertFromUnitToUnit(qreal value, const KReportUnit &fromUnit, | ||
223 | const KReportUnit &toUnit, qreal factor = 1.0); | ||||
224 | | ||||
225 | /** | ||||
226 | * convert the given value directly from one unit to another with high accuracy | ||||
227 | */ | ||||
228 | static QPointF convertFromUnitToUnit(const QPointF &value, | ||||
229 | const KReportUnit &fromUnit, | ||||
230 | const KReportUnit &toUnit); | ||||
231 | | ||||
232 | /** | ||||
233 | * convert the given value directly from one unit to another with high accuracy | ||||
234 | */ | ||||
235 | static QSizeF convertFromUnitToUnit(const QSizeF &value, const KReportUnit &fromUnit, | ||||
236 | const KReportUnit &toUnit); | ||||
223 | 237 | | |||
224 | /** | 238 | /** | ||
225 | * This method is the one to use to display a value in a dialog | 239 | * This method is the one to use to display a value in a dialog | ||
226 | * \return the value @p ptValue converted to unit and rounded, ready to be displayed | 240 | * \return the value @p ptValue converted to unit and rounded, ready to be displayed | ||
227 | */ | 241 | */ | ||
228 | qreal toUserValue(qreal ptValue) const; | 242 | qreal toUserValue(qreal ptValue) const; | ||
229 | 243 | | |||
230 | /** | 244 | /** | ||
231 | * Convert the value @p ptValue to a given unit @p unit | 245 | * Convert the value @p ptValue to a given unit @p unit | ||
232 | * Unlike KReportUnit::ptToUnit the return value remains unrounded, so that it can be used in complex calculation | 246 | * Unlike KReportUnit::ptToUnit the return value remains unrounded, so that it can be used in complex calculation | ||
233 | * \return the converted value | 247 | * \return the converted value | ||
234 | */ | 248 | */ | ||
235 | static qreal ptToUnit(qreal ptValue, const KReportUnit &unit); | 249 | static qreal ptToUnit(qreal ptValue, const KReportUnit &unit); | ||
236 | 250 | | |||
237 | /// This method is the one to use to display a value in a dialog | 251 | /// This method is the one to use to display a value in a dialog | ||
238 | /// @return the value @p ptValue converted the unit and rounded, ready to be displayed | 252 | /// @return the value @p ptValue converted the unit and rounded, ready to be displayed | ||
239 | QString toUserStringValue(qreal ptValue) const; | 253 | QString toUserStringValue(qreal ptValue) const; | ||
240 | 254 | | |||
241 | /// This method is the one to use to read a value from a dialog | 255 | //! @return the value converted to points with high accuracy | ||
242 | /// @return the value converted to points for internal use | 256 | qreal convertToPoint(qreal value) const; | ||
243 | qreal fromUserValue(qreal value) const; | 257 | | ||
258 | //! @return the value converted from points to the actual unit with high accuracy | ||||
259 | qreal convertFromPoint(qreal ptValue) const; | ||||
244 | 260 | | |||
245 | /// This method is the one to use to read a value from a dialog | 261 | //! @return the value converted from points to the actual unit with high accuracy | ||
262 | QPointF convertFromPoint(const QPointF &ptValue) const; | ||||
263 | | ||||
264 | //! @return the value converted from points to the actual unit with high accuracy | ||||
265 | QSizeF convertFromPoint(const QSizeF &ptValue) const; | ||||
266 | | ||||
267 | //! Equal to convertToPoint(), use convertToPoint() instead for clarity | ||||
268 | inline qreal fromUserValue(qreal value) const { return convertToPoint(value); } | ||||
269 | | ||||
270 | /// @return the value converted to points with high accuracy | ||||
271 | QPointF convertToPoint(const QPointF &value) const; | ||||
272 | | ||||
273 | /// @return the value converted to points with high accuracy | ||||
274 | QSizeF convertToPoint(const QSizeF &value) const; | ||||
275 | | ||||
276 | /// @return the value converted to points with high accuracy | ||||
246 | /// @param value value entered by the user | 277 | /// @param value value entered by the user | ||
247 | /// @param ok if set, the pointed bool is set to true if the value could be | 278 | /// @param ok if set, the pointed bool is set to true if the value could be | ||
248 | /// converted to a qreal, and to false otherwise. | 279 | /// converted to a qreal, and to false otherwise. | ||
249 | /// @return the value converted to points for internal use | 280 | /// @return the value converted to points for internal use | ||
250 | qreal fromUserValue(const QString &value, bool *ok = nullptr) const; | 281 | qreal convertToPoint(const QString &value, bool *ok = 0) const; | ||
282 | | ||||
283 | //! Equal to convertToPoint(), use convertToPoint() instead for clarity | ||||
284 | inline qreal fromUserValue(const QString &value, bool *ok = 0) const { | ||||
285 | return convertToPoint(value, ok); | ||||
286 | } | ||||
251 | 287 | | |||
252 | //! Returns the symbol string of given unit type | 288 | //! Returns the symbol string of given unit type | ||
253 | //! Symbol for Invalid type is empty string. | 289 | //! Symbol for Invalid type is empty string. | ||
254 | static QString symbol(KReportUnit::Type type); | 290 | static QString symbol(KReportUnit::Type type); | ||
255 | 291 | | |||
256 | //! Returns the symbol string of the unit | 292 | //! Returns the symbol string of the unit | ||
257 | //! Symbol for Invalid type is empty string. | 293 | //! Symbol for Invalid type is empty string. | ||
258 | QString symbol() const; | 294 | QString symbol() const; | ||
Show All 20 Lines | |||||
279 | * @brief Returns the list of unit symbols for the given types | 315 | * @brief Returns the list of unit symbols for the given types | ||
280 | * | 316 | * | ||
281 | * @since 3.1 | 317 | * @since 3.1 | ||
282 | */ | 318 | */ | ||
283 | static QStringList symbols(const QList<Type> &types); | 319 | static QStringList symbols(const QList<Type> &types); | ||
284 | 320 | | |||
285 | /// Parses common %KReport and ODF values, like "10cm", "5mm" to pt. | 321 | /// Parses common %KReport and ODF values, like "10cm", "5mm" to pt. | ||
286 | /// If no unit is specified, pt is assumed. | 322 | /// If no unit is specified, pt is assumed. | ||
323 | /// @a defaultVal is in Points | ||||
287 | static qreal parseValue(const QString &value, qreal defaultVal = 0.0); | 324 | static qreal parseValue(const QString &value, qreal defaultVal = 0.0); | ||
288 | 325 | | |||
289 | /// parse an angle to its value in degrees | 326 | /// parse an angle to its value in degrees | ||
327 | /// @a defaultVal is in degrees | ||||
290 | static qreal parseAngle(const QString &value, qreal defaultVal = 0.0); | 328 | static qreal parseAngle(const QString &value, qreal defaultVal = 0.0); | ||
291 | 329 | | |||
292 | private: | 330 | private: | ||
293 | class Private; | 331 | class Private; | ||
294 | Private * const d; | 332 | Private * const d; | ||
295 | }; | 333 | }; | ||
296 | 334 | | |||
297 | #ifndef QT_NO_DEBUG_STREAM | 335 | #ifndef QT_NO_DEBUG_STREAM | ||
298 | KREPORT_EXPORT QDebug operator<<(QDebug, const KReportUnit &); | 336 | KREPORT_EXPORT QDebug operator<<(QDebug, const KReportUnit &); | ||
299 | #endif | 337 | #endif | ||
300 | 338 | | |||
301 | Q_DECLARE_METATYPE(KReportUnit) | 339 | Q_DECLARE_METATYPE(KReportUnit) | ||
302 | 340 | | |||
303 | #endif | 341 | #endif |