aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/activitypub/apattachment.cpp15
-rw-r--r--src/activitypub/apattachment.h6
-rw-r--r--src/widgets/tab_actor_info.cpp14
3 files changed, 18 insertions, 17 deletions
diff --git a/src/activitypub/apattachment.cpp b/src/activitypub/apattachment.cpp
index db305ba..83d0bea 100644
--- a/src/activitypub/apattachment.cpp
+++ b/src/activitypub/apattachment.cpp
@@ -1,6 +1,7 @@
#include "apattachment.h"
#include <QFileInfo>
#include <QDebug>
+#include <memory>
APAttachment::APAttachment() {}
@@ -29,11 +30,11 @@ QString APAttachment::get_html_render(HtmlRenderDetails info) {
return html;
}
-const QPixmap& APAttachment::get_pixmap(int width, int height) {
- // Recreating the pixmap if it doesn't have the requested dimensions is quite inefficent. So it's better for the callee to resize the image instead of relying on this function.
- if (pixmap and pixmap_dimens.is_equal(width, height)) return *pixmap;
+std::shared_ptr<QPixmap> APAttachment::get_pixmap(int width, int height) {
+ // Recreating the pixmap if it doesn't have the requested dimensions is quite inefficent. So it's better for the callee to scale elsewhere the pixmap instead of relying on this function, if possible.
+ if (pixmap and pixmap_dimens.is_equal(width, height)) return pixmap;
else if (pixmap)
- delete pixmap;
+ pixmap.reset();
// pixmap_dimens are correctly based on the requested/function argument width and height, and not the actual dimentions of the pixmap!
pixmap_dimens.height = height;
@@ -52,13 +53,13 @@ const QPixmap& APAttachment::get_pixmap(int width, int height) {
else if (width == 0)
width = (height * image.width()) / image.height();
- pixmap = new QPixmap(image.scaled(QSize(width, height)));
+ pixmap = std::make_shared<QPixmap>(image.scaled(QSize(width, height)));
} else {
- pixmap = new QPixmap;
+ pixmap = std::make_shared<QPixmap>();
if (not pixmap->load(path_url))
qDebug() << "failed to load" << path_url;
}
- return *pixmap;
+ return pixmap;
}
QString APAttachmentList::get_html_render(HtmlRenderDetails render_info) {
diff --git a/src/activitypub/apattachment.h b/src/activitypub/apattachment.h
index 83e9339..4b5ba0e 100644
--- a/src/activitypub/apattachment.h
+++ b/src/activitypub/apattachment.h
@@ -4,7 +4,7 @@
#include "fields.h"
#include <QPixmap>
#include <array>
-#include <vector>
+#include <memory>
class APAttachment : APBase {
public:
@@ -12,7 +12,7 @@ public:
APAttachment(APAttachmentFields fields);
~APAttachment() {};
QString get_html_render(HtmlRenderDetails render_info);
- const QPixmap& get_pixmap(int width = 0, int height = 0);
+ std::shared_ptr<QPixmap> get_pixmap(int width = 0, int height = 0);
private:
QString blurhash;
@@ -22,7 +22,7 @@ private:
QString path_url; // attachment URL, might be file on filesystem (make sure that the attachment dir has been found and that the path is correct)
QString filename; // nicer descriptor of the attachment's path
- QPixmap* pixmap = nullptr;
+ std::shared_ptr<QPixmap> pixmap;
struct {
int width = 0;
int height = 0;
diff --git a/src/widgets/tab_actor_info.cpp b/src/widgets/tab_actor_info.cpp
index 282d093..1bfb59d 100644
--- a/src/widgets/tab_actor_info.cpp
+++ b/src/widgets/tab_actor_info.cpp
@@ -39,7 +39,7 @@ void TabActorInfo::update_ui() {
ui->displayNameText->setText(ui->displayNameText->text().arg(actor->name).arg(actor->username));
ui->summaryText->setHtml(actor->summary);
- ui->avatarImage->setPixmap(actor->avatar->get_pixmap(ui->avatarImage->size().width()));
+ ui->avatarImage->setPixmap(*actor->avatar->get_pixmap(ui->avatarImage->size().width()));
int row = 0;
for (APPropertyValue prop : actor->table) {
@@ -56,17 +56,17 @@ void TabActorInfo::paintEvent(QPaintEvent* event) {
painter.setOpacity(0.75);
auto &widget = *(ui->displayNameText);
- QPixmap pixmap = actor->header->get_pixmap(widget.width());
+ std::shared_ptr<QPixmap> pixmap = actor->header->get_pixmap(widget.width());
- QPoint centre(widget.width() / 2 - pixmap.width() / 2,
- widget.height() / 2 - pixmap.height() / 2);
+ QPoint centre(widget.width() / 2 - pixmap->width() / 2,
+ widget.height() / 2 - pixmap->height() / 2);
QRect source(
- QPoint(0, abs(widget.height() - pixmap.height()) / 2),
- QPoint(pixmap.width(), abs(widget.height() - pixmap.height()) / 2 + widget.height())
+ QPoint(0, abs(widget.height() - pixmap->height()) / 2),
+ QPoint(pixmap->width(), abs(widget.height() - pixmap->height()) / 2 + widget.height())
);
- painter.drawPixmap(widget.pos(), pixmap, source);
+ painter.drawPixmap(widget.pos(), *pixmap, source);
painter.setOpacity(1.0);
}
}