• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • API Reference
  • Sitemap
  • Contact Us
 

UNNAMED_READER/corelibrary

length.h

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2005-2006 by Stefan Kebekus <kebekus@kde.org>           *
00003  *   Copyright (C) 2006 by Wilfried Huss                                   *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU General Public License as published by  *
00007  *   the Free Software Foundation; either version 2 of the License, or     *
00008  *   (at your option) any later version.                                   *
00009  *                                                                         *
00010  *   This program 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         *
00013  *   GNU General Public License for more details.                          *
00014  *                                                                         *
00015  *   You should have received a copy of the GNU General Public License     *
00016  *   along with this program; if not, write to the                         *
00017  *   Free Software Foundation, Inc.,                                       *
00018  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00019  ***************************************************************************/
00020 
00021 
00022 #ifndef _length_h_
00023 #define _length_h_
00024 
00025 #include <cmath>
00026 #include <QString>
00027 
00028 #define mm_per_cm 10.0
00029 #define mm_per_m 1000.0
00030 #define mm_per_inch 25.4
00031 #define mm_per_TeXPoint (2540.0/7227.0)
00032 #define mm_per_bigPoint (25.4/72.0)
00033 #define mm_per_pica (25.4/6.0)
00034 #define mm_per_didot (25.4*0.0148)
00035 #define mm_per_cicero (25.4*0.178)
00036 #define mm_per_scaledPoint (25.4/(72.27 * 65536.0))
00037 
00038 namespace UNNAMED_READER {
00039 
00055 class Length
00056 {
00057  public:
00059   Length() {length_in_mm = 0;}
00060 
00062   void setLength_in_mm(double l)  {length_in_mm = l;}
00063 
00065   void setLength_in_cm(double l)  {length_in_mm = l*mm_per_cm;}
00066 
00068   void setLength_in_m(double l)  {length_in_mm = l*mm_per_m;}
00069 
00071   void setLength_in_inch(double l)  {length_in_mm = l*mm_per_inch;}
00072 
00074   void setLength_in_TeXPoints(double l)  {length_in_mm = l*mm_per_TeXPoint;}
00075 
00077   void setLength_in_bigPoints(double l)  {length_in_mm = l*mm_per_bigPoint;}
00078 
00080   void setLength_in_pica(double l)  {length_in_mm = l*mm_per_pica;}
00081 
00083   void setLength_in_didot(double l)  {length_in_mm = l*mm_per_didot;}
00084 
00086   void setLength_in_cicero(double l)  {length_in_mm = l*mm_per_cicero;}
00087 
00089   void setLength_in_scaledPoints(double l) {length_in_mm = l*mm_per_scaledPoint;}
00090 
00093   void setLength_in_pixel(int l, double res) { setLength_in_inch(l / res); }
00094 
00096   double getLength_in_mm() const {return length_in_mm;}
00097 
00099   double getLength_in_cm() const {return length_in_mm/mm_per_cm;}
00100 
00102   double getLength_in_m() const {return length_in_mm/mm_per_m;}
00103 
00105   double getLength_in_inch() const {return length_in_mm/mm_per_inch;}
00106 
00108   double getLength_in_TeXPoints() const {return length_in_mm/mm_per_TeXPoint;}
00109 
00111   double getLength_in_bigPoints() const {return length_in_mm/mm_per_bigPoint;}
00112 
00114   double getLength_in_pica() const {return length_in_mm/mm_per_pica;}
00115 
00117   double getLength_in_didot() const {return length_in_mm/mm_per_didot;}
00118 
00120   double getLength_in_cicero() const {return length_in_mm/mm_per_cicero;}
00121 
00123   double getLength_in_scaledPoints() const {return length_in_mm/mm_per_scaledPoint;}
00124 
00127   int getLength_in_pixel(double res) { return int(getLength_in_inch() * res); }
00128 
00130   bool isNearlyEqual(const Length &o) const {return fabs(length_in_mm-o.getLength_in_mm()) <= 2.0;}
00131 
00133   bool operator > (const Length &o) const {return (length_in_mm > o.getLength_in_mm());}
00134 
00136   bool operator < (const Length &o) const {return (length_in_mm < o.getLength_in_mm());}
00137 
00139   bool operator >= (const Length &o) const {return (length_in_mm >= o.getLength_in_mm());}
00140 
00142   bool operator <= (const Length &o) const {return (length_in_mm <= o.getLength_in_mm());}
00143 
00152   double operator / (const Length &o) const {return (length_in_mm/o.getLength_in_mm());}
00153 
00158   Length operator + (const Length &o) const {Length r; r.length_in_mm = length_in_mm + o.length_in_mm; return r; }
00159 
00164   Length operator - (const Length &o) const {Length r; r.length_in_mm = length_in_mm - o.length_in_mm; return r; }
00165 
00174   Length operator / (const double l) const {Length r; r.length_in_mm = length_in_mm/l; return r; }
00175 
00180   Length operator * (const double l) const {Length r; r.length_in_mm = length_in_mm*l; return r; }
00181 
00196   static float convertToMM(const QString &distance, bool *ok=0);
00197 
00199   operator QString() const { return QString::number(length_in_mm, 'f', 2)+"mm"; }
00200 
00201  private:
00203   double length_in_mm;
00204 };
00205 
00206 
00207 } // namespace UNNAMED_READER
00208 
00209 #undef mm_per_cm
00210 #undef mm_per_m
00211 #undef mm_per_inch
00212 #undef mm_per_TeXPoint
00213 #undef mm_per_bigPoint
00214 #undef mm_per_pica
00215 #undef mm_per_didot
00216 #undef mm_per_cicero
00217 #undef mm_per_scaledPoint
00218 
00219 #endif

UNNAMED_READER/corelibrary

Skip menu "UNNAMED_READER/corelibrary"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members

API Reference

Skip menu "API Reference"
  •   corelibrary
Generated for API Reference by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal