diff options
author | toma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2009-11-25 17:56:58 +0000 |
---|---|---|
committer | toma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2009-11-25 17:56:58 +0000 |
commit | ce599e4f9f94b4eb00c1b5edb85bce5431ab3df2 (patch) | |
tree | d3bb9f5d25a2dc09ca81adecf39621d871534297 /kalzium/src/kalziumutils.cpp | |
download | tdeedu-ce599e4f9f94b4eb00c1b5edb85bce5431ab3df2.tar.gz tdeedu-ce599e4f9f94b4eb00c1b5edb85bce5431ab3df2.zip |
Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features.
BUG:215923
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdeedu@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'kalzium/src/kalziumutils.cpp')
-rw-r--r-- | kalzium/src/kalziumutils.cpp | 88 |
1 files changed, 88 insertions, 0 deletions
diff --git a/kalzium/src/kalziumutils.cpp b/kalzium/src/kalziumutils.cpp new file mode 100644 index 00000000..2e4dd127 --- /dev/null +++ b/kalzium/src/kalziumutils.cpp @@ -0,0 +1,88 @@ +/*************************************************************************** + copyright : (C) 2005 by Carsten Niehaus + email : [email protected] + ***************************************************************************/ +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ +#include "kalziumutils.h" + +#include <kdebug.h> +#include <kglobal.h> +#include <klocale.h> +#include <qfont.h> +#include <qrect.h> +#include <qpainter.h> +#include <qglobal.h> + +#include <math.h> +#if defined(Q_OS_SOLARIS) +#include <ieeefp.h> +#endif + +int KalziumUtils::maxSize( const QString& string, const QRect& rect, QFont font, QPainter* p, int minFontSize, int maxFontSize ) +{ + bool goodSizeFound = false; + int size = maxFontSize; + QRect r; + + do + { + font.setPointSize( size ); + p->setFont( font ); + r = p->boundingRect( QRect(), Qt::AlignAuto, string ); + r.moveBy( rect.left(), rect.top() ); + + if ( rect.contains( r ) ) + goodSizeFound = true; + else + size--; + } + while ( !goodSizeFound && ( size > minFontSize ) ); + + return size; +} + +int KalziumUtils::StringHeight( const QString& string, const QFont& font, QPainter* p ) +{ + return p->boundingRect( QRect(), Qt::AlignAuto, string ).height(); +} + +int KalziumUtils::StringWidth( const QString& string, const QFont& font, QPainter* p ) +{ + return p->boundingRect( QRect(), Qt::AlignAuto, string ).width(); +} + +double KalziumUtils::strippedValue( double num ) +{ + if ( !finite( num ) ) + return num; + + double power; + power = 1e-6; + while ( power < num ) + power *= 10; + + num = num / power * 10000; + num = qRound( num ); + + return num * power / 10000; +} + +QString KalziumUtils::localizedValue( double val, int precision, unsigned long options ) +{ + QString str = KGlobal::locale()->formatNumber( val, precision ); + while( str.endsWith("0") ) + str.truncate( str.length()-1); + if ( str.endsWith( KGlobal::locale()->decimalSymbol() ) ) + { + // we do not want trailing ',' values so readd trailing 0 + str.append( '0' ); // + } + return str; +} |