9#include <qdesigner_utils_p.h>
11#include <QtCore/qcoreapplication.h>
12#include <QtCore/qvariant.h>
13#include <QtCore/qstring.h>
14#include <QtCore/qdebug.h>
15#include <QtCore/qfile.h>
16#include <QtCore/qtextstream.h>
17#include <QtCore/qxmlstream.h>
23using namespace Qt::StringLiterals;
27 using DisambiguatedTranslation =
std::pair<
const char *,
const char *>;
30 QT_TRANSLATE_NOOP(
"FontPropertyManager",
"PreferDefault"),
31 QT_TRANSLATE_NOOP(
"FontPropertyManager",
"NoAntialias"),
32 QT_TRANSLATE_NOOP(
"FontPropertyManager",
"PreferAntialias")
36 QT_TRANSLATE_NOOP3(
"FontPropertyManager",
"PreferDefaultHinting",
"QFont::StyleStrategy combo"),
37 QT_TRANSLATE_NOOP3(
"FontPropertyManager",
"PreferNoHinting",
"QFont::StyleStrategy combo"),
38 QT_TRANSLATE_NOOP3(
"FontPropertyManager",
"PreferVerticalHinting",
"QFont::StyleStrategy combo"),
39 QT_TRANSLATE_NOOP3(
"FontPropertyManager",
"PreferFullHinting",
"QFont::StyleStrategy combo")
44 for (
const auto *a : aliasingC)
45 m_aliasingEnumNames.append(QCoreApplication::translate(
"FontPropertyManager", a));
47 for (
const auto &h : hintingPreferenceC)
48 m_hintingPreferenceEnumNames.append(QCoreApplication::translate(
"FontPropertyManager", h.first, h.second));
51 if (!readFamilyMapping(&m_familyMappings, &errorMessage)) {
52 designerWarning(errorMessage);
61 if (m_createdFontProperty) {
62 auto it = m_propertyToFontSubProperties.find(m_createdFontProperty);
63 if (it == m_propertyToFontSubProperties.end())
64 it = m_propertyToFontSubProperties.insert(m_createdFontProperty, PropertyList());
65 const int index = it.value().size();
66 m_fontSubPropertyToFlag.insert(property, index);
67 it.value().push_back(property);
68 m_fontSubPropertyToProperty[property] = m_createdFontProperty;
69 resetMap[property] =
true;
72 if (type == QMetaType::QFont)
73 m_createdFontProperty = property;
82 const auto ncend = nm.constEnd();
83 for (
auto it = families.begin(), end = families.end(); it != end; ++it) {
84 const auto nit = nm.constFind(*it);
96 if (type != QMetaType::QFont)
100 QtVariantProperty *antialiasing = vm->addProperty(enumTypeId, QCoreApplication::translate(
"FontPropertyManager",
"Antialiasing"));
101 const QFont font = qvariant_cast<QFont>(vm->variantProperty(property)->value());
103 antialiasing->setAttribute(u"enumNames"_s, m_aliasingEnumNames);
104 antialiasing->setValue(antialiasingToIndex(font.styleStrategy()));
107 m_propertyToAntialiasing[property] = antialiasing;
108 m_antialiasingToProperty[antialiasing] = property;
110 QtVariantProperty *hintingPreference = vm->addProperty(enumTypeId, QCoreApplication::translate(
"FontPropertyManager",
"HintingPreference"));
111 hintingPreference->setAttribute(u"enumNames"_s, m_hintingPreferenceEnumNames);
112 hintingPreference->setValue(hintingPreferenceToIndex(font.hintingPreference()));
115 m_propertyToHintingPreference[property] = hintingPreference;
116 m_hintingPreferenceToProperty[hintingPreference] = property;
119 if (!m_familyMappings.isEmpty()) {
120 const auto it = m_propertyToFontSubProperties.find(m_createdFontProperty);
122 const QString enumNamesAttribute = u"enumNames"_s;
123 QStringList plainFamilyNames = familyProperty->attributeValue(enumNamesAttribute).toStringList();
125 if (m_designerFamilyNames.size() != plainFamilyNames.size())
126 m_designerFamilyNames = designerFamilyNames(plainFamilyNames, m_familyMappings);
127 familyProperty->setAttribute(enumNamesAttribute, m_designerFamilyNames);
130 m_createdFontProperty =
nullptr;
135 const auto ait = m_propertyToAntialiasing.find(property);
136 if (ait != m_propertyToAntialiasing.end()) {
138 m_antialiasingToProperty.remove(antialiasing);
139 m_propertyToAntialiasing.erase(ait);
143 const auto hit = m_propertyToHintingPreference.find(property);
144 if (hit != m_propertyToHintingPreference.end()) {
146 m_hintingPreferenceToProperty.remove(hintingPreference);
147 m_propertyToHintingPreference.erase(hit);
148 delete hintingPreference;
151 const auto sit = m_propertyToFontSubProperties.find(property);
152 if (sit == m_propertyToFontSubProperties.end())
155 m_propertyToFontSubProperties.erase(sit);
156 m_fontSubPropertyToFlag.remove(property);
157 m_fontSubPropertyToProperty.remove(property);
164 removeAntialiasingProperty(property);
165 removeHintingPreferenceProperty(property);
170 const auto ait = m_antialiasingToProperty.find(property);
171 if (ait == m_antialiasingToProperty.end())
173 m_propertyToAntialiasing[ait.value()] = 0;
174 m_antialiasingToProperty.erase(ait);
179 const auto hit = m_hintingPreferenceToProperty.find(property);
180 if (hit == m_hintingPreferenceToProperty.end())
182 m_propertyToHintingPreference[hit.value()] =
nullptr;
183 m_hintingPreferenceToProperty.erase(hit);
188 const auto it = m_fontSubPropertyToProperty.find(property);
189 if (it == m_fontSubPropertyToProperty.end())
194 QVariant v = fontProperty->value();
195 QFont font = qvariant_cast<QFont>(v);
196 unsigned mask = font.resolveMask();
197 const unsigned flag = fontFlag(m_fontSubPropertyToFlag.value(property));
200 font.setResolveMask(mask);
202 fontProperty->setValue(v);
209 case QFont::PreferDefault:
return 0;
210 case QFont::NoAntialias:
return 1;
211 case QFont::PreferAntialias:
return 2;
220 case 0:
return QFont::PreferDefault;
221 case 1:
return QFont::NoAntialias;
222 case 2:
return QFont::PreferAntialias;
224 return QFont::PreferDefault;
230 case QFont::PreferDefaultHinting:
232 case QFont::PreferNoHinting:
234 case QFont::PreferVerticalHinting:
236 case QFont::PreferFullHinting:
246 return QFont::PreferDefaultHinting;
248 return QFont::PreferNoHinting;
250 return QFont::PreferVerticalHinting;
252 return QFont::PreferFullHinting;
254 return QFont::PreferDefaultHinting;
261 return QFont::FamilyResolved | QFont::FamiliesResolved;
263 return QFont::SizeResolved;
266 return QFont::WeightResolved;
268 return QFont::StyleResolved;
270 return QFont::UnderlineResolved;
272 return QFont::StrikeOutResolved;
274 return QFont::KerningResolved;
276 return QFont::StyleStrategyResolved;
278 return QFont::HintingPreferenceResolved;
285 if (
auto *antialiasingProperty = m_antialiasingToProperty.value(property,
nullptr))
286 return antialiasingValueChanged(vm, antialiasingProperty, value);
288 if (
auto *hintingPreferenceProperty = m_hintingPreferenceToProperty.value(property,
nullptr))
289 return hintingPreferenceValueChanged(vm, hintingPreferenceProperty, value);
291 if (m_propertyToFontSubProperties.contains(property))
292 updateModifiedState(property, value);
294 return DesignerPropertyManager::NoMatch;
299 const QVariant &value)
302 const QFont::StyleStrategy newValue = indexToAntialiasing(value.toInt());
304 QFont font = qvariant_cast<QFont>(fontProperty->value());
305 const QFont::StyleStrategy oldValue = font.styleStrategy();
306 if (newValue == oldValue)
307 return DesignerPropertyManager::Unchanged;
309 font.setStyleStrategy(newValue);
310 fontProperty->setValue(QVariant::fromValue(font));
311 return DesignerPropertyManager::Changed;
316 const QVariant &value)
319 const QFont::HintingPreference newValue = indexToHintingPreference(value.toInt());
321 QFont font = qvariant_cast<QFont>(fontProperty->value());
322 const QFont::HintingPreference oldValue = font.hintingPreference();
323 if (newValue == oldValue)
324 return DesignerPropertyManager::Unchanged;
326 font.setHintingPreference(newValue);
327 fontProperty->setValue(QVariant::fromValue(font));
328 return DesignerPropertyManager::Changed;
333 const auto it = m_propertyToFontSubProperties.find(property);
334 if (it == m_propertyToFontSubProperties.end())
337 const PropertyList &subProperties = it.value();
339 QFont font = qvariant_cast<QFont>(value);
340 const unsigned mask = font.resolveMask();
342 const int count = subProperties.size();
343 for (
int index = 0; index < count; index++) {
344 const unsigned flag = fontFlag(index);
345 subProperties.at(index)->setModified(mask & flag);
351 updateModifiedState(property, value);
353 if (
QtProperty *antialiasingProperty = m_propertyToAntialiasing.value(property, 0)) {
356 QFont font = qvariant_cast<QFont>(value);
357 antialiasing->setValue(antialiasingToIndex(font.styleStrategy()));
361 if (
QtProperty *hintingPreferenceProperty = m_propertyToHintingPreference.value(property,
nullptr)) {
363 QFont font = qvariant_cast<QFont>(value);
364 hintingPreference->setValue(hintingPreferenceToIndex(font.hintingPreference()));
371
372
373
380 static QString
msgXmlError(
const QXmlStreamReader &r,
const QString& fileName)
382 return u"An error has been encountered at line %1 of %2: %3:"_s.arg(r.lineNumber()).arg(fileName, r.errorString());
391 switch (currentStage) {
410 const QString fileName = u":/qt-project.org/propertyeditor/fontmapping.xml"_s;
The QtProperty class encapsulates an instance of a property.
void addSubProperty(QtProperty *property)
Appends the given property to this property's subproperties.
The QtVariantPropertyManager class provides and manages QVariant based properties.
QtVariantProperty * variantProperty(const QtProperty *property) const
Returns the given property converted into a QtVariantProperty.
The QtVariantProperty class is a convenience class handling QVariant based properties.
bool resetFontSubProperty(QtVariantPropertyManager *vm, QtProperty *subProperty)
void setValue(QtVariantPropertyManager *vm, QtProperty *property, const QVariant &value)
void slotPropertyDestroyed(QtProperty *property)
void postInitializeProperty(QtVariantPropertyManager *vm, QtProperty *property, int type, int enumTypeId)
int valueChanged(QtVariantPropertyManager *vm, QtProperty *property, const QVariant &value)
bool uninitializeProperty(QtProperty *property)
void preInitializeProperty(QtProperty *property, int type, ResetMap &resetMap)
Auxiliary methods to store/retrieve settings.
static QString msgXmlError(const QXmlStreamReader &r, const QString &fileName)
static QStringList designerFamilyNames(QStringList families, const FontPropertyManager::NameMap &nm)
static constexpr auto familyTagC
static const char * aliasingC[]
static constexpr auto rootTagC
static ParseStage nextStage(ParseStage currentStage, QStringView startElement)
static constexpr auto displayTagC
static const DisambiguatedTranslation hintingPreferenceC[]
static constexpr auto mappingTagC