From: <ai...@us...> - 2009-12-03 22:08:01
|
Revision: 10675 http://plplot.svn.sourceforge.net/plplot/?rev=10675&view=rev Author: airwin Date: 2009-12-03 22:07:49 +0000 (Thu, 03 Dec 2009) Log Message: ----------- Implement native driver gradients for remaining qt devices (epsqt/pdfqt, qtwidget, and extqt). Some code cleanup. 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 2009-12-03 21:52:56 UTC (rev 10674) +++ trunk/bindings/qt_gui/plqt.cpp 2009-12-03 22:07:49 UTC (rev 10675) @@ -373,14 +373,15 @@ } void QtPLDriver::setGradient( int x1, int x2, int y1, int y2, - int *r, int *g, int *b, qreal *alpha, PLINT ncol1 ) + unsigned char *r, unsigned char *g, + unsigned char *b, PLFLT *alpha, PLINT ncol1 ) { if ( !m_painterP->isActive() || ncol1 < 2 ) return; - int i; - qreal stop_arg; - QGradient linear_gradient; - QGradientStops stops; + int i; + qreal stop_arg; + QLinearGradient linear_gradient; + QGradientStops stops; linear_gradient = QLinearGradient( QPointF((qreal) ( x1 * downscale ), (qreal) ( m_dHeight - y1 * downscale )), @@ -650,6 +651,10 @@ delete i->Data.ColourStruct; break; + case SET_GRADIENT: + delete i->Data.LinearGradient; + break; + default: break; } @@ -783,6 +788,35 @@ // redrawFromLastFlush=true; } +void QtPLWidget::setGradient( int x1, int x2, int y1, int y2, + unsigned char *r, unsigned char *g, + unsigned char *b, PLFLT *alpha, PLINT ncol1 ) +{ + int i; + BufferElement el; + qreal stop_arg; + QGradientStops stops; + + el.Element = SET_GRADIENT; + + el.Data.LinearGradient = new QLinearGradient; + *el.Data.LinearGradient = QLinearGradient( + QPointF((qreal) ( x1 * downscale ), (qreal) ( m_dHeight - y1 * downscale )), + QPointF((qreal) ( x2 * downscale ), (qreal) ( m_dHeight - y2 * downscale ))); + for ( i = 0; i < ncol1; i++ ) + { + stop_arg = (qreal) i / (qreal) ( ncol1 - 1 ); + stops << QGradientStop( stop_arg, QColor( r[i], g[i], + b[i], (int) ( alpha[i] * 255 ))); + } + ( *el.Data.LinearGradient ).setStops( stops ); + m_listBuffer.append( el ); + + // No need to ask for a redraw at this point. The gradient only + // affects subsequent items. + //redrawFromLastFlush=true; +} + void QtPLWidget::setBackgroundColor( int r, int g, int b, double alpha ) { BufferElement el; @@ -971,6 +1005,7 @@ QVector<qreal> vect; QRectF rect; + // QPen SolidPen; // // QPen NoPen(Qt::NoPen); @@ -1010,6 +1045,10 @@ p->setBrush( SolidBrush ); break; + case SET_GRADIENT: + p->setBrush( *( i->Data.LinearGradient )); + break; + case LINE: if ( !hasPen ) { Modified: trunk/drivers/qt.cpp =================================================================== --- trunk/drivers/qt.cpp 2009-12-03 21:52:56 UTC (rev 10674) +++ trunk/drivers/qt.cpp 2009-12-03 22:07:49 UTC (rev 10675) @@ -335,8 +335,8 @@ void plD_esc_rasterqt( PLStream * pls, PLINT op, void* ptr ) { short *xa, *ya; - int *r, *g, *b; - qreal *alpha; + unsigned char *r, *g, *b; + PLFLT *alpha; PLINT i; QtRasterDevice * widget = (QtRasterDevice *) pls->dev; if ( widget != NULL && qt_family_check( pls )) @@ -373,10 +373,10 @@ case PLESC_GRADIENT: xa = new short[pls->dev_npts]; ya = new short[pls->dev_npts]; - r = new int [pls->ncol1]; - g = new int [pls->ncol1]; - b = new int [pls->ncol1]; - alpha = new qreal [pls->ncol1]; + r = new unsigned char[pls->ncol1]; + g = new unsigned char[pls->ncol1]; + b = new unsigned char[pls->ncol1]; + alpha = new PLFLT[pls->ncol1]; for ( i = 0; i < pls->ncol1; i++ ) { @@ -385,7 +385,7 @@ b[i] = pls->cmap1[i].b; alpha[i] = pls->cmap1[i].a; } - widget->QtPLDriver::setGradient( pls->xgradient[0], pls->xgradient[1], pls->ygradient[0], pls->ygradient[1], r, g, b, alpha, pls->ncol1 ); + widget->setGradient( pls->xgradient[0], pls->xgradient[1], pls->ygradient[0], pls->ygradient[1], r, g, b, alpha, pls->ncol1 ); for ( i = 0; i < pls->dev_npts; i++ ) { @@ -768,11 +768,11 @@ void plD_esc_svgqt( PLStream * pls, PLINT op, void* ptr ) { - short *xa, *ya; - int *r, *g, *b; - qreal *alpha; - PLINT i; - QtSVGDevice * widget = (QtSVGDevice *) pls->dev; + short *xa, *ya; + unsigned char *r, *g, *b; + PLFLT *alpha; + PLINT i; + QtSVGDevice * widget = (QtSVGDevice *) pls->dev; if ( widget != NULL && qt_family_check( pls )) { return; @@ -800,10 +800,10 @@ case PLESC_GRADIENT: xa = new short[pls->dev_npts]; ya = new short[pls->dev_npts]; - r = new int [pls->ncol1]; - g = new int [pls->ncol1]; - b = new int [pls->ncol1]; - alpha = new qreal [pls->ncol1]; + r = new unsigned char[pls->ncol1]; + g = new unsigned char[pls->ncol1]; + b = new unsigned char[pls->ncol1]; + alpha = new PLFLT[pls->ncol1]; for ( i = 0; i < pls->ncol1; i++ ) { @@ -812,9 +812,8 @@ b[i] = pls->cmap1[i].b; alpha[i] = pls->cmap1[i].a; } - widget->QtPLDriver::setGradient( pls->xgradient[0], pls->xgradient[1], pls->ygradient[0], pls->ygradient[1], r, g, b, alpha, pls->ncol1 ); + widget->setGradient( pls->xgradient[0], pls->xgradient[1], pls->ygradient[0], pls->ygradient[1], r, g, b, alpha, pls->ncol1 ); - for ( i = 0; i < pls->dev_npts; i++ ) { xa[i] = pls->dev_x[i]; @@ -932,10 +931,11 @@ plParseDrvOpts( qt_options ); /* Stream setup */ - pls->color = 1; - pls->plbuf_write = 0; - pls->dev_fill0 = 1; - pls->dev_fill1 = 0; + pls->color = 1; + pls->plbuf_write = 0; + pls->dev_fill0 = 1; + pls->dev_fill1 = 0; + pls->dev_gradient = 1; /* driver renders gradient */ /* Let the PLplot core handle dashed lines since * the driver results for this capability have a number of issues. * pls->dev_dash=1; */ @@ -1047,9 +1047,11 @@ void plD_esc_epspdfqt( PLStream * pls, PLINT op, void* ptr ) { - short *xa, *ya; - PLINT i; - QtEPSDevice * widget = (QtEPSDevice *) pls->dev; + short *xa, *ya; + unsigned char *r, *g, *b; + PLFLT *alpha; + PLINT i; + QtEPSDevice * widget = (QtEPSDevice *) pls->dev; if ( widget != NULL && qt_family_check( pls )) { return; @@ -1074,6 +1076,38 @@ delete[] ya; break; + case PLESC_GRADIENT: + xa = new short[pls->dev_npts]; + ya = new short[pls->dev_npts]; + r = new unsigned char[pls->ncol1]; + g = new unsigned char[pls->ncol1]; + b = new unsigned char[pls->ncol1]; + alpha = new PLFLT[pls->ncol1]; + + for ( i = 0; i < pls->ncol1; i++ ) + { + r[i] = pls->cmap1[i].r; + g[i] = pls->cmap1[i].g; + b[i] = pls->cmap1[i].b; + alpha[i] = pls->cmap1[i].a; + } + widget->setGradient( pls->xgradient[0], pls->xgradient[1], pls->ygradient[0], pls->ygradient[1], r, g, b, alpha, pls->ncol1 ); + + for ( i = 0; i < pls->dev_npts; i++ ) + { + xa[i] = pls->dev_x[i]; + ya[i] = pls->dev_y[i]; + } + widget->drawPolygon( xa, ya, pls->dev_npts ); + + delete[] xa; + delete[] ya; + delete[] r; + delete[] g; + delete[] b; + delete[] alpha; + break; + case PLESC_HAS_TEXT: /*$$ call the generic ProcessString function * ProcessString( pls, (EscText *)ptr ); */ @@ -1197,10 +1231,11 @@ plP_setpxl( temp.logicalDpiX() / 25.4 / widget->downscale, temp.logicalDpiY() / 25.4 / widget->downscale ); - pls->color = 1; /* Is a color device */ - pls->plbuf_write = 1; /* Store commands to device in core buffer */ - pls->dev_fill0 = 1; /* Handle solid fills */ - pls->dev_fill1 = 0; + pls->color = 1; /* Is a color device */ + pls->plbuf_write = 1; /* Store commands to device in core buffer */ + pls->dev_fill0 = 1; /* Handle solid fills */ + pls->dev_fill1 = 0; + pls->dev_gradient = 1; /* driver renders gradient */ /* Let the PLplot core handle dashed lines since * the driver results for this capability have a number of issues. * pls->dev_dash=1; */ @@ -1261,9 +1296,11 @@ void plD_esc_qtwidget( PLStream * pls, PLINT op, void* ptr ) { - short *xa, *ya; - PLINT i; - QtPLWidget * widget = (QtPLWidget *) pls->dev; + short *xa, *ya; + PLINT i; + unsigned char *r, *g, *b; + PLFLT *alpha; + QtPLWidget * widget = (QtPLWidget *) pls->dev; if ( widget == NULL ) return; switch ( op ) @@ -1285,6 +1322,38 @@ delete[] ya; break; + case PLESC_GRADIENT: + xa = new short[pls->dev_npts]; + ya = new short[pls->dev_npts]; + r = new unsigned char[pls->ncol1]; + g = new unsigned char[pls->ncol1]; + b = new unsigned char[pls->ncol1]; + alpha = new PLFLT[pls->ncol1]; + + for ( i = 0; i < pls->ncol1; i++ ) + { + r[i] = pls->cmap1[i].r; + g[i] = pls->cmap1[i].g; + b[i] = pls->cmap1[i].b; + alpha[i] = pls->cmap1[i].a; + } + widget->setGradient( pls->xgradient[0], pls->xgradient[1], pls->ygradient[0], pls->ygradient[1], r, g, b, alpha, pls->ncol1 ); + + for ( i = 0; i < pls->dev_npts; i++ ) + { + xa[i] = pls->dev_x[i]; + ya[i] = pls->dev_y[i]; + } + widget->drawPolygon( xa, ya, pls->dev_npts ); + + delete[] xa; + delete[] ya; + delete[] r; + delete[] g; + delete[] b; + delete[] alpha; + break; + case PLESC_HAS_TEXT: widget->setColor( pls->curcolor.r, pls->curcolor.g, pls->curcolor.b, pls->curcolor.a ); widget->drawText( pls, (EscText *) ptr ); @@ -1383,10 +1452,11 @@ plP_setpxl( temp.logicalDpiX() / 25.4 / widget->downscale, temp.logicalDpiY() / 25.4 / widget->downscale ); - pls->color = 1; /* Is a color device */ - pls->plbuf_write = 0; - pls->dev_fill0 = 1; /* Handle solid fills */ - pls->dev_fill1 = 0; + pls->color = 1; /* Is a color device */ + pls->plbuf_write = 0; + pls->dev_fill0 = 1; /* Handle solid fills */ + pls->dev_fill1 = 0; + pls->dev_gradient = 1; /* driver renders gradient */ /* Let the PLplot core handle dashed lines since * the driver results for this capability have a number of issues. * pls->dev_dash=1; */ @@ -1426,9 +1496,11 @@ void plD_esc_extqt( PLStream * pls, PLINT op, void* ptr ) { - short *xa, *ya; - PLINT i; - QtExtWidget * widget = NULL; + short *xa, *ya; + PLINT i; + unsigned char *r, *g, *b; + PLFLT *alpha; + QtExtWidget * widget = NULL; widget = (QtExtWidget*) pls->dev; switch ( op ) @@ -1449,6 +1521,38 @@ delete[] ya; break; + case PLESC_GRADIENT: + xa = new short[pls->dev_npts]; + ya = new short[pls->dev_npts]; + r = new unsigned char[pls->ncol1]; + g = new unsigned char[pls->ncol1]; + b = new unsigned char[pls->ncol1]; + alpha = new PLFLT[pls->ncol1]; + + for ( i = 0; i < pls->ncol1; i++ ) + { + r[i] = pls->cmap1[i].r; + g[i] = pls->cmap1[i].g; + b[i] = pls->cmap1[i].b; + alpha[i] = pls->cmap1[i].a; + } + widget->setGradient( pls->xgradient[0], pls->xgradient[1], pls->ygradient[0], pls->ygradient[1], r, g, b, alpha, pls->ncol1 ); + + for ( i = 0; i < pls->dev_npts; i++ ) + { + xa[i] = pls->dev_x[i]; + ya[i] = pls->dev_y[i]; + } + widget->drawPolygon( xa, ya, pls->dev_npts ); + + delete[] xa; + delete[] ya; + delete[] r; + delete[] g; + delete[] b; + delete[] alpha; + break; + case PLESC_HAS_TEXT: /*$$ call the generic ProcessString function * ProcessString( pls, (EscText *)ptr ); */ Modified: trunk/include/qt.h =================================================================== --- trunk/include/qt.h 2009-12-03 21:52:56 UTC (rev 10674) +++ trunk/include/qt.h 2009-12-03 22:07:49 UTC (rev 10675) @@ -128,9 +128,10 @@ virtual void drawPolygon( short * x, short * y, PLINT npts ); virtual void drawText( PLStream* pls, EscText* txt ); virtual void setColor( int r, int g, int b, double alpha ); + virtual void setBackgroundColor( int r, int g, int b, double alpha ){} virtual void setGradient( int x1, int x2, int y1, int y2, - int *r, int *g, int *b, qreal *alpha, PLINT ncol1 ); - virtual void setBackgroundColor( int r, int g, int b, double alpha ){} + unsigned char *r, unsigned char *g, + unsigned char *b, PLFLT *alpha, PLINT ncol1 ); virtual void setWidth( PLINT w ); // Set pen to draw solid strokes (called after drawing dashed strokes) virtual void setSolid(); @@ -233,6 +234,7 @@ RECTANGLE, SET_WIDTH, SET_COLOUR, + SET_GRADIENT, SET_SMOOTH, TEXT, SET_BG_COLOUR @@ -272,6 +274,7 @@ QLineF * Line; QPolygonF * Polyline; QRectF * Rect; + QLinearGradient * LinearGradient; struct ColourStruct_* ColourStruct; struct TextStruct_ * TextStruct; PLINT intParam; @@ -303,6 +306,9 @@ void drawPolygon( short * x, short * y, PLINT npts ); void setColor( int r, int g, int b, double alpha ); void setBackgroundColor( int r, int g, int b, double alpha ); + void setGradient( int x1, int x2, int y1, int y2, + unsigned char *r, unsigned char *g, + unsigned char *b, PLFLT *alpha, PLINT ncol1 ); void setWidth( PLINT r ); void drawText( PLStream* pls, EscText* txt ); void flush(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |