void CLineGraph::Paint(CDC* pDC, CRect* pRect) { if ( m_pGridPen.m_hObject == NULL ) m_pGridPen.CreatePen( PS_SOLID, 1, m_crGrid ); DWORD nWidth = (DWORD)pRect->Width() / m_nScale + 2; if ( pRect->Width() > 64 ) { for ( POSITION pos = GetItemIterator() ; pos ; ) { CGraphItem* pItem = GetNextItem( pos ); pItem->SetHistory( nWidth ); } } pDC->FillSolidRect( pRect, m_crBack ); if ( m_pItems.IsEmpty() || m_nMaximum == 0 ) return; CFont* pOldFont = (CFont*)pDC->SelectObject( &theApp.m_gdiFont ); pDC->SetBkMode( TRANSPARENT ); if ( m_bShowGrid ) PaintGrid( pDC, pRect ); for ( POSITION pos = m_pItems.GetHeadPosition() ; pos ; ) { CGraphItem* pItem = (CGraphItem*)m_pItems.GetNext( pos ); DWORD nPoints = min( pItem->m_nLength, nWidth ); POINT* pPoints = new POINT[ nPoints ]; for ( DWORD nPos = 0 ; nPos < nPoints ; nPos++ ) { DWORD nValue = pItem->GetValueAt( nPos ); nValue = pRect->bottom - nValue * ( pRect->Height() - TOP_MARGIN ) / m_nMaximum; pPoints[ nPos ].x = pRect->right - nPos * m_nScale - 1; pPoints[ nPos ].y = nValue + 4; } pItem->MakeGradient( m_crBack ); CPen* pOldPen = (CPen*)pDC->SelectObject( &pItem->m_pPen[3] ); for ( int nLayer = 4 ; nLayer ; nLayer-- ) { pDC->Polyline( pPoints, nPoints ); if ( nLayer > 1 ) { for ( DWORD nPos = 0 ; nPos < nPoints ; nPos++ ) pPoints[ nPos ].y --; pDC->SelectObject( &pItem->m_pPen[ nLayer - 2 ] ); } } pDC->SelectObject( pOldPen ); delete [] pPoints; } if ( m_bShowLegend ) PaintLegend( pDC, pRect ); pDC->SelectObject( pOldFont ); }
void SectionViewWidget::paintEvent(QPaintEvent *event) { QPainter painter(this); painter.save(); MainFrame* pMainFrame = (MainFrame*)s_pMainFrame; QPen LinePen; LinePen.setColor(QColor(255,0,0)); LinePen.setWidth(2); painter.setPen(LinePen); painter.fillRect(rect(), pMainFrame->m_BackgroundColor); painter.setFont(pMainFrame->m_TextFont); if(m_bZoomIn&& !m_ZoomRect.isEmpty()) { QRect ZRect = m_ZoomRect.normalized(); QPen ZoomPen(QColor(100,100,100)); ZoomPen.setStyle(Qt::DashLine); painter.setPen(ZoomPen); painter.drawRect(ZRect); } if(m_bNeutralLine) { QPen NPen(m_NeutralColor); NPen.setStyle(GetStyle(m_NeutralStyle)); NPen.setWidth(m_NeutralWidth); painter.setPen(NPen); painter.drawLine(rect().right(), m_ptOffset.y(), rect().left(), m_ptOffset.y()); painter.drawLine(m_ptOffset.x(), rect().bottom(), m_ptOffset.x(), rect().top()); } if(!s_bCurrentOnly && m_pSail /* && m_pSail->IsSailcutSail()*/) { QColor clr = m_pSailSection->m_SCSpline.m_SplineColor; clr.setHsv(clr.hue(), (int)(clr.saturation()), (int)(clr.value()*.29)); QPen OtherPen(clr); OtherPen.setStyle(Qt::DashLine); OtherPen.setWidth(1.0); painter.setPen(OtherPen); for(int is=0; is<m_pSail->m_oaSection.size(); is++) { SailSection *pSection = (SailSection*)m_pSail->m_oaSection.at(is); if(pSection != m_pSailSection) { if(m_pSail->IsSailcutSail()) pSection->DrawSpline(painter, m_Scale,m_Scale*m_ScaleY, m_ptOffset, false); else { NURBSSail *pNSail = (NURBSSail*)m_pSail; int index = m_pSail->m_oaSection.indexOf(m_pSailSection); if(is!=index) pNSail->DrawFrame(is, painter, m_Scale, m_Scale*m_ScaleY, m_ptOffset); } } } } if(m_pSailSection) { if(m_pSail->IsNURBSSail()) { NURBSSail *pNSail = (NURBSSail*)m_pSail; int index = m_pSail->m_oaSection.indexOf(m_pSailSection); QPen SplinePen; SplinePen.setStyle(GetStyle(m_pSailSection->m_SCSpline.m_Style)); SplinePen.setWidth(m_pSailSection->m_SCSpline.m_Width); SplinePen.setColor(m_pSailSection->m_SCSpline.m_SplineColor); painter.setPen(SplinePen); // if(index==0 || index==m_pSail->m_oaSection.size()-1) { pNSail->DrawFrame(index, painter, m_Scale, m_Scale*m_ScaleY, m_ptOffset); } m_pSailSection->DrawCtrlPoints(painter, m_Scale, m_Scale*m_ScaleY, m_ptOffset); } else { m_pSailSection->DrawSpline(painter, m_Scale, m_Scale*m_ScaleY, m_ptOffset); } } QPen TextPen(pMainFrame->m_TextColor); painter.setPen(TextPen); PaintLegend(painter); QString str; str = QString("X-Scale = %1").arg(m_Scale/m_RefScale,4,'f',1); painter.drawText(5,10, str); str = QString("Y-Scale = %1").arg(m_ScaleY*m_Scale/m_RefScale,4,'f',1); painter.drawText(5,22, str); str = QString("x = %1").arg(m_MousePos.x,7,'f',4); painter.drawText(5,34, str); str = QString("y = %1").arg(m_MousePos.y,7,'f',4); painter.drawText(5,46, str); painter.restore(); }