kpresenter

KPrTextPreview.cpp

00001 #include "KPrTextPreview.h"
00002 
00003 #include <KoGlobal.h>
00004 
00005 #include <qpainter.h>
00006 #include <qfont.h>
00007 
00008 KPrTextPreview::KPrTextPreview( QWidget* parent, const char* name )
00009     : QFrame( parent, name ),
00010       shadowDirection( SD_LEFT_BOTTOM ),
00011       shadowDistance( 0 ),
00012       angle( 0 )
00013 {
00014     setBackgroundColor( white );
00015     setFrameStyle( NoFrame );
00016 }
00017 
00018 void KPrTextPreview::drawContents( QPainter* painter )
00019 {
00020     QFont font(KoGlobal::defaultFont().family(), 30, QFont::Bold);
00021     QFontMetrics fm( font );
00022 
00023     QRect br = fm.boundingRect( "KOffice" );
00024     int pw = br.width();
00025     int ph = br.height();
00026     QRect r = br;
00027     int textYPos = -r.y();
00028     int textXPos = -r.x();
00029     br.moveTopLeft( QPoint( -br.width() / 2, -br.height() / 2 ) );
00030     r.moveTopLeft( QPoint( -r.width() / 2, -r.height() / 2 ) );
00031 
00032     int x = r.left() + textXPos;
00033     int y = r.top() + textYPos;
00034     int sx = 0, sy = 0;
00035 
00036     switch ( shadowDirection )
00037     {
00038     case SD_LEFT_UP:
00039     {
00040         sx = x - shadowDistance;
00041         sy = y - shadowDistance;
00042     } break;
00043     case SD_UP:
00044     {
00045         sx = x;
00046         sy = y - shadowDistance;
00047     } break;
00048     case SD_RIGHT_UP:
00049     {
00050         sx = x + shadowDistance;
00051         sy = y - shadowDistance;
00052     } break;
00053     case SD_RIGHT:
00054     {
00055         sx = x + shadowDistance;
00056         sy = y;
00057     } break;
00058     case SD_RIGHT_BOTTOM:
00059     {
00060         sx = x + shadowDistance;
00061         sy = y + shadowDistance;
00062     } break;
00063     case SD_BOTTOM:
00064     {
00065         sx = x;
00066         sy = y + shadowDistance;
00067     } break;
00068     case SD_LEFT_BOTTOM:
00069     {
00070         sx = x - shadowDistance;
00071         sy = y + shadowDistance;
00072     } break;
00073     case SD_LEFT:
00074     {
00075         sx = x - shadowDistance;
00076         sy = y;
00077     } break;
00078     }
00079 
00080     painter->save();
00081 
00082     painter->setViewport( ( width() - pw ) / 2, ( height() - ph ) / 2, width(), height() );
00083 
00084     QWMatrix m, mtx;
00085     mtx.rotate( angle );
00086     m.translate( pw / 2, ph / 2 );
00087     m = mtx * m;
00088 
00089     painter->setWorldMatrix( m );
00090     painter->setFont( font );
00091 
00092     if ( shadowDistance > 0 ) {
00093     painter->setPen( shadowColor );
00094     painter->drawText( sx, sy, "KOffice" );
00095     }
00096     painter->setPen( blue );
00097     painter->drawText( x, y, "KOffice" );
00098 
00099     painter->restore();
00100 }
00101 #include "KPrTextPreview.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys