From: <ai...@us...> - 2009-07-30 20:14:12
|
Revision: 10192 http://plplot.svn.sourceforge.net/plplot/?rev=10192&view=rev Author: airwin Date: 2009-07-30 20:13:58 +0000 (Thu, 30 Jul 2009) Log Message: ----------- AWI for Alban Rochel. Allow changes to the background colors and background transparency. 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-07-30 20:12:09 UTC (rev 10191) +++ trunk/bindings/qt_gui/plqt.cpp 2009-07-30 20:13:58 UTC (rev 10192) @@ -408,7 +408,7 @@ m_painterP->setRenderHint(QPainter::Antialiasing, true); // Let's fill the background - m_painterP->fillRect(0, 0, width(), height(), QBrush(Qt::black)); +// m_painterP->fillRect(0, 0, width(), height(), QBrush(Qt::black)); // fontScalingFactor=1.; } @@ -437,8 +437,16 @@ QBrush b=m_painterP->brush(); b.setStyle(Qt::SolidPattern); m_painterP->setBrush(b); - m_painterP->fillRect(0, 0, width(), height(), QBrush(Qt::black)); +// m_painterP->fillRect(0, 0, width(), height(), QBrush(Qt::black)); } + +void QtRasterDevice::setBackgroundColor(int r, int g, int b, double alpha) +{ + if(!m_painterP->isActive()) return; + + QBrush brush(QColor(r, g, b, (int)(alpha*255))); + m_painterP->fillRect(0, 0, width(), height(), brush); +} #endif #if defined(PLD_svgqt) && QT_VERSION >= 0x040300 @@ -465,13 +473,21 @@ #endif m_painterP=new QPainter(this); - m_painterP->fillRect(0, 0, (int)m_dWidth, (int)m_dHeight, QBrush(Qt::black)); +// m_painterP->fillRect(0, 0, (int)m_dWidth, (int)m_dHeight, QBrush(Qt::black)); } void QtSVGDevice::savePlot() { m_painterP->end(); } + +void QtSVGDevice::setBackgroundColor(int r, int g, int b, double alpha) +{ + if(!m_painterP->isActive()) return; + + QBrush brush(QColor(r, g, b, (int)(alpha*255))); + m_painterP->fillRect(0, 0, width(), height(), brush); +} #endif #if defined (PLD_epsqt) || defined(PLD_pdfqt) @@ -521,13 +537,21 @@ } m_painterP=new QPainter(this); - m_painterP->fillRect(0, 0, (int)m_dWidth, (int)m_dHeight, QBrush(Qt::black)); +// m_painterP->fillRect(0, 0, (int)m_dWidth, (int)m_dHeight, QBrush(Qt::black)); } void QtEPSDevice::savePlot() { m_painterP->end(); } + +void QtEPSDevice::setBackgroundColor(int r, int g, int b, double alpha) +{ + if(!m_painterP->isActive()) return; + + QBrush brush(QColor(r, g, b, (int)(alpha*255))); + m_painterP->fillRect(0, 0, width(), height(), brush); +} #endif #if defined (PLD_qtwidget) || defined(PLD_extqt) @@ -577,6 +601,10 @@ case SET_COLOUR: delete i->Data.ColourStruct; break; + + case SET_BG_COLOUR: + delete i->Data.ColourStruct; + break; case TEXT: delete[] i->Data.TextStruct->text; @@ -650,6 +678,19 @@ m_listBuffer.append(el); } +void QtPLWidget::setBackgroundColor(int r, int g, int b, double alpha) +{ + BufferElement el; + el.Element=SET_BG_COLOUR; + el.Data.ColourStruct=new struct ColourStruct_; + el.Data.ColourStruct->R=r; + el.Data.ColourStruct->G=g; + el.Data.ColourStruct->B=b; + el.Data.ColourStruct->A=alpha*255.; + + m_listBuffer.append(el); +} + void QtPLWidget::setSolid() { BufferElement el; @@ -804,7 +845,7 @@ // Draw the margins and the background painter->fillRect(0, 0, width(), height(), QBrush(Qt::white)); painter->fillRect(0, 0, width(), height(), QBrush(Qt::gray, Qt::Dense4Pattern)); - painter->fillRect((int)x_offset, (int)y_offset, (int)floor(x_fact*m_dWidth+0.5), (int)floor(y_fact*m_dHeight+0.5), QBrush(Qt::black)); +// painter->fillRect((int)x_offset, (int)y_offset, (int)floor(x_fact*m_dWidth+0.5), (int)floor(y_fact*m_dHeight+0.5), QBrush(Qt::black)); // Draw the plot doPlot(painter, x_fact, y_fact, x_offset, y_offset); @@ -891,6 +932,11 @@ p->setBrush(brush); break; + case SET_BG_COLOUR: + brush.setColor(QColor(i->Data.ColourStruct->R, i->Data.ColourStruct->G, i->Data.ColourStruct->B, i->Data.ColourStruct->A)); + p->fillRect((int)x_offset, (int)y_offset, (int)floor(x_fact*m_dWidth+0.5), (int)floor(y_fact*m_dHeight+0.5), brush); + break; + case SET_SOLID: pen.setStyle(Qt::SolidLine); p->setPen(pen); Modified: trunk/drivers/qt.cpp =================================================================== --- trunk/drivers/qt.cpp 2009-07-30 20:12:09 UTC (rev 10191) +++ trunk/drivers/qt.cpp 2009-07-30 20:13:58 UTC (rev 10192) @@ -214,6 +214,7 @@ void plD_tidy_qtwidget(PLStream *); void plD_state_qtwidget(PLStream *, PLINT); void plD_esc_qtwidget(PLStream *, PLINT, void*); +void plD_bop_qtwidget(PLStream *); #endif #if defined(PLD_extqt) @@ -225,12 +226,9 @@ void plD_tidy_extqt(PLStream *); void plD_state_extqt(PLStream *, PLINT); void plD_esc_extqt(PLStream *, PLINT, void*); +void plD_bop_extqt(PLStream *); #endif -// Declaration of the generic interface functions - -void plD_bop_qt(PLStream *){} - ////////////////// Raster driver-specific definitions: class and interface functions ///////// #if defined (PLD_bmpqt) || defined(PLD_jpgqt) || defined (PLD_pngqt) || defined(PLD_ppmqt) || defined(PLD_tiffqt) void plD_init_rasterqt(PLStream * pls) @@ -437,6 +435,7 @@ pls->page++; if(qt_family_check(pls)) {return;} ((QtRasterDevice *)pls->dev)->definePlotName(pls->FileName, "BMP"); + ((QtRasterDevice *)pls->dev)->setBackgroundColor(pls->cmap0[0].r, pls->cmap0[0].g, pls->cmap0[0].b, pls->cmap0[0].a); } #endif @@ -468,6 +467,7 @@ pls->page++; if(qt_family_check(pls)) {return;} ((QtRasterDevice *)pls->dev)->definePlotName(pls->FileName, "JPG"); + ((QtRasterDevice *)pls->dev)->setBackgroundColor(pls->cmap0[0].r, pls->cmap0[0].g, pls->cmap0[0].b, pls->cmap0[0].a); } #endif @@ -499,6 +499,7 @@ pls->page++; if(qt_family_check(pls)) {return;} ((QtRasterDevice *)pls->dev)->definePlotName(pls->FileName, "PNG"); + ((QtRasterDevice *)pls->dev)->setBackgroundColor(pls->cmap0[0].r, pls->cmap0[0].g, pls->cmap0[0].b, pls->cmap0[0].a); } #endif @@ -530,6 +531,7 @@ pls->page++; if(qt_family_check(pls)) {return;} ((QtRasterDevice *)pls->dev)->definePlotName(pls->FileName, "PPM"); + ((QtRasterDevice *)pls->dev)->setBackgroundColor(pls->cmap0[0].r, pls->cmap0[0].g, pls->cmap0[0].b, pls->cmap0[0].a); } #endif @@ -561,6 +563,7 @@ pls->page++; if(qt_family_check(pls)) {return;} ((QtRasterDevice *)pls->dev)->definePlotName(pls->FileName, "TIFF"); + ((QtRasterDevice *)pls->dev)->setBackgroundColor(pls->cmap0[0].r, pls->cmap0[0].g, pls->cmap0[0].b, pls->cmap0[0].a); } #endif @@ -645,6 +648,7 @@ pls->page++; if(qt_family_check(pls)) {return;} ((QtSVGDevice *)pls->dev)->definePlotName(pls->FileName); + ((QtSVGDevice *)pls->dev)->setBackgroundColor(pls->cmap0[0].r, pls->cmap0[0].g, pls->cmap0[0].b, pls->cmap0[0].a); } void plD_eop_svgqt(PLStream *pls) @@ -875,6 +879,7 @@ pls->page++; if(qt_family_check(pls)) {return;} ((QtEPSDevice *)pls->dev)->definePlotName(pls->FileName, ifeps); + ((QtEPSDevice *)pls->dev)->setBackgroundColor(pls->cmap0[0].r, pls->cmap0[0].g, pls->cmap0[0].b, pls->cmap0[0].a); } void plD_eop_epspdfqt(PLStream *pls) @@ -1029,7 +1034,7 @@ pdt->pl_line = (plD_line_fp) plD_line_qtwidget; pdt->pl_polyline = (plD_polyline_fp) plD_polyline_qtwidget; pdt->pl_eop = (plD_eop_fp) plD_eop_qtwidget; - pdt->pl_bop = (plD_bop_fp) plD_bop_qt; + pdt->pl_bop = (plD_bop_fp) plD_bop_qtwidget; pdt->pl_tidy = (plD_tidy_fp) plD_tidy_qtwidget; pdt->pl_state = (plD_state_fp) plD_state_qtwidget; pdt->pl_esc = (plD_esc_fp) plD_esc_qtwidget; @@ -1105,6 +1110,12 @@ } } +void plD_bop_qtwidget(PLStream *pls) +{ + QtPLWidget* widget=((QtPLWidget*)pls->dev); + widget->setBackgroundColor(pls->cmap0[0].r, pls->cmap0[0].g, pls->cmap0[0].b, pls->cmap0[0].a); +} + void plD_line_qtwidget(PLStream * pls, short x1a, short y1a, short x2a, short y2a) { QtPLWidget* widget=(QtPLWidget*)pls->dev; @@ -1218,7 +1229,7 @@ pdt->pl_line = (plD_line_fp) plD_line_extqt; pdt->pl_polyline = (plD_polyline_fp) plD_polyline_extqt; pdt->pl_eop = (plD_eop_fp) plD_eop_extqt; - pdt->pl_bop = (plD_bop_fp) plD_bop_qt; + pdt->pl_bop = (plD_bop_fp) plD_bop_extqt; pdt->pl_tidy = (plD_tidy_fp) plD_tidy_extqt; pdt->pl_state = (plD_state_fp) plD_state_extqt; pdt->pl_esc = (plD_esc_fp) plD_esc_extqt; @@ -1374,4 +1385,11 @@ void plD_eop_extqt(PLStream *pls) { } + +void plD_bop_extqt(PLStream *pls) +{ + QtExtWidget * widget=NULL; + widget=(QtExtWidget*)pls->dev; + widget->setBackgroundColor(pls->cmap0[0].r, pls->cmap0[0].g, pls->cmap0[0].b, pls->cmap0[0].a); +} #endif Modified: trunk/include/qt.h =================================================================== --- trunk/include/qt.h 2009-07-30 20:12:09 UTC (rev 10191) +++ trunk/include/qt.h 2009-07-30 20:13:58 UTC (rev 10192) @@ -136,6 +136,8 @@ virtual void setColor(int r, int g, int b, double alpha); + virtual void setBackgroundColor(int r, int g, int b, double alpha){} + virtual void setWidth(PLINT w); virtual void setDashed(PLINT nms, PLINT* mark, PLINT* space); @@ -180,6 +182,8 @@ int i_iHeight=QT_DEFAULT_Y); virtual ~QtRasterDevice(); + + virtual void setBackgroundColor(int r, int g, int b, double alpha); void definePlotName(const char* fileName, const char* format); @@ -209,6 +213,8 @@ virtual ~QtSVGDevice(); + virtual void setBackgroundColor(int r, int g, int b, double alpha); + void definePlotName(const char* fileName); void savePlot(); @@ -229,7 +235,9 @@ #endif virtual ~QtEPSDevice(); - + + virtual void setBackgroundColor(int r, int g, int b, double alpha); + void definePlotName(const char* fileName, int ifeps); void savePlot(); @@ -249,7 +257,8 @@ SET_WIDTH, SET_COLOUR, SET_SOLID, - TEXT + TEXT, + SET_BG_COLOUR } ElementType; // Identifiers for elements of the buffer struct LineStruct_ @@ -333,6 +342,7 @@ void drawPolyline(short * x, short * y, PLINT npts); 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 setWidth(PLINT r); void setSolid(); void drawText(PLStream* pls, EscText* txt); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |