KPimTextEdit

richtextcomposerimages.h
1/*
2 SPDX-FileCopyrightText: 2015-2024 Laurent Montel <montel@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#pragma once
8
9#include "kpimtextedit_export.h"
10#include <QFileInfo>
11#include <QImage>
12#include <QObject>
13#include <QSharedPointer>
14#include <QTextImageFormat>
15namespace KPIMTextEdit
16{
17class RichTextComposer;
18/**
19 * Holds information about an embedded HTML image that will be useful for mail clients.
20 * A list with all images can be retrieved with TextEdit::embeddedImages().
21 */
23 QByteArray image; ///< The image, encoded as PNG with base64 encoding
24 QString contentID; ///< The content id of the embedded image
25 QString imageName; ///< Name of the image as it is available as a resource in the editor
26};
27
28/**
29 * Holds information about an embedded HTML image that will be generally useful.
30 * A list with all images can be retrieved with TextEdit::imagesWithName().
31 *
32 * @since 4.4
33 */
35 QImage image; ///< The image
36 QString name; ///< The name of the image as it is available as a resource in the editor
37};
38
42
43class KPIMTEXTEDIT_EXPORT RichTextComposerImages : public QObject
44{
45 Q_OBJECT
46public:
47 explicit RichTextComposerImages(RichTextComposer *composer, QObject *parent = nullptr);
48 ~RichTextComposerImages() override;
49
50 /**
51 * Adds an image. The image is loaded from file and then pasted to the current
52 * cursor position with the given @p width and @p height.
53 *
54 * @param url The URL of the file which contains the image
55 * @param width The width the inserted image will have.
56 * @param height The height the inserted image will have.
57 *
58 */
59 void addImage(const QUrl &url, int width = -1, int height = -1);
60
61 /**
62 * Loads an image into the textedit. The difference to addImage() is that this
63 * function expects that the image tag is already present in the HTML source.
64 *
65 * @param image the image to load
66 * @param matchName the name of tags to match image
67 * @param resourceName the resource name of image
68 * So what this message does is that it scans the HTML source for the image
69 * tag that matches the @p matchName, and then inserts the @p image as a
70 * resource, giving that resource the name @p resourceName.
71 *
72 */
73 void loadImage(const QImage &image, const QString &matchName, const QString &resourceName);
74
75 void addImageHelper(const QString &imageName, const QImage &image, int width = -1, int height = -1);
76 [[nodiscard]] ImageWithNameList imagesWithName() const;
77 [[nodiscard]] QList<QSharedPointer<EmbeddedImage>> embeddedImages() const;
78 [[nodiscard]] QList<QTextImageFormat> embeddedImageFormats() const;
79 void addImageHelper(const QUrl &url, int width = -1, int height = -1);
80 void insertImage(const QImage &image, const QFileInfo &fileInfo);
81
82 /**
83 * For all given embedded images, this function replace the image name
84 * in the <img> tag of the HTML body with cid:content-id, so that the
85 * HTML references the image body parts, see RFC 2557.
86 *
87 * This is useful when building a MIME message with inline images.
88 *
89 * Note that this function works on encoded content already.
90 *
91 * @param htmlBody the HTML code in which the <img> tag will be modified.
92 * The HTML code here could come from toHtml(), for example.
93 *
94 * @param imageList the list of images of which the <img> tag will be modified.
95 * You can get such a list from the embeddedImages() function.
96 *
97 * @return a modified HTML code, where the <img> tags got replaced
98 */
99 [[nodiscard]] static QByteArray imageNamesToContentIds(const QByteArray &htmlBody, const ImageList &imageList);
100
101 [[nodiscard]] QSharedPointer<EmbeddedImage> createEmbeddedImage(const QImage &img, const QString &imageName) const;
102
103private:
104 class RichTextComposerImagesPrivate;
105 std::unique_ptr<RichTextComposerImagesPrivate> const d;
106};
107}
The RichTextComposer class.
Holds information about an embedded HTML image that will be useful for mail clients.
QString contentID
The content id of the embedded image.
QByteArray image
The image, encoded as PNG with base64 encoding.
QString imageName
Name of the image as it is available as a resource in the editor.
Holds information about an embedded HTML image that will be generally useful.
QString name
The name of the image as it is available as a resource in the editor.
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:20:45 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.