summaryrefslogtreecommitdiffstats
path: root/kivio/kiviopart/kiviosdk/kivio_screen_painter.cpp
blob: 07f005fa1c03591f0fd2e68928b59506b019a117 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
/*
 * Kivio - Visual Modelling and Flowcharting
 * Copyright (C) 2000-2001 theKompany.com & Dave Marotti
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */
#include "kivioglobal.h"
#include "kivio_line_style.h"
#include "kivio_point.h"
#include "kivio_screen_painter.h"

#include <tqimage.h>
#include <tqpen.h>
#include <tqbrush.h>
#include <tqsimplerichtext.h>
#include <tqpalette.h>

#include <kdebug.h>

#define PAINTER_CHECK() { if(!m_pPainter) { kdDebug(43000) << "KivioScreenPainter::PAINTER_CHECK() - no TQPainter exists." << endl; } }


KivioScreenPainter::KivioScreenPainter()
    : m_pPainter(NULL)
{
   m_transX = 0.0f;
   m_transY = 0.0f;
   m_rotation = 0;
}

KivioScreenPainter::KivioScreenPainter(TQPainter* painter)
    : m_pPainter(painter)
{
   m_transX = 0.0f;
   m_transY = 0.0f;
   m_rotation = 0;
}

KivioScreenPainter::~KivioScreenPainter()
{
    if( m_pPainter )
    {
       kdDebug(43000) << "KivioScreenPainter::~KivioScreenPainter - A TQPainter slipped through the cracks" << endl;
        delete m_pPainter;
        m_pPainter = NULL;
    }
}

/**
 * Starts the drawing on a @ref TQPaintDevice
 *
 * @param dev The device to paint on
 *
 * Call this function before you call any other @ref KivioScreenPainter
 * functions.  This will create an internal TQPainter object for drawing
 * with.  If you fail to call this function, nothing will work.
 */
bool KivioScreenPainter::start( TQPaintDevice *dev )
{
    // Bomb out if one exists already
    if( m_pPainter )
    {
       kdDebug(43000) << "KivioScreenPainter::start() - A TQPainter already exists" << endl;
        return false;
    }

    // Allocate a new drawing thingy
    m_pPainter = new TQPainter(dev);

    return true;
}


/**
 * Stops the drawing and flushes the drawing pipeline
 *
 * After using the @ref KivioScreenPainter object, call stop() to
 * finalize it all.
 */
bool KivioScreenPainter::stop()
{
    // Bomb out if we don't have a painter.  This means that they never
    // called @ref start().
    if( !m_pPainter )
    {
       kdDebug(43000) <<"KivioScreenPainter::stop() called without previous call to start" << endl;
        return false;
    }

    // Otherwise delete and nullify the pointer
    delete m_pPainter;
    m_pPainter = NULL;

    return true;
}



/**
 * Draws a line from one point to another
 *
 * @param x1 The first x coord
 * @param y1 The first y coord
 * @param x2 The second x coord
 * @param y2 The second y coord
 *
 * This function will draw a line from one point to another in
 * the current fgColor and using the current lineWidth.
 */
void KivioScreenPainter::drawLine( float x1, float y1, float x2, float y2 )
{
    PAINTER_CHECK();

    m_pPainter->setPen(m_pLineStyle->pen(1.0f));

    m_pPainter->drawLine( int(x1), int(y1), int(x2), int(y2) );

}


/**
 * Draws an arc
 *
 * @param x1 The x-coord of the arc-box
 * @param y1 The y-coord of the arc-box
 * @param w1 The width of the arc
 * @param h1 The height of the arc
 * @param a1 The starting angle of the arc ??
 * @param a2 The total angle of the arc???
 *
 * This will draw an arc in the current fgColor and lineWidth.
 */
