kivio

kivio_screen_painter.cpp

00001 /*
00002  * Kivio - Visual Modelling and Flowcharting
00003  * Copyright (C) 2000-2001 theKompany.com & Dave Marotti
00004  *
00005  * This program is free software; you can redistribute it and/or
00006  * modify it under the terms of the GNU General Public License
00007  * as published by the Free Software Foundation; either version 2
00008  * of the License, or (at your option) any later version.
00009  *
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU General Public License
00016  * along with this program; if not, write to the Free Software
00017  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
00018  */
00019 #include "kivioglobal.h"
00020 #include "kivio_line_style.h"
00021 #include "kivio_point.h"
00022 #include "kivio_screen_painter.h"
00023 
00024 #include <qimage.h>
00025 #include <qpen.h>
00026 #include <qbrush.h>
00027 #include <qsimplerichtext.h>
00028 #include <qpalette.h>
00029 
00030 #include <kdebug.h>
00031 
00032 #define PAINTER_CHECK() { if(!m_pPainter) { kdDebug(43000) << "KivioScreenPainter::PAINTER_CHECK() - no QPainter exists." << endl; } }
00033 
00034 
00035 KivioScreenPainter::KivioScreenPainter()
00036     : m_pPainter(NULL)
00037 {
00038    m_transX = 0.0f;
00039    m_transY = 0.0f;
00040    m_rotation = 0;
00041 }
00042 
00043 KivioScreenPainter::KivioScreenPainter(QPainter* painter)
00044     : m_pPainter(painter)
00045 {
00046    m_transX = 0.0f;
00047    m_transY = 0.0f;
00048    m_rotation = 0;
00049 }
00050 
00051 KivioScreenPainter::~KivioScreenPainter()
00052 {
00053     if( m_pPainter )
00054     {
00055        kdDebug(43000) << "KivioScreenPainter::~KivioScreenPainter - A QPainter slipped through the cracks" << endl;
00056         delete m_pPainter;
00057         m_pPainter = NULL;
00058     }
00059 }
00060 
00070 bool KivioScreenPainter::start( QPaintDevice *dev )
00071 {
00072     // Bomb out if one exists already
00073     if( m_pPainter )
00074     {
00075        kdDebug(43000) << "KivioScreenPainter::start() - A QPainter already exists" << endl;
00076         return false;
00077     }
00078 
00079     // Allocate a new drawing thingy
00080     m_pPainter = new QPainter(dev);
00081 
00082     return true;
00083 }
00084 
00085 
00092 bool KivioScreenPainter::stop()
00093 {
00094     // Bomb out if we don't have a painter.  This means that they never
00095     // called @ref start().
00096     if( !m_pPainter )
00097     {
00098        kdDebug(43000) <<"KivioScreenPainter::stop() called without previous call to start" << endl;
00099         return false;
00100     }
00101 
00102     // Otherwise delete and nullify the pointer
00103     delete m_pPainter;
00104     m_pPainter = NULL;
00105 
00106     return true;
00107 }
00108 
00109 
00110 
00122 void KivioScreenPainter::drawLine( float x1, float y1, float x2, float y2 )
00123 {
00124     PAINTER_CHECK();
00125 
00126     m_pPainter->setPen(m_pLineStyle->pen(1.0f));
00127 
00128     m_pPainter->drawLine( int(x1), int(y1), int(x2), int(y2) );
00129 
00130 }
00131 
00132 
00145 void KivioScreenPainter::drawArc( float x1, float y1, float w1, float h1, float a1, float a2 )
00146 {
00147     PAINTER_CHECK();
00148 
00149     m_pPainter->setPen(m_pLineStyle->pen(1.0f));
00150 
00151     m_pPainter->drawArc( int(x1), int(y1), int(w1), int(h1), int(a1), int(a2) );
00152 }
00153 
00154 
00163 void KivioScreenPainter::drawBezier( QPointArray &pArray )
00164 {
00165     PAINTER_CHECK();
00166 
00167     m_pPainter->setPen(m_pLineStyle->pen(1.0f));
00168 
00169     m_pPainter->drawCubicBezier(pArray);
00170 }
00171 
00172 
00181 void KivioScreenPainter::drawRect( float x1, float y1, float w1, float h1 )
00182 {
00183     PAINTER_CHECK();
00184 
00185     m_pPainter->setPen(m_pLineStyle->pen(1.0f));
00186     m_pPainter->setBrush(QBrush::NoBrush);
00187     m_pPainter->drawRect( int(x1), int(y1), int(w1), int(h1) );
00188 }
00189 
00190 
00202 void KivioScreenPainter::fillRect( float x1, float y1, float w1, float h1 )
00203 {
00204     PAINTER_CHECK();
00205 
00206     QBrush b;
00207     b = m_pFillStyle->brush();
00208 
00209     if(m_pFillStyle->colorStyle() == KivioFillStyle::kcsGradient) {
00210       QPixmap pix((int)w1, (int)h1);
00211       QImage image = KImageEffect::gradient(pix.size(), m_pFillStyle->color(), m_pFillStyle->color2(),
00212         (KImageEffect::GradientType) m_pFillStyle->gradientType());
00213       pix.convertFromImage(image);
00214       b.setPixmap(pix);
00215       m_pPainter->setBrushOrigin(int(x1 + m_transX), int(y1 + m_transY));
00216     }
00217 
00218     m_pPainter->setPen(m_pLineStyle->pen(1.0f));
00219     m_pPainter->setBrush(b);
00220     m_pPainter->drawRect( int(x1), int(y1), int(w1), int(h1) );
00221     m_pPainter->setBrushOrigin(0, 0);
00222 }
00223 
00224 
00238 void KivioScreenPainter::drawRoundRect( float x1, float y1, float w1, float h1, float a1, float a2 )
00239 {
00240     PAINTER_CHECK();
00241 
00242     m_pPainter->setPen(m_pLineStyle->pen(1.0f));
00243     m_pPainter->setBrush(QBrush::NoBrush);
00244     m_pPainter->drawRoundRect( int(x1), int(y1), int(w1), int(h1), int(a1), int(a2) );
00245 }
00246 
00247 
00248 
00262 void KivioScreenPainter::fillRoundRect( float x1, float y1, float w1, float h1, float a1, float a2 )
00263 {
00264     PAINTER_CHECK();
00265 
00266     QBrush b;
00267     b = m_pFillStyle->brush();
00268 
00269     if(m_pFillStyle->colorStyle() == KivioFillStyle::kcsGradient) {
00270       QPixmap pix((int)w1, (int)h1);
00271       QImage image = KImageEffect::gradient(pix.size(), m_pFillStyle->color(), m_pFillStyle->color2(),
00272         (KImageEffect::GradientType) m_pFillStyle->gradientType());
00273       pix.convertFromImage(image);
00274       b.setPixmap(pix);
00275       m_pPainter->setBrushOrigin(int(x1 + m_transX), int(y1 + m_transY));
00276     }
00277 
00278     m_pPainter->setPen(m_pLineStyle->pen(1.0f));
00279     m_pPainter->setBrush(b);
00280     m_pPainter->drawRoundRect( int(x1), int(y1), int(w1), int(h1), int(a1), int(a2) );
00281     m_pPainter->setBrushOrigin(0, 0);
00282 }
00283 
00284 
00298 void KivioScreenPainter::drawPie( float x1, float y1, float w1, float h1, float a1, float a2 )
00299 {
00300     PAINTER_CHECK();
00301 
00302     m_pPainter->setPen(m_pLineStyle->pen(1.0f));
00303     m_pPainter->setBrush(QBrush::NoBrush);
00304     m_pPainter->drawPie( int(x1), int(y1), int(w1), int(h1), int(a1), int(a2) );
00305 }
00306 
00307 
00321 void KivioScreenPainter::fillPie( float x1, float y1, float w1, float h1, float a1, float a2 )
00322 {
00323     PAINTER_CHECK();
00324 
00325     QBrush b;
00326     b = m_pFillStyle->brush();
00327 
00328     if(m_pFillStyle->colorStyle() == KivioFillStyle::kcsGradient) {
00329       QPixmap pix((int)w1, (int)h1);
00330       QImage image = KImageEffect::gradient(pix.size(), m_pFillStyle->color(), m_pFillStyle->color2(),
00331         (KImageEffect::GradientType) m_pFillStyle->gradientType());
00332       pix.convertFromImage(image);
00333       b.setPixmap(pix);
00334       m_pPainter->setBrushOrigin(int(x1 + m_transX), int(y1 + m_transY));
00335     }
00336 
00337     m_pPainter->setPen(m_pLineStyle->pen(1.0f));
00338     m_pPainter->setBrush(b);
00339     m_pPainter->drawPie( int(x1), int(y1), int(w1), int(h1), int(a1), int(a2) );
00340     m_pPainter->setBrushOrigin(0, 0);
00341 }
00342 
00343 
00357 void KivioScreenPainter::drawChord( float x1, float y1, float w1, float h1, float a1, float a2 )
00358 {
00359     PAINTER_CHECK();
00360 
00361     m_pPainter->setPen(m_pLineStyle->pen(1.0f));
00362     m_pPainter->setBrush(QBrush::NoBrush);
00363     m_pPainter->drawChord( int(x1), int(y1), int(w1), int(h1), int(a1), int(a2) );
00364 }
00365 
00366 
00380 void KivioScreenPainter::fillChord( float x1, float y1, float w1, float h1, float a1, float a2 )
00381 {
00382     PAINTER_CHECK();
00383 
00384     QBrush b;
00385     b = m_pFillStyle->brush();
00386 
00387     if(m_pFillStyle->colorStyle() == KivioFillStyle::kcsGradient) {
00388       QPixmap pix((int)w1, (int)h1);
00389       QImage image = KImageEffect::gradient(pix.size(), m_pFillStyle->color(),
00390         m_pFillStyle->color2(), m_pFillStyle->gradientType());
00391       pix.convertFromImage(image);
00392       b.setPixmap(pix);
00393       m_pPainter->setBrushOrigin(int(x1 + m_transX), int(y1 + m_transY));
00394     }
00395 
00396     m_pPainter->setPen(m_pLineStyle->pen(1.0f));
00397     m_pPainter->setBrush(b);
00398     m_pPainter->drawChord( int(x1), int(y1), int(w1), int(h1), int(a1), int(a2) );
00399     m_pPainter->setBrushOrigin(0, 0);
00400 }
00401 
00402 
00414 void KivioScreenPainter::drawEllipse( float x1, float y1, float w1, float h1 )
00415 {
00416     PAINTER_CHECK();
00417 
00418     m_pPainter->setPen(m_pLineStyle->pen(1.0f));
00419     m_pPainter->setBrush(QBrush::NoBrush);
00420     m_pPainter->drawEllipse( int(x1), int(y1), int(w1), int(h1) );
00421 }
00422 
00423 
00435 void KivioScreenPainter::fillEllipse( float x1, float y1, float w1, float h1 )
00436 {
00437     PAINTER_CHECK();
00438 
00439     QBrush b;
00440     b = m_pFillStyle->brush();
00441 
00442     if(m_pFillStyle->colorStyle() == KivioFillStyle::kcsGradient) {
00443       QPixmap pix((int)w1, (int)h1);
00444       QImage image = KImageEffect::gradient(pix.size(), m_pFillStyle->color(), m_pFillStyle->color2(),
00445         (KImageEffect::GradientType) m_pFillStyle->gradientType());
00446       pix.convertFromImage(image);
00447       b.setPixmap(pix);
00448       m_pPainter->setBrushOrigin(int(x1 + m_transX), int(y1 + m_transY));
00449     }
00450 
00451     m_pPainter->setPen(m_pLineStyle->pen(1.0f));
00452     m_pPainter->setBrush(b);
00453     m_pPainter->drawEllipse( int(x1), int(y1), int(w1), int(h1) );
00454     m_pPainter->setBrushOrigin(0, 0);
00455 }
00456 
00457 
00466 void KivioScreenPainter::drawLineArray( QPtrList<KivioPoint> *pList )
00467 {
00468   PAINTER_CHECK();
00469 
00470   KivioPoint *pPoint;
00471   QPointArray points(pList->count());
00472   int i;
00473   QBrush b;
00474 
00475   b.setStyle( QBrush::NoBrush );
00476 
00477   i=0;
00478   pPoint = pList->first();
00479   while( pPoint )
00480   {
00481     points.setPoint( i++, int(pPoint->x()), int(pPoint->y()) );
00482 
00483     pPoint = pList->next();
00484   }
00485 
00486   m_pPainter->setPen(m_pLineStyle->pen(1.0f));
00487   m_pPainter->setBrush(b);
00488 
00489   m_pPainter->drawLineSegments(points);
00490 }
00491 
00492 
00500 void KivioScreenPainter::drawPolyline( QPtrList<KivioPoint> *pList )
00501 {
00502   PAINTER_CHECK();
00503 
00504   KivioPoint *pPoint;
00505   QPointArray points( pList->count() );
00506   int i = 0;
00507   pPoint = pList->first();
00508 
00509   while( pPoint )
00510   {
00511     points.setPoint(i++, int(pPoint->x()), int(pPoint->y()) );
00512     pPoint = pList->next();
00513   }
00514 
00515   drawPolyline(points);
00516 }
00517 
00518 
00519 
00527 void KivioScreenPainter::drawPolygon( QPtrList<KivioPoint> *pList )
00528 {
00529   PAINTER_CHECK();
00530 
00531   KivioPoint *pPoint;
00532   QPointArray points( pList->count() );
00533   int i = 0;
00534   pPoint = pList->first();
00535 
00536   while( pPoint )
00537   {
00538     points.setPoint(i++, int(pPoint->x()), int(pPoint->y()) );
00539     pPoint = pList->next();
00540   }
00541 
00542   drawPolygon(points);
00543 }
00544 
00545 void KivioScreenPainter::drawPolyline( QPointArray &pArray )
00546 {
00547   PAINTER_CHECK();
00548 
00549   m_pPainter->setPen(m_pLineStyle->pen(1.0f));
00550   m_pPainter->setBrush( QBrush::NoBrush );
00551 
00552   m_pPainter->drawPolyline( pArray, 0, pArray.size() );
00553 }
00554 
00555 void KivioScreenPainter::drawPolygon( QPointArray &pArray )
00556 {
00557   PAINTER_CHECK();
00558 
00559   QBrush b;
00560   b = m_pFillStyle->brush();
00561 
00562   if(m_pFillStyle->colorStyle() == KivioFillStyle::kcsGradient) {
00563     int x1, y1, w1, h1;
00564     x1 = pArray[0].x();
00565     y1 = pArray[0].y();
00566     w1 = h1 = 0;
00567 
00568     for(unsigned int i = 0; i < pArray.count(); i++) {
00569       x1 = QMIN(x1, pArray[i].x());
00570       y1 = QMIN(y1, pArray[i].y());
00571       w1 = QMAX(w1, pArray[i].x());
00572       h1 = QMAX(h1, pArray[i].y());
00573     }
00574 
00575     w1 = w1 - x1;
00576     h1 = h1 - y1;
00577 
00578     QPixmap pix(w1, h1);
00579     QImage image = KImageEffect::gradient(pix.size(), m_pFillStyle->color(), m_pFillStyle->color2(),
00580       (KImageEffect::GradientType) m_pFillStyle->gradientType());
00581     pix.convertFromImage(image);
00582     b.setPixmap(pix);
00583     m_pPainter->setBrushOrigin(x1 + (int)m_transX, y1 + (int)m_transY);
00584   }
00585 
00586   m_pPainter->setPen(m_pLineStyle->pen(1.0f));
00587   m_pPainter->setBrush(b);
00588 
00589   m_pPainter->drawPolygon( pArray, true );
00590   m_pPainter->setBrushOrigin(0, 0);
00591 }
00592 
00593 void KivioScreenPainter::drawLineArray( QPointArray &pArray )
00594 {
00595     PAINTER_CHECK();
00596 
00597     m_pPainter->setPen(m_pLineStyle->pen(1.0f));
00598     m_pPainter->setBrush(QBrush::NoBrush);
00599 
00600     m_pPainter->drawLineSegments(pArray);
00601 }
00602 
00603 
00612 void KivioScreenPainter::drawClosedPath( QPtrList<KivioPoint> *pPoints )
00613 {
00614     PAINTER_CHECK();
00615 
00616     QBrush brush;
00617 
00618     KivioPoint *pPoint, *pPoint2, *pPoint3, *pPoint4;
00619     QPtrList <KivioPoint> *pPointList = pPoints;
00620     QPointArray controlPoints(4), bPoints(0), tmpPoints;
00621 
00622     int pointIndex=0;
00623     pPoint = pPointList->first();
00624     while( pPoint )
00625     {
00626         if( pPoint->pointType() == KivioPoint::kptNormal )
00627         {
00628             bPoints.putPoints( pointIndex, 1, int(pPoint->x()), int(pPoint->y()) );
00629             pointIndex++;
00630         }
00631         else if( pPoint->pointType() == KivioPoint::kptBezier )
00632         {
00633             pPoint2 = pPointList->next();
00634             pPoint3 = pPointList->next();
00635             pPoint4 = pPointList->next();
00636 
00637             if( !pPoint2 || !pPoint3 || !pPoint4 )
00638             {
00639                 kdDebug(43000) << "drawClosedPath() - incorrect # of bezier points" << endl;
00640                 return;
00641             }
00642 
00643             if( pPoint2->pointType() != KivioPoint::kptBezier ||
00644                 pPoint3->pointType() != KivioPoint::kptBezier ||
00645                 pPoint4->pointType() != KivioPoint::kptBezier )
00646             {
00647                 kdDebug(43000) << "drawClosedPath() - bezier curves must have 4 points" << endl;
00648                 return;
00649             }
00650 
00651             controlPoints.setPoint( 0, qRound(pPoint->x()), qRound(pPoint->y()) );
00652             controlPoints.setPoint( 1, qRound(pPoint2->x()), qRound(pPoint2->y()) );
00653             controlPoints.setPoint( 2, qRound(pPoint3->x()), qRound(pPoint3->y()) );
00654             controlPoints.setPoint( 3, qRound(pPoint4->x()), qRound(pPoint4->y()) );
00655 
00656             tmpPoints = controlPoints.cubicBezier();
00657 
00658             for( int j=0; j<int(tmpPoints.size()); j++ )
00659             {
00660                 bPoints.putPoints( pointIndex, 1, tmpPoints.point(j).x(), tmpPoints.point(j).y() );
00661                 pointIndex++;
00662             }
00663         } // end pointtype==bezier
00664         else if( pPoint->pointType() == KivioPoint::kptArc )
00665         {
00666             pPoint2 = pPointList->next();
00667             pPoint3 = pPointList->next();
00668 
00669             if( !pPoint2 || !pPoint3 )
00670             {
00671                 kdDebug(43000) << "drawClosedPath() - incorrect # of arc points" << endl;
00672                 return;
00673             }
00674             if( pPoint2->pointType() != KivioPoint::kptArc ||
00675                 pPoint3->pointType() != KivioPoint::kptArc )
00676             {
00677                 kdDebug(43000) << "drawClosedPath() - Arc points must come in triplets" << endl;
00678                 return;
00679             }
00680 
00681             tmpPoints.makeArc( qRound(pPoint->x()), qRound(pPoint->y()), qRound(pPoint2->x()), qRound(pPoint2->y()),
00682                                qRound(pPoint3->x()), qRound(pPoint3->y()) );
00683 
00684             for( int j=0; j<int(tmpPoints.size()); j++ )
00685             {
00686                 bPoints.putPoints( pointIndex, 1, tmpPoints.point(j).x(),tmpPoints.point(j).y());
00687                 pointIndex++;
00688             }
00689         } // end pointtype==arc
00690         else
00691         {
00692           kdDebug(43000) << "drawClosedPath() - Unknown point type discovered. WOOO!!!" << endl;
00693         }
00694 
00695         pPoint = pPointList->next();
00696     }
00697 
00698     // If we make it here, the list is built
00699     switch( m_pFillStyle->colorStyle() )
00700     {
00701         case KivioFillStyle::kcsNone:
00702             // A hollow path? That's a polypath!
00703             drawPolyline( bPoints );
00704             break;
00705 
00706         case KivioFillStyle::kcsSolid:
00707         case KivioFillStyle::kcsGradient:
00708         {
00709             drawPolygon(bPoints);
00710             break;
00711         }
00712 
00713         default:
00714             kdDebug(43000) << "drawClosedPath() - Unknown colors style" << endl;
00715             break;
00716     }
00717 }
00718 
00719 void KivioScreenPainter::drawOpenPath( QPtrList<KivioPoint> *pPoints )
00720 {
00721     PAINTER_CHECK();
00722 
00723     QBrush brush;
00724 
00725     KivioPoint *pPoint, *pPoint2, *pPoint3, *pPoint4;
00726     QPtrList <KivioPoint> *pPointList = pPoints;
00727     QPointArray controlPoints(4), bPoints(0), tmpPoints;
00728 
00729     int pointIndex=0;
00730     pPoint = pPointList->first();
00731     while( pPoint )
00732     {
00733         if( pPoint->pointType() == KivioPoint::kptNormal )
00734         {
00735             bPoints.putPoints( pointIndex, 1, int(pPoint->x()), int(pPoint->y()) );
00736             pointIndex++;
00737         }
00738         else if( pPoint->pointType() == KivioPoint::kptBezier )
00739         {
00740             pPoint2 = pPointList->next();
00741             pPoint3 = pPointList->next();
00742             pPoint4 = pPointList->next();
00743 
00744             if( !pPoint2 || !pPoint3 || !pPoint4 )
00745             {
00746                 kdDebug(43000) << "drawOpenPath() - incorrect # of bezier points" << endl;
00747                 return;
00748             }
00749 
00750             if( pPoint2->pointType() != KivioPoint::kptBezier ||
00751                 pPoint3->pointType() != KivioPoint::kptBezier ||
00752                 pPoint4->pointType() != KivioPoint::kptBezier )
00753             {
00754                 kdDebug(43000) << "drawOpenPath() - bezier curves must have 4 points" << endl;
00755                 return;
00756             }
00757 
00758             controlPoints.setPoint( 0, qRound(pPoint->x()), qRound(pPoint->y()) );
00759             controlPoints.setPoint( 1, qRound(pPoint2->x()), qRound(pPoint2->y()) );
00760             controlPoints.setPoint( 2, qRound(pPoint3->x()), qRound(pPoint3->y()) );
00761             controlPoints.setPoint( 3, qRound(pPoint4->x()), qRound(pPoint4->y()) );
00762 
00763             tmpPoints = controlPoints.cubicBezier();
00764 
00765             for( int j=0; j<int(tmpPoints.size()); j++ )
00766             {
00767                 bPoints.putPoints( pointIndex, 1, tmpPoints.point(j).x(), tmpPoints.point(j).y() );
00768                 pointIndex++;
00769             }
00770         } // end pointtype==bezier
00771         else if( pPoint->pointType() == KivioPoint::kptArc )
00772         {
00773             pPoint2 = pPointList->next();
00774             pPoint3 = pPointList->next();
00775 
00776             if( !pPoint2 || !pPoint3 )
00777             {
00778                 kdDebug(43000) << "drawOpenPath() - incorrect # of arc points" << endl;
00779                 return;
00780             }
00781             if( pPoint2->pointType() != KivioPoint::kptArc ||
00782                 pPoint3->pointType() != KivioPoint::kptArc )
00783             {
00784                 kdDebug(43000) << "drawOpenPath() - Arc points must come in triplets" << endl;
00785                 return;
00786             }
00787 
00788             tmpPoints.makeArc( qRound(pPoint->x()), qRound(pPoint->y()), qRound(pPoint2->x()), qRound(pPoint2->y()),
00789                                qRound(pPoint3->x()), qRound(pPoint3->y()) );
00790 
00791             for( int j=0; j<int(tmpPoints.size()); j++ )
00792             {
00793                 bPoints.putPoints( pointIndex, 1, tmpPoints.point(j).x(),tmpPoints.point(j).y());
00794                 pointIndex++;
00795             }
00796         } // end pointtype==arc
00797         else
00798         {
00799             kdDebug(43000) << "drawOpenPath() - Unknown point type discovered. WOOO!!!" << endl;
00800         }
00801 
00802         pPoint = pPointList->next();
00803     }
00804 
00805     m_pPainter->setPen(m_pLineStyle->pen(1.0f));
00806     m_pPainter->setBrush( QBrush::NoBrush );
00807 
00808     m_pPainter->drawPolyline( bPoints );
00809 }
00810 
00811 void KivioScreenPainter::setFont( const QFont &f )
00812 {
00813     PAINTER_CHECK();
00814 
00815     m_pPainter->setFont( f );
00816 }
00817 
00818 void KivioScreenPainter::drawText( int x, int y, int w, int h, int tf, const QString &str )
00819 {
00820     PAINTER_CHECK();
00821 
00822     m_pPainter->setPen( m_textColor );
00823     m_pPainter->drawText( x, y, w, h, tf, str );
00824 /*    QSimpleRichText textArea(str, m_pPainter->font());
00825     textArea.setWidth(w);
00826     QColorGroup cg;
00827     cg.setColor(QColorGroup::Base, m_pFillStyle->color());
00828     cg.setColor(QColorGroup::Text, m_textColor);
00829     QBrush b = m_pFillStyle->brush();
00830     textArea.draw(m_pPainter, x, y, QRect(0, 0, 0, 0), cg, &b);*/
00831 }
00832 
00833 QRect KivioScreenPainter::boundingRect( int x, int y, int w, int h, int tf, const QString &str )
00834 {
00835    PAINTER_CHECK();
00836 
00837    return m_pPainter->boundingRect( x,y,w,h, tf, str );
00838 }
00839 
00840 void KivioScreenPainter::drawPixmap( float x, float y, const QPixmap &pix )
00841 {
00842   PAINTER_CHECK();
00843   m_pPainter->drawPixmap( (int)x, (int)y, pix );
00844 }
00845 
00846 void KivioScreenPainter::drawHandle( float x, float y, int flags )
00847 {
00848   PAINTER_CHECK();
00849   QColor fillColor, penColor;
00850   QBrush b;
00851   QPen p;
00852 
00853   const float HW = 6.0f;
00854   const float HWP1 = HW+1.0f;
00855   const float HWo2 = HW/2.0f;
00856 
00857   float x1, y1;
00858 
00859   // Is it a locked handle?
00860   if( flags & cpfLock )
00861   {
00862     x1 = x - 4;
00863     y1 = y - 4;
00864 
00865     m_pPainter->drawPixmap( qRound(x1), qRound(y1), Kivio::lockPixmap() );
00866     return;
00867   }
00868 
00869   if( flags & cpfConnected )
00870   {
00871     fillColor = QColor(200,0,0);
00872   }
00873   else
00874   {
00875     fillColor = QColor(0,200,0);
00876   }
00877 
00878   penColor.setRgb(0, 0, 0);
00879 
00880   b.setColor(fillColor);
00881   b.setStyle(Qt::SolidPattern);
00882   p.setColor(penColor);
00883   m_pPainter->setPen(p);
00884   m_pPainter->setBrush(b);
00885 
00886 
00887   x1 = x - HWo2;
00888   y1 = y - HWo2;
00889 
00890   // first fill it
00891 //   m_pPainter->fillRect( x1, y1, HWP1, HWP1, b );
00892 
00893   if(flags & cpfEnd) {
00894     m_pPainter->drawEllipse( qRound(x1), qRound(y1), qRound(HWP1), qRound(HWP1) );
00895   } else {
00896     m_pPainter->drawRect( qRound(x1), qRound(y1), qRound(HWP1), qRound(HWP1) );
00897   }
00898 
00899   // Now put something in it if needed
00900   if( flags & cpfConnectable )
00901   {
00902     b.setColor(QColor(0,0,0));
00903 
00904     m_pPainter->fillRect(qRound(x-1),qRound(y-1),3,3, b);
00905   }
00906 }
00907 
00908 void KivioScreenPainter::drawSelectionBox( const QRect& r )
00909 {
00910    PAINTER_CHECK();
00911    QPen p;
00912    p.setColor(QColor(0,200,0));
00913    p.setStyle(Qt::DashLine);
00914    m_pPainter->setBrush(Qt::NoBrush);
00915    m_pPainter->setPen(p);
00916    m_pPainter->drawRect(r);
00917 }
00918 
00919 void KivioScreenPainter::saveState()
00920 {
00921    PAINTER_CHECK();
00922 
00923    m_pPainter->save();
00924 }
00925 
00926 void KivioScreenPainter::restoreState()
00927 {
00928    PAINTER_CHECK();
00929 
00930    m_pPainter->restore();
00931 }
00932 
00933 void KivioScreenPainter::setTranslation( float _x, float _y )
00934 {
00935    PAINTER_CHECK();
00936 
00937    m_transX = _x;
00938    m_transY = _y;
00939 
00940    m_pPainter->translate(_x, _y);
00941 }
00942 
00943 void KivioScreenPainter::translateBy( float _x, float _y )
00944 {
00945    PAINTER_CHECK();
00946 
00947    m_transX += _x;
00948    m_transY += _y;
00949 
00950    m_pPainter->translate( m_transX, m_transY );
00951 }
00952 
00953 void KivioScreenPainter::setRotation( int _d )
00954 {
00955    PAINTER_CHECK();
00956 
00957    m_rotation = _d;
00958 
00959    m_pPainter->rotate(_d);
00960 }
00961 
00962 void KivioScreenPainter::rotateBy( int _d )
00963 {
00964    PAINTER_CHECK();
00965 
00966    m_rotation += _d;
00967 
00968    m_pPainter->rotate(m_rotation);
00969 }
00970 
00971 int KivioScreenPainter::rotation()
00972 {
00973   return m_rotation;
00974 }
00975 
00976 void KivioScreenPainter::setWorldMatrix(QWMatrix m, bool c)
00977 {
00978   PAINTER_CHECK();
00979   m_pPainter->setWorldMatrix(m, c);
00980 }
KDE Home | KDE Accessibility Home | Description of Access Keys