Commit 526974bf authored by Thorsten Zachmann's avatar Thorsten Zachmann

o add a way to store temporary images not part of the image collection

  to the store on saving. This should be used only for temporary images
  e.g. a pixmap representation of a draw:frame.
  The code is untested but should work.

@Mek: here is the functionality to save the qimage for the frame. Can
you please check if it works.

CCMAIL: m.kruisselbrink@student.tue.nl

svn path=/trunk/koffice/; revision=924575
parent a9db8384
......@@ -155,6 +155,16 @@ QString KoShapeSavingContext::imageHref(KoImageData * image)
return it.value();
}
QString KoShapeSavingContext::imageHref(QImage & image)
{
// TODO this can be optimized to recocnice images which have the same content
// Also this can use quite a lot of memeory as the qimage are all kept until
// the they are saved to the store in memory
QString href = QString("Pictures/image%1.png").arg(++m_imageId);
m_images.insert(href, image);
return href;
}
QMap<QByteArray, QString> KoShapeSavingContext::imagesToSave()
{
return m_imageNames;
......@@ -172,6 +182,25 @@ bool KoShapeSavingContext::saveDataCenter(KoStore *store, KoXmlWriter* manifestW
ok = ok && dataCenter->completeSaving(store, manifestWriter, this);
kDebug() << "ok" << ok;
}
for ( QMap<QString, QImage>::iterator it(m_images.begin()); it != m_images.end(); ++it ) {
if (store->open(it.key())) {
KoStoreDevice device(store);
ok = ok && it.value().save(&device, "PNG");
store->close();
// TODO error handling
if (ok) {
const QString mimetype(KMimeType::findByPath(it.key(), 0 , true)->name());
manifestWriter->addManifestEntry(it.key(), mimetype);
}
else {
kWarning(30006) << "saving image failed";
}
}
else {
ok = false;
kWarning(30006) << "saving image failed: open store failed";
}
}
return ok;
}
......
......@@ -179,6 +179,14 @@ public:
*/
QString imageHref(KoImageData * image);
/**
* Get the image href under which the image will be save in the store
*
* This should only be used for temporary images that are onle there during
* saving, e.g. a pixmap representation of a draw:frame
*/
QString imageHref(QImage & image);
/**
* Get the images that needs to be saved to the store
*/
......@@ -235,6 +243,7 @@ private:
QMap<QString, KoSharedSavingData*> m_sharedData;
QMap<QByteArray, QString> m_imageNames;
int m_imageId;
QMap<QString, QImage> m_images;
KoGenStyles& m_mainStyles;
KoEmbeddedDocumentSaver& m_embeddedSaver;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment