Render cached image and video previews without filesystem access or scaled pixmap allocation
This commit is contained in:
1 parent
9961ab8271
commit
e85cb022e2
2 files changed
+13
-18
No files matched your search
@@ -1212,25 +1212,21 @@ void MessageDelegate::paintBody(QPainter* painter, const QStyleOptionViewItem& o
|
||||
drawBubble(painter, L, option);
|
||||
if (!L.narrow) drawAvatar(painter, L, index);
|
||||
|
||||
QString filePath = index.data(MsgVoiceFileRole).toString();
|
||||
int dlState = index.data(MsgFileDownloadStateRole).toInt();
|
||||
QString thumbPath = filePath + ".jpg";
|
||||
|
||||
painter->save();
|
||||
painter->setRenderHint(QPainter::Antialiasing);
|
||||
painter->setRenderHint(QPainter::SmoothPixmapTransform);
|
||||
QPainterPath clip;
|
||||
clip.addRoundedRect(L.videoThumbRect, kRadius, kRadius);
|
||||
painter->setClipPath(clip);
|
||||
|
||||
QPixmap thumb;
|
||||
if (!thumbPath.isEmpty() && QFile::exists(thumbPath))
|
||||
thumb.load(thumbPath);
|
||||
const QImage thumb = index.data(MsgImagePreviewRole).value<QImage>();
|
||||
|
||||
if (!thumb.isNull()) {
|
||||
QPixmap scaled = thumb.scaled(L.videoThumbRect.size(), Qt::KeepAspectRatioByExpanding, Qt::SmoothTransformation);
|
||||
int dx = (scaled.width() - L.videoThumbRect.width()) / 2;
|
||||
int dy = (scaled.height() - L.videoThumbRect.height()) / 2;
|
||||
painter->drawPixmap(L.videoThumbRect.topLeft(), scaled, QRect(dx, dy, L.videoThumbRect.width(), L.videoThumbRect.height()));
|
||||
QSize source = L.videoThumbRect.size().scaled(thumb.size(), Qt::KeepAspectRatio);
|
||||
QRect crop(QPoint((thumb.width() - source.width()) / 2, (thumb.height() - source.height()) / 2), source);
|
||||
painter->drawImage(L.videoThumbRect, thumb, crop);
|
||||
} else {
|
||||
painter->fillRect(L.videoThumbRect, QColor(30, 30, 35));
|
||||
QFont iconFont = option.font;
|
||||
@@ -1335,14 +1331,13 @@ void MessageDelegate::paintBody(QPainter* painter, const QStyleOptionViewItem& o
|
||||
painter->setClipPath(clip);
|
||||
|
||||
const QImage image = index.data(MsgImagePreviewRole).value<QImage>();
|
||||
const QPixmap img = QPixmap::fromImage(image);
|
||||
|
||||
if (!img.isNull()) {
|
||||
if (!image.isNull()) {
|
||||
painter->fillRect(L.imageThumbRect, QColor(20, 20, 24));
|
||||
QPixmap scaled = img.scaled(L.imageThumbRect.size(), Qt::KeepAspectRatio, Qt::SmoothTransformation);
|
||||
int dx = (L.imageThumbRect.width() - scaled.width()) / 2;
|
||||
int dy = (L.imageThumbRect.height() - scaled.height()) / 2;
|
||||
painter->drawPixmap(L.imageThumbRect.left() + dx, L.imageThumbRect.top() + dy, scaled);
|
||||
painter->setRenderHint(QPainter::SmoothPixmapTransform);
|
||||
QSize fitted = image.size().scaled(L.imageThumbRect.size(), Qt::KeepAspectRatio);
|
||||
QPoint origin(L.imageThumbRect.left() + (L.imageThumbRect.width() - fitted.width()) / 2,
|
||||
L.imageThumbRect.top() + (L.imageThumbRect.height() - fitted.height()) / 2);
|
||||
painter->drawImage(QRect(origin, fitted), image);
|
||||
} else {
|
||||
painter->fillRect(L.imageThumbRect, QColor(30, 30, 35));
|
||||
QFont iconFont = option.font;
|
||||
|
||||
@@ -55,8 +55,8 @@ enum MessageDataRole {
|
||||
MsgHighlightRole = Qt::UserRole + 41,
|
||||
MsgEncryptedRole = Qt::UserRole + 42,
|
||||
MsgVersionRole = Qt::UserRole + 43,
|
||||
MsgImagePreviewRole = Qt::UserRole + 44, /* QImage ограниченного размера, подготовленный worker. */
|
||||
MsgImageErrorRole = Qt::UserRole + 45, /* Локальный файл не декодируется; показать читаемую ошибку. */
|
||||
MsgImagePreviewRole = Qt::UserRole + 44, /* QImage картинки либо первого видеокадра из общего кеша, подготовленный worker. */
|
||||
MsgImageErrorRole = Qt::UserRole + 45, /* Ошибка подготовки локального медиа; не повторять до изменения исходника/загрузки. */
|
||||
};
|
||||
|
||||
class MessageDelegate : public QStyledItemDelegate {
|
||||
|
||||
Reference in new issue
Block a user