[Kst] extragear/graphics/kst/kst
Rick Chern
rchern at interchange.ubc.ca
Tue Aug 2 21:22:19 CEST 2005
SVN commit 442474 by rchern:
- curves draw legend symbols themselves
- images have legend symbols too:
- gradient of the color palette if colormap,
- box in contour color if contourmap
M +3 -0 kstbasecurve.h
M +20 -0 kstimage.cpp
M +4 -0 kstimage.h
M +11 -34 kstlegend.cpp
M +17 -0 kstvcurve.cpp
M +3 -0 kstvcurve.h
--- trunk/extragear/graphics/kst/kst/kstbasecurve.h #442473:442474
@@ -92,6 +92,9 @@
// render this curve
virtual void paint(KstCurveRenderContext context) = 0;
+
+ // render the legend symbol for this curve
+ virtual void paintLegendSymbol(QPainter *p, const QRect& bound) = 0;
protected:
--- trunk/extragear/graphics/kst/kst/kstimage.cpp #442473:442474
@@ -715,4 +715,24 @@
}
+void KstImage::paintLegendSymbol(QPainter *p, const QRect& bound) {
+ if (hasColorMap()) {
+ // draw the color palette
+ if (_pal) {
+ for (int i = bound.left(); i <= bound.right(); i++) {
+ int index = (int)floor(((i - bound.left()) * (_pal->nrColors() - 1)) / (bound.right() - bound.left()));
+ QColor sliceColor = _pal->color(index).rgb();
+ p->setPen(QPen(sliceColor, 0));
+ p->drawLine(i, bound.top(), i, bound.bottom());
+ }
+ }
+ }
+ if (hasContourMap()) {
+ // draw a box with contour color
+ p->setPen(QPen(_contourColor, 0));
+ p->drawRect(bound.left(), bound.top(), bound.width(), bound.height());
+ }
+}
+
+
// vim: ts=2 sw=2 et
--- trunk/extragear/graphics/kst/kst/kstimage.h #442473:442474
@@ -109,7 +109,11 @@
// see KstBaseCurve::paint
virtual void paint(KstCurveRenderContext context);
+ // see KstBaseCurve::yRange
virtual void yRange(double xFrom, double xTo, double* yMin, double* yMax);
+
+ // see KstBaseCurve::paintLegendSymbol
+ virtual void paintLegendSymbol(QPainter *p, const QRect& bound);
private:
//use these to set defaults when either is not used.
--- trunk/extragear/graphics/kst/kst/kstlegend.cpp #442473:442474
@@ -133,7 +133,6 @@
}
void KstLegend::drawHorizontally(KstBaseCurveList* pCurves, QPainter &p, const QRect& rect, int px, int py) {
- KstPoint tmppoint;
QRect rectTotal;
int iLineSpace;
int iLineHeight;
@@ -200,6 +199,7 @@
iX = 0;
for(KstBaseCurveList::iterator it = pCurves->begin(); it != pCurves->end(); it++) {
iTextWidth = p.fontMetrics().width((*it)->tagName());
+ int iTextHeight = iLineHeight - p.fontMetrics().descent();
iItemWidth = iTextWidth + 4*iCharWidth;
if(iNumInLine > 0 && px + iX + iItemWidth > rect.width()) {
iNumInLine = 1;
@@ -213,22 +213,10 @@
p.setPen(_colorForeground);
p.drawText(px + iX + (iCharWidth/2), py + iY, (*it)->tagName());
- //
- // draw the corresponding line and point...if it is a vcurve
- //
- if (KstVCurvePtr vcurve = kst_cast<KstVCurve>(*it)) {
- if(vcurve->hasLines()) {
- p.setPen(QPen(vcurve->color(), vcurve->lineWidth(), KstLineStyle[vcurve->lineStyle()]));
- p.drawLine(px + iX + (iCharWidth/2) + iTextWidth + (1*iCharWidth), py + iY - (iLineHeight/2),
- px + iX + (iCharWidth/2) + iTextWidth + (3*iCharWidth), py + iY - (iLineHeight/2));
- }
- if(vcurve->hasPoints()) {
- p.setPen(QPen(vcurve->color(), vcurve->lineWidth()));
- tmppoint.setType(vcurve->Point.type());
- tmppoint.draw(&p, px + iX + (iCharWidth/2) + iTextWidth + 2*iCharWidth,
- py + iY - (iLineHeight/2), vcurve->lineWidth(), 600);
- }
- } //TODO: what to draw for images?
+ // draw the symbol for this curve
+ QRect symbolBound(QPoint(px+iX+(iCharWidth/2)+iTextWidth+(1*iCharWidth), py+iY-iTextHeight + 1),
+ QSize(2*iCharWidth, iTextHeight - 1));
+ (*it)->paintLegendSymbol(&p, symbolBound);
iX += iItemWidth;
}
@@ -245,7 +233,6 @@
int iLineWidthMax = 0;
int iCharWidth;
int iX;
- int iY;
iLineSpace = p.fontMetrics().lineSpacing();
iLineHeight = p.fontMetrics().ascent();
@@ -287,6 +274,7 @@
for(KstBaseCurveList::iterator it = pCurves->begin(); it != pCurves->end(); it++) {
iLineWidth = p.fontMetrics().width((*it)->tagName());
+ int iTextHeight = iLineHeight - p.fontMetrics().descent();
if(it == pCurves->begin()) {
px += iCharWidth / 2;
py += iLineHeight;
@@ -307,22 +295,11 @@
p.drawText( iX, py, (*it)->tagName());
- //
- // draw the corresponding line and point...if it is a vcurve
- //
- if (KstVCurvePtr vcurve = kst_cast<KstVCurve>(*it)) {
- iX = iX + iLineWidth + iCharWidth;
- iY = py - iLineHeight/2;
- if(vcurve->hasLines()) {
- p.setPen(QPen(vcurve->color(), vcurve->lineWidth(), KstLineStyle[vcurve->lineStyle()]));
- p.drawLine(iX, iY, iX+2*iCharWidth, iY);
- }
- if(vcurve->hasPoints()) {
- p.setPen(QPen(vcurve->color(), vcurve->lineWidth()));
- tmppoint.setType(vcurve->Point.type());
- tmppoint.draw(&p, iX+iCharWidth, iY, vcurve->lineWidth(), 600);
- }
- }
+ // draw the legend symbol
+ QRect symbolBound(QPoint(iX + iLineWidth + iCharWidth, py-iTextHeight + 1),
+ QSize(2*iCharWidth, iTextHeight - 1));
+ (*it)->paintLegendSymbol(&p, symbolBound);
+
py += iLineSpace;
}
}
--- trunk/extragear/graphics/kst/kst/kstvcurve.cpp #442473:442474
@@ -1514,5 +1514,22 @@
return fabs(ypos - near_y);
}
+
+void KstVCurve::paintLegendSymbol(QPainter *p, const QRect& bound) {
+ if (hasLines()) {
+ // draw a line from left to right centered vertically
+ p->setPen(QPen(color(), lineWidth(), KstLineStyle[lineStyle()]));
+ p->drawLine(bound.left(), bound.top() + bound.height()/2,
+ bound.right(), bound.top() + bound.height()/2);
+ }
+ if (hasPoints()) {
+ // draw a point in the middle
+ p->setPen(QPen(color(), lineWidth()));
+ KstPoint tmppoint;
+ tmppoint.setType(Point.type());
+ tmppoint.draw(p, bound.left() + bound.width()/2, bound.top() + bound.height()/2,
+ lineWidth(), 600);
+ }
+}
// vim: ts=2 sw=2 et
--- trunk/extragear/graphics/kst/kst/kstvcurve.h #442473:442474
@@ -138,6 +138,9 @@
// render this vcurve
virtual void paint(KstCurveRenderContext context);
+ // render the legend symbol for this curve
+ virtual void paintLegendSymbol(QPainter *p, const QRect& bound);
+
// see KstBaseCurve::distanceToPoint
virtual double distanceToPoint(double xpos, double dx, double ypos) const;
More information about the Kst
mailing list