kpresenter

KPrTextPreview.cpp
1#include "KPrTextPreview.h"
2
3#include <KoGlobal.h>
4
5#include <tqpainter.h>
6#include <tqfont.h>
7
8KPrTextPreview::KPrTextPreview( TQWidget* parent, const char* name )
9 : TQFrame( parent, name ),
10 shadowDirection( SD_LEFT_BOTTOM ),
11 shadowDistance( 0 ),
12 angle( 0 )
13{
14 setBackgroundColor( white );
15 setFrameStyle( NoFrame );
16}
17
18void KPrTextPreview::drawContents( TQPainter* painter )
19{
20 TQFont font(KoGlobal::defaultFont().family(), 30, TQFont::Bold);
21 TQFontMetrics fm( font );
22
23 TQRect br = fm.boundingRect( "KOffice" );
24 int pw = br.width();
25 int ph = br.height();
26 TQRect r = br;
27 int textYPos = -r.y();
28 int textXPos = -r.x();
29 br.moveTopLeft( TQPoint( -br.width() / 2, -br.height() / 2 ) );
30 r.moveTopLeft( TQPoint( -r.width() / 2, -r.height() / 2 ) );
31
32 int x = r.left() + textXPos;
33 int y = r.top() + textYPos;
34 int sx = 0, sy = 0;
35
36 switch ( shadowDirection )
37 {
38 case SD_LEFT_UP:
39 {
40 sx = x - shadowDistance;
41 sy = y - shadowDistance;
42 } break;
43 case SD_UP:
44 {
45 sx = x;
46 sy = y - shadowDistance;
47 } break;
48 case SD_RIGHT_UP:
49 {
50 sx = x + shadowDistance;
51 sy = y - shadowDistance;
52 } break;
53 case SD_RIGHT:
54 {
55 sx = x + shadowDistance;
56 sy = y;
57 } break;
58 case SD_RIGHT_BOTTOM:
59 {
60 sx = x + shadowDistance;
61 sy = y + shadowDistance;
62 } break;
63 case SD_BOTTOM:
64 {
65 sx = x;
66 sy = y + shadowDistance;
67 } break;
68 case SD_LEFT_BOTTOM:
69 {
70 sx = x - shadowDistance;
71 sy = y + shadowDistance;
72 } break;
73 case SD_LEFT:
74 {
75 sx = x - shadowDistance;
76 sy = y;
77 } break;
78 }
79
80 painter->save();
81
82 painter->setViewport( ( width() - pw ) / 2, ( height() - ph ) / 2, width(), height() );
83
84 TQWMatrix m, mtx;
85 mtx.rotate( angle );
86 m.translate( pw / 2, ph / 2 );
87 m = mtx * m;
88
89 painter->setWorldMatrix( m );
90 painter->setFont( font );
91
92 if ( shadowDistance > 0 ) {
93 painter->setPen( shadowColor );
94 painter->drawText( sx, sy, TQString("KOffice") );
95 }
96 painter->setPen( blue );
97 painter->drawText( x, y, TQString("KOffice") );
98
99 painter->restore();
100}
101#include "KPrTextPreview.moc"