void KivioScreenPainter::drawArc( float x1, float y1, float w1, float h1, float a1, float a2 )
{
    PAINTER_CHECK();

    m_pPainter->setPen(m_pLineStyle->pen(1.0f));

    m_pPainter->drawArc( int(x1), int(y1), int(w1), int(h1), int(a1), int(a2) );
}


/**
 * Draws a single quad-bezier curve
 *
 * @param pArray The array of 4 points to draw
 *
 * This will draw a quad-bezier curve in the current fgColor
 * and lineWidth.  @ref pArray must have 4 points.
 */
void KivioScreenPainter::drawBezier( TQPointArray &pArray )
{
    PAINTER_CHECK();

    m_pPainter->setPen(m_pLineStyle->pen(1.0f));

    m_pPainter->drawCubicBezier(pArray);
}


/**
 * Draws a hollow rectangle
 *
 * @param x1 The x coord
 * @param y1 The y coord
 * @param w1 The width
 * @param h1 The height
 */
void KivioScreenPainter::drawRect( float x1, float y1, float w1, float h1 )
{
    PAINTER_CHECK();

    m_pPainter->setPen(m_pLineStyle->pen(1.0f));
    m_pPainter->setBrush(TQBrush::NoBrush);
    m_pPainter->drawRect( int(x1), int(y1), int(w1), int(h1) );
}


/**
 * Draws a filled/outlined rectangle
 *
 * @param x1 The x coord
 * @param y1 The y coord
 * @param w1 The width
 * @param h1 The height
 *
 * This draws a filled, and outlined rectangle in the current
 * fgColor, lineWidth, and fillStyle.
 */
void KivioScreenPainter::fillRect( float x1, float y1, float w1, float h1 )
{
    PAINTER_CHECK();

    TQBrush b;
    b = m_pFillStyle->brush();

    if(m_pFillStyle->colorStyle() == KivioFillStyle::kcsGradient) {
      TQPixmap pix((int)w1, (int)h1);
      TQImage image = KImageEffect::gradient(pix.size(), m_pFillStyle->color(), m_pFillStyle->color2(),
        (KImageEffect::GradientType) m_pFillStyle->gradientType());
      pix.convertFromImage(image);
      b.setPixmap(pix);
      m_pPainter->setBrushOrigin(int(x1 + m_transX), int(y1 + m_transY));
    }

    m_pPainter->setPen(m_pLineStyle->pen(1.0f));
    m_pPainter->setBrush(b);
    m_pPainter->drawRect( int(x1), int(y1), int(w1), int(h1) );
    m_pPainter->setBrushOrigin(0, 0);
}


/**
 * Draws a hollow round-rectangle
 *
 * @param x1 The x coord
 * @param y1 The y coord
 * @param w1 The width
 * @param h1 The height
 * @param a1 ????
 * @param a2 ????
 *
 * This draws a hollow round-rectangle in the current
 * fgColor and lineWidth.
 */
void KivioScreenPainter::drawRoundRect( float x1, float y1, float w1, float h1, float a1, float a2 )
{
    PAINTER_CHECK();

    m_pPainter->setPen(m_pLineStyle->pen(1.0f));
    m_pPainter->setBrush(TQBrush::NoBrush);
    m_pPainter->drawRoundRect( int(x1), int(y1), int(w1), int(h1), int(a1), int(a2) );
}



/**
 * Draws a filled/outlined round-rectangle
 *
 * @param x1 The x coord
 * @param y1 The y coord
 * @param w1 The width
 * @param h1 The height
 * @param a1 ????
 * @param a2 ????
 *
 * This draws a hollow round-rectangle in the current
 * fgColor, lineWidth, and fillStyle.
 */
