Ejemplo n.º 1
0
void tAutorouteColorLegend::DrawOneLegendElement(int index)
{   
    int squareSize      = 16; // Size of square for legend
    int textXOffset     = 20; // Offset from side for text.
    int textYSeparation = 20; // Offset from each level in entry for text.
    int fontSize        = 12;

    QPainter p(this);

    QPen TextPen( p.pen() );
    TextPen.setColor( Qt::black );

    if ( NightMode() == true )
    {
        TextPen.setColor( Qt::white );
    }

    // Chose size 12 because it looks good
    QFont font;
    font.setPixelSize(fontSize);
    p.setFont(font);

    p.setPen(TextPen);
    p.drawText(textXOffset, textYSeparation*index + fontSize , qApp->translate( "tAutorouteColorLegend", m_cEasyRoutingLegendStringTable[index] ) );

    p.fillRect(QRect(0, textYSeparation*index, squareSize, squareSize), m_cEasyRoutingLegendColorTable[index]);
}
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]);
    }

}
Ejemplo n.º 3
0
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();

}
Ejemplo n.º 4
0
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();
}
Ejemplo n.º 5
0
void SectionViewWidget::PaintLegend(QPainter &painter)
{
	if(!m_pSailSection) return;
	painter.save();
	MainFrame* pMainFrame = (MainFrame*)s_pMainFrame;
	QString strlength;
	GetLengthUnit(strlength, pMainFrame->m_LengthUnit);

	painter.setFont(pMainFrame->m_TextFont);
	QFontMetrics fm(pMainFrame->m_TextFont);
	int dD = fm.height();//pixels

	QPoint Place(5, rect().bottom()-5*dD);

	if(m_pSail->IsNURBSSail()) Place.ry() -=dD;

	painter.setBackgroundMode(Qt::TransparentMode);

	QPen TextPen(pMainFrame->m_TextColor);
	painter.setPen(TextPen);

	if(m_pSail->IsNURBSSail() && m_pSailSection->IsTipSection())
	{
		QString strtwist = QString("Section chord = %1").arg(m_pSailSection->Chord()*pMainFrame->m_mtoUnit, 6,'f',2) + strlength;
		painter.drawText(Place.x(), Place.y() , strtwist);
	}

	if(m_pSail->IsSailcutSail() || m_pSailSection->IsTipSection())
	{
		double x, c;
		m_pSailSection->GetCamber(c, x);

		QString strc = QString("Camber        = %1").arg(c*100.0, 6, 'f',2);
		QString strx = QString("Camber pos    = %1").arg(x*100.0, 6, 'f',2);
		strc += QString::fromUtf8("%");
		strx += QString::fromUtf8("%");

		painter.drawText(Place.x(), Place.y() + dD, strx);
		painter.drawText(Place.x(), Place.y() + 2*dD, strc);
	}


	double s0,s1;
	m_pSailSection->GetSlopes(s0,s1);
	QString str0 = QString("Luff Slope    = %1").arg(s0,5,'f',1) + QString::fromUtf8("°");
	QString str1 = QString("Leech Slope   = %1").arg(s1,5,'f',1) + QString::fromUtf8("°");

	painter.drawText(Place.x(), Place.y() + 3*dD, str0);
	painter.drawText(Place.x(), Place.y() + 4*dD, str1);

	if(m_pSail->IsNURBSSail())
	{
		QString strtwist = QString("Section twist = %1").arg(m_pSailSection->Twist(), 5,'f',1) + QString::fromUtf8("°");
		painter.drawText(Place.x(), Place.y() + 5*dD, strtwist);
	}

	//right side legend

	if(m_pSail->IsNURBSSail())
	{
		int YPos = rect().bottom()- dD;
		int XPos = rect().right() -5;

		NURBSSail *pNSail =(NURBSSail*)m_pSail;
		CVector LE = pNSail->m_SplineSurface.LeadingEdgeAxis();
		QString strLuffAngle = QString("Luff Angle = %1").arg(atan2(LE.x, LE.z) * 180./PI, 5,'f',1) + QString::fromUtf8("°");
		painter.drawText(XPos-fm.width(strLuffAngle), YPos, strLuffAngle);
	}

	painter.restore();
}