kivio

kivio_sml_stencil.cpp
1/*
2 * Kivio - Visual Modelling and Flowcharting
3 * Copyright (C) 2000-2003 theKompany.com & Dave Marotti
4 * Peter Simonsson
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 */
20#include "kivioglobal.h"
21#include "kivio_common.h"
22#include "kivio_connector_point.h"
23#include "kivio_connector_target.h"
24#include "kivio_fill_style.h"
25#include "kivio_intra_stencil_data.h"
26#include "kivio_line_style.h"
27#include "kivio_painter.h"
28#include "kivio_screen_painter.h"
29#include "kivio_shape.h"
30#include "kivio_shape_data.h"
31#include "kivio_sml_stencil.h"
32#include "kivio_dia_stencil_spawner.h"
33#include "kivio_sml_stencil_spawner.h"
34#include "kivio_stencil_spawner.h"
35#include "kivio_stencil_spawner_info.h"
36#include "kivio_stencil_spawner_set.h"
37
38#include <tqdom.h>
39#include <tqpainter.h>
40#include <tqbrush.h>
41#include <tqcolor.h>
42#include <tqpalette.h>
43#include <tqrect.h>
44#include <tqbitmap.h>
45#include <kdebug.h>
46#include <KoGlobal.h>
47#include <math.h>
48#include <KoZoomHandler.h>
49
55KivioSMLStencil::KivioSMLStencil()
56 : KivioStencil(),
57 m_pShapeList(NULL),
58 m_pSubSelection(NULL),
59 m_pConnectorTargets(NULL)
60{
61 m_pShapeList = new TQPtrList<KivioShape>;
62 m_pShapeList->setAutoDelete(true);
63
64 m_pConnectorTargets = new TQPtrList<KivioConnectorTarget>;
65 m_pConnectorTargets->setAutoDelete(true);
66}
67
68
74KivioSMLStencil::~KivioSMLStencil()
75{
76 delete m_pShapeList;
77 m_pShapeList = 0;
78
79 delete m_pConnectorTargets;
80 m_pConnectorTargets = 0;
81
82 m_pSubSelection = 0;
83}
84
85
89bool KivioSMLStencil::loadXML( const TQDomElement &e )
90{
91 TQDomNode node;
92 TQDomElement ele;
93
94
95 node = e.firstChild();
96 while( !node.isNull() )
97 {
98 TQString nodeName = node.nodeName();
99
100 ele = node.toElement();
101
102 if( nodeName == "Position" )
103 {
104 m_x = XmlReadFloat( ele, "x", 0.0f );
105 m_y = XmlReadFloat( ele, "y", 0.0f );
106 }
107 else if( nodeName == "Dimension" )
108 {
109 m_w = XmlReadFloat( ele, "w", 0.0f );
110 m_h = XmlReadFloat( ele, "h", 0.0f );
111 }
112 else if( nodeName == "KivioShape" )
113 {
114 // Locate the shape we are supposed to load into
115 KivioShape *pShape = locateShape( XmlReadString( ele, "name", "" ) );
116
117 if(pShape) {
118 pShape->loadXML( ele );
119 }
120 }
121 else if( nodeName == "KivioConnectorTargetList" )
122 {
123 loadConnectorTargetListXML( ele );
124 }
125
126 node = node.nextSibling();
127 }
128 return true;
129}
130
134void KivioSMLStencil::loadConnectorTargetListXML( const TQDomElement &e )
135{
136 TQDomNode node;
137 TQDomElement ele;
138 TQString nodeName;
139 KivioConnectorTarget *pTarget;
140
141 pTarget = m_pConnectorTargets->first();
142 node = e.firstChild();
143 while( !node.isNull() && pTarget)
144 {
145 nodeName = node.nodeName();
146 ele = node.toElement();
147
148 if( nodeName == "KivioConnectorTarget" )
149 {
150 pTarget->loadXML( ele );
151 pTarget->setOffsets((pTarget->x() - x()) / w(), (pTarget->y() - y()) / h());
152 pTarget = m_pConnectorTargets->next();
153 }
154
155 node = node.nextSibling();
156 }
157
158 while(!node.isNull()) {
159 nodeName = node.nodeName();
160 ele = node.toElement();
161
162 if( nodeName == "KivioConnectorTarget" )
163 {
164 pTarget = new KivioConnectorTarget();
165 pTarget->loadXML( ele );
166 pTarget->setOffsets((pTarget->x() - x()) / w(), (pTarget->y() -y()) / h());
167 m_pConnectorTargets->append(pTarget);
168 }
169
170 node = node.nextSibling();
171 }
172}
173
174
178KivioShape *KivioSMLStencil::locateShape( const TQString &name )
179{
180 KivioShape *pShape;
181
182 if( name.isEmpty() )
183 return NULL;
184
185 pShape = m_pShapeList->first();
186 while( pShape )
187 {
188 if( pShape->shapeData()->name() == name )
189 {
190 return pShape;
191 }
192
193 pShape = m_pShapeList->next();
194 }
195
196 return NULL;
197}
198
199
203TQDomElement KivioSMLStencil::saveXML( TQDomDocument &doc )
204{
205 TQDomElement e = doc.createElement("KivioSMLStencil");
206
207 XmlWriteString( e, "id", m_pSpawner->info()->id() );
208 XmlWriteString( e, "setId", m_pSpawner->set()->id() );
209
210
211 // The positions
212 TQDomElement posE = doc.createElement("Position");
213 XmlWriteFloat( posE, "x", m_x );
214 XmlWriteFloat( posE, "y", m_y );
215 e.appendChild( posE );
216
217 // The dimensions
218 TQDomElement dimE = doc.createElement("Dimension");
219 XmlWriteFloat( dimE, "w", m_w );
220 XmlWriteFloat( dimE, "h", m_h );
221 e.appendChild( dimE );
222
223 // Save the target list
224 TQDomElement clE = doc.createElement("KivioConnectorTargetList");
225 TQDomElement targetE;
226 KivioConnectorTarget *pTarget = m_pConnectorTargets->first();
227 while( pTarget )
228 {
229 targetE = pTarget->saveXML( doc );
230 clE.appendChild( targetE );
231
232 pTarget = m_pConnectorTargets->next();
233 }
234 e.appendChild( clE );
235
236 // The shape list
237 KivioShape *pShape = m_pShapeList->first();
238 while( pShape )
239 {
240 e.appendChild( pShape->saveXML(doc ) );
241
242 pShape = m_pShapeList->next();
243 }
244
245 return e;
246}
247
248
255KivioStencil *KivioSMLStencil::duplicate()
256{
257 KivioSMLStencil *pNewStencil = new KivioSMLStencil();
258 KivioStencil *pReturn;
259 KivioShape *pShape, *pNewShape;
260
261 pNewStencil->m_x = m_x;
262 pNewStencil->m_y = m_y;
263 pNewStencil->m_w = m_w;
264 pNewStencil->m_h = m_h;
265
266 pNewStencil->m_rotation = m_rotation;
267
268 pNewStencil->m_pSpawner = m_pSpawner;
269
270
271 // Copy the shape list
272 pShape = m_pShapeList->first();
273 while( pShape )
274 {
275 pNewShape = new KivioShape( *pShape );
276 pNewStencil->m_pShapeList->append( pNewShape );
277
278 pShape = m_pShapeList->next();
279 }
280
281 // Copy the Connector Targets
282 KivioConnectorTarget *pTarget = m_pConnectorTargets->first();
283
284 while( pTarget ) //&& pOriginal )
285 {
286 pNewStencil->m_pConnectorTargets->append( pTarget->duplicate() );
287 pTarget = m_pConnectorTargets->next();
288 }
289
290 *(pNewStencil->protection()) = *m_pProtection;
291 *(pNewStencil->canProtect()) = *m_pCanProtect;
292
293
294 pReturn = pNewStencil;
295
296 return pReturn;
297}
298
299
303void KivioSMLStencil::paintOutline( KivioIntraStencilData *pData )
304{
305 KivioShape *pShape;
306 KivioShapeData *pShapeData;
307
308 m_zoomHandler = pData->zoomHandler;
309 pData->painter->saveState();
310 pData->painter->setTranslation(m_zoomHandler->zoomItX(m_x), m_zoomHandler->zoomItY(m_y));
311 rotatePainter(pData); // Rotate the painter if needed
312
313 pShape = m_pShapeList->first();
314 while( pShape )
315 {
316 pShapeData = pShape->shapeData();
317
318 switch( pShapeData->shapeType() )
319 {
320 case KivioShapeData::kstArc:
321 drawOutlineArc( pShape, pData );
322 break;
323
324 case KivioShapeData::kstPie:
325 drawOutlinePie( pShape, pData );
326 break;
327
328 case KivioShapeData::kstLineArray:
329 drawOutlineLineArray( pShape, pData );
330 break;
331
332 case KivioShapeData::kstPolyline:
333 drawOutlinePolyline( pShape, pData );
334 break;
335
336 case KivioShapeData::kstPolygon:
337 drawOutlinePolygon( pShape, pData );
338 break;
339
340 case KivioShapeData::kstBezier:
341 drawOutlineBezier( pShape, pData );
342 break;
343
344 case KivioShapeData::kstRectangle:
345 drawOutlineRectangle( pShape, pData );
346 break;
347
348 case KivioShapeData::kstRoundRectangle:
349 drawOutlineRoundRectangle( pShape, pData );
350 break;
351
352 case KivioShapeData::kstEllipse:
353 drawOutlineEllipse( pShape, pData );
354 break;
355
356 case KivioShapeData::kstOpenPath:
357 drawOutlineOpenPath( pShape, pData );
358 break;
359
360 case KivioShapeData::kstClosedPath:
361 drawOutlineClosedPath( pShape, pData );
362 break;
363
364 case KivioShapeData::kstTextBox:
365 drawOutlineTextBox( pShape, pData );
366 break;
367
368
369 case KivioShapeData::kstNone:
370 default:
371 kdDebug(43000) << "*** KivioShape::Paint AHHHHH!!! NO SHAPE!" << endl;
372 break;
373 }
374
375 pShape = m_pShapeList->next();
376 }
377 pData->painter->restoreState();
378
379 // Now iterate through anything connected to it drawing it as an outline
380 KivioConnectorTarget *pTarget;
381
382 pTarget = m_pConnectorTargets->first();
383 while( pTarget )
384 {
385 pTarget->paintOutline( pData );
386
387 pTarget = m_pConnectorTargets->next();
388 }
389}
390
391void KivioSMLStencil::drawOutlineArc( KivioShape *pShape, KivioIntraStencilData *pData )
392{
393 double _a, _l, _x, _y, _w, _h, defWidth, defHeight;
394 KivioPainter *painter;
395 KivioShapeData *pShapeData;
396 KivioPoint *pPosition, *pDimensions;
397 KivioPoint *pPoint;
398
399 pShapeData = pShape->shapeData();
400 pPosition = pShapeData->position();
401 pDimensions = pShapeData->dimensions();
402
403 defWidth = m_pSpawner->defWidth();
404 defHeight = m_pSpawner->defHeight();
405
406 _x = m_zoomHandler->zoomItX((pPosition->x() / defWidth) * m_w);
407 _y = m_zoomHandler->zoomItY((pPosition->y() / defHeight) * m_h);
408 _w = m_zoomHandler->zoomItX((pDimensions->x() / defWidth) * m_w) + 1;
409 _h = m_zoomHandler->zoomItY((pDimensions->y() / defHeight) * m_h) + 1;
410
411 pPoint = pShapeData->pointList()->first();
412 _a = m_zoomHandler->zoomItX(pPoint->x());
413 _l = m_zoomHandler->zoomItY(pPoint->y());
414
415
416 painter = pData->painter;
417 painter->drawArc( _x, _y, _w, _h, _a, _l );
418}
419
420void KivioSMLStencil::drawOutlineBezier( KivioShape *pShape, KivioIntraStencilData *pData )
421{
422 KivioPainter *painter;
423 KivioShapeData *pShapeData = pShape->shapeData();
424
425 double defWidth = m_pSpawner->defWidth();
426 double defHeight = m_pSpawner->defHeight();
427
428
429 painter = pData->painter;
430 pShapeData = pShape->shapeData();
431
432 KivioPoint *pPoint, *pPoint2, *pPoint3, *pPoint4;
433 TQPtrList <KivioPoint> *pPointList = pShapeData->pointList();
434 TQPointArray controlPoints( 4 );
435
436
437 pPoint = pPointList->first();
438 pPoint2 = pPointList->next();
439 pPoint3 = pPointList->next();
440 pPoint4 = pPointList->next();
441
442
443 controlPoints.setPoint( 0, m_zoomHandler->zoomItX((pPoint->x() / defWidth)*m_w),
444 m_zoomHandler->zoomItY((pPoint->y()/defHeight)*m_h) );
445 controlPoints.setPoint( 1, m_zoomHandler->zoomItX((pPoint2->x() / defWidth)*m_w),
446 m_zoomHandler->zoomItY((pPoint2->y()/defHeight)*m_h));
447 controlPoints.setPoint( 2, m_zoomHandler->zoomItX((pPoint3->x() / defWidth)*m_w),
448 m_zoomHandler->zoomItY((pPoint3->y()/defHeight)*m_h));
449 controlPoints.setPoint( 3, m_zoomHandler->zoomItX((pPoint4->x() / defWidth)*m_w),
450 m_zoomHandler->zoomItY((pPoint4->y()/defHeight)*m_h));
451
452 painter = pData->painter;
453 painter->drawBezier( controlPoints );
454}
455
456void KivioSMLStencil::drawOutlineOpenPath( KivioShape *pShape, KivioIntraStencilData *pData )
457{
458 KivioPainter *painter;
459 KivioShapeData *pShapeData = pShape->shapeData();
460 KivioPoint *pPoint, *pNewPoint;
461
462 double defWidth = m_pSpawner->defWidth();
463 double defHeight = m_pSpawner->defHeight();
464
465 TQPtrList <KivioPoint> *pPointList = pShapeData->pointList();
466 TQPtrList <KivioPoint> *pNewPoints = new TQPtrList<KivioPoint>;
467 pNewPoints->setAutoDelete(true);
468
469 pPoint = pPointList->first();
470
471 while( pPoint )
472 {
473 pNewPoint = new KivioPoint( m_zoomHandler->zoomItX((pPoint->x()/defWidth)*m_w),
474 m_zoomHandler->zoomItY((pPoint->y()/defHeight)*m_h),
475 pPoint->pointType() );
476 pNewPoints->append(pNewPoint);
477
478 pPoint = pPointList->next();
479 }
480
481 painter = pData->painter;
482 painter->drawOpenPath( pNewPoints );
483
484 delete pNewPoints;
485}
486
487void KivioSMLStencil::drawOutlineClosedPath( KivioShape *pShape, KivioIntraStencilData *pData )
488{
489 KivioPainter *painter;
490 KivioShapeData *pShapeData = pShape->shapeData();
491 KivioPoint *pPoint, *pNewPoint;
492
493 double defWidth = m_pSpawner->defWidth();
494 double defHeight = m_pSpawner->defHeight();
495
496 TQPtrList <KivioPoint> *pPointList = pShapeData->pointList();
497 TQPtrList <KivioPoint> *pNewPoints = new TQPtrList<KivioPoint>;
498 pNewPoints->setAutoDelete(true);
499
500 pPoint = pPointList->first();
501 while( pPoint )
502 {
503 pNewPoint = new KivioPoint( m_zoomHandler->zoomItX((pPoint->x()/defWidth)*m_w),
504 m_zoomHandler->zoomItY((pPoint->y()/defHeight)*m_h),
505 pPoint->pointType() );
506 pNewPoints->append(pNewPoint);
507
508 pPoint = pPointList->next();
509 }
510
511 painter = pData->painter;
512 painter->drawOpenPath( pNewPoints );
513
514 delete pNewPoints;
515}
516
517void KivioSMLStencil::drawOutlineEllipse( KivioShape *pShape, KivioIntraStencilData *pData )
518{
519 double _x, _y, _w, _h, defWidth, defHeight;
520 KivioPainter *painter;
521 KivioShapeData *pShapeData;
522 KivioPoint *pPosition, *pDimensions;
523
524 pShapeData = pShape->shapeData();
525 pPosition = pShapeData->position();
526 pDimensions = pShapeData->dimensions();
527
528 defWidth = m_pSpawner->defWidth();
529 defHeight = m_pSpawner->defHeight();
530
531 _x = m_zoomHandler->zoomItX((pPosition->x() / defWidth) * m_w);
532 _y = m_zoomHandler->zoomItY((pPosition->y() / defHeight) * m_h);
533 _w = m_zoomHandler->zoomItX((pDimensions->x() / defWidth) * m_w) + 1;
534 _h = m_zoomHandler->zoomItY((pDimensions->y() / defHeight) * m_h) + 1;
535
536
537 painter = pData->painter;
538 painter->setFGColor( TQColor(0, 0, 0) );
539 painter->drawEllipse( _x, _y, _w, _h );
540}
541
542void KivioSMLStencil::drawOutlineLineArray( KivioShape *pShape, KivioIntraStencilData *pData )
543{
544 double _x, _y, defWidth, defHeight;
545 KivioPainter *painter;
546 KivioShapeData *pShapeData;
547 TQPtrList <KivioPoint> *pList;
548
549 pShapeData = pShape->shapeData();
550
551 defWidth = m_pSpawner->defWidth();
552 defHeight = m_pSpawner->defHeight();
553
554 pList = pShapeData->pointList();
555
556
557 TQPointArray arr( pList->count() );
558
559 KivioPoint *pPoint;
560 int i=0;
561 pPoint = pList->first();
562 while( pPoint )
563 {
564 _x = m_zoomHandler->zoomItX((pPoint->x() / defWidth) * m_w);
565 _y = m_zoomHandler->zoomItY((pPoint->y() / defHeight) * m_h);
566
567 arr.setPoint( i, (int)_x, (int)_y );
568
569 i++;
570
571 pPoint = pList->next();
572 }
573
574 painter = pData->painter;
575 painter->drawLineArray( arr );
576}
577
578void KivioSMLStencil::drawOutlineRectangle( KivioShape *pShape, KivioIntraStencilData *pData )
579{
580 double _x, _y, _w, _h, defWidth, defHeight;
581 KivioPainter *painter;
582 KivioShapeData *pShapeData;
583 KivioPoint *pPosition, *pDimensions;
584
585 pShapeData = pShape->shapeData();
586 pPosition = pShapeData->position();
587 pDimensions = pShapeData->dimensions();
588
589 defWidth = m_pSpawner->defWidth();
590 defHeight = m_pSpawner->defHeight();
591
592 _x = m_zoomHandler->zoomItX((pPosition->x() / defWidth) * m_w);
593 _y = m_zoomHandler->zoomItY((pPosition->y() / defHeight) * m_h);
594 _w = m_zoomHandler->zoomItX((pDimensions->x() / defWidth) * m_w) + 1;
595 _h = m_zoomHandler->zoomItY((pDimensions->y() / defHeight) * m_h) + 1;
596
597 painter = pData->painter;
598 painter->setFGColor( TQColor(0, 0, 0) );
599 painter->drawRect( _x, _y, _w, _h );
600}
601
602void KivioSMLStencil::drawOutlineRoundRectangle( KivioShape *pShape, KivioIntraStencilData *pData )
603{
604 double _rx, _ry, _x, _y, _w, _h, defWidth, defHeight;
605 KivioPainter *painter;
606 KivioShapeData *pShapeData;
607 KivioPoint *pPosition, *pDimensions;
608
609 pShapeData = pShape->shapeData();
610 pPosition = pShapeData->position();
611 pDimensions = pShapeData->dimensions();
612
613 KivioPoint *pPoint;
614
615 defWidth = m_pSpawner->defWidth();
616 defHeight = m_pSpawner->defHeight();
617
618 pPoint = pShapeData->pointList()->first();
619 _rx = m_zoomHandler->zoomItX(pPoint->x());
620 _ry = m_zoomHandler->zoomItY(pPoint->y());
621
622
623 _x = m_zoomHandler->zoomItX((pPosition->x() / defWidth) * m_w);
624 _y = m_zoomHandler->zoomItY((pPosition->y() / defHeight) * m_h);
625 _w = m_zoomHandler->zoomItX((pDimensions->x() / defWidth) * m_w) + 1;
626 _h = m_zoomHandler->zoomItY((pDimensions->y() / defHeight) * m_h) + 1;
627
628
629 painter = pData->painter;
630 painter->setFGColor( TQColor(0, 0, 0) );
631 painter->drawRoundRect( _x, _y, _w, _h, _rx, _ry );
632}
633
634void KivioSMLStencil::drawOutlinePie( KivioShape *, KivioIntraStencilData * )
635{
636
637}
638
639void KivioSMLStencil::drawOutlinePolygon( KivioShape *pShape, KivioIntraStencilData *pData )
640{
641 double _x, _y, defWidth, defHeight;
642 KivioPainter *painter;
643 KivioShapeData *pShapeData;
644 TQPtrList <KivioPoint> *pList;
645
646 pShapeData = pShape->shapeData();
647
648 defWidth = m_pSpawner->defWidth();
649 defHeight = m_pSpawner->defHeight();
650
651 pList = pShapeData->pointList();
652
653
654 TQPointArray arr( pList->count() );
655
656 KivioPoint *pPoint;
657 int i=0;
658 pPoint = pList->first();
659 while( pPoint )
660 {
661 _x = m_zoomHandler->zoomItX((pPoint->x() / defWidth) * m_w);
662 _y = m_zoomHandler->zoomItY((pPoint->y() / defHeight) * m_h);
663
664 arr.setPoint( i, (int)_x, (int)_y );
665
666 i++;
667
668 pPoint = pList->next();
669 }
670
671 painter = pData->painter;
672 painter->drawPolyline( arr );
673}
674
675void KivioSMLStencil::drawOutlinePolyline( KivioShape *pShape, KivioIntraStencilData *pData )
676{
677 double _x, _y, defWidth, defHeight;
678 KivioPainter *painter;
679 KivioShapeData *pShapeData;
680 TQPtrList <KivioPoint> *pList;
681
682 pShapeData = pShape->shapeData();
683
684 defWidth = m_pSpawner->defWidth();
685 defHeight = m_pSpawner->defHeight();
686
687 pList = pShapeData->pointList();
688
689
690 TQPointArray arr( pList->count() );
691
692 KivioPoint *pPoint;
693 int i=0;
694 pPoint = pList->first();
695
696 while( pPoint )
697 {
698 _x = m_zoomHandler->zoomItX((pPoint->x() / defWidth) * m_w);
699 _y = m_zoomHandler->zoomItY((pPoint->y() / defHeight) * m_h);
700
701 arr.setPoint( i, (int)_x, (int)_y );
702
703 i++;
704
705 pPoint = pList->next();
706 }
707
708 painter = pData->painter;
709 painter->drawPolyline( arr );
710}
711
712void KivioSMLStencil::drawOutlineTextBox( KivioShape *pShape, KivioIntraStencilData *pData )
713{
714 double defWidth = m_pSpawner->defWidth();
715 double defHeight = m_pSpawner->defHeight();
716 int _x, _y, _w, _h;
717 KivioShapeData *pShapeData = pShape->shapeData();
718 KivioPoint *pPosition = pShapeData->position();
719 KivioPoint *pDimensions = pShapeData->dimensions();
720 KivioPainter *painter = pData->painter;
721 KoZoomHandler* zoomHandler = pData->zoomHandler;
722
723 if( pShapeData->text().length() <= 0 ) {
724 return;
725 }
726
727
728 _x = zoomHandler->zoomItX((pPosition->x() / defWidth) * m_w);
729 _y = zoomHandler->zoomItY((pPosition->y() / defHeight) * m_h);
730 _w = zoomHandler->zoomItX((pDimensions->x() / defWidth) * m_w) + 1;
731 _h = zoomHandler->zoomItY((pDimensions->y() / defHeight) * m_h) + 1;
732
733
734 TQPixmap pix(_w, _h);
735 pix.fill();
736 TQPainter p(&pix);
737
738 TQFont f = pShapeData->textFont();
739 f.setPointSizeFloat(f.pointSizeFloat() * (((float)zoomHandler->zoom()) / 100.0));
740 p.setFont( f );
741 p.setPen( TQColor(0, 0, 0) );
742 int tf = pShapeData->vTextAlign() | pShapeData->hTextAlign();
743 p.drawText( 0, 0, _w, _h, tf | TQt::WordBreak, pShapeData->text() );
744 TQBitmap mask;
745 mask = pix;
746 pix.setMask(mask);
747 painter->drawPixmap(_x, _y, pix);
748}
749
750
754void KivioSMLStencil::paint( KivioIntraStencilData *pData )
755{
756 KivioShape *pShape;
757 KivioShapeData *pShapeData;
758
759
760 m_zoomHandler = pData->zoomHandler;
761 pData->painter->saveState();
762 pData->painter->setTranslation(m_zoomHandler->zoomItX(m_x), m_zoomHandler->zoomItY(m_y));
763 rotatePainter(pData); // Rotate the painter if needed
764
765 pShape = m_pShapeList->first();
766 while( pShape )
767 {
768 pShapeData = pShape->shapeData();
769
770 switch( pShapeData->shapeType() )
771 {
772 case KivioShapeData::kstArc:
773 drawArc( pShape, pData );
774 break;
775
776 case KivioShapeData::kstPie:
777 drawPie( pShape, pData );
778 break;
779
780 case KivioShapeData::kstLineArray:
781 drawLineArray( pShape, pData );
782 break;
783
784 case KivioShapeData::kstPolyline:
785 drawPolyline( pShape, pData );
786 break;
787
788 case KivioShapeData::kstPolygon:
789 drawPolygon( pShape, pData );
790 break;
791
792 case KivioShapeData::kstBezier:
793 drawBezier( pShape, pData );
794 break;
795
796 case KivioShapeData::kstRectangle:
797 drawRectangle( pShape, pData );
798 break;
799
800 case KivioShapeData::kstRoundRectangle:
801 drawRoundRectangle( pShape, pData );
802 break;
803
804 case KivioShapeData::kstEllipse:
805 drawEllipse( pShape, pData );
806 break;
807
808 case KivioShapeData::kstOpenPath:
809 drawOpenPath( pShape, pData );
810 break;
811
812 case KivioShapeData::kstClosedPath:
813 drawClosedPath( pShape, pData );
814 break;
815
816 case KivioShapeData::kstTextBox:
817 drawTextBox( pShape, pData );
818 break;
819
820 case KivioShapeData::kstNone:
821 default:
822 break;
823 }
824
825 pShape = m_pShapeList->next();
826 }
827
828 pData->painter->restoreState();
829}
830
831
835void KivioSMLStencil::paintConnectorTargets( KivioIntraStencilData *pData )
836{
837 // We don't draw these if we are selected!!!
838 //if( isSelected() == true ) {
839 // return;
840 //}
841
842 TQPixmap targetPic;
843 KivioPainter *painter;
844 int x, y;
845
846 // Obtain the graphic used for KivioConnectorTargets
847 targetPic = Kivio::connectorTargetPixmap();
848
849
850 m_zoomHandler = pData->zoomHandler;
851 painter = pData->painter;
852
853 KivioConnectorTarget *pTarget;
854 pTarget = m_pConnectorTargets->first();
855 while( pTarget )
856 {
857 x = m_zoomHandler->zoomItX(pTarget->x());
858 y = m_zoomHandler->zoomItY(pTarget->y());
859
860 painter->drawPixmap( x-3, y-3, targetPic );
861
862 pTarget = m_pConnectorTargets->next();
863 }
864}
865
866
867void KivioSMLStencil::drawArc( KivioShape *pShape, KivioIntraStencilData *pData )
868{
869 double defWidth, defHeight;
870 int _a, _l, _x, _y, _w, _h;
871 KivioPainter *painter;
872 KivioShapeData *pShapeData;
873 KivioPoint *pPosition, *pDimensions;
874 KivioPoint *pPoint;
875
876 pShapeData = pShape->shapeData();
877 pPosition = pShapeData->position();
878 pDimensions = pShapeData->dimensions();
879
880 defWidth = m_pSpawner->defWidth();
881 defHeight = m_pSpawner->defHeight();
882
883 _x = m_zoomHandler->zoomItX((pPosition->x() / defWidth) * m_w);
884 _y = m_zoomHandler->zoomItY((pPosition->y() / defHeight) * m_h);
885 _w = m_zoomHandler->zoomItX((pDimensions->x() / defWidth) * m_w) + 1;
886 _h = m_zoomHandler->zoomItY((pDimensions->y() / defHeight) * m_h) + 1;
887
888 pPoint = pShapeData->pointList()->first();
889 _a = m_zoomHandler->zoomItX(pPoint->x());
890 _l = m_zoomHandler->zoomItY(pPoint->y());
891
892 painter = pData->painter;
893 painter->setLineStyle(pShapeData->lineStyle());
894 double lineWidth = pShapeData->lineStyle()->width();
895 painter->setLineWidth(m_zoomHandler->zoomItY(lineWidth));
896
897 switch( pShapeData->fillStyle()->colorStyle() )
898 {
899 case KivioFillStyle::kcsNone: // Hollow
900 painter->drawArc( _x, _y, _w, _h, _a, _l );
901 break;
902
903 case KivioFillStyle::kcsSolid: // Solid fill
904 case KivioFillStyle::kcsGradient: // Gradient
905 painter->setFillStyle( pShapeData->fillStyle() );
906 painter->drawArc( _x, _y, _w, _h, _a, _l );
907 break;
908
909 case KivioFillStyle::kcsPixmap:
910 default:
911 break;
912 }
913}
914
915void KivioSMLStencil::drawBezier( KivioShape *pShape, KivioIntraStencilData *pData )
916{
917 KivioPainter *painter;
918 KivioShapeData *pShapeData = pShape->shapeData();
919
920 double defWidth = m_pSpawner->defWidth();
921 double defHeight = m_pSpawner->defHeight();
922
923
924 painter = pData->painter;
925 pShapeData = pShape->shapeData();
926
927 KivioPoint *pPoint, *pPoint2, *pPoint3, *pPoint4;
928 TQPtrList <KivioPoint> *pPointList = pShapeData->pointList();
929 TQPointArray controlPoints( 4 );
930
931
932 pPoint = pPointList->first();
933 pPoint2 = pPointList->next();
934 pPoint3 = pPointList->next();
935 pPoint4 = pPointList->next();
936
937
938 controlPoints.setPoint( 0, m_zoomHandler->zoomItX((pPoint->x() / defWidth)*m_w),
939 m_zoomHandler->zoomItY((pPoint->y()/defHeight)*m_h));
940 controlPoints.setPoint( 1, m_zoomHandler->zoomItX((pPoint2->x() / defWidth)*m_w),
941 m_zoomHandler->zoomItY((pPoint2->y()/defHeight)*m_h));
942 controlPoints.setPoint( 2, m_zoomHandler->zoomItX((pPoint3->x() / defWidth)*m_w),
943 m_zoomHandler->zoomItY((pPoint3->y()/defHeight)*m_h));
944 controlPoints.setPoint( 3, m_zoomHandler->zoomItX((pPoint4->x() / defWidth)*m_w),
945 m_zoomHandler->zoomItY((pPoint4->y()/defHeight)*m_h));
946
947 painter->setLineStyle(pShapeData->lineStyle());
948 double lineWidth = pShapeData->lineStyle()->width();
949 painter->setLineWidth(m_zoomHandler->zoomItY(lineWidth));
950
951 painter->drawBezier( controlPoints );
952}
953
954void KivioSMLStencil::drawOpenPath( KivioShape *pShape, KivioIntraStencilData *pData )
955{
956 KivioPainter *painter;
957 KivioShapeData *pShapeData = pShape->shapeData();
958 KivioPoint *pPoint, *pNewPoint;
959
960 double defWidth = m_pSpawner->defWidth();
961 double defHeight = m_pSpawner->defHeight();
962
963 TQPtrList <KivioPoint> *pPointList = pShapeData->pointList();
964 TQPtrList <KivioPoint> *pNewPoints = new TQPtrList<KivioPoint>;
965 pNewPoints->setAutoDelete(true);
966
967 pPoint = pPointList->first();
968 while( pPoint )
969 {
970 pNewPoint = new KivioPoint( m_zoomHandler->zoomItX((pPoint->x()/defWidth)*m_w),
971 m_zoomHandler->zoomItY((pPoint->y()/defHeight)*m_h),
972 pPoint->pointType() );
973 pNewPoints->append(pNewPoint);
974
975 pPoint = pPointList->next();
976 }
977
978 painter = pData->painter;
979 painter->setLineStyle(pShapeData->lineStyle());
980 double lineWidth = pShapeData->lineStyle()->width();
981 painter->setLineWidth(m_zoomHandler->zoomItY(lineWidth));
982
983 painter->drawOpenPath( pNewPoints );
984
985 delete pNewPoints;
986}
987
988void KivioSMLStencil::drawClosedPath( KivioShape *pShape, KivioIntraStencilData *pData )
989{
990 KivioPainter *painter;
991 KivioShapeData *pShapeData = pShape->shapeData();
992 KivioPoint *pPoint, *pNewPoint;
993
994 double defWidth = m_pSpawner->defWidth();
995 double defHeight = m_pSpawner->defHeight();
996
997 TQPtrList <KivioPoint> *pPointList = pShapeData->pointList();
998 TQPtrList <KivioPoint> *pNewPoints = new TQPtrList<KivioPoint>;
999 pNewPoints->setAutoDelete(true);
1000
1001 pPoint = pPointList->first();
1002 while( pPoint )
1003 {
1004 pNewPoint = new KivioPoint( m_zoomHandler->zoomItX((pPoint->x()/defWidth)*m_w),
1005 m_zoomHandler->zoomItY((pPoint->y()/defHeight)*m_h),
1006 pPoint->pointType() );
1007 pNewPoints->append(pNewPoint);
1008
1009 pPoint = pPointList->next();
1010 }
1011
1012 painter = pData->painter;
1013 painter->setLineStyle(pShapeData->lineStyle());
1014 double lineWidth = pShapeData->lineStyle()->width();
1015 painter->setLineWidth(m_zoomHandler->zoomItY(lineWidth));
1016
1017 switch( pShapeData->fillStyle()->colorStyle() )
1018 {
1019 case KivioFillStyle::kcsNone: // Hollow
1020 painter->drawOpenPath( pNewPoints );
1021 break;
1022
1023 case KivioFillStyle::kcsSolid: // Solid fill
1024 case KivioFillStyle::kcsGradient: // Gradient
1025 painter->setFillStyle( pShapeData->fillStyle() );
1026 painter->drawClosedPath( pNewPoints );
1027 break;
1028
1029 case KivioFillStyle::kcsPixmap:
1030 default:
1031 break;
1032 }
1033
1034 delete pNewPoints;
1035}
1036
1037void KivioSMLStencil::drawPie( KivioShape *, KivioIntraStencilData * )
1038{
1039}
1040
1041void KivioSMLStencil::drawEllipse( KivioShape *pShape, KivioIntraStencilData *pData )
1042{
1043 double defWidth, defHeight;
1044 int _x, _y, _w, _h;
1045 KivioPainter *painter;
1046 KivioShapeData *pShapeData;
1047 KivioPoint *pPosition, *pDimensions;
1048
1049 pShapeData = pShape->shapeData();
1050 pPosition = pShapeData->position();
1051 pDimensions = pShapeData->dimensions();
1052
1053 defWidth = m_pSpawner->defWidth();
1054 defHeight = m_pSpawner->defHeight();
1055
1056 _x = m_zoomHandler->zoomItX((pPosition->x() / defWidth) * m_w);
1057 _y = m_zoomHandler->zoomItY((pPosition->y() / defHeight) * m_h);
1058 _w = m_zoomHandler->zoomItX((pDimensions->x() / defWidth) * m_w) + 1;
1059 _h = m_zoomHandler->zoomItY((pDimensions->y() / defHeight) * m_h) + 1;
1060
1061 painter = pData->painter;
1062 painter->setLineStyle(pShapeData->lineStyle());
1063 double lineWidth = pShapeData->lineStyle()->width();
1064 painter->setLineWidth(m_zoomHandler->zoomItY(lineWidth));
1065
1066 switch( pShapeData->fillStyle()->colorStyle() )
1067 {
1068 case KivioFillStyle::kcsNone: // Hollow
1069 painter->drawEllipse( _x, _y, _w, _h );
1070 break;
1071
1072 case KivioFillStyle::kcsSolid: // Solid fill
1073 case KivioFillStyle::kcsGradient: // Gradient
1074 painter->setFillStyle( pShapeData->fillStyle() );
1075 painter->fillEllipse( _x, _y, _w, _h );
1076 break;
1077
1078 case KivioFillStyle::kcsPixmap:
1079 default:
1080 break;
1081 }
1082}
1083
1084void KivioSMLStencil::drawLineArray( KivioShape *pShape, KivioIntraStencilData *pData )
1085{
1086 double defWidth, defHeight;
1087 int _x, _y;
1088 KivioPainter *painter;
1089 KivioShapeData *pShapeData;
1090 TQPtrList <KivioPoint> *pList;
1091
1092 pShapeData = pShape->shapeData();
1093
1094 defWidth = m_pSpawner->defWidth();
1095 defHeight = m_pSpawner->defHeight();
1096
1097 pList = pShapeData->pointList();
1098
1099
1100 TQPointArray arr( pList->count() );
1101
1102 KivioPoint *pPoint;
1103 int i=0;
1104 pPoint = pList->first();
1105 while( pPoint )
1106 {
1107 _x = m_zoomHandler->zoomItX((pPoint->x() / defWidth) * m_w);
1108 _y = m_zoomHandler->zoomItY((pPoint->y() / defHeight) * m_h);
1109
1110 arr.setPoint( i, _x, _y );
1111
1112 i++;
1113
1114 pPoint = pList->next();
1115 }
1116
1117 painter = pData->painter;
1118 painter->setLineStyle(pShapeData->lineStyle());
1119 double lineWidth = pShapeData->lineStyle()->width();
1120 painter->setLineWidth(m_zoomHandler->zoomItY(lineWidth));
1121
1122 painter->drawLineArray( arr );
1123}
1124
1125void KivioSMLStencil::drawRectangle( KivioShape *pShape, KivioIntraStencilData *pData )
1126{
1127 double defWidth, defHeight;
1128 int _x, _y, _w, _h;
1129 KivioPainter *painter;
1130 KivioShapeData *pShapeData;
1131 KivioPoint *pPosition, *pDimensions;
1132
1133 pShapeData = pShape->shapeData();
1134 pPosition = pShapeData->position();
1135 pDimensions = pShapeData->dimensions();
1136
1137 defWidth = m_pSpawner->defWidth();
1138 defHeight = m_pSpawner->defHeight();
1139
1140 _x = m_zoomHandler->zoomItX((pPosition->x() / defWidth) * m_w);
1141 _y = m_zoomHandler->zoomItY((pPosition->y() / defHeight) * m_h);
1142 _w = m_zoomHandler->zoomItX((pDimensions->x() / defWidth) * m_w) + 1;
1143 _h = m_zoomHandler->zoomItY((pDimensions->y() / defHeight) * m_h) + 1;
1144
1145 painter = pData->painter;
1146 painter->setLineStyle(pShapeData->lineStyle());
1147 double lineWidth = pShapeData->lineStyle()->width();
1148 painter->setLineWidth(m_zoomHandler->zoomItY(lineWidth));
1149
1150 switch( pShapeData->fillStyle()->colorStyle() )
1151 {
1152 case KivioFillStyle::kcsNone: // Hollow
1153 painter->drawRect( _x, _y, _w, _h );
1154 break;
1155
1156 case KivioFillStyle::kcsSolid: // Solid fill
1157 case KivioFillStyle::kcsGradient: // Gradient
1158 painter->setFillStyle( pShapeData->fillStyle() );
1159 painter->fillRect( _x, _y, _w, _h );
1160 break;
1161
1162 case KivioFillStyle::kcsPixmap:
1163 default:
1164 break;
1165 }
1166}
1167
1168void KivioSMLStencil::drawRoundRectangle( KivioShape *pShape, KivioIntraStencilData *pData )
1169{
1170 double defWidth, defHeight;
1171 int _rx, _ry, _x, _y, _w, _h;
1172 KivioPainter *painter;
1173 KivioShapeData *pShapeData;
1174 KivioPoint *pPosition, *pDimensions;
1175 KivioPoint *pPoint;
1176
1177 pShapeData = pShape->shapeData();
1178 pPosition = pShapeData->position();
1179 pDimensions = pShapeData->dimensions();
1180
1181 defWidth = m_pSpawner->defWidth();
1182 defHeight = m_pSpawner->defHeight();
1183
1184 _x = m_zoomHandler->zoomItX((pPosition->x() / defWidth) * m_w);
1185 _y = m_zoomHandler->zoomItY((pPosition->y() / defHeight) * m_h);
1186 _w = m_zoomHandler->zoomItX((pDimensions->x() / defWidth) * m_w) + 1;
1187 _h = m_zoomHandler->zoomItY((pDimensions->y() / defHeight) * m_h) + 1;
1188
1189 pPoint = pShapeData->pointList()->first();
1190 _rx = m_zoomHandler->zoomItX(pPoint->x());
1191 _ry = m_zoomHandler->zoomItY(pPoint->y());
1192
1193 painter = pData->painter;
1194 painter->setLineStyle(pShapeData->lineStyle());
1195 double lineWidth = pShapeData->lineStyle()->width();
1196 painter->setLineWidth(m_zoomHandler->zoomItY(lineWidth));
1197
1198 switch( pShapeData->fillStyle()->colorStyle() )
1199 {
1200 case KivioFillStyle::kcsNone: // Hollow
1201 painter->drawRoundRect( _x, _y, _w, _h, _rx, _ry );
1202 break;
1203
1204 case KivioFillStyle::kcsSolid: // Solid fill
1205 case KivioFillStyle::kcsGradient: // Gradient
1206 painter->setFillStyle( pShapeData->fillStyle() );
1207 painter->fillRoundRect( _x, _y, _w, _h, _rx, _ry );
1208 break;
1209
1210 case KivioFillStyle::kcsPixmap:
1211 default:
1212 break;
1213 }
1214}
1215
1216void KivioSMLStencil::drawPolygon( KivioShape *pShape, KivioIntraStencilData *pData )
1217{
1218 double defWidth, defHeight;
1219 int _x, _y;
1220 KivioPainter *painter;
1221 KivioShapeData *pShapeData;
1222 TQPtrList <KivioPoint> *pList;
1223
1224 pShapeData = pShape->shapeData();
1225
1226 defWidth = m_pSpawner->defWidth();
1227 defHeight = m_pSpawner->defHeight();
1228
1229 pList = pShapeData->pointList();
1230
1231
1232 TQPointArray arr( pList->count() );
1233
1234
1235 KivioPoint *pPoint;
1236 int i=0;
1237 pPoint = pList->first();
1238 while( pPoint )
1239 {
1240 _x = m_zoomHandler->zoomItX((pPoint->x() / defWidth) * m_w);
1241 _y = m_zoomHandler->zoomItY((pPoint->y() / defHeight) * m_h);
1242
1243
1244 arr.setPoint( i, _x, _y );
1245
1246 i++;
1247
1248 pPoint = pList->next();
1249 }
1250
1251 painter = pData->painter;
1252 painter->setLineStyle(pShapeData->lineStyle());
1253 double lineWidth = pShapeData->lineStyle()->width();
1254 painter->setLineWidth(m_zoomHandler->zoomItY(lineWidth));
1255
1256 switch( pShapeData->fillStyle()->colorStyle() )
1257 {
1258 case KivioFillStyle::kcsNone: // Hollow
1259 painter->drawPolygon(arr);
1260 break;
1261
1262 case KivioFillStyle::kcsSolid: // Solid fill
1263 case KivioFillStyle::kcsGradient: // Gradient
1264 painter->setFillStyle( pShapeData->fillStyle() );
1265 painter->drawPolygon(arr);
1266 break;
1267
1268 case KivioFillStyle::kcsPixmap:
1269 default:
1270 break;
1271 }
1272
1273}
1274
1275void KivioSMLStencil::drawPolyline( KivioShape *pShape, KivioIntraStencilData *pData )
1276{
1277 double defWidth, defHeight;
1278 int _x, _y;
1279 KivioPainter *painter;
1280 KivioShapeData *pShapeData;
1281 TQPtrList <KivioPoint> *pList;
1282
1283 pShapeData = pShape->shapeData();
1284
1285 defWidth = m_pSpawner->defWidth();
1286 defHeight = m_pSpawner->defHeight();
1287
1288 pList = pShapeData->pointList();
1289
1290
1291 TQPointArray arr( pList->count() );
1292
1293 KivioPoint *pPoint;
1294 int i=0;
1295 pPoint = pList->first();
1296 while( pPoint )
1297 {
1298 _x = m_zoomHandler->zoomItX((pPoint->x() / defWidth) * m_w);
1299 _y = m_zoomHandler->zoomItY((pPoint->y() / defHeight) * m_h);
1300
1301 arr.setPoint( i, _x, _y );
1302
1303 i++;
1304
1305 pPoint = pList->next();
1306 }
1307
1308 painter = pData->painter;
1309 painter->setLineStyle(pShapeData->lineStyle());
1310 double lineWidth = pShapeData->lineStyle()->width();
1311 painter->setLineWidth(m_zoomHandler->zoomItY(lineWidth));
1312
1313 painter->drawPolyline(arr);
1314}
1315
1316void KivioSMLStencil::drawTextBox( KivioShape *pShape, KivioIntraStencilData *pData )
1317{
1318 double defWidth = m_pSpawner->defWidth();
1319 double defHeight = m_pSpawner->defHeight();
1320 KivioShapeData *pShapeData = pShape->shapeData();
1321 KivioPoint *pPosition = pShapeData->position();
1322 KivioPoint *pDimensions = pShapeData->dimensions();
1323 KivioPainter *painter = pData->painter;
1324 KoZoomHandler* zoomHandler = pData->zoomHandler;
1325
1326
1327 if(pShapeData->text().isEmpty()) {
1328 return;
1329 }
1330
1331 int _x = zoomHandler->zoomItX((pPosition->x() / defWidth) * m_w);
1332 int _y = zoomHandler->zoomItY((pPosition->y() / defHeight) * m_h);
1333 int _w = zoomHandler->zoomItX((pDimensions->x() / defWidth) * m_w) + 1;
1334 int _h = zoomHandler->zoomItY((pDimensions->y() / defHeight) * m_h) + 1;
1335
1336
1337 TQFont f = pShapeData->textFont();
1338 f.setPointSizeFloat(f.pointSizeFloat() * (((float)zoomHandler->zoom()) / 100.0));
1339 painter->setFont( f );
1340 painter->setTextColor( pShapeData->textColor() );
1341
1342 int tf = pShapeData->vTextAlign() | pShapeData->hTextAlign();
1343 painter->drawText( _x, _y, _w, _h, tf | TQt::WordBreak, pShapeData->text() );
1344 // TODO Implement richtext support
1345}
1346
1347
1348
1349
1353void KivioSMLStencil::setFGColor( TQColor c )
1354{
1355 KivioShape *pShape;
1356
1357
1358 pShape = m_pShapeList->first();
1359 while( pShape )
1360 {
1361 pShape->shapeData()->lineStyle()->setColor( c );
1362
1363 pShape = m_pShapeList->next();
1364 }
1365}
1366
1367
1371void KivioSMLStencil::setBGColor( TQColor c )
1372{
1373 KivioShape *pShape;
1374
1375 pShape = m_pShapeList->first();
1376 while( pShape )
1377 {
1378 pShape->shapeData()->fillStyle()->setColor( c );
1379
1380 pShape = m_pShapeList->next();
1381 }
1382}
1383
1384void KivioSMLStencil::setFillPattern(int p)
1385{
1386 KivioShape *pShape;
1387
1388 pShape = m_pShapeList->first();
1389 while( pShape )
1390 {
1391 pShape->shapeData()->fillStyle()->setBrushStyle( static_cast<TQt::BrushStyle>(p) );
1392
1393 pShape = m_pShapeList->next();
1394 }
1395}
1396
1400void KivioSMLStencil::setTextColor( TQColor c )
1401{
1402 KivioShape *pShape;
1403
1404
1405 pShape = m_pShapeList->first();
1406 while( pShape )
1407 {
1408 pShape->shapeData()->setTextColor( c );
1409
1410 pShape = m_pShapeList->next();
1411 }
1412}
1413
1417void KivioSMLStencil::setTextFont( const TQFont &f )
1418{
1419 KivioShape *pShape;
1420
1421
1422 pShape = m_pShapeList->first();
1423 while( pShape )
1424 {
1425 pShape->shapeData()->setTextFont( f );
1426
1427 pShape = m_pShapeList->next();
1428 }
1429}
1430
1431
1435void KivioSMLStencil::setLineWidth( double f )
1436{
1437 KivioShape *pShape;
1438
1439 pShape = m_pShapeList->first();
1440 while( pShape )
1441 {
1442 pShape->shapeData()->lineStyle()->setWidth( f );
1443
1444 pShape = m_pShapeList->next();
1445 }
1446}
1447
1448void KivioSMLStencil::setLinePattern(int p)
1449{
1450 KivioShape *pShape = m_pShapeList->first();
1451
1452 while( pShape )
1453 {
1454 pShape->shapeData()->lineStyle()->setStyle( p );
1455 pShape = m_pShapeList->next();
1456 }
1457}
1458
1466KivioConnectorTarget *KivioSMLStencil::connectToTarget( KivioConnectorPoint *p, double threshHold )
1467{
1468 double px = p->x();
1469 double py = p->y();
1470
1471 double tx, ty;
1472
1473 KivioConnectorTarget *pTarget = m_pConnectorTargets->first();
1474
1475 while( pTarget )
1476 {
1477 tx = pTarget->x();
1478 ty = pTarget->y();
1479
1480 if( px >= tx - threshHold &&
1481 px <= tx + threshHold &&
1482 py >= ty - threshHold &&
1483 py <= ty + threshHold )
1484 {
1485 // setTarget calls pTarget->addConnectorPoint() and removes
1486 // any previous connections from p
1487 p->setTarget( pTarget );
1488 return pTarget;
1489 }
1490
1491 pTarget = m_pConnectorTargets->next();
1492 }
1493
1494 return NULL;
1495}
1496
1497KoPoint KivioSMLStencil::snapToTarget( const KoPoint& p, double thresh, bool& hit )
1498{
1499 KoPoint retVal = p;
1500 double tx, ty;
1501 hit = false;
1502
1503 KivioConnectorTarget *pTarget = m_pConnectorTargets->first();
1504
1505 while( pTarget )
1506 {
1507 tx = pTarget->x();
1508 ty = pTarget->y();
1509
1510 if( retVal.x() >= tx - thresh &&
1511 retVal.x() <= tx + thresh &&
1512 retVal.y() >= ty - thresh &&
1513 retVal.y() <= ty + thresh )
1514 {
1515 retVal.setX(tx);
1516 retVal.setY(ty);
1517 hit = true;
1518 }
1519
1520 pTarget = m_pConnectorTargets->next();
1521 }
1522
1523 return retVal;
1524}
1525
1531KivioConnectorTarget *KivioSMLStencil::connectToTarget( KivioConnectorPoint *p, int /*targetID*/ )
1532{
1533 int id = p->targetId();
1534
1535 KivioConnectorTarget *pTarget = m_pConnectorTargets->first();
1536 while( pTarget )
1537 {
1538 if( pTarget->id() == id )
1539 {
1540 p->setTarget(pTarget);
1541
1542 return pTarget;
1543 }
1544
1545 pTarget = m_pConnectorTargets->next();
1546 }
1547
1548 return NULL;
1549}
1550
1551
1558void KivioSMLStencil::updateGeometry()
1559{
1560 //kdDebug(43000) << "m_x = " << m_x << " m_y = " << m_y << endl;
1561
1562 TQWMatrix m;
1563 m.translate(m_x, m_y);
1564 m.translate(m_w / 2.0, m_h / 2.0);
1565 m.rotate(m_rotation);
1566 m.translate(-m_w / 2.0, -m_h / 2.0);
1567
1568 KivioConnectorTarget* pTarget = m_pConnectorTargets->first();
1569
1570 while( pTarget )
1571 {
1572 double _x = pTarget->xOffset() * m_w;
1573 double _y = pTarget->yOffset() * m_h;
1574 double newX = _x * m.m11() + _y * m.m21() + m.dx();
1575 double newY = _x * m.m12() + _y * m.m22() + m.dy();
1576 pTarget->setPosition( newX, newY );
1577
1578 pTarget = m_pConnectorTargets->next();
1579 }
1580}
1581
1582
1586TQFont KivioSMLStencil::textFont()
1587{
1588 KivioShape *pShape;
1589
1590 pShape = m_pShapeList->first();
1591 while( pShape )
1592 {
1593 if( pShape->shapeData()->shapeType() == KivioShapeData::kstTextBox )
1594 {
1595 return pShape->shapeData()->textFont();
1596 }
1597
1598 pShape = m_pShapeList->next();
1599 }
1600
1601 //return TQFont("times",12);
1602 return KoGlobal::defaultFont();
1603}
1604
1605TQColor KivioSMLStencil::textColor()
1606{
1607 KivioShape *pShape;
1608
1609 pShape = m_pShapeList->first();
1610 while( pShape )
1611 {
1612 if( pShape->shapeData()->shapeType() == KivioShapeData::kstTextBox )
1613 {
1614 return pShape->shapeData()->textColor();
1615 }
1616
1617 pShape = m_pShapeList->next();
1618 }
1619
1620 return TQColor(0, 0, 0);
1621}
1622
1626void KivioSMLStencil::setHTextAlign(int i)
1627{
1628 KivioShape *pShape;
1629
1630
1631 pShape = m_pShapeList->first();
1632 while( pShape )
1633 {
1634 if( pShape->shapeData()->shapeType() == KivioShapeData::kstTextBox )
1635 pShape->shapeData()->setHTextAlign( i );
1636
1637 pShape = m_pShapeList->next();
1638 }
1639}
1640
1641
1645void KivioSMLStencil::setVTextAlign(int i)
1646{
1647 KivioShape *pShape;
1648
1649
1650 pShape = m_pShapeList->first();
1651 while( pShape )
1652 {
1653 if( pShape->shapeData()->shapeType() == KivioShapeData::kstTextBox )
1654 pShape->shapeData()->setVTextAlign( i );
1655
1656 pShape = m_pShapeList->next();
1657 }
1658}
1659
1660
1664int KivioSMLStencil::hTextAlign()
1665{
1666 KivioShape *pShape;
1667
1668 pShape = m_pShapeList->first();
1669 while( pShape )
1670 {
1671 if( pShape->shapeData()->shapeType() == KivioShapeData::kstTextBox )
1672 {
1673 return pShape->shapeData()->hTextAlign();
1674 }
1675
1676 pShape = m_pShapeList->next();
1677 }
1678
1679 return 1;
1680}
1681
1682
1686int KivioSMLStencil::vTextAlign()
1687{
1688 KivioShape *pShape;
1689
1690 pShape = m_pShapeList->first();
1691 while( pShape )
1692 {
1693 if( pShape->shapeData()->shapeType() == KivioShapeData::kstTextBox )
1694 {
1695 return pShape->shapeData()->vTextAlign();
1696 }
1697
1698 pShape = m_pShapeList->next();
1699 }
1700
1701 return 1;
1702}
1703
1704
1708TQString KivioSMLStencil::text()
1709{
1710 KivioShape *pShape;
1711
1712 pShape = m_pShapeList->first();
1713 while( pShape )
1714 {
1715 if( pShape->shapeData()->shapeType() == KivioShapeData::kstTextBox )
1716 {
1717 return pShape->shapeData()->text();
1718 }
1719
1720 pShape = m_pShapeList->next();
1721 }
1722
1723 return TQString("");
1724}
1725
1726
1730void KivioSMLStencil::setText( const TQString &t )
1731{
1732 KivioShape *pShape;
1733
1734 pShape = m_pShapeList->first();
1735 while( pShape )
1736 {
1737 if( pShape->shapeData()->shapeType() == KivioShapeData::kstTextBox )
1738 {
1739 pShape->shapeData()->setText(t);
1740 }
1741
1742 pShape = m_pShapeList->next();
1743 }
1744}
1745
1746
1750double KivioSMLStencil::lineWidth()
1751{
1752 KivioShape *pShape;
1753
1754 pShape = m_pShapeList->first();
1755 if( pShape )
1756 return pShape->shapeData()->lineStyle()->width();
1757
1758 return 1.0f;
1759}
1760
1761int KivioSMLStencil::linePattern()
1762{
1763 KivioShape *pShape = m_pShapeList->first();
1764
1765 if( pShape )
1766 return pShape->shapeData()->lineStyle()->style();
1767
1768 return 1;
1769}
1770
1774TQColor KivioSMLStencil::fgColor()
1775{
1776 KivioShape *pShape;
1777
1778 pShape = m_pShapeList->first();
1779 if( pShape )
1780 return pShape->shapeData()->lineStyle()->color();
1781
1782 return TQColor(0,0,0);
1783}
1784
1785
1789TQColor KivioSMLStencil::bgColor()
1790{
1791 KivioShape *pShape;
1792
1793 pShape = m_pShapeList->first();
1794 if( pShape )
1795 return pShape->shapeData()->fillStyle()->color();
1796
1797 return TQColor(0,0,0);
1798}
1799
1800int KivioSMLStencil::fillPattern()
1801{
1802 KivioShape *pShape;
1803
1804 pShape = m_pShapeList->first();
1805 if( pShape )
1806 return pShape->shapeData()->fillStyle()->brushStyle();
1807
1808 return 1;
1809}
1810
1814int KivioSMLStencil::generateIds( int nextAvailable )
1815{
1816 KivioConnectorTarget *pTarget = m_pConnectorTargets->first();
1817
1818 // Iterate through all the targets
1819 while( pTarget )
1820 {
1821 // If this target has something connected to it
1822 if( pTarget->hasConnections() )
1823 {
1824 // Set it's id to the next available id
1825 pTarget->setId( nextAvailable );
1826
1827 // Increment the next available id
1828 nextAvailable++;
1829 }
1830 else
1831 {
1832 // Otherwise mark it as unused (-1)
1833 pTarget->setId( -1 );
1834 }
1835
1836 pTarget = m_pConnectorTargets->next();
1837 }
1838
1839 // Return the next availabe id
1840 return nextAvailable;
1841}
1842
1846KivioCollisionType KivioSMLStencil::checkForCollision( KoPoint *pPoint, double )
1847{
1848 KivioCollisionType type = kctNone;
1849
1850 TQWMatrix m;
1851 m.translate(m_x, m_y);
1852 m.translate(m_w / 2.0, m_h / 2.0);
1853 m.rotate(m_rotation);
1854 m.translate(-m_w / 2.0, -m_h / 2.0);
1855
1856 KoPoint pPoints[4];
1857 pPoints[0].setX(0 * m.m11() + 0 * m.m21() + m.dx());
1858 pPoints[0].setY(0 * m.m12() + 0 * m.m22() + m.dy());
1859 pPoints[1].setX(m_w * m.m11() + 0 * m.m21() + m.dx());
1860 pPoints[1].setY(m_w * m.m12() + 0 * m.m22() + m.dy());
1861 pPoints[2].setX(m_w * m.m11() + m_h * m.m21() + m.dx());
1862 pPoints[2].setY(m_w * m.m12() + m_h * m.m22() + m.dy());
1863 pPoints[3].setX(0 * m.m11() + m_h * m.m21() + m.dx());
1864 pPoints[3].setY(0 * m.m12() + m_h * m.m22() + m.dy());
1865
1866 if(PointInPoly(pPoints, 4, pPoint)) {
1867 type = kctBody;
1868 }
1869
1870 return type;
1871}
1872
1873bool KivioSMLStencil::checkCollisionArc( KivioShape *, KoPoint * )
1874{
1875 return false;
1876}
1877
1878
1879bool KivioSMLStencil::checkCollisionBezier( KivioShape *, KoPoint * )
1880{
1881 return false;
1882}
1883
1884bool KivioSMLStencil::checkCollisionOpenPath( KivioShape *, KoPoint * )
1885{
1886 return false;
1887}
1888
1889bool KivioSMLStencil::checkCollisionClosedPath( KivioShape *, KoPoint * )
1890{
1891 return false;
1892}
1893
1894bool KivioSMLStencil::checkCollisionPie( KivioShape *, KoPoint * )
1895{
1896 return false;
1897}
1898
1899bool KivioSMLStencil::checkCollisionEllipse( KivioShape *, KoPoint * )
1900{
1901 return false;
1902}
1903
1904bool KivioSMLStencil::checkCollisionLineArray( KivioShape *, KoPoint * )
1905{
1906 return false;
1907}
1908
1909bool KivioSMLStencil::checkCollisionRectangle( KivioShape *, KoPoint * )
1910{
1911 return false;
1912}
1913
1914bool KivioSMLStencil::checkCollisionRoundRectangle( KivioShape *, KoPoint * )
1915{
1916 return false;
1917}
1918
1919bool KivioSMLStencil::checkCollisionPolygon( KivioShape *pShape, KoPoint *pCheckPoint )
1920{
1921 double _x, _y, defWidth, defHeight;
1922 KivioShapeData *pShapeData;
1923 TQPtrList<KivioPoint> *pList;
1924 KoPoint *pPoints;
1925
1926 pShapeData = pShape->shapeData();
1927
1928 defWidth = m_pSpawner->defWidth();
1929 defHeight = m_pSpawner->defHeight();
1930
1931 pList = pShapeData->pointList();
1932
1933 pPoints = new KoPoint[pList->count()];
1934
1935 KivioPoint *pPoint;
1936 int i=0;
1937 pPoint = pList->first();
1938 while( pPoint )
1939 {
1940 _x = m_zoomHandler->zoomItX((pPoint->x() / defWidth) * m_w);
1941 _y = m_zoomHandler->zoomItY((pPoint->y() / defHeight) * m_h);
1942
1943 pPoints[i].setX(_x);
1944 pPoints[i].setY(_y);
1945
1946 i++;
1947
1948 pPoint = pList->next();
1949 }
1950
1951 if( PointInPoly( pPoints, i, pCheckPoint ) )
1952 {
1953 delete [] pPoints;
1954 return true;
1955 }
1956
1957 delete [] pPoints;
1958
1959 return false;
1960}
1961
1962bool KivioSMLStencil::checkCollisionPolyline( KivioShape *, KoPoint * )
1963{
1964 return false;
1965}
1966
1967bool KivioSMLStencil::checkCollisionTextBox( KivioShape *, KoPoint * )
1968{
1969 return false;
1970}
1971
1972
1976int KivioSMLStencil::resizeHandlePositions()
1977{
1978 // Calculate the resize handle positions
1979 int mask = KIVIO_RESIZE_HANDLE_POSITION_ALL;
1980
1981 if( m_pProtection->at( kpWidth ) )
1982 {
1983 mask &= ~(krhpNE | krhpNW | krhpSW | krhpSE | krhpE | krhpW);
1984 }
1985
1986 if( m_pProtection->at( kpHeight ) )
1987 {
1988 mask &= ~(krhpNE | krhpNW | krhpSW | krhpSE | krhpN | krhpS);
1989 }
1990
1991 if( m_pProtection->at( kpAspect ) )
1992 {
1993 mask = KIVIO_RESIZE_HANDLE_POSITION_CORNERS;
1994 }
1995
1996 return mask;
1997}
1998
1999KivioLineStyle KivioSMLStencil::lineStyle()
2000{
2001 KivioShape *pShape = m_pShapeList->first();
2002
2003 if( pShape )
2004 return *(pShape->shapeData()->lineStyle());
2005
2006 return KivioLineStyle();
2007}
2008
2009void KivioSMLStencil::setLineStyle(KivioLineStyle ls)
2010{
2011 KivioShape *pShape = m_pShapeList->first();
2012
2013 while( pShape )
2014 {
2015 pShape->shapeData()->setLineStyle(ls);;
2016 pShape = m_pShapeList->next();
2017 }
2018}
2019
2020TQString KivioSMLStencil::getTextBoxName(const KoPoint& p)
2021{
2022 KivioShape* pShape = m_pShapeList->first();
2023 KivioShape* first = 0;
2024 KoPoint pos = p;
2025
2026 // Calculate the rotation...
2027 TQWMatrix m;
2028 m.translate(m_x, m_y);
2029 m.translate(m_w / 2.0, m_h / 2.0);
2030 m.rotate(m_rotation);
2031 m.translate(-m_w / 2.0, -m_h / 2.0);
2032
2033 while(pShape)
2034 {
2035 if(pShape->shapeData()->shapeType() == KivioShapeData::kstTextBox)
2036 {
2037 double x = pShape->shapeData()->x();
2038 double y = pShape->shapeData()->y();
2039 double x2 = pShape->shapeData()->w() + x;
2040 double y2 = pShape->shapeData()->h() + y;
2041
2042 // Create the rotated rectangle
2043 KoPoint pPoints[4];
2044 pPoints[0].setX(x * m.m11() + y * m.m21() + m.dx());
2045 pPoints[0].setY(x * m.m12() + y * m.m22() + m.dy());
2046 pPoints[1].setX(x2 * m.m11() + y * m.m21() + m.dx());
2047 pPoints[1].setY(x2 * m.m12() + y * m.m22() + m.dy());
2048 pPoints[2].setX(x2 * m.m11() + y2 * m.m21() + m.dx());
2049 pPoints[2].setY(x2 * m.m12() + y2 * m.m22() + m.dy());
2050 pPoints[3].setX(x * m.m11() + y2 * m.m21() + m.dx());
2051 pPoints[3].setY(x * m.m12() + y2 * m.m22() + m.dy());
2052
2053 if(PointInPoly(pPoints, 4, &pos)) {
2054 return pShape->shapeData()->name();
2055 }
2056
2057 if(!first) {
2058 first = pShape;
2059 }
2060 }
2061
2062 pShape = m_pShapeList->next();
2063 }
2064
2065 if(first) {
2066 return first->shapeData()->name();
2067 }
2068
2069 return TQString();
2070}
2071
2072void KivioSMLStencil::setText(const TQString& text, const TQString& name)
2073{
2074 KivioShape* pShape = m_pShapeList->first();
2075
2076 while(pShape)
2077 {
2078 if(pShape->shapeData()->name() == name)
2079 {
2080 pShape->shapeData()->setText(text);
2081 return;
2082 }
2083
2084 pShape = m_pShapeList->next();
2085 }
2086}
2087
2088TQString KivioSMLStencil::text(const TQString& name)
2089{
2090 KivioShape* pShape = m_pShapeList->first();
2091
2092 while(pShape)
2093 {
2094 if(pShape->shapeData()->name() == name)
2095 {
2096 return pShape->shapeData()->text();
2097 }
2098
2099 pShape = m_pShapeList->next();
2100 }
2101
2102 return TQString();
2103}
2104
2105void KivioSMLStencil::addConnectorTarget(const KoPoint& p)
2106{
2107 KivioConnectorTarget* target = new KivioConnectorTarget(p.x(), p.y(), (p.x() - x())/ w(), (p.y() - y())/ h());
2108 m_pConnectorTargets->append(target);
2109}
2110
2111void KivioSMLStencil::removeConnectorTarget(const KoPoint& pos)
2112{
2113 KivioConnectorTarget* target = m_pConnectorTargets->first();
2114
2115 while(target)
2116 {
2117 if(target->position() == pos)
2118 {
2119 m_pConnectorTargets->remove(target);
2120 return;
2121 }
2122
2123 target = m_pConnectorTargets->next();
2124 }
2125}
2126
2127bool KivioSMLStencil::hasTextBox() const
2128{
2129 KivioShape* pShape = m_pShapeList->first();
2130 while(pShape) {
2131 if(pShape->shapeData()->shapeType() == KivioShapeData::kstTextBox) {
2132 return true;
2133 }
2134
2135 pShape = m_pShapeList->next();
2136 }
2137
2138 return false;
2139}
2140
2141TQColor KivioSMLStencil::textColor(const TQString& textBoxName)
2142{
2143 KivioShape* shape = locateShape(textBoxName);
2144
2145 if(!shape)
2146 return textColor();
2147
2148 return shape->shapeData()->textColor();
2149}
2150
2151void KivioSMLStencil::setTextColor(const TQString& textBoxName, const TQColor& color)
2152{
2153 KivioShape* shape = locateShape(textBoxName);
2154
2155 // If we didn't find the shape set the color stencil wide
2156 if(!shape) {
2157 setTextColor(color);
2158 return;
2159 }
2160
2161 shape->shapeData()->setTextColor(color);
2162}
2163
2164TQFont KivioSMLStencil::textFont(const TQString& textBoxName)
2165{
2166 KivioShape* shape = locateShape(textBoxName);
2167
2168 if(!shape)
2169 return textFont();
2170
2171 return shape->shapeData()->textFont();
2172}
2173
2174void KivioSMLStencil::setTextFont(const TQString& textBoxName, const TQFont& font)
2175{
2176 KivioShape* shape = locateShape(textBoxName);
2177
2178 if(!shape) {
2179 setTextFont(font);
2180 return;
2181 }
2182
2183 shape->shapeData()->setTextFont(font);
2184}
2185
2186int KivioSMLStencil::hTextAlign(const TQString& textBoxName)
2187{
2188 KivioShape* shape = locateShape(textBoxName);
2189
2190 if(!shape)
2191 return hTextAlign();
2192
2193 return shape->shapeData()->hTextAlign();
2194}
2195
2196int KivioSMLStencil::vTextAlign(const TQString& textBoxName)
2197{
2198 KivioShape* shape = locateShape(textBoxName);
2199
2200 if(!shape)
2201 return vTextAlign();
2202
2203 return shape->shapeData()->vTextAlign();
2204}
2205
2206void KivioSMLStencil::setHTextAlign(const TQString& textBoxName, int align)
2207{
2208 KivioShape* shape = locateShape(textBoxName);
2209
2210 if(!shape) {
2211 setHTextAlign(align);
2212 return;
2213 }
2214
2215 shape->shapeData()->setHTextAlign(align);
2216}
2217
2218void KivioSMLStencil::setVTextAlign(const TQString& textBoxName, int align)
2219{
2220 KivioShape* shape = locateShape(textBoxName);
2221
2222 if(!shape) {
2223 setVTextAlign(align);
2224 return;
2225 }
2226
2227 shape->shapeData()->setVTextAlign(align);
2228}