lib
KoUnit.h00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef kounit_h
00022 #define kounit_h
00023 #include <qstring.h>
00024 #include <qstringlist.h>
00025 #include <math.h>
00026 #include <koffice_export.h>
00027
00028 class KoXmlWriter;
00029 class QDomElement;
00030
00031
00032
00033
00034
00035
00036
00037
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,
00070 U_DD = 6,
00071 U_CC = 7,
00072 U_LASTUNIT = U_CC
00073
00074 };
00075
00077 static double toPoint( double ptValue ) {
00078
00079 return floor( ptValue * 1000.0 ) / 1000.0;
00080 }
00081
00083 static double toMM( double ptValue ) {
00084
00085 return floor( POINT_TO_MM( ptValue ) * 10000.0 ) / 10000.0;
00086 }
00087
00089 static double toCM( double ptValue ) {
00090 return floor( POINT_TO_CM( ptValue ) * 10000.0 ) / 10000.0;
00091 }
00092
00094 static double toDM( double ptValue ) {
00095 return floor( POINT_TO_DM( ptValue ) * 10000.0 ) / 10000.0;
00096 }
00097
00099 static double toInch( double ptValue ) {
00100
00101 return floor( POINT_TO_INCH( ptValue ) * 100000.0 ) / 100000.0;
00102 }
00103
00105 static double toPI( double ptValue ) {
00106
00107 return floor( POINT_TO_PI( ptValue ) * 100000.0 ) / 100000.0;
00108 }
00109
00111 static double toDD( double ptValue ) {
00112
00113 return floor( POINT_TO_DD( ptValue ) * 100000.0 ) / 100000.0;
00114 }
00115
00117 static double toCC( double ptValue ) {
00118
00119 return floor( POINT_TO_CC( ptValue ) * 100000.0 ) / 100000.0;
00120 }
00121
00127 static double toUserValue( double ptValue, Unit unit );
00128
00135 static double ptToUnit( const double ptValue, const Unit unit );
00136
00140 static QString toUserStringValue( double ptValue, Unit unit );
00141
00145 static double fromUserValue( double value, Unit unit );
00146
00153 static double fromUserValue( const QString& value, Unit unit, bool* ok = 0 );
00154
00158 static Unit unit( const QString &_unitName, bool* ok = 0 );
00160 static QString unitName( Unit _unit );
00162 static QString unitDescription( Unit _unit );
00163 static QStringList listOfUnitName();
00164
00166 static double parseValue( QString value, double defaultVal = 0.0 );
00167
00168
00170 static void saveOasis(KoXmlWriter* settingsWriter, Unit _unit);
00171
00172 };
00173
00174
00175 #endif
|