kivio_screen_painter.cpp
1/*
2 * Kivio - Visual Modelling and Flowcharting
3 * Copyright (C) 2000-2001 theKompany.com & Dave Marotti
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
9 *
10 * This program 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
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 */
19#include "kivioglobal.h"
20#include "kivio_line_style.h"
21#include "kivio_point.h"
22#include "kivio_screen_painter.h"
23
24#include <tqimage.h>
25#include <tqpen.h>
26#include <tqbrush.h>
27#include <tqsimplerichtext.h>
28#include <tqpalette.h>
29
30#include <kdebug.h>
31
32#define PAINTER_CHECK() { if(!m_pPainter) { kdDebug(43000) << "KivioScreenPainter::PAINTER_CHECK() - no TQPainter exists." << endl; } }
33
34
35KivioScreenPainter::KivioScreenPainter()
36 : m_pPainter(NULL)
37{
38 m_transX = 0.0f;
39 m_transY = 0.0f;
40 m_rotation = 0;
41}
42
43KivioScreenPainter::KivioScreenPainter(TQPainter* painter)
44 : m_pPainter(painter)
45{
46 m_transX = 0.0f;
47 m_transY = 0.0f;
48 m_rotation = 0;
49}
50
51KivioScreenPainter::~KivioScreenPainter()
52{
53 if( m_pPainter )
54 {
55 kdDebug(43000) << "KivioScreenPainter::~KivioScreenPainter - A TQPainter slipped through the cracks" << endl;
56 delete m_pPainter;
57 m_pPainter = NULL;
58 }
59}
60
70bool KivioScreenPainter::start( TQPaintDevice *dev )
71{
72 // Bomb out if one exists already
73 if( m_pPainter )
74 {
75 kdDebug(43000) << "KivioScreenPainter::start() - A TQPainter already exists" << endl;
76 return false;
77 }
78
79 // Allocate a new drawing thingy
80 m_pPainter = new TQPainter(dev);
81
82 return true;
83}
84
85
92bool KivioScreenPainter::stop()
93{
94 // Bomb out if we don't have a painter. This means that they never
95 // called @ref start().
96 if( !m_pPainter )
97 {
98 kdDebug(43000) <<"KivioScreenPainter::stop() called without previous call to start" << endl;
99 return false;
100 }
101
102 // Otherwise delete and nullify the pointer
103 delete m_pPainter;
104 m_pPainter = NULL;
105
106 return true;
107}
108
109
110
122void KivioScreenPainter::drawLine( float x1, float y1, float x2, float y2 )
123{
124 PAINTER_CHECK();
125
126 m_pPainter->setPen(m_pLineStyle->pen(1.0f));
127
128 m_pPainter->drawLine( int(x1), int(y1), int(x2), int(y2) );
129
130}
131
132
145void KivioScreenPainter::drawArc( float x1, float y1, float w1, float h1, float a1, float a2 )
146{
147 PAINTER_CHECK();
148
149 m_pPainter->setPen(m_pLineStyle->pen(1.0f));
150
151 m_pPainter->drawArc( int(x1), int(y1), int(w1), int(h1), int(a1), int(a2) );
152}
153
154
163void KivioScreenPainter::drawBezier( TQPointArray &pArray )
164{
165 PAINTER_CHECK();
166
167 m_pPainter->setPen(m_pLineStyle->pen(1.0f));
168
169 m_pPainter->drawCubicBezier(pArray);
170}
171
172
181void KivioScreenPainter::drawRect( float x1, float y1, float w1, float h1 )
182{
183 PAINTER_CHECK();
184
185 m_pPainter->setPen(m_pLineStyle->pen(1.0f));
186 m_pPainter->setBrush(TQBrush::NoBrush);
187 m_pPainter->drawRect( int(x1), int(y1), int(w1), int(h1) );
188}
189
190
202void KivioScreenPainter::fillRect( float x1, float y1, float w1, float h1 )
203{
204 PAINTER_CHECK();
205
206 TQBrush b;
207 b = m_pFillStyle->brush();
208
209 if(m_pFillStyle->colorStyle() == KivioFillStyle::kcsGradient) {
210 TQPixmap pix((int)w1, (int)h1);
211 TQImage image = KImageEffect::gradient(pix.size(), m_pFillStyle->color(), m_pFillStyle->color2(),
212 (KImageEffect::GradientType) m_pFillStyle->gradientType());
213 pix.convertFromImage(image);
214 b.setPixmap(pix);
215 m_pPainter->setBrushOrigin(int(x1 + m_transX), int(y1 + m_transY));
216 }
217
218 m_pPainter->setPen(m_pLineStyle->pen(1.0f));
219 m_pPainter->setBrush(b);
220 m_pPainter->drawRect( int(x1), int(y1), int(w1), int(h1) );
221 m_pPainter->setBrushOrigin(0, 0);
222}
223
224
238void KivioScreenPainter::drawRoundRect( float x1, float y1, float w1, float h1, float a1, float a2 )
239{
240 PAINTER_CHECK();
241
242 m_pPainter->setPen(m_pLineStyle->pen(1.0f));
243 m_pPainter->setBrush(TQBrush::NoBrush);
244 m_pPainter->drawRoundRect( int(x1), int(y1), int(w1), int(h1), int(a1), int(a2) );
245}
246
247
248
262void KivioScreenPainter::fillRoundRect( float x1, float y1, float w1, float h1, float a1, float a2 )
263{
264 PAINTER_CHECK();
265
266 TQBrush b;
267 b = m_pFillStyle->brush();
268
269 if(m_pFillStyle->colorStyle() == KivioFillStyle::kcsGradient) {
270 TQPixmap pix((int)w1, (int)h1);
271 TQImage image = KImageEffect::gradient(pix.size(), m_pFillStyle->color(), m_pFillStyle->color2(),
272 (KImageEffect::GradientType) m_pFillStyle->gradientType());
273 pix.convertFromImage(image);
274 b.setPixmap(pix);
275 m_pPainter->setBrushOrigin(int(x1 + m_transX), int(y1 + m_transY));
276 }
277
278 m_pPainter->setPen(m_pLineStyle->pen(1.0f));
279 m_pPainter->setBrush(b);
280 m_pPainter->drawRoundRect( int(x1), int(y1), int(w1), int(h1), int(a1), int(a2) );
281 m_pPainter->setBrushOrigin(0, 0);
282}
283
284
298void KivioScreenPainter::drawPie( float x1, float y1, float w1, float h1, float a1, float a2 )
299{
300 PAINTER_CHECK();
301
302 m_pPainter->setPen(m_pLineStyle->pen(1.0f));
303 m_pPainter->setBrush(TQBrush::NoBrush);
304 m_pPainter->drawPie( int(x1), int(y1), int(w1), int(h1), int(a1), int(a2) );
305}
306
307
321void KivioScreenPainter::fillPie( float x1, float y1, float w1, float h1, float a1, float a2 )
322{
323 PAINTER_CHECK();
324
325 TQBrush b;
326 b = m_pFillStyle->brush();
327
328 if(m_pFillStyle->colorStyle() == KivioFillStyle::kcsGradient) {
329 TQPixmap pix((int)w1, (int)h1);
330 TQImage image = KImageEffect::gradient(pix.size(), m_pFillStyle->color(), m_pFillStyle->color2(),
331 (KImageEffect::GradientType) m_pFillStyle->gradientType());
332 pix.convertFromImage(image);
333 b.setPixmap(pix);
334 m_pPainter->setBrushOrigin(int(x1 + m_transX), int(y1 + m_transY));
335 }
336
337 m_pPainter->setPen(m_pLineStyle->pen(1.0f));
338 m_pPainter->setBrush(b);
339 m_pPainter->drawPie( int(x1), int(y1), int(w1), int(h1), int(a1), int(a2) );
340 m_pPainter->setBrushOrigin(0, 0);
341}
342
343
357void KivioScreenPainter::drawChord( float x1, float y1, float w1, float h1, float a1, float a2 )
358{
359 PAINTER_CHECK();
360
361 m_pPainter->setPen(m_pLineStyle->pen(1.0f));
362 m_pPainter->setBrush(TQBrush::NoBrush);
363 m_pPainter->drawChord( int(x1), int(y1), int(w1), int(h1), int(a1), int(a2) );
364}
365
366
380void KivioScreenPainter::fillChord( float x1, float y1, float w1, float h1, float a1, float a2 )
381{
382 PAINTER_CHECK();
383
384 TQBrush b;
385 b = m_pFillStyle->brush();
386
387 if(m_pFillStyle->colorStyle() == KivioFillStyle::kcsGradient) {
388 TQPixmap pix((int)w1, (int)h1);
389 TQImage image = KImageEffect::gradient(pix.size(), m_pFillStyle->color(),
390 m_pFillStyle->color2(), m_pFillStyle->gradientType());
391 pix.convertFromImage(image);
392 b.setPixmap(pix);
393 m_pPainter->setBrushOrigin(int(x1 + m_transX), int(y1 + m_transY));
394 }
395
396 m_pPainter->setPen(m_pLineStyle->pen(1.0f));
397 m_pPainter->setBrush(b);
398 m_pPainter->drawChord( int(x1), int(y1), int(w1), int(h1), int(a1), int(a2) );
399 m_pPainter->setBrushOrigin(0, 0);
400}
401
402
414void KivioScreenPainter::drawEllipse( float x1, float y1, float w1, float h1 )
415{
416 PAINTER_CHECK();
417
418 m_pPainter->setPen(m_pLineStyle->pen(1.0f));
419 m_pPainter->setBrush(TQBrush::NoBrush);
420 m_pPainter->drawEllipse( int(x1), int(y1), int(w1), int(h1) );
421}
422
423
435void KivioScreenPainter::fillEllipse( float x1, float y1, float w1, float h1 )
436{
437 PAINTER_CHECK();
438
439 TQBrush b;
440 b = m_pFillStyle->brush();
441
442 if(m_pFillStyle->colorStyle() == KivioFillStyle::kcsGradient) {
443 TQPixmap pix((int)w1, (int)h1);
444 TQImage image = KImageEffect::gradient(pix.size(), m_pFillStyle->color(), m_pFillStyle->color2(),
445 (KImageEffect::GradientType) m_pFillStyle->gradientType());
446 pix.convertFromImage(image);
447 b.setPixmap(pix);
448 m_pPainter->setBrushOrigin(int(x1 + m_transX), int(y1 + m_transY));
449 }
450
451 m_pPainter->setPen(m_pLineStyle->pen(1.0f));
452 m_pPainter->setBrush(b);
453 m_pPainter->drawEllipse( int(x1), int(y1), int(w1), int(h1) );
454 m_pPainter->setBrushOrigin(0, 0);
455}
456
457
466void KivioScreenPainter::drawLineArray( TQPtrList<KivioPoint> *pList )
467{
468 PAINTER_CHECK();
469
470 KivioPoint *pPoint;
471 TQPointArray points(pList->count());
472 int i;
473 TQBrush b;
474
475 b.setStyle( TQt::NoBrush );
476
477 i=0;
478 pPoint = pList->first();
479 while( pPoint )
480 {
481 points.setPoint( i++, int(pPoint->x()), int(pPoint->y()) );
482
483 pPoint = pList->next();
484 }
485
486 m_pPainter->setPen(m_pLineStyle->pen(1.0f));
487 m_pPainter->setBrush(b);
488
489 m_pPainter->drawLineSegments(points);
490}
491
492
500void KivioScreenPainter::drawPolyline( TQPtrList<KivioPoint> *pList )
501{
502 PAINTER_CHECK();
503
504 KivioPoint *pPoint;
505 TQPointArray points( pList->count() );
506 int i = 0;
507 pPoint = pList->first();
508
509 while( pPoint )
510 {
511 points.setPoint(i++, int(pPoint->x()), int(pPoint->y()) );
512 pPoint = pList->next();
513 }
514
515 drawPolyline(points);
516}
517
518
519
527void KivioScreenPainter::drawPolygon( TQPtrList<KivioPoint> *pList )
528{
529 PAINTER_CHECK();
530
531 KivioPoint *pPoint;
532 TQPointArray points( pList->count() );
533 int i = 0;
534 pPoint = pList->first();
535
536 while( pPoint )
537 {
538 points.setPoint(i++, int(pPoint->x()), int(pPoint->y()) );
539 pPoint = pList->next();
540 }
541
542 drawPolygon(points);
543}
544
545void KivioScreenPainter::drawPolyline( TQPointArray &pArray )
546{
547 PAINTER_CHECK();
548
549 m_pPainter->setPen(m_pLineStyle->pen(1.0f));
550 m_pPainter->setBrush( TQBrush::NoBrush );
551
552 m_pPainter->drawPolyline( pArray, 0, pArray.size() );
553}
554
555void KivioScreenPainter::drawPolygon( TQPointArray &pArray )
556{
557 PAINTER_CHECK();
558
559 TQBrush b;
560 b = m_pFillStyle->brush();
561
562 if(m_pFillStyle->colorStyle() == KivioFillStyle::kcsGradient) {
563 int x1, y1, w1, h1;
564 x1 = pArray[0].x();
565 y1 = pArray[0].y();
566 w1 = h1 = 0;
567
568 for(unsigned int i = 0; i < pArray.count(); i++) {
569 x1 = TQMIN(x1, pArray[i].x());
570 y1 = TQMIN(y1, pArray[i].y());
571 w1 = TQMAX(w1, pArray[i].x());
572 h1 = TQMAX(h1, pArray[i].y());
573 }
574
575 w1 = w1 - x1;
576 h1 = h1 - y1;
577
578 TQPixmap pix(w1, h1);
579 TQImage image = KImageEffect::gradient(pix.size(), m_pFillStyle->color(), m_pFillStyle->color2(),
580 (KImageEffect::GradientType) m_pFillStyle->gradientType());
581 pix.convertFromImage(image);
582 b.setPixmap(pix);
583 m_pPainter->setBrushOrigin(x1 + (int)m_transX, y1 + (int)m_transY);
584 }
585
586 m_pPainter->setPen(m_pLineStyle->pen(1.0f));
587 m_pPainter->setBrush(b);
588
589 m_pPainter->drawPolygon( pArray, true );
590 m_pPainter->setBrushOrigin(0, 0);
591}
592
593void KivioScreenPainter::drawLineArray( TQPointArray &pArray )
594{
595 PAINTER_CHECK();
596
597 m_pPainter->setPen(m_pLineStyle->pen(1.0f));
598 m_pPainter->setBrush(TQBrush::NoBrush);
599
600 m_pPainter->drawLineSegments(pArray);
601}
602
603
612void KivioScreenPainter::drawClosedPath( TQPtrList<KivioPoint> *pPoints )
613{
614 PAINTER_CHECK();
615
616 TQBrush brush;
617
618 KivioPoint *pPoint, *pPoint2, *pPoint3, *pPoint4;
619 TQPtrList <KivioPoint> *pPointList = pPoints;
620 TQPointArray controlPoints(4), bPoints(0), tmpPoints;
621
622 int pointIndex=0;
623 pPoint = pPointList->first();
624 while( pPoint )
625 {
626 if( pPoint->pointType() == KivioPoint::kptNormal )
627 {
628 bPoints.putPoints( pointIndex, 1, int(pPoint->x()), int(pPoint->y()) );
629 pointIndex++;
630 }
631 else if( pPoint->pointType() == KivioPoint::kptBezier )
632 {
633 pPoint2 = pPointList->next();
634 pPoint3 = pPointList->next();
635 pPoint4 = pPointList->next();
636
637 if( !pPoint2 || !pPoint3 || !pPoint4 )
638 {
639 kdDebug(43000) << "drawClosedPath() - incorrect # of bezier points" << endl;
640 return;
641 }
642
643 if( pPoint2->pointType() != KivioPoint::kptBezier ||
644 pPoint3->pointType() != KivioPoint::kptBezier ||
645 pPoint4->pointType() != KivioPoint::kptBezier )
646 {
647 kdDebug(43000) << "drawClosedPath() - bezier curves must have 4 points" << endl;
648 return;
649 }
650
651 controlPoints.setPoint( 0, tqRound(pPoint->x()), tqRound(pPoint->y()) );
652 controlPoints.setPoint( 1, tqRound(pPoint2->x()), tqRound(pPoint2->y()) );
653 controlPoints.setPoint( 2, tqRound(pPoint3->x()), tqRound(pPoint3->y()) );
654 controlPoints.setPoint( 3, tqRound(pPoint4->x()), tqRound(pPoint4->y()) );
655
656 tmpPoints = controlPoints.cubicBezier();
657
658 for( int j=0; j<int(tmpPoints.size()); j++ )
659 {
660 bPoints.putPoints( pointIndex, 1, tmpPoints.point(j).x(), tmpPoints.point(j).y() );
661 pointIndex++;
662 }
663 } // end pointtype==bezier
664 else if( pPoint->pointType() == KivioPoint::kptArc )
665 {
666 pPoint2 = pPointList->next();
667 pPoint3 = pPointList->next();
668
669 if( !pPoint2 || !pPoint3 )
670 {
671 kdDebug(43000) << "drawClosedPath() - incorrect # of arc points" << endl;
672 return;
673 }
674 if( pPoint2->pointType() != KivioPoint::kptArc ||
675 pPoint3->pointType() != KivioPoint::kptArc )
676 {
677 kdDebug(43000) << "drawClosedPath() - Arc points must come in triplets" << endl;
678 return;
679 }
680
681 tmpPoints.makeArc( tqRound(pPoint->x()), tqRound(pPoint->y()), tqRound(pPoint2->x()), tqRound(pPoint2->y()),
682 tqRound(pPoint3->x()), tqRound(pPoint3->y()) );
683
684 for( int j=0; j<int(tmpPoints.size()); j++ )
685 {
686 bPoints.putPoints( pointIndex, 1, tmpPoints.point(j).x(),tmpPoints.point(j).y());
687 pointIndex++;
688 }
689 } // end pointtype==arc
690 else
691 {
692 kdDebug(43000) << "drawClosedPath() - Unknown point type discovered. WOOO!!!" << endl;
693 }
694
695 pPoint = pPointList->next();
696 }
697
698 // If we make it here, the list is built
699 switch( m_pFillStyle->colorStyle() )
700 {
701 case KivioFillStyle::kcsNone:
702 // A hollow path? That's a polypath!
703 drawPolyline( bPoints );
704 break;
705
706 case KivioFillStyle::kcsSolid:
707 case KivioFillStyle::kcsGradient:
708 {
709 drawPolygon(bPoints);
710 break;
711 }
712
713 default:
714 kdDebug(43000) << "drawClosedPath() - Unknown colors style" << endl;
715 break;
716 }
717}
718
719void KivioScreenPainter::drawOpenPath( TQPtrList<KivioPoint> *pPoints )
720{
721 PAINTER_CHECK();
722
723 TQBrush brush;
724
725 KivioPoint *pPoint, *pPoint2, *pPoint3, *pPoint4;
726 TQPtrList <KivioPoint> *pPointList = pPoints;
727 TQPointArray controlPoints(4), bPoints(0), tmpPoints;
728
729 int pointIndex=0;
730 pPoint = pPointList->first();
731 while( pPoint )
732 {
733 if( pPoint->pointType() == KivioPoint::kptNormal )
734 {
735 bPoints.putPoints( pointIndex, 1, int(pPoint->x()), int(pPoint->y()) );
736 pointIndex++;
737 }
738 else if( pPoint->pointType() == KivioPoint::kptBezier )
739 {
740 pPoint2 = pPointList->next();
741 pPoint3 = pPointList->next();
742 pPoint4 = pPointList->next();
743
744 if( !pPoint2 || !pPoint3 || !pPoint4 )
745 {
746 kdDebug(43000) << "drawOpenPath() - incorrect # of bezier points" << endl;
747 return;
748 }
749
750 if( pPoint2->pointType() != KivioPoint::kptBezier ||
751 pPoint3->pointType() != KivioPoint::kptBezier ||
752 pPoint4->pointType() != KivioPoint::kptBezier )
753 {
754 kdDebug(43000) << "drawOpenPath() - bezier curves must have 4 points" << endl;
755 return;
756 }
757
758 controlPoints.setPoint( 0, tqRound(pPoint->x()), tqRound(pPoint->y()) );
759 controlPoints.setPoint( 1, tqRound(pPoint2->x()), tqRound(pPoint2->y()) );
760 controlPoints.setPoint( 2, tqRound(pPoint3->x()), tqRound(pPoint3->y()) );
761 controlPoints.setPoint( 3, tqRound(pPoint4->x()), tqRound(pPoint4->y()) );
762
763 tmpPoints = controlPoints.cubicBezier();
764
765 for( int j=0; j<int(tmpPoints.size()); j++ )
766 {
767 bPoints.putPoints( pointIndex, 1, tmpPoints.point(j).x(), tmpPoints.point(j).y() );
768 pointIndex++;
769 }
770 } // end pointtype==bezier
771 else if( pPoint->pointType() == KivioPoint::kptArc )
772 {
773 pPoint2 = pPointList->next();
774 pPoint3 = pPointList->next();
775
776 if( !pPoint2 || !pPoint3 )
777 {
778 kdDebug(43000) << "drawOpenPath() - incorrect # of arc points" << endl;
779 return;
780 }
781 if( pPoint2->pointType() != KivioPoint::kptArc ||
782 pPoint3->pointType() != KivioPoint::kptArc )
783 {
784 kdDebug(43000) << "drawOpenPath() - Arc points must come in triplets" << endl;
785 return;
786 }
787
788 tmpPoints.makeArc( tqRound(pPoint->x()), tqRound(pPoint->y()), tqRound(pPoint2->x()), tqRound(pPoint2->y()),
789 tqRound(pPoint3->x()), tqRound(pPoint3->y()) );
790
791 for( int j=0; j<int(tmpPoints.size()); j++ )
792 {
793 bPoints.putPoints( pointIndex, 1, tmpPoints.point(j).x(),tmpPoints.point(j).y());
794 pointIndex++;
795 }
796 } // end pointtype==arc
797 else
798 {
799 kdDebug(43000) << "drawOpenPath() - Unknown point type discovered. WOOO!!!" << endl;
800 }
801
802 pPoint = pPointList->next();
803 }
804
805 m_pPainter->setPen(m_pLineStyle->pen(1.0f));
806 m_pPainter->setBrush( TQBrush::NoBrush );
807
808 m_pPainter->drawPolyline( bPoints );
809}
810
811void KivioScreenPainter::setFont( const TQFont &f )
812{
813 PAINTER_CHECK();
814
815 m_pPainter->setFont( f );
816}
817
818void KivioScreenPainter::drawText( int x, int y, int w, int h, int tf, const TQString &str )
819{
820 PAINTER_CHECK();
821
822 m_pPainter->setPen( m_textColor );
823 m_pPainter->drawText( x, y, w, h, tf, str );
824/* TQSimpleRichText textArea(str, m_pPainter->font());
825 textArea.setWidth(w);
826 TQColorGroup cg;
827 cg.setColor(TQColorGroup::Base, m_pFillStyle->color());
828 cg.setColor(TQColorGroup::Text, m_textColor);
829 TQBrush b = m_pFillStyle->brush();
830 textArea.draw(m_pPainter, x, y, TQRect(0, 0, 0, 0), cg, &b);*/
831}
832
833TQRect KivioScreenPainter::boundingRect( int x, int y, int w, int h, int tf, const TQString &str )
834{
835 PAINTER_CHECK();
836
837 return m_pPainter->boundingRect( x,y,w,h, tf, str );
838}
839
840void KivioScreenPainter::drawPixmap( float x, float y, const TQPixmap &pix )
841{
842 PAINTER_CHECK();
843 m_pPainter->drawPixmap( (int)x, (int)y, pix );
844}
845
846void KivioScreenPainter::drawHandle( float x, float y, int flags )
847{
848 PAINTER_CHECK();
849 TQColor fillColor, penColor;
850 TQBrush b;
851 TQPen p;
852
853 const float HW = 6.0f;
854 const float HWP1 = HW+1.0f;
855 const float HWo2 = HW/2.0f;
856
857 float x1, y1;
858
859 // Is it a locked handle?
860 if( flags & cpfLock )
861 {
862 x1 = x - 4;
863 y1 = y - 4;
864
865 m_pPainter->drawPixmap( tqRound(x1), tqRound(y1), Kivio::lockPixmap() );
866 return;
867 }
868
869 if( flags & cpfConnected )
870 {
871 fillColor = TQColor(200,0,0);
872 }
873 else
874 {
875 fillColor = TQColor(0,200,0);
876 }
877
878 penColor.setRgb(0, 0, 0);
879
880 b.setColor(fillColor);
881 b.setStyle(TQt::SolidPattern);
882 p.setColor(penColor);
883 m_pPainter->setPen(p);
884 m_pPainter->setBrush(b);
885
886
887 x1 = x - HWo2;
888 y1 = y - HWo2;
889
890 // first fill it
891// m_pPainter->fillRect( x1, y1, HWP1, HWP1, b );
892
893 if(flags & cpfEnd) {
894 m_pPainter->drawEllipse( tqRound(x1), tqRound(y1), tqRound(HWP1), tqRound(HWP1) );
895 } else {
896 m_pPainter->drawRect( tqRound(x1), tqRound(y1), tqRound(HWP1), tqRound(HWP1) );
897 }
898
899 // Now put something in it if needed
900 if( flags & cpfConnectable )
901 {
902 b.setColor(TQColor(0,0,0));
903
904 m_pPainter->fillRect(tqRound(x-1),tqRound(y-1),3,3, b);
905 }
906}
907
908void KivioScreenPainter::drawSelectionBox( const TQRect& r )
909{
910 PAINTER_CHECK();
911 TQPen p;
912 p.setColor(TQColor(0,200,0));
913 p.setStyle(TQt::DashLine);
914 m_pPainter->setBrush(TQt::NoBrush);
915 m_pPainter->setPen(p);
916 m_pPainter->drawRect(r);
917}
918
919void KivioScreenPainter::saveState()
920{
921 PAINTER_CHECK();
922
923 m_pPainter->save();
924}
925
926void KivioScreenPainter::restoreState()
927{
928 PAINTER_CHECK();
929
930 m_pPainter->restore();
931}
932
933void KivioScreenPainter::setTranslation( float _x, float _y )
934{
935 PAINTER_CHECK();
936
937 m_transX = _x;
938 m_transY = _y;
939
940 m_pPainter->translate(_x, _y);
941}
942
943void KivioScreenPainter::translateBy( float _x, float _y )
944{
945 PAINTER_CHECK();
946
947 m_transX += _x;
948 m_transY += _y;
949
950 m_pPainter->translate( m_transX, m_transY );
951}
952
953void KivioScreenPainter::setRotation( int _d )
954{
955 PAINTER_CHECK();
956
957 m_rotation = _d;
958
959 m_pPainter->rotate(_d);
960}
961
962void KivioScreenPainter::rotateBy( int _d )
963{
964 PAINTER_CHECK();
965
966 m_rotation += _d;
967
968 m_pPainter->rotate(m_rotation);
969}
970
971int KivioScreenPainter::rotation()
972{
973 return m_rotation;
974}
975
976void KivioScreenPainter::setWorldMatrix(TQWMatrix m, bool c)
977{
978 PAINTER_CHECK();
979 m_pPainter->setWorldMatrix(m, c);
980}