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