summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2023-05-23 15:54:01 +0200
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2023-06-07 06:24:21 +0000
commitd0962ccebe3bfd1b59c09e61ddd3c2cce266da2f (patch)
tree8de4def947f23868b96d08bf7fbe1eb5035d9fa9
parent38c0d600471f2743a8e30cf254c53cf66baa7fc5 (diff)
uic: Generate QFont::Weight
Check for the new "fontweight" attribute before "bold". Task-number: QTBUG-113670 Change-Id: Ib34ab5a19872adb3c063861ffbe6b2d3374afcaa Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io> (cherry picked from commit 79436bd34ddf2dc39d42ed9b80a54f4d581c44d9) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r--src/tools/uic/cpp/cppwriteinitialization.cpp28
-rw-r--r--src/tools/uic/ui4.cpp18
-rw-r--r--src/tools/uic/ui4.h9
3 files changed, 44 insertions, 11 deletions
diff --git a/src/tools/uic/cpp/cppwriteinitialization.cpp b/src/tools/uic/cpp/cppwriteinitialization.cpp
index 30cb9a4d58..ec30ce296c 100644
--- a/src/tools/uic/cpp/cppwriteinitialization.cpp
+++ b/src/tools/uic/cpp/cppwriteinitialization.cpp
@@ -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;
diff --git a/src/tools/uic/ui4.cpp b/src/tools/uic/ui4.cpp
index 5c9240a5c9..d65fc4a8c3 100644
--- a/src/tools/uic/ui4.cpp
+++ b/src/tools/uic/ui4.cpp
@@ -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)
diff --git a/src/tools/uic/ui4.h b/src/tools/uic/ui4.h
index 7244d1d59b..333f7f4e6a 100644
--- a/src/tools/uic/ui4.h
+++ b/src/tools/uic/ui4.h
@@ -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
};
};