Commit ee5562c6 authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Add method for creating embedded image (used by markdown plugin)

parent eb91d4ba
cmake_minimum_required(VERSION 3.5)
set(PIM_VERSION "5.11.40")
set(PIM_VERSION "5.11.41")
project(KPimTextEdit VERSION ${PIM_VERSION})
......
......@@ -190,20 +190,26 @@ QList< QSharedPointer<EmbeddedImage> > RichTextComposerImages::embeddedImages()
QList< QSharedPointer<EmbeddedImage> > retImages;
retImages.reserve(normalImages.count());
for (const ImageWithNamePtr &normalImage : normalImages) {
QBuffer buffer;
buffer.open(QIODevice::WriteOnly);
normalImage->image.save(&buffer, "PNG");
qsrand(QDateTime::currentDateTimeUtc().toSecsSinceEpoch() + qHash(normalImage->name));
QSharedPointer<EmbeddedImage> embeddedImage(new EmbeddedImage());
retImages.append(embeddedImage);
embeddedImage->image = KCodecs::Codec::codecForName("base64")->encode(buffer.buffer());
embeddedImage->imageName = normalImage->name;
embeddedImage->contentID = QStringLiteral("%1@KDE").arg(qrand());
retImages.append(createEmbeddedImage(normalImage->image, normalImage->name));
}
return retImages;
}
QSharedPointer<EmbeddedImage> RichTextComposerImages::createEmbeddedImage(const QImage &img, const QString &imageName) const
{
QBuffer buffer;
buffer.open(QIODevice::WriteOnly);
img.save(&buffer, "PNG");
qsrand(QDateTime::currentDateTimeUtc().toSecsSinceEpoch() + qHash(imageName));
QSharedPointer<EmbeddedImage> embeddedImage(new EmbeddedImage());
embeddedImage->image = KCodecs::Codec::codecForName("base64")->encode(buffer.buffer());
embeddedImage->imageName = imageName;
embeddedImage->contentID = QStringLiteral("%1@KDE").arg(qrand());
return embeddedImage;
}
QList<QTextImageFormat> RichTextComposerImages::embeddedImageFormats() const
{
QTextDocument *doc = d->composer->document();
......
......@@ -111,6 +111,7 @@ public:
*/
static QByteArray imageNamesToContentIds(const QByteArray &htmlBody, const ImageList &imageList);
Q_REQUIRED_RESULT QSharedPointer<EmbeddedImage> createEmbeddedImage(const QImage &img, const QString &imageName) const;
private:
class RichTextComposerImagesPrivate;
RichTextComposerImagesPrivate *const d;
......
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