00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
#ifndef kounit_h
00021
#define kounit_h
00022
#include <qstring.h>
00023
#include <qstringlist.h>
00024
00025
00026
00027
00028
00029
00030
00031
00032
#define POINT_TO_MM(px) ((px)*0.352777167)
00033
#define MM_TO_POINT(mm) ((mm)*2.83465058)
00034
#define POINT_TO_CM(px) ((px)*0.0352777167)
00035
#define CM_TO_POINT(cm) ((cm)*28.3465058)
00036
#define POINT_TO_DM(px) ((px)*0.00352777167)
00037
#define DM_TO_POINT(dm) ((dm)*283.465058)
00038
#define POINT_TO_INCH(px) ((px)*0.01388888888889)
00039
#define INCH_TO_POINT(inch) ((inch)*72.0)
00040
#define MM_TO_INCH(mm) ((mm)*0.039370147)
00041
#define INCH_TO_MM(inch) ((inch)*25.399956)
00042
#define POINT_TO_PI(px)((px)*0.083333333)
00043
#define POINT_TO_DD(px)((px)*0.006490083)
00044
#define POINT_TO_CC(px)((px)*0.077880997)
00045
#define PI_TO_POINT(pi)((pi)*12)
00046
#define DD_TO_POINT(dd)((dd)*154.08124)
00047
#define CC_TO_POINT(cc)((cc)*12.840103)
00048
00053 class KoUnit
00054 {
00055
public:
00056
enum Unit {
00057 U_MM = 0,
00058 U_PT = 1,
00059 U_INCH = 2,
00060 U_CM = 3,
00061 U_DM = 4,
00062 U_PI = 5,
00063 U_DD = 6,
00064 U_CC = 7,
00065 U_LASTUNIT = U_CC
00066
00067 };
00068
00070 static double toPoint(
double ptValue ) {
00071
00072
return qRound( ptValue * 1000.0 ) / 1000.0;
00073 }
00074
00076 static double toMM(
double ptValue ) {
00077
00078
return qRound( POINT_TO_MM( ptValue ) * 10000.0 ) / 10000.0;
00079 }
00080
00082 static double toCM(
double ptValue ) {
00083
return qRound( POINT_TO_CM( ptValue ) * 10000.0 ) / 10000.0;
00084 }
00085
00087 static double toDM(
double ptValue ) {
00088
return qRound( POINT_TO_DM( ptValue ) * 10000.0 ) / 10000.0;
00089 }
00090
00092 static double toInch(
double ptValue ) {
00093
00094
return qRound( POINT_TO_INCH( ptValue ) * 100000.0 ) / 100000.0;
00095 }
00096
00098 static double toPI(
double ptValue ) {
00099
00100
return qRound( POINT_TO_PI( ptValue ) * 100000.0 ) / 100000.0;
00101 }
00102
00104 static double toDD(
double ptValue ) {
00105
00106
return qRound( POINT_TO_DD( ptValue ) * 100000.0 ) / 100000.0;
00107 }
00108
00110 static double toCC(
double ptValue ) {
00111
00112
return qRound( POINT_TO_CC( ptValue ) * 100000.0 ) / 100000.0;
00113 }
00114
00117
static double ptToUnit(
double ptValue, Unit unit );
00118
00121
static QString userValue(
double ptValue, Unit unit );
00122
00125
static double ptFromUnit(
double value, Unit unit );
00126
00129
static double fromUserValue(
const QString& value, Unit unit );
00130
00132 static Unit
unit(
const QString &_unitName ) {
00133
if ( _unitName == QString::fromLatin1(
"mm" ) )
return U_MM;
00134
if ( _unitName == QString::fromLatin1(
"cm" ) )
return U_CM;
00135
if ( _unitName == QString::fromLatin1(
"dm" ) )
return U_DM;
00136
if ( _unitName == QString::fromLatin1(
"in" )
00137 || _unitName == QString::fromLatin1(
"inch") )
return U_INCH;
00138
if ( _unitName == QString::fromLatin1(
"pi" ) )
return U_PI;
00139
if ( _unitName == QString::fromLatin1(
"dd" ) )
return U_DD;
00140
if ( _unitName == QString::fromLatin1(
"cc" ) )
return U_CC;
00141
return U_PT;
00142 }
00144 static QString unitName( Unit _unit ) {
00145
if ( _unit == U_MM )
return QString::fromLatin1(
"mm" );
00146
if ( _unit == U_CM )
return QString::fromLatin1(
"cm" );
00147
if ( _unit == U_DM )
return QString::fromLatin1(
"dm" );
00148
if ( _unit == U_INCH )
return QString::fromLatin1(
"in" );
00149
if ( _unit == U_PI )
return QString::fromLatin1(
"pi" );
00150
if ( _unit == U_DD )
return QString::fromLatin1(
"dd" );
00151
if ( _unit == U_CC )
return QString::fromLatin1(
"cc" );
00152
return QString::fromLatin1(
"pt" );
00153 }
00155
static QString unitDescription( Unit _unit );
00156
static QStringList listOfUnitName();
00157
00159
static double parseValue(
QString value,
double defaultVal = 0.0 );
00160
00161 };
00162
00163
00164
#endif