KPIMTextEdit::RichTextComposerImages Class
class KPIMTextEdit::RichTextComposerImagesThe RichTextComposerImages class manages embedded images in rich text documents. More...
| Header: | #include <KPIMTextEdit/RichTextComposerImages> |
| CMake: | find_package(KPim6TextEdit REQUIRED)target_link_libraries(mytarget PRIVATE KPim6::TextEdit) |
| Inherits: | QObject |
Public Functions
| RichTextComposerImages(KPIMTextEdit::RichTextComposer *composer, QObject *parent = nullptr) | |
| virtual | ~RichTextComposerImages() override |
| void | addImage(const QUrl &url, int width = -1, int height = -1) |
| void | addImageHelper(const QUrl &url, int width = -1, int height = -1) |
| void | addImageHelper(const QString &imageName, const QImage &image, int width = -1, int height = -1) |
| QSharedPointer<KPIMTextEdit::EmbeddedImage> | createEmbeddedImage(const QImage &img, const QString &imageName) const |
| QList<QTextImageFormat> | embeddedImageFormats() const |
| QList<QSharedPointer<KPIMTextEdit::EmbeddedImage>> | embeddedImages() const |
| KPIMTextEdit::ImageWithNameList | imagesWithName() const |
| void | insertImage(const QImage &image, const QFileInfo &fileInfo) |
| void | loadImage(const QImage &image, const QString &matchName, const QString &resourceName) |
Static Public Members
| QByteArray | imageNamesToContentIds(const QByteArray &htmlBody, const KPIMTextEdit::ImageList &imageList) |
(since 6.9) QByteArray | imageNamesToContentIds(const QByteArray &htmlBody, const KPIMTextEdit::ImageList &imageList, const QByteArray &charset) |
Detailed Description
Member Function Documentation
[explicit] RichTextComposerImages::RichTextComposerImages(KPIMTextEdit::RichTextComposer *composer, QObject *parent = nullptr)
Constructs a RichTextComposerImages object.
composer The RichTextComposer instance parent The parent QObject
[override virtual noexcept] RichTextComposerImages::~RichTextComposerImages()
Destroys the RichTextComposerImages object.
void RichTextComposerImages::addImage(const QUrl &url, int width = -1, int height = -1)
Adds an image. The image is loaded from file and then pasted to the current cursor position with the given width and height.
url The URL of the file which contains the image width The width the inserted image will have. height The height the inserted image will have.
void RichTextComposerImages::addImageHelper(const QUrl &url, int width = -1, int height = -1)
Helper function to add an image from a URL.
url The URL of the image file width The width of the image, or -1 for default height The height of the image, or -1 for default
void RichTextComposerImages::addImageHelper(const QString &imageName, const QImage &image, int width = -1, int height = -1)
Helper function to add an image with the given name.
imageName The name of the image image The image to add width The width of the image, or -1 for default height The height of the image, or -1 for default
QSharedPointer<KPIMTextEdit::EmbeddedImage> RichTextComposerImages::createEmbeddedImage(const QImage &img, const QString &imageName) const
Creates an embedded image from a QImage.
img The image to embed imageName The name of the image Returns A shared pointer to the created EmbeddedImage
QList<QTextImageFormat> RichTextComposerImages::embeddedImageFormats() const
Returns a list of all embedded image formats.
Returns A list of QTextImageFormat objects
QList<QSharedPointer<KPIMTextEdit::EmbeddedImage>> RichTextComposerImages::embeddedImages() const
Returns a list of all embedded images.
Returns A list of embedded image pointers
[static] QByteArray RichTextComposerImages::imageNamesToContentIds(const QByteArray &htmlBody, const KPIMTextEdit::ImageList &imageList)
For all given embedded images, this function replace the image name in the <img> tag of the HTML body with cid:content-id, so that the HTML references the image body parts, see RFC 2557.
This is useful when building a MIME message with inline images.
Note that this function works on encoded content already.
htmlBody the HTML code in which the <img> tag will be modified. The HTML code here could come from toHtml(), for example.
imageList the list of images of which the <img> tag will be modified. You can get such a list from the embeddedImages() function.
Returns a modified HTML code, where the <img> tags got replaced
[static, since 6.9] QByteArray RichTextComposerImages::imageNamesToContentIds(const QByteArray &htmlBody, const KPIMTextEdit::ImageList &imageList, const QByteArray &charset)
charset the charset which was used to encode htmlBody, so that the image names are encoded the same way. Image names with non-ascii characters are not found otherwise.
This is an overloaded function.
This function was introduced in 6.9.
KPIMTextEdit::ImageWithNameList RichTextComposerImages::imagesWithName() const
Returns a list of all images with their names.
Returns A list of ImageWithNamePtr objects
void RichTextComposerImages::insertImage(const QImage &image, const QFileInfo &fileInfo)
Inserts an image from file information.
image The image to insert fileInfo The file information for the image
void RichTextComposerImages::loadImage(const QImage &image, const QString &matchName, const QString &resourceName)
Loads an image into the textedit. The difference to addImage() is that this function expects that the image tag is already present in the HTML source.
image the image to load matchName the name of tags to match image resourceName the resource name of image So what this message does is that it scans the HTML source for the image tag that matches the matchName, and then inserts the image as a resource, giving that resource the name resourceName.