Allow Text meter widgets to be of same size and well aligned (#3506)

The y scale is computed from the font instead of only from the current content, to avoid having different scales between different Text widgets of the same size. For example, "kph" has a high k and low p, resulting in a text widget with bigger bounding box, and thus smaller scale than a text widget with "watts". Options are added for alignment and for text width, to help align the different entries. The formatting of metrics with the integer part as Text and fraction as AltText is more systematic and it is possible to add an AltTextSuffix, to specify the units when they are not provided in VideoWindow. The visibility of the BoundingRect and Background car be controlled.
This commit is contained in:
Michel Dagenais
2020-06-24 10:58:08 -04:00
committed by GitHub
parent 028e822aa4
commit a27065673c
5 changed files with 146 additions and 61 deletions

View File

@@ -37,23 +37,23 @@ VideoLayoutParser::VideoLayoutParser (QList<MeterWidget*>* metersWidget, QList<Q
void VideoLayoutParser::SetDefaultValues()
{
if (meterWidget)
{
meterWidget->m_RelativeWidth = 20.0;
meterWidget->m_RelativeHeight = 20.0;
meterWidget->m_RelativePosX = 50.0;
meterWidget->m_RelativePosY = 80.0;
meterWidget->m_RangeMin = 0.0;
meterWidget->m_RangeMax = 80.0;
meterWidget->m_MainColor = QColor(255,0,0,200);
meterWidget->m_ScaleColor = QColor(255,255,255,200);
meterWidget->m_OutlineColor = QColor(100,100,100,200);
meterWidget->m_BackgroundColor = QColor(100,100,100,0);
meterWidget->m_MainFont = QFont(meterWidget->font().family(), 64);
meterWidget->m_AltFont = QFont(meterWidget->font().family(), 48);
meterWidget->m_VideoContainer = VideoContainer;
}
meterWidget->m_RelativeWidth = 20.0;
meterWidget->m_RelativeHeight = 20.0;
meterWidget->m_RelativePosX = 50.0;
meterWidget->m_RelativePosY = 80.0;
meterWidget->m_RangeMin = 0.0;
meterWidget->m_RangeMax = 80.0;
meterWidget->m_MainColor = QColor(255,0,0,200);
meterWidget->m_ScaleColor = QColor(255,255,255,200);
meterWidget->m_OutlineColor = QColor(100,100,100,200);
meterWidget->m_BackgroundColor = QColor(100,100,100,0);
meterWidget->m_BoundingRectColor = QColor(150,150,150,100);
meterWidget->m_MainFont = QFont(meterWidget->font().family(), 64);
meterWidget->m_AltFont = QFont(meterWidget->font().family(), 48);
meterWidget->m_VideoContainer = VideoContainer;
meterWidget->Text = "";
meterWidget->AltText = "";
meterWidget->AltTextSuffix = "";
}
QColor GetColorFromFields(const QXmlAttributes& qAttributes)
@@ -77,6 +77,15 @@ bool VideoLayoutParser::startElement( const QString&, const QString&,
const QString& qName,
const QXmlAttributes& qAttributes)
{
QString source;
QString meterName;
QString meterType;
QString container; // will be "Video" when not defined otherwise another meter name (allows positioning of one meter inside another one)
int textWidth;
Qt::Alignment alignment;
bool boundingRectVisibility;
bool backgroundVisibility;
if(skipLayout) return true;
buffer.clear();
@@ -114,6 +123,32 @@ bool VideoLayoutParser::startElement( const QString&, const QString&,
else
meterType = QString("Text");
i = qAttributes.index("alignment");
if(i >= 0)
if(qAttributes.value(i) == QString("AlignLeft")) alignment = Qt::AlignLeft;
else if(qAttributes.value(i) == QString("AlignRight")) alignment = Qt::AlignRight;
else alignment = Qt::AlignHCenter;
else
alignment = Qt::AlignHCenter;
i = qAttributes.index("textWidth");
if(i >= 0)
textWidth = qAttributes.value(i).toInt();
else
textWidth = 0;
i = qAttributes.index("BoundingRect");
if(i >= 0 && qAttributes.value(i) == QString("true"))
boundingRectVisibility = true;
else
boundingRectVisibility = false;
i = qAttributes.index("Background");
if(i >= 0 && qAttributes.value(i) == QString("true"))
backgroundVisibility = true;
else
backgroundVisibility = false;
//TODO: allow creation of meter when container will be created later
QWidget* containerWidget = NULL;
if (container == QString("Video"))
@@ -159,7 +194,14 @@ bool VideoLayoutParser::startElement( const QString&, const QString&,
qDebug() << QObject::tr("Error creating meter");
}
SetDefaultValues();
if (meterWidget)
{
SetDefaultValues();
meterWidget->textWidth = textWidth;
meterWidget->alignment = alignment;
meterWidget->boundingRectVisibility = boundingRectVisibility;
meterWidget->backgroundVisibility = backgroundVisibility;
}
}
else if ((qName == "MainColor") && meterWidget)
meterWidget->m_MainColor = GetColorFromFields(qAttributes);
@@ -169,6 +211,8 @@ bool VideoLayoutParser::startElement( const QString&, const QString&,
meterWidget->m_ScaleColor = GetColorFromFields(qAttributes);
else if ((qName == "BackgroundColor") && meterWidget)
meterWidget->m_BackgroundColor = GetColorFromFields(qAttributes);
else if ((qName == "BoundingRectColor") && meterWidget)
meterWidget->m_BoundingRectColor = GetColorFromFields(qAttributes);
else if ((qName == "RelativeSize") && meterWidget)
{
@@ -204,6 +248,8 @@ bool VideoLayoutParser::startElement( const QString&, const QString&,
if ((i = qAttributes.index("Size")) >= 0)
FontSize = qAttributes.value(i).toInt();
meterWidget->m_MainFont = QFont(FontName, FontSize);
// Set fixed width, otherwise the meter digits keep moving sideways from a thin "1" to a fat "5"
meterWidget->m_MainFont.setFixedPitch(true);
}
else if ((qName == "AltFont") && meterWidget)
{
@@ -215,6 +261,11 @@ bool VideoLayoutParser::startElement( const QString&, const QString&,
if ((i = qAttributes.index("Size")) >= 0)
FontSize = qAttributes.value(i).toInt();
meterWidget->m_AltFont = QFont(FontName, FontSize);
meterWidget->m_AltFont.setFixedPitch(true);
}
else if(qName != "layouts" && qName != "Text" && qName != "AltText" && qName != "Angle" && qName != "SubRange")
{
qDebug() << QObject::tr("Unknown start element ") << qName;
}
return true;
@@ -241,6 +292,8 @@ bool VideoLayoutParser::endElement( const QString&, const QString&, const QStrin
meterWidget->m_Zoom = buffer.toInt();
else if (qName == "Text")
meterWidget->Text = QString(buffer);
else if (qName == "AltText")
meterWidget->AltTextSuffix = QString(buffer);
else if (qName == "meter")
{