#include "apattachment.h" #include APAttachment::APAttachment() {} APAttachment::APAttachment(APAttachmentFields fields) { path_url = fields.path; type = fields.media_type; description = fields.name; } QString APAttachment::get_html_render(HtmlRenderDetails info) { QString html(get_html_template("apattachment")); if (not path_url.isEmpty()) { html.replace("{{path}}", path_url); html.replace("{{filename}}", QFileInfo(path_url).fileName()); // FIXME: this is maybe ugly? } if (type.startsWith("image/")) // dynamically resize image based on the display widget size to avoid horizontal scrolling html.replace("{{img-width}}", QString::number((float)info.text_zone_width - (float)info.text_zone_width*0.15)); // finally after passing this for so long i finally use it else html.replace("{{img-width}}", "0"); html.replace("{{alt-text}}", description); return html; } QString APAttachmentList::get_html_render(HtmlRenderDetails render_info) { QString html; int i = 1; for (APAttachment attachment : *this) { QString item_html(get_html_template("apattachmentlist_item")); item_html.replace("{{id}}", QString::number(i)); item_html.replace("{{attachment}}", attachment.get_html_render(render_info)); html.append(item_html); ++i; } return html; }