kpresenter

KPrPBPreview.cpp
1/* This file is part of the KDE project
2 Copyright (C) 2004 Thorsten Zachmann <zachmann@kde.org>
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18*/
19
20#include "KPrPBPreview.h"
21
22#include <tqpainter.h>
23
24#include <KoTextZoomHandler.h>
25#include "KPrUtils.h"
26
27KPrPBPreview::KPrPBPreview( TQWidget* parent, const char* name, PaintType _paintType )
28 : TQFrame( parent, name )
29{
30 //FIXME zoom
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;
37
38 setFrameStyle( WinPanel | Sunken );
39
40 switch ( paintType ) {
41 case Pen:
42 setFixedHeight( 40 );
43 break;
44 default:
45 setMinimumWidth( 230 );
46 break;
47 }
48}
49
50void KPrPBPreview::resizeEvent( TQResizeEvent *e )
51{
52 TQFrame::resizeEvent( e );
53 if ( gradient )
54 {
55#if 1
56 gradient->setSize( contentsRect().size() );
57 repaint();
58#endif
59 }
60}
61
62void KPrPBPreview::drawContents( TQPainter *painter )
63{
64 painter->save();
65 painter->translate( contentsRect().x(), contentsRect().y() );
66
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() );
72
73 if ( lineBegin != L_NORMAL )
74 diff1 = getOffset( lineBegin, _w, + 180.0 );
75
76 if ( lineEnd != L_NORMAL )
77 diff2 = getOffset( lineEnd, _w, 0 );
78
79 if ( lineBegin != L_NORMAL )
80 drawFigure( lineBegin, painter, KoPoint( 5, _zoomHandler->unzoomItY( contentsRect().height() ) / 2 ),
81 pen.color(), _w, 180.0, _zoomHandler );
82
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 );
87
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 );
93
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());
100
101 painter->restore();
102}
103
104KPrPBPreview::~KPrPBPreview()
105{
106 delete _zoomHandler;
107 delete savedGradient;
108}
109
110
111void KPrPBPreview::setGradient( const TQColor &_c1, const TQColor &_c2, BCType _t,
112 bool _unbalanced, int _xfactor, int _yfactor )
113{
114 gradient->setColor1( _c1 );
115 gradient->setColor2( _c2 );
116 gradient->setBackColorType( _t );
117 gradient->setUnbalanced( _unbalanced );
118 gradient->setXFactor( _xfactor );
119 gradient->setYFactor( _yfactor );
120 repaint( false );
121}
122
123
124#include "KPrPBPreview.moc"
Class: KPrGradient.
Definition KPrGradient.h:40