From kde-commits Tue Aug 02 13:13:53 2005 From: Carsten Niehaus Date: Tue, 02 Aug 2005 13:13:53 +0000 To: kde-commits Subject: branches/KDE/3.5/kdeedu/kalzium/src Message-Id: <1122988433.291641.18355.nullmailer () svn ! kde ! org> X-MARC-Message: https://marc.info/?l=kde-commits&m=112299341213460 SVN commit 442361 by cniehaus: * Moving strippedValue(double) to the new class KalziumUtils. I want that class to handle all operations which are not really bound to a class * Remove some kdDebug() * Now the table can at maximum use a fontsize of 20. That is still pretty big, until yesterday the used size was 18. Kalzium is now calculation the optimum size of every font with KalziumUtils::maxSize() M +2 -25 element.cpp M +0 -6 element.h M +1 -1 exporter.cpp M +5 -4 exporter.h M +20 -4 kalziumutils.cpp M +5 -0 kalziumutils.h M +2 -1 molcalcwidget.cpp M +2 -1 periodictableview.cpp --- branches/KDE/3.5/kdeedu/kalzium/src/element.cpp #442360:442361 @@ -36,8 +36,6 @@ #include #include -#include - Element::Element() { m_radioactive = false; @@ -60,30 +58,10 @@ return orbits; } - -double Element::strippedValue( double num ) -{ - if ( !finite( num ) ) - return num; - - double power; - power = 1e-6; - while ( power < num ) - power *= 10; - - num = num / power * 10000; - num = round( num ); - - return num * power / 10000; -} - - Element::~Element() { } - - double Element::meanmass() { return m_mass/m_number; @@ -264,7 +242,7 @@ //top left p->setPen( Qt::black ); - text = QString::number( strippedValue( mass( ) ) ); + text = QString::number( KalziumUtils::strippedValue( mass( ) ) ); p->drawText( X,Y ,ELEMENTSIZE,h_small,Qt::AlignCenter, text ); text = QString::number( number() ); @@ -365,7 +343,6 @@ QString text; QFont symbol_font = p->font(); - bool goodSizeFound = false; const int max = ELEMENTSIZE-10; const QRect rect = QRect( X,Y,ELEMENTSIZE-2,max ); @@ -410,7 +387,7 @@ text = i18n( "Crystalsystem cubic close packed", "ccp" ); } else - text = QString::number( strippedValue( mass( ) ) ); + text = QString::number( KalziumUtils::strippedValue( mass( ) ) ); p->drawText( X+2,Y ,ELEMENTSIZE-4 ,h_small,Qt::AlignCenter, text ); } --- branches/KDE/3.5/kdeedu/kalzium/src/element.h #442360:442361 @@ -375,12 +375,6 @@ IONICRADIUS }; - /** - * calculate the 4-digit value of the value @p w - * @return the 4-digit value - */ - static double strippedValue( double w ); - QPoint pos() const; QPoint coords() const; --- branches/KDE/3.5/kdeedu/kalzium/src/exporter.cpp #442360:442361 @@ -39,7 +39,7 @@ { } -bool Exporter::saveAsImage( const QPixmap* pixmap, QString fileName, int x, int y, int width, int height ) +bool Exporter::saveAsImage( const QPixmap* pixmap, const QString& fileName, int x, int y, int width, int height ) { if ( x != 0 || y != 0 || width != 0 || height != 0 ) { --- branches/KDE/3.5/kdeedu/kalzium/src/exporter.h #442360:442361 @@ -5,8 +5,8 @@ The header for the exporter class of Kalzium ------------------- - begin : June 2003 - copyright : (C) 2003, 2004, 2005 by Martin Pfeiffer + begin : June 2005 + copyright : (C) 2005 by Martin Pfeiffer email : hubipete@gmx.net ***************************************************************************/ @@ -23,7 +23,8 @@ class QString; /** - * Small class that provides some exporting functions. + * Small class that provides some exporting functions for graphics. + * @class Martin Pfeiffer */ class Exporter { @@ -38,7 +39,7 @@ * exported. * @return whether the image was saved successfully */ - bool saveAsImage( const QPixmap* pixmap, QString fileName, int x = 0, int y = 0, int width = 0, int height = 0 ); + bool saveAsImage( const QPixmap* pixmap, const QString& fileName, int x = 0, int y = 0, int width = 0, int height = 0 ); /** * Which image type can we export to? --- branches/KDE/3.5/kdeedu/kalzium/src/kalziumutils.cpp #442360:442361 @@ -5,21 +5,21 @@ #include #include +#include + int KalziumUtils::maxSize( const QString& string, const QRect& rect, QFont font, QPainter* p ) { bool goodSizeFound = false; - int size = 25; + int size = 20; QRect r; - kdDebug() << "At the beginning: " << rect << endl; - do { font.setPointSize( size ); p->setFont( font ); r = p->boundingRect( QRect(), Qt::AlignAuto, string ); r.moveBy( rect.left(), rect.top() ); - kdDebug() << "String: " << string << " size: " << font.pointSize() << " r: " << r << " rect: " << rect << endl; + if ( rect.contains( r ) ) goodSizeFound = true; else @@ -29,4 +29,20 @@ return size; } + +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 = round( num ); + + return num * power / 10000; +} --- branches/KDE/3.5/kdeedu/kalzium/src/kalziumutils.h #442360:442361 @@ -17,6 +17,11 @@ */ static int maxSize( const QString& string, const QRect& rect, QFont font, QPainter* painter ); + /** + * calculate the 4-digit value of the value @p w + * @return the 4-digit value + */ + static double strippedValue( double w ); }; #endif // KALZIUMUTILS_H --- branches/KDE/3.5/kdeedu/kalzium/src/molcalcwidget.cpp #442360:442361 @@ -22,6 +22,7 @@ #include "kalziumdataobject.h" #include "molcalcwidgetbase.h" #include "element.h" +#include "kalziumutils.h" #include #include @@ -192,7 +193,7 @@ {//update the resultLabel str += i18n( "For example: \"1 Carbon\" or \"3 Oxygen\"", "%1 %2." ).arg( itMap.data() ).arg( itMap.key()->elname() ); str += "\n"; - complexString += i18n( "For example: 1 Seaborgium. Cumulative Mass: 263.119 u (39.25%)", "%1 %2. Cumulative Mass: %3 u (%4%)\n" ).arg( itMap.data() ).arg( itMap.key()->elname() ).arg( itMap.data() * itMap.key()->mass() ).arg(Element::strippedValue( (( itMap.data() * itMap.key()->mass() )/m_mass )*100) ); + complexString += i18n( "For example: 1 Seaborgium. Cumulative Mass: 263.119 u (39.25%)", "%1 %2. Cumulative Mass: %3 u (%4%)\n" ).arg( itMap.data() ).arg( itMap.key()->elname() ).arg( itMap.data() * itMap.key()->mass() ).arg(KalziumUtils::strippedValue( (( itMap.data() * itMap.key()->mass() )/m_mass )*100) ); } resultLabel->setText( str ); --- branches/KDE/3.5/kdeedu/kalzium/src/periodictableview.cpp #442360:442361 @@ -21,6 +21,7 @@ #include "prefs.h" #include "element.h" #include "kalziumtip.h" +#include "kalziumutils.h" #include "kalziumdataobject.h" #include @@ -1171,7 +1172,7 @@ if ( value >= minValue && coeff != -1.0) { QColor c = calculateColor( coeff ); - e->drawGradient( p, QString::number( Element::strippedValue( value ) ), c ); + e->drawGradient( p, QString::number( KalziumUtils::strippedValue( value ) ), c ); } else e->drawGradient( p, i18n("It means: Not Available. Translators: keep it as short as you can!", "N/A"), Qt::lightGray );