void KivioScreenPainter::fillRoundRect( float x1, float y1, float w1, float h1, float a1, float a2 )
{
    PAINTER_CHECK();

    TQBrush b;
    b = m_pFillStyle->brush();

    if(m_pFillStyle->colorStyle() == KivioFillStyle::kcsGradient) {
      TQPixmap pix((int)w1, (int)h1);
      TQImage image = KImageEffect::gradient(pix.size(), m_pFillStyle->color(), m_pFillStyle->color2(),
        (KImageEffect::GradientType) m_pFillStyle->gradientType());
      pix.convertFromImage(image);
      b.setPixmap(pix);
      m_pPainter->setBrushOrigin(int(x1 + m_transX), int(y1 + m_transY));
    }

    m_pPainter->setPen(m_pLineStyle->pen(1.0f));
    m_pPainter->setBrush(b);
    m_pPainter->drawRoundRect( int(x1), int(y1), int(w1), int(h1), int(a1), int(a2) );
    m_pPainter->setBrushOrigin(0, 0);
}


/**
 * Draws a hollow pie
 *
 * @param x1 The x coord
 * @param y1 The y coord
 * @param w1 The width
 * @param h1 The height
 * @param a1 ????
 * @param a2 ????
 *
 * This draws a hollow pie in the current
 * fgColor and lineWidth.
 */
void KivioScreenPainter::drawPie( float x1, float y1, float w1, float h1, float a1, float a2 )
{
    PAINTER_CHECK();

    m_pPainter->setPen(m_pLineStyle->pen(1.0f));
    m_pPainter->setBrush(TQBrush::NoBrush);
    m_pPainter->drawPie( int(x1), int(y1), int(w1), int(h1), int(a1), int(a2) );
}


/**
 * Draws a filled/outlined pie
 *
 * @param x1 The x coord
 * @param y1 The y coord
 * @param w1 The width
 * @param h1 The height
 * @param a1 ????
 * @param a2 ????
 *
 * This draws a filled/outlined pie in the current
 * fgColor, lineWidth, and fillStyle.
 */
void KivioScreenPainter::fillPie( float x1, float y1, float w1, float h1, float a1, float a2 )
{
    PAINTER_CHECK();

    TQBrush b;
    b = m_pFillStyle->brush();

    if(m_pFillStyle->colorStyle() == KivioFillStyle::kcsGradient) {
      TQPixmap pix((int)w1, (int)h1);
      TQImage image = KImageEffect::gradient(pix.size(), m_pFillStyle->color(), m_pFillStyle->color2(),
        (KImageEffect::GradientType) m_pFillStyle->gradientType());
      pix.convertFromImage(image);
      b.setPixmap(pix);
      m_pPainter->setBrushOrigin(int(x1 + m_transX), int(y1 + m_transY));
    }

    m_pPainter->setPen(m_pLineStyle->pen(1.0f));
    m_pPainter->setBrush(b);
    m_pPainter->drawPie( int(x1), int(y1), int(w1), int(h1), int(a1), int(a2) );
    m_pPainter->setBrushOrigin(0, 0);
}


/**
 * Draws a hollow chord
 *
 * @param x1 The x coord
 * @param y1 The y coord
 * @param w1 The width
 * @param h1 The height
 * @param a1 ????
 * @param a2 ????
 *
 * This draws a hollow chord in the current
 * fgColor and lineWidth.
 */
void KivioScreenPainter::drawChord( float x1, float y1, float w1, float h1, float a1, float a2 )
{
    PAINTER_CHECK();

    m_pPainter->setPen(m_pLineStyle->pen(1.0f));
    m_pPainter->setBrush(TQBrush::NoBrush);
    m_pPainter->drawChord( int(x1), int(y1), int(w1), int(h1), int(a1), int(a2) );
}


/**
 * Draws a filled/outlined chord
 *
 * @param x1 The x coord
 * @param y1 The y coord
 * @param w1 The width
 * @param h1 The height
 * @param a1 ????
 * @param a2 ????
 *
 * This draws a filled/outlined chord in the current
 * fgColor, fillStyle and lineWidth.
 */
