Exemplo n.º 1
0
QDomElement PhotoItem::toSvg(QDomDocument & document) const
{
    QDomElement result = AbstractPhoto::toSvg(document);
    result.setAttribute("class", "PhotoItem");

    // 'defs' tag
    QDomElement defs = document.createElement("defs");
    defs.setAttribute("class", "data");
    result.appendChild(defs);

    // 'defs'-> pfe:'data'
    QDomElement appNS = document.createElementNS(KIPIPhotoLayoutsEditor::uri(), "data");
    appNS.setPrefix(KIPIPhotoLayoutsEditor::name());
    defs.appendChild(appNS);

    if (!m_image_path.isEmpty())
    {
        // 'defs'-> pfe:'data' ->'path'
        QDomElement path = KIPIPhotoLayoutsEditor::pathToSvg(m_image_path, document);
        path.setAttribute("class", "m_image_path");
        path.setPrefix(KIPIPhotoLayoutsEditor::name());
        appNS.appendChild(path);
    }

    QDomElement image = document.createElementNS(KIPIPhotoLayoutsEditor::uri(), "image");
    appNS.appendChild(image);
    // Saving image data
    if (!PLEConfigSkeleton::embedImagesData())
    {
        int result = KMessageBox::questionYesNo(0,
                                                i18n("Do you want to embed images data?\n"
                                                        "Remember that when you move or rename image files on your disk or the storage device become unavailable, those images become unavailable for %1 "
                                                        "and this layout might become broken.", KApplication::applicationName()),
                                                i18n("Saving: %1", this->name()),
                                                KStandardGuiItem::yes(),
                                                KStandardGuiItem::no(),
                                                PLEConfigSkeleton::self()->config()->name());
        if (result == KMessageBox::Yes)
            PLEConfigSkeleton::setEmbedImagesData(true);
    }

    if ( (PLEConfigSkeleton::embedImagesData() && !d->pixmap().isNull()) || !d->fileUrl().isValid())
    {
        QByteArray byteArray;
        QBuffer buffer(&byteArray);
        d->pixmap().save(&buffer, "PNG");
        image.appendChild( document.createTextNode( QString(byteArray.toBase64()) ) );
    }

    // Saving image path
    if (d->fileUrl().isValid())
        image.setAttribute("src", d->fileUrl().url());

    return result;
}