QtnPropertyDelegateEnumFlags::QtnPropertyDelegateEnumFlags(QtnPropertyEnumFlagsBase& owner)
    : QtnPropertyDelegateTypedEx<QtnPropertyEnumFlagsBase>(owner)
{
    const QtnEnumInfo *enumInfo = owner.enumInfo();
    if (enumInfo)
    {
        QtnEnumFlagsValueType value= owner;
        enumInfo->forEachEnumValue([this, &owner, value](const QtnEnumValueInfo& e)->bool {
            if (e.state() == QtnEnumValueStateNone)
            {
                QtnEnumValueType enum_value = e.value();
                QtnPropertyEnumFlagsBase& _owner = owner;

                QtnPropertyBoolCallback *flagProperty = new QtnPropertyBoolCallback(0);
                flagProperty->setName(e.name());
                flagProperty->setDescription(owner.tr("%1 flag for %2.").arg(e.name(), owner.name()));
                flagProperty->setCallbackValueGet([&_owner, enum_value]()->bool {
                    return _owner.value() & enum_value;
                });
                flagProperty->setCallbackValueSet([&_owner, enum_value](bool value) {
                    if (value)
                        _owner.setValue(_owner.value() | enum_value);
                    else
                        _owner.setValue(_owner.value() & ~enum_value);
                });

                this->addSubProperty(flagProperty);
            }

            return true;
        });
    }
}
QtnPropertyDelegateQFont::QtnPropertyDelegateQFont(QtnPropertyQFontBase& owner)
    : QtnPropertyDelegateTypedEx<QtnPropertyQFontBase>(owner)
{
    QtnPropertyQStringCallback* propertyFamily = new QtnPropertyQStringCallback(0);
    addSubProperty(propertyFamily);
    propertyFamily->setName(owner.tr("Family"));
    propertyFamily->setDescription(owner.tr("Font Family for %1.").arg(owner.name()));
    propertyFamily->setCallbackValueGet([&owner]()->QString {
        return owner.value().family();
    });
    propertyFamily->setCallbackValueSet([&owner](QString value) {
        QFont font = owner.value();
        font.setFamily(value);
        owner.setValue(font);
    });
    QtnPropertyDelegateInfo delegate;
    delegate.name = "List";
    QFontDatabase fDB;
    delegate.attributes["items"] = fDB.families();
    propertyFamily->setDelegate(delegate);

    QtnPropertyUIntCallback* propertyPointSize = new QtnPropertyUIntCallback(0);
    addSubProperty(propertyPointSize);
    propertyPointSize->setName(owner.tr("PointSize"));
    propertyPointSize->setDescription(owner.tr("Point size for %1.").arg(owner.name()));
    propertyPointSize->setCallbackValueGet([&owner]()->quint32 {
        int ps = owner.value().pointSize();
        return ps != -1 ? ps : 1;
    });
    propertyPointSize->setCallbackValueSet([&owner](quint32 value) {
        QFont font = owner.value();
        font.setPointSize((int)value);
        owner.setValue(font);
    });
    propertyPointSize->setMinValue(1);
    propertyPointSize->setMaxValue((quint32)std::numeric_limits<int>::max());

    QtnPropertyBoolCallback* propertyBold = new QtnPropertyBoolCallback(0);
    addSubProperty(propertyBold);
    propertyBold->setName(owner.tr("Bold"));
    propertyBold->setDescription(owner.tr("Bold flag for %1").arg(owner.name()));
    propertyBold->setCallbackValueGet([&owner]()->bool {
        return owner.value().bold();
    });
    propertyBold->setCallbackValueSet([&owner](bool value) {
        QFont font = owner.value();
        font.setBold(value);
        owner.setValue(font);
    });

    QtnPropertyBoolCallback* propertyItalic = new QtnPropertyBoolCallback(0);
    addSubProperty(propertyItalic);
    propertyItalic->setName(owner.tr("Italic"));
    propertyItalic->setDescription(owner.tr("Italic flag for %1").arg(owner.name()));
    propertyItalic->setCallbackValueGet([&owner]()->bool {
        return owner.value().italic();
    });
    propertyItalic->setCallbackValueSet([&owner](bool value) {
        QFont font = owner.value();
        font.setItalic(value);
        owner.setValue(font);
    });

    QtnPropertyBoolCallback* propertyUnderline = new QtnPropertyBoolCallback(0);
    addSubProperty(propertyUnderline);
    propertyUnderline->setName(owner.tr("Underline"));
    propertyUnderline->setDescription(owner.tr("Underline flag for %1").arg(owner.name()));
    propertyUnderline->setCallbackValueGet([&owner]()->bool {
        return owner.value().underline();
    });
    propertyUnderline->setCallbackValueSet([&owner](bool value) {
        QFont font = owner.value();
        font.setUnderline(value);
        owner.setValue(font);
    });

    QtnPropertyBoolCallback* propertyStrikeout = new QtnPropertyBoolCallback(0);
    addSubProperty(propertyStrikeout);
    propertyStrikeout->setName(owner.tr("Strikeout"));
    propertyStrikeout->setDescription(owner.tr("Strikeout flag for %1").arg(owner.name()));
    propertyStrikeout->setCallbackValueGet([&owner]()->bool {
        return owner.value().strikeOut();
    });
    propertyStrikeout->setCallbackValueSet([&owner](bool value) {
        QFont font = owner.value();
        font.setStrikeOut(value);
        owner.setValue(font);
    });

    QtnPropertyBoolCallback* propertyKerning = new QtnPropertyBoolCallback(0);
    addSubProperty(propertyKerning);
    propertyKerning->setName(owner.tr("Kerning"));
    propertyKerning->setDescription(owner.tr("Kerning flag for %1").arg(owner.name()));
    propertyKerning->setCallbackValueGet([&owner]()->bool {
        return owner.value().kerning();
    });
    propertyKerning->setCallbackValueSet([&owner](bool value) {
        QFont font = owner.value();
        font.setKerning(value);
        owner.setValue(font);
    });

    QtnPropertyEnumCallback* propertyAntialiasing = new QtnPropertyEnumCallback(0);
    addSubProperty(propertyAntialiasing);
    propertyAntialiasing->setName(owner.tr("Antialiasing"));
    propertyAntialiasing->setDescription(owner.tr("Antialiasing flag for %1.").arg(owner.name()));
    propertyAntialiasing->setEnumInfo(styleStrategyEnum());
    propertyAntialiasing->setCallbackValueGet([&owner]()->QtnEnumValueType {
        return owner.value().styleStrategy();
    });
    propertyAntialiasing->setCallbackValueSet([&owner](QtnEnumValueType value) {
        QFont font = owner.value();
        font.setStyleStrategy((QFont::StyleStrategy)value);
        owner.setValue(font);
    });
}