From: <and...@us...> - 2011-08-10 08:51:31
|
Revision: 11867 http://plplot.svn.sourceforge.net/plplot/?rev=11867&view=rev Author: andrewross Date: 2011-08-10 08:51:24 +0000 (Wed, 10 Aug 2011) Log Message: ----------- Add driver-level support for drawing arcs to qt driver. Modified Paths: -------------- trunk/bindings/qt_gui/plqt.cpp trunk/drivers/qt.cpp trunk/include/qt.h Modified: trunk/bindings/qt_gui/plqt.cpp =================================================================== --- trunk/bindings/qt_gui/plqt.cpp 2011-08-09 22:42:00 UTC (rev 11866) +++ trunk/bindings/qt_gui/plqt.cpp 2011-08-10 08:51:24 UTC (rev 11867) @@ -81,6 +81,34 @@ pls = p; } +void QtPLDriver::drawArc( short x, short y, short a, short b, PLFLT angle1, PLFLT angle2, PLFLT rotate, bool fill ) +{ + if ( !m_painterP->isActive() ) + return; + QRectF rect( (PLFLT) (x-a) * downscale, + m_dHeight - (PLFLT) (y+b) * downscale, + (PLFLT) a * downscale * 2, + (PLFLT) b * downscale * 2 + ); + if (rotate != 0.0) { + m_painterP->save(); + m_painterP->translate((PLFLT)x*downscale, m_dHeight - (PLFLT) y * downscale ); + m_painterP->rotate(-rotate); + m_painterP->translate(-(PLFLT)x*downscale, -m_dHeight + (PLFLT) y * downscale ); + } + + if (fill) + m_painterP->drawPie( rect, (int) (angle1*16), (int) ((angle2-angle1)*16) ); + else + m_painterP->drawArc( rect, (int) (angle1*16), (int) ((angle2-angle1)*16) ); + + if (rotate != 0.0) { + m_painterP->restore(); + } + + +} + void QtPLDriver::drawLine( short x1, short y1, short x2, short y2 ) { if ( !m_painterP->isActive() ) @@ -688,6 +716,11 @@ case SET_GRADIENT: delete i->Data.LinearGradient; break; + + case ARC: + delete i->Data.ArcStruct->rect; + delete i->Data.ArcStruct->dx; + delete i->Data.ArcStruct; default: break; @@ -699,6 +732,28 @@ redrawAll = true; } + +void QtPLWidget::drawArc( short x, short y, short a, short b, PLFLT angle1, PLFLT angle2, PLFLT rotate, bool fill ) +{ + BufferElement el; + el.Element = ARC; + el.Data.ArcStruct = new struct ArcStruct_; + el.Data.ArcStruct->rect = new QRectF( (PLFLT) (x-a) * downscale, + m_dHeight - (PLFLT) (y+b) * downscale, + (PLFLT) a * downscale * 2, + (PLFLT) b * downscale * 2 + ); + el.Data.ArcStruct->startAngle = (int) (angle1*16); + el.Data.ArcStruct->spanAngle = (int) ((angle2-angle1)*16); + el.Data.ArcStruct->rotate = rotate; + el.Data.ArcStruct->dx = new QPointF( (PLFLT)x*downscale, m_dHeight - (PLFLT) y * downscale ); + el.Data.ArcStruct->fill = fill; + + m_listBuffer.append( el ); + redrawFromLastFlush = true; +} + + void QtPLWidget::drawLine( short x1, short y1, short x2, short y2 ) { BufferElement el; @@ -1369,6 +1424,29 @@ p->fillRect( 0, 0, (int) m_dWidth, (int) m_dHeight, SolidBrush ); break; + case ARC: + if ( !hasPen ) + { + p->setPen( SolidPen ); + hasPen = true; + } + if (i->Data.ArcStruct->rotate != 0.0) { + p->save(); + p->translate( *(i->Data.ArcStruct->dx) ); + p->rotate( - i->Data.ArcStruct->rotate ); + p->translate( - *(i->Data.ArcStruct->dx) ); + } + + if (i->Data.ArcStruct->fill) + p->drawPie( *(i->Data.ArcStruct->rect), i->Data.ArcStruct->startAngle, i->Data.ArcStruct->spanAngle ); + else + p->drawArc( *(i->Data.ArcStruct->rect), i->Data.ArcStruct->startAngle, i->Data.ArcStruct->spanAngle ); + + if (i->Data.ArcStruct->rotate != 0.0) { + p->restore(); + } + + break; default: break; } Modified: trunk/drivers/qt.cpp =================================================================== --- trunk/drivers/qt.cpp 2011-08-09 22:42:00 UTC (rev 11866) +++ trunk/drivers/qt.cpp 2011-08-10 08:51:24 UTC (rev 11867) @@ -422,7 +422,7 @@ break; case PLESC_HAS_TEXT: - //$$ call the generic ProcessString function + // call the generic ProcessString function // ProcessString( pls, (EscText *)ptr ); widget->QtPLDriver::setColor( pls->curcolor.r, pls->curcolor.g, pls->curcolor.b, pls->curcolor.a ); widget->drawText( (EscText *) ptr ); @@ -860,7 +860,7 @@ break; case PLESC_HAS_TEXT: - //$$ call the generic ProcessString function + // call the generic ProcessString function // ProcessString( pls, (EscText *)ptr ); widget->setColor( pls->curcolor.r, pls->curcolor.g, pls->curcolor.b, pls->curcolor.a ); widget->drawText( (EscText *) ptr ); @@ -968,6 +968,7 @@ pls->dev_fill0 = 1; pls->dev_fill1 = 0; pls->dev_gradient = 1; // driver renders gradient + pls->dev_arc = 1; // driver renders arcs // Let the PLplot core handle dashed lines since // the driver results for this capability have a number of issues. // pls->dev_dash=1; @@ -1091,6 +1092,8 @@ PLFLT *alpha; PLINT i; QtEPSDevice * widget = (QtEPSDevice *) pls->dev; + arc_struct *arc_info = (arc_struct *) ptr; + if ( widget != NULL && qt_family_check( pls ) ) { return; @@ -1149,12 +1152,16 @@ break; case PLESC_HAS_TEXT: - //$$ call the generic ProcessString function + // call the generic ProcessString function // ProcessString( pls, (EscText *)ptr ); widget->setColor( pls->curcolor.r, pls->curcolor.g, pls->curcolor.b, pls->curcolor.a ); widget->drawText( (EscText *) ptr ); break; + case PLESC_ARC: + widget->drawArc( arc_info->x, arc_info->y, arc_info->a, arc_info->b, arc_info->angle1, arc_info->angle2, arc_info->rotate, arc_info->fill); + break; + default: break; } } @@ -1280,6 +1287,7 @@ pls->dev_fill0 = 1; // Handle solid fills pls->dev_fill1 = 0; pls->dev_gradient = 1; // driver renders gradient + pls->dev_arc = 1; // driver renders arcs // Let the PLplot core handle dashed lines since // the driver results for this capability have a number of issues. // pls->dev_dash=1; @@ -1348,6 +1356,7 @@ unsigned char *r, *g, *b; PLFLT *alpha; QtPLWidget * widget = (QtPLWidget *) pls->dev; + arc_struct *arc_info = (arc_struct *) ptr; if ( widget == NULL ) return; @@ -1407,6 +1416,10 @@ widget->drawText( (EscText *) ptr ); break; + case PLESC_ARC: + widget->drawArc( arc_info->x, arc_info->y, arc_info->a, arc_info->b, arc_info->angle1, arc_info->angle2, arc_info->rotate, arc_info->fill); + break; + case PLESC_FLUSH: widget->flush(); break; @@ -1506,6 +1519,7 @@ pls->dev_fill0 = 1; // Handle solid fills pls->dev_fill1 = 0; pls->dev_gradient = 1; // driver renders gradient + pls->dev_arc = 1; // driver renders arcs // Let the PLplot core handle dashed lines since // the driver results for this capability have a number of issues. // pls->dev_dash=1; @@ -1551,6 +1565,7 @@ unsigned char *r, *g, *b; PLFLT *alpha; QtExtWidget * widget = NULL; + arc_struct *arc_info = (arc_struct *) ptr; widget = (QtExtWidget *) pls->dev; switch ( op ) @@ -1604,12 +1619,16 @@ break; case PLESC_HAS_TEXT: - //$$ call the generic ProcessString function + // call the generic ProcessString function // ProcessString( pls, (EscText *)ptr ); widget->setColor( pls->curcolor.r, pls->curcolor.g, pls->curcolor.b, pls->curcolor.a ); widget->drawText( (EscText *) ptr ); break; + case PLESC_ARC: + widget->drawArc( arc_info->x, arc_info->y, arc_info->a, arc_info->b, arc_info->angle1, arc_info->angle2, arc_info->rotate, arc_info->fill); + break; + default: break; } } @@ -1701,6 +1720,7 @@ pls->dev_fill0 = 1; pls->dev_fill1 = 0; pls->dev_gradient = 1; // driver renders gradient + pls->dev_arc = 1; // driver renders arcs // Let the PLplot core handle dashed lines since // the driver results for this capability have a number of issues. // pls->dev_dash=1; Modified: trunk/include/qt.h =================================================================== --- trunk/include/qt.h 2011-08-09 22:42:00 UTC (rev 11866) +++ trunk/include/qt.h 2011-08-10 08:51:24 UTC (rev 11867) @@ -124,6 +124,7 @@ void setPLStream( PLStream *pls ); // store the related stream + virtual void drawArc( short x, short y, short width, short height, PLFLT angle1, PLFLT angle2, PLFLT rotate, bool fill ); // Draws a line from (x1, y1) to (x2, y2) in internal plplot coordinates virtual void drawLine( short x1, short y1, short x2, short y2 ); virtual void drawPolyline( short * x, short * y, PLINT npts ); @@ -243,7 +244,8 @@ SET_GRADIENT, SET_SMOOTH, TEXT, - SET_BG_COLOUR + SET_BG_COLOUR, + ARC } ElementType; // Identifiers for elements of the buffer struct ColourStruct_ @@ -269,6 +271,15 @@ PLFLT chrht; }; +struct ArcStruct_ +{ + QRectF *rect; + QPointF *dx; + int startAngle; + int spanAngle; + PLFLT rotate; + bool fill; +}; class BufferElement { @@ -283,6 +294,7 @@ QLinearGradient * LinearGradient; struct ColourStruct_* ColourStruct; struct TextStruct_ * TextStruct; + struct ArcStruct_ * ArcStruct; PLINT intParam; PLFLT fltParam; } Data; @@ -307,6 +319,7 @@ int pageNumber; + void drawArc( short x, short y, short width, short height, PLFLT angle1, PLFLT angle2, PLFLT rotate, bool fill ); void drawLine( short x1, short y1, short x2, short y2 ); void drawPolyline( short * x, short * y, PLINT npts ); void drawPolygon( short * x, short * y, PLINT npts ); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |