20#include "KPrPBPreview.h"
24#include <KoTextZoomHandler.h>
27KPrPBPreview::KPrPBPreview( TQWidget* parent,
const char* name, PaintType _paintType )
28 : TQFrame( parent, name )
31 _zoomHandler=
new KoTextZoomHandler();
32 paintType = _paintType;
33 pen = KoPen( black, 1, TQt::SolidLine );
34 brush = TQBrush( white, SolidPattern );
35 gradient =
new KPrGradient( TQt::red, TQt::green, BCT_GHORZ,
false, 100, 100 );
36 savedGradient = gradient;
38 setFrameStyle( WinPanel | Sunken );
40 switch ( paintType ) {
45 setMinimumWidth( 230 );
50void KPrPBPreview::resizeEvent( TQResizeEvent *e )
52 TQFrame::resizeEvent( e );
56 gradient->setSize( contentsRect().size() );
62void KPrPBPreview::drawContents( TQPainter *painter )
65 painter->translate( contentsRect().x(), contentsRect().y() );
67 if ( paintType == Pen ) {
68 painter->fillRect( 0, 0, contentsRect().width(), contentsRect().height(),
69 colorGroup().base() );
70 KoSize diff1( 0, 0 ), diff2( 0, 0 );
71 int _w = int( pen.pointWidth() );
73 if ( lineBegin != L_NORMAL )
74 diff1 = getOffset( lineBegin, _w, + 180.0 );
76 if ( lineEnd != L_NORMAL )
77 diff2 = getOffset( lineEnd, _w, 0 );
79 if ( lineBegin != L_NORMAL )
80 drawFigure( lineBegin, painter, KoPoint( 5, _zoomHandler->unzoomItY( contentsRect().height() ) / 2 ),
81 pen.color(), _w, 180.0, _zoomHandler );
83 if ( lineEnd != L_NORMAL )
84 drawFigure( lineEnd, painter, KoPoint( _zoomHandler->unzoomItX( contentsRect().width() - 7 ) ,
85 _zoomHandler->unzoomItY( contentsRect().height() ) / 2 ),
86 pen.color(), _w, 0.0, _zoomHandler );
88 painter->setPen( pen.zoomedPen( _zoomHandler ) );
89 painter->drawLine( - (
int)diff1.width() + 8,
90 contentsRect().height() / 2,
91 contentsRect().width() - (
int)diff2.width() - 7,
92 contentsRect().height() / 2 );
94 }
else if ( paintType == Brush ) {
95 painter->fillRect( 0, 0, contentsRect().width(), contentsRect().height(),
96 colorGroup().base() );
97 painter->fillRect( 0, 0, contentsRect().width(), contentsRect().height(), brush );
98 }
else if ( paintType == Gradient )
99 painter->drawPixmap( 0, 0, gradient->pixmap());
104KPrPBPreview::~KPrPBPreview()
107 delete savedGradient;
111void KPrPBPreview::setGradient(
const TQColor &_c1,
const TQColor &_c2, BCType _t,
112 bool _unbalanced,
int _xfactor,
int _yfactor )
114 gradient->setColor1( _c1 );
115 gradient->setColor2( _c2 );
116 gradient->setBackColorType( _t );
117 gradient->setUnbalanced( _unbalanced );
118 gradient->setXFactor( _xfactor );
119 gradient->setYFactor( _yfactor );
124#include "KPrPBPreview.moc"