handled a case when user removes downloaded file, minor optimizations on message changing

This commit is contained in:
Blue 2021-04-28 23:26:19 +03:00
parent b44873d587
commit 50190f3eac
23 changed files with 136 additions and 40 deletions

View file

@ -304,6 +304,7 @@ void FeedView::setItemDelegate(QAbstractItemDelegate* delegate)
if (specialDelegate) {
MessageDelegate* del = static_cast<MessageDelegate*>(itemDelegate());
disconnect(del, &MessageDelegate::buttonPushed, this, &FeedView::onMessageButtonPushed);
disconnect(del, &MessageDelegate::invalidPath, this, &FeedView::onMessageInvalidPath);
}
QAbstractItemView::setItemDelegate(delegate);
@ -312,6 +313,7 @@ void FeedView::setItemDelegate(QAbstractItemDelegate* delegate)
if (del) {
specialDelegate = true;
connect(del, &MessageDelegate::buttonPushed, this, &FeedView::onMessageButtonPushed);
connect(del, &MessageDelegate::invalidPath, this, &FeedView::onMessageInvalidPath);
} else {
specialDelegate = false;
}
@ -341,3 +343,12 @@ void FeedView::onMessageButtonPushed(const QString& messageId, bool download)
}
}
}
void FeedView::onMessageInvalidPath(const QString& messageId)
{
if (specialModel) {
Models::MessageFeed* feed = static_cast<Models::MessageFeed*>(model());
feed->reportLocalPathInvalid(messageId);
}
}

View file

@ -55,6 +55,7 @@ protected slots:
void verticalScrollbarValueChanged(int value) override;
void dataChanged(const QModelIndex & topLeft, const QModelIndex & bottomRight, const QVector<int> & roles) override;
void onMessageButtonPushed(const QString& messageId, bool download);
void onMessageInvalidPath(const QString& messageId);
protected:
int verticalOffset() const override;

View file

@ -310,7 +310,11 @@ void MessageDelegate::paintPreview(const Models::FeedItem& data, QPainter* paint
start = option.rect.topLeft();
}
QImage img(data.attach.localPath);
painter->drawImage(QRect(start, size), img);
if (img.isNull()) {
emit invalidPath(data.id);
} else {
painter->drawImage(QRect(start, size), img);
}
option.rect.adjust(0, size.height() + textMargin, 0, 0);
}

View file

@ -55,6 +55,7 @@ public:
signals:
void buttonPushed(const QString& messageId, bool download) const;
void invalidPath(const QString& messageId) const;
protected:
void paintButton(QPushButton* btn, QPainter* painter, bool sentByMe, QStyleOptionViewItem& option) const;