F:/KPlato/koffice/libs/kofficecore/KoUnit.h

Aller à la documentation de ce fichier.
00001 /* This file is part of the KDE project
00002    Copyright (C) 1998, 1999 Reginald Stadlbauer <reggie@kde.org>, Torben Weis <weis@kde.org>
00003    Copyright (C) 2004, Nicolas GOUTTE <goutte@kde.org>
00004 
00005    This library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Library General Public
00007    License as published by the Free Software Foundation; either
00008    version 2 of the License, or (at your option) any later version.
00009 
00010    This library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Library General Public License for more details.
00014 
00015    You should have received a copy of the GNU Library General Public License
00016    along with this library; see the file COPYING.LIB.  If not, write to
00017    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00018  * Boston, MA 02110-1301, USA.
00019 */
00020 
00021 #ifndef kounit_h
00022 #define kounit_h
00023 #include <QString>
00024 #include <QStringList>
00025 #include <math.h> // for floor
00026 #include <koffice_export.h>
00027 
00028 class KoXmlWriter;
00029 class QDomElement;
00030 
00031 // 1 inch ^= 72 pt
00032 // 1 inch ^= 25.399956 mm (-pedantic ;p)
00033 // 1 pt = 1/12 pi
00034 // 1 pt ^= 0.0077880997 cc
00035 // 1 cc = 12 dd
00036 // Note: I don't use division but multiplication with the inverse value
00037 // because it's faster ;p (Werner)
00038 #define POINT_TO_MM(px) ((px)*0.352777167)
00039 #define MM_TO_POINT(mm) ((mm)*2.83465058)
00040 #define POINT_TO_CM(px) ((px)*0.0352777167)
00041 #define CM_TO_POINT(cm) ((cm)*28.3465058)
00042 #define POINT_TO_DM(px) ((px)*0.00352777167)
00043 #define DM_TO_POINT(dm) ((dm)*283.465058)
00044 #define POINT_TO_INCH(px) ((px)*0.01388888888889)
00045 #define INCH_TO_POINT(inch) ((inch)*72.0)
00046 #define MM_TO_INCH(mm) ((mm)*0.039370147)
00047 #define INCH_TO_MM(inch) ((inch)*25.399956)
00048 #define POINT_TO_PI(px)((px)*0.083333333)
00049 #define POINT_TO_DD(px)((px)*0.006490083)
00050 #define POINT_TO_CC(px)((px)*0.077880997)
00051 #define PI_TO_POINT(pi)((pi)*12)
00052 #define DD_TO_POINT(dd)((dd)*154.08124)
00053 #define CC_TO_POINT(cc)((cc)*12.840103)
00054 
00059 class KOFFICECORE_EXPORT KoUnit
00060 {
00061 public:
00063     enum Unit {
00064         U_MM = 0,
00065         U_PT = 1,
00066         U_INCH = 2,
00067         U_CM = 3,
00068         U_DM = 4,
00069         U_PI = 5, // pica
00070         U_DD = 6, // didot
00071         U_CC = 7, // cicero
00072 // XXX update U_LASTUNIT and rulers to allow for the new U_PIXEL!
00073         U_PIXEL = 8,
00074         U_LASTUNIT = U_CC// update when adding a new unit
00075         // when adding a new unit, make sure to implement support for it in koRuler too
00076     };
00077 
00079     static double toPoint( double ptValue ) {
00080         // No conversion, only rounding (to 0.001 precision)
00081         return floor( ptValue * 1000.0 ) / 1000.0;
00082     }
00083 
00085     static double toMM( double ptValue ) {
00086         // "mm" values are rounded to 0.0001 millimeters
00087         return floor( POINT_TO_MM( ptValue ) * 10000.0 ) / 10000.0;
00088     }
00089 
00091     static double toCM( double ptValue ) {
00092         return floor( POINT_TO_CM( ptValue ) * 10000.0 ) / 10000.0;
00093     }
00094 
00096     static double toDM( double ptValue ) {
00097         return floor( POINT_TO_DM( ptValue ) * 10000.0 ) / 10000.0;
00098     }
00099 
00101     static double toInch( double ptValue ) {
00102         // "in" values are rounded to 0.00001 inches
00103         return floor( POINT_TO_INCH( ptValue ) * 100000.0 ) / 100000.0;
00104     }
00105 
00107     static double toPI( double ptValue ) {
00108         // "pi" values are rounded to 0.00001 inches
00109         return floor( POINT_TO_PI( ptValue ) * 100000.0 ) / 100000.0;
00110     }
00111 
00113     static double toDD( double ptValue ) {
00114         // "dd" values are rounded to 0.00001 inches
00115         return floor( POINT_TO_DD( ptValue ) * 100000.0 ) / 100000.0;
00116     }
00117 
00119     static double toCC( double ptValue ) {
00120         // "cc" values are rounded to 0.00001 inches
00121         return floor( POINT_TO_CC( ptValue ) * 100000.0 ) / 100000.0;
00122     }
00123 
00129     static double toUserValue( double ptValue, Unit unit );
00130 
00137     static double ptToUnit( const double ptValue, const Unit unit );
00138 
00142     static QString toUserStringValue( double ptValue, Unit unit );
00143 
00147     static double fromUserValue( double value, Unit unit );
00148 
00155     static double fromUserValue( const QString& value, Unit unit, bool* ok = 0 );
00156 
00160     static Unit unit( const QString &_unitName, bool* ok = 0 );
00162     static QString unitName( Unit _unit );
00164     static QString unitDescription( Unit _unit );
00165     static QStringList listOfUnitName();
00166 
00168     static double parseValue( QString value, double defaultVal = 0.0 );
00169     // Note: the above method doesn't take a const ref, since it modifies the arg.
00170 
00172     static void saveOasis(KoXmlWriter* settingsWriter, Unit _unit);
00173 
00174 };
00175 
00176 
00177 #endif

Généré le Wed Nov 22 23:41:04 2006 pour KPlato par  doxygen 1.5.1-p1