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;
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 resetMap[property] =
true;
71 if (type == QMetaType::QFont)
72 m_createdFontProperty = property;
81 const auto ncend = nm.constEnd();
82 for (
auto it = families.begin(), end = families.end(); it != end; ++it) {
83 const auto nit = nm.constFind(*it);
95 if (type != QMetaType::QFont)
99 QtVariantProperty *antialiasing = vm->addProperty(enumTypeId, QCoreApplication::translate(
"FontPropertyManager",
"Antialiasing"));
100 const QFont font = qvariant_cast<QFont>(vm->variantProperty(property)->value());
102 antialiasing->setAttribute(u"enumNames"_s, m_aliasingEnumNames);
103 antialiasing->setValue(antialiasingToIndex(font.styleStrategy()));
106 m_propertyToAntialiasing[property] = antialiasing;
107 m_antialiasingToProperty[antialiasing] = property;
109 QtVariantProperty *hintingPreference = vm->addProperty(enumTypeId, QCoreApplication::translate(
"FontPropertyManager",
"HintingPreference"));
110 hintingPreference->setAttribute(u"enumNames"_s, m_hintingPreferenceEnumNames);
111 hintingPreference->setValue(hintingPreferenceToIndex(font.hintingPreference()));
114 m_propertyToHintingPreference[property] = hintingPreference;
115 m_hintingPreferenceToProperty[hintingPreference] = property;
118 if (!m_familyMappings.isEmpty()) {
119 const auto it = m_propertyToFontSubProperties.find(m_createdFontProperty);
121 const QString enumNamesAttribute = u"enumNames"_s;
122 QStringList plainFamilyNames = familyProperty->attributeValue(enumNamesAttribute).toStringList();
124 if (m_designerFamilyNames.size() != plainFamilyNames.size())
125 m_designerFamilyNames = designerFamilyNames(plainFamilyNames, m_familyMappings);
126 familyProperty->setAttribute(enumNamesAttribute, m_designerFamilyNames);
129 m_createdFontProperty =
nullptr;
134 const auto ait = m_propertyToAntialiasing.find(property);
135 if (ait != m_propertyToAntialiasing.end()) {
137 m_antialiasingToProperty.remove(antialiasing);
138 m_propertyToAntialiasing.erase(ait);
142 const auto hit = m_propertyToHintingPreference.find(property);
143 if (hit != m_propertyToHintingPreference.end()) {
145 m_hintingPreferenceToProperty.remove(hintingPreference);
146 m_propertyToHintingPreference.erase(hit);
147 delete hintingPreference;
150 const auto sit = m_propertyToFontSubProperties.find(property);
151 if (sit == m_propertyToFontSubProperties.end())
154 m_propertyToFontSubProperties.erase(sit);
155 m_fontSubPropertyToFlag.remove(property);
162 removeAntialiasingProperty(property);
163 removeHintingPreferenceProperty(property);
168 const auto ait = m_antialiasingToProperty.find(property);
169 if (ait == m_antialiasingToProperty.end())
171 m_propertyToAntialiasing[ait.value()] = 0;
172 m_antialiasingToProperty.erase(ait);
177 const auto hit = m_hintingPreferenceToProperty.find(property);
178 if (hit == m_hintingPreferenceToProperty.end())
180 m_propertyToHintingPreference[hit.value()] =
nullptr;
181 m_hintingPreferenceToProperty.erase(hit);
187 if (!m_propertyToFontSubProperties.contains(parentItem))
192 QVariant v = fontProperty->value();
193 QFont font = qvariant_cast<QFont>(v);
194 unsigned mask = font.resolveMask();
195 const unsigned flag = fontFlag(m_fontSubPropertyToFlag.value(property));
198 font.setResolveMask(mask);
200 fontProperty->setValue(v);
207 case QFont::PreferDefault:
return 0;
208 case QFont::NoAntialias:
return 1;
209 case QFont::PreferAntialias:
return 2;
218 case 0:
return QFont::PreferDefault;
219 case 1:
return QFont::NoAntialias;
220 case 2:
return QFont::PreferAntialias;
222 return QFont::PreferDefault;
228 case QFont::PreferDefaultHinting:
230 case QFont::PreferNoHinting:
232 case QFont::PreferVerticalHinting:
234 case QFont::PreferFullHinting:
244 return QFont::PreferDefaultHinting;
246 return QFont::PreferNoHinting;
248 return QFont::PreferVerticalHinting;
250 return QFont::PreferFullHinting;
252 return QFont::PreferDefaultHinting;
259 return QFont::FamilyResolved | QFont::FamiliesResolved;
261 return QFont::SizeResolved;
264 return QFont::WeightResolved;
266 return QFont::StyleResolved;
268 return QFont::UnderlineResolved;
270 return QFont::StrikeOutResolved;
272 return QFont::KerningResolved;
274 return QFont::StyleStrategyResolved;
276 return QFont::HintingPreferenceResolved;
283 if (
auto *antialiasingProperty = m_antialiasingToProperty.value(property,
nullptr))
284 return antialiasingValueChanged(vm, antialiasingProperty, value);
286 if (
auto *hintingPreferenceProperty = m_hintingPreferenceToProperty.value(property,
nullptr))
287 return hintingPreferenceValueChanged(vm, hintingPreferenceProperty, value);
289 if (m_propertyToFontSubProperties.contains(property))
290 updateModifiedState(property, value);
292 return DesignerPropertyManager::NoMatch;
297 const QVariant &value)
300 const QFont::StyleStrategy newValue = indexToAntialiasing(value.toInt());
302 QFont font = qvariant_cast<QFont>(fontProperty->value());
303 const QFont::StyleStrategy oldValue = font.styleStrategy();
304 if (newValue == oldValue)
305 return DesignerPropertyManager::Unchanged;
307 font.setStyleStrategy(newValue);
308 fontProperty->setValue(QVariant::fromValue(font));
309 return DesignerPropertyManager::Changed;
314 const QVariant &value)
317 const QFont::HintingPreference newValue = indexToHintingPreference(value.toInt());
319 QFont font = qvariant_cast<QFont>(fontProperty->value());
320 const QFont::HintingPreference oldValue = font.hintingPreference();
321 if (newValue == oldValue)
322 return DesignerPropertyManager::Unchanged;
324 font.setHintingPreference(newValue);
325 fontProperty->setValue(QVariant::fromValue(font));
326 return DesignerPropertyManager::Changed;
331 const auto it = m_propertyToFontSubProperties.find(property);
332 if (it == m_propertyToFontSubProperties.end())
335 const PropertyList &subProperties = it.value();
337 QFont font = qvariant_cast<QFont>(value);
338 const unsigned mask = font.resolveMask();
340 const int count = subProperties.size();
341 for (
int index = 0; index < count; index++) {
342 const unsigned flag = fontFlag(index);
343 subProperties.at(index)->setModified(mask & flag);
349 updateModifiedState(property, value);
351 if (
QtProperty *antialiasingProperty = m_propertyToAntialiasing.value(property, 0)) {
354 QFont font = qvariant_cast<QFont>(value);
355 antialiasing->setValue(antialiasingToIndex(font.styleStrategy()));
359 if (
QtProperty *hintingPreferenceProperty = m_propertyToHintingPreference.value(property,
nullptr)) {
361 QFont font = qvariant_cast<QFont>(value);
362 hintingPreference->setValue(hintingPreferenceToIndex(font.hintingPreference()));
369
370
371
378 static QString
msgXmlError(
const QXmlStreamReader &r,
const QString& fileName)
380 return u"An error has been encountered at line %1 of %2: %3:"_s.arg(r.lineNumber()).arg(fileName, r.errorString());
389 switch (currentStage) {
408 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