@@ -64,6 +64,7 @@ void PreviewEntryAttachmentsDialog::setAttachment(const QString& name, const QBy
64
64
65
65
m_type = attachmentType (data);
66
66
m_data = data;
67
+ m_imageCache = QImage ();
67
68
68
69
update ();
69
70
}
@@ -86,23 +87,31 @@ void PreviewEntryAttachmentsDialog::updateTextAttachment(const QByteArray& data)
86
87
87
88
void PreviewEntryAttachmentsDialog::updateImageAttachment (const QByteArray& data)
88
89
{
89
- QImage image{};
90
- if (!image.loadFromData (data)) {
90
+ if (m_imageCache.isNull () && !m_imageCache.loadFromData (data)) {
91
91
updateTextAttachment (tr (" Image format not supported" ).toUtf8 ());
92
92
return ;
93
93
}
94
94
95
+ updateImageAttachment (m_imageCache);
96
+ }
97
+
98
+ void PreviewEntryAttachmentsDialog::updateImageAttachment (const QImage& image)
99
+ {
95
100
m_ui->attachmentTextEdit ->clear ();
96
101
auto cursor = m_ui->attachmentTextEdit ->textCursor ();
97
102
103
+ cursor.insertImage (image.scaled (calculateImageSize (), Qt::KeepAspectRatio, Qt::SmoothTransformation));
104
+ }
105
+
106
+ QSize PreviewEntryAttachmentsDialog::calculateImageSize ()
107
+ {
98
108
// Scale the image to the contents rect minus another set of margins to avoid scrollbars
99
109
auto margins = m_ui->attachmentTextEdit ->contentsMargins ();
100
110
auto size = m_ui->attachmentTextEdit ->contentsRect ().size ();
101
111
size.setWidth (size.width () - margins.left () - margins.right ());
102
112
size.setHeight (size.height () - margins.top () - margins.bottom ());
103
- image = image.scaled (size, Qt::KeepAspectRatio, Qt::SmoothTransformation);
104
113
105
- cursor. insertImage (image) ;
114
+ return size ;
106
115
}
107
116
108
117
Tools::MimeType PreviewEntryAttachmentsDialog::attachmentType (const QByteArray& data) const
0 commit comments