[TD]Fix welding text positions

This commit is contained in:
wandererfan
2019-09-09 11:11:37 -04:00
committed by WandererFan
parent f25bf04b8c
commit 5720c2d0bb
3 changed files with 40 additions and 15 deletions

View File

@@ -73,7 +73,8 @@ QGITile::QGITile() :
addToGroup(m_qgTextC);
m_wide = getSymbolWidth();
m_high = prefFontSize();
m_high = getSymbolHeight();
// m_high = prefFontSize();
m_textL = QString();
m_textR = QString();
m_textC = QString();
@@ -113,7 +114,8 @@ void QGITile::draw(void)
prepareGeometryChange();
m_wide = getSymbolWidth();
m_high = getSymbolHeight() * scaleToFont();
// m_high = getSymbolHeight() * scaleToFont();
m_high = getSymbolHeight();
makeText();
makeSymbol();
@@ -170,7 +172,8 @@ void QGITile::makeSymbol(void)
return;
}
svgFile.close();
m_qgSvg->setScale(scaleToFont());
// m_qgSvg->setScale(scaleToFont());
m_qgSvg->setScale(getSymbolFactor());
m_qgSvg->centerAt(0.0, 0.0); //(0,0) is based on symbol size
} else {
Base::Console().Error("Error - Could not open file **%s**\n", qPrintable(m_svgPath));
@@ -188,7 +191,7 @@ void QGITile::makeText(void)
m_font.setPixelSize(prefFontSize());
double verticalFudge = 0.10;
//(0, 0) is 1/2 up (above line symbol)!
//(0, 0) is 1/2 up symbol (above line symbol)!
m_qgTextL->setFont(m_font);
m_qgTextL->setPlainText(m_textL);
m_qgTextL->setColor(m_colCurrent);
@@ -196,17 +199,23 @@ void QGITile::makeText(void)
double charWidth = textWidth / m_textL.size(); //not good for non-ASCII chars
double hMargin = 1;
if (!m_textL.isEmpty()) {
hMargin = (m_wide / 2.0) + (charWidth / 2.0);
hMargin = (m_wide / 2.0) + (charWidth * 1.5);
}
double vertAdjust = 0.0;
double minVertAdjust = prefFontSize() * 0.1;
if (prefFontSize() > m_high) { //text is bigger than symbol
vertAdjust = ((prefFontSize() - m_high) / 2.0) + minVertAdjust;
}
double textHeightL = m_qgTextL->boundingRect().height();
double vOffset = 0.0;
if (m_row < 0) { // below line
vOffset = textHeightL * verticalFudge;
} else {
vOffset = 0.0;
} else { // above line
vOffset = -vertAdjust;
}
m_qgTextL->justifyRightAt(-hMargin, vOffset, true);
m_qgTextL->justifyRightAt(-hMargin, vOffset, true); //sb vCentered at 0.5 m_high
m_qgTextR->setFont(m_font);
m_qgTextR->setPlainText(m_textR);
@@ -215,13 +224,13 @@ void QGITile::makeText(void)
charWidth = textWidth / m_textR.size();
hMargin = 1;
if (!m_textR.isEmpty()) {
hMargin = (m_wide / 2.0) + (charWidth / 2.0);
hMargin = (m_wide / 2.0) + (charWidth);
}
double textHeightR = m_qgTextR->boundingRect().height();
if (m_row < 0) { // below line
vOffset = textHeightR * verticalFudge;
} else {
vOffset = 0.0;
vOffset = -vertAdjust;
}
m_qgTextR->justifyLeftAt(hMargin, vOffset, true);
@@ -341,6 +350,7 @@ double QGITile::getSymbolWidth(void) const
// double w = 64.0;
double fudge = 4.0; //allowance for tile border
w = w - fudge;
w = w * getSymbolFactor();
return w;
}
@@ -352,9 +362,11 @@ double QGITile::getSymbolHeight(void) const
double fudge = 4.0;
h = h - fudge;
// double h = 60.0;
h = h * getSymbolFactor();
return h;
}
//make symbols larger or smaller than standard
double QGITile::getSymbolFactor(void) const
{
Base::Reference<ParameterGrp> hGrp = App::GetApplication().GetUserParameter().GetGroup("BaseApp")->
@@ -378,7 +390,8 @@ double QGITile::scaleToFont(void) const
{
double fpx = prefFontSize();
double spx = getSymbolHeight();
double factor = getSymbolFactor();
// double factor = getSymbolFactor();
double factor = 1.0;
double sf = (fpx / spx) * factor;
return sf;
}

View File

@@ -258,7 +258,7 @@ void QGIWeldSymbol::drawTailText(void)
}
m_font.setFamily(getPrefFont());
m_font.setPixelSize(calculateFontPixelSize(getDimFontSize()));
m_font.setPixelSize(prefFontSize());
m_tailText->setFont(m_font);
m_tailText->setPlainText(
@@ -270,10 +270,13 @@ void QGIWeldSymbol::drawTailText(void)
double charWidth = textWidth / tText.size();
double hMargin = charWidth + prefArrowSize();
double textHeight = m_tailText->boundingRect().width();
double vFudge = textHeight * 0.1;
if (getFeature()->isTailRightSide()) {
m_tailText->justifyLeftAt(textPos.x() + hMargin, textPos.y(), true);
m_tailText->justifyLeftAt(textPos.x() + hMargin, textPos.y() - vFudge, true);
} else {
m_tailText->justifyRightAt(textPos.x() - hMargin, textPos.y(), true);
m_tailText->justifyRightAt(textPos.x() - hMargin, textPos.y() - vFudge, true);
}
}
@@ -497,6 +500,14 @@ double QGIWeldSymbol::prefArrowSize()
return size;
}
double QGIWeldSymbol::prefFontSize(void) const
{
Base::Reference<ParameterGrp> hGrp = App::GetApplication().GetUserParameter().
GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/TechDraw/Dimensions");
double sizeMM = hGrp->GetFloat("FontSize", QGIView::DefaultFontSizeInMM);
double fontSize = QGIView::calculateFontPixelSize(sizeMM);
return fontSize;
}
QRectF QGIWeldSymbol::boundingRect() const
{

View File

@@ -108,7 +108,8 @@ protected:
virtual QColor prefNormalColor();
double prefArrowSize();
double prefFontSize(void) const;
TechDraw::DrawWeldSymbol* m_weldFeat;
TechDraw::DrawLeaderLine* m_leadFeat;
TechDraw::DrawTileWeld* m_arrowFeat;