1 /***************************************************************************
2 copyright : (C) 2005, 2006, 2007 by Carsten Niehaus
3 email : cniehaus@kde.org
4 ***************************************************************************/
5 /***************************************************************************
7 * This program is free software; you can redistribute it and/or modify *
8 * it under the terms of the GNU General Public License as published by *
9 * the Free Software Foundation; either version 2 of the License, or *
10 * (at your option) any later version. *
12 ***************************************************************************/
14 #include "kalziumutils.h"
29 #if defined(Q_OS_SOLARIS)
33 int KalziumUtils::maxSize( const QString
& string
, const QRect
& rect
, QFont font
, QPainter
* p
, int minFontSize
, int maxFontSize
)
35 bool goodSizeFound
= false;
36 int size
= maxFontSize
;
41 font
.setPointSize( size
);
43 r
= p
->boundingRect( QRect(), Qt::AlignTop
| Qt::AlignLeft
, string
);
44 r
.translate( rect
.left(), rect
.top() );
46 if ( rect
.contains( r
) )
51 while ( !goodSizeFound
&& ( size
> minFontSize
) );
56 int KalziumUtils::StringHeight( const QString
& string
, const QFont
& font
, QPainter
* p
)
59 return p
->boundingRect( QRect(), Qt::AlignTop
| Qt::AlignLeft
, string
).height();
62 int KalziumUtils::StringWidth( const QString
& string
, const QFont
& font
, QPainter
* p
)
65 return p
->boundingRect( QRect(), Qt::AlignTop
| Qt::AlignLeft
, string
).width();
68 double KalziumUtils::strippedValue( double num
)
78 num
= num
/ power
* 10000;
81 return num
* power
/ 10000;
84 QString
KalziumUtils::prettyUnit( const Element
* el
, ChemicalDataObject::BlueObelisk kind
)
86 if (!el
) return "error";
89 double val
= 0.0; //the value to convert
93 //FIXME I just copied the code from "boilingpoint", no clue
94 //if that really works
95 case ChemicalDataObject::meltingpoint
: // a temperature
97 val
= el
->dataAsVariant( kind
).toDouble();
99 result
= i18n( "Unknown Value" );
102 val
= TempUnit::convert( val
, (int)TempUnit::Kelvin
, Prefs::temperature() );
103 result
= i18nc( "%1 is the temperature, %2 is the unit, like \"300 K\"", "%1 %2", val
, TempUnit::unitListSymbol( Prefs::temperature() ) );
107 case ChemicalDataObject::boilingpoint
:
109 val
= el
->dataAsVariant( kind
).toDouble();
111 result
= i18n( "Unknown Value" );
114 val
= TempUnit::convert( val
, (int)TempUnit::Kelvin
, Prefs::temperature() );
115 result
= i18nc( "%1 is the temperature, %2 is the unit, like \"300 K\"", "%1 %2", val
, TempUnit::unitListSymbol( Prefs::temperature() ) );
119 case ChemicalDataObject::electronegativityPauling
: // electronegativity
121 val
= el
->dataAsVariant( kind
).toDouble();
123 result
= i18n( "Value not defined" );
125 result
= i18nc("Just a number", "%1", val
);
128 case ChemicalDataObject::electronAffinity
: // an energy
130 val
= el
->dataAsVariant( kind
).toDouble();
131 result
= i18nc( "electron volt", "%1 eV", val
);
134 case ChemicalDataObject::ionization
:
136 val
= el
->dataAsVariant( kind
).toDouble();
138 result
= i18n( "Value not defined" );
141 switch ( Prefs::energies() )
145 result
= i18nc( "kilo joule per mol", "%1 kJ/mol", val
);
148 case 1: // use electronvolt
151 result
= i18nc( "electron volt", "%1 eV", val
);
158 case ChemicalDataObject::mass
: // a mass
160 val
= el
->dataAsVariant( kind
).toDouble();
162 result
= i18n( "Unknown Value" );
164 result
= i18nc( "x u (units). The atomic mass.", "%1 u", val
);
167 case ChemicalDataObject::date
: // a date
169 val
= el
->dataAsVariant( kind
).toInt();
171 result
= i18n( "This element was discovered in the year <numid>%1</numid>.", val
);
172 }else if( val
== -1 ){
173 result
= i18n( "The element has not yet been offically recoqnized by the IUPAC." );
174 } //this should now really be 0. If not there is a bug in the database
176 result
= i18n( "This element was known to ancient cultures." );
180 case ChemicalDataObject::radiusCovalent
: // a length
182 val
= el
->dataAsVariant( kind
).toDouble() * 100;
184 result
= i18n( "Unknown Value" );
186 result
= i18nc( "%1 is a length, eg: 12.3 pm", "%1 pm", val
);
189 case ChemicalDataObject::radiusVDW
:
191 val
= el
->dataAsVariant( kind
).toDouble() * 100;
193 result
= i18n( "Unknown Value" );
195 result
= i18nc( "%1 is a length, eg: 12.3 pm", "%1 pm", val
);
200 result
= el
->dataAsVariant( kind
).toString();