Commit c4c675cb authored by kaniini's avatar kaniini

make attachment preview work

parent a6ce8571
......@@ -211,6 +211,8 @@ void Account::upload(std::shared_ptr<Post> p, QFile *file, QString filename)
if (att->m_url.isEmpty ())
return;
att->fetchPreviewImage ();
p->m_attachments.append (att);
emit attachmentUploaded (p, att);
......
......@@ -20,11 +20,11 @@ void PreviewDelegate::paint(QPainter* painter, const QStyleOptionViewItem & opti
auto alignment = Qt::AlignHCenter | Qt::AlignTop;
option.rect.moveBottom(option.rect.bottom() + PREVIEW_MARGIN);
QRect aligned_rect = QStyle::alignedRect(option.direction, alignment, QSize(PREVIEW_SIZE, PREVIEW_SIZE), option.rect);
QPixmap avatar = index.data(Qt::DecorationRole).value<QPixmap>();
QPixmap preview = index.data(Qt::DecorationRole).value<QPixmap>();
painter->save();
painter->setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform, true);
painter->drawPixmap(aligned_rect, avatar, avatar.rect());
painter->drawPixmap(aligned_rect, preview, preview.rect());
painter->restore();
}
......@@ -50,13 +50,16 @@ int AttachmentEditorModel::rowCount(const QModelIndex &) const
QVariant AttachmentEditorModel::data(const QModelIndex &index, int role) const
{
if (role != Qt::DisplayRole)
return QVariant ();
int row = index.row ();
int col = index.column ();
auto att = m_scratch->m_attachments[row];
if (role == Qt::DecorationRole && col == Preview)
return att->m_preview;
if (role != Qt::DisplayRole)
return QVariant ();
switch (col)
{
case Preview:
......
......@@ -91,6 +91,13 @@ ComposeForm::ComposeForm(Michabo::AccountManager *manager, QWidget *parent)
m_attachment_editor->updateDirty ();
});
QObject::connect(m_account, &Michabo::Account::invalidatedPost, [=] (Michabo::Post *p) {
if (p != m_scratch.get ())
return;
m_attachment_editor->updateDirty ();
});
}
void ComposeForm::updateScratch()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment