Back to index

scribus-ng  1.3.4.dfsg+svn20071115
gtmeasure.cpp
Go to the documentation of this file.
00001 /*
00002 For general Scribus (>=1.3.2) copyright and licensing information please refer
00003 to the COPYING file provided with the program. Following this notice may exist
00004 a copyright and/or license notice that predates the release of Scribus 1.3.2
00005 for which a new license (GPL+exception) is in place.
00006 */
00007 /***************************************************************************
00008  *   Copyright (C) 2004 by Riku Leino                                      *
00009  *   tsoots@gmail.com                                                      *
00010  *                                                                         *
00011  *   This program is free software; you can redistribute it and/or modify  *
00012  *   it under the terms of the GNU General Public License as published by  *
00013  *   the Free Software Foundation; either version 2 of the License, or     *
00014  *   (at your option) any later version.                                   *
00015  *                                                                         *
00016  *   This program is distributed in the hope that it will be useful,       *
00017  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00018  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00019  *   GNU General Public License for more details.                          *
00020  *                                                                         *
00021  *   You should have received a copy of the GNU General Public License     *
00022  *   along with this program; if not, write to the                         *
00023  *   Free Software Foundation, Inc.,                                       *
00024  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00025  ***************************************************************************/
00026 
00027 #include <qstring.h>
00028 #include <qobject.h>
00029 
00030 #include "gtmeasure.h"
00031 
00032 double gtMeasure::ratio = 1.0;
00033 
00034 void gtMeasure::init(scUnit u)
00035 {
00036        ratio=unitGetRatioFromIndex((int)u);
00037 }
00038 
00039 double gtMeasure::convert(double value)
00040 {
00041        return value / ratio;
00042 }
00043 
00044 double gtMeasure::convert(int value)
00045 {
00046        return value / ratio;
00047 }
00048 
00049 double gtMeasure::convert2(double value)
00050 {
00051        return value * ratio;
00052 }
00053 
00054 double gtMeasure::convert2(int value)
00055 {
00056        return value * ratio;
00057 }
00058 
00059 double gtMeasure::parse(const QString& value)
00060 {
00061        init(unitIndexFromString(value));
00062        return unitValueFromString(value);
00063 }
00064 
00065 double gtMeasure::convert(double value, scUnit from, scUnit to)
00066 {
00067        return d2d(value, from, to);
00068 }
00069 
00070 double gtMeasure::convert(int value, scUnit from, scUnit to)
00071 {
00072        return i2d(value, from, to);
00073 }
00074 
00075 double gtMeasure::d2d(double value, scUnit from, scUnit to)
00076 {
00077        init(from);
00078        double tmp = convert(value);
00079        init(to);
00080        return convert2(tmp);
00081 }
00082 
00083 
00084 double gtMeasure::i2d(int value, scUnit from, scUnit to)
00085 {
00086        init(from);
00087        double tmp = convert(value);
00088        init(to);
00089        return convert2(tmp);
00090 }
00091 
00092 double gtMeasure::qs2d(const QString& value, scUnit to)
00093 {
00094        double tmp = convert(parse(value));
00095        init(to);
00096        return convert2(tmp);
00097 }
00098 
00099