void KivioScreenPainter::fillChord( float x1, float y1, float w1, float h1, float a1, float a2 )
{
    PAINTER_CHECK();

    TQBrush b;
    b = m_pFillStyle->brush();

    if(m_pFillStyle->colorStyle() == KivioFillStyle::kcsGradient) {
      TQPixmap pix((int)w1, (int)h1);
      TQImage image = KImageEffect::gradient(pix.size(), m_pFillStyle->color(),
        m_pFillStyle->color2(), m_pFillStyle->gradientType());
      pix.convertFromImage(image);
      b.setPixmap(pix);
      m_pPainter->setBrushOrigin(int(x1 + m_transX), int(y1 + m_transY));
    }

    m_pPainter->setPen(m_pLineStyle->pen(1.0f));
    m_pPainter->setBrush(b);
    m_pPainter->drawChord( int(x1), int(y1), int(w1), int(h1), int(a1), int(a2) );
    m_pPainter->setBrushOrigin(0, 0);
}


/**
 * Draws a hollow ellipse
 *
 * @param x1 The x coord
 * @param y1 The y coord
 * @param w1 The width
 * @param h1 The height
 *
 * This draws a hollow ellipse in the current
 * fgColor and lineWidth.
 */
void KivioScreenPainter::drawEllipse( float x1, float y1, float w1, float h1 )
{
    PAINTER_CHECK();

    m_pPainter->setPen(m_pLineStyle->pen(1.0f));
    m_pPainter->setBrush(TQBrush::NoBrush);
    m_pPainter->drawEllipse( int(x1), int(y1), int(w1), int(h1) );
}


/**
 * Draws a filled/outlined ellipse
 *
 * @param x1 The x coord
 * @param y1 The y coord
 * @param w1 The width
 * @param h1 The height
 *
 * This draws a filled/outlined ellipse in the current
 * fgColor, fillstyle and lineWidth.
 */
void KivioScreenPainter::fillEllipse( float x1, float y1, float w1, float h1 )
{
    PAINTER_CHECK();

    TQBrush b;
    b = m_pFillStyle->brush();

    if(m_pFillStyle->colorStyle() == KivioFillStyle::kcsGradient) {
      TQPixmap pix((int)w1, (int)h1);
      TQImage image = KImageEffect::gradient(pix.size(), m_pFillStyle->color(), m_pFillStyle->color2(),
        (KImageEffect::GradientType) m_pFillStyle->gradientType());
      pix.convertFromImage(image);
      b.setPixmap(pix);
      m_pPainter->setBrushOrigin(int(x1 + m_transX), int(y1 + m_transY));
    }

    m_pPainter->setPen(m_pLineStyle->pen(1.0f));
    m_pPainter->setBrush(b);
    m_pPainter->drawEllipse( int(x1), int(y1), int(w1), int(h1) );
    m_pPainter->setBrushOrigin(0, 0);
}


/**
 * Draws an array of lines
 *
 * @param pList The array of points to draw lines with
 *
 * The list of points should contain a list of points in
 * pairs.  Lines are drawn from p1->p2 p3->p4 p5->p6, etc...
 */
void KivioScreenPainter::drawLineArray( TQPtrList<KivioPoint> *pList )
{
  PAINTER_CHECK();

  KivioPoint *pPoint;
  TQPointArray points(pList->count());
  int i;
  TQBrush b;

  b.setStyle( Qt::NoBrush );

  i=0;
  pPoint = pList->first();
  while( pPoint )
  {
    points.setPoint( i++, int(pPoint->x()), int(pPoint->y()) );

    pPoint = pList->next();
  }

  m_pPainter->setPen(m_pLineStyle->pen(1.0f));
  m_pPainter->setBrush(b);

  m_pPainter->drawLineSegments(points);
}


/**
 * Draws a polyline
 *
 * @param pList The array of points to draw the polyline with
 *
 * Draws a polyline (hollow) from p1->p2->p3->pn
 */
void KivioScreenPainter::drawPolyline( TQPtrList<KivioPoint> *pList )
{
  PAINTER_CHECK();

  KivioPoint *pPoint;
  TQPointArray points( pList->count() );
  int i = 0;
  pPoint = pList->first();

  while( pPoint )
  {
    points.setPoint(i++, int(pPoint->x()), int(pPoint->y()) );
    pPoint = pList->next();
  }

  drawPolyline(points);
}



/**
 * Draws a polygon
 *
 * @param pList The array of points to draw the polyline with
 *
 * Draws a filled (if set) polygon from p1->p2->p3->pn->p1
 */
void KivioScreenPainter::drawPolygon( TQPtrList<KivioPoint> *pList )
{
  PAINTER_CHECK();

  KivioPoint *pPoint;
  TQPointArray points( pList->count() );
  int i = 0;
  pPoint = pList->first();

  while( pPoint )
  {
    points.setPoint(i++, int(pPoint->x()), int(pPoint->y()) );
    pPoint = pList->next();
  }

  drawPolygon(points);
}

void KivioScreenPainter::drawPolyline( TQPointArray &pArray )
{
  PAINTER_CHECK();

  m_pPainter->setPen(m_pLineStyle->pen(1.0f));
  m_pPainter->setBrush( TQBrush::NoBrush );

  m_pPainter->tqdrawPolyline( pArray, 0, pArray.size() );
}

void KivioScreenPainter::drawPolygon( TQPointArray &pArray )
{
  PAINTER_CHECK();

  TQBrush b;
  b = m_pFillStyle->brush();

  if(m_pFillStyle->colorStyle() == KivioFillStyle::kcsGradient) {
    int x1, y1, w1, h1;
    x1 = pArray[0].x();
    y1 = pArray[0].y();
    w1 = h1 = 0;

    for(unsigned int i = 0; i < pArray.count(); i++) {
      x1 = TQMIN(x1, pArray[i].x());
      y1 = TQMIN(y1, pArray[i].y());
      w1 = TQMAX(w1, pArray[i].x());
      h1 = TQMAX(h1, pArray[i].y());
    }

    w1 = w1 - x1;
    h1 = h1 - y1;

    TQPixmap pix(w1, h1);
    TQImage image = KImageEffect::gradient(pix.size(), m_pFillStyle->color(), m_pFillStyle->color2(),
      (KImageEffect::GradientType) m_pFillStyle->gradientType());
    pix.convertFromImage(image);
    b.setPixmap(pix);
    m_pPainter->setBrushOrigin(x1 + (int)m_transX, y1 + (int)m_transY);
  }

  m_pPainter->setPen(m_pLineStyle->pen(1.0f));
  m_pPainter->setBrush(b);

  m_pPainter->tqdrawPolygon( pArray, true );
  m_pPainter->setBrushOrigin(0, 0);
}

void KivioScreenPainter::drawLineArray( TQPointArray &pArray )
{
    PAINTER_CHECK();

    m_pPainter->setPen(m_pLineStyle->pen(1.0f));
    m_pPainter->setBrush(TQBrush::NoBrush);

    m_pPainter->drawLineSegments(pArray);
}


/**
 * Draws a filled path object
 *
 * @param pPoints The array of points to draw the polyline with
 *
 * Draws a filled (if set) curve with the points stored
 * in pPoints.  They can be made up of bezier, arc, and normal points.
 */
void KivioScreenPainter::drawClosedPath( TQPtrList<KivioPoint> *pPoints )
{
    PAINTER_CHECK();

    TQBrush brush;

    KivioPoint *pPoint, *pPoint2, *pPoint3, *pPoint4;
    TQPtrList <KivioPoint> *pPointList = pPoints;
    TQPointArray controlPoints(4), bPoints(0), tmpPoints;

    int pointIndex=0;
    pPoint = pPointList->first();
    while( pPoint )
    {
        if( pPoint->pointType() == KivioPoint::kptNormal )
        {
            bPoints.putPoints( pointIndex, 1, int(pPoint->x()), int(pPoint->y()) );
            pointIndex++;
        }
        else if( pPoint->pointType() == KivioPoint::kptBezier )
        {
            pPoint2 = pPointList->next();
            pPoint3 = pPointList->next();
            pPoint4 = pPointList->next();

            if( !pPoint2 || !pPoint3 || !pPoint4 )
            {
                kdDebug(43000) << "drawClosedPath() - incorrect # of bezier points" << endl;
                return;
            }

            if( pPoint2->pointType() != KivioPoint::kptBezier ||
                pPoint3->pointType() != KivioPoint::kptBezier ||
                pPoint4->pointType() != KivioPoint::kptBezier )
            {
                kdDebug(43000) << "drawClosedPath() - bezier curves must have 4 points" << endl;
                return;
            }

            controlPoints.setPoint( 0, tqRound(pPoint->x()), tqRound(pPoint->y()) );
            controlPoints.setPoint( 1, tqRound(pPoint2->x()), tqRound(pPoint2->y()) );
            controlPoints.setPoint( 2, tqRound(pPoint3->x()), tqRound(pPoint3->y()) );
            controlPoints.setPoint( 3, tqRound(pPoint4->x()), tqRound(pPoint4->y()) );

            tmpPoints = controlPoints.cubicBezier();

            for( int j=0; j<int(tmpPoints.size()); j++ )
            {
                bPoints.putPoints( pointIndex, 1, tmpPoints.point(j).x(), tmpPoints.point(j).y() );
                pointIndex++;
            }
        } // end pointtype==bezier
        else if( pPoint->pointType() == KivioPoint::kptArc )
        {
            pPoint2 = pPointList->next();
            pPoint3 = pPointList->next();

            if( !pPoint2 || !pPoint3 )
            {
                kdDebug(43000) << "drawClosedPath() - incorrect # of arc points" << endl;
                return;
            }
            if( pPoint2->pointType() != KivioPoint::kptArc ||
                pPoint3->pointType() != KivioPoint::kptArc )
            {
                kdDebug(43000) << "drawClosedPath() - Arc points must come in triplets" << endl;
                return;
            }

            tmpPoints.makeArc( tqRound(pPoint->x()), tqRound(pPoint->y()), tqRound(pPoint2->x()), tqRound(pPoint2->y()),
                               tqRound(pPoint3->x()), tqRound(pPoint3->y()) );

            for( int j=0; j<int(tmpPoints.size()); j++ )
            {
                bPoints.putPoints( pointIndex, 1, tmpPoints.point(j).x(),tmpPoints.point(j).y());
                pointIndex++;
            }
        } // end pointtype==arc
        else
        {
          kdDebug(43000) << "drawClosedPath() - Unknown point type discovered. WOOO!!!" << endl;
        }

        pPoint = pPointList->next();
    }

    // If we make it here, the list is built
    switch( m_pFillStyle->colorStyle() )
    {
        case KivioFillStyle::kcsNone:
            // A hollow path? That's a polypath!
            drawPolyline( bPoints );
            break;

        case KivioFillStyle::kcsSolid:
        case KivioFillStyle::kcsGradient:
        {
            drawPolygon(bPoints);
            break;
        }

        default:
            kdDebug(43000) << "drawClosedPath() - Unknown colors style" << endl;
            break;
    }
}

