21#include "KPrAutoformObject.h"
22#include "KPrAutoFormObjectIface.h"
24#include "KPrGradient.h"
27#include <tqpointarray.h>
33#include <kstandarddirs.h>
35#include <KoTextZoomHandler.h>
39KPrAutoformObject::KPrAutoformObject()
41, KPrStartEndLine( L_NORMAL, L_NORMAL )
46KPrAutoformObject::KPrAutoformObject(
const KoPen & _pen,
const TQBrush &_brush,
const TQString & _filename,
47 LineEnd _lineBegin, LineEnd _lineEnd,
48 FillType _fillType,
const TQColor &_gColor1,
49 const TQColor &_gColor2, BCType _gType,
50 bool _unbalanced,
int _xfactor,
int _yfactor)
51: KPr2DObject( _pen, _brush, _fillType, _gColor1, _gColor2, _gType, _unbalanced, _xfactor, _yfactor )
52, KPrStartEndLine( _lineBegin, _lineEnd )
53, filename( _filename ), atfInterp()
55 atfInterp.load( filename );
58KPrAutoformObject &KPrAutoformObject::operator=(
const KPrAutoformObject & )
63DCOPObject* KPrAutoformObject::dcopObject()
66 dcop =
new KPrAutoFormObjectIface(
this );
70void KPrAutoformObject::setFileName(
const TQString & _filename )
73 atfInterp.load( filename );
77bool KPrAutoformObject::saveOasisObjectAttributes( KPOasisSaveContext &sc )
const
79 kdDebug(33001) <<
"bool KPrAutoformObject::saveOasisObjectAttributes()" << endl;
80 TQSize size(
int( ext.width() * 100 ),
int( ext.height() * 100 ) );
82 sc.xmlWriter.addAttribute(
"svg:viewBox", TQString(
"0 0 %1 %2" ).arg( size.width() )
83 .arg( size.height() ) );
85 TQPointArray points =
const_cast<ATFInterpreter &
>( atfInterp ).getPointArray( size.width(), size.height() );
87 unsigned int pointCount = points.size();
89 bool closed = points.at( 0 ) == points.at( pointCount - 1 );
95 d += TQString(
"M%1 %2" ).arg( points.at(pos).x() )
96 .arg( points.at(pos).y() );
99 while ( pos < pointCount )
101 d += TQString(
"L%1 %2" ).arg( points.at( pos ).x() )
102 .arg( points.at( pos ).y() );
109 sc.xmlWriter.addAttribute(
"svg:d", d );
114void KPrAutoformObject::fillStyle( KoGenStyle& styleObjectAuto, KoGenStyles& mainStyles )
const
116 kdDebug(33001) <<
"KPr2DObject::fillStyle" << endl;
117 KPrShadowObject::fillStyle( styleObjectAuto, mainStyles );
119 TQPointArray points =
const_cast<ATFInterpreter &
>( atfInterp ).getPointArray(
int( ext.width() * 100 ),
120 int( ext.height() * 100 ) );
123 if ( points.at( 0 ) == points.at( points.size() - 1 ) )
125 m_brush.saveOasisFillStyle( styleObjectAuto, mainStyles );
129 saveOasisMarkerElement( mainStyles, styleObjectAuto );
133const char * KPrAutoformObject::getOasisElementName()
const
138TQDomDocumentFragment KPrAutoformObject::save( TQDomDocument& doc,
double offset )
140 TQDomDocumentFragment fragment=KPr2DObject::save(doc, offset);
141 KPrStartEndLine::save( fragment, doc );
146 TQStringList afDirs = KPrFactory::global()->dirs()->resourceDirs(
"autoforms");
147 TQValueList<TQString>::ConstIterator it=afDirs.begin();
149 for( ; it!=afDirs.end(); ++it) {
150 if(filename.startsWith(*it)) {
151 str=filename.mid((*it).length());
155 TQDomElement elem=doc.createElement(
"FILENAME");
156 elem.setAttribute(
"value", str);
157 fragment.appendChild(elem);
161double KPrAutoformObject::load(
const TQDomElement &element)
163 double offset=KPr2DObject::load(element);
164 KPrStartEndLine::load( element );
165 TQDomElement e=element.namedItem(
"FILENAME").toElement();
167 if(e.hasAttribute(
"value"))
168 filename=e.attribute(
"value");
170 if(filename.isEmpty())
171 filename=
"Connections/.source/Connection1.atf";
173 if(filename[0]==
'/') {
174 kdDebug(33001) <<
"rubbish ahead! cleaning up..." << endl;
176 filename=filename.mid(filename.findRev(
'/', filename.findRev(
'/')-1)+1);
182 if(filename.find(
".source")==-1) {
184 filename=filename.insert(filename.find(
'/'),
"/.source");
186 filename = locate(
"autoforms", filename, KPrFactory::global());
187 atfInterp.load( filename );
192void KPrAutoformObject::paint( TQPainter* _painter, KoTextZoomHandler *_zoomHandler,
193 int ,
bool drawingShadow,
bool drawContour )
195 unsigned int pw = 0, pwOrig = 0, px, py;
197 TQSize size( _zoomHandler->zoomSize( ext ) );
200 pen2 = TQPen( TQt::black, 1, TQt::DotLine );
202 pen2 = pen.zoomedPen( _zoomHandler );
205 _painter->setPen( pen2 );
206 pwOrig = ( pen2.style() == TQt::NoPen ) ? 1 : pen2.width();
208 _painter->setBrush( getBrush() );
210 TQPointArray pntArray = atfInterp.getPointArray( _zoomHandler->zoomItX( ext.width()),
211 _zoomHandler->zoomItY( ext.height() ) );
212 TQPtrList<ATFInterpreter::AttribList> atrLs = atfInterp.getAttribList();
213 TQPointArray pntArray2( pntArray.size() );
214 int ex = _zoomHandler->zoomItX(ext.width());
215 int ey = _zoomHandler->zoomItY(ext.height());
216 for (
unsigned int i = 0; i < pntArray.size(); i++ )
218 px = pntArray.at( i ).x();
219 py = pntArray.at( i ).y();
220 if ( atrLs.at( i )->pwDiv > 0 )
222 pw = pwOrig / atrLs.at( i )->pwDiv;
223 px = (int)((
double)(ex - pw) / (
double)ex * px + pw / 2);
224 py = (int)((
double)(ey - pw) / (
double)ey * py + pw / 2);
226 pntArray2.setPoint( i, px, py );
229 if ( pntArray2.size() > 0 )
231 if ( pntArray2.at( 0 ) == pntArray2.at( pntArray2.size() - 1 ) )
233 if ( drawContour || (drawingShadow || getFillType() == FT_BRUSH || !gradient) )
234 _painter->drawPolygon( pntArray2 );
237 if ( angle == 0 || angle==360 )
242 TQPointArray pntArray3 = pntArray2.copy();
245 TQRegion clipregion( pntArray3 );
248 if ( _painter->hasClipping() )
249 clipregion = _painter->clipRegion(TQPainter::CoordPainter).intersect( clipregion );
251 _painter->setClipRegion( clipregion, TQPainter::CoordPainter );
253 gradient->setSize( size );
254 _painter->drawPixmap( 0, 0, gradient->pixmap() );
260 if ( m_redrawGradientPix || gradient->size() != size )
262 kdDebug(33001) <<
"KPrAutoformObject::draw redrawPix" << endl;
263 gradient->setSize( size );
264 m_redrawGradientPix =
false;
265 TQRegion clipregion( pntArray2 );
266 m_gradientPix.resize ( _zoomHandler->zoomItX(ext.width()),_zoomHandler->zoomItY(ext.height()) );
267 m_gradientPix.fill( TQt::white );
271 p.begin( &m_gradientPix );
272 p.setClipRegion( clipregion , TQPainter::CoordPainter);
273 p.drawPixmap( 0, 0, gradient->pixmap() );
276 m_gradientPix.setMask( m_gradientPix.createHeuristicMask() );
279 _painter->drawPixmap( 0, 0, m_gradientPix );
282 _painter->setPen( pen2 );
283 _painter->setBrush( TQt::NoBrush );
284 _painter->drawPolygon( pntArray2 );
289 KoSize diff1( 0, 0 ), diff2( 0, 0 );
290 int _w = int( pen.pointWidth() );
292 if ( lineBegin != L_NORMAL )
293 diff1 = getBoundingSize( lineBegin, _w, _zoomHandler );
295 if ( lineEnd != L_NORMAL )
296 diff2 = getBoundingSize( lineEnd, _w, _zoomHandler );
298 if ( pntArray.size() > 1 )
300 if ( lineBegin != L_NORMAL && !drawContour )
302 TQPoint pnt1( pntArray2.at( 0 ) ), pnt2( pntArray2.at( 1 ) );
303 TQPoint pnt3, pnt4( pntArray.at( 0 ) );
304 float _angle = KoPoint::getAngle( KoPoint( pnt1 ), KoPoint( pnt2 ) );
306 switch (
static_cast<int>( _angle ) )
310 pnt3.setX( pnt4.x() - (
int)diff1.width() / 2 );
311 pnt3.setY( pnt1.y() );
315 pnt3.setX( pnt4.x() + (
int)diff1.width() / 2 );
316 pnt3.setY( pnt1.y() );
320 pnt3.setX( pnt1.x() );
321 pnt3.setY( pnt4.y() - (
int)diff1.width() / 2 );
325 pnt3.setX( pnt1.x() );
326 pnt3.setY( pnt4.y() + (
int)diff1.width() / 2 );
333 drawFigure( lineBegin, _painter, _zoomHandler->unzoomPoint( pnt3 ), pen2.color(), _w, _angle, _zoomHandler );
336 if ( lineEnd != L_NORMAL && !drawContour )
338 TQPoint pnt1( pntArray2.at( pntArray2.size() - 1 ) ), pnt2( pntArray2.at( pntArray2.size() - 2 ) );
339 TQPoint pnt3, pnt4( pntArray.at( pntArray.size() - 1 ) );
340 float _angle = KoPoint::getAngle( KoPoint( pnt1 ), KoPoint( pnt2 ) );
342 switch ( (
int )_angle )
346 pnt3.setX( pnt4.x() - (
int)diff2.width() / 2 );
347 pnt3.setY( pnt1.y() );
351 pnt3.setX( pnt4.x() + (
int)diff2.width() / 2 );
352 pnt3.setY( pnt1.y() );
356 pnt3.setX( pnt1.x() );
357 pnt3.setY( pnt4.y() - (
int)diff2.width() / 2 );
361 pnt3.setX( pnt1.x() );
362 pnt3.setY( pnt4.y() + (
int)diff2.width() / 2 );
369 drawFigure( lineEnd, _painter, _zoomHandler->unzoomPoint( pnt3 ), pen2.color(), _w, _angle,_zoomHandler );
373 _painter->setPen( pen2 );
374 _painter->drawPolyline( pntArray2 );