00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "KPrObject2DIface.h"
00022 #include "KPrEllipseObject.h"
00023 #include "KPrGradient.h"
00024
00025 #include <kdebug.h>
00026 #include <qbitmap.h>
00027 #include <qregion.h>
00028 #include <qdom.h>
00029 #include <qpicture.h>
00030 #include <qpainter.h>
00031 #include <KoTextZoomHandler.h>
00032 #include <KoOasisContext.h>
00033
00034 using namespace std;
00035
00036 KPrEllipseObject::KPrEllipseObject()
00037 : KPr2DObject()
00038 {
00039 }
00040
00041 KPrEllipseObject::KPrEllipseObject( const KoPen &_pen, const QBrush &_brush, FillType _fillType,
00042 const QColor &_gColor1, const QColor &_gColor2, BCType _gType,
00043 bool _unbalanced, int _xfactor, int _yfactor)
00044 : KPr2DObject( _pen, _brush, _fillType, _gColor1, _gColor2, _gType, _unbalanced, _xfactor, _yfactor )
00045 {
00046 }
00047
00048 KPrEllipseObject &KPrEllipseObject::operator=( const KPrEllipseObject & )
00049 {
00050 return *this;
00051 }
00052
00053 DCOPObject* KPrEllipseObject::dcopObject()
00054 {
00055 if ( !dcop )
00056 dcop = new KPrObject2DIface( this );
00057 return dcop;
00058 }
00059
00060 void KPrEllipseObject::paint( QPainter* _painter, KoTextZoomHandler *_zoomHandler,
00061 int , bool drawingShadow, bool drawContour )
00062 {
00063 int ow = _zoomHandler->zoomItX( ext.width() );
00064 int oh = _zoomHandler->zoomItY( ext.height() );
00065 QSize size( _zoomHandler->zoomSize( ext ) );
00066
00067 if ( drawContour ) {
00068 QPen pen3( Qt::black, 1, Qt::DotLine );
00069 _painter->setPen( pen3 );
00070 _painter->setRasterOp( Qt::NotXorROP );
00071 _painter->drawEllipse( 0, 0, ow, oh );
00072 return;
00073 }
00074
00075 QPen pen2 = pen.zoomedPen( _zoomHandler );
00076 int pw = ( pen2.style() == Qt::NoPen ) ? 1 : pen2.width();
00077 _painter->setPen( pen2 );
00078
00079 if ( drawingShadow || getFillType() == FT_BRUSH || !gradient )
00080 _painter->setBrush( getBrush() );
00081 else {
00082 if ( m_redrawGradientPix || gradient->size() != size ) {
00083 m_redrawGradientPix = false;
00084 gradient->setSize( size );
00085 QRegion clipregion( 0, 0, ow - pw + 1, oh - pw + 1, QRegion::Ellipse );
00086 m_gradientPix.resize ( ow, oh );
00087 m_gradientPix.fill( Qt::white );
00088 QPainter p;
00089 p.begin( &m_gradientPix );
00090 p.setClipRegion( clipregion );
00091 p.drawPixmap( 0, 0, gradient->pixmap() );
00092 p.end();
00093
00094 m_gradientPix.setMask( m_gradientPix.createHeuristicMask() );
00095 }
00096
00097 _painter->drawPixmap( pw / 2, pw / 2, m_gradientPix, 0, 0, ow - pw + 1, oh - pw + 1 );
00098
00099 _painter->setBrush( Qt::NoBrush );
00100 }
00101 _painter->drawEllipse( pw / 2, pw / 2, ow - pw + 1, oh - pw + 1 );
00102 }
00103
00104 KoSize KPrEllipseObject::getRealSize() const {
00105 KoSize size = ext;
00106
00107 if ( angle != 0.0 ) {
00108 float angInRad = angle * M_PI / 180;
00109 size.setWidth( sqrt( pow ( ext.width() * cos( angInRad ), 2) +
00110 pow ( ext.height() * sin( angInRad ) ,2 ) ) );
00111 size.setHeight( sqrt( pow ( ext.width() * sin( angInRad ), 2) +
00112 pow ( ext.height() * cos( angInRad ) ,2 ) ) );
00113 }
00114
00115 return size;
00116 }
00117
00118 bool KPrEllipseObject::saveOasisObjectAttributes( KPOasisSaveContext & ) const
00119 {
00120
00121 return true;
00122 }
00123
00124 const char * KPrEllipseObject::getOasisElementName() const
00125 {
00126 return ext.width() == ext.height() ? "draw:circle" : "draw:ellipse";
00127 }
00128