SVN commit 442404 by cniehaus: * Make the detailgraphicaloverview-widget also use optimum-sized strings M +25 -17 detailedgraphicaloverview.cpp M +10 -0 kalziumutils.cpp M +19 -2 kalziumutils.h --- branches/KDE/3.5/kdeedu/kalzium/src/detailedgraphicaloverview.cpp #442403:442404 @@ -14,16 +14,19 @@ ***************************************************************************/ #include "detailedgraphicaloverview.h" #include "element.h" +#include "kalziumutils.h" //KDE-Includes #include #include #include +#include //QT-Includes #include #include #include +#include DetailedGraphicalOverview::DetailedGraphicalOverview( Element *el, QWidget *parent, const char *name ) : QWidget( parent, name ) @@ -91,7 +94,6 @@ fC.setBold( true ); QFontMetrics fmA = QFontMetrics( fA ); QFontMetrics fmB = QFontMetrics( fB ); - QFontMetrics fmC = QFontMetrics( fC ); //coordinates for element symbol: near the center int xA = 4 * w / 10; @@ -101,18 +103,6 @@ int xB = xA - fmB.width( QString::number( m_element->number() ) ); int yB = yA - fmA.height() + fmB.height(); - //coordinates for element name: lower left - int xC1 = 8; - int yC1 = h - 8; - - //coordinates for oxidation: right side, above atomic mass - int xC2 = w - fmC.width( m_element->oxstage() ) - 8; - int yC2 = h - fmC.height() - 8; - - //coordinates for mass: lower right corner - int xC3 = w - fmC.width( QString::number( m_element->mass() ) ) - 8; - int yC3 = h - 8; - //Element Symbol p.setFont( fA ); p.drawText( xA, yA , m_element->symbol() ); @@ -121,14 +111,32 @@ p.setFont( fB ); p.drawText( xB, yB, QString::number( m_element->number() )); + QRect rect( 0, 20, w/2, h ); + + p.setFont( fC ); + + int size = KalziumUtils::maxSize(m_element->elname(), rect , fC, &p); + int size2 = KalziumUtils::maxSize(m_element->oxstage(), rect, fC, &p); + int size3 = KalziumUtils::maxSize(QString::number( m_element->mass() ), rect , fC, &p); + //Name and other data + fC.setPointSize( size ); p.setFont( fC ); + //Name - p.drawText( xC1, yC1, m_element->elname() ); - //Oxidationszahlen - p.drawText( xC2, yC2, m_element->oxstage() ); + p.drawText( 1, 0, w/2, h, Qt::AlignLeft, m_element->elname() ); + + //Oxidationstates + fC.setPointSize( size2 ); + p.setFont( fC ); + int offsetOx = KalziumUtils::StringHeight( QString::number( m_element->mass() ), fC, &p ); + p.drawText( 1, h-offsetOx, w/2, offsetOx, Qt::AlignLeft, m_element->oxstage() ); + //Mass - p.drawText( xC3, yC3, QString::number( m_element->mass() )); + fC.setPointSize( size3 ); + p.setFont( fC ); + int offset = KalziumUtils::StringHeight( QString::number( m_element->mass() ), fC, &p ); + p.drawText( w/2, h-offset, w/2, offset, Qt::AlignRight, QString::number( m_element->mass() ) ); //TODO until I found again what those symbols mean disable this //drawBiologicalSymbol( &p ); --- branches/KDE/3.5/kdeedu/kalzium/src/kalziumutils.cpp #442403:442404 @@ -30,6 +30,16 @@ 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 ) ) --- branches/KDE/3.5/kdeedu/kalzium/src/kalziumutils.h #442403:442404 @@ -18,10 +18,27 @@ static int maxSize( const QString& string, const QRect& rect, QFont font, QPainter* painter ); /** - * calculate the 4-digit value of the value @p w + * calculate the 4-digit value of the value @p w. For + * example, 12.3456 will be returned as 12.35 + * @param value the value which will be stripped * @return the 4-digit value */ - static double strippedValue( double w ); + static double strippedValue( double value ); + + /** + * @param string the string which is measured + * @param font the used font + * @param painter the used painter + * @return the width of the string @p string + */ + static int StringWidth( const QString& string, const QFont& font, QPainter* painter ); + /** + * @param string the string which is measured + * @param font the used font + * @param painter the used painter + * @return the height of the string @p string + */ + static int StringHeight( const QString& string, const QFont& font, QPainter* painter ); }; #endif // KALZIUMUTILS_H