summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--tdegtk/tqtcairopainter.cpp92
-rw-r--r--tests/test-painter.cpp64
2 files changed, 121 insertions, 35 deletions
diff --git a/tdegtk/tqtcairopainter.cpp b/tdegtk/tqtcairopainter.cpp
index 6bf5b9f..ae440b7 100644
--- a/tdegtk/tqtcairopainter.cpp
+++ b/tdegtk/tqtcairopainter.cpp
@@ -384,6 +384,8 @@ bool TQt3CairoPaintDevice::cmd( int c, TQPainter *pt, TQPDevCmdParam *p )
double x;
double y;
+ double x2;
+ double y2;
double width;
double height;
@@ -393,13 +395,16 @@ bool TQt3CairoPaintDevice::cmd( int c, TQPainter *pt, TQPDevCmdParam *p )
// Convert data types
if (p) {
-// if ((c == PdcDrawPoint) || (c == PdcMoveTo) || (c == PdcLineTo) || (c == PdcSetBrushOrigin)) {
-// qt4point1 = QPoint(p[0].point->x(), p[0].point->y());
-// }
-// if (c == PdcDrawLine) {
-// qt4point1 = QPoint(p[0].point->x(), p[0].point->y());
-// qt4point2 = QPoint(p[1].point->x(), p[1].point->y());
-// }
+ if ((c == PdcDrawPoint) || (c == PdcMoveTo) || (c == PdcLineTo) || (c == PdcSetBrushOrigin)) {
+ x = p[0].point->x();
+ y = p[0].point->y();
+ }
+ if (c == PdcDrawLine) {
+ x = p[0].point->x();
+ y = p[0].point->y();
+ x2 = p[1].point->x();
+ y2 = p[1].point->y();
+ }
// if ((c == PdcDrawPolyline) || (c == PdcDrawPolygon) || (c == PdcDrawLineSegments) || (c == PdcDrawCubicBezier)) {
// TQPointArray qt3parray = *p[0].ptarr;
// qt4polygon.resize(qt3parray.count());
@@ -420,24 +425,52 @@ bool TQt3CairoPaintDevice::cmd( int c, TQPainter *pt, TQPDevCmdParam *p )
switch ( c ) { // exec cmd
case PdcNOP:
break;
-#if 0
case PdcDrawPoint:
- m_qt4painter->drawPoint( qt4point1 );
+ if (m_painter) {
+ cairo_save(m_painter);
+ if (m_pen.style() != TQPen::NoPen) {
+ cairo_move_to(m_painter, x+CAIRO_PIXEL_OFFSET, y+CAIRO_PIXEL_OFFSET);
+ cairo_line_to(m_painter, x+CAIRO_PIXEL_OFFSET, y+CAIRO_PIXEL_OFFSET);
+ updatePen(FALSE);
+ cairo_set_line_cap(m_painter, CAIRO_LINE_CAP_ROUND);
+ cairo_stroke(m_painter);
+ }
+ cairo_restore(m_painter);
+ }
break;
case PdcMoveTo:
- curPt = qt4point1;
+ if (m_painter) {
+ cairo_save(m_painter);
+ if (m_pen.style() != TQPen::NoPen) {
+ cairo_move_to(m_painter, x+CAIRO_PIXEL_OFFSET, y+CAIRO_PIXEL_OFFSET);
+ }
+ cairo_restore(m_painter);
+ }
break;
case PdcLineTo:
- prevPt = curPt;
- curPt = qt4point1;
- m_qt4painter->drawLine( prevPt, curPt );
+ if (m_painter) {
+ cairo_save(m_painter);
+ if (m_pen.style() != TQPen::NoPen) {
+ cairo_line_to(m_painter, x2+CAIRO_PIXEL_OFFSET, y2+CAIRO_PIXEL_OFFSET);
+ dualStrokePen();
+ }
+ cairo_restore(m_painter);
+ }
break;
case PdcDrawLine:
- m_qt4painter->drawLine( qt4point1, qt4point2 );
+ if (m_painter) {
+ cairo_save(m_painter);
+ if (m_pen.style() != TQPen::NoPen) {
+ cairo_move_to(m_painter, x+CAIRO_PIXEL_OFFSET, y+CAIRO_PIXEL_OFFSET);
+ cairo_line_to(m_painter, x2+CAIRO_PIXEL_OFFSET, y2+CAIRO_PIXEL_OFFSET);
+ dualStrokePen();
+ }
+ cairo_restore(m_painter);
+ }
break;
-#endif
case PdcDrawRect:
if (m_painter) {
+ cairo_save(m_painter);
if (m_pen.style() != TQPen::NoPen) {
cairo_rectangle(m_painter, x+CAIRO_PIXEL_OFFSET, y+CAIRO_PIXEL_OFFSET, width, height);
dualStrokePen();
@@ -447,6 +480,7 @@ bool TQt3CairoPaintDevice::cmd( int c, TQPainter *pt, TQPDevCmdParam *p )
cairo_rectangle(m_painter, x+line_width+CAIRO_PIXEL_OFFSET, y+line_width+CAIRO_PIXEL_OFFSET, width-(line_width*2), height-(line_width*2));
dualStrokeBrush();
}
+ cairo_restore(m_painter);
}
else {
#if defined(QT_CHECK_RANGE)
@@ -476,9 +510,35 @@ bool TQt3CairoPaintDevice::cmd( int c, TQPainter *pt, TQPDevCmdParam *p )
lineCount = (count == -1) ? (qt4polygon.size() - index) / 2 : count;
m_qt4painter->drawLines(qt4polygon.constData() + index * 2, lineCount);
break;
+#endif
case PdcDrawPolyline:
- m_qt4painter->drawPolyline( qt4polygon );
+ if (m_painter) {
+ cairo_save(m_painter);
+ if (p) {
+ const TQPointArray* pointarray = p[0].ptarr;
+ if (pointarray) {
+ int x;
+ int y;
+ bool first=true;
+ for (i=0;i<pointarray->count();i++) {
+ pointarray->point(i, &x, &y );
+ if (first) {
+ cairo_move_to(m_painter, x+CAIRO_PIXEL_OFFSET, y+CAIRO_PIXEL_OFFSET);
+ first = false;
+ }
+ else {
+ cairo_line_to(m_painter, x+CAIRO_PIXEL_OFFSET, y+CAIRO_PIXEL_OFFSET);
+ }
+ }
+ if (m_pen.style() != TQPen::NoPen) {
+ dualStrokePen();
+ }
+ }
+ }
+ cairo_restore(m_painter);
+ }
break;
+#if 0
case PdcDrawPolygon:
m_qt4painter->drawPolygon( qt4polygon, (p[1].ival == 0)?Qt::OddEvenFill:Qt::WindingFill );
break;
diff --git a/tests/test-painter.cpp b/tests/test-painter.cpp
index 0cdaac1..8a2b02e 100644
--- a/tests/test-painter.cpp
+++ b/tests/test-painter.cpp
@@ -11,7 +11,7 @@ main (int argc, char *argv[])
cairo_surface_t *surface;
cairo_t *cr;
- surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 120, 120);
+ surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 500, 500);
// cr = cairo_create (surface);
// /* Examples are in 1.0 x 1.0 coordinate space */
@@ -28,24 +28,50 @@ main (int argc, char *argv[])
TQt3CairoPaintDevice pd(surface);
TQPainter p(&pd);
- p.setPen(TQPen(TQt::red, 1));
- p.drawRect(5, 5, 50, 50);
-
- TQBrush brush( TQt::yellow, TQBrush::DiagCrossPattern ); // yellow pattern
- p.setBrush( brush ); // set the yellow brush
- p.setPen( TQt::NoPen ); // do not draw outline
- p.drawRect( 0,0, 25,25 ); // draw filled rectangle
- TQBrush brush2( TQt::green, TQBrush::SolidPattern ); // green pattern
- p.setBrush( brush2 ); // set the yellow brush
- p.setPen( TQt::NoPen ); // do not draw outline
- p.drawRect( 40,30, 200,100 ); // draw filled rectangle
- p.setBrush( TQt::NoBrush ); // do not fill
- p.setPen( TQt::blue ); // set blue pen, 0 pixel width
- p.drawRect( 10,10, 30,20 ); // draw rectangle outline
- TQBrush brush3( TQColor(255,128,0), TQBrush::SolidPattern ); // green pattern
- p.setBrush( brush3 ); // set the yellow brush
- p.setPen( TQColor(255,0,255) ); // draw outline
- p.drawRect( 50,50, 180,80 ); // draw filled rectangle
+
+ // Rectangle tests
+ {
+ p.setPen(TQPen(TQt::red, 1));
+ p.drawRect(5, 5, 50, 50);
+ TQBrush brush( TQt::yellow, TQBrush::DiagCrossPattern ); // yellow pattern
+ p.setBrush( brush ); // set the yellow brush
+ p.setPen( TQt::NoPen ); // do not draw outline
+ p.drawRect( 0,0, 25,25 ); // draw filled rectangle
+ TQBrush brush2( TQt::green, TQBrush::SolidPattern ); // green pattern
+ p.setBrush( brush2 ); // set the yellow brush
+ p.setPen( TQt::NoPen ); // do not draw outline
+ p.drawRect( 40,30, 200,100 ); // draw filled rectangle
+ p.setBrush( TQt::NoBrush ); // do not fill
+ p.setPen( TQt::blue ); // set blue pen, 0 pixel width
+ p.drawRect( 10,10, 30,20 ); // draw rectangle outline
+ TQBrush brush3( TQColor(255,128,0), TQBrush::SolidPattern ); // green pattern
+ p.setBrush( brush3 ); // set the yellow brush
+ p.setPen( TQColor(255,0,255) ); // draw outline
+ p.drawRect( 50,40, 180,80 ); // draw filled rectangle
+ }
+
+ // Line tests
+ {
+ p.setPen( TQt::blue ); // set blue pen, 0 pixel width
+ p.drawLine(140,140, 160,160);
+ }
+
+ // Point tests
+ {
+ p.setPen( TQt::green ); // set green pen, 0 pixel width
+ p.drawPoint(135,135);
+ }
+
+ // Polyline tests
+ {
+ TQPointArray a;
+ int x1 = 200;
+ int y1 = 10;
+
+ a.setPoints( 11, x1+0, y1+85, x1+75, y1+75, x1+100, y1+10, x1+125, y1+75, x1+200, y1+85, x1+150, y1+125, x1+160, y1+190, x1+100, y1+150, x1+40, y1+190, x1+50, y1+125, x1+0, y1+85 );
+ p.setPen(TQt::red);
+ p.drawPolyline(a);
+ }
p.end();