21#include "KPrLineObject.h"
23#include "KPrDocument.h"
24#include "KPrLineObjectIface.h"
25#include "KoPointArray.h"
26#include <KoStyleStack.h>
27#include <KoOasisContext.h>
34#include <KoTextZoomHandler.h>
41KPrLineObject::KPrLineObject()
47KPrLineObject::KPrLineObject(
const KoPen &_pen, LineEnd _lineBegin,
48 LineEnd _lineEnd, LineType _lineType )
54KPrLineObject &KPrLineObject::operator=(
const KPrLineObject & )
59DCOPObject* KPrLineObject::dcopObject()
62 dcop =
new KPrLineObjectIface(
this );
67void KPrLineObject::fillStyle( KoGenStyle& styleObjectAuto, KoGenStyles& mainStyles )
const
69 KPrShadowObject::fillStyle( styleObjectAuto, mainStyles );
70 saveOasisMarkerElement( mainStyles, styleObjectAuto );
74bool KPrLineObject::saveOasisObjectAttributes( KPOasisSaveContext & )
const
80void KPrLineObject::saveOasisPosObject( KoXmlWriter &xmlWriter,
int indexObj )
const
82 xmlWriter.addAttribute(
"draw:id",
"object" + TQString::number( indexObj ) );
88 KoPoint center( ext.width() / 2, ext.height() / 2 );
113 if ( kAbs( angle ) > 1E-6 )
115 double angInRad = -angle * M_PI / 180.0;
116 TQWMatrix m( cos( angInRad ), -sin( angInRad ), sin( angInRad ), cos( angInRad ), 0, 0 );
117 double transX1 = 0.0;
118 double transY1 = 0.0;
119 double transX2 = 0.0;
120 double transY2 = 0.0;
121 m.map( x1, y1, &transX1, &transY1 );
122 m.map( x2, y2, &transX2, &transY2 );
129 x1 += orig.x() + center.x();
130 y1 += orig.y() + center.y();
131 x2 += orig.x() + center.x();
132 y2 += orig.y() + center.y();
135 xmlWriter.addAttributePt(
"svg:x1", x1 );
136 xmlWriter.addAttributePt(
"svg:y1", y1 );
137 xmlWriter.addAttributePt(
"svg:x2", x2 );
138 xmlWriter.addAttributePt(
"svg:y2", y2 );
141const char * KPrLineObject::getOasisElementName()
const
146TQDomDocumentFragment KPrLineObject::save( TQDomDocument& doc,
double offset )
148 TQDomDocumentFragment fragment=KPrShadowObject::save(doc, offset);
149 if (lineType!=LT_HORZ)
150 fragment.appendChild(KPrObject::createValueElement(
"LINETYPE",
static_cast<int>(lineType), doc));
151 KPrStartEndLine::save( fragment, doc );
155void KPrLineObject::loadOasis(
const TQDomElement &element, KoOasisContext & context,
KPrLoadingInfo *info)
157 KPrShadowObject::loadOasis(element, context, info);
159 double x1 = KoUnit::parseValue( element.attributeNS( KoXmlNS::svg,
"x1", TQString() ) );
160 double y1 = KoUnit::parseValue( element.attributeNS( KoXmlNS::svg,
"y1", TQString() ) );
161 double x2 = KoUnit::parseValue( element.attributeNS( KoXmlNS::svg,
"x2", TQString() ) );
162 double y2 = KoUnit::parseValue( element.attributeNS( KoXmlNS::svg,
"y2", TQString() ) );
164 kdDebug()<<
" KPrLineObject::loadOasis(const TQDomElement &element) : x1 "<< x1 <<
" y1 : "<<y1<<
" x2 :"<<x2 <<
" y2 "<<y2<<endl;
165 double x = TQMIN( x1, x2 );
166 double y = TQMIN( y1, y2 );
171 ext.setWidth( fabs( x1 - x2 ) );
172 ext.setHeight( fabs( y1 - y2 ) );
179 orig.setY( y - 5.0 );
186 orig.setX( x - 5.0 );
188 else if ( ( x1 < x2 && y1 < y2 ) || ( x1 > x2 && y1 > y2 ) )
193 kdDebug()<<
"KPrLineObject::loadOasis(const TQDomElement &element) : real position x :"<<orig.x()<<
" y "<<orig.y()<<
" width :"<<ext.width()<<
" height :"<<ext.height()<<endl;
195 TQString attr = (x1 <= x2) ?
"marker-start" :
"marker-end";
196 loadOasisMarkerElement( context, attr, lineBegin );
198 attr = (x1 <= x2) ?
"marker-end" :
"marker-start";
199 loadOasisMarkerElement( context, attr, lineEnd );
202double KPrLineObject::load(
const TQDomElement &element)
204 double offset=KPrShadowObject::load(element);
205 TQDomElement e=element.namedItem(
"LINETYPE").toElement();
208 if(e.hasAttribute(
"value"))
209 tmp=e.attribute(
"value").toInt();
210 lineType=
static_cast<LineType
>(tmp);
212 KPrStartEndLine::load( element );
216void KPrLineObject::paint( TQPainter* _painter, KoTextZoomHandler*_zoomHandler,
217 int ,
bool ,
bool drawContour )
219 double ow = ext.width();
220 double oh = ext.height();
221 int _w = int( pen.pointWidth() );
225 pen2 = TQPen( TQt::black, 1, TQt::DotLine );
226 _painter->setRasterOp( TQt::NotXorROP );
229 pen2 = pen.zoomedPen( _zoomHandler );
231 _painter->setPen( pen2 );
234 KoSize diff1( 0, 0 ), diff2( 0, 0 );
246 KoRect _rect = KoRect( orig, ext );
247 KoPoint pnt1 = _rect.topLeft();
248 KoPoint pnt2 = _rect.bottomRight();
250 _angle = KoPoint::getAngle( pnt1, pnt2 ) - 180.0;
253 KoRect _rect = KoRect( orig, ext );
254 KoPoint pnt1 = _rect.bottomLeft();
255 KoPoint pnt2 = _rect.topRight();
257 _angle = KoPoint::getAngle( pnt1, pnt2 ) - 180.0;
261 if ( lineBegin != L_NORMAL )
262 diff1 = getOffset( lineBegin, _w, _angle + 180.0);
264 if ( lineEnd != L_NORMAL )
265 diff2 = getOffset( lineEnd, _w, _angle );
270 if ( lineBegin != L_NORMAL && !drawContour )
271 drawFigure( lineBegin, _painter,
272 KoPoint( 0, oh / 2.0 ),
273 pen2.color(), _w, 180.0, _zoomHandler );
275 if ( lineEnd != L_NORMAL && !drawContour )
276 drawFigure( lineEnd, _painter,
277 KoPoint( ow , oh / 2.0),
278 pen2.color(), _w, 0.0, _zoomHandler );
280 _painter->drawLine( _zoomHandler->zoomItX( - diff1.width() ),
281 _zoomHandler->zoomItY( oh / 2 ),
282 _zoomHandler->zoomItX( ow - diff2.width() ),
283 _zoomHandler->zoomItY( oh / 2 ) );
286 if ( lineBegin != L_NORMAL && !drawContour )
287 drawFigure( lineBegin, _painter,
288 KoPoint( ow / 2.0, 0 ),
289 pen2.color(), _w, 270.0, _zoomHandler );
291 if ( lineEnd != L_NORMAL && !drawContour )
292 drawFigure( lineEnd, _painter,
293 KoPoint( ow / 2.0, oh ),
294 pen2.color(), _w, 90.0, _zoomHandler );
296 _painter->drawLine( _zoomHandler->zoomItX( ow / 2 ),
297 _zoomHandler->zoomItX( - diff1.height() ),
298 _zoomHandler->zoomItX( ow / 2 ),
299 _zoomHandler->zoomItY( oh - diff2.height() ) );
302 if ( lineBegin != L_NORMAL && !drawContour ) {
304 drawFigure( lineBegin, _painter,
305 KoPoint( 0, 0 ), pen2.color(),
306 _w, _angle + 180, _zoomHandler );
309 if ( lineEnd != L_NORMAL && !drawContour ) {
311 _painter->translate( _zoomHandler->zoomItX( ow ),
312 _zoomHandler->zoomItY( oh ) );
313 drawFigure( lineEnd, _painter,
314 KoPoint( 0, 0 ), pen2.color(),
315 _w, _angle, _zoomHandler );
319 _painter->drawLine( _zoomHandler->zoomItX( - diff1.width() ),
320 _zoomHandler->zoomItY( - diff1.height() ),
321 _zoomHandler->zoomItX( ow - diff2.width() ),
322 _zoomHandler->zoomItY( oh - diff2.height() ) );
325 if ( lineBegin != L_NORMAL && !drawContour ) {
327 _painter->translate( _zoomHandler->zoomItX( 0 ),
328 _zoomHandler->zoomItY( oh ) );
329 drawFigure( lineBegin, _painter,
330 KoPoint( 0, 0 ), pen2.color(),
331 _w, _angle + 180,_zoomHandler );
334 if ( lineEnd != L_NORMAL && !drawContour ) {
336 _painter->translate( _zoomHandler->zoomItX( ow ),
337 _zoomHandler->zoomItY( 0 ) );
338 drawFigure( lineEnd, _painter,
339 KoPoint( 0, 0 ), pen2.color(),
340 _w, _angle,_zoomHandler );
343 _painter->drawLine( _zoomHandler->zoomItX( - diff1.width() ),
344 _zoomHandler->zoomItY( oh - diff1.height() ),
345 _zoomHandler->zoomItX( ow - diff2.width() ),
346 _zoomHandler->zoomItY( - diff2.height() ));
351void KPrLineObject::flip(
bool horizontal )
353 KPrObject::flip( horizontal );
356 if ( lineType == LT_LU_RD )
358 else if ( lineType == LT_LD_RU )
363 if ( lineType == LT_LU_RD )
365 else if ( lineType == LT_LD_RU )
368 LineEnd tmp = lineBegin;
374KoSize KPrLineObject::getRealSize()
const {
375 KoPoint realOrig( orig );
378 KoPointArray points(4);
380 if ( lineType == LT_LU_RD || lineType == LT_LD_RU )
382 double objAngle = atan( ext.width() / ext.height() );
383 double x = cos( objAngle ) * pen.pointWidth();
384 double y = sin( objAngle ) * pen.pointWidth();
386 if ( lineType == LT_LU_RD )
388 points.setPoint( 0, x, 0 );
389 points.setPoint( 1, 0, y );
390 points.setPoint( 2, ext.width() + x, ext.height() );
391 points.setPoint( 3, ext.width(), ext.height() + y );
395 points.setPoint( 0, 0, ext.height() );
396 points.setPoint( 1, x, ext.height() + y );
397 points.setPoint( 2, ext.width(), 0 );
398 points.setPoint( 3, ext.width() + x, y );
400 realOrig.setX( realOrig.x() - x / 2.0 );
401 realOrig.setY( realOrig.y() - y / 2.0 );
402 size.setWidth( size.width() + x );
403 size.setHeight( size.height() + y );
406 if ( angle == 0.0 && lineType == LT_HORZ )
408 size.setHeight( pen.pointWidth() );
410 else if ( angle == 0.0 && lineType == LT_VERT )
412 size.setWidth( pen.pointWidth() );
416 if ( lineType == LT_HORZ )
418 points.setPoint( 0, 0, ( ext.height() - pen.pointWidth() ) / 2.0 );
419 points.setPoint( 1, 0, ( ext.height() + pen.pointWidth() ) / 2.0 );
420 points.setPoint( 2, ext.width(), ( ext.height() - pen.pointWidth() ) / 2.0 );
421 points.setPoint( 3, ext.width(), ( ext.height() + pen.pointWidth() ) / 2.0 );
423 else if ( lineType == LT_VERT )
425 points.setPoint( 0, ( ext.width() - pen.pointWidth() ) / 2.0, 0 );
426 points.setPoint( 1, ( ext.width() + pen.pointWidth() ) / 2.0, 0 );
427 points.setPoint( 2, ( ext.width() - pen.pointWidth() ) / 2.0, ext.height() );
428 points.setPoint( 3, ( ext.width() + pen.pointWidth() ) / 2.0, ext.height() );
431 getRealSizeAndOrigFromPoints( points, angle, size, realOrig );
437KoPoint KPrLineObject::getRealOrig()
const {
438 KoPoint realOrig( orig );
441 KoPointArray points(4);
443 if ( lineType == LT_LU_RD || lineType == LT_LD_RU )
445 double objAngle = atan( ext.width() / ext.height() );
446 double x = cos( objAngle ) * pen.pointWidth();
447 double y = sin( objAngle ) * pen.pointWidth();
449 if ( lineType == LT_LU_RD )
451 points.setPoint( 0, x, 0 );
452 points.setPoint( 1, 0, y );
453 points.setPoint( 2, ext.width() + x, ext.height() );
454 points.setPoint( 3, ext.width(), ext.height() + y );
458 points.setPoint( 0, 0, ext.height() );
459 points.setPoint( 1, x, ext.height() + y );
460 points.setPoint( 2, ext.width(), 0 );
461 points.setPoint( 3, ext.width() + x, y );
463 realOrig.setX( realOrig.x() - x / 2.0 );
464 realOrig.setY( realOrig.y() - y / 2.0 );
465 size.setWidth( size.width() + x );
466 size.setHeight( size.height() + y );
469 if ( angle == 0.0 && lineType == LT_HORZ )
471 realOrig.setY( realOrig.y() + ( ext.height() - pen.pointWidth() ) / 2.0 );
473 else if ( angle == 0.0 && lineType == LT_VERT )
475 realOrig.setX( realOrig.x() + ( ext.width() - pen.pointWidth() ) / 2.0 );
479 if ( lineType == LT_HORZ )
481 points.setPoint( 0, 0, ( ext.height() - pen.pointWidth() ) / 2.0 );
482 points.setPoint( 1, 0, ( ext.height() + pen.pointWidth() ) / 2.0 );
483 points.setPoint( 2, ext.width(), ( ext.height() - pen.pointWidth() ) / 2.0 );
484 points.setPoint( 3, ext.width(), ( ext.height() + pen.pointWidth() ) / 2.0 );
486 else if ( lineType == LT_VERT )
488 points.setPoint( 0, ( ext.width() - pen.pointWidth() ) / 2.0, 0 );
489 points.setPoint( 1, ( ext.width() + pen.pointWidth() ) / 2.0, 0 );
490 points.setPoint( 2, ( ext.width() - pen.pointWidth() ) / 2.0, ext.height() );
491 points.setPoint( 3, ( ext.width() + pen.pointWidth() ) / 2.0, ext.height() );
494 getRealSizeAndOrigFromPoints( points, angle, size, realOrig );
Temporary information used only during loading.
Base class for objects with a pen and a brush, and which takes care of painting the shadow in draw() ...