some random code
void CConnectionLine::updateDataLabel()
{
if(NULL != m_pDataLabel)
{
double dPixelScale = CApi::GetInstance()->getPixelScale();
QString sText = QString(“%1 mm”).arg(getLength() * dPixelScale);
m_pDataLabel->setText(sText);
QPointF pt = (m_pStart->pos()+ m_pEnd->pos())/2;
QRectF textRect = m_pTextLabel->boundingRect();
double dHeight = textRect.height();
double dAngle = 0;
double dX = m_pStart->pos().x() – m_pEnd->pos().x();
double dY = m_pStart->pos().y() – m_pEnd->pos().y();
dAngle = atan(dY / dX) * 180 / 3.14159265;
m_pDataLabel->resetTransform();
m_pDataLabel->translate(pt.x(), pt.y());
QRectF rect = m_pDataLabel->boundingRect();
m_pDataLabel->rotate(dAngle);
m_pDataLabel->scale(m_dScaleFactor, m_dScaleFactor);
m_pDataLabel->translate(-rect.width()/2, dHeight / 2);
m_pDataLabel->update();
}
}
void CApi::setPixelScale(double dScale)
{
m_dPixelScale = dScale;
for(int i = 0; i < (int)m_vpLines.size(); ++i)
{
if(CConnectionLine::eDistance == m_vpLines[i]->getType())
{
m_vpLines[i]->updateDataLabel();
}
}
}