void KivioScreenPainter::drawOpenPath( TQPtrList<KivioPoint> *pPoints )
{
    PAINTER_CHECK();

    TQBrush brush;

    KivioPoint *pPoint, *pPoint2, *pPoint3, *pPoint4;
    TQPtrList <KivioPoint> *pPointList = pPoints;
    TQPointArray controlPoints(4), bPoints(0), tmpPoints;

    int pointIndex=0;
    pPoint = pPointList->first();
    while( pPoint )
    {
        if( pPoint->pointType() == KivioPoint::kptNormal )
        {
            bPoints.putPoints( pointIndex, 1, int(pPoint->x()), int(pPoint->y()) );
            pointIndex++;
        }
        else if( pPoint->pointType() == KivioPoint::kptBezier )
        {
            pPoint2 = pPointList->next();
            pPoint3 = pPointList->next();
            pPoint4 = pPointList->next();

            if( !pPoint2 || !pPoint3 || !pPoint4 )
            {
                kdDebug(43000) << "drawOpenPath() - incorrect # of bezier points" << endl;
                return;
            }

            if( pPoint2->pointType() != KivioPoint::kptBezier ||
                pPoint3->pointType() != KivioPoint::kptBezier ||
                pPoint4->pointType() != KivioPoint::kptBezier )
            {
                kdDebug(43000) << "drawOpenPath() - bezier curves must have 4 points" << endl;
                return;
            }

            controlPoints.setPoint( 0, tqRound(pPoint->x()), tqRound(pPoint->y()) );
            controlPoints.setPoint( 1, tqRound(pPoint2->x()), tqRound(pPoint2->y()) );
            controlPoints.setPoint( 2, tqRound(pPoint3->x()), tqRound(pPoint3->y()) );
            controlPoints.setPoint( 3, tqRound(pPoint4->x()), tqRound(pPoint4->y()) );

            tmpPoints = controlPoints.cubicBezier();

            for( int j=0; j<int(tmpPoints.size()); j++ )
            {
                bPoints.putPoints( pointIndex, 1, tmpPoints.point(j).x(), tmpPoints.point(j).y() );
                pointIndex++;
            }
        } // end pointtype==bezier
        else if( pPoint->pointType() == KivioPoint::kptArc )
        {
            pPoint2 = pPointList->next();
            pPoint3 = pPointList->next();

            if( !pPoint2 || !pPoint3 )
            {
                kdDebug(43000) << "drawOpenPath() - incorrect # of arc points" << endl;
                return;
            }
            if( pPoint2->pointType() != KivioPoint::kptArc ||
                pPoint3->pointType() != KivioPoint::kptArc )
            {
                kdDebug(43000) << "drawOpenPath() - Arc points must come in triplets" << endl;
                return;
            }

            tmpPoints.makeArc( tqRound(pPoint->x()), tqRound(pPoint->y()), tqRound(pPoint2->x()), tqRound(pPoint2->y()),
                               tqRound(pPoint3->x()), tqRound(pPoint3->y()) );

            for( int j=0; j<int(tmpPoints.size()); j++ )
            {
                bPoints.putPoints( pointIndex, 1, tmpPoints.point(j).x(),tmpPoints.point(j).y());
                pointIndex++;
            }
        } // end pointtype==arc
        else
        {
            kdDebug(43000) << "drawOpenPath() - Unknown point type discovered. WOOO!!!" << endl;
        }

        pPoint = pPointList->next();
    }

    m_pPainter->setPen(m_pLineStyle->pen(1.0f));
    m_pPainter->setBrush( TQBrush::NoBrush );

    m_pPainter->drawPolyline( bPoints );
}

void KivioScreenPainter::setFont( const TQFont &f )
{
    PAINTER_CHECK();

    m_pPainter->setFont( f );
}

void KivioScreenPainter::drawText( int x, int y, int w, int h, int tf, const TQString &str )
{
    PAINTER_CHECK();

    m_pPainter->setPen( m_textColor );
    m_pPainter->drawText( x, y, w, h, tf, str );
/*    TQSimpleRichText textArea(str, m_pPainter->font());
    textArea.setWidth(w);
    TQColorGroup cg;
    cg.setColor(TQColorGroup::Base, m_pFillStyle->color());
    cg.setColor(TQColorGroup::Text, m_textColor);
    TQBrush b = m_pFillStyle->brush();
    textArea.draw(m_pPainter, x, y, TQRect(0, 0, 0, 0), cg, &b);*/
}

