uic: Generate QFont::Weight
Check for the new "fontweight" attribute before "bold". Pick-to: 6.6 6.5 Task-number: QTBUG-113670 Change-Id: Ib34ab5a19872adb3c063861ffbe6b2d3374afcaa Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
This commit is contained in:
parent
71bf2a3a32
commit
79436bd34d
@ -180,6 +180,15 @@ FontHandle::FontHandle(const DomFont *domFont) :
|
||||
{
|
||||
}
|
||||
|
||||
static QString fontWeight(const DomFont *domFont)
|
||||
{
|
||||
if (domFont->hasElementFontWeight())
|
||||
return domFont->elementFontWeight();
|
||||
if (domFont->hasElementBold())
|
||||
return domFont->elementBold() ? u"Bold"_s : u"Normal"_s;
|
||||
return {};
|
||||
}
|
||||
|
||||
int FontHandle::compare(const FontHandle &rhs) const
|
||||
{
|
||||
const QString family = m_domFont->hasElementFamily() ? m_domFont->elementFamily() : QString();
|
||||
@ -194,10 +203,10 @@ int FontHandle::compare(const FontHandle &rhs) const
|
||||
if (const int crc = compareInt(pointSize, rhsPointSize))
|
||||
return crc;
|
||||
|
||||
const int bold = m_domFont->hasElementBold() ? (m_domFont->elementBold() ? 1 : 0) : -1;
|
||||
const int rhsBold = rhs.m_domFont->hasElementBold() ? (rhs.m_domFont->elementBold() ? 1 : 0) : -1;
|
||||
if (const int crc = compareInt(bold, rhsBold))
|
||||
return crc;
|
||||
const QString fontWeight = CPP::fontWeight(m_domFont);
|
||||
const QString rhsFontWeight = CPP::fontWeight(rhs.m_domFont);
|
||||
if (const int wrc = fontWeight.compare(rhsFontWeight))
|
||||
return wrc;
|
||||
|
||||
const int italic = m_domFont->hasElementItalic() ? (m_domFont->elementItalic() ? 1 : 0) : -1;
|
||||
const int rhsItalic = rhs.m_domFont->hasElementItalic() ? (rhs.m_domFont->elementItalic() ? 1 : 0) : -1;
|
||||
@ -209,11 +218,6 @@ int FontHandle::compare(const FontHandle &rhs) const
|
||||
if (const int crc = compareInt(underline, rhsUnderline))
|
||||
return crc;
|
||||
|
||||
const int weight = m_domFont->hasElementWeight() ? m_domFont->elementWeight() : -1;
|
||||
const int rhsWeight = rhs.m_domFont->hasElementWeight() ? rhs.m_domFont->elementWeight() : -1;
|
||||
if (const int crc = compareInt(weight, rhsWeight))
|
||||
return crc;
|
||||
|
||||
const int strikeOut = m_domFont->hasElementStrikeOut() ? (m_domFont->elementStrikeOut() ? 1 : 0) : -1;
|
||||
const int rhsStrikeOut = rhs.m_domFont->hasElementStrikeOut() ? (rhs.m_domFont->elementStrikeOut() ? 1 : 0) : -1;
|
||||
if (const int crc = compareInt(strikeOut, rhsStrikeOut))
|
||||
@ -1634,10 +1638,14 @@ QString WriteInitialization::writeFontProperties(const DomFont *f)
|
||||
<< ")" << language::eol;
|
||||
}
|
||||
|
||||
if (f->hasElementBold()) {
|
||||
if (f->hasElementFontWeight()) {
|
||||
m_output << m_indent << fontName << ".setWeight(QFont"
|
||||
<< language::qualifier << f->elementFontWeight() << ')' << language::eol;
|
||||
} else if (f->hasElementBold()) {
|
||||
m_output << m_indent << fontName << ".setBold("
|
||||
<< language::boolValue(f->elementBold()) << ')' << language::eol;
|
||||
}
|
||||
|
||||
if (f->hasElementItalic()) {
|
||||
m_output << m_indent << fontName << ".setItalic("
|
||||
<< language::boolValue(f->elementItalic()) << ')' << language::eol;
|
||||
|
@ -3125,6 +3125,10 @@ void DomFont::read(QXmlStreamReader &reader)
|
||||
setElementHintingPreference(reader.readElementText());
|
||||
continue;
|
||||
}
|
||||
if (!tag.compare(u"fontweight"_s, Qt::CaseInsensitive)) {
|
||||
setElementFontWeight(reader.readElementText());
|
||||
continue;
|
||||
}
|
||||
reader.raiseError("Unexpected element "_L1 + tag);
|
||||
}
|
||||
break;
|
||||
@ -3173,6 +3177,9 @@ void DomFont::write(QXmlStreamWriter &writer, const QString &tagName) const
|
||||
if (m_children & HintingPreference)
|
||||
writer.writeTextElement(u"hintingpreference"_s, m_hintingPreference);
|
||||
|
||||
if (m_children & FontWeight)
|
||||
writer.writeTextElement(u"fontweight"_s, m_fontWeight);
|
||||
|
||||
writer.writeEndElement();
|
||||
}
|
||||
|
||||
@ -3242,6 +3249,12 @@ void DomFont::setElementHintingPreference(const QString &a)
|
||||
m_hintingPreference = a;
|
||||
}
|
||||
|
||||
void DomFont::setElementFontWeight(const QString &a)
|
||||
{
|
||||
m_children |= FontWeight;
|
||||
m_fontWeight = a;
|
||||
}
|
||||
|
||||
void DomFont::clearElementFamily()
|
||||
{
|
||||
m_children &= ~Family;
|
||||
@ -3297,6 +3310,11 @@ void DomFont::clearElementHintingPreference()
|
||||
m_children &= ~HintingPreference;
|
||||
}
|
||||
|
||||
void DomFont::clearElementFontWeight()
|
||||
{
|
||||
m_children &= ~FontWeight;
|
||||
}
|
||||
|
||||
DomPoint::~DomPoint() = default;
|
||||
|
||||
void DomPoint::read(QXmlStreamReader &reader)
|
||||
|
@ -1650,6 +1650,11 @@ public:
|
||||
inline bool hasElementHintingPreference() const { return m_children & HintingPreference; }
|
||||
void clearElementHintingPreference();
|
||||
|
||||
inline QString elementFontWeight() const { return m_fontWeight; }
|
||||
void setElementFontWeight(const QString &a);
|
||||
inline bool hasElementFontWeight() const { return m_children & FontWeight; }
|
||||
void clearElementFontWeight();
|
||||
|
||||
private:
|
||||
|
||||
// child element data
|
||||
@ -1665,6 +1670,7 @@ private:
|
||||
QString m_styleStrategy;
|
||||
bool m_kerning = false;
|
||||
QString m_hintingPreference;
|
||||
QString m_fontWeight;
|
||||
|
||||
enum Child {
|
||||
Family = 1,
|
||||
@ -1677,7 +1683,8 @@ private:
|
||||
Antialiasing = 128,
|
||||
StyleStrategy = 256,
|
||||
Kerning = 512,
|
||||
HintingPreference = 1024
|
||||
HintingPreference = 1024,
|
||||
FontWeight = 2048
|
||||
};
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user