Example #1
0
void QGraph::DrawYMinGrid(QPainter &painter)
{
	double scaley = m_scaley;
	if(fabs(yunit)<0.00000001) return;
	if(fabs(m_YMinorUnit)<0.00000001) return;
	if(fabs(ymax-ymin)/yunit>30.0) return;
	if(fabs(ymax-ymin)/m_YMinorUnit>100.0) return;

	painter.save();
	QPen GridPen(m_YMinClr);
	GridPen.setStyle(GetStyle(m_YMinStyle));
	GridPen.setWidth(m_YMinWidth);
	painter.setPen(GridPen);

	double yDelta = m_YMinorUnit;
	double yt = yo-int((yo-ymin)*1.0001/yDelta)*yDelta;//one tick at the origin
	int XMin = qMax((int)(xmin/m_scalex + m_ptoffset.x()), m_rCltRect.left());
	int XMax = qMin((int)(xmax/m_scalex + m_ptoffset.x()), m_rCltRect.right());

	while(yt<=ymax*1.0001)
	{
		if(yt>=ymin)
		{
			painter.drawLine(XMin, (int)(yt/scaley)   + m_ptoffset.y(), XMax, (int)(yt/scaley)   + m_ptoffset.y());
		}
		yt += yDelta ;
	}
	painter.restore();
}
Example #2
0
void QGraph::DrawXMinGrid(QPainter &painter)
{
	double scaley = m_scaley;
	if(fabs(xunit)<0.00000001) return;
	if(fabs(m_XMinorUnit)<0.00000001) return;
	if(fabs(xmax-xmin)/xunit>30.0) return;
	if(fabs(xmax-xmin)/m_XMinorUnit>100.0) return;
	int YMin, YMax;

	painter.save();
	QPen GridPen(m_XMinClr);
	GridPen.setStyle(GetStyle(m_XMinStyle));
	GridPen.setWidth(m_XMinWidth);
	painter.setPen(GridPen);


	YMin = (int)(ymin/scaley)+ m_ptoffset.y();
	YMax = (int)(ymax/scaley)+ m_ptoffset.y();

	double xDelta = m_XMinorUnit;
	double xt = xo-int((xo-xmin)*1.0001/xDelta)*xDelta;//one tick at the origin


	while(xt<=xmax*1.001)
	{
		if(xt>=xmin)
		{
			painter.drawLine(int(xt/m_scalex) + m_ptoffset.x(), YMin, int(xt/m_scalex) + m_ptoffset.x(), YMax);
		}
		xt += xDelta;
	}
	painter.restore();
}
void CStatsWidget::DrawGrid(const QStringList& labelList)
{
    unsigned int nCols = labelList.size();
    unsigned int nWidth = width() - m_nLeftBorder;
    unsigned int nHeight = height() - m_nBottomBorder;
    QPainter p(this);
    QPen GridPen(Qt::gray);
    QPen TextPen(Qt::lightGray);
    p.setPen(GridPen);

    // draw horizontal line
    p.drawLine(m_nLeftBorder, nHeight, width(), nHeight);
    
    unsigned int nColWidth = nWidth / nCols;
	    
    // draw vertical lines
    for(unsigned int i=0; i<nCols; i++){
	unsigned int nX = i*nColWidth + m_nLeftBorder;
	p.drawLine(nX, 0, nX, nHeight);
    }
    
    p.setPen(TextPen);
    
    // draw weekday names
    for(unsigned int i=0; i<labelList.size(); i++){
	unsigned int nX = i*nColWidth + m_nLeftBorder + 5;
	p.drawText(nX, height()-5, labelList[i]);
    }

}
void CStatsWidget::DrawBars()
{
//    for(int i=0; i<m_pData->size(); i++)
//	kdDebug() << "Value: " << m_pData->at(i) << endl;
    unsigned int nCols = m_pData->size();
    unsigned int nDrawWidth = width() - m_nLeftBorder;
    unsigned int nDrawHeight = height() - m_nBottomBorder;
    unsigned int nColWidth = nDrawWidth / nCols;
    unsigned int nMaxVal = *(std::max_element(m_pData->begin(), m_pData->end())); 
   
    float fScale = ((float)nDrawHeight) / nMaxVal;

    // scale to 90% of draw area
    fScale *= 0.9;
    
    QPainter p(this);
    QPen BarFramePen(Qt::white);
    QPen GridPen(Qt::gray);
     
    unsigned int nStep=0;
    if(nMaxVal<10000)
	nStep = 1000;
    else if(nMaxVal<50000)
	nStep = 5000;
    else if(nMaxVal<100000)
	nStep = 10000;
    else if(nMaxVal<500000)
	nStep = 50000;
    else
	nStep = 100000;
   
    // draw values on the y-axis
    for(unsigned int i=0; i<nMaxVal + nStep; i+=nStep){
	p.setPen(BarFramePen);
	unsigned int nY = nDrawHeight - (unsigned int)(i*fScale)-10;
	p.drawText(5, nY, m_nLeftBorder-10, 20, Qt::AlignRight, 
				QString::number(i/1000));
	p.setPen(GridPen);
	p.drawLine(m_nLeftBorder, nY+10, width(), nY+10);  
    }
	
    QBrush BarFillBrush(Qt::red, Qt::Dense3Pattern);
    p.setPen(BarFramePen);
    p.setBrush(BarFillBrush);

    // draw bars
    for(unsigned int i=0; i<m_pData->size(); i++){
	if(m_pData->at(i) == 0)
	    continue;
	unsigned int nX = i*nColWidth + m_nLeftBorder;
	unsigned int nY = nDrawHeight-(unsigned int)(m_pData->at(i)*fScale);
	p.drawRect(nX, nY, nColWidth, nDrawHeight-nY);
    }
   
   
}
Example #5
0
void CPanel::DrawPanel(CDC* pDC)
{
	CBrush brush;
	CPen pen(PS_DOT,2,RGB(10,10,255)),GridPen(PS_SOLID,1,RGB(190,190,190));
	brush.CreateSolidBrush(PanelColor);
	pDC->SelectObject(&pen);
	CBrush *pOldBrush=pDC->SelectObject(&brush);
	//DrawBegin

	RECT Rect=PanelRect;
	Rect.bottom=PanelRect.bottom;
	Rect.right=PanelRect.right;
	pDC->Rectangle(&Rect);
	pDC->Rectangle(&TextRect);
	//Text
	CString str;
	pDC->SetTextColor(RGB(255,0,255));
	pDC->SetBkColor(PanelColor);

	str="姓名: " + pManager->Name;
	pDC->TextOut(TextRect.left+10,TextRect.top+10,str);
	str.Format("等级:        %d",pManager->Level);
	pDC->TextOut(TextRect.left+10,TextRect.top+40,str);
	str.Format("消掉行数:%d",pManager->LineNumber);	
	pDC->TextOut(TextRect.left+10,TextRect.top+70,str);
	str.Format("分值:        %d",pManager->Result);
	pDC->TextOut(TextRect.left+10,TextRect.top+100,str);
	//DrawLine
	pDC->SelectObject(&GridPen);
	for(int iy=PanelRect.top;iy<PanelRect.bottom;iy+=GridSize.cy)
	{
		pDC->MoveTo(PanelRect.left,iy);
		pDC->LineTo(PanelRect.right,iy);
	}

	for(int ix=PanelRect.left;ix<PanelRect.right;ix+=GridSize.cx)
	{
		pDC->MoveTo(ix,PanelRect.top);
		pDC->LineTo(ix,PanelRect.bottom);
	}
	//DrawEnd
	pDC->SelectObject(pOldBrush);
	brush.DeleteObject();
}