QList<QByteArray> QMacPasteboardMimePict::convertFromMime(const QString &mime, QVariant variant, QString flav) { QList<QByteArray> ret; if (!resolveMimeQuickTimeSymbols()) return ret; if (!canConvert(mime, flav)) return ret; QCFType<CGImageRef> cgimage = qt_mac_createCGImageFromQImage(qvariant_cast<QImage>(variant)); Handle pic = NewHandle(0); GraphicsExportComponent graphicsExporter; ComponentResult result = OpenADefaultComponent(GraphicsExporterComponentType, kQTFileTypePicture, &graphicsExporter); if (!result) { unsigned long sizeWritten; result = ptrGraphicsExportSetInputCGImage(graphicsExporter, cgimage); if (!result) result = ptrGraphicsExportSetOutputHandle(graphicsExporter, pic); if (!result) result = ptrGraphicsExportDoExport(graphicsExporter, &sizeWritten); CloseComponent(graphicsExporter); } int size = GetHandleSize((Handle)pic); // Skip the Picture File header (512 bytes) and feed the raw data QByteArray ar(reinterpret_cast<char *>(*pic + 512), size - 512); ret.append(ar); DisposeHandle(pic); return ret; }
QVariant QMacPasteboardMimePict::convertToMime(const QString &mime, QList<QByteArray> data, QString flav) { if(data.count() > 1) qWarning("QMacPasteboardMimePict: Cannot handle multiple member data"); QVariant ret; if (!resolveMimeQuickTimeSymbols()) return ret; if(!canConvert(mime, flav)) return ret; const QByteArray &a = data.first(); // This function expects the 512 header (just to skip it, so create the extra space for it). Handle pic = NewHandle(a.size() + 512); memcpy(*pic + 512, a.constData(), a.size()); GraphicsImportComponent graphicsImporter; ComponentResult result = OpenADefaultComponent(GraphicsImporterComponentType, kQTFileTypePicture, &graphicsImporter); QCFType<CGImageRef> cgImage; if (!result) result = ptrGraphicsImportSetDataHandle(graphicsImporter, pic); if (!result) result = ptrGraphicsImportCreateCGImage(graphicsImporter, &cgImage, kGraphicsImportCreateCGImageUsingCurrentSettings); if (!result) ret = QVariant(QPixmap::fromMacCGImageRef(cgImage).toImage()); CloseComponent(graphicsImporter); DisposeHandle(pic); return ret; }
QList<QByteArray> QMacPasteboardMimeHTMLText::convertFromMime(const QString &mime, QVariant data, QString flavor) { QList<QByteArray> ret; if (!canConvert(mime, flavor)) return ret; ret.append(data.toByteArray()); return ret; }
QVariant QMacPasteboardMimeHTMLText::convertToMime(const QString &mimeType, QList<QByteArray> data, QString flavor) { if (!canConvert(mimeType, flavor)) return QVariant(); if (data.count() > 1) qWarning("QMacPasteboardMimeHTMLText: Cannot handle multiple member data"); return data.first(); }
bool PropertyConverterManager::registerObject(PropertyConverter *converter) { std::string src = converter->getSourcePropertyClassIdenetifier(); std::string dst = converter->getDestinationPropertyClassIdenetifier(); if (canConvert(src, dst)) { LogWarn("Property Converter from type " << src << " to type " << dst << " already registered"); return false; } converters_.insert(std::make_pair(std::make_pair(src, dst), converter)); return true; }
void ModelOverlay::setProperties(const QVariantMap& properties) { auto origPosition = getWorldPosition(); auto origRotation = getWorldOrientation(); auto origDimensions = getDimensions(); auto origScale = getSNScale(); Base3DOverlay::setProperties(properties); auto scale = properties["scale"]; if (scale.isValid()) { setSNScale(vec3FromVariant(scale)); } auto dimensions = properties["dimensions"]; if (!dimensions.isValid()) { dimensions = properties["size"]; } if (dimensions.isValid()) { _scaleToFit = true; setDimensions(vec3FromVariant(dimensions)); } else if (scale.isValid()) { // if "scale" property is set but "dimensions" is not. // do NOT scale to fit. _scaleToFit = false; } if (origPosition != getWorldPosition() || origRotation != getWorldOrientation() || origDimensions != getDimensions() || origScale != getSNScale()) { _updateModel = true; } auto loadPriorityProperty = properties["loadPriority"]; if (loadPriorityProperty.isValid()) { _loadPriority = loadPriorityProperty.toFloat(); _model->setLoadingPriority(_loadPriority); } auto urlValue = properties["url"]; if (urlValue.isValid() && urlValue.canConvert<QString>()) { _url = urlValue.toString(); _updateModel = true; _isLoaded = false; _texturesLoaded = false; } auto texturesValue = properties["textures"]; if (texturesValue.isValid() && texturesValue.canConvert(QVariant::Map)) { _texturesLoaded = false; QVariantMap textureMap = texturesValue.toMap(); QMetaObject::invokeMethod(_model.get(), "setTextures", Qt::AutoConnection, Q_ARG(const QVariantMap&, textureMap)); }
QVariant QMacPasteboardMimeFileUri::convertToMime(const QString &mime, QList<QByteArray> data, QString flav) { if(!canConvert(mime, flav)) return QVariant(); QList<QVariant> ret; for(int i = 0; i < data.size(); ++i) { QUrl url = QUrl::fromEncoded(data.at(i)); if (url.host().toLower() == QLatin1String("localhost")) url.setHost(QString()); url.setPath(url.path().normalized(QString::NormalizationForm_C)); ret.append(url); } return QVariant(ret); }
void ModelOverlay::setProperties(const QVariantMap& properties) { auto origPosition = getPosition(); auto origRotation = getRotation(); auto origDimensions = getDimensions(); auto origScale = getScale(); Base3DOverlay::setProperties(properties); auto scale = properties["scale"]; if (scale.isValid()) { setScale(vec3FromVariant(scale)); } auto dimensions = properties["dimensions"]; if (dimensions.isValid()) { _scaleToFit = true; setDimensions(vec3FromVariant(dimensions)); } else if (scale.isValid()) { // if "scale" property is set but "dimentions" is not. // do NOT scale to fit. _scaleToFit = false; } if (origPosition != getPosition() || origRotation != getRotation() || origDimensions != getDimensions() || origScale != getScale()) { _updateModel = true; } auto urlValue = properties["url"]; if (urlValue.isValid() && urlValue.canConvert<QString>()) { _url = urlValue.toString(); _updateModel = true; _isLoaded = false; } auto texturesValue = properties["textures"]; if (texturesValue.isValid() && texturesValue.canConvert(QVariant::Map)) { QVariantMap textureMap = texturesValue.toMap(); foreach(const QString& key, textureMap.keys()) { QUrl newTextureURL = textureMap[key].toUrl(); qDebug() << "Updating texture named" << key << "to texture at URL" << newTextureURL; QMetaObject::invokeMethod(_model.get(), "setTextureWithNameToURL", Qt::AutoConnection, Q_ARG(const QString&, key), Q_ARG(const QUrl&, newTextureURL)); _modelTextures[key] = newTextureURL; // Keep local track of textures for getProperty() } }
QVariant RTF::Converter::convertToMime(const QString &mime, QList<QByteArray> data, QString flavor) { if (!canConvert(mime, flavor)) { return QVariant(); } // Parse RTF RTF::Reader reader; QTextDocument document; int count = data.count(); for (int i = 0; i < count; ++i) { QBuffer buffer(&data[i]); buffer.open(QIODevice::ReadOnly); reader.read(&buffer, &document); } // Convert to HTML return document.toHtml(); }
QList<QByteArray> QMacPasteboardMimeFileUri::convertFromMime(const QString &mime, QVariant data, QString flav) { QList<QByteArray> ret; if (!canConvert(mime, flav)) return ret; QList<QVariant> urls = data.toList(); for(int i = 0; i < urls.size(); ++i) { QUrl url = urls.at(i).toUrl(); if (url.scheme().isEmpty()) url.setScheme(QLatin1String("file")); if (url.scheme().toLower() == QLatin1String("file")) { if (url.host().isEmpty()) url.setHost(QLatin1String("localhost")); url.setPath(url.path().normalized(QString::NormalizationForm_D)); } ret.append(url.toEncoded()); } return ret; }
QVariant QMacPasteboardMimeTiff::convertToMime(const QString &mime, QList<QByteArray> data, QString flav) { if(data.count() > 1) qWarning("QMacPasteboardMimeTiff: Cannot handle multiple member data"); QVariant ret; if (!canConvert(mime, flav)) return ret; const QByteArray &a = data.first(); QCFType<CGImageRef> image; #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4 if (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_4) { QCFType<CFDataRef> data = CFDataCreateWithBytesNoCopy(0, reinterpret_cast<const UInt8 *>(a.constData()), a.size(), kCFAllocatorNull); QCFType<CGImageSourceRef> imageSource = CGImageSourceCreateWithData(data, 0); image = CGImageSourceCreateImageAtIndex(imageSource, 0, 0); } else #endif { #ifdef Q_WS_MAC32 if (resolveMimeQuickTimeSymbols()) { Handle tiff = NewHandle(a.size()); memcpy(*tiff, a.constData(), a.size()); GraphicsImportComponent graphicsImporter; ComponentResult result = OpenADefaultComponent(GraphicsImporterComponentType, kQTFileTypeTIFF, &graphicsImporter); if (!result) result = ptrGraphicsImportSetDataHandle(graphicsImporter, tiff); if (!result) result = ptrGraphicsImportCreateCGImage(graphicsImporter, &image, kGraphicsImportCreateCGImageUsingCurrentSettings); CloseComponent(graphicsImporter); DisposeHandle(tiff); } #endif } if (image != 0) ret = QVariant(QPixmap::fromMacCGImageRef(image).toImage()); return ret; }
QList<QByteArray> RTF::Converter::convertFromMime(const QString &mime, QVariant data, QString flavor) { QList<QByteArray> result; if (!canConvert(mime, flavor)) { return result; } // Parse HTML QTextDocument document; document.setHtml(data.toString()); // Convert to RTF QByteArray rtf; QBuffer buffer(&rtf); buffer.open(QIODevice::WriteOnly); RTF::Writer writer; writer.write(&buffer, &document); result.append(rtf); return result; }
IScaObject *ScaObjectConverter::convert(IScaObject *obj, IScaObject::IScaObjectType toType) { if (!canConvert(obj->getType(), toType)) { return NULL; } switch (obj->getType()) { case IScaObject::IDENTIFIER: { IScaObjectIdentifier *object = static_cast<IScaObjectIdentifier *>(obj); switch (toType) { case IScaObject::TEXTBLOCK: return makeTextBlockFromIdentifier(object); default: //Conversion can't be done return NULL; } } case IScaObject::TEXTBLOCK: { IScaObjectTextBlock *object = static_cast<IScaObjectTextBlock *>(obj); switch (toType) { case IScaObject::IDENTIFIER: return makeIdentifierFromBlock(object); default: //Conversion can't be done return NULL; } } default: //Conversion can't be done return NULL; } }
bool QDeclarativePropertyPrivate::write(QObject *object, const QDeclarativePropertyCache::Data &property, const QVariant &value, QDeclarativeContextData *context, WriteFlags flags) { int coreIdx = property.coreIndex; int status = -1; //for dbus if (property.flags & QDeclarativePropertyCache::Data::IsEnumType) { QMetaProperty prop = object->metaObject()->property(property.coreIndex); QVariant v = value; // Enum values come through the script engine as doubles if (value.userType() == QVariant::Double) { double integral; double fractional = modf(value.toDouble(), &integral); if (qFuzzyIsNull(fractional)) v.convert(QVariant::Int); } return writeEnumProperty(prop, coreIdx, object, v, flags); } int propertyType = property.propType; int variantType = value.userType(); QDeclarativeEnginePrivate *enginePriv = QDeclarativeEnginePrivate::get(context); if (propertyType == QVariant::Url) { QUrl u; bool found = false; if (variantType == QVariant::Url) { u = value.toUrl(); found = true; } else if (variantType == QVariant::ByteArray) { u = QUrl(QString::fromUtf8(value.toByteArray())); found = true; } else if (variantType == QVariant::String) { u = QUrl(value.toString()); found = true; } if (!found) return false; if (context && u.isRelative() && !u.isEmpty()) u = context->resolvedUrl(u); int status = -1; void *argv[] = { &u, 0, &status, &flags }; QMetaObject::metacall(object, QMetaObject::WriteProperty, coreIdx, argv); } else if (variantType == propertyType) { void *a[] = { (void *)value.constData(), 0, &status, &flags }; QMetaObject::metacall(object, QMetaObject::WriteProperty, coreIdx, a); } else if (qMetaTypeId<QVariant>() == propertyType) { void *a[] = { (void *)&value, 0, &status, &flags }; QMetaObject::metacall(object, QMetaObject::WriteProperty, coreIdx, a); } else if (property.flags & QDeclarativePropertyCache::Data::IsQObjectDerived) { const QMetaObject *valMo = rawMetaObjectForType(enginePriv, value.userType()); if (!valMo) return false; QObject *o = *(QObject **)value.constData(); const QMetaObject *propMo = rawMetaObjectForType(enginePriv, propertyType); if (o) valMo = o->metaObject(); if (canConvert(valMo, propMo)) { void *args[] = { &o, 0, &status, &flags }; QMetaObject::metacall(object, QMetaObject::WriteProperty, coreIdx, args); } else if (!o && canConvert(propMo, valMo)) { // In the case of a null QObject, we assign the null if there is // any change that the null variant type could be up or down cast to // the property type. void *args[] = { &o, 0, &status, &flags }; QMetaObject::metacall(object, QMetaObject::WriteProperty, coreIdx, args); } else { return false; } } else if (property.flags & QDeclarativePropertyCache::Data::IsQList) { const QMetaObject *listType = 0; if (enginePriv) { listType = enginePriv->rawMetaObjectForType(enginePriv->listType(property.propType)); } else { QDeclarativeType *type = QDeclarativeMetaType::qmlType(QDeclarativeMetaType::listType(property.propType)); if (!type) return false; listType = type->baseMetaObject(); } if (!listType) return false; QDeclarativeListProperty<void> prop; void *args[] = { &prop, 0 }; QMetaObject::metacall(object, QMetaObject::ReadProperty, coreIdx, args); if (!prop.clear) return false; prop.clear(&prop); if (value.userType() == qMetaTypeId<QList<QObject *> >()) { const QList<QObject *> &list = qvariant_cast<QList<QObject *> >(value); for (int ii = 0; ii < list.count(); ++ii) { QObject *o = list.at(ii); if (o && !canConvert(o->metaObject(), listType)) o = 0; prop.append(&prop, (void *)o); } } else { QObject *o = enginePriv?enginePriv->toQObject(value):QDeclarativeMetaType::toQObject(value); if (o && !canConvert(o->metaObject(), listType)) o = 0; prop.append(&prop, (void *)o); } } else { Q_ASSERT(variantType != propertyType); QVariant v = value; if (v.convert((QVariant::Type)propertyType)) { void *a[] = { (void *)v.constData(), 0, &status, &flags}; QMetaObject::metacall(object, QMetaObject::WriteProperty, coreIdx, a); } else if ((uint)propertyType >= QVariant::UserType && variantType == QVariant::String) { QDeclarativeMetaType::StringConverter con = QDeclarativeMetaType::customStringConverter(propertyType); if (!con) return false; QVariant v = con(value.toString()); if (v.userType() == propertyType) { void *a[] = { (void *)v.constData(), 0, &status, &flags}; QMetaObject::metacall(object, QMetaObject::WriteProperty, coreIdx, a); } } else if (variantType == QVariant::String) { bool ok = false; QVariant v = QDeclarativeStringConverters::variantFromString(value.toString(), propertyType, &ok); if (!ok) return false; void *a[] = { (void *)v.constData(), 0, &status, &flags}; QMetaObject::metacall(object, QMetaObject::WriteProperty, coreIdx, a); } else { return false; } } return true; }
bool ScaObjectConverter::canConvert(IScaObject *obj, IScaObject::IScaObjectType toType) { return canConvert(obj->getType(), toType); }
QList<QByteArray> QMacPasteboardMimeTiff::convertFromMime(const QString &mime, QVariant variant, QString flav) { QList<QByteArray> ret; if (!canConvert(mime, flav)) return ret; QImage img = qvariant_cast<QImage>(variant); QCFType<CGImageRef> cgimage = qt_mac_createCGImageFromQImage(img); #if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4) if (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_4) { QCFType<CFMutableDataRef> data = CFDataCreateMutable(0, 0); QCFType<CGImageDestinationRef> imageDestination = CGImageDestinationCreateWithData(data, kUTTypeTIFF, 1, 0); if (imageDestination != 0) { CFTypeRef keys[2]; QCFType<CFTypeRef> values[2]; QCFType<CFDictionaryRef> options; keys[0] = kCGImagePropertyPixelWidth; keys[1] = kCGImagePropertyPixelHeight; int width = img.width(); int height = img.height(); values[0] = CFNumberCreate(0, kCFNumberIntType, &width); values[1] = CFNumberCreate(0, kCFNumberIntType, &height); options = CFDictionaryCreate(0, reinterpret_cast<const void **>(keys), reinterpret_cast<const void **>(values), 2, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); CGImageDestinationAddImage(imageDestination, cgimage, options); CGImageDestinationFinalize(imageDestination); } QByteArray ar(CFDataGetLength(data), 0); CFDataGetBytes(data, CFRangeMake(0, ar.size()), reinterpret_cast<UInt8 *>(ar.data())); ret.append(ar); } else #endif { #ifdef Q_WS_MAC32 Handle tiff = NewHandle(0); if (resolveMimeQuickTimeSymbols()) { GraphicsExportComponent graphicsExporter; ComponentResult result = OpenADefaultComponent(GraphicsExporterComponentType, kQTFileTypeTIFF, &graphicsExporter); if (!result) { unsigned long sizeWritten; result = ptrGraphicsExportSetInputCGImage(graphicsExporter, cgimage); if (!result) result = ptrGraphicsExportSetOutputHandle(graphicsExporter, tiff); if (!result) result = ptrGraphicsExportDoExport(graphicsExporter, &sizeWritten); CloseComponent(graphicsExporter); } } int size = GetHandleSize((Handle)tiff); QByteArray ar(reinterpret_cast<char *>(*tiff), size); ret.append(ar); DisposeHandle(tiff); #endif } return ret; }