diff options
Diffstat (limited to 'libkdchart/KDDrawText.cpp')
-rw-r--r-- | libkdchart/KDDrawText.cpp | 232 |
1 files changed, 116 insertions, 116 deletions
diff --git a/libkdchart/KDDrawText.cpp b/libkdchart/KDDrawText.cpp index 4b9467f..2ef9308 100644 --- a/libkdchart/KDDrawText.cpp +++ b/libkdchart/KDDrawText.cpp @@ -26,9 +26,9 @@ ** licensing are not clear to you. ** **********************************************************************/ -#include <qpainter.h> -#include <qbitmap.h> -#include <qpixmap.h> +#include <tqpainter.h> +#include <tqbitmap.h> +#include <tqpixmap.h> #include <math.h> #include <limits.h> @@ -38,14 +38,14 @@ #define M_PI 3.14159265358979323846 #endif -void KDDrawText::drawRotatedText( QPainter* painter, +void KDDrawText::drawRotatedText( TQPainter* painter, float degrees, - QPoint anchor, - const QString& text, - const QFont* font, + TQPoint anchor, + const TQString& text, + const TQFont* font, int align, bool showAnchor, - const QFontMetrics* fontMet, + const TQFontMetrics* fontMet, bool noFirstrotate, bool noBackrotate, KDDrawTextRegionAndTrueRect* infos, @@ -71,13 +71,13 @@ void KDDrawText::drawRotatedText( QPainter* painter, KDDrawTextRegionAndTrueRect KDDrawText::measureRotatedText( - QPainter* painter, + TQPainter* painter, float degrees, - QPoint anchor, - const QString& text, - const QFont* font, + TQPoint anchor, + const TQString& text, + const TQFont* font, int align, - const QFontMetrics* fontMet, + const TQFontMetrics* fontMet, bool noFirstrotate, bool noBackrotate, int addPercentOfHeightToRegion ) @@ -104,17 +104,17 @@ KDDrawTextRegionAndTrueRect KDDrawText::measureRotatedText( } -void KDDrawText::drawRotatedTxt( QPainter* painter, +void KDDrawText::drawRotatedTxt( TQPainter* painter, bool optimizeOutputForScreen, float degrees, - QPoint anchor, - const QString& text, - const QFont* font, + TQPoint anchor, + const TQString& text, + const TQFont* font, int align, bool showAnchor, int txtWidth, int txtHeight, - const QFontMetrics* fontMet, + const TQFontMetrics* fontMet, bool calculateOnly, bool doNotCalculate, bool noFirstrotate, @@ -124,17 +124,17 @@ void KDDrawText::drawRotatedTxt( QPainter* painter, { // showAnchor=true; - //qDebug("\nanchor: "+ text + " / "+QString::number(anchor.x()) - // +" / "+QString::number(anchor.y())); + //qDebug("\nanchor: "+ text + " / "+TQString::number(anchor.x()) + // +" / "+TQString::number(anchor.y())); bool useInfos = doNotCalculate && infos; bool fontChanged = ( 0 != font ); - QFont oldFont; + TQFont oldFont; if( fontChanged ) { oldFont = painter->font(); painter->setFont( *font ); } else - font = &painter->font(); + font = static_cast<const TQFont*>(&painter->font()); bool mustBackrotate = false; if( !optimizeOutputForScreen && !noFirstrotate ){ @@ -143,7 +143,7 @@ void KDDrawText::drawRotatedTxt( QPainter* painter, mustBackrotate = true; } - QPoint pos = useInfos ? infos->pos : painter->xFormDev( anchor ); + TQPoint pos = useInfos ? infos->pos : painter->xFormDev( anchor ); if( useInfos ) { @@ -156,31 +156,31 @@ void KDDrawText::drawRotatedTxt( QPainter* painter, // a bug in the AIX 5.2 compiler means using (?:) syntax doesn't work here // therefor we do it the following way: - QFontMetrics* pFM=0; + TQFontMetrics* pFM=0; if( ! pFM ) { - pFM = new QFontMetrics( painter->fontMetrics() ); + pFM = new TQFontMetrics( painter->fontMetrics() ); } else { - pFM = const_cast<QFontMetrics*>(fontMet); + pFM = const_cast<TQFontMetrics*>(fontMet); } - int nLF = text.contains('\n'); + int nLF = text.tqcontains('\n'); if( INT_MAX == txtWidth ) { if( nLF ){ int tw; txtWidth = 0; int i0 = 0; - int iLF = text.find('\n'); + int iLF = text.tqfind('\n'); while( -1 != iLF ){ - const QRect r(pFM->boundingRect( text.mid(i0, iLF-i0) )); + const TQRect r(pFM->boundingRect( text.mid(i0, iLF-i0) )); tw = r.width()+ 2; newHeight = r.height(); if( tw > txtWidth ) txtWidth = tw; i0 = iLF+1; - iLF = text.find('\n', i0); + iLF = text.tqfind('\n', i0); } if( iLF < (int)text.length() ){ - const QRect r(pFM->boundingRect( text.mid( i0 ) )); + const TQRect r(pFM->boundingRect( text.mid( i0 ) )); tw = r.width()+2; newHeight = r.height(); if( tw > txtWidth ) @@ -188,7 +188,7 @@ void KDDrawText::drawRotatedTxt( QPainter* painter, i0 = iLF+1; } }else{ - const QRect r(painter->boundingRect( 0,0,1,1, Qt::AlignAuto, text )); + const TQRect r(painter->boundingRect( 0,0,1,1, TQt::AlignAuto, text )); // correct width and height before painting with 2 unit to avoid truncating. // PENDING Michel - improve txtWidth = r.width()+2; @@ -209,8 +209,8 @@ void KDDrawText::drawRotatedTxt( QPainter* painter, } if( showAnchor ) { int d = txtHeight/4; - QPen savePen = painter->pen(); - painter->setPen( QColor( Qt::darkRed ) ); + TQPen savePen = painter->pen(); + painter->setPen( TQColor( TQt::darkRed ) ); painter->drawLine( pos.x(), pos.y()-d, pos.x(), pos.y()+d ); painter->drawLine( pos.x()-d, pos.y(), @@ -219,32 +219,32 @@ void KDDrawText::drawRotatedTxt( QPainter* painter, } int x = useInfos ? infos->x : pos.x(); int y = useInfos ? infos->y : pos.y(); - //qDebug("1.: (x / y) :" + text + " / "+QString::number(x) - // +" / "+QString::number(y)); + //qDebug("1.: (x / y) :" + text + " / "+TQString::number(x) + // +" / "+TQString::number(y)); //qDebug("2.: (posx / posy) :" + text ); // qDebug ( "%d", pos.x() ); qDebug ( "%d", pos.y() ); - //qDebug("3.: (infosx / infosy) :" + text + " / "+QString::number(infos->x) - // +" / "+QString::number(infos->y)); + //qDebug("3.: (infosx / infosy) :" + text + " / "+TQString::number(infos->x) + // +" / "+TQString::number(infos->y)); if( !useInfos && !optimizeOutputForScreen ) { - switch( align & ( Qt::AlignLeft | Qt::AlignRight | Qt::AlignHCenter ) ) { - case Qt::AlignLeft: + switch( align & ( TQt::AlignLeft | TQt::AlignRight | TQt::AlignHCenter ) ) { + case TQt::AlignLeft: break; - case Qt::AlignRight: -//qDebug( QPaintDeviceMetrics::logicalDpiX() ); + case TQt::AlignRight: +//qDebug( TQPaintDeviceMetrics::logicalDpiX() ); x -= txtWidth; break; - case Qt::AlignHCenter: + case TQt::AlignHCenter: x -= txtWidth - txtWidth/2; break; } - switch( align & ( Qt::AlignTop | Qt::AlignBottom | Qt::AlignVCenter ) ) { - case Qt::AlignTop: + switch( align & ( TQt::AlignTop | TQt::AlignBottom | TQt::AlignVCenter ) ) { + case TQt::AlignTop: break; - case Qt::AlignBottom: + case TQt::AlignBottom: y -= txtHeight; break; - case Qt::AlignVCenter: + case TQt::AlignVCenter: y -= txtHeight/2; break; } @@ -254,52 +254,52 @@ void KDDrawText::drawRotatedTxt( QPainter* painter, infos->x = x - 4; infos->y = y - 4; //PENDING Michel updating info using x , y from pos - //qDebug("4.: (infosx / infosy) :" + text + " / "+QString::number(infos->x) - //+" / "+QString::number(infos->y)); - //qDebug("5.: (x / y) :" + text + " / "+QString::number(x) - // +" / "+QString::number(y)); - //qDebug("6.: (anchorx /anchory) :" + text + " / "+QString::number(x) - // +" / "+QString::number(y)); - QRect rect( painter->boundingRect( x, y, + //qDebug("4.: (infosx / infosy) :" + text + " / "+TQString::number(infos->x) + //+" / "+TQString::number(infos->y)); + //qDebug("5.: (x / y) :" + text + " / "+TQString::number(x) + // +" / "+TQString::number(y)); + //qDebug("6.: (anchorx /anchory) :" + text + " / "+TQString::number(x) + // +" / "+TQString::number(y)); + TQRect rect( painter->boundingRect( x, y, txtWidth, txtHeight, - Qt::AlignLeft + Qt::AlignTop, + TQt::AlignLeft + TQt::AlignTop, text ) ); - //painter->fillRect (rect, Qt::blue ); + //painter->fillRect (rect, TQt::blue ); - QPoint topLeft( painter->xForm( rect.topLeft() ) ); - QPoint topRight( painter->xForm( rect.topRight() ) ); - QPoint bottomRight( painter->xForm( rect.bottomRight() ) ); - QPoint bottomLeft( painter->xForm( rect.bottomLeft() ) ); + TQPoint topLeft( painter->xForm( rect.topLeft() ) ); + TQPoint topRight( painter->xForm( rect.topRight() ) ); + TQPoint bottomRight( painter->xForm( rect.bottomRight() ) ); + TQPoint bottomLeft( painter->xForm( rect.bottomLeft() ) ); int additor = addPercentOfHeightToRegion * txtHeight / 100; - QPointArray points; + TQPointArray points; points.setPoints( 4, topLeft.x()-additor, topLeft.y()-additor, topRight.x()+additor, topRight.y()-additor, bottomRight.x()+additor, bottomRight.y()+additor, bottomLeft.x()-additor, bottomLeft.y()+additor ); - infos->region = QRegion( points ); + infos->region = TQRegion( points ); } - // When the Qt initialization bug is fixed the following scope + // When the TQt initialization bug is fixed the following scope // will be put into an "if( showAnchor )" entirely. { int d = txtHeight/4; - QPen savePen = painter->pen(); + TQPen savePen = painter->pen(); if( showAnchor ) { - painter->setPen( QColor( Qt::blue ) ); + painter->setPen( TQColor( TQt::blue ) ); painter->drawLine( x, y-d, x, y+d ); painter->drawLine( x-d, y, x+d, y ); - painter->setPen( QColor( Qt::darkGreen ) ); + painter->setPen( TQColor( TQt::darkGreen ) ); painter->drawRect(x,y,txtWidth,txtHeight); //painter->drawText( x, y-d, text); /* }else{ - // Working around a strange Qt bug: Rotated painter must be + // Working around a strange TQt bug: Rotated painter must be // initialized by drawing before text can be painted there. - painter->setPen( QColor( Qt::white ) ); + painter->setPen( TQColor( TQt::white ) ); painter->drawLine( 30000,0,30001,0 ); */ } @@ -317,27 +317,27 @@ void KDDrawText::drawRotatedTxt( QPainter* painter, /* painter->drawText( x, y, txtWidth, txtHeight, - Qt::AlignLeft + Qt::AlignTop, + TQt::AlignLeft + TQt::AlignTop, text ); */ painter->drawText( x, y, txtWidth, txtHeight, - Qt::AlignLeft + Qt::AlignTop, + TQt::AlignLeft + TQt::AlignTop, text ); /* painter->drawText( x, y, text, -1, - Qt::AlignRight + Qt::AlignTop ); + TQt::AlignRight + TQt::AlignTop ); */ }else{ // new code (rotating the text ourselves for better quality on screens) - QPixmap pm( txtWidth+2, txtHeight+2, 1 ); + TQPixmap pm( txtWidth+2, txtHeight+2, 1 ); // note: When using colored axis labels it will be necessary // to change this code and use a 256 color pixmap instead // of a monochrome one. (khz, 2002/08/15) - pm.fill(Qt::color0); - QPainter p; + pm.fill(TQt::color0); + TQPainter p; p.begin( &pm ); if( showAnchor ){ p.drawRect(0,0, txtWidth,txtHeight); @@ -347,21 +347,21 @@ void KDDrawText::drawRotatedTxt( QPainter* painter, p.setFont(painter->font()); p.drawText( 0, 0, txtWidth, txtHeight, - Qt::AlignLeft + Qt::AlignTop, + TQt::AlignLeft + TQt::AlignTop, text ); /* p.drawText( 0,0, text, -1, - Qt::AlignLeft + Qt::AlignTop ); + TQt::AlignLeft + TQt::AlignTop ); */ - QBitmap mask; - mask = pm; - pm.setMask( mask ); - QWMatrix m; + TQBitmap tqmask; + tqmask = pm; + pm.setMask( tqmask ); + TQWMatrix m; m.rotate( degrees ); - QPixmap theRotatedPixmap = pm.xForm(m); + TQPixmap theRotatedPixmap = pm.xForm(m); // where are our four corner points now: double degreesRad = degrees; @@ -370,20 +370,20 @@ void KDDrawText::drawRotatedTxt( QPainter* painter, degreesRad *= M_PI / 180.0; double cosA = cos( degreesRad ); double sinA = sin( degreesRad ); - QPoint pTopLeft( 0, + TQPoint pTopLeft( 0, 0 ); - QPoint pBotLeft( static_cast < int > ( 0 * cosA - txtHeight * sinA ), + TQPoint pBotLeft( static_cast < int > ( 0 * cosA - txtHeight * sinA ), static_cast < int > ( txtHeight * cosA + 0 * sinA ) ); - QPoint pTopRight( static_cast < int > ( txtWidth * cosA - 0 * sinA ), + TQPoint pTopRight( static_cast < int > ( txtWidth * cosA - 0 * sinA ), static_cast < int > ( 0 * cosA + txtWidth * sinA ) ); - QPoint pBotRight( static_cast < int > ( txtWidth * cosA - txtHeight * sinA ), + TQPoint pBotRight( static_cast < int > ( txtWidth * cosA - txtHeight * sinA ), static_cast < int > ( txtHeight * cosA + txtWidth * sinA ) ); // make our four corner points relative // to the bounding rect of the rotated pixmap { - QPoint pDeltaTL( QMIN(0, QMIN(pBotLeft.x(), QMIN(pTopRight.x(), pBotRight.x()))), - QMIN(0, QMIN(pBotLeft.y(), QMIN(pTopRight.y(), pBotRight.y()))) ); + TQPoint pDeltaTL( TQMIN(0, TQMIN(pBotLeft.x(), TQMIN(pTopRight.x(), pBotRight.x()))), + TQMIN(0, TQMIN(pBotLeft.y(), TQMIN(pTopRight.y(), pBotRight.y()))) ); pTopLeft -= pDeltaTL; pBotLeft -= pDeltaTL; pTopRight -= pDeltaTL; @@ -391,82 +391,82 @@ void KDDrawText::drawRotatedTxt( QPainter* painter, } /* - painter->setPen( QColor( Qt::black ) ); + painter->setPen( TQColor( TQt::black ) ); painter->drawLine( x-13, y, x+13, y ); painter->drawLine( x, y-13, x, y+13 ); - painter->setPen( QColor( Qt::blue ) ); + painter->setPen( TQColor( TQt::blue ) ); painter->drawLine( x+pTopLeft.x()-3, y+pTopLeft.y(), x+pTopLeft.x()+3, y+pTopLeft.y() ); painter->drawLine( x+pTopLeft.x(), y+pTopLeft.y()-3, x+pTopLeft.x(), y+pTopLeft.y()+3 ); - painter->setPen( QColor( Qt::red ) ); + painter->setPen( TQColor( TQt::red ) ); painter->drawLine( x+pTopRight.x()-3, y+pTopRight.y(), x+pTopRight.x()+3, y+pTopRight.y() ); painter->drawLine( x+pTopRight.x(), y+pTopRight.y()-3, x+pTopRight.x(), y+pTopRight.y()+3 ); - painter->setPen( QColor( Qt::green ) ); + painter->setPen( TQColor( TQt::green ) ); painter->drawLine( x+pBotLeft.x()-3, y+pBotLeft.y(), x+pBotLeft.x()+3, y+pBotLeft.y() ); painter->drawLine( x+pBotLeft.x(), y+pBotLeft.y()-3, x+pBotLeft.x(), y+pBotLeft.y()+3 ); - painter->setPen( QColor( Qt::yellow ) ); + painter->setPen( TQColor( TQt::yellow ) ); painter->drawLine( x+pBotRight.x()-3, y+pBotRight.y(), x+pBotRight.x()+3, y+pBotRight.y() ); painter->drawLine( x+pBotRight.x(), y+pBotRight.y()-3, x+pBotRight.x(), y+pBotRight.y()+3 ); */ - // The horizontal and vertical alignment together define one of + // The horizontal and vertical tqalignment together define one of // NINE possible points: this point must be moved on the anchor. - int hAlign = align & ( Qt::AlignLeft | Qt::AlignRight | Qt::AlignHCenter ); - int vAlign = align & ( Qt::AlignTop | Qt::AlignBottom | Qt::AlignVCenter ); + int hAlign = align & ( TQt::AlignLeft | TQt::AlignRight | TQt::AlignHCenter ); + int vAlign = align & ( TQt::AlignTop | TQt::AlignBottom | TQt::AlignVCenter ); - QPoint pixPoint; + TQPoint pixPoint; switch( hAlign ) { - case Qt::AlignLeft: + case TQt::AlignLeft: switch( vAlign ) { - case Qt::AlignTop: + case TQt::AlignTop: pixPoint = pTopLeft; break; - case Qt::AlignBottom: + case TQt::AlignBottom: pixPoint = pBotLeft; break; - case Qt::AlignVCenter: + case TQt::AlignVCenter: default: - pixPoint = QPoint( (pTopLeft.x() + pBotLeft.x()) / 2, + pixPoint = TQPoint( (pTopLeft.x() + pBotLeft.x()) / 2, (pTopLeft.y() + pBotLeft.y()) / 2 ); break; } break; - case Qt::AlignRight: + case TQt::AlignRight: switch( vAlign ) { - case Qt::AlignTop: + case TQt::AlignTop: pixPoint = pTopRight; break; - case Qt::AlignBottom: + case TQt::AlignBottom: pixPoint = pBotRight; break; - case Qt::AlignVCenter: + case TQt::AlignVCenter: default: - pixPoint = QPoint( (pTopRight.x() + pBotRight.x()) / 2, + pixPoint = TQPoint( (pTopRight.x() + pBotRight.x()) / 2, (pTopRight.y() + pBotRight.y()) / 2 ); break; } break; - case Qt::AlignHCenter: + case TQt::AlignHCenter: default: switch( vAlign ) { - case Qt::AlignTop: - pixPoint = QPoint( (pTopLeft.x() + pTopRight.x()) / 2, + case TQt::AlignTop: + pixPoint = TQPoint( (pTopLeft.x() + pTopRight.x()) / 2, (pTopLeft.y() + pTopRight.y()) / 2 ); break; - case Qt::AlignBottom: - pixPoint = QPoint( (pBotLeft.x() + pBotRight.x()) / 2, + case TQt::AlignBottom: + pixPoint = TQPoint( (pBotLeft.x() + pBotRight.x()) / 2, (pBotLeft.y() + pBotRight.y()) / 2 ); break; - case Qt::AlignVCenter: + case TQt::AlignVCenter: default: - pixPoint = QPoint( (pTopLeft.x() + pBotRight.x()) / 2, + pixPoint = TQPoint( (pTopLeft.x() + pBotRight.x()) / 2, (pTopLeft.y() + pBotRight.y()) / 2 ); break; } break; } - //qDebug("2.: (x / y) : "+QString::number(x) - // +" / "+QString::number(y)); - painter->drawPixmap( QPoint( x - pixPoint.x(), + //qDebug("2.: (x / y) : "+TQString::number(x) + // +" / "+TQString::number(y)); + painter->drawPixmap( TQPoint( x - pixPoint.x(), y - pixPoint.y() ), theRotatedPixmap ); p.end(); |