TQRect KivioScreenPainter::boundingRect( int x, int y, int w, int h, int tf, const TQString &str )
{
   PAINTER_CHECK();

   return m_pPainter->boundingRect( x,y,w,h, tf, str );
}

void KivioScreenPainter::drawPixmap( float x, float y, const TQPixmap &pix )
{
  PAINTER_CHECK();
  m_pPainter->drawPixmap( (int)x, (int)y, pix );
}

void KivioScreenPainter::drawHandle( float x, float y, int flags )
{
  PAINTER_CHECK();
  TQColor fillColor, penColor;
  TQBrush b;
  TQPen p;

  const float HW = 6.0f;
  const float HWP1 = HW+1.0f;
  const float HWo2 = HW/2.0f;

  float x1, y1;

  // Is it a locked handle?
  if( flags & cpfLock )
  {
    x1 = x - 4;
    y1 = y - 4;

    m_pPainter->drawPixmap( tqRound(x1), tqRound(y1), Kivio::lockPixmap() );
    return;
  }

  if( flags & cpfConnected )
  {
    fillColor = TQColor(200,0,0);
  }
  else
  {
    fillColor = TQColor(0,200,0);
  }

  penColor.setRgb(0, 0, 0);

  b.setColor(fillColor);
  b.setStyle(Qt::SolidPattern);
  p.setColor(penColor);
  m_pPainter->setPen(p);
  m_pPainter->setBrush(b);


  x1 = x - HWo2;
  y1 = y - HWo2;

  // first fill it
//   m_pPainter->fillRect( x1, y1, HWP1, HWP1, b );

  if(flags & cpfEnd) {
    m_pPainter->drawEllipse( tqRound(x1), tqRound(y1), tqRound(HWP1), tqRound(HWP1) );
  } else {
    m_pPainter->drawRect( tqRound(x1), tqRound(y1), tqRound(HWP1), tqRound(HWP1) );
  }

  // Now put something in it if needed
  if( flags & cpfConnectable )
  {
    b.setColor(TQColor(0,0,0));

    m_pPainter->fillRect(tqRound(x-1),tqRound(y-1),3,3, b);
  }
}

void KivioScreenPainter::drawSelectionBox( const TQRect& r )
{
   PAINTER_CHECK();
   TQPen p;
   p.setColor(TQColor(0,200,0));
   p.setStyle(Qt::DashLine);
   m_pPainter->setBrush(TQt::NoBrush);
   m_pPainter->setPen(p);
   m_pPainter->drawRect(r);
}

void KivioScreenPainter::saveState()
{
   PAINTER_CHECK();

   m_pPainter->save();
}

void KivioScreenPainter::restoreState()
{
   PAINTER_CHECK();

   m_pPainter->restore();
}

void KivioScreenPainter::setTranslation( float _x, float _y )
{
   PAINTER_CHECK();

   m_transX = _x;
   m_transY = _y;

   m_pPainter->translate(_x, _y);
}

void KivioScreenPainter::translateBy( float _x, float _y )
{
   PAINTER_CHECK();

   m_transX += _x;
   m_transY += _y;

   m_pPainter->translate( m_transX, m_transY );
}

void KivioScreenPainter::setRotation( int _d )
{
   PAINTER_CHECK();

   m_rotation = _d;

   m_pPainter->rotate(_d);
}

void KivioScreenPainter::rotateBy( int _d )
{
   PAINTER_CHECK();

   m_rotation += _d;

   m_pPainter->rotate(m_rotation);
}

int KivioScreenPainter::rotation()
{
  return m_rotation;
}

void KivioScreenPainter::setWorldMatrix(TQWMatrix m, bool c)
{
  PAINTER_CHECK();
  m_pPainter->setWorldMatrix(m, c);
}