1 /*
2 For general Scribus (>=1.3.2) copyright and licensing information please refer
3 to the COPYING file provided with the program. Following this notice may exist
4 a copyright and/or license notice that predates the release of Scribus 1.3.2
5 for which a new license (GPL+exception) is in place.
6 */
7 /***************************************************************************
8  *   Copyright (C) 2004 by Riku Leino                                      *
9  *   tsoots@gmail.com                                                      *
10  *                                                                         *
11  *   This program is free software; you can redistribute it and/or modify  *
12  *   it under the terms of the GNU General Public License as published by  *
13  *   the Free Software Foundation; either version 2 of the License, or     *
14  *   (at your option) any later version.                                   *
15  *                                                                         *
16  *   This program is distributed in the hope that it will be useful,       *
17  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
18  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
19  *   GNU General Public License for more details.                          *
20  *                                                                         *
21  *   You should have received a copy of the GNU General Public License     *
22  *   along with this program; if not, write to the                         *
23  *   Free Software Foundation, Inc.,                                       *
24  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.             *
25  ***************************************************************************/
26 
27 #include <QString>
28 #include <QObject>
29 
30 #include "gtmeasure.h"
31 
32 double gtMeasure::m_ratio = 1.0;
33 
init(scUnit u)34 void gtMeasure::init(scUnit u)
35 {
36 	m_ratio=unitGetRatioFromIndex((int)u);
37 }
38 
convert(double value)39 double gtMeasure::convert(double value)
40 {
41 	return value / m_ratio;
42 }
43 
convert(int value)44 double gtMeasure::convert(int value)
45 {
46 	return value / m_ratio;
47 }
48 
convert2(double value)49 double gtMeasure::convert2(double value)
50 {
51 	return value * m_ratio;
52 }
53 
convert2(int value)54 double gtMeasure::convert2(int value)
55 {
56 	return value * m_ratio;
57 }
58 
parse(const QString & value)59 double gtMeasure::parse(const QString& value)
60 {
61 	init(unitIndexFromString(value));
62 	return unitValueFromString(value);
63 }
64 
convert(double value,scUnit from,scUnit to)65 double gtMeasure::convert(double value, scUnit from, scUnit to)
66 {
67 	return d2d(value, from, to);
68 }
69 
convert(int value,scUnit from,scUnit to)70 double gtMeasure::convert(int value, scUnit from, scUnit to)
71 {
72 	return i2d(value, from, to);
73 }
74 
d2d(double value,scUnit from,scUnit to)75 double gtMeasure::d2d(double value, scUnit from, scUnit to)
76 {
77 	init(from);
78 	double tmp = convert(value);
79 	init(to);
80 	return convert2(tmp);
81 }
82 
83 
i2d(int value,scUnit from,scUnit to)84 double gtMeasure::i2d(int value, scUnit from, scUnit to)
85 {
86 	init(from);
87 	double tmp = convert(value);
88 	init(to);
89 	return convert2(tmp);
90 }
91 
qs2d(const QString & value,scUnit to)92 double gtMeasure::qs2d(const QString& value, scUnit to)
93 {
94 	double tmp = convert(parse(value));
95 	init(to);
96 	return convert2(tmp);
97 }
98 
99 
100