kpresenter

KPrEllipseObject.cpp
1/* This file is part of the KDE project
2 Copyright (C) 1998, 1999 Reginald Stadlbauer <reggie@kde.org>
3 Copyright (C) 2005 Thorsten Zachmann <zachmann@kde.org>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
19*/
20#include "KPrObject2DIface.h"
21#include "KPrEllipseObject.h"
22#include "KPrGradient.h"
23
24#include <kdebug.h>
25#include <tqbitmap.h>
26#include <tqregion.h>
27#include <tqdom.h>
28#include <tqpicture.h>
29#include <tqpainter.h>
30#include <KoTextZoomHandler.h>
31#include <KoOasisContext.h>
32
33using namespace std;
34
35KPrEllipseObject::KPrEllipseObject()
36 : KPr2DObject()
37{
38}
39
40KPrEllipseObject::KPrEllipseObject( const KoPen &_pen, const TQBrush &_brush, FillType _fillType,
41 const TQColor &_gColor1, const TQColor &_gColor2, BCType _gType,
42 bool _unbalanced, int _xfactor, int _yfactor)
43 : KPr2DObject( _pen, _brush, _fillType, _gColor1, _gColor2, _gType, _unbalanced, _xfactor, _yfactor )
44{
45}
46
47KPrEllipseObject &KPrEllipseObject::operator=( const KPrEllipseObject & )
48{
49 return *this;
50}
51
52DCOPObject* KPrEllipseObject::dcopObject()
53{
54 if ( !dcop )
55 dcop = new KPrObject2DIface( this );
56 return dcop;
57}
58
59void KPrEllipseObject::paint( TQPainter* _painter, KoTextZoomHandler *_zoomHandler,
60 int /* pageNum */, bool drawingShadow, bool drawContour )
61{
62 int ow = _zoomHandler->zoomItX( ext.width() );
63 int oh = _zoomHandler->zoomItY( ext.height() );
64 TQSize size( _zoomHandler->zoomSize( ext ) );
65
66 if ( drawContour ) {
67 TQPen pen3( TQt::black, 1, TQt::DotLine );
68 _painter->setPen( pen3 );
69 _painter->setRasterOp( TQt::NotXorROP );
70 _painter->drawEllipse( 0, 0, ow, oh );
71 return;
72 }
73
74 TQPen pen2 = pen.zoomedPen( _zoomHandler );
75 int pw = ( pen2.style() == TQt::NoPen ) ? 1 : pen2.width();
76 _painter->setPen( pen2 );
77
78 if ( drawingShadow || getFillType() == FT_BRUSH || !gradient )
79 _painter->setBrush( getBrush() );
80 else {
81 if ( m_redrawGradientPix || gradient->size() != size ) {
82 m_redrawGradientPix = false;
83 gradient->setSize( size );
84 TQRegion clipregion( 0, 0, ow - pw + 1, oh - pw + 1, TQRegion::Ellipse );
85 m_gradientPix.resize ( ow, oh );
86 m_gradientPix.fill( TQt::white );
87 TQPainter p;
88 p.begin( &m_gradientPix );
89 p.setClipRegion( clipregion );
90 p.drawPixmap( 0, 0, gradient->pixmap() );
91 p.end();
92
93 m_gradientPix.setMask( m_gradientPix.createHeuristicMask() );
94 }
95
96 _painter->drawPixmap( pw / 2, pw / 2, m_gradientPix, 0, 0, ow - pw + 1, oh - pw + 1 );
97
98 _painter->setBrush( TQt::NoBrush );
99 }
100 _painter->drawEllipse( pw / 2, pw / 2, ow - pw + 1, oh - pw + 1 );
101}
102
103KoSize KPrEllipseObject::getRealSize() const {
104 KoSize size = ext;
105
106 if ( angle != 0.0 ) {
107 float angInRad = angle * M_PI / 180;
108 size.setWidth( sqrt( pow ( ext.width() * cos( angInRad ), 2) +
109 pow ( ext.height() * sin( angInRad ) ,2 ) ) );
110 size.setHeight( sqrt( pow ( ext.width() * sin( angInRad ), 2) +
111 pow ( ext.height() * cos( angInRad ) ,2 ) ) );
112 }
113
114 return size;
115}
116
117bool KPrEllipseObject::saveOasisObjectAttributes( KPOasisSaveContext &/*sc*/ ) const
118{
119 // nothing to do
120 return true;
121}
122
123const char * KPrEllipseObject::getOasisElementName() const
124{
125 return ext.width() == ext.height() ? "draw:circle" : "draw:ellipse";
126}
127