void QGraph::DrawLegend(QPainter &painter, QPoint &Place, QFont &LegendFont, QColor &LegendColor) { painter.save(); int LegendSize, ypos; QString strong; LegendSize = 30; ypos = 12; painter.setFont(LegendFont); CCurve* pCurve; QPen TextPen(LegendColor); QPen LegendPen(Qt::gray); int npos = 0; for (int nc=0; nc< m_oaCurves.size(); nc++) { pCurve = (CCurve*) m_oaCurves[nc]; if(pCurve->IsVisible()) { pCurve->GetTitle(strong); if(pCurve->n>0 && strong.length())//is there anything to draw ? { LegendPen.setColor(pCurve->GetColor()); LegendPen.setStyle(GetStyle(pCurve->GetStyle())); LegendPen.setWidth(pCurve->GetWidth()); painter.setPen(LegendPen); painter.drawLine(Place.x(), Place.y() + ypos*npos, Place.x() + (int)(LegendSize), Place.y() + ypos*npos); painter.setPen(TextPen); painter.drawText(Place.x() + (int)(1.5*LegendSize), Place.y() + ypos*npos+(int)(ypos/2), strong); npos++; } } } painter.restore(); }
void QGraph::DrawCurve(int nIndex, QPainter &painter) { painter.save(); static double scaley; static int i, ptside; static QPoint From, To, Min, Max; static QRect rViewRect; ptside = 2; CCurve* pCurve = GetCurve(nIndex); scaley = m_scaley; QBrush FillBrush(m_BkColor); painter.setBrush(FillBrush); QPen CurvePen(pCurve->GetColor()); CurvePen.setStyle(GetStyle(pCurve->GetStyle())); CurvePen.setWidth((int)pCurve->GetWidth()); painter.setPen(CurvePen); Min.setX(int(xmin/m_scalex) +m_ptoffset.x()); Min.setY(int(ymin/scaley) +m_ptoffset.y()); Max.setX(int(xmax/m_scalex) +m_ptoffset.x()); Max.setY(int(ymax/scaley) +m_ptoffset.y()); rViewRect.setTopLeft(Min); rViewRect.setBottomRight(Max); if(pCurve->n>=1) { From.setX(int(pCurve->x[0]/m_scalex+m_ptoffset.x())); From.setY(int(pCurve->y[0]/scaley +m_ptoffset.y())); if(pCurve->IsVisible()) { for (i=1; i<pCurve->n;i++) { To.setX(int(pCurve->x[i]/m_scalex+m_ptoffset.x())); To.setY(int(pCurve->y[i]/scaley +m_ptoffset.y())); painter.drawLine(From, To); From = To; } } if(pCurve->PointsVisible()) { for (i=0; i<pCurve->n;i++) { if(pCurve->GetSelected() !=i) painter.drawRect(int(pCurve->x[i]/m_scalex+m_ptoffset.x())-ptside, int(pCurve->y[i]/ scaley+m_ptoffset.y())-ptside, 2*ptside,2*ptside); } } } if(m_bHighlightPoint) { int point = pCurve->GetSelected(); if(point>=0) { //highlight QColor HighColor(0,40, 150); CurvePen.setWidth((int)pCurve->GetWidth()); CurvePen.setColor(HighColor); painter.setPen(CurvePen); To.setX(int(pCurve->x[point]/m_scalex+m_ptoffset.x())); To.setY(int(pCurve->y[point]/scaley +m_ptoffset.y())); painter.drawRect(To.x()-ptside-1,To.y()-ptside-1, 2*(ptside+1),2*(ptside+1)); } } painter.restore(); }