10#include <qdesigner_utils_p.h>
12#include <QtCore/qcoreapplication.h>
13#include <QtCore/qvariant.h>
14#include <QtCore/qstring.h>
15#include <QtCore/qdebug.h>
16#include <QtCore/qfile.h>
17#include <QtCore/qtextstream.h>
18#include <QtCore/qxmlstream.h>
24using namespace Qt::StringLiterals;
31 QT_TRANSLATE_NOOP(
"FontPropertyManager",
"PreferDefault"),
32 QT_TRANSLATE_NOOP(
"FontPropertyManager",
"NoAntialias"),
33 QT_TRANSLATE_NOOP(
"FontPropertyManager",
"PreferAntialias")
37 QT_TRANSLATE_NOOP3(
"FontPropertyManager",
"PreferDefaultHinting",
"QFont::StyleStrategy combo"),
38 QT_TRANSLATE_NOOP3(
"FontPropertyManager",
"PreferNoHinting",
"QFont::StyleStrategy combo"),
39 QT_TRANSLATE_NOOP3(
"FontPropertyManager",
"PreferVerticalHinting",
"QFont::StyleStrategy combo"),
40 QT_TRANSLATE_NOOP3(
"FontPropertyManager",
"PreferFullHinting",
"QFont::StyleStrategy combo")
45 for (
const auto *a : aliasingC)
46 m_aliasingEnumNames.append(QCoreApplication::translate(
"FontPropertyManager", a));
48 for (
const auto &h : hintingPreferenceC)
49 m_hintingPreferenceEnumNames.append(QCoreApplication::translate(
"FontPropertyManager", h.first, h.second));
52 if (!readFamilyMapping(&m_familyMappings, &errorMessage)) {
53 designerWarning(errorMessage);
62 if (m_createdFontProperty) {
63 auto it = m_propertyToFontSubProperties.find(m_createdFontProperty);
64 if (it == m_propertyToFontSubProperties.end())
65 it = m_propertyToFontSubProperties.insert(m_createdFontProperty, PropertyList());
66 const int index = it.value().size();
67 m_fontSubPropertyToFlag.insert(property, index);
68 it.value().push_back(property);
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);
163 removeAntialiasingProperty(property);
164 removeHintingPreferenceProperty(property);
169 const auto ait = m_antialiasingToProperty.find(property);
170 if (ait == m_antialiasingToProperty.end())
172 m_propertyToAntialiasing[ait.value()] = 0;
173 m_antialiasingToProperty.erase(ait);
178 const auto hit = m_hintingPreferenceToProperty.find(property);
179 if (hit == m_hintingPreferenceToProperty.end())
181 m_propertyToHintingPreference[hit.value()] =
nullptr;
182 m_hintingPreferenceToProperty.erase(hit);
188 if (!m_propertyToFontSubProperties.contains(parentItem))
193 QVariant v = fontProperty->value();
194 QFont font = qvariant_cast<QFont>(v);
195 unsigned mask = font.resolveMask();
196 const unsigned flag = fontFlag(m_fontSubPropertyToFlag.value(property));
199 font.setResolveMask(mask);
201 fontProperty->setValue(v);
208 case QFont::PreferDefault:
return 0;
209 case QFont::NoAntialias:
return 1;
210 case QFont::PreferAntialias:
return 2;
219 case 0:
return QFont::PreferDefault;
220 case 1:
return QFont::NoAntialias;
221 case 2:
return QFont::PreferAntialias;
223 return QFont::PreferDefault;
229 case QFont::PreferDefaultHinting:
231 case QFont::PreferNoHinting:
233 case QFont::PreferVerticalHinting:
235 case QFont::PreferFullHinting:
245 return QFont::PreferDefaultHinting;
247 return QFont::PreferNoHinting;
249 return QFont::PreferVerticalHinting;
251 return QFont::PreferFullHinting;
253 return QFont::PreferDefaultHinting;
260 return QFont::FamilyResolved | QFont::FamiliesResolved;
262 return QFont::SizeResolved;
265 return QFont::WeightResolved;
267 return QFont::StyleResolved;
269 return QFont::UnderlineResolved;
271 return QFont::StrikeOutResolved;
273 return QFont::KerningResolved;
275 return QFont::StyleStrategyResolved;
277 return QFont::HintingPreferenceResolved;
284 if (
auto *antialiasingProperty = m_antialiasingToProperty.value(property,
nullptr))
285 return antialiasingValueChanged(vm, antialiasingProperty, value);
287 if (
auto *hintingPreferenceProperty = m_hintingPreferenceToProperty.value(property,
nullptr))
288 return hintingPreferenceValueChanged(vm, hintingPreferenceProperty, value);
290 if (m_propertyToFontSubProperties.contains(property))
291 updateModifiedState(property, value);
293 return DesignerPropertyManager::NoMatch;
298 const QVariant &value)
301 const QFont::StyleStrategy newValue = indexToAntialiasing(value.toInt());
303 QFont font = qvariant_cast<QFont>(fontProperty->value());
304 const QFont::StyleStrategy oldValue = font.styleStrategy();
305 if (newValue == oldValue)
306 return DesignerPropertyManager::Unchanged;
308 font.setStyleStrategy(newValue);
309 fontProperty->setValue(QVariant::fromValue(font));
310 return DesignerPropertyManager::Changed;
315 const QVariant &value)
318 const QFont::HintingPreference newValue = indexToHintingPreference(value.toInt());
320 QFont font = qvariant_cast<QFont>(fontProperty->value());
321 const QFont::HintingPreference oldValue = font.hintingPreference();
322 if (newValue == oldValue)
323 return DesignerPropertyManager::Unchanged;
325 font.setHintingPreference(newValue);
326 fontProperty->setValue(QVariant::fromValue(font));
327 return DesignerPropertyManager::Changed;
332 const auto it = m_propertyToFontSubProperties.find(property);
333 if (it == m_propertyToFontSubProperties.end())
336 const PropertyList &subProperties = it.value();
338 QFont font = qvariant_cast<QFont>(value);
339 const unsigned mask = font.resolveMask();
341 const int count = subProperties.size();
342 for (
int index = 0; index < count; index++) {
343 const unsigned flag = fontFlag(index);
344 subProperties.at(index)->setModified(mask & flag);
350 updateModifiedState(property, value);
352 if (
QtProperty *antialiasingProperty = m_propertyToAntialiasing.value(property, 0)) {
355 QFont font = qvariant_cast<QFont>(value);
356 antialiasing->setValue(antialiasingToIndex(font.styleStrategy()));
360 if (
QtProperty *hintingPreferenceProperty = m_propertyToHintingPreference.value(property,
nullptr)) {
362 QFont font = qvariant_cast<QFont>(value);
363 hintingPreference->setValue(hintingPreferenceToIndex(font.hintingPreference()));
370
371
372
379 static QString
msgXmlError(
const QXmlStreamReader &r,
const QString& fileName)
381 return u"An error has been encountered at line %1 of %2: %3:"_s.arg(r.lineNumber()).arg(fileName, r.errorString());
390 switch (currentStage) {
409 const QString fileName = u":/qt-project.org/propertyeditor/fontmapping.xml"_s;
The QtProperty class encapsulates an instance of a property.
QtProperty * parentProperty() const
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[]
std::pair< const char *, const char * > DisambiguatedTranslation
static constexpr auto rootTagC
static ParseStage nextStage(ParseStage currentStage, QStringView startElement)
static constexpr auto displayTagC
static const DisambiguatedTranslation hintingPreferenceC[]
static constexpr auto mappingTagC