Fix image width in project description

Signed-off-by: Trial97 <alexandru.tripon97@gmail.com>
(cherry picked from commit c902da4461)
This commit is contained in:
Trial97
2024-04-24 22:02:55 +03:00
committed by github-actions[bot]
parent cf87aed7ff
commit 28378c77aa
2 changed files with 66 additions and 14 deletions

View File

@ -22,6 +22,7 @@
#include <QString>
#include <QTextObjectInterface>
#include <QUrl>
#include <memory>
/** Custom image text object to be used instead of the normal one in ProjectDescriptionPage.
*
@ -32,6 +33,14 @@ class VariableSizedImageObject final : public QObject, public QTextObjectInterfa
Q_OBJECT
Q_INTERFACES(QTextObjectInterface)
struct ImageMetadata {
int posInDocument;
QUrl url;
QImage image;
int width;
int height;
};
public:
QSizeF intrinsicSize(QTextDocument* doc, int posInDocument, const QTextFormat& format) override;
void drawObject(QPainter* painter, const QRectF& rect, QTextDocument* doc, int posInDocument, const QTextFormat& format) override;
@ -49,13 +58,13 @@ class VariableSizedImageObject final : public QObject, public QTextObjectInterfa
private:
/** Adds the image to the document, in the given position.
*/
void parseImage(QTextDocument* doc, QImage image, int posInDocument);
void parseImage(QTextDocument* doc, std::shared_ptr<ImageMetadata> meta);
/** Loads an image from an external source, and adds it to the document.
*
* This uses m_meta_entry to cache the image.
*/
void loadImage(QTextDocument* doc, const QUrl& source, int posInDocument);
void loadImage(QTextDocument* doc, std::shared_ptr<ImageMetadata> meta);
private:
QString m_meta_entry;