QFont stripStyleName(QFont &f, QFontDatabase &db) { const QString &styleName = f.styleName(); if (styleName.isEmpty()) { return f; } else { QFont g = (db.styleString(f) != styleName) ? db.font(f.family(), styleName, f.pointSize()) : QFont(f.family(), f.pointSize(), f.weight()); if (auto s = f.pixelSize() > 0) { g.setPixelSize(s); } g.setStyleHint(f.styleHint(), f.styleStrategy()); g.setStyle(f.style()); if (f.underline()) { g.setUnderline(true); } if (f.strikeOut()) { g.setStrikeOut(true); } if (f.fixedPitch()) { g.setFixedPitch(true); } return g; } }
void FontPropertyManager::postInitializeProperty(QtVariantPropertyManager *vm, QtProperty *property, int type, int enumTypeId) { if (type != QVariant::Font) return; // This will cause a recursion QtVariantProperty *antialiasing = vm->addProperty(enumTypeId, QCoreApplication::translate("FontPropertyManager", "Antialiasing")); const QFont font = qVariantValue<QFont>(vm->variantProperty(property)->value()); antialiasing->setAttribute(QLatin1String("enumNames"), m_aliasingEnumNames); antialiasing->setValue(antialiasingToIndex(font.styleStrategy())); property->addSubProperty(antialiasing); m_propertyToAntialiasing[property] = antialiasing; m_antialiasingToProperty[antialiasing] = property; // Fiddle family names if (!m_familyMappings.empty()) { const PropertyToSubPropertiesMap::iterator it = m_propertyToFontSubProperties.find(m_createdFontProperty); QtVariantProperty *familyProperty = vm->variantProperty(it.value().front()); const QString enumNamesAttribute = QLatin1String("enumNames"); QStringList plainFamilyNames = familyProperty->attributeValue(enumNamesAttribute).toStringList(); // Did someone load fonts or something? if (m_designerFamilyNames.size() != plainFamilyNames.size()) m_designerFamilyNames = designerFamilyNames(plainFamilyNames, m_familyMappings); familyProperty->setAttribute(enumNamesAttribute, m_designerFamilyNames); } // Next m_createdFontProperty = 0; }
int QFontProto::styleStrategy() const { QFont *item = qscriptvalue_cast<QFont*>(thisObject()); if (item) return item->styleStrategy(); return 0; }
void FontPropertyManager::setValue(QtVariantPropertyManager *vm, QtProperty *property, const QVariant &value) { updateModifiedState(property, value); if (QtProperty *antialiasingProperty = m_propertyToAntialiasing.value(property, 0)) { QtVariantProperty *antialiasing = vm->variantProperty(antialiasingProperty); if (antialiasing) { QFont font = qVariantValue<QFont>(value); antialiasing->setValue(antialiasingToIndex(font.styleStrategy())); } } }
QFont Manager::codeFont() { QString fontFamily = value("IDE/editor/font/family").toString(); int fontSize = value("IDE/editor/font/size").toInt(); bool fontAntialas = value("IDE/editor/font/antialias").toBool(); QFont font = QApplication::font("QPlainTextEdit"); font.setStyleHint(QFont::TypeWriter); font.setFamily(fontFamily); if (fontSize > 0) font.setPointSize(fontSize); if (!fontAntialas) font.setStyleStrategy(QFont::StyleStrategy(font.styleStrategy() | QFont::NoAntialias)); return font; }
void DFont :: FromODataLayout (ODataLayout *pODataLayout ) { QFont *qfont = NULL; QColor *qcolor = NULL; BEGINSEQ if ( !pODataLayout ) LEAVESEQ if ( qfont = pODataLayout->get_font() ) { strcpy(family_name,QS2SZ(qfont->family())); weight = (ADK_FontWeight)qfont->weight(); italic = qfont->italic(); underline = qfont->underline(); strike_out = qfont->strikeOut(); fixed_pitch = qfont->fixedPitch(); style_hint = (ADK_FontStyle)qfont->styleHint(); style_strategy = (ADK_FontStyleStrategy)qfont->styleStrategy(); stretch = qfont->stretch(); } prefer_quality = NO; if ( style_strategy && QFont::PreferQuality ) { prefer_quality = YES; style_strategy = (ADK_FontStyleStrategy)(style_strategy - QFont::PreferQuality); } if ( qcolor = pODataLayout->get_text_color() ) text_color = QCOLOR2DCOLOR(*qcolor); if ( qcolor = pODataLayout->get_bg_color() ) bg_color = QCOLOR2DCOLOR(*qcolor); use_pixel = NO; if ( (size = qfont->pointSize()) == -1 ) // pixel size used { use_pixel = YES; size = qfont->pixelSize(); } ENDSEQ }
FontPropertyManager::ValueChangedResult FontPropertyManager::valueChanged(QtVariantPropertyManager *vm, QtProperty *property, const QVariant &value) { QtProperty *antialiasingProperty = m_antialiasingToProperty.value(property, 0); if (!antialiasingProperty) { if (m_propertyToFontSubProperties.contains(property)) { updateModifiedState(property, value); } return NoMatch; } QtVariantProperty *fontProperty = vm->variantProperty(antialiasingProperty); const QFont::StyleStrategy newValue = indexToAntialiasing(value.toInt()); QFont font = qVariantValue<QFont>(fontProperty->value()); const QFont::StyleStrategy oldValue = font.styleStrategy(); if (newValue == oldValue) return Unchanged; font.setStyleStrategy(newValue); fontProperty->setValue(qVariantFromValue(font)); return Changed; }
// Apply a simple variant type to a DOM property static bool applySimpleProperty(const QVariant &v, bool translateString, DomProperty *dom_prop) { switch (v.type()) { case QVariant::String: { DomString *str = new DomString(); str->setText(v.toString()); if (!translateString) str->setAttributeNotr(QStringLiteral("true")); dom_prop->setElementString(str); } return true; case QVariant::ByteArray: dom_prop->setElementCstring(QString::fromUtf8(v.toByteArray())); return true; case QVariant::Int: dom_prop->setElementNumber(v.toInt()); return true; case QVariant::UInt: dom_prop->setElementUInt(v.toUInt()); return true; case QVariant::LongLong: dom_prop->setElementLongLong(v.toLongLong()); return true; case QVariant::ULongLong: dom_prop->setElementULongLong(v.toULongLong()); return true; case QVariant::Double: dom_prop->setElementDouble(v.toDouble()); return true; case QVariant::Bool: dom_prop->setElementBool(v.toBool() ? QFormBuilderStrings::instance().trueValue : QFormBuilderStrings::instance().falseValue); return true; case QVariant::Char: { DomChar *ch = new DomChar(); const QChar character = v.toChar(); ch->setElementUnicode(character.unicode()); dom_prop->setElementChar(ch); } return true; case QVariant::Point: { DomPoint *pt = new DomPoint(); const QPoint point = v.toPoint(); pt->setElementX(point.x()); pt->setElementY(point.y()); dom_prop->setElementPoint(pt); } return true; case QVariant::PointF: { DomPointF *ptf = new DomPointF(); const QPointF pointf = v.toPointF(); ptf->setElementX(pointf.x()); ptf->setElementY(pointf.y()); dom_prop->setElementPointF(ptf); } return true; case QVariant::Color: { DomColor *clr = new DomColor(); const QColor color = qvariant_cast<QColor>(v); clr->setElementRed(color.red()); clr->setElementGreen(color.green()); clr->setElementBlue(color.blue()); const int alphaChannel = color.alpha(); if (alphaChannel != 255) clr->setAttributeAlpha(alphaChannel); dom_prop->setElementColor(clr); } return true; case QVariant::Size: { DomSize *sz = new DomSize(); const QSize size = v.toSize(); sz->setElementWidth(size.width()); sz->setElementHeight(size.height()); dom_prop->setElementSize(sz); } return true; case QVariant::SizeF: { DomSizeF *szf = new DomSizeF(); const QSizeF sizef = v.toSizeF(); szf->setElementWidth(sizef.width()); szf->setElementHeight(sizef.height()); dom_prop->setElementSizeF(szf); } return true; case QVariant::Rect: { DomRect *rc = new DomRect(); const QRect rect = v.toRect(); rc->setElementX(rect.x()); rc->setElementY(rect.y()); rc->setElementWidth(rect.width()); rc->setElementHeight(rect.height()); dom_prop->setElementRect(rc); } return true; case QVariant::RectF: { DomRectF *rcf = new DomRectF(); const QRectF rectf = v.toRectF(); rcf->setElementX(rectf.x()); rcf->setElementY(rectf.y()); rcf->setElementWidth(rectf.width()); rcf->setElementHeight(rectf.height()); dom_prop->setElementRectF(rcf); } return true; case QVariant::Font: { DomFont *fnt = new DomFont(); const QFont font = qvariant_cast<QFont>(v); const uint mask = font.resolve(); if (mask & QFont::WeightResolved) { fnt->setElementBold(font.bold()); fnt->setElementWeight(font.weight()); } if (mask & QFont::FamilyResolved) fnt->setElementFamily(font.family()); if (mask & QFont::StyleResolved) fnt->setElementItalic(font.italic()); if (mask & QFont::SizeResolved) fnt->setElementPointSize(font.pointSize()); if (mask & QFont::StrikeOutResolved) fnt->setElementStrikeOut(font.strikeOut()); if (mask & QFont::UnderlineResolved) fnt->setElementUnderline(font.underline()); if (mask & QFont::KerningResolved) fnt->setElementKerning(font.kerning()); if (mask & QFont::StyleStrategyResolved) { const QMetaEnum styleStrategy_enum = metaEnum<QAbstractFormBuilderGadget>("styleStrategy"); fnt->setElementStyleStrategy(QLatin1String(styleStrategy_enum.valueToKey(font.styleStrategy()))); } dom_prop->setElementFont(fnt); } return true; #ifndef QT_NO_CURSOR case QVariant::Cursor: { const QMetaEnum cursorShape_enum = metaEnum<QAbstractFormBuilderGadget>("cursorShape"); dom_prop->setElementCursorShape(QLatin1String(cursorShape_enum.valueToKey(qvariant_cast<QCursor>(v).shape()))); } return true; #endif case QVariant::KeySequence: { DomString *s = new DomString(); s->setText(qvariant_cast<QKeySequence>(v).toString(QKeySequence::PortableText)); dom_prop->setElementString(s); } return true; case QVariant::Locale: { DomLocale *dom = new DomLocale(); const QLocale locale = qvariant_cast<QLocale>(v); const QMetaEnum language_enum = metaEnum<QAbstractFormBuilderGadget>("language"); const QMetaEnum country_enum = metaEnum<QAbstractFormBuilderGadget>("country"); dom->setAttributeLanguage(QLatin1String(language_enum.valueToKey(locale.language()))); dom->setAttributeCountry(QLatin1String(country_enum.valueToKey(locale.country()))); dom_prop->setElementLocale(dom); } return true; case QVariant::SizePolicy: { DomSizePolicy *dom = new DomSizePolicy(); const QSizePolicy sizePolicy = qvariant_cast<QSizePolicy>(v); dom->setElementHorStretch(sizePolicy.horizontalStretch()); dom->setElementVerStretch(sizePolicy.verticalStretch()); const QMetaEnum sizeType_enum = metaEnum<QAbstractFormBuilderGadget>("sizeType"); dom->setAttributeHSizeType(QLatin1String(sizeType_enum.valueToKey(sizePolicy.horizontalPolicy()))); dom->setAttributeVSizeType(QLatin1String(sizeType_enum.valueToKey(sizePolicy.verticalPolicy()))); dom_prop->setElementSizePolicy(dom); } return true; case QVariant::Date: { DomDate *dom = new DomDate(); const QDate date = qvariant_cast<QDate>(v); dom->setElementYear(date.year()); dom->setElementMonth(date.month()); dom->setElementDay(date.day()); dom_prop->setElementDate(dom); } return true; case QVariant::Time: { DomTime *dom = new DomTime(); const QTime time = qvariant_cast<QTime>(v); dom->setElementHour(time.hour()); dom->setElementMinute(time.minute()); dom->setElementSecond(time.second()); dom_prop->setElementTime(dom); } return true; case QVariant::DateTime: { DomDateTime *dom = new DomDateTime(); const QDateTime dateTime = qvariant_cast<QDateTime>(v); dom->setElementHour(dateTime.time().hour()); dom->setElementMinute(dateTime.time().minute()); dom->setElementSecond(dateTime.time().second()); dom->setElementYear(dateTime.date().year()); dom->setElementMonth(dateTime.date().month()); dom->setElementDay(dateTime.date().day()); dom_prop->setElementDateTime(dom); } return true; case QVariant::Url: { DomUrl *dom = new DomUrl(); const QUrl url = v.toUrl(); DomString *str = new DomString(); str->setText(url.toString()); dom->setElementString(str); dom_prop->setElementUrl(dom); } return true; case QVariant::StringList: { DomStringList *sl = new DomStringList; sl->setElementString(qvariant_cast<QStringList>(v)); dom_prop->setElementStringList(sl); } return true; default: break; } return false; }
static QFont fontFromObject(QQmlV4Handle object, QV4::ExecutionEngine *v4, bool *ok) { if (ok) *ok = false; QFont retn; QV4::Scope scope(v4); QV4::ScopedObject obj(scope, object); if (!obj) { if (ok) *ok = false; return retn; } QV4::ScopedString s(scope); QV4::ScopedValue vbold(scope, obj->get((s = v4->newString(QStringLiteral("bold"))))); QV4::ScopedValue vcap(scope, obj->get((s = v4->newString(QStringLiteral("capitalization"))))); QV4::ScopedValue vfam(scope, obj->get((s = v4->newString(QStringLiteral("family"))))); QV4::ScopedValue vstyle(scope, obj->get((s = v4->newString(QStringLiteral("styleName"))))); QV4::ScopedValue vital(scope, obj->get((s = v4->newString(QStringLiteral("italic"))))); QV4::ScopedValue vlspac(scope, obj->get((s = v4->newString(QStringLiteral("letterSpacing"))))); QV4::ScopedValue vpixsz(scope, obj->get((s = v4->newString(QStringLiteral("pixelSize"))))); QV4::ScopedValue vpntsz(scope, obj->get((s = v4->newString(QStringLiteral("pointSize"))))); QV4::ScopedValue vstrk(scope, obj->get((s = v4->newString(QStringLiteral("strikeout"))))); QV4::ScopedValue vundl(scope, obj->get((s = v4->newString(QStringLiteral("underline"))))); QV4::ScopedValue vweight(scope, obj->get((s = v4->newString(QStringLiteral("weight"))))); QV4::ScopedValue vwspac(scope, obj->get((s = v4->newString(QStringLiteral("wordSpacing"))))); QV4::ScopedValue vhint(scope, obj->get((s = v4->newString(QStringLiteral("hintingPreference"))))); QV4::ScopedValue vkerning(scope, obj->get((s = v4->newString(QStringLiteral("kerning"))))); QV4::ScopedValue vshaping(scope, obj->get((s = v4->newString(QStringLiteral("preferShaping"))))); // pull out the values, set ok to true if at least one valid field is given. if (vbold->isBoolean()) { retn.setBold(vbold->booleanValue()); if (ok) *ok = true; } if (vcap->isInt32()) { retn.setCapitalization(static_cast<QFont::Capitalization>(vcap->integerValue())); if (ok) *ok = true; } if (vfam->isString()) { retn.setFamily(vfam->toQString()); if (ok) *ok = true; } if (vstyle->isString()) { retn.setStyleName(vstyle->toQString()); if (ok) *ok = true; } if (vital->isBoolean()) { retn.setItalic(vital->booleanValue()); if (ok) *ok = true; } if (vlspac->isNumber()) { retn.setLetterSpacing(QFont::AbsoluteSpacing, vlspac->asDouble()); if (ok) *ok = true; } if (vpixsz->isInt32()) { retn.setPixelSize(vpixsz->integerValue()); if (ok) *ok = true; } if (vpntsz->isNumber()) { retn.setPointSize(vpntsz->asDouble()); if (ok) *ok = true; } if (vstrk->isBoolean()) { retn.setStrikeOut(vstrk->booleanValue()); if (ok) *ok = true; } if (vundl->isBoolean()) { retn.setUnderline(vundl->booleanValue()); if (ok) *ok = true; } if (vweight->isInt32()) { retn.setWeight(static_cast<QFont::Weight>(vweight->integerValue())); if (ok) *ok = true; } if (vwspac->isNumber()) { retn.setWordSpacing(vwspac->asDouble()); if (ok) *ok = true; } if (vhint->isInt32()) { retn.setHintingPreference(static_cast<QFont::HintingPreference>(vhint->integerValue())); if (ok) *ok = true; } if (vkerning->isBoolean()) { retn.setKerning(vkerning->booleanValue()); if (ok) *ok = true; } if (vshaping->isBoolean()) { bool enable = vshaping->booleanValue(); if (enable) retn.setStyleStrategy(static_cast<QFont::StyleStrategy>(retn.styleStrategy() & ~QFont::PreferNoShaping)); else retn.setStyleStrategy(static_cast<QFont::StyleStrategy>(retn.styleStrategy() | QFont::PreferNoShaping)); } return retn; }